diff options
Diffstat (limited to 'libgo/go/runtime/stubs.go')
-rw-r--r-- | libgo/go/runtime/stubs.go | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/libgo/go/runtime/stubs.go b/libgo/go/runtime/stubs.go index e24313c..268ef5e 100644 --- a/libgo/go/runtime/stubs.go +++ b/libgo/go/runtime/stubs.go @@ -5,7 +5,8 @@ package runtime import ( - "runtime/internal/sys" + "internal/goarch" + "runtime/internal/math" "unsafe" ) @@ -119,20 +120,32 @@ func reflect_memmove(to, from unsafe.Pointer, n uintptr) { func memcmp(a, b unsafe.Pointer, size uintptr) int32 // exported value for testing -var hashLoad = float32(loadFactorNum) / float32(loadFactorDen) +const hashLoad = float32(loadFactorNum) / float32(loadFactorDen) //go:nosplit func fastrand() uint32 { mp := getg().m + // Implement wyrand: https://github.com/wangyi-fudan/wyhash + // Only the platform that math.Mul64 can be lowered + // by the compiler should be in this list. + if goarch.IsAmd64|goarch.IsArm64|goarch.IsPpc64| + goarch.IsPpc64le|goarch.IsMips64|goarch.IsMips64le| + goarch.IsS390x|goarch.IsRiscv64 == 1 { + mp.fastrand += 0xa0761d6478bd642f + hi, lo := math.Mul64(mp.fastrand, mp.fastrand^0xe7037ed1a0b428db) + return uint32(hi ^ lo) + } + // Implement xorshift64+: 2 32-bit xorshift sequences added together. // Shift triplet [17,7,16] was calculated as indicated in Marsaglia's // Xorshift paper: https://www.jstatsoft.org/article/view/v008i14/xorshift.pdf // This generator passes the SmallCrush suite, part of TestU01 framework: // http://simul.iro.umontreal.ca/testu01/tu01.html - s1, s0 := mp.fastrand[0], mp.fastrand[1] + t := (*[2]uint32)(unsafe.Pointer(&mp.fastrand)) + s1, s0 := t[0], t[1] s1 ^= s1 << 17 s1 = s1 ^ s0 ^ s1>>7 ^ s0>>16 - mp.fastrand[0], mp.fastrand[1] = s0, s1 + t[0], t[1] = s0, s1 return s0 + s1 } @@ -143,8 +156,8 @@ func fastrandn(n uint32) uint32 { return uint32(uint64(fastrand()) * uint64(n) >> 32) } -//go:linkname sync_fastrand sync.fastrand -func sync_fastrand() uint32 { return fastrand() } +//go:linkname sync_fastrandn sync.fastrandn +func sync_fastrandn(n uint32) uint32 { return fastrandn(n) } //go:linkname net_fastrand net.fastrand func net_fastrand() uint32 { return fastrand() } @@ -335,7 +348,7 @@ func rethrowException() // used by the stack unwinder. func unwindExceptionSize() uintptr -const uintptrMask = 1<<(8*sys.PtrSize) - 1 +const uintptrMask = 1<<(8*goarch.PtrSize) - 1 type bitvector struct { n int32 // # of bits |