1

By default, clang defines some SIMD related macros:

~ $ 0 clang++  -dM -E -x c /dev/null | grep -i sse
#define __SSE2_MATH__ 1
#define __SSE2__ 1
#define __SSE_MATH__ 1
#define __SSE__ 1

These can be disabled by using -mno-sse. However, combining the -mno-sse flag with another architecture triple outputs a legitimate warning:

~ $ 1 clang++ -mno-sse --target=arm-none-eabi -dM -E -x c /dev/null
clang++: error: unsupported option '-mno-sse' for target 'arm-none-eabi'

Is it possible to disable all SIMD related defines, regardless of the target architecture?

2
  • 1
    obviously you need to specify the SIMD for that target, like Neon/SVE for ARM, Altivec/VSX for PPC, MDMX/MSA for MIPS... But why do you want to disable SIMD? Commented May 25 at 11:17
  • 1
    Typically done through compiler flags, not code. The compiler will be vectorize loops etc. even if you don't explicitly use simd intrinsics. You have to tell the compiler not to use them via flags - and the flags are highly compiler dependent. Best to check the docs - you usually disable them by their extension name (e g. neon (arm), sse/avx (x86), etc) Commented May 25 at 11:27

1 Answer 1

3

For targets that support -mgeneral-regs-only, it also turns off the relevant SIMD feature macros. It's supported on a few ISAs including x86 and -target arm64-linux-gnu.
(The manual incorrectly claims it only applies to AArch64, but it does work on my x86-64 desktop.)

But unfortunately it's not supported for -target arm-none-eabi or -target arm-linux-gnu, on clang 18 where I tested, so isn't the answer for your specific use-case.

For x86 (including x86-64) it also disables use of the x87 FPU, so you can't compile code that uses float, double, or long double.
Any target that has a scalar FPU would be similarly affected by this option.

GCC also supports -mgeneral-regs-only, but also only for a limited set of architectures.
It's used by the Linux kernel, and probably some other kernels, to make sure FP state isn't disturbed during system calls and interrupt handlers. Linux only uses SIMD registers via inline asm for e.g. software RAID5 and other places where it's worth doing a save/restore of the SIMD/FP state.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.