]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Aarch64: Add __sqrt and __sqrtf intrinsics and corresponding tests
authorAyan Shafqat <ayan.x.shafqat@gmail.com>
Thu, 1 May 2025 13:17:30 +0000 (06:17 -0700)
committerKyrylo Tkachov <ktkachov@nvidia.com>
Thu, 1 May 2025 13:44:28 +0000 (15:44 +0200)
This patch introduces two new inline functions, __sqrt and __sqrtf, in
arm_acle.h for Aarch64 targets. These functions wrap the new builtins
__builtin_aarch64_sqrtdf and __builtin_aarch64_sqrtsf, respectively,
providing direct access to hardware instructions without relying on the
standard math library or optimization levels.

This patch also introduces acle_sqrt.c in the AArch64 testsuite,
verifying that the new __sqrt and __sqrtf intrinsics emit the expected
fsqrt instructions for double and float arguments.

Coverage for new intrinsics ensures that __sqrt and __sqrtf are
correctly expanded to hardware instructions and do not fall back to
library calls, regardless of optimization levels.

gcc/ChangeLog:

* config/aarch64/arm_acle.h (__sqrt, __sqrtf): New function.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/acle/acle_sqrt.c: New test.

Signed-off-by: Ayan Shafqat <ayan.x.shafqat@gmail.com>
gcc/config/aarch64/arm_acle.h
gcc/testsuite/gcc.target/aarch64/acle/acle_sqrt.c [new file with mode: 0644]

index d9e2401ea9f67885d0bc027ccb5311188b24b0dd..507b6e72bcb1565b0ff0261cd8b1ccdea02e3511 100644 (file)
@@ -118,6 +118,20 @@ __revl (unsigned long __value)
     return __rev (__value);
 }
 
+__extension__ extern __inline double
+__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
+__sqrt (double __x)
+{
+  return __builtin_aarch64_sqrtdf (__x);
+}
+
+__extension__ extern __inline float
+__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
+__sqrtf (float __x)
+{
+  return __builtin_aarch64_sqrtsf (__x);
+}
+
 #pragma GCC push_options
 #pragma GCC target ("+nothing+jscvt")
 __extension__ extern __inline int32_t
diff --git a/gcc/testsuite/gcc.target/aarch64/acle/acle_sqrt.c b/gcc/testsuite/gcc.target/aarch64/acle/acle_sqrt.c
new file mode 100644 (file)
index 0000000..482351f
--- /dev/null
@@ -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 "fsqrt\td\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "fsqrt\ts\[0-9\]" 1 } } */