]> Cypherpunks repositories - gostls13.git/commitdiff
math/big: make nat.setUint64 vet-friendly
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 10 Mar 2017 23:09:05 +0000 (15:09 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sat, 11 Mar 2017 00:39:23 +0000 (00:39 +0000)
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>
src/cmd/vet/all/whitelist/64bit.txt
src/math/big/nat.go

index b2c8e05b599b361f23e516629bee6d4e6960644d..39855f7d70131a15fda522fb81f6ea62abbbe491 100644 (file)
@@ -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
index 1e6f7ae8a891e267ee9574a7cd699ca5eefa07fb..67176553b0ac53283c020aab8030715ac713dcf0 100644 (file)
@@ -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
 }