mirror of
https://github.com/golang/go
synced 2024-11-18 08:04:40 -07:00
math/big: make nat.setUint64 vet-friendly
nat.setUint64 is nicely generic. By assuming 32- or 64-bit words, however, we can write simpler code, and eliminate some shifts in dead code that vet complains about. Generated code for 64 bit systems is unaltered. Generated code for 32 bit systems is much better. For 386, the routine length drops from 325 bytes of code to 271 bytes of code, with fewer loops. Change-Id: I1bc14c06272dee37a7fcb48d33dd1e621eba945d Reviewed-on: https://go-review.googlesource.com/38070 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
95c5227c15
commit
2de773d45f
@ -22,7 +22,5 @@ math/big/arith.go: (xi&yi | (xi|yi)&^zi) might be too small for shift of 63
|
||||
math/big/arith.go: (yi&^xi | (yi|^xi)&zi) might be too small for shift of 63
|
||||
math/big/arith.go: xi &^ zi might be too small for shift of 63
|
||||
math/big/arith.go: (zi &^ xi) might be too small for shift of 63
|
||||
math/big/nat.go: t too small for shift of 64
|
||||
math/big/nat.go: x too small for shift of 64
|
||||
math/big/nat.go: yi might be too small for shift of 60
|
||||
math/big/nat.go: yi might be too small for shift of 60
|
||||
|
@ -68,24 +68,14 @@ func (z nat) setWord(x Word) nat {
|
||||
}
|
||||
|
||||
func (z nat) setUint64(x uint64) nat {
|
||||
// single-digit values
|
||||
// single-word value
|
||||
if w := Word(x); uint64(w) == x {
|
||||
return z.setWord(w)
|
||||
}
|
||||
|
||||
// compute number of words n required to represent x
|
||||
n := 0
|
||||
for t := x; t > 0; t >>= _W {
|
||||
n++
|
||||
}
|
||||
|
||||
// split x into n words
|
||||
z = z.make(n)
|
||||
for i := range z {
|
||||
z[i] = Word(x & _M)
|
||||
x >>= _W
|
||||
}
|
||||
|
||||
// 2-word value
|
||||
z = z.make(2)
|
||||
z[1] = Word(x >> 32)
|
||||
z[0] = Word(x)
|
||||
return z
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user