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. [1] https://developer.arm.com/documentation/101028/0012/3--C-language-extensions gcc/ChangeLog: * config/arm/arm_acle.h (__sqrt, __sqrtf): New functions gcc/testsuite/ChangeLog: * gcc.target/arm/acle/acle_sqrt.c: New test. Signed-off-by: Ayan Shafqat <ayan.x.shaf...@gmail.com> --- gcc/config/arm/arm_acle.h | 18 ++++++++++++++++++ gcc/testsuite/gcc.target/arm/acle/acle_sqrt.c | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/gcc.target/arm/acle/acle_sqrt.c diff --git a/gcc/config/arm/arm_acle.h b/gcc/config/arm/arm_acle.h index c6c03fdce27..c00a5dbce69 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__ static __inline double +__attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) +__sqrt (double __x) +{ + return __builtin_neon_vsqrtdf (__x); +} +#endif + +#ifdef __ARM_FP +__extension__ static __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/gcc.target/arm/acle/acle_sqrt.c b/gcc/testsuite/gcc.target/arm/acle/acle_sqrt.c new file mode 100644 index 00000000000..bf2ff1ffa8b --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/acle/acle_sqrt.c @@ -0,0 +1,19 @@ +/* { 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