diff --git a/src/runtime/algorithm.go b/src/runtime/algorithm.go index 15487176..35e2e260 100644 --- a/src/runtime/algorithm.go +++ b/src/runtime/algorithm.go @@ -25,6 +25,22 @@ func xorshift32(x uint32) uint32 { return x } +// This function is used by hash/maphash. +func fastrand64() uint64 { + xorshift64State = xorshiftMult64(xorshift64State) + return xorshift64State +} + +var xorshift64State uint64 = 1 + +// 64-bit xorshift multiply rng from http://vigna.di.unimi.it/ftp/papers/xorshift.pdf +func xorshiftMult64(x uint64) uint64 { + x ^= x >> 12 // a + x ^= x << 25 // b + x ^= x >> 27 // c + return x * 2685821657736338717 +} + // This function is used by hash/maphash. func memhash(p unsafe.Pointer, seed, s uintptr) uintptr { if unsafe.Sizeof(uintptr(0)) > 4 {