]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/gc: use 512 bits (rather than 464) for multi-precision arithmetic
authorRobert Griesemer <gri@golang.org>
Thu, 2 Apr 2015 23:34:48 +0000 (16:34 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 3 Apr 2015 17:13:07 +0000 (17:13 +0000)
The original implementation used 16 int "words" but only 29 bits per word
for a total of 16*29 = 464 bits, with a space consumption of 16*64 = 1024
bits on a 64 bit machine. Switching to 512 bits increases precision while
still using (in the worst case) half the amount of memory per mp value on
a 64 bit machine.

Also: Decreased permitted number of least-significant mantissa bits which
may be incorrect when considering if a precise floating-point constant is
an integer from 29 to 16 bits.

Change-Id: Iee9287056f0e9aa4f06ceac0724ff4674f710c53
Reviewed-on: https://go-review.googlesource.com/8429
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/internal/gc/go.go
src/cmd/internal/gc/mparith2.go
src/cmd/internal/gc/mparith3.go
test/fixedbugs/issue6889.go
test/fixedbugs/issue7740.go

index e4305961a059c71a64bb617183a39a821487ed0a..027ad28fb1d954b49619e63b22017fdf8ce9c57d 100644 (file)
@@ -57,10 +57,11 @@ const (
 )
 
 const (
-       // TODO(gri) consider increasing Mpprec to 512 or perhaps 1024
-       // (this would permit enabling additional tests).
-       Mpprec  = 16 * 29 // == 464, to match original value
-       Mpdebug = 0
+       // Maximum size in bits for Mpints before signalling
+       // overflow and also mantissa precision for Mpflts.
+       Mpprec = 512
+       // Turn on for constant arithmetic debugging output.
+       Mpdebug = false
 )
 
 // Mpint represents an integer constant.
index a4b870eb679ad22bab154a4a2e0d89326a9596b1..e369ad064fc077cdbf3c13daaa4434f68bce1689 100644 (file)
@@ -35,10 +35,7 @@ func mpmovefltfix(a *Mpint, b *Mpflt) int {
                return 0
        }
 
-       // TODO(gri) reduce the value of delta - currently
-       // we use the size of a mp-word of the old implementation
-       // for approximately similar behavior.
-       const delta = 29 // a reasonably small number of bits > 0
+       const delta = 16 // a reasonably small number of bits > 0
        var t big.Float
        t.SetPrec(Mpprec - delta)
 
index b2424df92a9d7dac7fd09c638bf56e160715429f..d1ae41dd740f9c8f4d014b2f23cbed06f2007726 100644 (file)
@@ -32,13 +32,13 @@ func mpmovefltflt(a *Mpflt, b *Mpflt) {
 }
 
 func mpaddfltflt(a *Mpflt, b *Mpflt) {
-       if Mpdebug != 0 {
+       if Mpdebug {
                fmt.Printf("\n%v + %v", Fconv(a, 0), Fconv(b, 0))
        }
 
        a.Val.Add(&a.Val, &b.Val)
 
-       if Mpdebug != 0 {
+       if Mpdebug {
                fmt.Printf(" = %v\n\n", Fconv(a, 0))
        }
 }
@@ -51,25 +51,25 @@ func mpaddcflt(a *Mpflt, c float64) {
 }
 
 func mpsubfltflt(a *Mpflt, b *Mpflt) {
-       if Mpdebug != 0 {
+       if Mpdebug {
                fmt.Printf("\n%v - %v", Fconv(a, 0), Fconv(b, 0))
        }
 
        a.Val.Sub(&a.Val, &b.Val)
 
-       if Mpdebug != 0 {
+       if Mpdebug {
                fmt.Printf(" = %v\n\n", Fconv(a, 0))
        }
 }
 
 func mpmulfltflt(a *Mpflt, b *Mpflt) {
-       if Mpdebug != 0 {
+       if Mpdebug {
                fmt.Printf("%v\n * %v\n", Fconv(a, 0), Fconv(b, 0))
        }
 
        a.Val.Mul(&a.Val, &b.Val)
 
-       if Mpdebug != 0 {
+       if Mpdebug {
                fmt.Printf(" = %v\n\n", Fconv(a, 0))
        }
 }
@@ -82,13 +82,13 @@ func mpmulcflt(a *Mpflt, c float64) {
 }
 
 func mpdivfltflt(a *Mpflt, b *Mpflt) {
-       if Mpdebug != 0 {
+       if Mpdebug {
                fmt.Printf("%v\n / %v\n", Fconv(a, 0), Fconv(b, 0))
        }
 
        a.Val.Quo(&a.Val, &b.Val)
 
-       if Mpdebug != 0 {
+       if Mpdebug {
                fmt.Printf(" = %v\n\n", Fconv(a, 0))
        }
 }
@@ -140,13 +140,13 @@ func mpgetflt32(a *Mpflt) float64 {
 }
 
 func Mpmovecflt(a *Mpflt, c float64) {
-       if Mpdebug != 0 {
+       if Mpdebug {
                fmt.Printf("\nconst %g", c)
        }
 
        a.Val.SetFloat64(c)
 
-       if Mpdebug != 0 {
+       if Mpdebug {
                fmt.Printf(" = %v\n", Fconv(a, 0))
        }
 }
index 46bb5dacf6bf16d6252683e39a1887804659e3fc..805a877d582728389fc630aae40e71191364fcf0 100644 (file)
@@ -99,5 +99,13 @@ const (
        f88 = f87 * 88
        f89 = f88 * 89
        f90 = f89 * 90
-       f91 = f90 * 91 // ERROR "overflow"
+       f91 = f90 * 91
+       f92 = f91 * 92
+       f93 = f92 * 93
+       f94 = f93 * 94
+       f95 = f94 * 95
+       f96 = f95 * 96
+       f97 = f96 * 97
+       f98 = f97 * 98
+       f99 = f98 * 99 // ERROR "overflow"
 )
index d5005ed6c0da2650c180f14bd58140606fb256a4..8f1afe86dae5ed1258190fdb1308522de238d2c7 100644 (file)
@@ -21,7 +21,7 @@ func main() {
        var prec float64
        switch runtime.Compiler {
        case "gc":
-               prec = 16 * 29
+               prec = 512
        case "gccgo":
                prec = 256
        default: