|
71 | 71 |
|
72 | 72 | // Float values for this were taken from Microsoft online documentation for the |
73 | 73 | // DirectX HALF data type. HALF is equivalent to IEEE 754 binary 16 format. |
74 | | -const DirectX::PackedVector::HALF HALF_MIN = |
75 | | - DirectX::PackedVector::XMConvertFloatToHalf(float(6.10e-5f)); |
76 | | -const DirectX::PackedVector::HALF HALF_MAX = |
77 | | - DirectX::PackedVector::XMConvertFloatToHalf(float(65504.0f)); |
78 | 74 |
|
79 | 75 | // A more recent Windows SDK than currently required is needed for these. |
80 | 76 | typedef HRESULT(WINAPI *D3D12EnableExperimentalFeaturesFn)( |
@@ -11511,95 +11507,53 @@ template <typename T> struct LongVectorOpTestConfig { |
11511 | 11507 | LongVectorOpType OpType = LongVectorOpType_UnInitialized; |
11512 | 11508 | }; |
11513 | 11509 |
|
11514 | | -// A helper class to generate deterministic random numbers. For any given seed |
11515 | | -// the generated sequence will always be the same. Each call to generate() will |
11516 | | -// return the next number in the sequence. |
| 11510 | +template <typename T> struct LongVectorTestTraits { |
| 11511 | + std::uniform_int_distribution<T> UD = std::uniform_int_distribution( |
| 11512 | + std::numeric_limits<T>::min(), std::numeric_limits<T>::max()); |
| 11513 | +}; |
| 11514 | + |
| 11515 | +template <> struct LongVectorTestTraits<HLSLHalf_t> { |
| 11516 | + // Float values for this were taken from Microsoft online documentation for |
| 11517 | + // the DirectX HALF data type. HALF is equivalent to IEEE 754 binary 16 |
| 11518 | + // format. |
| 11519 | + std::uniform_int_distribution<DirectX::PackedVector::HALF> UD = |
| 11520 | + std::uniform_int_distribution( |
| 11521 | + DirectX::PackedVector::XMConvertFloatToHalf(float(6.10e-5f)), |
| 11522 | + DirectX::PackedVector::XMConvertFloatToHalf(float(65504.0f))); |
| 11523 | +}; |
| 11524 | + |
| 11525 | +template <> struct LongVectorTestTraits<HLSLBool_t> { |
| 11526 | + std::uniform_int_distribution<uint16_t> UD = |
| 11527 | + std::uniform_int_distribution<uint16_t>(0u, 1u); |
| 11528 | +}; |
| 11529 | + |
| 11530 | +template <> struct LongVectorTestTraits<float> { |
| 11531 | + // The ranges for generation. A std::uniform_real_distribution can only |
| 11532 | + // have a range that is equal to the types largest value. This is due to |
| 11533 | + // precision issues. So instead we define some large values. |
| 11534 | + std::uniform_real_distribution<float> UD = |
| 11535 | + std::uniform_real_distribution(-1e20f, 1e20f); |
| 11536 | +}; |
| 11537 | + |
| 11538 | +template <> struct LongVectorTestTraits<double> { |
| 11539 | + // The ranges for generation. A std::uniform_real_distribution can only |
| 11540 | + // have a range that is equal to the types largest value. This is due to |
| 11541 | + // precision issues. So instead we define some large values. |
| 11542 | + std::uniform_real_distribution<double> UD = |
| 11543 | + std::uniform_real_distribution(-1e100, 1e100); |
| 11544 | +}; |
| 11545 | + |
11517 | 11546 | template <typename T> class DeterministicNumberGenerator { |
| 11547 | + // Mersenne Twister 'random' number generator. Generated numbers are based |
| 11548 | + // on the seed value and are deterministic for any given seed. |
| 11549 | + std::mt19937 Generator; |
| 11550 | + |
| 11551 | + LongVectorTestTraits<T> UD; |
| 11552 | + |
11518 | 11553 | public: |
11519 | | - DeterministicNumberGenerator(unsigned int seedValue) : generator(seedValue) { |
11520 | | - if constexpr (std::is_same_v<T, HLSLHalf_t>) |
11521 | | - DXHalfDist = std::uniform_int_distribution<DirectX::PackedVector::HALF>( |
11522 | | - HALF_MIN, HALF_MAX); |
11523 | | - else if constexpr (std::is_same_v<T, HLSLBool_t>) |
11524 | | - // Anything non-zero, including negative values, is true as a bool. So 0 |
11525 | | - // and 1 are all we need. |
11526 | | - Uint16Dist = std::uniform_int_distribution<uint16_t>(0, 1); |
11527 | | - else if constexpr (std::is_same_v<T, int16_t>) |
11528 | | - Int16Dist = std::uniform_int_distribution<int16_t>( |
11529 | | - std::numeric_limits<T>::min(), std::numeric_limits<T>::max()); |
11530 | | - else if constexpr (std::is_same_v<T, int32_t>) |
11531 | | - Int32Dist = std::uniform_int_distribution<T>( |
11532 | | - std::numeric_limits<T>::min(), std::numeric_limits<T>::max()); |
11533 | | - else if constexpr (std::is_same_v<T, int64_t>) |
11534 | | - Int64Dist = std::uniform_int_distribution<T>( |
11535 | | - std::numeric_limits<T>::min(), std::numeric_limits<T>::max()); |
11536 | | - else if constexpr (std::is_same_v<T, uint16_t>) |
11537 | | - Uint16Dist = std::uniform_int_distribution<T>( |
11538 | | - std::numeric_limits<T>::min(), std::numeric_limits<T>::max()); |
11539 | | - else if constexpr (std::is_same_v<T, uint32_t>) |
11540 | | - Uint32Dist = std::uniform_int_distribution<T>( |
11541 | | - std::numeric_limits<T>::min(), std::numeric_limits<T>::max()); |
11542 | | - else if constexpr (std::is_same_v<T, uint64_t>) |
11543 | | - Uint64Dist = std::uniform_int_distribution<T>( |
11544 | | - std::numeric_limits<T>::min(), std::numeric_limits<T>::max()); |
11545 | | - else if constexpr (std::is_same_v<T, float>) |
11546 | | - FloatDist = |
11547 | | - std::uniform_real_distribution<T>(FLOAT_RANGE_MIN, FLOAT_RANGE_MAX); |
11548 | | - else if constexpr (std::is_same_v<T, double>) |
11549 | | - DoubleDist = |
11550 | | - std::uniform_real_distribution<T>(DOUBLE_RANGE_MIN, DOUBLE_RANGE_MAX); |
11551 | | - else |
11552 | | - VERIFY_FAIL("Unsupported type for DeterministicNumberGenerator"); |
11553 | | - } |
11554 | | - |
11555 | | - // Function to generate a random number within the range of the type. Ranges |
11556 | | - // are specificed at construction time. |
11557 | | - T generate() { |
11558 | | - if constexpr (std::is_same_v<T, int16_t>) |
11559 | | - return Int16Dist(generator); |
11560 | | - if constexpr (std::is_same_v<T, HLSLBool_t>) |
11561 | | - return Uint16Dist(generator); |
11562 | | - if constexpr (std::is_same_v<T, HLSLHalf_t>) |
11563 | | - return DXHalfDist(generator); |
11564 | | - if constexpr (std::is_same_v<T, int32_t>) |
11565 | | - return Int32Dist(generator); |
11566 | | - if constexpr (std::is_same_v<T, int64_t>) |
11567 | | - return Int64Dist(generator); |
11568 | | - if constexpr (std::is_same_v<T, float>) |
11569 | | - return FloatDist(generator); |
11570 | | - if constexpr (std::is_same_v<T, double>) |
11571 | | - return DoubleDist(generator); |
11572 | | - if constexpr (std::is_same_v<T, uint16_t>) |
11573 | | - return Uint16Dist(generator); |
11574 | | - if constexpr (std::is_same_v<T, uint32_t>) |
11575 | | - return Uint32Dist(generator); |
11576 | | - if constexpr (std::is_same_v<T, uint64_t>) |
11577 | | - return Uint64Dist(generator); |
11578 | | - |
11579 | | - VERIFY_FAIL("Unsupported data type for generate()"); |
11580 | | - } |
| 11554 | + DeterministicNumberGenerator(unsigned SeedValue) : Generator(SeedValue) {} |
11581 | 11555 |
|
11582 | | -private: |
11583 | | - // Mersenne Twister 'random' number generator. Generated numbers are based on |
11584 | | - // the seed value and are deterministic for any given seed. |
11585 | | - std::mt19937 generator; |
11586 | | - std::uniform_int_distribution<int16_t> Int16Dist; |
11587 | | - std::uniform_int_distribution<int32_t> Int32Dist; |
11588 | | - std::uniform_int_distribution<int64_t> Int64Dist; |
11589 | | - std::uniform_int_distribution<DirectX::PackedVector::HALF> DXHalfDist; |
11590 | | - std::uniform_int_distribution<uint16_t> Uint16Dist; |
11591 | | - std::uniform_int_distribution<uint32_t> Uint32Dist; |
11592 | | - std::uniform_int_distribution<uint64_t> Uint64Dist; |
11593 | | - std::uniform_real_distribution<float> FloatDist; |
11594 | | - std::uniform_real_distribution<double> DoubleDist; |
11595 | | - |
11596 | | - // The ranges for generation. A std::uniform_real_distribution can only have |
11597 | | - // a range that is equal to the types largest value. This is due to precision |
11598 | | - // issues. So instead we define some large values. |
11599 | | - const float FLOAT_RANGE_MIN = -1e20f; |
11600 | | - const float FLOAT_RANGE_MAX = 1e20f; |
11601 | | - const double DOUBLE_RANGE_MIN = -1e100; |
11602 | | - const double DOUBLE_RANGE_MAX = 1e100; |
| 11556 | + T generate() { return UD.UD(Generator); } |
11603 | 11557 | }; |
11604 | 11558 |
|
11605 | 11559 | template <typename T, std::size_t N> |
|
0 commit comments