How to use the internal properties of RDRAND?

I was looking at HJ Lu PATCH: update x86 rdrand intrinsics . I can not say if I should use _rdrand_u64 , _rdrand64_step , or if there are other functions. It seems that test cases have not been written for them.

Also, there seems to be a lack of man pages (from Ubuntu 14, GCC 4.8.4):

 $ man -k rdrand rdrand: nothing appropriate. 

How to use the built-in RDRAND functions to generate, say, a block of 32 bytes?


A related question is RDRAND and RDSEED integrated GCC and Intel C ++ . But that does not tell me how to use them, or how to generate a block.

+2
gcc rdrand intrinsics
source share
1 answer

If you look at <immintrin.h> (mine is located in `/usr/lib/gcc/x86_64-linux-gnu/4.9/include/ ', Ubuntu 15.04 64bit), there are compatible ones (with MSVC, Intel CC functions) that transmit data back to GCC built-in modules

 extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) _rdrand64_step (unsigned long long *__P) { return __builtin_ia32_rdrand64_step (__P); } 

for a 64-bit parameter and two others for 16-bit and 32-bit parameters

 _rdrand16_step (unsigned short *__P) _rdrand32_step (unsigned int *__P) 

You must use them to make your code compatible with MSVC, Intel CC and other compilers.

_rdrand64_step will populate the 64-bit parameter passed by the pointer, with random bits and a return code. Same for 32-bit and 16-bit versions

UPDATE

"These built-in functions generate random numbers of 16/32/64 bit random integers. The generated random value is written to the given memory location and the success status is returned:" 1 "if the hardware returned a valid random value, and '0' otherwise.

https://software.intel.com/en-us/node/523864

+2
source share

All Articles