Skip to content

internal/runtime/maps: loop invariant code motion with h2(hash) by hand #74952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/internal/runtime/maps/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ func runtime_mapaccess1(typ *abi.MapType, m *Map, key unsafe.Pointer) unsafe.Poi

// Probe table.
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)

match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

for match != 0 {
i := match.first()
Expand Down Expand Up @@ -168,10 +169,11 @@ func runtime_mapaccess2(typ *abi.MapType, m *Map, key unsafe.Pointer) (unsafe.Po

// Probe table.
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)

match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

for match != 0 {
i := match.first()
Expand Down Expand Up @@ -262,9 +264,10 @@ outer:
var firstDeletedGroup groupReference
var firstDeletedSlot uintptr

h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)
match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

// Look for an existing slot containing this key.
for match != 0 {
Expand Down Expand Up @@ -329,7 +332,7 @@ outer:
slotElem = emem
}

g.ctrls().set(i, ctrl(h2(hash)))
g.ctrls().set(i, ctrl(h2Hash))
t.growthLeft--
t.used++
m.used++
Expand Down
16 changes: 10 additions & 6 deletions src/internal/runtime/maps/runtime_fast32.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ func runtime_mapaccess1_fast32(typ *abi.MapType, m *Map, key uint32) unsafe.Poin

// Probe table.
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)

match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

for match != 0 {
i := match.first()
Expand Down Expand Up @@ -124,10 +125,11 @@ func runtime_mapaccess2_fast32(typ *abi.MapType, m *Map, key uint32) (unsafe.Poi

// Probe table.
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)

match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

for match != 0 {
i := match.first()
Expand Down Expand Up @@ -245,9 +247,10 @@ outer:
var firstDeletedGroup groupReference
var firstDeletedSlot uintptr

h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)
match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

// Look for an existing slot containing this key.
for match != 0 {
Expand Down Expand Up @@ -302,7 +305,7 @@ outer:

slotElem = g.elem(typ, i)

g.ctrls().set(i, ctrl(h2(hash)))
g.ctrls().set(i, ctrl(h2Hash))
t.growthLeft--
t.used++
m.used++
Expand Down Expand Up @@ -383,9 +386,10 @@ outer:
var firstDeletedGroup groupReference
var firstDeletedSlot uintptr

h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)
match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

// Look for an existing slot containing this key.
for match != 0 {
Expand Down Expand Up @@ -435,7 +439,7 @@ outer:

slotElem = g.elem(typ, i)

g.ctrls().set(i, ctrl(h2(hash)))
g.ctrls().set(i, ctrl(h2Hash))
t.growthLeft--
t.used++
m.used++
Expand Down
17 changes: 11 additions & 6 deletions src/internal/runtime/maps/runtime_fast64.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ func runtime_mapaccess1_fast64(typ *abi.MapType, m *Map, key uint64) unsafe.Poin

// Probe table.
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)

match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

for match != 0 {
i := match.first()
Expand Down Expand Up @@ -124,10 +125,12 @@ func runtime_mapaccess2_fast64(typ *abi.MapType, m *Map, key uint64) (unsafe.Poi

// Probe table.
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)

h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)

match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

for match != 0 {
i := match.first()
Expand Down Expand Up @@ -245,9 +248,10 @@ outer:
var firstDeletedGroup groupReference
var firstDeletedSlot uintptr

h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)
match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

// Look for an existing slot containing this key.
for match != 0 {
Expand Down Expand Up @@ -302,7 +306,7 @@ outer:

slotElem = g.elem(typ, i)

g.ctrls().set(i, ctrl(h2(hash)))
g.ctrls().set(i, ctrl(h2Hash))
t.growthLeft--
t.used++
m.used++
Expand Down Expand Up @@ -422,9 +426,10 @@ outer:
var firstDeletedGroup groupReference
var firstDeletedSlot uintptr

h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)
match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

// Look for an existing slot containing this key.
for match != 0 {
Expand Down Expand Up @@ -474,7 +479,7 @@ outer:

slotElem = g.elem(typ, i)

g.ctrls().set(i, ctrl(h2(hash)))
g.ctrls().set(i, ctrl(h2Hash))
t.growthLeft--
t.used++
m.used++
Expand Down
11 changes: 7 additions & 4 deletions src/internal/runtime/maps/runtime_faststr.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ func runtime_mapaccess1_faststr(typ *abi.MapType, m *Map, key string) unsafe.Poi

// Probe table.
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)

match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

for match != 0 {
i := match.first()
Expand Down Expand Up @@ -190,10 +191,11 @@ func runtime_mapaccess2_faststr(typ *abi.MapType, m *Map, key string) (unsafe.Po

// Probe table.
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)

match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

for match != 0 {
i := match.first()
Expand Down Expand Up @@ -313,9 +315,10 @@ outer:
var firstDeletedGroup groupReference
var firstDeletedSlot uintptr

h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)
match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

// Look for an existing slot containing this key.
for match != 0 {
Expand Down Expand Up @@ -373,7 +376,7 @@ outer:

slotElem = g.elem(typ, i)

g.ctrls().set(i, ctrl(h2(hash)))
g.ctrls().set(i, ctrl(h2Hash))
t.growthLeft--
t.used++
m.used++
Expand Down
14 changes: 9 additions & 5 deletions src/internal/runtime/maps/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ func (t *table) getWithKey(typ *abi.MapType, hash uintptr, key unsafe.Pointer) (
// load factors, k is less than 32, meaning that the number of false
// positive comparisons we must perform is less than 1/8 per find.
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)

match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

for match != 0 {
i := match.first()
Expand Down Expand Up @@ -225,10 +226,11 @@ func (t *table) getWithKey(typ *abi.MapType, hash uintptr, key unsafe.Pointer) (

func (t *table) getWithoutKey(typ *abi.MapType, hash uintptr, key unsafe.Pointer) (unsafe.Pointer, bool) {
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)

match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

for match != 0 {
i := match.first()
Expand Down Expand Up @@ -271,9 +273,10 @@ func (t *table) PutSlot(typ *abi.MapType, m *Map, hash uintptr, key unsafe.Point
var firstDeletedGroup groupReference
var firstDeletedSlot uintptr

h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)
match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

// Look for an existing slot containing this key.
for match != 0 {
Expand Down Expand Up @@ -348,7 +351,7 @@ func (t *table) PutSlot(typ *abi.MapType, m *Map, hash uintptr, key unsafe.Point
slotElem = emem
}

g.ctrls().set(i, ctrl(h2(hash)))
g.ctrls().set(i, ctrl(h2Hash))
t.growthLeft--
t.used++
m.used++
Expand Down Expand Up @@ -420,9 +423,10 @@ func (t *table) uncheckedPutSlot(typ *abi.MapType, hash uintptr, key, elem unsaf
// Delete returns true if it put a tombstone in t.
func (t *table) Delete(typ *abi.MapType, m *Map, hash uintptr, key unsafe.Pointer) bool {
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
h2Hash := h2(hash)
for ; ; seq = seq.next() {
g := t.groups.group(typ, seq.offset)
match := g.ctrls().matchH2(h2(hash))
match := g.ctrls().matchH2(h2Hash)

for match != 0 {
i := match.first()
Expand Down