mini-llvm
0.1.0
Toggle main menu visibility
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
8
namespace
mini_llvm
{
9
10
class
PCG32
{
11
public
:
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
38
private
:
39
uint64_t state_;
40
uint64_t inc_;
41
};
42
43
}
// namespace mini_llvm
mini_llvm::PCG32::max
static constexpr uint32_t max() noexcept
Definition
PCG32.h:34
mini_llvm::PCG32::result_type
uint32_t result_type
Definition
PCG32.h:12
mini_llvm::PCG32::min
static constexpr uint32_t min() noexcept
Definition
PCG32.h:30
mini_llvm::PCG32::operator()
uint32_t operator()() noexcept
Definition
PCG32.h:22
mini_llvm::PCG32::PCG32
PCG32(uint64_t seed, uint64_t seq=UINT64_C(0)) noexcept
Definition
PCG32.h:14
mini_llvm
Definition
GraphColoringAllocator.h:13
include
mini-llvm
utils
PCG32.h
Generated by
1.17.0