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

Side by Side Diff: src/IceRNG.h

Issue 1216963007: Doxygenize the documentation comments (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Rebase to master Created 5 years, 5 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 | « src/IceOperand.cpp ('k') | src/IceRNG.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 /// \file
11 // 11 /// This file declares a random number generator.
12 ///
12 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
13 14
14 #ifndef SUBZERO_SRC_ICERNG_H 15 #ifndef SUBZERO_SRC_ICERNG_H
15 #define SUBZERO_SRC_ICERNG_H 16 #define SUBZERO_SRC_ICERNG_H
16 17
17 #include "llvm/ADT/StringRef.h" 18 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Compiler.h" 19 #include "llvm/Support/Compiler.h"
19 #include <cstdint> 20 #include <cstdint>
20 21
21 namespace Ice { 22 namespace Ice {
22 23
23 class RandomNumberGenerator { 24 class RandomNumberGenerator {
24 RandomNumberGenerator() = delete; 25 RandomNumberGenerator() = delete;
25 RandomNumberGenerator(const RandomNumberGenerator &) = delete; 26 RandomNumberGenerator(const RandomNumberGenerator &) = delete;
26 RandomNumberGenerator &operator=(const RandomNumberGenerator &) = delete; 27 RandomNumberGenerator &operator=(const RandomNumberGenerator &) = delete;
27 28
28 public: 29 public:
29 explicit RandomNumberGenerator(uint64_t Seed, llvm::StringRef Salt = ""); 30 explicit RandomNumberGenerator(uint64_t Seed, llvm::StringRef Salt = "");
30 uint64_t next(uint64_t Max); 31 uint64_t next(uint64_t Max);
31 32
32 private: 33 private:
33 uint64_t State; 34 uint64_t State;
34 }; 35 };
35 36
36 // This class adds additional random number generator utilities. The 37 /// This class adds additional random number generator utilities. The
37 // reason for the wrapper class is that we want to keep the 38 /// reason for the wrapper class is that we want to keep the
38 // RandomNumberGenerator interface identical to LLVM's. 39 /// RandomNumberGenerator interface identical to LLVM's.
39 class RandomNumberGeneratorWrapper { 40 class RandomNumberGeneratorWrapper {
40 RandomNumberGeneratorWrapper() = delete; 41 RandomNumberGeneratorWrapper() = delete;
41 RandomNumberGeneratorWrapper(const RandomNumberGeneratorWrapper &) = delete; 42 RandomNumberGeneratorWrapper(const RandomNumberGeneratorWrapper &) = delete;
42 RandomNumberGeneratorWrapper & 43 RandomNumberGeneratorWrapper &
43 operator=(const RandomNumberGeneratorWrapper &) = delete; 44 operator=(const RandomNumberGeneratorWrapper &) = delete;
44 45
45 public: 46 public:
46 uint64_t operator()(uint64_t Max) { return RNG.next(Max); } 47 uint64_t operator()(uint64_t Max) { return RNG.next(Max); }
47 bool getTrueWithProbability(float Probability); 48 bool getTrueWithProbability(float Probability);
48 explicit RandomNumberGeneratorWrapper(RandomNumberGenerator &RNG) 49 explicit RandomNumberGeneratorWrapper(RandomNumberGenerator &RNG)
49 : RNG(RNG) {} 50 : RNG(RNG) {}
50 51
51 private: 52 private:
52 RandomNumberGenerator &RNG; 53 RandomNumberGenerator &RNG;
53 }; 54 };
54 55
55 // RandomShuffle is an implementation of std::random_shuffle() that 56 /// RandomShuffle is an implementation of std::random_shuffle() that
56 // doesn't change across stdlib implementations. Adapted from a 57 /// doesn't change across stdlib implementations. Adapted from a
57 // sample implementation at cppreference.com. 58 /// sample implementation at cppreference.com.
58 template <class RandomIt, class RandomFunc> 59 template <class RandomIt, class RandomFunc>
59 void RandomShuffle(RandomIt First, RandomIt Last, RandomFunc &&RNG) { 60 void RandomShuffle(RandomIt First, RandomIt Last, RandomFunc &&RNG) {
60 for (auto i = Last - First - 1; i > 0; --i) 61 for (auto i = Last - First - 1; i > 0; --i)
61 std::swap(First[i], First[RNG(i + 1)]); 62 std::swap(First[i], First[RNG(i + 1)]);
62 } 63 }
63 64
64 } // end of namespace Ice 65 } // end of namespace Ice
65 66
66 #endif // SUBZERO_SRC_ICERNG_H 67 #endif // SUBZERO_SRC_ICERNG_H
OLDNEW
« no previous file with comments | « src/IceOperand.cpp ('k') | src/IceRNG.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698