mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
src/runtime: add xorshift-based fastrand64
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user