summaryrefslogtreecommitdiff
path: root/test/codegen/arithmetic.go
diff options
context:
space:
mode:
authorAlberto Donizetti <alb.donizetti@gmail.com>2018-03-09 14:51:30 +0100
committerAlberto Donizetti <alb.donizetti@gmail.com>2018-03-09 17:01:56 +0000
commit5f541b11aaa345b4cf0fb37a80c32b704a6854ea (patch)
tree88fe9cfa379bfa57d2e0d16b2207b6a53c0d7def /test/codegen/arithmetic.go
parent91f74069ef442f8d963f43cc898af8af3e8b8d0e (diff)
downloadgo-git-5f541b11aaa345b4cf0fb37a80c32b704a6854ea.tar.gz
test/codegen: port MULs merging tests to codegen
And delete them from asm_go. Change-Id: I0057cbd90ca55fa51c596e32406e190f3866f93e Reviewed-on: https://go-review.googlesource.com/99815 Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/codegen/arithmetic.go')
-rw-r--r--test/codegen/arithmetic.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go
index c09fad60c8..eecb101395 100644
--- a/test/codegen/arithmetic.go
+++ b/test/codegen/arithmetic.go
@@ -24,3 +24,37 @@ func Pow2Muls(n1, n2 int) (int, int) {
return a, b
}
+
+// ------------------ //
+// MULs merging //
+// ------------------ //
+
+func MergeMuls1(n int) int {
+ // amd64:"IMULQ\t[$]46"
+ // 386:"IMULL\t[$]46"
+ return 15*n + 31*n // 46n
+}
+
+func MergeMuls2(n int) int {
+ // amd64:"IMULQ\t[$]23","ADDQ\t[$]29"
+ // 386:"IMULL\t[$]23","ADDL\t[$]29"
+ return 5*n + 7*(n+1) + 11*(n+2) // 23n + 29
+}
+
+func MergeMuls3(a, n int) int {
+ // amd64:"ADDQ\t[$]19",-"IMULQ\t[$]19"
+ // 386:"ADDL\t[$]19",-"IMULL\t[$]19"
+ return a*n + 19*n // (a+19)n
+}
+
+func MergeMuls4(n int) int {
+ // amd64:"IMULQ\t[$]14"
+ // 386:"IMULL\t[$]14"
+ return 23*n - 9*n // 14n
+}
+
+func MergeMuls5(a, n int) int {
+ // amd64:"ADDQ\t[$]-19",-"IMULQ\t[$]19"
+ // 386:"ADDL\t[$]-19",-"IMULL\t[$]19"
+ return a*n - 19*n // (a-19)n
+}