I need to check ECX
for bit 30, which is a CPU feature necessary for RDRAND
. From the RDRAND
Wiki,
If supported, bit 30 of the ECX register is set after calling CPUID standard function 01H.
I don't exactly know what this means. "Standard function 01H
"?
Does this mean EAX=80000001h? I'm not really sure how to proceed.
I think it means that %eax should be 1 when invoking the cpuid function. Hardware guys have strange conventions, so they say
01H
instead of 1 or 0x1.See the intel manual Vol 2. Ch 3. Table 3.8. Initial value of eax is 01H. ECX on return is full of feature information in table 3.10. At the bottom of that table for bit 30, it says a value of 1 means the processor supports RDRAND.
If you have gcc, you can try something like this:
It'll take quite a bit of time to decode everything, but there are defines in <cpuid.h> that can help:
There are a bunch more in the header file. You'll notice that bit 30 of my ecx (7fbee3bf) is set at level 1, so I have the RDRND instruction available.
More information can actually be pulled out by this instruction. There is extended information with eax having the top bit set when invoking cpuid. Also a number of levels have different "leafs" depending on the value of ecx when you invoke cpuid. Somebody who is bored could spend a day or two coding up something to do all of the feature extraction and make it look pretty. Alternatively, one could do a "grep flags /proc/cpuinfo" and get something like this: