diff options
| author | Robert Griesemer <gri@golang.org> | 2009-12-15 15:33:31 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2009-12-15 15:33:31 -0800 |
| commit | d9527dd16f72598b54a64550607bf892efa12384 (patch) | |
| tree | 2ad16a7db2d3c484b47426ad2568359ab633820c /src/pkg/bignum/arith.go | |
| parent | aea97e0bd7da9cef1cc631ddbd3578a0877a4fcc (diff) | |
| download | golang-d9527dd16f72598b54a64550607bf892efa12384.tar.gz | |
1) Change default gofmt default settings for
parsing and printing to new syntax.
Use -oldparser to parse the old syntax,
use -oldprinter to print the old syntax.
2) Change default gofmt formatting settings
to use tabs for indentation only and to use
spaces for alignment. This will make the code
alignment insensitive to an editor's tabwidth.
Use -spaces=false to use tabs for alignment.
3) Manually changed src/exp/parser/parser_test.go
so that it doesn't try to parse the parser's
source files using the old syntax (they have
new syntax now).
4) gofmt -w src misc test/bench
1st set of files.
R=rsc
CC=agl, golang-dev, iant, ken2, r
http://codereview.appspot.com/180047
Diffstat (limited to 'src/pkg/bignum/arith.go')
| -rw-r--r-- | src/pkg/bignum/arith.go | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/pkg/bignum/arith.go b/src/pkg/bignum/arith.go index 243e34b9c..aa65dbd7a 100644 --- a/src/pkg/bignum/arith.go +++ b/src/pkg/bignum/arith.go @@ -18,10 +18,10 @@ func Mul128(x, y uint64) (z1, z0 uint64) { // and return the product as 2 words. const ( - W = uint(unsafe.Sizeof(x)) * 8; - W2 = W / 2; - B2 = 1 << W2; - M2 = B2 - 1; + W = uint(unsafe.Sizeof(x)) * 8 + W2 = W / 2 + B2 = 1 << W2 + M2 = B2 - 1 ) if x < y { @@ -32,44 +32,44 @@ func Mul128(x, y uint64) (z1, z0 uint64) { // y < B2 because y <= x // sub-digits of x and y are (0, x) and (0, y) // z = z[0] = x*y - z0 = x * y; - return; + z0 = x * y + return } if y < B2 { // sub-digits of x and y are (x1, x0) and (0, y) // x = (x1*B2 + x0) // y = (y1*B2 + y0) - x1, x0 := x>>W2, x&M2; + x1, x0 := x>>W2, x&M2 // x*y = t2*B2*B2 + t1*B2 + t0 - t0 := x0 * y; - t1 := x1 * y; + t0 := x0 * y + t1 := x1 * y // compute result digits but avoid overflow // z = z[1]*B + z[0] = x*y - z0 = t1<<W2 + t0; - z1 = (t1 + t0>>W2) >> W2; - return; + z0 = t1<<W2 + t0 + z1 = (t1 + t0>>W2) >> W2 + return } // general case // sub-digits of x and y are (x1, x0) and (y1, y0) // x = (x1*B2 + x0) // y = (y1*B2 + y0) - x1, x0 := x>>W2, x&M2; - y1, y0 := y>>W2, y&M2; + x1, x0 := x>>W2, x&M2 + y1, y0 := y>>W2, y&M2 // x*y = t2*B2*B2 + t1*B2 + t0 - t0 := x0 * y0; - t1 := x1*y0 + x0*y1; - t2 := x1 * y1; + t0 := x0 * y0 + t1 := x1*y0 + x0*y1 + t2 := x1 * y1 // compute result digits but avoid overflow // z = z[1]*B + z[0] = x*y - z0 = t1<<W2 + t0; - z1 = t2 + (t1+t0>>W2)>>W2; - return; + z0 = t1<<W2 + t0 + z1 = t2 + (t1+t0>>W2)>>W2 + return } @@ -80,10 +80,10 @@ func MulAdd128(x, y, c uint64) (z1, z0 uint64) { // and return the product as 2 words. const ( - W = uint(unsafe.Sizeof(x)) * 8; - W2 = W / 2; - B2 = 1 << W2; - M2 = B2 - 1; + W = uint(unsafe.Sizeof(x)) * 8 + W2 = W / 2 + B2 = 1 << W2 + M2 = B2 - 1 ) // TODO(gri) Should implement special cases for faster execution. @@ -92,30 +92,30 @@ func MulAdd128(x, y, c uint64) (z1, z0 uint64) { // sub-digits of x, y, and c are (x1, x0), (y1, y0), (c1, c0) // x = (x1*B2 + x0) // y = (y1*B2 + y0) - x1, x0 := x>>W2, x&M2; - y1, y0 := y>>W2, y&M2; - c1, c0 := c>>W2, c&M2; + x1, x0 := x>>W2, x&M2 + y1, y0 := y>>W2, y&M2 + c1, c0 := c>>W2, c&M2 // x*y + c = t2*B2*B2 + t1*B2 + t0 - t0 := x0*y0 + c0; - t1 := x1*y0 + x0*y1 + c1; - t2 := x1 * y1; + t0 := x0*y0 + c0 + t1 := x1*y0 + x0*y1 + c1 + t2 := x1 * y1 // compute result digits but avoid overflow // z = z[1]*B + z[0] = x*y - z0 = t1<<W2 + t0; - z1 = t2 + (t1+t0>>W2)>>W2; - return; + z0 = t1<<W2 + t0 + z1 = t2 + (t1+t0>>W2)>>W2 + return } // q = (x1<<64 + x0)/y + r func Div128(x1, x0, y uint64) (q, r uint64) { if x1 == 0 { - q, r = x0/y, x0%y; - return; + q, r = x0/y, x0%y + return } // TODO(gri) Implement general case. - panic("Div128 not implemented for x > 1<<64-1"); + panic("Div128 not implemented for x > 1<<64-1") } |
