]> Cypherpunks repositories - gostls13.git/commitdiff
internal/runtime/maps: speed up Clear
authorKeith Randall <khr@golang.org>
Wed, 20 Aug 2025 23:53:09 +0000 (16:53 -0700)
committerKeith Randall <khr@golang.org>
Wed, 10 Sep 2025 22:06:08 +0000 (15:06 -0700)
We don't need to know the actual full slots, just whether there
are any or not.

The test for any full slots is simpler on amd64. We don't have to
use PMOVMSKB and do the intreg->floatreg transfer.

Fixes #75097

Change-Id: Iace1c100618d7fc2ac5ddd5fe9e8fe5c9595243f
Reviewed-on: https://go-review.googlesource.com/c/go/+/697875
Reviewed-by: Youlin Feng <fengyoulin@live.com>
Auto-Submit: Keith Randall <khr@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Keith Randall <khr@google.com>
src/internal/runtime/maps/group.go
src/internal/runtime/maps/table.go

index c8d38ba27c8c5d1ba5aa580010a4838d5301df11..a56d32aca0aef5e2c69642c743887511ec61ec8c 100644 (file)
@@ -215,6 +215,12 @@ func (g ctrlGroup) matchFull() bitset {
        return ctrlGroupMatchFull(g)
 }
 
+// anyFull reports whether any slots in the group are full.
+func (g ctrlGroup) anyFull() bool {
+       // A slot is full iff bit 7 is unset. Test whether any slot has bit 7 unset.
+       return (^g)&bitsetMSB != 0
+}
+
 // Portable implementation of matchFull.
 //
 // Note: On AMD64, this is an intrinsic implemented with SIMD instructions. See
index 49f392b8aee1d42c4dfe0b3571c8b17d5bd3241e..a8160befd2b42b6d95bad5098b2cf8864a0273d2 100644 (file)
@@ -606,7 +606,7 @@ func (t *table) Clear(typ *abi.MapType) {
        }
        for i := uint64(0); i <= t.groups.lengthMask; i++ {
                g := t.groups.group(typ, i)
-               if g.ctrls().matchFull() != 0 {
+               if g.ctrls().anyFull() {
                        typedmemclr(typ.Group, g.data)
                }
                g.ctrls().setEmpty()