diff options
author | Martin Möhrmann <moehrmann@google.com> | 2018-01-27 11:55:34 +0100 |
---|---|---|
committer | Martin Möhrmann <moehrmann@google.com> | 2018-10-15 19:04:09 +0000 |
commit | a1ca4893ff755d6b0b3bf4b026196d55251ea846 (patch) | |
tree | 72a39af659aa88e0a62a5da6ef6d45a659fcfc51 /src/runtime/internal | |
parent | 9f66b41beea82cc613cad9138c10a50f2b3ea137 (diff) | |
download | go-a1ca4893ff755d6b0b3bf4b026196d55251ea846.tar.gz go-a1ca4893ff755d6b0b3bf4b026196d55251ea846.zip |
cmd/compile: add intrinsics for runtime/internal/math on 386 and amd64
Add generic, 386 and amd64 specific ops and SSA rules for multiplication
with overflow and branching based on overflow flags. Use these to intrinsify
runtime/internal/math.MulUinptr.
On amd64
mul, overflow := math.MulUintptr(a, b)
if overflow {
is lowered to two instructions:
MULQ SI
JO 0x10ee35c
No codegen tests as codegen can not currently test unexported internal runtime
functions.
amd64:
name old time/op new time/op delta
MulUintptr/small 1.16ns ± 5% 0.88ns ± 6% -24.36% (p=0.000 n=19+20)
MulUintptr/large 10.7ns ± 1% 1.1ns ± 1% -89.28% (p=0.000 n=17+19)
Change-Id: If60739a86f820e5044d677276c21df90d3c7a86a
Reviewed-on: https://go-review.googlesource.com/c/141820
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/internal')
-rw-r--r-- | src/runtime/internal/math/math_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/runtime/internal/math/math_test.go b/src/runtime/internal/math/math_test.go index 9447bd23f9..303eb63405 100644 --- a/src/runtime/internal/math/math_test.go +++ b/src/runtime/internal/math/math_test.go @@ -49,3 +49,31 @@ func TestMulUintptr(t *testing.T) { } } } + +var SinkUintptr uintptr +var SinkBool bool + +var x, y uintptr + +func BenchmarkMulUintptr(b *testing.B) { + x, y = 1, 2 + b.Run("small", func(b *testing.B) { + for i := 0; i < b.N; i++ { + var overflow bool + SinkUintptr, overflow = MulUintptr(x, y) + if overflow { + SinkUintptr = 0 + } + } + }) + x, y = MaxUintptr, MaxUintptr-1 + b.Run("large", func(b *testing.B) { + for i := 0; i < b.N; i++ { + var overflow bool + SinkUintptr, overflow = MulUintptr(x, y) + if overflow { + SinkUintptr = 0 + } + } + }) +} |