-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
289 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2023 Maikel Nadolski | ||
* Copyright (c) 2023 NVIDIA Corporation | ||
* | ||
* Licensed under the Apache License Version 2.0 with LLVM Exceptions | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* https://llvm.org/LICENSE.txt | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* I have taken and modified this code from https://gist.github.com/Leandros/6dc334c22db135b033b57e9ee0311553 */ | ||
/* Copyright (c) 2018 Arvid Gerstmann. */ | ||
/* This code is licensed under MIT license. */ | ||
|
||
#include <cstddef> | ||
#include <random> | ||
|
||
namespace exec { | ||
|
||
class xorshift { | ||
public: | ||
using result_type = std::uint32_t; | ||
|
||
static constexpr result_type(min)() { | ||
return 0; | ||
} | ||
|
||
static constexpr result_type(max)() { | ||
return UINT32_MAX; | ||
} | ||
|
||
friend bool operator==(xorshift const &, xorshift const &) = default; | ||
|
||
xorshift() | ||
: m_seed(0xc1f651c67c62c6e0ull) { | ||
} | ||
|
||
explicit xorshift(std::random_device &rd) { | ||
seed(rd); | ||
} | ||
|
||
void seed(std::random_device &rd) { | ||
m_seed = std::uint64_t(rd()) << 31 | std::uint64_t(rd()); | ||
} | ||
|
||
result_type operator()() { | ||
std::uint64_t result = m_seed * 0xd989bcacc137dcd5ull; | ||
m_seed ^= m_seed >> 11; | ||
m_seed ^= m_seed << 31; | ||
m_seed ^= m_seed >> 18; | ||
return std::uint32_t(result >> 32ull); | ||
} | ||
|
||
void discard(unsigned long long n) { | ||
for (unsigned long long i = 0; i < n; ++i) | ||
operator()(); | ||
} | ||
|
||
private: | ||
std::uint64_t m_seed; | ||
}; | ||
|
||
} // namespace exec |
Oops, something went wrong.