]> Cypherpunks repositories - gostls13.git/commit
runtime: improve fastrand with a better generator
authorGiovanni Bajo <rasky@develer.com>
Sat, 9 Sep 2017 12:59:06 +0000 (14:59 +0200)
committerMichael Munday <mike.munday@ibm.com>
Sat, 16 Sep 2017 10:17:26 +0000 (10:17 +0000)
commite7e4a4ffa3330518250c4075e1f16a8ba62414df
tree606cdb68ede7472f92af54c9d05dfdd6d3af2ac7
parenta5d6b414493fdbd958dfbc973e6e890c2ee045d1
runtime: improve fastrand with a better generator

The current generator is a simple LSFR, which showed strong
correlation in higher bits, as manifested by fastrandn().

Change it with xorshift64+, which is slightly more complex,
has a larger state, but has a period of 2^64-1 and is much better
at statistical tests. The version used here is capable of
passing Diehard and even SmallCrush.

Speed is slightly worse but is probably insignificant:

name                old time/op  new time/op  delta
Fastrand-4          0.77ns ±12%  0.91ns ±21%  +17.31%  (p=0.048 n=5+5)
FastrandHashiter-4  13.6ns ±21%  15.2ns ±17%     ~     (p=0.160 n=6+5)
Fastrandn/2-4       2.30ns ± 5%  2.45ns ±15%     ~     (p=0.222 n=5+5)
Fastrandn/3-4       2.36ns ± 7%  2.45ns ± 6%     ~     (p=0.222 n=5+5)
Fastrandn/4-4       2.33ns ± 8%  2.61ns ±30%     ~     (p=0.126 n=6+5)
Fastrandn/5-4       2.33ns ± 5%  2.48ns ± 9%     ~     (p=0.052 n=6+5)

Fixes #21806

Change-Id: I013bb37b463fdfc229a7f324df8fe2da8d286f33
Reviewed-on: https://go-review.googlesource.com/62530
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/chan_test.go
src/runtime/proc.go
src/runtime/runtime2.go
src/runtime/stubs.go