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

Unified Diff: src/IceRNG.h

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: 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/IceGlobalContext.cpp ('k') | src/IceRNG.cpp » ('j') | src/IceRegAlloc.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceRNG.h
diff --git a/src/IceRNG.h b/src/IceRNG.h
index 5ddd97f247fedfa551f01bf78cbb4b27e9635244..4eeefa6c25243f291a5c83538012981df8607973 100644
--- a/src/IceRNG.h
+++ b/src/IceRNG.h
@@ -17,6 +17,8 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
+#include "IceDefs.h"
+
#include <cstdint>
namespace Ice {
@@ -28,6 +30,22 @@ class RandomNumberGenerator {
public:
explicit RandomNumberGenerator(uint64_t Seed, llvm::StringRef Salt = "");
+ /// Create a random number generator with: global seed, randomization pass ID
+ /// and a salt uint64_t integer.
+ /// @param Seed should be a global seed.
+ /// @param RandomizationPassID should be one of RandomizationPassesEnum.
+ /// @param Salt should be an additional integer input for generating unique
+ /// RNG.
+ /// The global seed is 64 bits; since it is likely to originate from the
+ /// system time, the lower bits are more "valuable" than the upper bits. As
+ /// such, we merge the randomization pass ID and the salt into the global seed
+ /// by xor'ing them into high bit ranges. We expect the pass ID to fit within
+ /// 4 bits, so it gets shifted by 60 to merge into the upper 4 bits. We expect
+ /// the salt (usually the function sequence number) to fit within 12 bits, so
+ /// it gets shifted by 48 before merging.
+ explicit RandomNumberGenerator(uint64_t Seed,
+ RandomizationPassesEnum RandomizationPassID,
+ uint64_t Salt = 0);
uint64_t next(uint64_t Max);
private:
« no previous file with comments | « src/IceGlobalContext.cpp ('k') | src/IceRNG.cpp » ('j') | src/IceRegAlloc.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698