Somewhat better unxorshift
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 unxorshift(uint64_t xs, uint32_t shamt) | |
| { | |
| // NB shamt >= 1 required; shamt=0 is not reversible for obvious reasons :) | |
| // I am still convinced there's a much tighter way to code this, but this one | |
| // is less terrible. | |
| uint64_t x = xs; | |
| for (uint32_t k = 32; k >= 1; k >>= 1) | |
| { | |
| uint32_t l = k * shamt; | |
| if (l < 64) | |
| x ^= x >> l; | |
| } | |
| return x; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment