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?
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.