RDRAND instruction spec says:

Loads a hardware generated random value and store it in the destination
register. The size of the random value is determined by the destination
register size and operating mode. The Carry Flag indicates whether a random
value is available at the time the instruction is executed. CF=1 indicates
that the data in the destination is valid. Otherwise CF=0 and the data in
the destination operand will be returned as zeros for the specified width.
All other flags are forced to 0 in either situation. Software must check
the state of CF=1 for determining if a valid random value has been returned,
otherwise it is expected to loop and retry execution of RDRAND.

Gcc implemented:

[...@gnu-6 rdrand-1]$ cat rdrand-2.c
/* { dg-do compile } */
/* { dg-options "-O2 -mrdrnd " } */
/* { dg-final { scan-assembler "rdrand\[ \t]+(%|)eax" } } */

#include <immintrin.h>

unsigned int
read_rdrand32 (void)
{
  return _rdrand_u32 ();
}
[...@gnu-6 rdrand-1]$ cat rdrand-2.s
        .file   "rdrand-2.c"
        .text
        .p2align 4,,15
.globl read_rdrand32
        .type   read_rdrand32, @function
read_rdrand32:
.LFB564:
        .cfi_startproc
        rdrand %eax
        ret
        .cfi_endproc
.LFE564:
        .size   read_rdrand32, .-read_rdrand32
        .ident  "GCC: (GNU) 4.6.0 20100705 (experimental)"
        .section        .note.GNU-stack,"",@progbits
[...@gnu-6 rdrand-1]$ 

There is no loop to check CF=1.


-- 
           Summary: Wrong _rdrand_uXX intrinsic implementation
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hjl dot tools at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44844

Reply via email to