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