]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Fix status return logic in RNG intrinsics
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Wed, 17 Mar 2021 18:21:05 +0000 (18:21 +0000)
committerKyrylo Tkachov <kyrylo.tkachov@arm.com>
Wed, 17 Mar 2021 18:21:05 +0000 (18:21 +0000)
There is a bug with the RNG intrinsics in their return code. The definition says:

"Stores a 64-bit random number into the object pointed to by the argument and returns zero.
If the implementation could not generate a random number within a reasonable period of time
the object pointed to by the input is set to zero and a non-zero value is returned."

This means we should be testing whether to return non-zero with:
CSET W0, EQ
rather than NE.

This patch fixes that.

gcc/ChangeLog:

* config/aarch64/aarch64-builtins.c (aarch64_expand_rng_builtin): Use EQ
to compare against CC_REG rather than NE.

gcc/testsuite/ChangeLog:

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

gcc/config/aarch64/aarch64-builtins.c
gcc/testsuite/gcc.target/aarch64/acle/rng_2.c [new file with mode: 0644]

index 25ab866ccd4e5ab15efe60574062423f7f0c41d1..acdea2a0601c1208afe7b3c653489cf1e0634526 100644 (file)
@@ -1954,7 +1954,7 @@ aarch64_expand_rng_builtin (tree exp, rtx target, int fcode, int ignore)
     return target;
 
   rtx cc_reg = gen_rtx_REG (CC_Zmode, CC_REGNUM);
-  rtx cmp_rtx = gen_rtx_fmt_ee (NE, SImode, cc_reg, const0_rtx);
+  rtx cmp_rtx = gen_rtx_fmt_ee (EQ, SImode, cc_reg, const0_rtx);
   emit_insn (gen_aarch64_cstoresi (target, cmp_rtx, cc_reg));
   return target;
 }
diff --git a/gcc/testsuite/gcc.target/aarch64/acle/rng_2.c b/gcc/testsuite/gcc.target/aarch64/acle/rng_2.c
new file mode 100644 (file)
index 0000000..206136c
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=armv8.5-a+rng" } */
+
+#include <arm_acle.h>
+
+int test_rndr (uint64_t *addr)
+{
+  return  __rndr (addr);
+}
+
+/* { dg-final { scan-assembler-times {cset\t...?, eq} 1 } } */
+