如何使用RDRAND内部函数? [英] How to use RDRAND intrinsics?

查看:343
本文介绍了如何使用RDRAND内部函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在看HJ Lu的补丁:更新x86 rdrand内在的。我不知道是否应该使用 _rdrand_u64 _rdrand64_step ,或者是否有其他功能。看起来没有为他们编写测试用例。



似乎缺少手册页(来自Ubuntu 14,GCC 4.8.4):

p>

  $ man -k rdrand 
rdrand:没有什么合适的。

如何使用 RDRAND intrinsics生成一个32字节的块?






相关的问题是 RDRAND和RDSEED内部函数GCC和Intel C ++ 。但它并没有告诉我如何使用它们,或者如何生成一个块。

$ c>< immintrin.h> (我在`/usr/lib/gcc/x86_64-linux-gnu/4.9/include/',Ubuntu 15.04 64bit)中,有兼容的MSVC,Intel CC)定义了将数据传递回GCC内置函数的函数

  extern __inline int __attribute __((__ gnu_inline__,__always_inline__, __artificial__))
_rdrand64_step(unsigned long long * __ P)
{
return __builtin_ia32_rdrand64_step(__P);
}

用于64位参数,另外两个用于16位和32位参数

  _rdrand16_step(unsigned short * __ P)
_rdrand32_step(unsigned int * __ P)

您应该使用这些代码以便您的代码与MSVC,Intel CC和其他编译器兼容。



_rdrand64_step 将填充64位参数,通过指针传递,随机位并返回错误代码。同上为32位和16位版本



更新



这些内在函数生成随机数16/32/64位生成的随机值被写入给定的内存位置,并返回成功状态:如果硬件返回了一个有效的随机值,则为'1',否则为'0'。

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


I was looking at H.J. Lu's PATCH: Update x86 rdrand intrinsics. I can't tell if I should be using _rdrand_u64, _rdrand64_step, or if there are other function(s). There does not appear to be test cases written for them.

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

$ man -k rdrand
rdrand: nothing appropriate.

How does one use the RDRAND intrinsics to generate, say, a block of 32 bytes?


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

解决方案

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

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

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

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

You supposed to use those so your code would be compatible with MSVC, Intel CC and other compilers.

_rdrand64_step will fill 64bit parameter, passed by pointer, with random bits and return error code. Ditto for 32bit and 16bit versions

UPDATE

"These intrinsics generate random numbers of 16/32/64 bit wide 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

这篇关于如何使用RDRAND内部函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆