]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/internal/maps: remove entryMask
authorKeith Randall <khr@golang.org>
Mon, 4 Nov 2024 23:52:02 +0000 (15:52 -0800)
committerGopher Robot <gobot@golang.org>
Sun, 17 Nov 2024 21:09:09 +0000 (21:09 +0000)
It is easily recomputed as capacity-1.

This reduces a table from 40 to 32 bytes (on 64-bit archs).
That gets us down one sizeclass.

Change-Id: Icb74fb2de50baa18ca62052c7b2fe8e6af4c8837
Reviewed-on: https://go-review.googlesource.com/c/go/+/625198
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Keith Randall <khr@google.com>
src/cmd/compile/internal/reflectdata/map_swiss.go
src/internal/runtime/maps/group.go
src/internal/runtime/maps/table.go

index 629136821b5710b71440c868b0bd53146499f7c8..86c07ef117ee633b5c6d02a85284da49df9f6869 100644 (file)
@@ -109,7 +109,6 @@ func swissTableType() *types.Type {
        //     // From groups.
        //     groups_data       unsafe.Pointer
        //     groups_lengthMask uint64
-       //     groups_entryMask  uint64
        // }
        // must match internal/runtime/maps/table.go:table.
        fields := []*types.Field{
@@ -120,7 +119,6 @@ func swissTableType() *types.Type {
                makefield("index", types.Types[types.TINT]),
                makefield("groups_data", types.Types[types.TUNSAFEPTR]),
                makefield("groups_lengthMask", types.Types[types.TUINT64]),
-               makefield("groups_entryMask", types.Types[types.TUINT64]),
        }
 
        n := ir.NewDeclNameAt(src.NoXPos, ir.OTYPE, ir.Pkgs.InternalMaps.Lookup("table"))
@@ -131,9 +129,9 @@ func swissTableType() *types.Type {
        table.SetUnderlying(types.NewStruct(fields))
        types.CalcSize(table)
 
-       // The size of table should be 40 bytes on 64 bit
-       // and 32 bytes on 32 bit platforms.
-       if size := int64(3*2 + 2*1 /* one extra for padding */ + 2*8 + 2*types.PtrSize); table.Size() != size {
+       // The size of table should be 32 bytes on 64 bit
+       // and 24 bytes on 32 bit platforms.
+       if size := int64(3*2 + 2*1 /* one extra for padding */ + 1*8 + 2*types.PtrSize); table.Size() != size {
                base.Fatalf("internal/runtime/maps.table size not correct: got %d, want %d", table.Size(), size)
        }
 
index aae667c8d8124dbe42b52b9f60b0ef7ef7dd3c9d..59df1fb25a0db854b2c127252a58e7a13bd5052b 100644 (file)
@@ -218,9 +218,6 @@ type groupsReference struct {
        // length must be a power of two). This allows computing i%length
        // quickly using bitwise AND.
        lengthMask uint64
-
-       // entryMask is the total number of slots in the groups minus one.
-       entryMask uint64
 }
 
 // newGroups allocates a new array of length groups.
@@ -231,7 +228,6 @@ func newGroups(typ *abi.SwissMapType, length uint64) groupsReference {
                // TODO: make the length type the same throughout.
                data:       newarray(typ.Group, int(length)),
                lengthMask: length - 1,
-               entryMask:  (length * abi.SwissMapGroupSlots) - 1,
        }
 }
 
index 847ff7fa6bbb56667ed5b81a521fc1a032d13a11..80745e9a7265ee0430219e27bd5c20bb86282163 100644 (file)
@@ -803,7 +803,8 @@ func (it *Iter) Next() {
                // table for key selection if the table has grown. See comment
                // on grown below.
 
-               if it.entryIdx > it.tab.groups.entryMask {
+               entryMask := uint64(it.tab.capacity) - 1
+               if it.entryIdx > entryMask {
                        // Continue to next table.
                        continue
                }
@@ -819,7 +820,7 @@ func (it *Iter) Next() {
                // it is cheaper to check a single slot than do a full control
                // match.
 
-               entryIdx := (it.entryIdx + it.entryOffset) & it.tab.groups.entryMask
+               entryIdx := (it.entryIdx + it.entryOffset) & entryMask
                slotIdx := uintptr(entryIdx & (abi.SwissMapGroupSlots - 1))
                if slotIdx == 0 || it.group.data == nil {
                        // Only compute the group (a) when we switch
@@ -864,7 +865,7 @@ func (it *Iter) Next() {
                        return
                }
 
-next:
+       next:
                it.entryIdx++
 
                // Slow path: use a match on the control word to jump ahead to
@@ -885,8 +886,8 @@ next:
                // double-check the control value.
 
                var groupMatch bitset
-               for it.entryIdx <= it.tab.groups.entryMask {
-                       entryIdx := (it.entryIdx + it.entryOffset) & it.tab.groups.entryMask
+               for it.entryIdx <= entryMask {
+                       entryIdx := (it.entryIdx + it.entryOffset) & entryMask
                        slotIdx := uintptr(entryIdx & (abi.SwissMapGroupSlots - 1))
 
                        if slotIdx == 0 || it.group.data == nil {
@@ -918,7 +919,7 @@ next:
 
                                i := groupMatch.first()
                                it.entryIdx += uint64(i - slotIdx)
-                               if it.entryIdx > it.tab.groups.entryMask {
+                               if it.entryIdx > entryMask {
                                        // Past the end of this table's iteration.
                                        continue
                                }