Commit 44571753 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

runtime: refactor out tophash calculation

No functional changes; tophash is inlined.

Change-Id: Ic8ce95b3622eafbddcfbc97f8c630ab8c5bfe7ad
Reviewed-on: https://go-review.googlesource.com/55233
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent 02ad116b
...@@ -170,6 +170,15 @@ type hiter struct { ...@@ -170,6 +170,15 @@ type hiter struct {
checkBucket uintptr checkBucket uintptr
} }
// tophash calculates the tophash value for hash.
func tophash(hash uintptr) uint8 {
top := uint8(hash >> (sys.PtrSize*8 - 8))
if top < minTopHash {
top += minTopHash
}
return top
}
func evacuated(b *bmap) bool { func evacuated(b *bmap) bool {
h := b.tophash[0] h := b.tophash[0]
return h > empty && h < minTopHash return h > empty && h < minTopHash
...@@ -374,10 +383,7 @@ func mapaccess1(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer { ...@@ -374,10 +383,7 @@ func mapaccess1(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer {
b = oldb b = oldb
} }
} }
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
for { for {
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
if b.tophash[i] != top { if b.tophash[i] != top {
...@@ -432,10 +438,7 @@ func mapaccess2(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, bool) ...@@ -432,10 +438,7 @@ func mapaccess2(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, bool)
b = oldb b = oldb
} }
} }
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
for { for {
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
if b.tophash[i] != top { if b.tophash[i] != top {
...@@ -479,10 +482,7 @@ func mapaccessK(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, unsafe ...@@ -479,10 +482,7 @@ func mapaccessK(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, unsafe
b = oldb b = oldb
} }
} }
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
for { for {
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
if b.tophash[i] != top { if b.tophash[i] != top {
...@@ -557,10 +557,7 @@ again: ...@@ -557,10 +557,7 @@ again:
growWork(t, h, bucket) growWork(t, h, bucket)
} }
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize))) b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
var inserti *uint8 var inserti *uint8
var insertk unsafe.Pointer var insertk unsafe.Pointer
...@@ -667,10 +664,7 @@ func mapdelete(t *maptype, h *hmap, key unsafe.Pointer) { ...@@ -667,10 +664,7 @@ func mapdelete(t *maptype, h *hmap, key unsafe.Pointer) {
growWork(t, h, bucket) growWork(t, h, bucket)
} }
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize))) b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
for { for {
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
if b.tophash[i] != top { if b.tophash[i] != top {
...@@ -1102,10 +1096,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) { ...@@ -1102,10 +1096,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
} else { } else {
hash &^= newbit hash &^= newbit
} }
top = uint8(hash >> (sys.PtrSize*8 - 8)) top = tophash(hash)
if top < minTopHash {
top += minTopHash
}
} }
if hash&newbit != 0 { if hash&newbit != 0 {
useY = 1 useY = 1
......
...@@ -281,10 +281,7 @@ dohash: ...@@ -281,10 +281,7 @@ dohash:
b = oldb b = oldb
} }
} }
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
for { for {
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
if b.tophash[i] != top { if b.tophash[i] != top {
...@@ -385,10 +382,7 @@ dohash: ...@@ -385,10 +382,7 @@ dohash:
b = oldb b = oldb
} }
} }
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
for { for {
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
if b.tophash[i] != top { if b.tophash[i] != top {
...@@ -435,10 +429,7 @@ again: ...@@ -435,10 +429,7 @@ again:
growWork(t, h, bucket) growWork(t, h, bucket)
} }
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize))) b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
var inserti *uint8 var inserti *uint8
var insertk unsafe.Pointer var insertk unsafe.Pointer
...@@ -523,10 +514,7 @@ again: ...@@ -523,10 +514,7 @@ again:
growWork(t, h, bucket) growWork(t, h, bucket)
} }
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize))) b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
var inserti *uint8 var inserti *uint8
var insertk unsafe.Pointer var insertk unsafe.Pointer
...@@ -612,10 +600,7 @@ again: ...@@ -612,10 +600,7 @@ again:
growWork(t, h, bucket) growWork(t, h, bucket)
} }
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize))) b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
var inserti *uint8 var inserti *uint8
var insertk unsafe.Pointer var insertk unsafe.Pointer
...@@ -700,10 +685,7 @@ func mapdelete_fast32(t *maptype, h *hmap, key uint32) { ...@@ -700,10 +685,7 @@ func mapdelete_fast32(t *maptype, h *hmap, key uint32) {
growWork(t, h, bucket) growWork(t, h, bucket)
} }
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize))) b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
for { for {
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
if b.tophash[i] != top { if b.tophash[i] != top {
...@@ -755,10 +737,7 @@ func mapdelete_fast64(t *maptype, h *hmap, key uint64) { ...@@ -755,10 +737,7 @@ func mapdelete_fast64(t *maptype, h *hmap, key uint64) {
growWork(t, h, bucket) growWork(t, h, bucket)
} }
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize))) b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
for { for {
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
if b.tophash[i] != top { if b.tophash[i] != top {
...@@ -811,10 +790,7 @@ func mapdelete_faststr(t *maptype, h *hmap, ky string) { ...@@ -811,10 +790,7 @@ func mapdelete_faststr(t *maptype, h *hmap, ky string) {
growWork(t, h, bucket) growWork(t, h, bucket)
} }
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize))) b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
top := uint8(hash >> (sys.PtrSize*8 - 8)) top := tophash(hash)
if top < minTopHash {
top += minTopHash
}
for { for {
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
if b.tophash[i] != top { if b.tophash[i] != top {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment