2

According to Microsoft's x64 (amd64) Intrinsics List, Microsoft offers an intrinsic for RDRAND:

  • _rdrand16_step
  • _rdrand32_step
  • _rdrand64_step

However, the page does not discuss detecting the availability of the intrinsic. There is a footnote with [2], but it says its only available for Intel CPUs.

I have two questions. First, how can I detect the availability of the intrinsics. That is, what preprocessor macro should I use to guard the call to say _rdrand64_step.

Second, how can I access RDRAND under AMD CPUs? According to the AMD manual, AMD offers it too.

(More humorously, Microsoft titles the page amd64 Intrinsic List. Why do they call it AMD64 Intrinsic List when they don't include AMD???)


For AMD and the RDRAND instruction, reference AMD64 Architecture Programmer’s Manual Volume 3: General-Purpose and System Instructions, page 278.

phuclv
  • 37,963
  • 15
  • 156
  • 475
jww
  • 97,681
  • 90
  • 411
  • 885
  • I think the idea of that footnote is that af of documenting the intrinsic ( – SEJPM Oct 19 '15 at 12:31
  • @SEJPM - The footnote applies to many instructions, and not just RDRAND. Intel aggressively moves against AMD. Intel's compilers and tools produce/utilize slower code when they discover an AMD CPU. [The FTC investigated Intel for it, and Intel settled the case](http://www.google.com/search?q=intel+amd+ftc). Obviously you are free to do what you want. But I would not trust Microsoft or Intel in this situation since Microsoft clearly states the intrinsics are for Intel CPUs only, and past history between Intel and AMD. – jww Oct 19 '15 at 18:10

2 Answers2

3

First, how can I detect the availability of the intrinsics. That is, what preprocessor macro should I use to guard the call to say _rdrand64_step.

Here are the compiler versions needed for RDRAND intrinsics:

  • Microsoft added RDRAND in August 2012, VS2012. Test for _MSC_VER >= 1700.
  • GCC added RDRAND in December 2010, GCC 4.6.
  • Clang added RDRAND in July 2012, Clang 3.2.
  • Intel added RDRAND in September 2011, ICC 12.1.

Second, how can I access RDRAND under AMD CPUs. According to the AMD manual, AMD offers it too.

AMD CPUs that provide the RDRAND instruction appear to be forth coming. That is, there are currently no CPUs shipping with the feature.

The Microsoft docs clearly state the intrinsics are for Intel CPUs only. To ensure AMD support given the anti-competitive history between Intel and AMD, the ASM should be crafted by hand and assembled with MASM/ML and MASM64/ML64.

jww
  • 97,681
  • 90
  • 411
  • 885
1

you can check the version of MS compiler using:

  1. MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015) Detailed

  2. I am not sure how to use it with AMD architecture. Will let you know if I get some solution

  3. You can get the answer why MS documentation calls it amd64 in this post.

Community
  • 1
  • 1
  • If I am not mistaken, 1900 is the `cl.exe` version (`_MSC_VER`) shipped with Visual Studio 2015. I believe AES-NI, which was introduced around the same time, is available on earlier compilers. – jww Oct 12 '15 at 07:16
  • @jww, you need 1700 (=VS2012) as `_MSC_VER` for rdrand – SEJPM Oct 19 '15 at 12:29