I have a x86 RDRAND implementation like below. I have a similar implementation for RDSEED.
inline void RDRAND32(void* output)
{
#if defined(HAVE_GCC_RDRAND_ASM)
__asm__
(
"1:\n"
".byte 0x0f, 0xc7, 0xf0;\n"
"jnc 1b;\n"
: "=a" (*(uint32_t*)output)
: : "cc"
);
#endif
}
The byte codes emitted are rdrand eax
and a capable processor happily consumes them. Sun Studio 12.1 and above supports GCC inline assembly and also consumes them.
The Sun docs say I need -xarch=avx_i
for the ISA that provides RDRAND (and -xarch=avx2_i
for RDSEED). Also see Sun Studio 12.6 | -xarch Flags for x86.
Do I still need to add -xarch=avx_i
to my linker flags for RDRAND
in this use case?
In case it matters we guard CPU features at runtime and use a Mapfile to lower the ISA (because runtime paths are guarded):
$ cat cryptopp.mapfile
# Solaris mapfile to override hardware caps to avoid kills
hwcap_1 = SSE SSE2 OVERRIDE;
No, you don't need to. The compiler does not process instructions inside __asm
statement. And the assembler will detect the instructions you used and mark the .o with the appropriate HWCAP. You don't have to pass anything to the compiler explicitly.
The only case the compiler will require -xarch=avx_i
from you is if you are using rdrand intrinsics as in this case the compiler is aware that it is about to generate the instructions for avx_i
and has to check if the currently selected architecture allows it.