diff options
author | Sokolov Yura <funny.falcon@gmail.com> | 2017-01-05 09:36:27 +0300 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2017-02-10 19:16:29 +0000 |
commit | d03c1248604679e1e6a01253144065bc57da48b8 (patch) | |
tree | e668dc946c619cc67b9a5b79df244e58bf0b2233 /src/runtime/stubs.go | |
parent | 9f75ecd5e12f2b9988086954933d610cd5647918 (diff) | |
download | go-d03c1248604679e1e6a01253144065bc57da48b8.tar.gz go-d03c1248604679e1e6a01253144065bc57da48b8.zip |
runtime: implement fastrand in go
So it could be inlined.
Using bit-tricks it could be implemented without condition
(improved trick version by Minux Ma).
Simple benchmark shows it is faster on i386 and x86_64, though
I don't know will it be faster on other architectures?
benchmark old ns/op new ns/op delta
BenchmarkFastrand-3 2.79 1.48 -46.95%
BenchmarkFastrandHashiter-3 25.9 24.9 -3.86%
Change-Id: Ie2eb6d0f598c0bb5fac7f6ad0f8b5e3eddaa361b
Reviewed-on: https://go-review.googlesource.com/34782
Reviewed-by: Minux Ma <minux@golang.org>
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/stubs.go')
-rw-r--r-- | src/runtime/stubs.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/runtime/stubs.go b/src/runtime/stubs.go index e431b441b2..101c8cfd10 100644 --- a/src/runtime/stubs.go +++ b/src/runtime/stubs.go @@ -93,8 +93,15 @@ func reflect_memmove(to, from unsafe.Pointer, n uintptr) { // exported value for testing var hashLoad = loadFactor -// in asm_*.s -func fastrand() uint32 +//go:nosplit +func fastrand() uint32 { + mp := getg().m + fr := mp.fastrand + fr <<= 1 + fr ^= uint32(int32(fr)>>31) & 0x88888eef + mp.fastrand = fr + return fr +} //go:linkname sync_fastrand sync.fastrand func sync_fastrand() uint32 { return fastrand() } |