reversible
Hash finalizers and a xorshift step, each with a generated inverse.
jihoo run examples/reversible.jh
import std.fmt
#[reversible(unmix_murmur)]
fn fmix64(inout x: u64) {
x ^= x >> 33
x *%= 0xff51afd7ed558ccd
x ^= x >> 33
x *%= 0xc4ceb9fe1a85ec53
x ^= x >> 33
}
#[reversible(unxorshift)]
fn xorshift64(inout x: u64) {
x ^= x << 13
x ^= x >> 7
x ^= x << 17
}
#[reversible(unsplitmix)]
fn splitmix64(inout x: u64) {
x +%= 0x9e3779b97f4a7c15
x ^= x >> 30
x *%= 0xbf58476d1ce4e5b9
x ^= x >> 27
x *%= 0x94d049bb133111eb
x ^= x >> 31
}
fn main() {
let seed: u64 = 123456789
var x = seed
fmix64(&x)
fmt.println("fmix64: {}", x)
unmix_murmur(&x)
assert(x == seed, "fmix64 round trip")
xorshift64(&x)
fmt.println("xorshift64: {}", x)
unxorshift(&x)
assert(x == seed, "xorshift64 round trip")
splitmix64(&x)
fmt.println("splitmix64: {}", x)
unsplitmix(&x)
assert(x == seed, "splitmix64 round trip")
}