Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: src/IceRNG.cpp

Issue 1300993002: Use separate random number generator for each randomization pass (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: rebase to master Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceRNG.h ('k') | src/IceRegAlloc.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceRNG.cpp
diff --git a/src/IceRNG.cpp b/src/IceRNG.cpp
index a6b9adf5b93bfb2b867ebc4ce3e84b33ec7a5e07..28efb8ffa14f432ce18d398f725afaa2a6199adb 100644
--- a/src/IceRNG.cpp
+++ b/src/IceRNG.cpp
@@ -31,6 +31,16 @@ constexpr unsigned MAX = 2147483647;
RandomNumberGenerator::RandomNumberGenerator(uint64_t Seed, llvm::StringRef)
: State(Seed) {}
+RandomNumberGenerator::RandomNumberGenerator(
+ uint64_t Seed, RandomizationPassesEnum RandomizationPassID, uint64_t Salt) {
+ constexpr unsigned NumBitsGlobalSeed = CHAR_BIT * sizeof(State);
+ constexpr unsigned NumBitsPassID = 4;
+ constexpr unsigned NumBitsSalt = 12;
+ static_assert(RPE_num < (1 << NumBitsPassID), "NumBitsPassID too small");
+ State = Seed ^ ((uint64_t)RandomizationPassID
+ << (NumBitsGlobalSeed - NumBitsPassID)) ^
+ (Salt << (NumBitsGlobalSeed - NumBitsPassID - NumBitsSalt));
+}
uint64_t RandomNumberGenerator::next(uint64_t Max) {
// Lewis, Goodman, and Miller (1969)
State = (16807 * State) % MAX;
« no previous file with comments | « src/IceRNG.h ('k') | src/IceRegAlloc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698