Patchwork PATCH: PR target/44844: Wrong _rdrand_uXX intrinsic implementation

login
register
mail settings
Submitter H.J. Lu
Date July 6, 2010, 5:46 p.m.
Message ID <20100706174602.GA16462@intel.com>
Download mbox | patch
Permalink /patch/58050/
State New
Headers show

Comments

H.J. Lu - July 6, 2010, 5:46 p.m.
Hi,

This patch adds a loop to rdrand<mode> to check if the carry flag is
valid as specified by RDRAND spec.  Tested on Linux/x86-64.  OK to
install?

Thanks.


H.J.
---
gcc/

2010-07-06  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/44844
	* config/i386/i386.md (rdrand<mode>): Changed to expand to
	retry if the carry flag isn't valid.
	(rdrand<mode>_1): New.

gcc/testsuite/

2010-07-06  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/44844
	* gcc.target/i386/rdrand-1.c: Scan "jnc".
	* gcc.target/i386/rdrand-2.c: Likewise.
	* gcc.target/i386/rdrand-3.c: Likewise.
Uros Bizjak - July 7, 2010, 6:12 a.m.
On Tue, Jul 6, 2010 at 7:46 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:

> This patch adds a loop to rdrand<mode> to check if the carry flag is
> valid as specified by RDRAND spec.  Tested on Linux/x86-64.  OK to
> install?

> gcc/
>
> 2010-07-06  H.J. Lu  <hongjiu.lu@intel.com>
>
>        PR target/44844
>        * config/i386/i386.md (rdrand<mode>): Changed to expand to
>        retry if the carry flag isn't valid.
>        (rdrand<mode>_1): New.
>
> gcc/testsuite/
>
> 2010-07-06  H.J. Lu  <hongjiu.lu@intel.com>
>
>        PR target/44844
>        * gcc.target/i386/rdrand-1.c: Scan "jnc".
>        * gcc.target/i386/rdrand-2.c: Likewise.
>        * gcc.target/i386/rdrand-3.c: Likewise.

OK for mainline.

Thanks,
Uros.

Patch

diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 4170711..12e0579 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -18494,7 +18494,32 @@ 
   [(set_attr "type" "other")
    (set_attr "prefix_extra" "2")])
 
-(define_insn "rdrand<mode>"
+(define_expand "rdrand<mode>"
+  [(set (match_operand:SWI248 0 "register_operand" "=r")
+	(unspec_volatile:SWI248 [(const_int 0)] UNSPECV_RDRAND))]
+  "TARGET_RDRND"
+{
+  rtx retry_label, insn, ccc;
+
+  retry_label = gen_label_rtx ();
+
+  emit_label (retry_label);
+
+  /* Generate rdrand.  */
+  emit_insn (gen_rdrand<mode>_1 (operands[0]));
+
+  /* Retry if the carry flag isn't valid.  */
+  ccc = gen_rtx_REG (CCCmode, FLAGS_REG);
+  ccc = gen_rtx_EQ (VOIDmode, ccc, const0_rtx);
+  ccc = gen_rtx_IF_THEN_ELSE (VOIDmode, ccc, pc_rtx,
+			      gen_rtx_LABEL_REF (VOIDmode, retry_label));
+  insn = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, ccc));
+  JUMP_LABEL (insn) = retry_label;
+
+  DONE;
+})
+
+(define_insn "rdrand<mode>_1"
   [(set (match_operand:SWI248 0 "register_operand" "=r")
 	(unspec_volatile:SWI248 [(const_int 0)] UNSPECV_RDRAND))]
   "TARGET_RDRND"
diff --git a/gcc/testsuite/gcc.target/i386/rdrand-1.c b/gcc/testsuite/gcc.target/i386/rdrand-1.c
index 9af6bc5..4f6b9e1 100644
--- a/gcc/testsuite/gcc.target/i386/rdrand-1.c
+++ b/gcc/testsuite/gcc.target/i386/rdrand-1.c
@@ -1,6 +1,7 @@ 
 /* { dg-do compile } */
 /* { dg-options "-O2 -mrdrnd " } */
 /* { dg-final { scan-assembler "rdrand\[ \t]+(%|)ax" } } */
+/* { dg-final { scan-assembler "jnc\[ \t]+" } } */
 
 #include <immintrin.h>
 
diff --git a/gcc/testsuite/gcc.target/i386/rdrand-2.c b/gcc/testsuite/gcc.target/i386/rdrand-2.c
index f356763..2297383 100644
--- a/gcc/testsuite/gcc.target/i386/rdrand-2.c
+++ b/gcc/testsuite/gcc.target/i386/rdrand-2.c
@@ -1,6 +1,7 @@ 
 /* { dg-do compile } */
 /* { dg-options "-O2 -mrdrnd " } */
 /* { dg-final { scan-assembler "rdrand\[ \t]+(%|)eax" } } */
+/* { dg-final { scan-assembler "jnc\[ \t]+" } } */
 
 #include <immintrin.h>
 
diff --git a/gcc/testsuite/gcc.target/i386/rdrand-3.c b/gcc/testsuite/gcc.target/i386/rdrand-3.c
index b18e2e8..17c7c6f 100644
--- a/gcc/testsuite/gcc.target/i386/rdrand-3.c
+++ b/gcc/testsuite/gcc.target/i386/rdrand-3.c
@@ -2,6 +2,7 @@ 
 /* { dg-require-effective-target lp64 } */
 /* { dg-options "-O2 -mrdrnd " } */
 /* { dg-final { scan-assembler "rdrand\[ \t]+(%|)rax" } } */
+/* { dg-final { scan-assembler "jnc\[ \t]+" } } */
 
 #include <immintrin.h>