Commit 64bd2c49 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

runtime: simplify b.tophash[i] calculation

The compiler is now smart enough not to insert a bounds check.
Not only is this simpler, it eliminates a LEAQ from the
generated code.

Change-Id: Ie90cbd11584542edd99edd5456d9b02c406e8063
Reviewed-on: https://go-review.googlesource.com/53892
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: 's avatarKeith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent dabc3618
...@@ -45,8 +45,7 @@ func mapaccess1_fast32(t *maptype, h *hmap, key uint32) unsafe.Pointer { ...@@ -45,8 +45,7 @@ func mapaccess1_fast32(t *maptype, h *hmap, key uint32) unsafe.Pointer {
if k != key { if k != key {
continue continue
} }
x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check if b.tophash[i] == empty {
if x == empty {
continue continue
} }
return add(unsafe.Pointer(b), dataOffset+bucketCnt*4+i*uintptr(t.valuesize)) return add(unsafe.Pointer(b), dataOffset+bucketCnt*4+i*uintptr(t.valuesize))
...@@ -94,8 +93,7 @@ func mapaccess2_fast32(t *maptype, h *hmap, key uint32) (unsafe.Pointer, bool) { ...@@ -94,8 +93,7 @@ func mapaccess2_fast32(t *maptype, h *hmap, key uint32) (unsafe.Pointer, bool) {
if k != key { if k != key {
continue continue
} }
x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check if b.tophash[i] == empty {
if x == empty {
continue continue
} }
return add(unsafe.Pointer(b), dataOffset+bucketCnt*4+i*uintptr(t.valuesize)), true return add(unsafe.Pointer(b), dataOffset+bucketCnt*4+i*uintptr(t.valuesize)), true
...@@ -143,8 +141,7 @@ func mapaccess1_fast64(t *maptype, h *hmap, key uint64) unsafe.Pointer { ...@@ -143,8 +141,7 @@ func mapaccess1_fast64(t *maptype, h *hmap, key uint64) unsafe.Pointer {
if k != key { if k != key {
continue continue
} }
x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check if b.tophash[i] == empty {
if x == empty {
continue continue
} }
return add(unsafe.Pointer(b), dataOffset+bucketCnt*8+i*uintptr(t.valuesize)) return add(unsafe.Pointer(b), dataOffset+bucketCnt*8+i*uintptr(t.valuesize))
...@@ -192,8 +189,7 @@ func mapaccess2_fast64(t *maptype, h *hmap, key uint64) (unsafe.Pointer, bool) { ...@@ -192,8 +189,7 @@ func mapaccess2_fast64(t *maptype, h *hmap, key uint64) (unsafe.Pointer, bool) {
if k != key { if k != key {
continue continue
} }
x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check if b.tophash[i] == empty {
if x == empty {
continue continue
} }
return add(unsafe.Pointer(b), dataOffset+bucketCnt*8+i*uintptr(t.valuesize)), true return add(unsafe.Pointer(b), dataOffset+bucketCnt*8+i*uintptr(t.valuesize)), true
...@@ -223,8 +219,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer { ...@@ -223,8 +219,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer {
if key.len < 32 { if key.len < 32 {
// short key, doing lots of comparisons is ok // short key, doing lots of comparisons is ok
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check if b.tophash[i] == empty {
if x == empty {
continue continue
} }
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize)) k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
...@@ -240,8 +235,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer { ...@@ -240,8 +235,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer {
// long key, try not to do more comparisons than necessary // long key, try not to do more comparisons than necessary
keymaybe := uintptr(bucketCnt) keymaybe := uintptr(bucketCnt)
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check if b.tophash[i] == empty {
if x == empty {
continue continue
} }
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize)) k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
...@@ -293,8 +287,7 @@ dohash: ...@@ -293,8 +287,7 @@ dohash:
} }
for { for {
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check if b.tophash[i] != top {
if x != top {
continue continue
} }
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize)) k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
...@@ -330,8 +323,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) { ...@@ -330,8 +323,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) {
if key.len < 32 { if key.len < 32 {
// short key, doing lots of comparisons is ok // short key, doing lots of comparisons is ok
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check if b.tophash[i] == empty {
if x == empty {
continue continue
} }
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize)) k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
...@@ -347,8 +339,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) { ...@@ -347,8 +339,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) {
// long key, try not to do more comparisons than necessary // long key, try not to do more comparisons than necessary
keymaybe := uintptr(bucketCnt) keymaybe := uintptr(bucketCnt)
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check if b.tophash[i] == empty {
if x == empty {
continue continue
} }
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize)) k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
...@@ -400,8 +391,7 @@ dohash: ...@@ -400,8 +391,7 @@ dohash:
} }
for { for {
for i := uintptr(0); i < bucketCnt; i++ { for i := uintptr(0); i < bucketCnt; i++ {
x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check if b.tophash[i] != top {
if x != top {
continue continue
} }
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize)) k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
......
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