src/runtime: add xorshift-based fastrand64

This commit is contained in:
Damian Gryski
2023-01-06 20:24:34 -08:00
committed by Ron Evans
parent 5f3534fe72
commit 715b269f78
+16
View File
@@ -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 {