cmd/compile: use math/bits functions where possible

Use the math/bits functions to calculate the number of leading/
trailing zeros, bit length and the population count.

The math/bits package is built as part of the bootstrap process
so we do not need to provide an alternative implementation for
Go versions prior to 1.9.

Passes toolstash-check -all.

Change-Id: I393b4cc1c8accd0ca7cb3599d3926fa6319b574f
Reviewed-on: https://go-review.googlesource.com/113336
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Michael Munday 2018-05-16 11:21:18 +01:00
parent cc09212f59
commit 5654114d04
4 changed files with 14 additions and 70 deletions

View file

@ -8,6 +8,7 @@ import (
"cmd/internal/obj"
"encoding/hex"
"fmt"
"math/bits"
"sort"
"strings"
)
@ -92,7 +93,7 @@ func (state *stateAtPC) reset(live []liveSlot) {
if mask == 0 {
break
}
reg := uint8(TrailingZeros64(mask))
reg := uint8(bits.TrailingZeros64(mask))
mask &^= 1 << reg
registers[reg] = append(registers[reg], live.slot)
@ -116,7 +117,7 @@ func (s *debugState) LocString(loc VarLoc) string {
if mask == 0 {
break
}
reg := uint8(TrailingZeros64(mask))
reg := uint8(bits.TrailingZeros64(mask))
mask &^= 1 << reg
storage = append(storage, s.registers[reg].String())
@ -613,7 +614,7 @@ func (state *debugState) mergePredecessors(b *Block, blockLocs []*BlockDebug) ([
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)
@ -643,7 +644,7 @@ func (state *debugState) processValue(v *Value, vSlots []SlotID, vReg *Register)
if clobbers == 0 {
break
}
reg := uint8(TrailingZeros64(clobbers))
reg := uint8(bits.TrailingZeros64(clobbers))
clobbers &^= 1 << reg
for _, slot := range locs.registers[reg] {
@ -812,7 +813,7 @@ func firstReg(set RegisterSet) uint8 {
// 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