From f7aa454c58ed0d06823f509fc39474b6f52f7c3a Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sun, 20 Aug 2017 11:47:50 -0700 Subject: [PATCH] runtime: mask shifts in map implementation on x86 This slightly improves the generated code on x86 architectures, including on many hot paths. It is a no-op on other architectures. Change-Id: I86336fd846bc5805a27bbec572e8c73dcbd0d567 Reviewed-on: https://go-review.googlesource.com/57411 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/runtime/hashmap.go | 37 +++++++++++++++++++++++++------------ src/runtime/hashmap_fast.go | 24 ++++++++++++------------ src/runtime/runtime_test.go | 2 +- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index 60af870fac..df4df053d1 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -170,6 +170,19 @@ type hiter struct { checkBucket uintptr } +// bucketShift returns 1<> (sys.PtrSize*8 - 8)) @@ -374,7 +387,7 @@ func mapaccess1(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer { } alg := t.key.alg hash := alg.hash(key, uintptr(h.hash0)) - m := uintptr(1)< 31-bucketCntBits { r += uintptr(fastrand()) << 31 } - it.startBucket = r & (uintptr(1)<> h.B & (bucketCnt - 1)) // iterator state @@ -817,7 +830,7 @@ next: checkBucket = noCheck } bucket++ - if bucket == uintptr(1)<= bucketCnt && uint64(count) >= loadFactorNum*((uint64(1)<= bucketCnt && uintptr(count) >= loadFactorNum*(bucketShift(B)/loadFactorDen) } // tooManyOverflowBuckets reports whether noverflow buckets is too many for a map with 1<