]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove manually implemented popcount in _gen/main.go
authorJorropo <jorropo.pgm@gmail.com>
Sun, 13 Nov 2022 19:41:58 +0000 (20:41 +0100)
committerKeith Randall <khr@golang.org>
Tue, 15 Nov 2022 16:10:08 +0000 (16:10 +0000)
Change-Id: I7b4da26bace15c2b632c2dbfe56cc2799bbfdb02
Reviewed-on: https://go-review.googlesource.com/c/go/+/450058
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Keith Randall <khr@golang.org>

src/cmd/compile/internal/ssa/_gen/main.go

index 6a8ae0e45cdc4129435892e6a330f82e233ddb90..f37438796ced5a2be12f349216162856936d160b 100644 (file)
@@ -12,6 +12,7 @@ import (
        "fmt"
        "go/format"
        "log"
+       "math/bits"
        "os"
        "path"
        "regexp"
@@ -546,12 +547,7 @@ func (a arch) Name() string {
 
 // countRegs returns the number of set bits in the register mask.
 func countRegs(r regMask) int {
-       n := 0
-       for r != 0 {
-               n += int(r & 1)
-               r >>= 1
-       }
-       return n
+       return bits.OnesCount64(uint64(r))
 }
 
 // for sorting a pair of integers by key