Oh ye of little faith.
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
| uint64_t shuffle(uint64_t state) | |
| { | |
| uint64_t word = ((state >> ((state >> 59u) + 5u)) ^ state) | |
| * 12605985483714917081ull; | |
| return (word >> 43u) ^ word; | |
| } | |
| uint64_t unxorshift(uint64_t xs, uint32_t shamt) | |
| { | |
| // bits: | |
| // xs[i] = x[i] ^ x[i+shamt] | |
| // recover one by one, higher bits to low | |
| uint64_t x = xs; | |
| uint64_t bitmask; | |
| for (bitmask = 1ull << (63 - shamt); bitmask; bitmask >>= 1) | |
| x ^= (x >> shamt) & bitmask; | |
| return x; | |
| } | |
| uint64_t unshuffle(uint64_t shuffled) | |
| { | |
| uint64_t word = shuffled; | |
| word = unxorshift(word, 43u); | |
| word *= 15009553638781119849ull; // modular inverse | |
| word = unxorshift(word, (word >> 59u) + 5u); | |
| return word; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment