+++ /dev/null
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build !go1.9
-
-package ssa
-
-const deBruijn64 = 0x03f79d71b4ca8b09
-
-var deBruijn64tab = [64]byte{
- 0, 1, 56, 2, 57, 49, 28, 3, 61, 58, 42, 50, 38, 29, 17, 4,
- 62, 47, 59, 36, 45, 43, 51, 22, 53, 39, 33, 30, 24, 18, 12, 5,
- 63, 55, 48, 27, 60, 41, 37, 16, 46, 35, 44, 21, 52, 32, 23, 11,
- 54, 26, 40, 15, 34, 20, 31, 10, 25, 14, 19, 9, 13, 8, 7, 6,
-}
-
-// TrailingZeros64 returns the number of trailing zero bits in x; the result is 64 for x == 0.
-func TrailingZeros64(x uint64) int {
- if x == 0 {
- return 64
- }
- return int(deBruijn64tab[(x&-x)*deBruijn64>>(64-6)])
-}
+++ /dev/null
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build go1.9
-
-package ssa
-
-import "math/bits"
-
-func TrailingZeros64(x uint64) int {
- return bits.TrailingZeros64(x)
-}
"cmd/internal/obj"
"encoding/hex"
"fmt"
+ "math/bits"
"sort"
"strings"
)
if mask == 0 {
break
}
- reg := uint8(TrailingZeros64(mask))
+ reg := uint8(bits.TrailingZeros64(mask))
mask &^= 1 << reg
registers[reg] = append(registers[reg], live.slot)
if mask == 0 {
break
}
- reg := uint8(TrailingZeros64(mask))
+ reg := uint8(bits.TrailingZeros64(mask))
mask &^= 1 << reg
storage = append(storage, s.registers[reg].String())
if mask == 0 {
break
}
- reg := uint8(TrailingZeros64(mask))
+ reg := uint8(bits.TrailingZeros64(mask))
mask &^= 1 << reg
state.currentState.registers[reg] = append(state.currentState.registers[reg], predSlot.slot)
if clobbers == 0 {
break
}
- reg := uint8(TrailingZeros64(clobbers))
+ reg := uint8(bits.TrailingZeros64(clobbers))
clobbers &^= 1 << reg
for _, slot := range locs.registers[reg] {
// produce locations with no storage.
return 0
}
- return uint8(TrailingZeros64(uint64(set)))
+ return uint8(bits.TrailingZeros64(uint64(set)))
}
// buildLocationLists builds location lists for all the user variables in
"fmt"
"io"
"math"
+ "math/bits"
"os"
"path/filepath"
)
// nlz returns the number of leading zeros.
func nlz(x int64) int64 {
- // log2(0) == 1, so nlz(0) == 64
- return 63 - log2(x)
+ return int64(bits.LeadingZeros64(uint64(x)))
}
// ntz returns the number of trailing zeros.
func ntz(x int64) int64 {
- return 64 - nlz(^x&(x-1))
+ return int64(bits.TrailingZeros64(uint64(x)))
}
func oneBit(x int64) bool {
- return nlz(x)+ntz(x) == 63
+ return bits.OnesCount64(uint64(x)) == 1
}
// nlo returns the number of leading ones.
// log2 returns logarithm in base 2 of uint64(n), with log2(0) = -1.
// Rounds down.
-func log2(n int64) (l int64) {
- l = -1
- x := uint64(n)
- for ; x >= 0x8000; x >>= 16 {
- l += 16
- }
- if x >= 0x80 {
- x >>= 8
- l += 8
- }
- if x >= 0x8 {
- x >>= 4
- l += 4
- }
- if x >= 0x2 {
- x >>= 2
- l += 2
- }
- if x >= 0x1 {
- l++
- }
- return
+func log2(n int64) int64 {
+ return int64(bits.Len64(uint64(n))) - 1
}
// log2uint32 returns logarithm in base 2 of uint32(n), with log2(0) = -1.
// Rounds down.
-func log2uint32(n int64) (l int64) {
- return log2(int64(uint32(n)))
+func log2uint32(n int64) int64 {
+ return int64(bits.Len32(uint32(n))) - 1
}
// isPowerOfTwo reports whether n is a power of 2.