diff options
| author | Rémy Oudompheng <remyoudompheng@gmail.com> | 2019-01-13 18:10:19 +0100 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2019-03-04 22:25:21 +0000 |
| commit | a1f7dbf0aa5c9c7bd6677c53d68aa991e4b18797 (patch) | |
| tree | 738f22ff15824067ae81d376633c99dc709bcb61 /src/strconv/extfloat.go | |
| parent | d5edbcac9857cd77723f153d03c55c87923d714f (diff) | |
| download | go-git-a1f7dbf0aa5c9c7bd6677c53d68aa991e4b18797.tar.gz | |
strconv: simplify (*extFloat).Multiply using math/bits.Mul64
This method was using a handwritten long multiplication of uint64s.
Since implementation of #24813 we can remove it and replace it
by Mul64 from math/bits.
This brings a small speedup for 64-bit platforms.
Benchmarks on Haswell Celeron 2955U.
benchmark old ns/op new ns/op delta
BenchmarkAppendFloat/Decimal-2 127 127 +0.00%
BenchmarkAppendFloat/Float-2 340 317 -6.76%
BenchmarkAppendFloat/Exp-2 258 233 -9.69%
BenchmarkAppendFloat/NegExp-2 256 231 -9.77%
BenchmarkAppendFloat/Big-2 402 375 -6.72%
BenchmarkAppendFloat/BinaryExp-2 113 114 +0.88%
BenchmarkAppendFloat/32Integer-2 125 125 +0.00%
BenchmarkAppendFloat/32ExactFraction-2 274 249 -9.12%
BenchmarkAppendFloat/32Point-2 339 317 -6.49%
BenchmarkAppendFloat/32Exp-2 255 229 -10.20%
BenchmarkAppendFloat/32NegExp-2 254 229 -9.84%
BenchmarkAppendFloat/64Fixed1-2 165 154 -6.67%
BenchmarkAppendFloat/64Fixed2-2 184 176 -4.35%
BenchmarkAppendFloat/64Fixed3-2 168 158 -5.95%
BenchmarkAppendFloat/64Fixed4-2 187 177 -5.35%
BenchmarkAppendFloat/Slowpath64-2 84977 84883 -0.11%
Change-Id: If05784e856289b3b7bf136567882e7ee10234756
Reviewed-on: https://go-review.googlesource.com/c/go/+/157717
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/strconv/extfloat.go')
| -rw-r--r-- | src/strconv/extfloat.go | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/src/strconv/extfloat.go b/src/strconv/extfloat.go index 32d3340f5f..2a2dd7a408 100644 --- a/src/strconv/extfloat.go +++ b/src/strconv/extfloat.go @@ -214,20 +214,9 @@ func (f *extFloat) Normalize() uint { // Multiply sets f to the product f*g: the result is correctly rounded, // but not normalized. func (f *extFloat) Multiply(g extFloat) { - fhi, flo := f.mant>>32, uint64(uint32(f.mant)) - ghi, glo := g.mant>>32, uint64(uint32(g.mant)) - - // Cross products. - cross1 := fhi * glo - cross2 := flo * ghi - - // f.mant*g.mant is fhi*ghi << 64 + (cross1+cross2) << 32 + flo*glo - f.mant = fhi*ghi + (cross1 >> 32) + (cross2 >> 32) - rem := uint64(uint32(cross1)) + uint64(uint32(cross2)) + ((flo * glo) >> 32) + hi, lo := bits.Mul64(f.mant, g.mant) // Round up. - rem += (1 << 31) - - f.mant += (rem >> 32) + f.mant = hi + (lo >> 63) f.exp = f.exp + g.exp + 64 } |
