Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Commit

Permalink
Replace several 32-bit multiplies with a 64-bit one
Browse files Browse the repository at this point in the history
name                          old time/op  new time/op  delta
AppendFloat32/0e+00-12        2.97ns ± 1%  2.97ns ± 1%     ~     (p=0.889 n=5+5)
AppendFloat32/1e+00-12        41.4ns ± 1%  36.5ns ± 1%  -11.70%  (p=0.008 n=5+5)
AppendFloat32/3e-01-12        35.9ns ± 1%  32.3ns ± 2%  -10.09%  (p=0.008 n=5+5)
AppendFloat32/1e+06-12        40.1ns ± 1%  36.3ns ± 1%   -9.33%  (p=0.008 n=5+5)
AppendFloat32/-1.2345e+02-12  41.4ns ± 1%  33.6ns ± 1%  -18.84%  (p=0.008 n=5+5)
  • Loading branch information
cespare committed Jan 12, 2019
1 parent a8cbc0a commit 1f734ae
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions ryu32.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,8 @@ func decimalLen32(u uint32) int {
func mulShift32(m uint32, mul uint64, shift int32) uint32 {
assert(shift > 32, "shift > 32")

// FIXME: Test against just using 64-bit multiplication.
mulLo := uint32(mul)
mulHi := uint32(mul >> 32)
bits0 := uint64(m) * uint64(mulLo)
bits1 := uint64(m) * uint64(mulHi)

sum := (bits0 >> 32) + bits1
shiftedSum := sum >> uint(shift-32)
hi, lo := bits.Mul64(uint64(m), mul)
shiftedSum := (lo >> uint(shift)) + (hi << uint(64-shift))
assert(shiftedSum <= math.MaxUint32, "shiftedSum <= math.MaxUint32")
return uint32(shiftedSum)
}
Expand Down

0 comments on commit 1f734ae

Please sign in to comment.