mirror of
https://github.com/golang/go
synced 2024-11-15 04:40:28 -07:00
internal/runtime/maps: use uintptr instead of uint32 for index in group
This avoids some zero-extension ops on 64-bit machines. Based on khr@'s CL 619479. For #54766. Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest-swissmap Change-Id: Ie9a56da26382dc9e515c613abc8cf6fec3767671 Reviewed-on: https://go-review.googlesource.com/c/go/+/620216 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
This commit is contained in:
parent
d95b7980aa
commit
0b652e3ef6
@ -82,7 +82,7 @@ func (m *Map) KeyFromFullGroup(typ *abi.SwissMapType) unsafe.Pointer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// All full or deleted slots.
|
// All full or deleted slots.
|
||||||
for j := uint32(0); j < abi.SwissMapGroupSlots; j++ {
|
for j := uintptr(0); j < abi.SwissMapGroupSlots; j++ {
|
||||||
if g.ctrls().get(j) == ctrlDeleted {
|
if g.ctrls().get(j) == ctrlDeleted {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -40,8 +40,8 @@ type bitset uint64
|
|||||||
// first control byte in the group that has the MSB set.
|
// first control byte in the group that has the MSB set.
|
||||||
//
|
//
|
||||||
// Returns abi.SwissMapGroupSlots if the bitset is empty.
|
// Returns abi.SwissMapGroupSlots if the bitset is empty.
|
||||||
func (b bitset) first() uint32 {
|
func (b bitset) first() uintptr {
|
||||||
return uint32(sys.TrailingZeros64(uint64(b))) >> 3
|
return uintptr(sys.TrailingZeros64(uint64(b))) >> 3
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeFirst removes the first set bit (that is, resets the least significant set bit to 0).
|
// removeFirst removes the first set bit (that is, resets the least significant set bit to 0).
|
||||||
@ -64,7 +64,7 @@ type ctrl uint8
|
|||||||
type ctrlGroup uint64
|
type ctrlGroup uint64
|
||||||
|
|
||||||
// get returns the i-th control byte.
|
// get returns the i-th control byte.
|
||||||
func (g *ctrlGroup) get(i uint32) ctrl {
|
func (g *ctrlGroup) get(i uintptr) ctrl {
|
||||||
if goarch.BigEndian {
|
if goarch.BigEndian {
|
||||||
return *(*ctrl)(unsafe.Add(unsafe.Pointer(g), 7-i))
|
return *(*ctrl)(unsafe.Add(unsafe.Pointer(g), 7-i))
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ func (g *ctrlGroup) get(i uint32) ctrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set sets the i-th control byte.
|
// set sets the i-th control byte.
|
||||||
func (g *ctrlGroup) set(i uint32, c ctrl) {
|
func (g *ctrlGroup) set(i uintptr, c ctrl) {
|
||||||
if goarch.BigEndian {
|
if goarch.BigEndian {
|
||||||
*(*ctrl)(unsafe.Add(unsafe.Pointer(g), 7-i)) = c
|
*(*ctrl)(unsafe.Add(unsafe.Pointer(g), 7-i)) = c
|
||||||
return
|
return
|
||||||
@ -202,15 +202,15 @@ func (g *groupReference) ctrls() *ctrlGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// key returns a pointer to the key at index i.
|
// key returns a pointer to the key at index i.
|
||||||
func (g *groupReference) key(typ *abi.SwissMapType, i uint32) unsafe.Pointer {
|
func (g *groupReference) key(typ *abi.SwissMapType, i uintptr) unsafe.Pointer {
|
||||||
offset := groupSlotsOffset + uintptr(i)*typ.SlotSize
|
offset := groupSlotsOffset + i*typ.SlotSize
|
||||||
|
|
||||||
return unsafe.Pointer(uintptr(g.data) + offset)
|
return unsafe.Pointer(uintptr(g.data) + offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
// elem returns a pointer to the element at index i.
|
// elem returns a pointer to the element at index i.
|
||||||
func (g *groupReference) elem(typ *abi.SwissMapType, i uint32) unsafe.Pointer {
|
func (g *groupReference) elem(typ *abi.SwissMapType, i uintptr) unsafe.Pointer {
|
||||||
offset := groupSlotsOffset + uintptr(i)*typ.SlotSize + typ.ElemOff
|
offset := groupSlotsOffset + i*typ.SlotSize + typ.ElemOff
|
||||||
|
|
||||||
return unsafe.Pointer(uintptr(g.data) + offset)
|
return unsafe.Pointer(uintptr(g.data) + offset)
|
||||||
}
|
}
|
||||||
|
@ -430,7 +430,7 @@ func (m *Map) getWithKeySmall(typ *abi.SwissMapType, hash uintptr, key unsafe.Po
|
|||||||
h2 := uint8(h2(hash))
|
h2 := uint8(h2(hash))
|
||||||
ctrls := *g.ctrls()
|
ctrls := *g.ctrls()
|
||||||
|
|
||||||
for i := uint32(0); i < abi.SwissMapGroupSlots; i++ {
|
for i := uintptr(0); i < abi.SwissMapGroupSlots; i++ {
|
||||||
c := uint8(ctrls)
|
c := uint8(ctrls)
|
||||||
ctrls >>= 8
|
ctrls >>= 8
|
||||||
if c != h2 {
|
if c != h2 {
|
||||||
@ -590,7 +590,7 @@ func (m *Map) growToTable(typ *abi.SwissMapType) {
|
|||||||
data: m.dirPtr,
|
data: m.dirPtr,
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := uint32(0); i < abi.SwissMapGroupSlots; i++ {
|
for i := uintptr(0); i < abi.SwissMapGroupSlots; i++ {
|
||||||
if (g.ctrls().get(i) & ctrlEmpty) == ctrlEmpty {
|
if (g.ctrls().get(i) & ctrlEmpty) == ctrlEmpty {
|
||||||
// Empty
|
// Empty
|
||||||
continue
|
continue
|
||||||
|
@ -21,7 +21,7 @@ func (m *Map) getWithoutKeySmallFast32(typ *abi.SwissMapType, hash uintptr, key
|
|||||||
h2 := uint8(h2(hash))
|
h2 := uint8(h2(hash))
|
||||||
ctrls := *g.ctrls()
|
ctrls := *g.ctrls()
|
||||||
|
|
||||||
for i := uint32(0); i < 8; i++ {
|
for i := uintptr(0); i < 8; i++ {
|
||||||
c := uint8(ctrls)
|
c := uint8(ctrls)
|
||||||
ctrls >>= 8
|
ctrls >>= 8
|
||||||
if c != h2 {
|
if c != h2 {
|
||||||
@ -245,7 +245,7 @@ outer:
|
|||||||
// we find, which we'll use to insert the new entry if
|
// we find, which we'll use to insert the new entry if
|
||||||
// necessary.
|
// necessary.
|
||||||
var firstDeletedGroup groupReference
|
var firstDeletedGroup groupReference
|
||||||
var firstDeletedSlot uint32
|
var firstDeletedSlot uintptr
|
||||||
|
|
||||||
for ; ; seq = seq.next() {
|
for ; ; seq = seq.next() {
|
||||||
g := t.groups.group(typ, seq.offset)
|
g := t.groups.group(typ, seq.offset)
|
||||||
@ -272,7 +272,7 @@ outer:
|
|||||||
// Finding an empty slot means we've reached the end of
|
// Finding an empty slot means we've reached the end of
|
||||||
// the probe sequence.
|
// the probe sequence.
|
||||||
|
|
||||||
var i uint32
|
var i uintptr
|
||||||
|
|
||||||
// If we found a deleted slot along the way, we
|
// If we found a deleted slot along the way, we
|
||||||
// can replace it without consuming growthLeft.
|
// can replace it without consuming growthLeft.
|
||||||
@ -386,7 +386,7 @@ outer:
|
|||||||
// As we look for a match, keep track of the first deleted slot we
|
// As we look for a match, keep track of the first deleted slot we
|
||||||
// find, which we'll use to insert the new entry if necessary.
|
// find, which we'll use to insert the new entry if necessary.
|
||||||
var firstDeletedGroup groupReference
|
var firstDeletedGroup groupReference
|
||||||
var firstDeletedSlot uint32
|
var firstDeletedSlot uintptr
|
||||||
|
|
||||||
for ; ; seq = seq.next() {
|
for ; ; seq = seq.next() {
|
||||||
g := t.groups.group(typ, seq.offset)
|
g := t.groups.group(typ, seq.offset)
|
||||||
@ -413,7 +413,7 @@ outer:
|
|||||||
// Finding an empty slot means we've reached the end of
|
// Finding an empty slot means we've reached the end of
|
||||||
// the probe sequence.
|
// the probe sequence.
|
||||||
|
|
||||||
var i uint32
|
var i uintptr
|
||||||
|
|
||||||
// If we found a deleted slot along the way, we
|
// If we found a deleted slot along the way, we
|
||||||
// can replace it without consuming growthLeft.
|
// can replace it without consuming growthLeft.
|
||||||
|
@ -21,7 +21,7 @@ func (m *Map) getWithoutKeySmallFast64(typ *abi.SwissMapType, hash uintptr, key
|
|||||||
h2 := uint8(h2(hash))
|
h2 := uint8(h2(hash))
|
||||||
ctrls := *g.ctrls()
|
ctrls := *g.ctrls()
|
||||||
|
|
||||||
for i := uint32(0); i < 8; i++ {
|
for i := uintptr(0); i < 8; i++ {
|
||||||
c := uint8(ctrls)
|
c := uint8(ctrls)
|
||||||
ctrls >>= 8
|
ctrls >>= 8
|
||||||
if c != h2 {
|
if c != h2 {
|
||||||
@ -245,7 +245,7 @@ outer:
|
|||||||
// we find, which we'll use to insert the new entry if
|
// we find, which we'll use to insert the new entry if
|
||||||
// necessary.
|
// necessary.
|
||||||
var firstDeletedGroup groupReference
|
var firstDeletedGroup groupReference
|
||||||
var firstDeletedSlot uint32
|
var firstDeletedSlot uintptr
|
||||||
|
|
||||||
for ; ; seq = seq.next() {
|
for ; ; seq = seq.next() {
|
||||||
g := t.groups.group(typ, seq.offset)
|
g := t.groups.group(typ, seq.offset)
|
||||||
@ -272,7 +272,7 @@ outer:
|
|||||||
// Finding an empty slot means we've reached the end of
|
// Finding an empty slot means we've reached the end of
|
||||||
// the probe sequence.
|
// the probe sequence.
|
||||||
|
|
||||||
var i uint32
|
var i uintptr
|
||||||
|
|
||||||
// If we found a deleted slot along the way, we
|
// If we found a deleted slot along the way, we
|
||||||
// can replace it without consuming growthLeft.
|
// can replace it without consuming growthLeft.
|
||||||
@ -424,7 +424,7 @@ outer:
|
|||||||
// we find, which we'll use to insert the new entry if
|
// we find, which we'll use to insert the new entry if
|
||||||
// necessary.
|
// necessary.
|
||||||
var firstDeletedGroup groupReference
|
var firstDeletedGroup groupReference
|
||||||
var firstDeletedSlot uint32
|
var firstDeletedSlot uintptr
|
||||||
|
|
||||||
for ; ; seq = seq.next() {
|
for ; ; seq = seq.next() {
|
||||||
g := t.groups.group(typ, seq.offset)
|
g := t.groups.group(typ, seq.offset)
|
||||||
@ -451,7 +451,7 @@ outer:
|
|||||||
// Finding an empty slot means we've reached the end of
|
// Finding an empty slot means we've reached the end of
|
||||||
// the probe sequence.
|
// the probe sequence.
|
||||||
|
|
||||||
var i uint32
|
var i uintptr
|
||||||
|
|
||||||
// If we found a deleted slot along the way, we
|
// If we found a deleted slot along the way, we
|
||||||
// can replace it without consuming growthLeft.
|
// can replace it without consuming growthLeft.
|
||||||
|
@ -23,7 +23,7 @@ func (m *Map) getWithoutKeySmallFastStr(typ *abi.SwissMapType, hash uintptr, key
|
|||||||
h2 := uint8(h2(hash))
|
h2 := uint8(h2(hash))
|
||||||
ctrls := *g.ctrls()
|
ctrls := *g.ctrls()
|
||||||
|
|
||||||
for i := uint32(0); i < abi.SwissMapGroupSlots; i++ {
|
for i := uintptr(0); i < abi.SwissMapGroupSlots; i++ {
|
||||||
c := uint8(ctrls)
|
c := uint8(ctrls)
|
||||||
ctrls >>= 8
|
ctrls >>= 8
|
||||||
if c != h2 {
|
if c != h2 {
|
||||||
@ -249,7 +249,7 @@ outer:
|
|||||||
// we find, which we'll use to insert the new entry if
|
// we find, which we'll use to insert the new entry if
|
||||||
// necessary.
|
// necessary.
|
||||||
var firstDeletedGroup groupReference
|
var firstDeletedGroup groupReference
|
||||||
var firstDeletedSlot uint32
|
var firstDeletedSlot uintptr
|
||||||
|
|
||||||
for ; ; seq = seq.next() {
|
for ; ; seq = seq.next() {
|
||||||
g := t.groups.group(typ, seq.offset)
|
g := t.groups.group(typ, seq.offset)
|
||||||
@ -279,7 +279,7 @@ outer:
|
|||||||
// Finding an empty slot means we've reached the end of
|
// Finding an empty slot means we've reached the end of
|
||||||
// the probe sequence.
|
// the probe sequence.
|
||||||
|
|
||||||
var i uint32
|
var i uintptr
|
||||||
|
|
||||||
// If we found a deleted slot along the way, we
|
// If we found a deleted slot along the way, we
|
||||||
// can replace it without consuming growthLeft.
|
// can replace it without consuming growthLeft.
|
||||||
|
@ -245,7 +245,7 @@ outer:
|
|||||||
// we find, which we'll use to insert the new entry if
|
// we find, which we'll use to insert the new entry if
|
||||||
// necessary.
|
// necessary.
|
||||||
var firstDeletedGroup groupReference
|
var firstDeletedGroup groupReference
|
||||||
var firstDeletedSlot uint32
|
var firstDeletedSlot uintptr
|
||||||
|
|
||||||
for ; ; seq = seq.next() {
|
for ; ; seq = seq.next() {
|
||||||
g := t.groups.group(typ, seq.offset)
|
g := t.groups.group(typ, seq.offset)
|
||||||
@ -282,7 +282,7 @@ outer:
|
|||||||
// Finding an empty slot means we've reached the end of
|
// Finding an empty slot means we've reached the end of
|
||||||
// the probe sequence.
|
// the probe sequence.
|
||||||
|
|
||||||
var i uint32
|
var i uintptr
|
||||||
|
|
||||||
// If we found a deleted slot along the way, we
|
// If we found a deleted slot along the way, we
|
||||||
// can replace it without consuming growthLeft.
|
// can replace it without consuming growthLeft.
|
||||||
|
@ -271,7 +271,7 @@ func (t *table) PutSlot(typ *abi.SwissMapType, m *Map, hash uintptr, key unsafe.
|
|||||||
// As we look for a match, keep track of the first deleted slot we
|
// As we look for a match, keep track of the first deleted slot we
|
||||||
// find, which we'll use to insert the new entry if necessary.
|
// find, which we'll use to insert the new entry if necessary.
|
||||||
var firstDeletedGroup groupReference
|
var firstDeletedGroup groupReference
|
||||||
var firstDeletedSlot uint32
|
var firstDeletedSlot uintptr
|
||||||
|
|
||||||
for ; ; seq = seq.next() {
|
for ; ; seq = seq.next() {
|
||||||
g := t.groups.group(typ, seq.offset)
|
g := t.groups.group(typ, seq.offset)
|
||||||
@ -308,7 +308,7 @@ func (t *table) PutSlot(typ *abi.SwissMapType, m *Map, hash uintptr, key unsafe.
|
|||||||
// Finding an empty slot means we've reached the end of
|
// Finding an empty slot means we've reached the end of
|
||||||
// the probe sequence.
|
// the probe sequence.
|
||||||
|
|
||||||
var i uint32
|
var i uintptr
|
||||||
|
|
||||||
// If we found a deleted slot along the way, we can
|
// If we found a deleted slot along the way, we can
|
||||||
// replace it without consuming growthLeft.
|
// replace it without consuming growthLeft.
|
||||||
@ -618,7 +618,7 @@ func (it *Iter) Next() {
|
|||||||
// Map was small at Init.
|
// Map was small at Init.
|
||||||
g := it.groupSmall
|
g := it.groupSmall
|
||||||
for ; it.entryIdx < abi.SwissMapGroupSlots; it.entryIdx++ {
|
for ; it.entryIdx < abi.SwissMapGroupSlots; it.entryIdx++ {
|
||||||
k := uint32(it.entryIdx+it.entryOffset) % abi.SwissMapGroupSlots
|
k := uintptr(it.entryIdx+it.entryOffset) % abi.SwissMapGroupSlots
|
||||||
|
|
||||||
if (g.ctrls().get(k) & ctrlEmpty) == ctrlEmpty {
|
if (g.ctrls().get(k) & ctrlEmpty) == ctrlEmpty {
|
||||||
// Empty or deleted.
|
// Empty or deleted.
|
||||||
@ -745,7 +745,7 @@ func (it *Iter) Next() {
|
|||||||
// on grown below.
|
// on grown below.
|
||||||
for ; it.entryIdx <= it.tab.groups.entryMask; it.entryIdx++ {
|
for ; it.entryIdx <= it.tab.groups.entryMask; it.entryIdx++ {
|
||||||
entryIdx := (it.entryIdx + it.entryOffset) & it.tab.groups.entryMask
|
entryIdx := (it.entryIdx + it.entryOffset) & it.tab.groups.entryMask
|
||||||
slotIdx := uint32(entryIdx & (abi.SwissMapGroupSlots - 1))
|
slotIdx := uintptr(entryIdx & (abi.SwissMapGroupSlots - 1))
|
||||||
|
|
||||||
if slotIdx == 0 || g.data == nil {
|
if slotIdx == 0 || g.data == nil {
|
||||||
// Only compute the group (a) when we switch
|
// Only compute the group (a) when we switch
|
||||||
@ -922,7 +922,7 @@ func (t *table) split(typ *abi.SwissMapType, m *Map) {
|
|||||||
|
|
||||||
for i := uint64(0); i <= t.groups.lengthMask; i++ {
|
for i := uint64(0); i <= t.groups.lengthMask; i++ {
|
||||||
g := t.groups.group(typ, i)
|
g := t.groups.group(typ, i)
|
||||||
for j := uint32(0); j < abi.SwissMapGroupSlots; j++ {
|
for j := uintptr(0); j < abi.SwissMapGroupSlots; j++ {
|
||||||
if (g.ctrls().get(j) & ctrlEmpty) == ctrlEmpty {
|
if (g.ctrls().get(j) & ctrlEmpty) == ctrlEmpty {
|
||||||
// Empty or deleted
|
// Empty or deleted
|
||||||
continue
|
continue
|
||||||
@ -968,7 +968,7 @@ func (t *table) grow(typ *abi.SwissMapType, m *Map, newCapacity uint16) {
|
|||||||
if t.capacity > 0 {
|
if t.capacity > 0 {
|
||||||
for i := uint64(0); i <= t.groups.lengthMask; i++ {
|
for i := uint64(0); i <= t.groups.lengthMask; i++ {
|
||||||
g := t.groups.group(typ, i)
|
g := t.groups.group(typ, i)
|
||||||
for j := uint32(0); j < abi.SwissMapGroupSlots; j++ {
|
for j := uintptr(0); j < abi.SwissMapGroupSlots; j++ {
|
||||||
if (g.ctrls().get(j) & ctrlEmpty) == ctrlEmpty {
|
if (g.ctrls().get(j) & ctrlEmpty) == ctrlEmpty {
|
||||||
// Empty or deleted
|
// Empty or deleted
|
||||||
continue
|
continue
|
||||||
|
@ -24,7 +24,7 @@ func (t *table) checkInvariants(typ *abi.SwissMapType, m *Map) {
|
|||||||
var empty uint16
|
var empty uint16
|
||||||
for i := uint64(0); i <= t.groups.lengthMask; i++ {
|
for i := uint64(0); i <= t.groups.lengthMask; i++ {
|
||||||
g := t.groups.group(typ, i)
|
g := t.groups.group(typ, i)
|
||||||
for j := uint32(0); j < abi.SwissMapGroupSlots; j++ {
|
for j := uintptr(0); j < abi.SwissMapGroupSlots; j++ {
|
||||||
c := g.ctrls().get(j)
|
c := g.ctrls().get(j)
|
||||||
switch {
|
switch {
|
||||||
case c == ctrlDeleted:
|
case c == ctrlDeleted:
|
||||||
@ -96,7 +96,7 @@ func (t *table) Print(typ *abi.SwissMapType, m *Map) {
|
|||||||
|
|
||||||
g := t.groups.group(typ, i)
|
g := t.groups.group(typ, i)
|
||||||
ctrls := g.ctrls()
|
ctrls := g.ctrls()
|
||||||
for j := uint32(0); j < abi.SwissMapGroupSlots; j++ {
|
for j := uintptr(0); j < abi.SwissMapGroupSlots; j++ {
|
||||||
print("\t\t\tslot ", j, "\n")
|
print("\t\t\tslot ", j, "\n")
|
||||||
|
|
||||||
c := ctrls.get(j)
|
c := ctrls.get(j)
|
||||||
|
Loading…
Reference in New Issue
Block a user