The ISA-3.0 instruction set includes DARN ("deliver a random number") which can be used similar to the existing support for RDRAND and RDSEED. libstdc++-v3/ChangeLog: * src/c++11/random.cc (USE_DARN): Define. (__ppc_darn): New function to use POWER9 DARN instruction. (Which): Add 'darn' enumerator. (which_source): Check for __ppc_darn. (random_device::_M_init): Support "darn" and "hw" tokens. (random_device::_M_getentropy): Add darn to switch. * testsuite/26_numerics/random/random_device/cons/token.cc: Check "darn" token. * testsuite/26_numerics/random/random_device/entropy.cc: Likewise. Tested powerpc64le-linux (power8 and power9) and x86_64-linux. The new "darn" (power-specific) and "hw" (x86 and power) strings should be documented, but I'll do that if this gets committed. Most of this patch is just "more of the same", similar to the existing code for RDRAND and RDSEED on x86, but the parts of the patch I'd like more eyes on are: +#elif defined __powerpc__ && defined __BUILTIN_CPU_SUPPORTS__ +# define USE_DARN 1 #endif #include and: @@ -135,6 +137,15 @@ namespace std _GLIBCXX_VISIBILITY(default) #endif #endif +#ifdef USE_DARN + unsigned int + __attribute__((target("power9"))) + __ppc_darn(void*) + { + return __builtin_darn_32(); + } +#endif + and: @@ -346,6 +375,17 @@ namespace std _GLIBCXX_VISIBILITY(default) } #endif // USE_RDRAND +#ifdef USE_DARN + if (which & darn) + { + if (__builtin_cpu_supports("darn")) + { + _M_func = &__ppc_darn; + return; + } + } +#endif // USE_DARN + #ifdef _GLIBCXX_USE_DEV_RANDOM if (which & device_file) {