From: Russ Cox Date: Tue, 24 May 2016 06:45:11 +0000 (-0400) Subject: math/big: write t*10 to multiply t by 10 X-Git-Tag: go1.7beta1~124 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ab4414773e27624abf4361e48a0ca0979e804970;p=gostls13.git math/big: write t*10 to multiply t by 10 The compiler has caught up. In fact the compiler is ahead; it knows about a magic multiply-by-5 instruction: // compute '0' + byte(r - t*10) in AX MOVQ t, AX LEAQ (AX)(AX*4), AX SHLQ $1, AX MOVQ r, CX SUBQ AX, CX LEAL 48(CX), AX For comparison, the shifty version compiles to: // compute '0' + byte(r - t*10) in AX MOVQ t, AX MOVQ AX, CX SHLQ $3, AX MOVQ r, DX SUBQ AX, DX SUBQ CX, DX SUBQ CX, DX LEAL 48(DX), AX Fixes #2671. Change-Id: Ifbf23dbfeb19c0bb020fa44eb2f025943969fb6b Reviewed-on: https://go-review.googlesource.com/23372 Run-TryBot: Russ Cox Reviewed-by: Andrew Gerrand TryBot-Result: Gobot Gobot --- diff --git a/src/math/big/natconv.go b/src/math/big/natconv.go index e216bd288c..44547842c1 100644 --- a/src/math/big/natconv.go +++ b/src/math/big/natconv.go @@ -391,7 +391,7 @@ func (q nat) convertWords(s []byte, b Word, ndigits int, bb Word, table []diviso // this appears to be faster for BenchmarkString10000Base10 // and smaller strings (but a bit slower for larger ones) t := r / 10 - s[i] = '0' + byte(r-t<<3-t-t) // TODO(gri) replace w/ t*10 once compiler produces better code + s[i] = '0' + byte(r-t*10) r = t } }