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

Unified Diff: src/IceRNG.h

Issue 1072913002: Subzero: Use a "deterministic" random shuffle for register allocation. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 5 years, 8 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 | « no previous file | src/IceTargetLoweringX8632.cpp » ('j') | no next file with comments »
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 bf01e410d559ffaac0a94fa176f6ff91531cd8bb..a2d8e96fd959bf59c0845103169ec7b2ee1f89f0 100644
--- a/src/IceRNG.h
+++ b/src/IceRNG.h
@@ -53,6 +53,15 @@ private:
RandomNumberGenerator &RNG;
};
+// RandomShuffle is an implementation of std::random_shuffle() that
+// doesn't change across stdlib implementations. Adapted from a
+// sample implementation at cppreference.com.
+template <class RandomIt, class RandomFunc>
+void RandomShuffle(RandomIt First, RandomIt Last, RandomFunc &&RNG) {
+ for (auto i = Last - First - 1; i > 0; --i)
+ std::swap(First[i], First[RNG(i + 1)]);
+}
+
} // end of namespace Ice
#endif // SUBZERO_SRC_ICERNG_H
« no previous file with comments | « no previous file | src/IceTargetLoweringX8632.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698