From: Jorropo Date: Sun, 7 Dec 2025 02:19:47 +0000 (+0100) Subject: cmd/compile: improve PopCount's limits modeling and add bruteforce tests X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f35fb95503575f9a198c21b34db15ae5f354b635;p=gostls13.git cmd/compile: improve PopCount's limits modeling and add bruteforce tests This make PopCount perfect within the limitations limits can represent. Change-Id: Ia52e5d79064ad8109117f009c5390a6eba8ccd98 Reviewed-on: https://go-review.googlesource.com/c/go/+/727782 LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Carlos Amedee Auto-Submit: Jorropo Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go index 233d0b30d1..3de964f061 100644 --- a/src/cmd/compile/internal/ssa/prove.go +++ b/src/cmd/compile/internal/ssa/prove.go @@ -436,6 +436,29 @@ func (l limit) bitlen(b uint) limit { ) } +// Similar to add, but computes the PopCount of the limit for bitsize b. +func (l limit) popcount(b uint) limit { + fixed, fixedCount := l.unsignedFixedLeadingBits() + varying := 64 - fixedCount + fixedContribution := uint64(bits.OnesCount64(fixed)) + + min := fixedContribution + max := fixedContribution + uint64(varying) + + varyingMask := uint64(1)<