aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/alg.go
diff options
context:
space:
mode:
authorKeith Randall <keithr@alum.mit.edu>2019-08-20 11:03:13 -0700
committerKeith Randall <khr@golang.org>2019-08-29 21:16:09 +0000
commitfbfb41e6389089b637562b41e05d40f5581b3bbd (patch)
tree1a87c88aadc8eeb91cfaeaef2a442e9467882638 /src/runtime/alg.go
parent9675f819288ae27ed4b95521303ec7ceb16686ab (diff)
downloadgo-fbfb41e6389089b637562b41e05d40f5581b3bbd.tar.xz
runtime: switch default order of hashing algorithms
Currently the standard hasher is memhash, which checks whether aes instructions are available, and if so redirects to aeshash. With this CL, we call aeshash directly, which then redirects to the fallback hash if aes instructions are not available. This reduces the overhead for the hash function in the common case, as it requires just one call instead of two. On architectures which have no assembly hasher, it's a single jump slower. Thanks to Martin for this idea. name old time/op new time/op delta BigKeyMap-4 22.6ns ± 1% 21.1ns ± 2% -6.55% (p=0.000 n=9+10) Change-Id: Ib7ca77b63d28222eb0189bc3d7130531949d853c Reviewed-on: https://go-review.googlesource.com/c/go/+/190998 Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Diffstat (limited to 'src/runtime/alg.go')
-rw-r--r--src/runtime/alg.go19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/runtime/alg.go b/src/runtime/alg.go
index 732d32bf41..57306f81d9 100644
--- a/src/runtime/alg.go
+++ b/src/runtime/alg.go
@@ -88,14 +88,14 @@ var algarray = [alg_max]typeAlg{
var useAeshash bool
// in asm_*.s
-func aeshash(p unsafe.Pointer, h, s uintptr) uintptr
-func aeshash32(p unsafe.Pointer, h uintptr) uintptr
-func aeshash64(p unsafe.Pointer, h uintptr) uintptr
-func aeshashstr(p unsafe.Pointer, h uintptr) uintptr
+func memhash(p unsafe.Pointer, h, s uintptr) uintptr
+func memhash32(p unsafe.Pointer, h uintptr) uintptr
+func memhash64(p unsafe.Pointer, h uintptr) uintptr
+func strhash(p unsafe.Pointer, h uintptr) uintptr
-func strhash(a unsafe.Pointer, h uintptr) uintptr {
+func strhashFallback(a unsafe.Pointer, h uintptr) uintptr {
x := (*stringStruct)(a)
- return memhash(x.str, h, uintptr(x.len))
+ return memhashFallback(x.str, h, uintptr(x.len))
}
// NOTE: Because NaN != NaN, a map can contain any
@@ -305,14 +305,7 @@ func alginit() {
}
func initAlgAES() {
- if GOOS == "aix" {
- // runtime.algarray is immutable on AIX: see cmd/link/internal/ld/xcoff.go
- return
- }
useAeshash = true
- algarray[alg_MEM32].hash = aeshash32
- algarray[alg_MEM64].hash = aeshash64
- algarray[alg_STRING].hash = aeshashstr
// Initialize with random data so hash collisions will be hard to engineer.
getRandomData(aeskeysched[:])
}