mirror of
https://github.com/golang/go.git
synced 2025-05-15 12:24:37 +00:00
cmd/compile: use math/bits for bvec
And delete some dead code. Minor cleanup. Passes toolstash-check. Change-Id: Ia3c77c6bf14942654d00d125a6221e63a442f3c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/227317 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
3c8101c7e4
commit
7a4247cd46
@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
package gc
|
package gc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/bits"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
wordBits = 32
|
wordBits = 32
|
||||||
wordMask = wordBits - 1
|
wordMask = wordBits - 1
|
||||||
@ -108,30 +112,11 @@ func (bv bvec) Next(i int32) int32 {
|
|||||||
|
|
||||||
// Find 1 bit.
|
// Find 1 bit.
|
||||||
w := bv.b[i>>wordShift] >> uint(i&wordMask)
|
w := bv.b[i>>wordShift] >> uint(i&wordMask)
|
||||||
|
i += int32(bits.TrailingZeros32(w))
|
||||||
for w&1 == 0 {
|
|
||||||
w >>= 1
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
// Len returns the minimum number of bits required to represent bv.
|
|
||||||
// The result is 0 if no bits are set in bv.
|
|
||||||
func (bv bvec) Len() int32 {
|
|
||||||
for wi := len(bv.b) - 1; wi >= 0; wi-- {
|
|
||||||
if w := bv.b[wi]; w != 0 {
|
|
||||||
for i := wordBits - 1; i >= 0; i-- {
|
|
||||||
if w>>uint(i) != 0 {
|
|
||||||
return int32(wi)*wordBits + int32(i) + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bv bvec) IsEmpty() bool {
|
func (bv bvec) IsEmpty() bool {
|
||||||
for _, x := range bv.b {
|
for _, x := range bv.b {
|
||||||
if x != 0 {
|
if x != 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user