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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/IceTargetLoweringX8632.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceRNG.h - Random number generator -----------*- C++ -*-===// 1 //===- subzero/src/IceRNG.h - Random number generator -----------*- C++ -*-===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file declares a random number generator. 10 // This file declares a random number generator.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 public: 46 public:
47 uint64_t operator()(uint64_t Max) { return RNG.next(Max); } 47 uint64_t operator()(uint64_t Max) { return RNG.next(Max); }
48 bool getTrueWithProbability(float Probability); 48 bool getTrueWithProbability(float Probability);
49 explicit RandomNumberGeneratorWrapper(RandomNumberGenerator &RNG) 49 explicit RandomNumberGeneratorWrapper(RandomNumberGenerator &RNG)
50 : RNG(RNG) {} 50 : RNG(RNG) {}
51 51
52 private: 52 private:
53 RandomNumberGenerator &RNG; 53 RandomNumberGenerator &RNG;
54 }; 54 };
55 55
56 // RandomShuffle is an implementation of std::random_shuffle() that
57 // doesn't change across stdlib implementations. Adapted from a
58 // sample implementation at cppreference.com.
59 template <class RandomIt, class RandomFunc>
60 void RandomShuffle(RandomIt First, RandomIt Last, RandomFunc &&RNG) {
61 for (auto i = Last - First - 1; i > 0; --i)
62 std::swap(First[i], First[RNG(i + 1)]);
63 }
64
56 } // end of namespace Ice 65 } // end of namespace Ice
57 66
58 #endif // SUBZERO_SRC_ICERNG_H 67 #endif // SUBZERO_SRC_ICERNG_H
OLDNEW
« 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