aboutsummaryrefslogtreecommitdiff
path: root/test/codegen/arithmetic.go
diff options
context:
space:
mode:
authorAlberto Donizetti <alb.donizetti@gmail.com>2018-03-14 11:47:34 +0100
committerAlberto Donizetti <alb.donizetti@gmail.com>2018-03-14 15:56:46 +0000
commit858042b8fd51ae827e85cd47a0daf2957b84738e (patch)
tree1238ac4baeb41e2f859736403132a90a7d09df71 /test/codegen/arithmetic.go
parentb8d26225c1984286a0c677993047748698ef301b (diff)
downloadgo-858042b8fd51ae827e85cd47a0daf2957b84738e.tar.xz
test/codegen: add codegen tests for div
Change-Id: I6ce8981e85fd55ade6078b0946e54a9215d9deca Reviewed-on: https://go-review.googlesource.com/100575 Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'test/codegen/arithmetic.go')
-rw-r--r--test/codegen/arithmetic.go66
1 files changed, 63 insertions, 3 deletions
diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go
index 1294cfffd9..20adc84bee 100644
--- a/test/codegen/arithmetic.go
+++ b/test/codegen/arithmetic.go
@@ -9,6 +9,10 @@ package codegen
// This file contains codegen tests related to arithmetic
// simplifications/optimizations.
+// -------------------- //
+// Multiplication //
+// -------------------- //
+
func Pow2Muls(n1, n2 int) (int, int) {
// amd64:"SHLQ\t[$]5",-"IMULQ"
// 386:"SHLL\t[$]5",-"IMULL"
@@ -25,9 +29,7 @@ func Pow2Muls(n1, n2 int) (int, int) {
return a, b
}
-// ------------------ //
-// MULs merging //
-// ------------------ //
+// Multiplications merging tests
func MergeMuls1(n int) int {
// amd64:"IMUL3Q\t[$]46"
@@ -58,3 +60,61 @@ func MergeMuls5(a, n int) int {
// 386:"ADDL\t[$]-19",-"IMULL\t[$]19"
return a*n - 19*n // (a-19)n
}
+
+// -------------- //
+// Division //
+// -------------- //
+
+func Pow2Divs(n1 uint, n2 int) (uint, int) {
+ // 386:"SHRL\t[$]5",-"DIVL"
+ // amd64:"SHRQ\t[$]5",-"DIVQ"
+ // arm:"SRL\t[$]5",-".*udiv"
+ // arm64:"LSR\t[$]5",-"UDIV"
+ a := n1 / 32 // unsigned
+
+ // amd64:"SARQ\t[$]6",-"IDIVQ"
+ // 386:"SARL\t[$]6",-"IDIVL"
+ // arm:"SRA\t[$]6",-".*udiv"
+ // arm64:"ASR\t[$]6",-"SDIV"
+ b := n2 / 64 // signed
+
+ return a, b
+}
+
+// Check that constant divisions get turned into MULs
+func ConstDivs(n1 uint, n2 int) (uint, int) {
+ // amd64:"MOVQ\t[$]-1085102592571150095","MULQ",-"DIVQ"
+ a := n1 / 17 // unsigned
+
+ // amd64:"MOVQ\t[$]-1085102592571150095","IMULQ",-"IDIVQ"
+ b := n2 / 17 // signed
+
+ return a, b
+}
+
+func Pow2Mods(n1 uint, n2 int) (uint, int) {
+ // 386:"ANDL\t[$]31",-"DIVL"
+ // amd64:"ANDQ\t[$]31",-"DIVQ"
+ // arm:"AND\t[$]31",-".*udiv"
+ // arm64:"AND\t[$]31",-"UDIV"
+ a := n1 % 32 // unsigned
+
+ // 386:-"IDIVL"
+ // amd64:-"IDIVQ"
+ // arm:-".*udiv"
+ // arm64:-"REM"
+ b := n2 % 64 // signed
+
+ return a, b
+}
+
+// Check that constant modulo divs get turned into MULs
+func ConstMods(n1 uint, n2 int) (uint, int) {
+ // amd64:"MOVQ\t[$]-1085102592571150095","MULQ",-"DIVQ"
+ a := n1 % 17 // unsigned
+
+ // amd64:"MOVQ\t[$]-1085102592571150095","IMULQ",-"IDIVQ"
+ b := n2 % 17 // signed
+
+ return a, b
+}