diff options
author | Richard Earnshaw <rearnsha@arm.com> | 2025-03-07 15:17:14 +0000 |
---|---|---|
committer | Richard Earnshaw <rearnsha@arm.com> | 2025-03-07 15:51:29 +0000 |
commit | 104d86ceb14bfa30e6b9fdff494f3ce7246f46d0 (patch) | |
tree | 56036472a5d0a5bcb48af4e801e17ced32d8ec92 /gcc | |
parent | aa247ea8c3e443a6d60f382e2db2ef5c0069f879 (diff) | |
download | gcc-104d86ceb14bfa30e6b9fdff494f3ce7246f46d0.zip gcc-104d86ceb14bfa30e6b9fdff494f3ce7246f46d0.tar.gz gcc-104d86ceb14bfa30e6b9fdff494f3ce7246f46d0.tar.bz2 |
arm: make arm_neon.h compatible with '-march=<base> -mfloat-abi=softfp'
With -mfpu set to auto, an architecture specification that lacks
floating-point, but has -mfloat-abi=softfp will cause a misleading
error. Specifically, if we have
gcc -c test.c -mfloat-abi=softfp -march=armv7-a -mfpu=auto
where test.c contains #include <arm_neon.h>
then we get a misleading error:
test.c:11:2: error: #error "NEON intrinsics not available with the
soft-float ABI. Please use -mfloat-abi=softfp or -mfloat-abi=hard"
... the error message is advising us to add -mfloat-abi=softfp when we
already have it.
The difficulty is that we can't directly detect the softfp abi from
the available set of pre-defines.
Consider the options in this table, assuming -mfpu=auto:
-mfloat-abi
hard softfp soft
+-----------------------------------------------
-march=armv7-a | *build-error* __ARM_FP=0 __ARM_FP=0
-march=armv7-a+fp | __ARM_FP=12 __ARM_FP=12 __ARM_FP=0
However, for the first line, if we subsequently add
#pragma GCC target ("fpu=vfp")
then the value of __ARM_FP will change as follows:
-mfloat-abi
hard softfp soft
+-----------------------------------------------
-march=armv7-a | *build-error* __ARM_FP=12 __ARM_FP=0
-march=armv7-a+fp | __ARM_FP=12 __ARM_FP=12 __ARM_FP=0
We can therefore distinguish between the soft and softfp ABIs by
temporarily forcing VFP instructions into the ISA. If __ARM_FP is
still zero after doing this then we must be using the soft ABI.
gcc:
* config/arm/arm_neon.h: Try harder to detect if we have
the softfp ABI enabled.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/config/arm/arm_neon.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/gcc/config/arm/arm_neon.h b/gcc/config/arm/arm_neon.h index 578ada8..cba50de 100644 --- a/gcc/config/arm/arm_neon.h +++ b/gcc/config/arm/arm_neon.h @@ -27,7 +27,21 @@ #ifndef _GCC_ARM_NEON_H #define _GCC_ARM_NEON_H 1 +/* This header is only useful if we're compiling with -mfloat-abi=hard or + -mfloat-abi=softfp. But we can't detect that directly here as the + compiler does not provide a pre-define for it. However, we can check + whether forcing VFP will cause __ARM_FP to become defined and use that. */ + +#pragma GCC push_options +#pragma GCC target ("fpu=vfp") #ifndef __ARM_FP +#define __ARM_SOFT_ABI 1 +#else +#define __ARM_SOFT_ABI 0 +#endif +#pragma GCC pop_options + +#if __ARM_SOFT_ABI #error "NEON intrinsics not available with the soft-float ABI. Please use -mfloat-abi=softfp or -mfloat-abi=hard" #else @@ -21489,4 +21503,7 @@ vst4q_lane_bf16 (bfloat16_t * __a, bfloat16x8x4_t __b, const int __c) #pragma GCC pop_options #endif + +#undef __ARM_SOFT_ABI + #endif |