aboutsummaryrefslogtreecommitdiff
path: root/src/internal/runtime
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2024-11-18 16:23:43 -0800
committerKeith Randall <khr@golang.org>2024-11-19 21:15:45 +0000
commitc14fc500c772c35050699f3bcc3688db3d0fbed2 (patch)
treec23de09b821e429fb3d934c7bcf7e1c36495d01f /src/internal/runtime
parent253a9933d181ce5e57de81f56d7e50565c423f0f (diff)
downloadgo-c14fc500c772c35050699f3bcc3688db3d0fbed2.tar.xz
internal/runtime/maps: assume constant elem offset with int64 and string keys
Note this doesn't work with int32 keys because alignment padding can change the offset of the element. Change-Id: I27804d3cfc7cc1b7f995f7e29630f0824f0ee899 Reviewed-on: https://go-review.googlesource.com/c/go/+/629418 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/internal/runtime')
-rw-r--r--src/internal/runtime/maps/runtime_fast64_swiss.go8
-rw-r--r--src/internal/runtime/maps/runtime_faststr_swiss.go9
2 files changed, 9 insertions, 8 deletions
diff --git a/src/internal/runtime/maps/runtime_fast64_swiss.go b/src/internal/runtime/maps/runtime_fast64_swiss.go
index f4716dffda..90e84f83d2 100644
--- a/src/internal/runtime/maps/runtime_fast64_swiss.go
+++ b/src/internal/runtime/maps/runtime_fast64_swiss.go
@@ -39,7 +39,7 @@ func runtime_mapaccess1_fast64(typ *abi.SwissMapType, m *Map, key uint64) unsafe
slotSize := typ.SlotSize
for full != 0 {
if key == *(*uint64)(slotKey) && full&(1<<7) != 0 {
- slotElem := unsafe.Pointer(uintptr(slotKey) + typ.ElemOff)
+ slotElem := unsafe.Pointer(uintptr(slotKey) + 8)
return slotElem
}
slotKey = unsafe.Pointer(uintptr(slotKey) + slotSize)
@@ -66,7 +66,7 @@ func runtime_mapaccess1_fast64(typ *abi.SwissMapType, m *Map, key uint64) unsafe
slotKey := g.key(typ, i)
if key == *(*uint64)(slotKey) {
- slotElem := unsafe.Pointer(uintptr(slotKey) + typ.ElemOff)
+ slotElem := unsafe.Pointer(uintptr(slotKey) + 8)
return slotElem
}
match = match.removeFirst()
@@ -107,7 +107,7 @@ func runtime_mapaccess2_fast64(typ *abi.SwissMapType, m *Map, key uint64) (unsaf
slotSize := typ.SlotSize
for full != 0 {
if key == *(*uint64)(slotKey) && full&(1<<7) != 0 {
- slotElem := unsafe.Pointer(uintptr(slotKey) + typ.ElemOff)
+ slotElem := unsafe.Pointer(uintptr(slotKey) + 8)
return slotElem, true
}
slotKey = unsafe.Pointer(uintptr(slotKey) + slotSize)
@@ -134,7 +134,7 @@ func runtime_mapaccess2_fast64(typ *abi.SwissMapType, m *Map, key uint64) (unsaf
slotKey := g.key(typ, i)
if key == *(*uint64)(slotKey) {
- slotElem := unsafe.Pointer(uintptr(slotKey) + typ.ElemOff)
+ slotElem := unsafe.Pointer(uintptr(slotKey) + 8)
return slotElem, true
}
match = match.removeFirst()
diff --git a/src/internal/runtime/maps/runtime_faststr_swiss.go b/src/internal/runtime/maps/runtime_faststr_swiss.go
index eed8d8666d..a104945501 100644
--- a/src/internal/runtime/maps/runtime_faststr_swiss.go
+++ b/src/internal/runtime/maps/runtime_faststr_swiss.go
@@ -8,6 +8,7 @@ package maps
import (
"internal/abi"
+ "internal/goarch"
"internal/race"
"internal/runtime/sys"
"unsafe"
@@ -48,7 +49,7 @@ func (m *Map) getWithoutKeySmallFastStr(typ *abi.SwissMapType, key string) unsaf
// There's exactly one slot that passed the quick test. Do the single expensive comparison.
slotKey = g.key(typ, uintptr(j))
if key == *(*string)(slotKey) {
- return unsafe.Pointer(uintptr(slotKey) + typ.ElemOff)
+ return unsafe.Pointer(uintptr(slotKey) + 2*goarch.PtrSize)
}
return nil
}
@@ -62,7 +63,7 @@ dohash:
for range abi.SwissMapGroupSlots {
if uint8(ctrls) == h2 && key == *(*string)(slotKey) {
- return unsafe.Pointer(uintptr(slotKey) + typ.ElemOff)
+ return unsafe.Pointer(uintptr(slotKey) + 2*goarch.PtrSize)
}
slotKey = unsafe.Pointer(uintptr(slotKey) + slotSize)
ctrls >>= 8
@@ -141,7 +142,7 @@ func runtime_mapaccess1_faststr(typ *abi.SwissMapType, m *Map, key string) unsaf
slotKey := g.key(typ, i)
if key == *(*string)(slotKey) {
- slotElem := unsafe.Pointer(uintptr(slotKey) + typ.ElemOff)
+ slotElem := unsafe.Pointer(uintptr(slotKey) + 2*goarch.PtrSize)
return slotElem
}
match = match.removeFirst()
@@ -199,7 +200,7 @@ func runtime_mapaccess2_faststr(typ *abi.SwissMapType, m *Map, key string) (unsa
slotKey := g.key(typ, i)
if key == *(*string)(slotKey) {
- slotElem := unsafe.Pointer(uintptr(slotKey) + typ.ElemOff)
+ slotElem := unsafe.Pointer(uintptr(slotKey) + 2*goarch.PtrSize)
return slotElem, true
}
match = match.removeFirst()