From: Keith Randall Date: Mon, 4 Nov 2024 23:52:02 +0000 (-0800) Subject: runtime/internal/maps: remove entryMask X-Git-Tag: go1.24rc1~350 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=01e1e5c20438145df65a2fb79c77e3d5c3eb6831;p=gostls13.git runtime/internal/maps: remove entryMask 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 Auto-Submit: Keith Randall Reviewed-by: Michael Pratt Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/reflectdata/map_swiss.go b/src/cmd/compile/internal/reflectdata/map_swiss.go index 629136821b..86c07ef117 100644 --- a/src/cmd/compile/internal/reflectdata/map_swiss.go +++ b/src/cmd/compile/internal/reflectdata/map_swiss.go @@ -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) } diff --git a/src/internal/runtime/maps/group.go b/src/internal/runtime/maps/group.go index aae667c8d8..59df1fb25a 100644 --- a/src/internal/runtime/maps/group.go +++ b/src/internal/runtime/maps/group.go @@ -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, } } diff --git a/src/internal/runtime/maps/table.go b/src/internal/runtime/maps/table.go index 847ff7fa6b..80745e9a72 100644 --- a/src/internal/runtime/maps/table.go +++ b/src/internal/runtime/maps/table.go @@ -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 }