]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
AArch64: Use standard names for SVE saturating arithmetic
authorTamar Christina <tamar.christina@arm.com>
Fri, 17 Jan 2025 17:44:23 +0000 (17:44 +0000)
committerTamar Christina <tamar.christina@arm.com>
Fri, 17 Jan 2025 17:46:52 +0000 (17:46 +0000)
Rename the existing SVE unpredicated saturating arithmetic instructions
to use standard names which are used by IFN_SAT_ADD and IFN_SAT_SUB.

gcc/ChangeLog:

* config/aarch64/aarch64-sve.md: Rename insns

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/sve/saturating_arithmetic.inc:
Template file for auto-vectorizer tests.
* gcc.target/aarch64/sve/saturating_arithmetic_1.c:
Instantiate 8-bit vector tests.
* gcc.target/aarch64/sve/saturating_arithmetic_2.c:
Instantiate 16-bit vector tests.
* gcc.target/aarch64/sve/saturating_arithmetic_3.c:
Instantiate 32-bit vector tests.
* gcc.target/aarch64/sve/saturating_arithmetic_4.c:
Instantiate 64-bit vector tests.

gcc/config/aarch64/aarch64-sve.md
gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic.inc [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_4.c [new file with mode: 0644]

index ba4b4d904c7744c0a2114baca69e0b555bb5a965..e975286a01904bec0b283b7ba4afde6f0fd60bf1 100644 (file)
 ;; -------------------------------------------------------------------------
 
 ;; Unpredicated saturating signed addition and subtraction.
-(define_insn "@aarch64_sve_<optab><mode>"
+(define_insn "<su_optab>s<addsub><mode>3"
   [(set (match_operand:SVE_FULL_I 0 "register_operand")
        (SBINQOPS:SVE_FULL_I
          (match_operand:SVE_FULL_I 1 "register_operand")
 )
 
 ;; Unpredicated saturating unsigned addition and subtraction.
-(define_insn "@aarch64_sve_<optab><mode>"
+(define_insn "<su_optab>s<addsub><mode>3"
   [(set (match_operand:SVE_FULL_I 0 "register_operand")
        (UBINQOPS:SVE_FULL_I
          (match_operand:SVE_FULL_I 1 "register_operand")
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic.inc b/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic.inc
new file mode 100644 (file)
index 0000000..0b3ebbc
--- /dev/null
@@ -0,0 +1,68 @@
+/* Template file for vector saturating arithmetic validation.
+
+   This file defines saturating addition and subtraction functions for a given
+   scalar type, testing the auto-vectorization of these two operators. This
+   type, along with the corresponding minimum and maximum values for that type,
+   must be defined by any test file which includes this template file.  */
+
+#ifndef SAT_ARIT_AUTOVEC_INC
+#define SAT_ARIT_AUTOVEC_INC
+
+#include <limits.h>
+#include <arm_neon.h>
+
+#ifndef UT
+#define UT uint32_t
+#define UMAX UINT_MAX
+#define UMIN 0
+#endif
+
+void uaddq (UT *out, UT *a, UT *b, int n)
+{
+  for (int i = 0; i < n; i++)
+    {
+      UT sum = a[i] + b[i];
+      out[i] = sum < a[i] ? UMAX : sum;
+    }
+}
+
+void uaddq2 (UT *out, UT *a, UT *b, int n)
+{
+  for (int i = 0; i < n; i++)
+    {
+      UT sum;
+      if (!__builtin_add_overflow(a[i], b[i], &sum))
+       out[i] = sum;
+      else
+       out[i] = UMAX;
+    }
+}
+
+void uaddq_imm (UT *out, UT *a, int n)
+{
+  for (int i = 0; i < n; i++)
+    {
+      UT sum = a[i] + 50;
+      out[i] = sum < a[i] ? UMAX : sum;
+    }
+}
+
+void usubq (UT *out, UT *a, UT *b, int n)
+{
+  for (int i = 0; i < n; i++)
+    {
+      UT sum = a[i] - b[i];
+      out[i] = sum > a[i] ? UMIN : sum;
+    }
+}
+
+void usubq_imm (UT *out, UT *a, int n)
+{
+  for (int i = 0; i < n; i++)
+    {
+      UT sum = a[i] - 50;
+      out[i] = sum > a[i] ? UMIN : sum;
+    }
+}
+
+#endif
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_1.c b/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_1.c
new file mode 100644 (file)
index 0000000..6936e9a
--- /dev/null
@@ -0,0 +1,60 @@
+/* { dg-do compile { target { aarch64*-*-* } } } */
+/* { dg-options "-O2 --save-temps -ftree-vectorize" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** uaddq:
+** ...
+**     ld1b\tz([0-9]+)\.b, .*
+**     ld1b\tz([0-9]+)\.b, .*
+**     uqadd\tz\2.b, z\1\.b, z\2\.b
+** ...
+**     ldr\tb([0-9]+), .*
+**     ldr\tb([0-9]+), .*
+**     uqadd\tb\4, b\3, b\4
+** ...
+*/
+/*
+** uaddq2:
+** ...
+**     ld1b\tz([0-9]+)\.b, .*
+**     ld1b\tz([0-9]+)\.b, .*
+**     uqadd\tz\2.b, z\1\.b, z\2\.b
+** ...
+**     ldr\tb([0-9]+), .*
+**     ldr\tb([0-9]+), .*
+**     uqadd\tb\4, b\3, b\4
+** ...
+*/
+/*
+** uaddq_imm:
+** ...
+**     ld1b\tz([0-9]+)\.b, .*
+**     uqadd\tz\1.b, z\1\.b, #50
+** ...
+**     movi\tv([0-9]+)\.8b, 0x32
+** ...
+**     ldr\tb([0-9]+), .*
+**     uqadd\tb\3, b\3, b\2
+** ...
+*/
+/*
+** usubq: { xfail *-*-* }
+** ...
+**     ld1b\tz([0-9]+)\.b, .*
+**     ld1b\tz([0-9]+)\.b, .*
+**     uqsub\tz\2.b, z\1\.b, z\2\.b
+** ...
+**     ldr\tb([0-9]+), .*
+**     ldr\tb([0-9]+), .*
+**     uqsub\tb\4, b\3, b\4
+** ...
+*/
+
+#include <limits.h>
+
+#define UT unsigned char
+#define UMAX UCHAR_MAX
+#define UMIN 0
+
+#include "saturating_arithmetic.inc"
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_2.c b/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_2.c
new file mode 100644 (file)
index 0000000..928bc00
--- /dev/null
@@ -0,0 +1,60 @@
+/* { dg-do compile { target { aarch64*-*-* } } } */
+/* { dg-options "-O2 --save-temps -ftree-vectorize" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** uaddq:
+** ...
+**     ld1h\tz([0-9]+)\.h, .*
+**     ld1h\tz([0-9]+)\.h, .*
+**     uqadd\tz\2.h, z\1\.h, z\2\.h
+** ...
+**     ldr\th([0-9]+), .*
+**     ldr\th([0-9]+), .*
+**     uqadd\th\4, h\3, h\4
+** ...
+*/
+/*
+** uaddq2:
+** ...
+**     ld1h\tz([0-9]+)\.h, .*
+**     ld1h\tz([0-9]+)\.h, .*
+**     uqadd\tz\2.h, z\1\.h, z\2\.h
+** ...
+**     ldr\th([0-9]+), .*
+**     ldr\th([0-9]+), .*
+**     uqadd\th\4, h\3, h\4
+** ...
+*/
+/*
+** uaddq_imm:
+** ...
+**     ld1h\tz([0-9]+)\.h, .*
+**     uqadd\tz\1.h, z\1\.h, #50
+** ...
+**     movi\tv([0-9]+)\.4h, 0x32
+** ...
+**     ldr\th([0-9]+), .*
+**     uqadd\th\3, h\3, h\2
+** ...
+*/
+/*
+** usubq: { xfail *-*-* }
+** ...
+**     ld1h\tz([0-9]+)\.h, .*
+**     ld1h\tz([0-9]+)\.h, .*
+**     usubq\tz\2.h, z\1\.h, z\2\.h
+** ...
+**     ldr\th([0-9]+), .*
+**     ldr\th([0-9]+), .*
+**     usubq\th\4, h\3, h\4
+** ...
+*/
+
+#include <limits.h>
+
+#define UT unsigned short
+#define UMAX USHRT_MAX
+#define UMIN 0
+
+#include "saturating_arithmetic.inc"
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_3.c b/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_3.c
new file mode 100644 (file)
index 0000000..14e2de5
--- /dev/null
@@ -0,0 +1,62 @@
+/* { dg-do compile { target { aarch64*-*-* } } } */
+/* { dg-options "-O2 --save-temps -ftree-vectorize" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** uaddq:
+** ...
+**     ld1w\tz([0-9]+)\.s, .*
+**     ld1w\tz([0-9]+)\.s, .*
+**     uqadd\tz\2.s, z\1\.s, z\2\.s
+** ...
+**     ldr\tw([0-9]+), .*
+**     ldr\tw([0-9]+), .*
+**     adds\tw\3, w\3, w\4
+**     csinv\tw\3, w\3, wzr, cc
+** ...
+*/
+/*
+** uaddq2:
+** ...
+**     ld1w\tz([0-9]+)\.s, .*
+**     ld1w\tz([0-9]+)\.s, .*
+**     uqadd\tz\2.s, z\1\.s, z\2\.s
+** ...
+**     ldr\tw([0-9]+), .*
+**     ldr\tw([0-9]+), .*
+**     adds\tw\3, w\3, w\4
+**     csinv\tw\3, w\3, wzr, cc
+** ...
+*/
+/*
+** uaddq_imm:
+** ...
+**     ld1w\tz([0-9]+)\.s, .*
+**     uqadd\tz\1.s, z\1\.s, #50
+** ...
+**     ldr\tw([0-9]+), .*
+**     adds\tw\2, w\2, #50
+**     csinv\tw\2, w\2, wzr, cc
+** ...
+*/
+/*
+** usubq: { xfail *-*-* }
+** ...
+**     ld1w\tz([0-9]+)\.s, .*
+**     ld1w\tz([0-9]+)\.s, .*
+**     uqsub\tz\2.s, z\1\.s, z\2\.s
+** ...
+**     ldr\tw([0-9]+), .*
+**     ldr\tw([0-9]+), .*
+**     subs\tw\3, w\3, w\4
+**     csel\tw\3, w\3, wzr, cs
+** ...
+*/
+
+#include <limits.h>
+
+#define UT unsigned int
+#define UMAX UINT_MAX
+#define UMIN 0
+
+#include "saturating_arithmetic.inc"
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_4.c b/gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic_4.c
new file mode 100644 (file)
index 0000000..05a5786
--- /dev/null
@@ -0,0 +1,62 @@
+/* { dg-do compile { target { aarch64*-*-* } } } */
+/* { dg-options "-O2 --save-temps -ftree-vectorize" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+** uaddq:
+** ...
+**     ld1d\tz([0-9]+)\.d, .*
+**     ld1d\tz([0-9]+)\.d, .*
+**     uqadd\tz\2.d, z\1\.d, z\2\.d
+** ...
+**     ldr\tx([0-9]+), .*
+**     ldr\tx([0-9]+), .*
+**     adds\tx\3, x\3, x\4
+**     csinv\tx\3, x\3, xzr, cc
+** ...
+*/
+/*
+** uaddq2:
+** ...
+**     ld1d\tz([0-9]+)\.d, .*
+**     ld1d\tz([0-9]+)\.d, .*
+**     uqadd\tz\2.d, z\1\.d, z\2\.d
+** ...
+**     ldr\tx([0-9]+), .*
+**     ldr\tx([0-9]+), .*
+**     adds\tx\3, x\3, x\4
+**     csinv\tx\3, x\3, xzr, cc
+** ...
+*/
+/*
+** uaddq_imm:
+** ...
+**     ld1d\tz([0-9]+)\.d, .*
+**     uqadd\tz\1.d, z\1\.d, #50
+** ...
+**     ldr\tx([0-9]+), .*
+**     adds\tx\2, x\2, #50
+**     csinv\tx\2, x\2, xzr, cc
+** ...
+*/
+/*
+** usubq: { xfail *-*-* }
+** ...
+**     ld1d\tz([0-9]+)\.d, .*
+**     ld1d\tz([0-9]+)\.d, .*
+**     uqsub\tz\2.d, z\1\.d, z\2\.d
+** ...
+**     ldr\tx([0-9]+), .*
+**     ldr\tx([0-9]+), .*
+**     subs\tx\3, x\3, x\4
+**     csel\tx\3, x\3, xzr, cs
+** ...
+*/
+
+#include <limits.h>
+
+#define UT unsigned long
+#define UMAX ULONG_MAX
+#define UMIN 0
+
+#include "saturating_arithmetic.inc"
\ No newline at end of file