src/runtime: add xorshift-based fastrand64
Этот коммит содержится в:
родитель
5f3534fe72
коммит
715b269f78
1 изменённых файлов: 16 добавлений и 0 удалений
|
@ -25,6 +25,22 @@ func xorshift32(x uint32) uint32 {
|
||||||
return x
|
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.
|
// This function is used by hash/maphash.
|
||||||
func memhash(p unsafe.Pointer, seed, s uintptr) uintptr {
|
func memhash(p unsafe.Pointer, seed, s uintptr) uintptr {
|
||||||
if unsafe.Sizeof(uintptr(0)) > 4 {
|
if unsafe.Sizeof(uintptr(0)) > 4 {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче