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

Unified Diff: src/IceRNG.cpp

Issue 463563006: Subzero: Randomly insert nops. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Fix insertion strategy Created 6 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/IceTargetLowering.h » ('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 6a9f51552e475d7d6b974b8de3c33d69f18588f6..b874d8392bdfd43c83ddbb8f4c09d4bbb1065918 100644
--- a/src/IceRNG.cpp
+++ b/src/IceRNG.cpp
@@ -26,6 +26,8 @@ cl::opt<unsigned long long>
RandomSeed("rng-seed", cl::desc("Seed the random number generator"),
cl::init(time(0)));
+const unsigned MAX = 2147483647;
+
} // end of anonymous namespace
// TODO(wala,stichnot): Switch to RNG implementation from LLVM or C++11.
@@ -39,8 +41,12 @@ RandomNumberGenerator::RandomNumberGenerator(llvm::StringRef)
uint64_t RandomNumberGenerator::next(uint64_t Max) {
// Lewis, Goodman, and Miller (1969)
- State = (16807 * State) % 2147483647;
+ State = (16807 * State) % MAX;
return State % Max;
}
+bool RandomNumberGeneratorWrapper::getTrueWithProbability(float Probability) {
+ return RNG.next(MAX) < Probability * MAX;
+}
+
} // end of namespace Ice
« no previous file with comments | « src/IceRNG.h ('k') | src/IceTargetLowering.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698