Skip to content

Commit b096ddb

Browse files
cuiweixiegopherbot
authored andcommitted
internal/runtime/maps: loop invariant code motion with h2(hash) by hand
Change-Id: I0cd9763aeedfe326bc566da39b8be0d0ebd113ec GitHub-Last-Rev: 1ec8864 GitHub-Pull-Request: #74952 Reviewed-on: https://go-review.googlesource.com/c/go/+/694016 Auto-Submit: Michael Pratt <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent a243177 commit b096ddb

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

src/internal/runtime/maps/runtime.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ func runtime_mapaccess1(typ *abi.MapType, m *Map, key unsafe.Pointer) unsafe.Poi
9494

9595
// Probe table.
9696
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
97+
h2Hash := h2(hash)
9798
for ; ; seq = seq.next() {
9899
g := t.groups.group(typ, seq.offset)
99100

100-
match := g.ctrls().matchH2(h2(hash))
101+
match := g.ctrls().matchH2(h2Hash)
101102

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

169170
// Probe table.
170171
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
172+
h2Hash := h2(hash)
171173
for ; ; seq = seq.next() {
172174
g := t.groups.group(typ, seq.offset)
173175

174-
match := g.ctrls().matchH2(h2(hash))
176+
match := g.ctrls().matchH2(h2Hash)
175177

176178
for match != 0 {
177179
i := match.first()
@@ -262,9 +264,10 @@ outer:
262264
var firstDeletedGroup groupReference
263265
var firstDeletedSlot uintptr
264266

267+
h2Hash := h2(hash)
265268
for ; ; seq = seq.next() {
266269
g := t.groups.group(typ, seq.offset)
267-
match := g.ctrls().matchH2(h2(hash))
270+
match := g.ctrls().matchH2(h2Hash)
268271

269272
// Look for an existing slot containing this key.
270273
for match != 0 {
@@ -329,7 +332,7 @@ outer:
329332
slotElem = emem
330333
}
331334

332-
g.ctrls().set(i, ctrl(h2(hash)))
335+
g.ctrls().set(i, ctrl(h2Hash))
333336
t.growthLeft--
334337
t.used++
335338
m.used++

src/internal/runtime/maps/runtime_fast32.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ func runtime_mapaccess1_fast32(typ *abi.MapType, m *Map, key uint32) unsafe.Poin
5555

5656
// Probe table.
5757
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
58+
h2Hash := h2(hash)
5859
for ; ; seq = seq.next() {
5960
g := t.groups.group(typ, seq.offset)
6061

61-
match := g.ctrls().matchH2(h2(hash))
62+
match := g.ctrls().matchH2(h2Hash)
6263

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

125126
// Probe table.
126127
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
128+
h2Hash := h2(hash)
127129
for ; ; seq = seq.next() {
128130
g := t.groups.group(typ, seq.offset)
129131

130-
match := g.ctrls().matchH2(h2(hash))
132+
match := g.ctrls().matchH2(h2Hash)
131133

132134
for match != 0 {
133135
i := match.first()
@@ -245,9 +247,10 @@ outer:
245247
var firstDeletedGroup groupReference
246248
var firstDeletedSlot uintptr
247249

250+
h2Hash := h2(hash)
248251
for ; ; seq = seq.next() {
249252
g := t.groups.group(typ, seq.offset)
250-
match := g.ctrls().matchH2(h2(hash))
253+
match := g.ctrls().matchH2(h2Hash)
251254

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

303306
slotElem = g.elem(typ, i)
304307

305-
g.ctrls().set(i, ctrl(h2(hash)))
308+
g.ctrls().set(i, ctrl(h2Hash))
306309
t.growthLeft--
307310
t.used++
308311
m.used++
@@ -383,9 +386,10 @@ outer:
383386
var firstDeletedGroup groupReference
384387
var firstDeletedSlot uintptr
385388

389+
h2Hash := h2(hash)
386390
for ; ; seq = seq.next() {
387391
g := t.groups.group(typ, seq.offset)
388-
match := g.ctrls().matchH2(h2(hash))
392+
match := g.ctrls().matchH2(h2Hash)
389393

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

436440
slotElem = g.elem(typ, i)
437441

438-
g.ctrls().set(i, ctrl(h2(hash)))
442+
g.ctrls().set(i, ctrl(h2Hash))
439443
t.growthLeft--
440444
t.used++
441445
m.used++

src/internal/runtime/maps/runtime_fast64.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ func runtime_mapaccess1_fast64(typ *abi.MapType, m *Map, key uint64) unsafe.Poin
5555

5656
// Probe table.
5757
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
58+
h2Hash := h2(hash)
5859
for ; ; seq = seq.next() {
5960
g := t.groups.group(typ, seq.offset)
6061

61-
match := g.ctrls().matchH2(h2(hash))
62+
match := g.ctrls().matchH2(h2Hash)
6263

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

125126
// Probe table.
126127
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
128+
129+
h2Hash := h2(hash)
127130
for ; ; seq = seq.next() {
128131
g := t.groups.group(typ, seq.offset)
129132

130-
match := g.ctrls().matchH2(h2(hash))
133+
match := g.ctrls().matchH2(h2Hash)
131134

132135
for match != 0 {
133136
i := match.first()
@@ -245,9 +248,10 @@ outer:
245248
var firstDeletedGroup groupReference
246249
var firstDeletedSlot uintptr
247250

251+
h2Hash := h2(hash)
248252
for ; ; seq = seq.next() {
249253
g := t.groups.group(typ, seq.offset)
250-
match := g.ctrls().matchH2(h2(hash))
254+
match := g.ctrls().matchH2(h2Hash)
251255

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

303307
slotElem = g.elem(typ, i)
304308

305-
g.ctrls().set(i, ctrl(h2(hash)))
309+
g.ctrls().set(i, ctrl(h2Hash))
306310
t.growthLeft--
307311
t.used++
308312
m.used++
@@ -422,9 +426,10 @@ outer:
422426
var firstDeletedGroup groupReference
423427
var firstDeletedSlot uintptr
424428

429+
h2Hash := h2(hash)
425430
for ; ; seq = seq.next() {
426431
g := t.groups.group(typ, seq.offset)
427-
match := g.ctrls().matchH2(h2(hash))
432+
match := g.ctrls().matchH2(h2Hash)
428433

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

475480
slotElem = g.elem(typ, i)
476481

477-
g.ctrls().set(i, ctrl(h2(hash)))
482+
g.ctrls().set(i, ctrl(h2Hash))
478483
t.growthLeft--
479484
t.used++
480485
m.used++

src/internal/runtime/maps/runtime_faststr.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@ func runtime_mapaccess1_faststr(typ *abi.MapType, m *Map, key string) unsafe.Poi
131131

132132
// Probe table.
133133
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
134+
h2Hash := h2(hash)
134135
for ; ; seq = seq.next() {
135136
g := t.groups.group(typ, seq.offset)
136137

137-
match := g.ctrls().matchH2(h2(hash))
138+
match := g.ctrls().matchH2(h2Hash)
138139

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

191192
// Probe table.
192193
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
194+
h2Hash := h2(hash)
193195
for ; ; seq = seq.next() {
194196
g := t.groups.group(typ, seq.offset)
195197

196-
match := g.ctrls().matchH2(h2(hash))
198+
match := g.ctrls().matchH2(h2Hash)
197199

198200
for match != 0 {
199201
i := match.first()
@@ -313,9 +315,10 @@ outer:
313315
var firstDeletedGroup groupReference
314316
var firstDeletedSlot uintptr
315317

318+
h2Hash := h2(hash)
316319
for ; ; seq = seq.next() {
317320
g := t.groups.group(typ, seq.offset)
318-
match := g.ctrls().matchH2(h2(hash))
321+
match := g.ctrls().matchH2(h2Hash)
319322

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

374377
slotElem = g.elem(typ, i)
375378

376-
g.ctrls().set(i, ctrl(h2(hash)))
379+
g.ctrls().set(i, ctrl(h2Hash))
377380
t.growthLeft--
378381
t.used++
379382
m.used++

src/internal/runtime/maps/table.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,11 @@ func (t *table) getWithKey(typ *abi.MapType, hash uintptr, key unsafe.Pointer) (
192192
// load factors, k is less than 32, meaning that the number of false
193193
// positive comparisons we must perform is less than 1/8 per find.
194194
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
195+
h2Hash := h2(hash)
195196
for ; ; seq = seq.next() {
196197
g := t.groups.group(typ, seq.offset)
197198

198-
match := g.ctrls().matchH2(h2(hash))
199+
match := g.ctrls().matchH2(h2Hash)
199200

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

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

231-
match := g.ctrls().matchH2(h2(hash))
233+
match := g.ctrls().matchH2(h2Hash)
232234

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

276+
h2Hash := h2(hash)
274277
for ; ; seq = seq.next() {
275278
g := t.groups.group(typ, seq.offset)
276-
match := g.ctrls().matchH2(h2(hash))
279+
match := g.ctrls().matchH2(h2Hash)
277280

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

351-
g.ctrls().set(i, ctrl(h2(hash)))
354+
g.ctrls().set(i, ctrl(h2Hash))
352355
t.growthLeft--
353356
t.used++
354357
m.used++
@@ -420,9 +423,10 @@ func (t *table) uncheckedPutSlot(typ *abi.MapType, hash uintptr, key, elem unsaf
420423
// Delete returns true if it put a tombstone in t.
421424
func (t *table) Delete(typ *abi.MapType, m *Map, hash uintptr, key unsafe.Pointer) bool {
422425
seq := makeProbeSeq(h1(hash), t.groups.lengthMask)
426+
h2Hash := h2(hash)
423427
for ; ; seq = seq.next() {
424428
g := t.groups.group(typ, seq.offset)
425-
match := g.ctrls().matchH2(h2(hash))
429+
match := g.ctrls().matchH2(h2Hash)
426430

427431
for match != 0 {
428432
i := match.first()

0 commit comments

Comments
 (0)