https://gcc.gnu.org/g:f4f7216c56fe2f67c72db5b7c4afa220725f3ed1

commit r15-8083-gf4f7216c56fe2f67c72db5b7c4afa220725f3ed1
Author: Ayan Shafqat <ayan.x.shaf...@gmail.com>
Date:   Mon Mar 17 09:28:27 2025 +0100

    Aarch64: Add FMA and FMAF intrinsic and corresponding tests
    
    This patch introduces inline definitions for the __fma and __fmaf
    functions in arm_acle.h for Aarch64 targets. These definitions rely on
    __builtin_fma and __builtin_fmaf to ensure proper inlining and to meet
    the ACLE requirements [1].
    
    The patch has been tested locally using a crosstool-NG sysroot for
    Aarch64, confirming that the generated code uses the expected fused
    multiply-accumulate instructions (fmadd).
    
    [1] 
https://arm-software.github.io/acle/main/acle.html#fused-multiply-accumulate-fma
    
    gcc/ChangeLog:
    
            * config/aarch64/arm_acle.h (__fma, __fmaf): New functions.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/aarch64/acle/acle_fma.c: New test.

Diff:
---
 gcc/config/aarch64/arm_acle.h                    | 14 ++++++++++++++
 gcc/testsuite/gcc.target/aarch64/acle/acle_fma.c | 17 +++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/gcc/config/aarch64/arm_acle.h b/gcc/config/aarch64/arm_acle.h
index 7976c117daf7..d9e2401ea9f6 100644
--- a/gcc/config/aarch64/arm_acle.h
+++ b/gcc/config/aarch64/arm_acle.h
@@ -129,6 +129,20 @@ __jcvt (double __a)
 
 #pragma GCC pop_options
 
+__extension__ extern __inline double
+__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
+__fma (double __x, double __y, double __z)
+{
+  return __builtin_fma (__x, __y, __z);
+}
+
+__extension__ extern __inline float
+__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
+__fmaf (float __x, float __y, float __z)
+{
+  return __builtin_fmaf (__x, __y, __z);
+}
+
 #pragma GCC push_options
 #pragma GCC target ("+nothing+frintts")
 __extension__ extern __inline float
diff --git a/gcc/testsuite/gcc.target/aarch64/acle/acle_fma.c 
b/gcc/testsuite/gcc.target/aarch64/acle/acle_fma.c
new file mode 100644
index 000000000000..9363a75b593d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/acle/acle_fma.c
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+#include "arm_acle.h"
+
+double test_acle_fma (double x, double y, double z)
+{
+  return __fma (x, y, z);
+}
+
+float test_acle_fmaf (float x, float y, float z)
+{
+  return __fmaf (x, y, z);
+}
+
+/* { dg-final { scan-assembler-times "fmadd\td\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "fmadd\ts\[0-9\]" 1 } } */

Reply via email to