File indexing completed on 2025-02-22 10:31:30
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <cstdint>
0011
0012 #include "corecel/Assert.hh"
0013 #include "corecel/Macros.hh"
0014 #include "corecel/Types.hh"
0015 #include "corecel/cont/Array.hh"
0016 #include "corecel/cont/Span.hh"
0017 #include "corecel/data/Collection.hh"
0018
0019 namespace celeritas
0020 {
0021
0022
0023 using XorwowUInt = std::uint32_t;
0024
0025 using XorwowSeed = Array<XorwowUInt, 1>;
0026
0027
0028
0029
0030
0031 template<Ownership W, MemSpace M>
0032 struct XorwowRngParamsData
0033 {
0034
0035
0036 using JumpPoly = Array<XorwowUInt, 5>;
0037 using ArrayJumpPoly = Array<JumpPoly, 32>;
0038
0039
0040
0041
0042
0043 XorwowSeed seed;
0044
0045
0046 ArrayJumpPoly jump;
0047 ArrayJumpPoly jump_subsequence;
0048
0049
0050
0051 static CELER_CONSTEXPR_FUNCTION size_type num_words()
0052 {
0053 return JumpPoly{}.size();
0054 }
0055 static CELER_CONSTEXPR_FUNCTION size_type num_bits()
0056 {
0057 return 8 * sizeof(XorwowUInt);
0058 }
0059
0060
0061 explicit CELER_FUNCTION operator bool() const { return true; }
0062
0063
0064 template<Ownership W2, MemSpace M2>
0065 XorwowRngParamsData& operator=(XorwowRngParamsData<W2, M2> const& other)
0066 {
0067 CELER_EXPECT(other);
0068 seed = other.seed;
0069 jump = other.jump;
0070 jump_subsequence = other.jump_subsequence;
0071 return *this;
0072 }
0073 };
0074
0075
0076
0077
0078
0079 struct XorwowRngInitializer
0080 {
0081 Array<unsigned int, 1> seed{0};
0082 ull_int subsequence{0};
0083 ull_int offset{0};
0084 };
0085
0086
0087
0088 struct XorwowState
0089 {
0090 Array<XorwowUInt, 5> xorstate;
0091 XorwowUInt weylstate;
0092 };
0093
0094
0095
0096
0097
0098 template<Ownership W, MemSpace M>
0099 struct XorwowRngStateData
0100 {
0101
0102
0103 template<class T>
0104 using Items = Collection<T, W, M>;
0105 template<class T>
0106 using StateItems = StateCollection<T, W, M>;
0107
0108
0109
0110 StateItems<XorwowState> state;
0111
0112
0113
0114
0115 explicit CELER_FUNCTION operator bool() const { return !state.empty(); }
0116
0117
0118 CELER_FUNCTION size_type size() const { return state.size(); }
0119
0120
0121 template<Ownership W2, MemSpace M2>
0122 XorwowRngStateData& operator=(XorwowRngStateData<W2, M2>& other)
0123 {
0124 CELER_EXPECT(other);
0125 state = other.state;
0126 return *this;
0127 }
0128 };
0129
0130
0131
0132 void initialize_xorwow(Span<XorwowState> state,
0133 XorwowSeed const& seed,
0134 StreamId stream);
0135
0136
0137
0138 template<MemSpace M>
0139 void resize(XorwowRngStateData<Ownership::value, M>* state,
0140 HostCRef<XorwowRngParamsData> const& params,
0141 StreamId stream,
0142 size_type size);
0143
0144
0145 }