Add inline implementations of the ACLE __sqrt() and __sqrtf() functions in arm_acle.h. These functions, defined when __ARM_FP is available[1], forward the square-root operation to the corresponding NEON builtins:
* __sqrt() calls __builtin_neon_vsqrtdf for double precision. * __sqrtf() calls __builtin_neon_vsqrtsf for single precision. Additionally, a new testsuite file (acle_sqrt.c) is introduced to verify the generated assembly contains the proper vsqrt instructions (vsqrt.f64 and vsqrt.f32) when compiling ACLE sqrt intrinsics. modified: gcc/config/arm/arm_acle.h * Add inline definitions for __sqrt() and __sqrtf(). new file: gcc/testsuite/gcc.target/arm/acle/acle_sqrt.c * Create tests to compile and check for vsqrt.f64 and vsqrt.f32 instructions. [1] https://developer.arm.com/documentation/101028/0012/3--C-language-extensions Signed-off-by: Ayan Shafqat <ayan.x.shaf...@gmail.com> --- gcc/ChangeLog | 16 ++++++++++++++++ gcc/config/arm/arm_acle.h | 18 ++++++++++++++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.target/arm/acle/acle_sqrt.c | 17 +++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 gcc/testsuite/gcc.target/arm/acle/acle_sqrt.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 704146d97aa..25b1905fa77 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2025-03-13 Ayan Shafqat <ayan.x.shaf...@gmail.com> + + * config/arm/arm_acle.h (__sqrt, __sqrtf): + Add inline definitions for __sqrt() and __sqrtf() (guarded by __ARM_FP) + that forward to the NEON square-root builtins (__builtin_neon_vsqrtdf + and __builtin_neon_vsqrtsf), enabling ACLE sqrt intrinsics. + + * config/arm/arm-builtins.cc (df_UP): + Define df_UP to map to E_DFmode and add CODE_FOR_neon_vsqrtsf and + CODE_FOR_neon_vsqrtdf to support the new vsqrt builtins. + + * config/arm/arm_vfp_builtins.def (VAR1, VAR3): + Replace the single-mode vsqrt entry (VAR1) with a VAR3 entry that supports + hf, sf, and df modes. + + 2025-03-12 Jeff Law <j...@ventanamicro.com> Revert: diff --git a/gcc/config/arm/arm_acle.h b/gcc/config/arm/arm_acle.h index c6c03fdce27..c5f8d35c7d5 100644 --- a/gcc/config/arm/arm_acle.h +++ b/gcc/config/arm/arm_acle.h @@ -829,6 +829,24 @@ __crc32cd (uint32_t __a, uint64_t __b) #endif /* __ARM_FEATURE_CRC32 */ #pragma GCC pop_options +#ifdef __ARM_FP +__extension__ extern __inline double +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) +__sqrt(double __x) +{ + return __builtin_neon_vsqrtdf (__x); +} +#endif + +#ifdef __ARM_FP +__extension__ extern __inline float +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) +__sqrtf(float __x) +{ + return __builtin_neon_vsqrtsf (__x); +} +#endif + #ifdef __cplusplus } #endif diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 95a405651c6..a03b78f9fba 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2025-03-13 Ayan Shafqat <ayan.x.shaf...@gmail.com> + + * gcc.target/arm/acle/acle_sqrt.c: New test to verify that the ACLE + __sqrt() and __sqrtf() intrinsics are correctly lowered to the expected + vsqrt.f64 and vsqrt.f32 instructions. + 2025-03-11 Jakub Jelinek <ja...@redhat.com> PR c/117178 diff --git a/gcc/testsuite/gcc.target/arm/acle/acle_sqrt.c b/gcc/testsuite/gcc.target/arm/acle/acle_sqrt.c new file mode 100644 index 00000000000..f95e3476c4d --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/acle/acle_sqrt.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#include "arm_acle.h" + +double test_acle_sqrt (double x) +{ + return __sqrt (x); +} + +float test_acle_sqrtf (float x) +{ + return __sqrtf (x); +} + +/* { dg-final { scan-assembler-times "vsqrt.f64\td\[0-9\]" 1 } } */ +/* { dg-final { scan-assembler-times "vsqrt.f32\ts\[0-9\]" 1 } } */ -- 2.43.0