]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: simplify b.tophash[i] calculation
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 5 Jun 2017 14:18:09 +0000 (07:18 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 8 Aug 2017 19:51:48 +0000 (19:51 +0000)
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: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/hashmap_fast.go

index 6f21624d3212b5411612440498215ff8a815ade3..18ceee46d82357c35a833ba9a3da7ad242e30538 100644 (file)
@@ -45,8 +45,7 @@ func mapaccess1_fast32(t *maptype, h *hmap, key uint32) unsafe.Pointer {
                        if k != key {
                                continue
                        }
-                       x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
-                       if x == empty {
+                       if b.tophash[i] == empty {
                                continue
                        }
                        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) {
                        if k != key {
                                continue
                        }
-                       x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
-                       if x == empty {
+                       if b.tophash[i] == empty {
                                continue
                        }
                        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 {
                        if k != key {
                                continue
                        }
-                       x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
-                       if x == empty {
+                       if b.tophash[i] == empty {
                                continue
                        }
                        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) {
                        if k != key {
                                continue
                        }
-                       x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
-                       if x == empty {
+                       if b.tophash[i] == empty {
                                continue
                        }
                        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 {
                if key.len < 32 {
                        // short key, doing lots of comparisons is ok
                        for i := uintptr(0); i < bucketCnt; i++ {
-                               x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
-                               if x == empty {
+                               if b.tophash[i] == empty {
                                        continue
                                }
                                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 {
                // long key, try not to do more comparisons than necessary
                keymaybe := uintptr(bucketCnt)
                for i := uintptr(0); i < bucketCnt; i++ {
-                       x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
-                       if x == empty {
+                       if b.tophash[i] == empty {
                                continue
                        }
                        k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
@@ -293,8 +287,7 @@ dohash:
        }
        for {
                for i := uintptr(0); i < bucketCnt; i++ {
-                       x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
-                       if x != top {
+                       if b.tophash[i] != top {
                                continue
                        }
                        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) {
                if key.len < 32 {
                        // short key, doing lots of comparisons is ok
                        for i := uintptr(0); i < bucketCnt; i++ {
-                               x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
-                               if x == empty {
+                               if b.tophash[i] == empty {
                                        continue
                                }
                                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) {
                // long key, try not to do more comparisons than necessary
                keymaybe := uintptr(bucketCnt)
                for i := uintptr(0); i < bucketCnt; i++ {
-                       x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
-                       if x == empty {
+                       if b.tophash[i] == empty {
                                continue
                        }
                        k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
@@ -400,8 +391,7 @@ dohash:
        }
        for {
                for i := uintptr(0); i < bucketCnt; i++ {
-                       x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
-                       if x != top {
+                       if b.tophash[i] != top {
                                continue
                        }
                        k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))