Add Hygon x86 RNG instructions to std::random_device
std::random_device now supports Hygon CPUs via RDRAND/RDSEED instructions.
Libstdc++‘s std::random_device has been updated to recognize and utilize the Hygon x86 hardware random number generator (RNG) instructions, RDRAND and RDSEED. This brings Hygon C86 platforms in line with Intel and AMD, allowing them to use hardware-based randomness instead of falling back to a software RNG. The change involves adding the Hygon vendor signature to the allowlists for these instructions, with a default preference for RDRAND on Hygon for better throughput.
In Details
This commit extends std::random_device's hardware RNG support to Hygon C86 processors by adding signature_HYGON_ebx to the vendor allowlists for RDRAND and RDSEED in random_device::_M_init. Hygon CPUs report the vendor string 'HygonGenuine' (CPUID leaf 0 EBX). For Hygon, RDRAND is now the preferred default source for throughput, while RDSEED remains available for higher entropy needs or via explicit tokens, mirroring the behavior of Intel and AMD defaults, respectively.
- std::random_device
- A C++ class that produces non-deterministic random numbers, typically using a hardware entropy source if available.
- RDRAND
- An x86 instruction that generates a pseudo-random number using a hardware-based random number generator.
- RDSEED
- An x86 instruction that generates a high-entropy random seed value using a hardware-based random number generator.
- libstdc++
- The standard C++ library implementation used by GCC.
- Hygon C86
- A specific line of x86-compatible CPUs manufactured by Hygon.
- CPUID
- A processor instruction that returns information about the CPU, such as its vendor, model, and supported features.
- entropy
- In cryptography and random number generation, entropy refers to the measure of randomness or unpredictability in a sequence of numbers.