Subzero: Use a "deterministic" random shuffle for register allocation. To make this work, Subzero provides its own RandomShuffle() as a replacement for std::random_shuffle(), and the Subzero implementation doesn't depend on the stdlib implementation. BUG= https://code.google.com/p/nativeclient/issues/detail?id=4129 R=jvoung@chromium.org Review URL: https://codereview.chromium.org/1072913002
diff --git a/src/IceRNG.h b/src/IceRNG.h index bf01e41..a2d8e96 100644 --- a/src/IceRNG.h +++ b/src/IceRNG.h
@@ -53,6 +53,15 @@ 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