]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Add __builtin_aarch64_chkfeat and __chkfeat tests
authorSzabolcs Nagy <szabolcs.nagy@arm.com>
Thu, 14 Nov 2024 16:15:06 +0000 (16:15 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Thu, 14 Nov 2024 16:15:06 +0000 (16:15 +0000)
gcc/testsuite/ChangeLog:

* gcc.target/aarch64/acle/chkfeat-1.c: New test.
* gcc.target/aarch64/chkfeat-1.c: New test.
* gcc.target/aarch64/chkfeat-2.c: New test.

Co-authored-by: Yury Khrustalev <yury.khrustalev@arm.com>
Co-authored-by: Richard Sandiford <richard.sandiford@arm.com>
gcc/testsuite/gcc.target/aarch64/acle/chkfeat-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/chkfeat-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/chkfeat-2.c [new file with mode: 0644]

diff --git a/gcc/testsuite/gcc.target/aarch64/acle/chkfeat-1.c b/gcc/testsuite/gcc.target/aarch64/acle/chkfeat-1.c
new file mode 100644 (file)
index 0000000..d8393fd
--- /dev/null
@@ -0,0 +1,20 @@
+/* Test the __chkfeat ACLE intrinsic.  */
+/* { dg-do compile } */
+/* { dg-options "-O1" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+#include <arm_acle.h>
+
+/*
+** test_chkfeat:
+** ...
+**     mov     x16, 1
+**     hint    40 // chkfeat x16
+**     eor     x0, x16, 1
+**     ret
+*/
+uint64_t
+test_chkfeat ()
+{
+  return __chkfeat (1);
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/chkfeat-1.c b/gcc/testsuite/gcc.target/aarch64/chkfeat-1.c
new file mode 100644 (file)
index 0000000..2fae81e
--- /dev/null
@@ -0,0 +1,75 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mbranch-protection=none" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+/*
+**foo1:
+**     mov     x16, 1
+**     hint    40 // chkfeat x16
+**     mov     x0, x16
+**     ret
+*/
+unsigned long long
+foo1 (void)
+{
+  return __builtin_aarch64_chkfeat (1);
+}
+
+/*
+**foo2:
+**     mov     x16, 1
+**     movk    x16, 0x5678, lsl 32
+**     movk    x16, 0x1234, lsl 48
+**     hint    40 // chkfeat x16
+**     mov     x0, x16
+**     ret
+*/
+unsigned long long
+foo2 (void)
+{
+  return __builtin_aarch64_chkfeat (0x1234567800000001);
+}
+
+/*
+**foo3:
+**     mov     x16, x0
+**     hint    40 // chkfeat x16
+**     mov     x0, x16
+**     ret
+*/
+unsigned long long
+foo3 (unsigned long long x)
+{
+  return __builtin_aarch64_chkfeat (x);
+}
+
+/*
+**foo4:
+**     ldr     x16, \[x0\]
+**     hint    40 // chkfeat x16
+**     str     x16, \[x0\]
+**     ret
+*/
+void
+foo4 (unsigned long long *p)
+{
+  *p = __builtin_aarch64_chkfeat (*p);
+}
+
+/*
+**foo5:
+**     mov     x16, 1
+**     hint    40 // chkfeat x16
+**     cmp     x16, 0
+**(
+**     csel    w0, w1, w0, eq
+**|
+**     csel    w0, w0, w1, ne
+**)
+**     ret
+*/
+int
+foo5 (int x, int y)
+{
+  return __builtin_aarch64_chkfeat (1) ? x : y;
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/chkfeat-2.c b/gcc/testsuite/gcc.target/aarch64/chkfeat-2.c
new file mode 100644 (file)
index 0000000..f98d709
--- /dev/null
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-final { check-function-bodies "**" "" "" } } */
+
+void bar (void);
+
+/* Extern call may change enabled HW features.  */
+
+/*
+** foo:
+**     ...
+**     mov     x16, 1
+**     ...
+**     hint    40 // chkfeat x16
+**     ...
+**     bl      bar
+**     ...
+**     mov     x16, 1
+**     ...
+**     hint    40 // chkfeat x16
+**     ...
+*/
+unsigned long long
+foo (void)
+{
+  unsigned long long a = __builtin_aarch64_chkfeat (1);
+  bar ();
+  unsigned long long b = __builtin_aarch64_chkfeat (1);
+  return a + b;
+}