18 #include <sys/random.h>
27 #include <immintrin.h>
49 constexpr
unsigned flag_RDRAND = (1 << 30);
55 return ((ex[2] & flag_RDRAND) == flag_RDRAND);
57 unsigned eax, ebx, ecx, edx;
59 __get_cpuid(1, &eax, &ebx, &ecx, &edx);
61 return ((ecx & flag_RDRAND) == flag_RDRAND);
83 #if ENABLE_RNDFILE && !ENABLE_DEVRAND
87 static RandFile& getInstance()
89 static RandFile instance;
98 fSize = fread(&v,
sizeof(
unsigned), 1, dataFile);
100 _readNextRandDataFile();
108 RandFile() { _readNextRandDataFile(); }
118 void _readNextRandDataFile();
121 RandFile(RandFile
const&) =
delete;
122 void operator=(RandFile
const&) =
delete;
130 #if ENABLE_RDRAND || ENABLE_DEVRAND
131 constexpr
int max_rdrand_tries = 10;
132 for (
int i = 0; i < max_rdrand_tries; ++i) {
134 if (
sizeof(
unsigned) == getrandom(
reinterpret_cast<char*
>(pv),
sizeof(
unsigned), 0))
136 if (_rdrand32_step(pv))
147 #if ENABLE_RNDFILE && !ENABLE_DEVRAND
148 unsigned NextRaw() {
return RandFile::getInstance().NextRaw(); }
154 throw std::runtime_error(
"Random number generator failed up to retry limit.");
163 constexpr
double inc = 1.0 / (double)(1ULL << 32U);
Definition: rdrandwrapper.hpp:36
bool SupportsRDRAND()
Definition: rdrandwrapper.hpp:80
static bool CheckHardwareRDRANDSupport()
Definition: rdrandwrapper.hpp:46
RandSupportSingleton()
Definition: rdrandwrapper.hpp:40
RandSupportSingleton(RandSupportSingleton const &)=delete
bool isSupported
Definition: rdrandwrapper.hpp:38
static RandSupportSingleton & Instance()
Get a pointer to the Instance of the singleton. (The instance will be instantiated,...
Definition: rdrandwrapper.hpp:72
void operator=(RandSupportSingleton const &)=delete
Definition: rdrandwrapper.hpp:126
bool getRdRand(unsigned *pv)
Definition: rdrandwrapper.hpp:128
unsigned NextRaw()
Definition: rdrandwrapper.hpp:150
real1_f Next()
Definition: rdrandwrapper.hpp:161
bool SupportsRDRAND()
Definition: rdrandwrapper.hpp:145
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
float real1_f
Definition: qrack_types.hpp:95