mini-llvm 0.1.0
Loading...
Searching...
No Matches
PCG32.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <cstdint>
6#include <limits>
7
8namespace mini_llvm {
9
10class PCG32 {
11public:
12 using result_type = uint32_t;
13
14 explicit PCG32(uint64_t seed, uint64_t seq = UINT64_C(0)) noexcept {
15 state_ = UINT64_C(0);
16 inc_ = (seq << 1) | UINT64_C(1);
17 (*this)();
18 state_ += seed;
19 (*this)();
20 }
21
22 uint32_t operator()() noexcept {
23 uint64_t oldState = state_;
24 state_ = oldState * UINT64_C(6364136223846793005) + inc_;
25 uint32_t shifted = static_cast<uint32_t>(((oldState >> 18) ^ oldState) >> 27);
26 uint32_t rot = oldState >> 59;
27 return (shifted >> rot) | (shifted << ((-rot) & 31));
28 }
29
30 static constexpr uint32_t min() noexcept {
31 return UINT32_C(0);
32 }
33
34 static constexpr uint32_t max() noexcept {
35 return std::numeric_limits<uint32_t>::max();
36 }
37
38private:
39 uint64_t state_;
40 uint64_t inc_;
41};
42
43} // namespace mini_llvm
static constexpr uint32_t max() noexcept
Definition PCG32.h:34
uint32_t result_type
Definition PCG32.h:12
static constexpr uint32_t min() noexcept
Definition PCG32.h:30
uint32_t operator()() noexcept
Definition PCG32.h:22
PCG32(uint64_t seed, uint64_t seq=UINT64_C(0)) noexcept
Definition PCG32.h:14
Definition GraphColoringAllocator.h:13