Commit c042fedb authored by Ben Shi's avatar Ben Shi

test/codegen: add arithmetic tests for 386/amd64/arm/arm64

This CL adds several test cases of arithmetic operations for
386/amd64/arm/arm64.

Change-Id: I362687c06249f31091458a1d8c45fc4d006b616a
Reviewed-on: https://go-review.googlesource.com/c/151897
Run-TryBot: Ben Shi <powerman1st@163.com>
Reviewed-by: 's avatarKeith Randall <khr@golang.org>
parent 6d6c8582
...@@ -66,7 +66,10 @@ func Pow2Muls(n1, n2 int) (int, int) { ...@@ -66,7 +66,10 @@ func Pow2Muls(n1, n2 int) (int, int) {
} }
func Mul_96(n int) int { func Mul_96(n int) int {
// amd64:`SHLQ\t[$]5`,`LEAQ\t\(.*\)\(.*\*2\),` // amd64:`SHLQ\t[$]5`,`LEAQ\t\(.*\)\(.*\*2\),`,-`IMULQ`
// 386:`SHLL\t[$]5`,`LEAL\t\(.*\)\(.*\*2\),`,-`IMULL`
// arm64:`LSL\t[$]5`,`ADD\sR[0-9]+<<1,\sR[0-9]+`,-`MUL`
// arm:`SLL\t[$]5`,`ADD\sR[0-9]+<<1,\sR[0-9]+`,-`MUL`
return n * 96 return n * 96
} }
...@@ -74,6 +77,7 @@ func MulMemSrc(a []uint32, b []float32) { ...@@ -74,6 +77,7 @@ func MulMemSrc(a []uint32, b []float32) {
// 386:`IMULL\s4\([A-Z]+\),\s[A-Z]+` // 386:`IMULL\s4\([A-Z]+\),\s[A-Z]+`
a[0] *= a[1] a[0] *= a[1]
// 386/sse2:`MULSS\s4\([A-Z]+\),\sX[0-9]+` // 386/sse2:`MULSS\s4\([A-Z]+\),\sX[0-9]+`
// amd64:`MULSS\s4\([A-Z]+\),\sX[0-9]+`
b[0] *= b[1] b[0] *= b[1]
} }
...@@ -115,6 +119,7 @@ func MergeMuls5(a, n int) int { ...@@ -115,6 +119,7 @@ func MergeMuls5(a, n int) int {
func DivMemSrc(a []float64) { func DivMemSrc(a []float64) {
// 386/sse2:`DIVSD\s8\([A-Z]+\),\sX[0-9]+` // 386/sse2:`DIVSD\s8\([A-Z]+\),\sX[0-9]+`
// amd64:`DIVSD\s8\([A-Z]+\),\sX[0-9]+`
a[0] /= a[1] a[0] /= a[1]
} }
...@@ -141,9 +146,15 @@ func Pow2Divs(n1 uint, n2 int) (uint, int) { ...@@ -141,9 +146,15 @@ func Pow2Divs(n1 uint, n2 int) (uint, int) {
// Check that constant divisions get turned into MULs // Check that constant divisions get turned into MULs
func ConstDivs(n1 uint, n2 int) (uint, int) { func ConstDivs(n1 uint, n2 int) (uint, int) {
// amd64:"MOVQ\t[$]-1085102592571150095","MULQ",-"DIVQ" // amd64:"MOVQ\t[$]-1085102592571150095","MULQ",-"DIVQ"
// 386:"MOVL\t[$]-252645135","MULL",-"DIVL"
// arm64:`MOVD`,`UMULH`,-`DIV`
// arm:`MOVW`,`MUL`,-`.*udiv`
a := n1 / 17 // unsigned a := n1 / 17 // unsigned
// amd64:"MOVQ\t[$]-1085102592571150095","IMULQ",-"IDIVQ" // amd64:"MOVQ\t[$]-1085102592571150095","IMULQ",-"IDIVQ"
// 386:"MOVL\t[$]-252645135","IMULL",-"IDIVL"
// arm64:`MOVD`,`SMULH`,-`DIV`
// arm:`MOVW`,`MUL`,-`.*udiv`
b := n2 / 17 // signed b := n2 / 17 // signed
return a, b return a, b
...@@ -151,6 +162,7 @@ func ConstDivs(n1 uint, n2 int) (uint, int) { ...@@ -151,6 +162,7 @@ func ConstDivs(n1 uint, n2 int) (uint, int) {
func FloatDivs(a []float32) float32 { func FloatDivs(a []float32) float32 {
// amd64:`DIVSS\s8\([A-Z]+\),\sX[0-9]+` // amd64:`DIVSS\s8\([A-Z]+\),\sX[0-9]+`
// 386/sse2:`DIVSS\s8\([A-Z]+\),\sX[0-9]+`
return a[1] / a[2] return a[1] / a[2]
} }
...@@ -175,9 +187,15 @@ func Pow2Mods(n1 uint, n2 int) (uint, int) { ...@@ -175,9 +187,15 @@ func Pow2Mods(n1 uint, n2 int) (uint, int) {
// Check that constant modulo divs get turned into MULs // Check that constant modulo divs get turned into MULs
func ConstMods(n1 uint, n2 int) (uint, int) { func ConstMods(n1 uint, n2 int) (uint, int) {
// amd64:"MOVQ\t[$]-1085102592571150095","MULQ",-"DIVQ" // amd64:"MOVQ\t[$]-1085102592571150095","MULQ",-"DIVQ"
// 386:"MOVL\t[$]-252645135","MULL",-"DIVL"
// arm64:`MOVD`,`UMULH`,-`DIV`
// arm:`MOVW`,`MUL`,-`.*udiv`
a := n1 % 17 // unsigned a := n1 % 17 // unsigned
// amd64:"MOVQ\t[$]-1085102592571150095","IMULQ",-"IDIVQ" // amd64:"MOVQ\t[$]-1085102592571150095","IMULQ",-"IDIVQ"
// 386:"MOVL\t[$]-252645135","IMULL",-"IDIVL"
// arm64:`MOVD`,`SMULH`,-`DIV`
// arm:`MOVW`,`MUL`,-`.*udiv`
b := n2 % 17 // signed b := n2 % 17 // signed
return a, b return a, b
...@@ -270,6 +288,8 @@ func NoFix16B(divd int16) (int16, int16) { ...@@ -270,6 +288,8 @@ func NoFix16B(divd int16) (int16, int16) {
func LenDiv1(a []int) int { func LenDiv1(a []int) int {
// 386:"SHRL\t[$]10" // 386:"SHRL\t[$]10"
// amd64:"SHRQ\t[$]10" // amd64:"SHRQ\t[$]10"
// arm64:"LSR\t[$]10",-"SDIV"
// arm:"SRL\t[$]10",-".*udiv"
// ppc64:"SRD"\t[$]10" // ppc64:"SRD"\t[$]10"
// ppc64le:"SRD"\t[$]10" // ppc64le:"SRD"\t[$]10"
return len(a) / 1024 return len(a) / 1024
...@@ -278,6 +298,8 @@ func LenDiv1(a []int) int { ...@@ -278,6 +298,8 @@ func LenDiv1(a []int) int {
func LenDiv2(s string) int { func LenDiv2(s string) int {
// 386:"SHRL\t[$]11" // 386:"SHRL\t[$]11"
// amd64:"SHRQ\t[$]11" // amd64:"SHRQ\t[$]11"
// arm64:"LSR\t[$]11",-"SDIV"
// arm:"SRL\t[$]11",-".*udiv"
// ppc64:"SRD\t[$]11" // ppc64:"SRD\t[$]11"
// ppc64le:"SRD\t[$]11" // ppc64le:"SRD\t[$]11"
return len(s) / (4097 >> 1) return len(s) / (4097 >> 1)
...@@ -286,6 +308,9 @@ func LenDiv2(s string) int { ...@@ -286,6 +308,9 @@ func LenDiv2(s string) int {
func LenMod1(a []int) int { func LenMod1(a []int) int {
// 386:"ANDL\t[$]1023" // 386:"ANDL\t[$]1023"
// amd64:"ANDQ\t[$]1023" // amd64:"ANDQ\t[$]1023"
// arm64:"AND\t[$]1023",-"SDIV"
// arm/6:"AND",-".*udiv"
// arm/7:"BFC",-".*udiv",-"AND"
// ppc64:"ANDCC\t[$]1023" // ppc64:"ANDCC\t[$]1023"
// ppc64le:"ANDCC\t[$]1023" // ppc64le:"ANDCC\t[$]1023"
return len(a) % 1024 return len(a) % 1024
...@@ -294,6 +319,9 @@ func LenMod1(a []int) int { ...@@ -294,6 +319,9 @@ func LenMod1(a []int) int {
func LenMod2(s string) int { func LenMod2(s string) int {
// 386:"ANDL\t[$]2047" // 386:"ANDL\t[$]2047"
// amd64:"ANDQ\t[$]2047" // amd64:"ANDQ\t[$]2047"
// arm64:"AND\t[$]2047",-"SDIV"
// arm/6:"AND",-".*udiv"
// arm/7:"BFC",-".*udiv",-"AND"
// ppc64:"ANDCC\t[$]2047" // ppc64:"ANDCC\t[$]2047"
// ppc64le:"ANDCC\t[$]2047" // ppc64le:"ANDCC\t[$]2047"
return len(s) % (4097 >> 1) return len(s) % (4097 >> 1)
...@@ -302,6 +330,8 @@ func LenMod2(s string) int { ...@@ -302,6 +330,8 @@ func LenMod2(s string) int {
func CapDiv(a []int) int { func CapDiv(a []int) int {
// 386:"SHRL\t[$]12" // 386:"SHRL\t[$]12"
// amd64:"SHRQ\t[$]12" // amd64:"SHRQ\t[$]12"
// arm64:"LSR\t[$]12",-"SDIV"
// arm:"SRL\t[$]12",-".*udiv"
// ppc64:"SRD\t[$]12" // ppc64:"SRD\t[$]12"
// ppc64le:"SRD\t[$]12" // ppc64le:"SRD\t[$]12"
return cap(a) / ((1 << 11) + 2048) return cap(a) / ((1 << 11) + 2048)
...@@ -310,6 +340,9 @@ func CapDiv(a []int) int { ...@@ -310,6 +340,9 @@ func CapDiv(a []int) int {
func CapMod(a []int) int { func CapMod(a []int) int {
// 386:"ANDL\t[$]4095" // 386:"ANDL\t[$]4095"
// amd64:"ANDQ\t[$]4095" // amd64:"ANDQ\t[$]4095"
// arm64:"AND\t[$]4095",-"SDIV"
// arm/6:"AND",-".*udiv"
// arm/7:"BFC",-".*udiv",-"AND"
// ppc64:"ANDCC\t[$]4095" // ppc64:"ANDCC\t[$]4095"
// ppc64le:"ANDCC\t[$]4095" // ppc64le:"ANDCC\t[$]4095"
return cap(a) % ((1 << 11) + 2048) return cap(a) % ((1 << 11) + 2048)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment