diff options
author | Keith Randall <keithr@alum.mit.edu> | 2019-08-20 11:03:13 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2019-08-29 21:16:09 +0000 |
commit | fbfb41e6389089b637562b41e05d40f5581b3bbd (patch) | |
tree | 1a87c88aadc8eeb91cfaeaef2a442e9467882638 /src/runtime/asm_arm64.s | |
parent | 9675f819288ae27ed4b95521303ec7ceb16686ab (diff) | |
download | go-fbfb41e6389089b637562b41e05d40f5581b3bbd.tar.gz go-fbfb41e6389089b637562b41e05d40f5581b3bbd.zip |
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/asm_arm64.s')
-rw-r--r-- | src/runtime/asm_arm64.s | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/runtime/asm_arm64.s b/src/runtime/asm_arm64.s index 6e3b1b14a6..21ea519d64 100644 --- a/src/runtime/asm_arm64.s +++ b/src/runtime/asm_arm64.s @@ -445,8 +445,11 @@ CALLFN(·call268435456, 268435464 ) CALLFN(·call536870912, 536870920 ) CALLFN(·call1073741824, 1073741832 ) -// func aeshash32(p unsafe.Pointer, h uintptr) uintptr -TEXT runtime·aeshash32(SB),NOSPLIT|NOFRAME,$0-24 +// func memhash32(p unsafe.Pointer, h uintptr) uintptr +TEXT runtime·memhash32(SB),NOSPLIT|NOFRAME,$0-24 + MOVB runtime·useAeshash(SB), R0 + CMP $0, R0 + BEQ noaes MOVD p+0(FP), R0 MOVD h+8(FP), R1 MOVD $ret+16(FP), R2 @@ -465,9 +468,14 @@ TEXT runtime·aeshash32(SB),NOSPLIT|NOFRAME,$0-24 VST1 [V0.D1], (R2) RET +noaes: + B runtime·memhash32Fallback(SB) -// func aeshash64(p unsafe.Pointer, h uintptr) uintptr -TEXT runtime·aeshash64(SB),NOSPLIT|NOFRAME,$0-24 +// func memhash64(p unsafe.Pointer, h uintptr) uintptr +TEXT runtime·memhash64(SB),NOSPLIT|NOFRAME,$0-24 + MOVB runtime·useAeshash(SB), R0 + CMP $0, R0 + BEQ noaes MOVD p+0(FP), R0 MOVD h+8(FP), R1 MOVD $ret+16(FP), R2 @@ -486,22 +494,34 @@ TEXT runtime·aeshash64(SB),NOSPLIT|NOFRAME,$0-24 VST1 [V0.D1], (R2) RET +noaes: + B runtime·memhash64Fallback(SB) -// func aeshash(p unsafe.Pointer, h, size uintptr) uintptr -TEXT runtime·aeshash(SB),NOSPLIT|NOFRAME,$0-32 +// func memhash(p unsafe.Pointer, h, size uintptr) uintptr +TEXT runtime·memhash(SB),NOSPLIT|NOFRAME,$0-32 + MOVB runtime·useAeshash(SB), R0 + CMP $0, R0 + BEQ noaes MOVD p+0(FP), R0 MOVD s+16(FP), R1 MOVWU h+8(FP), R3 MOVD $ret+24(FP), R2 B aeshashbody<>(SB) +noaes: + B runtime·memhashFallback(SB) -// func aeshashstr(p unsafe.Pointer, h uintptr) uintptr -TEXT runtime·aeshashstr(SB),NOSPLIT|NOFRAME,$0-24 +// func strhash(p unsafe.Pointer, h uintptr) uintptr +TEXT runtime·strhash(SB),NOSPLIT|NOFRAME,$0-24 + MOVB runtime·useAeshash(SB), R0 + CMP $0, R0 + BEQ noaes MOVD p+0(FP), R10 // string pointer LDP (R10), (R0, R1) //string data/ length MOVWU h+8(FP), R3 MOVD $ret+16(FP), R2 // return adddress B aeshashbody<>(SB) +noaes: + B runtime·strhashFallback(SB) // R0: data // R1: length (maximum 32 bits) |