aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/hash32.go
AgeCommit message (Collapse)Author
2021-03-16runtime: using wyhash for memhashFallback on 32bit platformMeng Zhuo
wyhash is a general hash function that: 1. Default hash function of Zig, Nim 2. Passed Smhasher, BigCrush and PractRand 3. Less code 4. 3~26% faster than internal hashmap name old time/op new time/op delta Hash5 67.8ns ± 0% 65.4ns ± 0% -3.45% (p=0.000 n=7+10) Hash16 82.5ns ± 0% 74.2ns ± 0% -10.12% (p=0.000 n=6+8) Hash64 121ns ± 0% 102ns ± 0% -15.82% (p=0.000 n=7+10) Hash1024 1.13µs ± 0% 0.89µs ± 0% -20.58% (p=0.000 n=10+9) Hash65536 68.9µs ± 0% 54.4µs ± 0% -21.04% (p=0.000 n=10+7) HashStringSpeed 103ns ± 2% 93ns ± 3% -10.24% (p=0.000 n=9+10) HashBytesSpeed 191ns ± 2% 180ns ± 1% -5.40% (p=0.000 n=10+8) HashInt32Speed 59.0ns ± 2% 59.1ns ± 1% ~ (p=0.655 n=9+8) HashInt64Speed 72.7ns ± 3% 66.1ns ± 5% -9.04% (p=0.000 n=10+10) HashStringArraySpeed 270ns ± 1% 222ns ± 2% -17.91% (p=0.000 n=10+10) FastrandHashiter 108ns ± 0% 109ns ± 1% +0.96% (p=0.002 n=10+10) name old speed new speed delta Hash5 73.8MB/s ± 0% 76.4MB/s ± 0% +3.58% (p=0.000 n=7+10) Hash16 194MB/s ± 0% 216MB/s ± 0% +11.25% (p=0.000 n=10+8) Hash64 530MB/s ± 0% 630MB/s ± 0% +18.74% (p=0.000 n=8+10) Hash1024 910MB/s ± 0% 1145MB/s ± 0% +25.88% (p=0.000 n=10+9) Hash65536 951MB/s ± 0% 1204MB/s ± 0% +26.64% (p=0.000 n=10+7) Update #43130 Change-Id: Id00c54b116a2411fcf675e95896fffb85f0e25b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/280372 Trust: Meng Zhuo <mzh@golangcn.org> Run-TryBot: Meng Zhuo <mzh@golangcn.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2021-02-20all: go fmt std cmd (but revert vendor)Russ Cox
Make all our package sources use Go 1.17 gofmt format (adding //go:build lines). Part of //go:build change (#41184). See https://golang.org/design/draft-gobuild Change-Id: Ia0534360e4957e58cd9a18429c39d0e32a6addb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/294430 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-08-29runtime: switch default order of hashing algorithmsKeith Randall
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>
2017-08-28runtime: specialize memhash32 and memhash64Martin Möhrmann
AMD64 with AES support disabled: name old time/op new time/op delta MapPopulate/1 78.0ns ± 1% 75.5ns ± 1% -3.17% (p=0.000 n=10+9) MapPopulate/10 764ns ± 2% 673ns ± 2% -11.91% (p=0.000 n=10+10) MapPopulate/100 9.52µs ± 1% 8.54µs ± 1% -10.37% (p=0.000 n=8+10) MapPopulate/1000 116µs ± 2% 103µs ± 1% -10.40% (p=0.000 n=10+8) MapPopulate/10000 1.01ms ± 1% 0.90ms ± 1% -10.70% (p=0.000 n=10+10) MapPopulate/100000 9.81ms ± 1% 8.67ms ± 2% -11.54% (p=0.000 n=10+10) 386 with AES support disabled: name old time/op new time/op delta MapPopulate/1 95.3ns ± 1% 90.6ns ± 1% -4.95% (p=0.000 n=10+9) MapPopulate/10 983ns ± 2% 912ns ± 1% -7.18% (p=0.000 n=10+10) MapPopulate/100 11.9µs ± 2% 11.2µs ± 1% -6.01% (p=0.000 n=10+10) MapPopulate/1000 140µs ± 1% 131µs ± 1% -6.19% (p=0.000 n=10+10) MapPopulate/10000 1.26ms ± 2% 1.18ms ± 1% -5.93% (p=0.000 n=9+10) MapPopulate/100000 12.1ms ± 2% 11.4ms ± 1% -5.48% (p=0.000 n=10+10) Fixes #21539 Change-Id: Ice128c947c9a6a294800d6a5250d82045eb70b55 Reviewed-on: https://go-review.googlesource.com/59352 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2016-11-15runtime: add support files for linux/mips{,le} portVladimir Stefanovic
Only exe buildmode without cgo supported. Change-Id: Id104a79a99d3285c04db00fd98b8affa94ea3c37 Reviewed-on: https://go-review.googlesource.com/31487 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2015-10-08runtime: make aeshash more DOS-proofKeith Randall
Improve the aeshash implementation to make it harder to engineer collisions. 1) Scramble the seed before xoring with the input string. This makes it harder to cancel known portions of the seed (like the size) because it mixes the per-table seed into those other parts. 2) Use table-dependent seeds for all stripes when hashing >16 byte strings. For small strings this change uses 4 aesenc ops instead of 3, so it is somewhat slower. The first two can run in parallel, though, so it isn't 33% slower. benchmark old ns/op new ns/op delta BenchmarkHash64-12 10.2 11.2 +9.80% BenchmarkHash16-12 5.71 6.13 +7.36% BenchmarkHash5-12 6.64 7.01 +5.57% BenchmarkHashBytesSpeed-12 30.3 31.9 +5.28% BenchmarkHash65536-12 2785 2882 +3.48% BenchmarkHash1024-12 53.6 55.4 +3.36% BenchmarkHashStringArraySpeed-12 54.9 56.5 +2.91% BenchmarkHashStringSpeed-12 18.7 19.2 +2.67% BenchmarkHashInt32Speed-12 14.8 15.1 +2.03% BenchmarkHashInt64Speed-12 14.5 14.5 +0.00% Change-Id: I59ea124b5cb92b1c7e8584008257347f9049996c Reviewed-on: https://go-review.googlesource.com/14124 Reviewed-by: jcd . <jcd@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-01-07runtime: remove size argument from hash and equal algorithmsKeith Randall
The equal algorithm used to take the size equal(p, q *T, size uintptr) bool With this change, it does not equal(p, q *T) bool Similarly for the hash algorithm. The size is rarely used, as most equal functions know the size of the thing they are comparing. For instance f32equal already knows its inputs are 4 bytes in size. For cases where the size is not known, we allocate a closure (one for each size needed) that points to an assembly stub that reads the size out of the closure and calls generic code that has a size argument. Reduces the size of the go binary by 0.07%. Performance impact is not measurable. Change-Id: I6e00adf3dde7ad2974adbcff0ee91e86d2194fec Reviewed-on: https://go-review.googlesource.com/2392 Reviewed-by: Russ Cox <rsc@golang.org>
2015-01-07runtime: use some startup randomness in the fallback hashesKeith Randall
Fold in some startup randomness to make the hash vary across different runs. This helps prevent attackers from choosing keys that all map to the same bucket. Also, reorganize the hash a bit. Move the *m1 multiply to after the xor of the current hash and the message. For hash quality it doesn't really matter, but for DDOS resistance it helps a lot (any processing done to the message before it is merged with the random seed is useless, as it is easily inverted by an attacker). Update #9365 Change-Id: Ib19968168e1bbc541d1d28be2701bb83e53f1e24 Reviewed-on: https://go-review.googlesource.com/2344 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2014-12-22runtime: a better fallback hashKeith Randall
For arm and powerpc, as well as x86 without aes instructions. Contains a mixture of ideas from cityhash and xxhash. Compared to our old fallback on ARM, it's ~no slower on small objects and up to ~50% faster on large objects. More importantly, it is a much better hash function and thus has less chance of bad behavior. Fixes #8737 benchmark old ns/op new ns/op delta BenchmarkHash5 173 181 +4.62% BenchmarkHash16 252 212 -15.87% BenchmarkHash64 575 419 -27.13% BenchmarkHash1024 7173 3995 -44.31% BenchmarkHash65536 516940 313173 -39.42% BenchmarkHashStringSpeed 300 279 -7.00% BenchmarkHashBytesSpeed 478 424 -11.30% BenchmarkHashInt32Speed 217 207 -4.61% BenchmarkHashInt64Speed 262 231 -11.83% BenchmarkHashStringArraySpeed 609 631 +3.61% Change-Id: I0a9335028f32b10ad484966e3019987973afd3eb Reviewed-on: https://go-review.googlesource.com/1360 Reviewed-by: Russ Cox <rsc@golang.org>