summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qsimd.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-09-27 09:52:15 -0700
committerThiago Macieira <thiago.macieira@intel.com>2024-10-04 10:45:21 -0700
commit6543f50536f3547b43a27b32af59d68f28a60247 (patch)
tree87c89d4eabbdce70dae2af2da8ea946d11f90177 /src/corelib/global/qsimd.cpp
parentf85a17abeb1e9464492eb57cbb772683d6c8093d (diff)
Remove dead code in checkRdrndWorks() if __RDRND__ is defined
The only place where we call qRandomCpu() in qrandom.cpp is guarded by a check using qCpuHasFeature(): if (qHasHwrng() && (uint(qt_randomdevice_control.loadAcquire()) & SkipHWRNG) == 0) filled += qRandomCpu(buffer, count); static inline bool qHasHwrng() { return qCpuHasFeature(RDRND); } Since qCpuHasFeature() also checks if __RDRND__ was defined, we ignore the result of checkRdrndWorks(). Users of CPUs without RNG must compile with an -march= flag that doesn't enable it or must pass -mno-rdrnd to keep the runtime detection code. Task-number: QTBUG-69423 Task-number: QTBUG-129193 Pick-to: 6.8 Change-Id: Ib7819f80041fe330d033fffda7e7c160141d7dd8 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/corelib/global/qsimd.cpp')
-rw-r--r--src/corelib/global/qsimd.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/corelib/global/qsimd.cpp b/src/corelib/global/qsimd.cpp
index b4fff814e6c..6f1e12312f9 100644
--- a/src/corelib/global/qsimd.cpp
+++ b/src/corelib/global/qsimd.cpp
@@ -747,6 +747,12 @@ static bool checkRdrndWorks() noexcept
constexpr qsizetype TestBufferSize = 4;
unsigned testBuffer[TestBufferSize] = {};
+ // But if the RDRND feature was statically enabled by the compiler, we
+ // assume that the RNG works. That's because the calls to qRandomCpu() will
+ // be guarded by qCpuHasFeature(RDRND) and that will be a constant true.
+ if (_compilerCpuFeatures & CpuFeatureRDRND)
+ return true;
+
unsigned *end = qt_random_rdrnd(testBuffer, testBuffer + TestBufferSize);
if (end < testBuffer + 3) {
// Random generation didn't produce enough data for us to make a