aboutsummaryrefslogtreecommitdiff
path: root/test/codegen/arithmetic.go
diff options
context:
space:
mode:
authorPaul E. Murphy <murp@ibm.com>2023-01-25 11:53:10 -0600
committerPaul Murphy <murp@ibm.com>2023-01-27 18:24:12 +0000
commit0301c6c3512561b85b48d0e167f3e405484f496f (patch)
tree18ac5ab56f9115b0fc1d16f953d0d1ef11efd7fc /test/codegen/arithmetic.go
parent4b3726e99bec62e4a8b8e9cecc478b51ce0d4636 (diff)
downloadgo-0301c6c3512561b85b48d0e167f3e405484f496f.tar.xz
test/codegen: combine trivial PPC64 tests into ppc64x
Use a small python script to consolidate duplicate ppc64/ppc64le tests into a single ppc64x codegen test. This makes small assumption that anytime two tests with for different arch/variant combos exists, those tests can be combined into a single ppc64x test. E.x: // ppc64le: foo // ppc64le/power9: foo into // ppc64x: foo or // ppc64: foo // ppc64le: foo into // ppc64x: foo import glob import re files = glob.glob("codegen/*.go") for file in files: with open(file) as f: text = [l for l in f] i = 0 while i < len(text): first = re.match("\s*// ?ppc64(le)?(/power[89])?:(.*)", text[i]) if first: j = i+1 while j < len(text): second = re.match("\s*// ?ppc64(le)?(/power[89])?:(.*)", text[j]) if not second: break if (not first.group(2) or first.group(2) == second.group(2)) and first.group(3) == second.group(3): text[i] = re.sub(" ?ppc64(le|x)?"," ppc64x",text[i]) text=text[:j] + (text[j+1:]) else: j += 1 i+=1 with open(file, 'w') as f: f.write("".join(text)) Change-Id: Ic6b009b54eacaadc5a23db9c5a3bf7331b595821 Reviewed-on: https://go-review.googlesource.com/c/go/+/463220 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Lynn Boger <laboger@linux.vnet.ibm.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Paul Murphy <murp@ibm.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'test/codegen/arithmetic.go')
-rw-r--r--test/codegen/arithmetic.go129
1 files changed, 43 insertions, 86 deletions
diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go
index 5139d1340a..00311e8b7f 100644
--- a/test/codegen/arithmetic.go
+++ b/test/codegen/arithmetic.go
@@ -43,75 +43,65 @@ func SubMem(arr []int, b, c, d int) int {
}
func SubFromConst(a int) int {
- // ppc64le: `SUBC\tR[0-9]+,\s[$]40,\sR`
- // ppc64: `SUBC\tR[0-9]+,\s[$]40,\sR`
+ // ppc64x: `SUBC\tR[0-9]+,\s[$]40,\sR`
b := 40 - a
return b
}
func SubFromConstNeg(a int) int {
- // ppc64le: `ADD\t[$]40,\sR[0-9]+,\sR`
- // ppc64: `ADD\t[$]40,\sR[0-9]+,\sR`
+ // ppc64x: `ADD\t[$]40,\sR[0-9]+,\sR`
c := 40 - (-a)
return c
}
func SubSubFromConst(a int) int {
- // ppc64le: `ADD\t[$]20,\sR[0-9]+,\sR`
- // ppc64: `ADD\t[$]20,\sR[0-9]+,\sR`
+ // ppc64x: `ADD\t[$]20,\sR[0-9]+,\sR`
c := 40 - (20 - a)
return c
}
func AddSubFromConst(a int) int {
- // ppc64le: `SUBC\tR[0-9]+,\s[$]60,\sR`
- // ppc64: `SUBC\tR[0-9]+,\s[$]60,\sR`
+ // ppc64x: `SUBC\tR[0-9]+,\s[$]60,\sR`
c := 40 + (20 - a)
return c
}
func NegSubFromConst(a int) int {
- // ppc64le: `ADD\t[$]-20,\sR[0-9]+,\sR`
- // ppc64: `ADD\t[$]-20,\sR[0-9]+,\sR`
+ // ppc64x: `ADD\t[$]-20,\sR[0-9]+,\sR`
c := -(20 - a)
return c
}
func NegAddFromConstNeg(a int) int {
- // ppc64le: `SUBC\tR[0-9]+,\s[$]40,\sR`
- // ppc64: `SUBC\tR[0-9]+,\s[$]40,\sR`
+ // ppc64x: `SUBC\tR[0-9]+,\s[$]40,\sR`
c := -(-40 + a)
return c
}
func SubSubNegSimplify(a, b int) int {
// amd64:"NEGQ"
- // ppc64:"NEG"
- // ppc64le:"NEG"
+ // ppc64x:"NEG"
r := (a - b) - a
return r
}
func SubAddSimplify(a, b int) int {
// amd64:-"SUBQ",-"ADDQ"
- // ppc64:-"SUB",-"ADD"
- // ppc64le:-"SUB",-"ADD"
+ // ppc64x:-"SUB",-"ADD"
r := a + (b - a)
return r
}
func SubAddNegSimplify(a, b int) int {
// amd64:"NEGQ",-"ADDQ",-"SUBQ"
- // ppc64:"NEG",-"ADD",-"SUB"
- // ppc64le:"NEG",-"ADD",-"SUB"
+ // ppc64x:"NEG",-"ADD",-"SUB"
r := a - (b + a)
return r
}
func AddAddSubSimplify(a, b, c int) int {
// amd64:-"SUBQ"
- // ppc64:-"SUB"
- // ppc64le:-"SUB"
+ // ppc64x:-"SUB"
r := a + (b + (c - a))
return r
}
@@ -125,16 +115,14 @@ func Pow2Muls(n1, n2 int) (int, int) {
// 386:"SHLL\t[$]5",-"IMULL"
// arm:"SLL\t[$]5",-"MUL"
// arm64:"LSL\t[$]5",-"MUL"
- // ppc64:"SLD\t[$]5",-"MUL"
- // ppc64le:"SLD\t[$]5",-"MUL"
+ // ppc64x:"SLD\t[$]5",-"MUL"
a := n1 * 32
// amd64:"SHLQ\t[$]6",-"IMULQ"
// 386:"SHLL\t[$]6",-"IMULL"
// arm:"SLL\t[$]6",-"MUL"
// arm64:`NEG\sR[0-9]+<<6,\sR[0-9]+`,-`LSL`,-`MUL`
- // ppc64:"SLD\t[$]6","NEG\\sR[0-9]+,\\sR[0-9]+",-"MUL"
- // ppc64le:"SLD\t[$]6","NEG\\sR[0-9]+,\\sR[0-9]+",-"MUL"
+ // ppc64x:"SLD\t[$]6","NEG\\sR[0-9]+,\\sR[0-9]+",-"MUL"
b := -64 * n2
return a, b
@@ -167,8 +155,7 @@ func MulMemSrc(a []uint32, b []float32) {
func MergeMuls1(n int) int {
// amd64:"IMUL3Q\t[$]46"
// 386:"IMUL3L\t[$]46"
- // ppc64le:"MULLD\t[$]46"
- // ppc64:"MULLD\t[$]46"
+ // ppc64x:"MULLD\t[$]46"
return 15*n + 31*n // 46n
}
@@ -183,24 +170,21 @@ func MergeMuls2(n int) int {
func MergeMuls3(a, n int) int {
// amd64:"ADDQ\t[$]19",-"IMULQ\t[$]19"
// 386:"ADDL\t[$]19",-"IMULL\t[$]19"
- // ppc64:"ADD\t[$]19",-"MULLD\t[$]19"
- // ppc64le:"ADD\t[$]19",-"MULLD\t[$]19"
+ // ppc64x:"ADD\t[$]19",-"MULLD\t[$]19"
return a*n + 19*n // (a+19)n
}
func MergeMuls4(n int) int {
// amd64:"IMUL3Q\t[$]14"
// 386:"IMUL3L\t[$]14"
- // ppc64:"MULLD\t[$]14"
- // ppc64le:"MULLD\t[$]14"
+ // ppc64x:"MULLD\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"
- // ppc64:"ADD\t[$]-19",-"MULLD\t[$]19"
- // ppc64le:"ADD\t[$]-19",-"MULLD\t[$]19"
+ // ppc64x:"ADD\t[$]-19",-"MULLD\t[$]19"
return a*n - 19*n // (a-19)n
}
@@ -219,16 +203,14 @@ func Pow2Divs(n1 uint, n2 int) (uint, int) {
// amd64:"SHRQ\t[$]5",-"DIVQ"
// arm:"SRL\t[$]5",-".*udiv"
// arm64:"LSR\t[$]5",-"UDIV"
- // ppc64:"SRD"
- // ppc64le:"SRD"
+ // ppc64x:"SRD"
a := n1 / 32 // unsigned
// amd64:"SARQ\t[$]6",-"IDIVQ"
// 386:"SARL\t[$]6",-"IDIVL"
// arm:"SRA\t[$]6",-".*udiv"
// arm64:"ASR\t[$]6",-"SDIV"
- // ppc64:"SRAD"
- // ppc64le:"SRAD"
+ // ppc64x:"SRAD"
b := n2 / 64 // signed
return a, b
@@ -262,16 +244,14 @@ func Pow2Mods(n1 uint, n2 int) (uint, int) {
// amd64:"ANDL\t[$]31",-"DIVQ"
// arm:"AND\t[$]31",-".*udiv"
// arm64:"AND\t[$]31",-"UDIV"
- // ppc64:"ANDCC\t[$]31"
- // ppc64le:"ANDCC\t[$]31"
+ // ppc64x:"ANDCC\t[$]31"
a := n1 % 32 // unsigned
// 386:"SHRL",-"IDIVL"
// amd64:"SHRQ",-"IDIVQ"
// arm:"SRA",-".*udiv"
// arm64:"ASR",-"REM"
- // ppc64:"SRAD"
- // ppc64le:"SRAD"
+ // ppc64x:"SRAD"
b := n2 % 64 // signed
return a, b
@@ -283,16 +263,14 @@ func Pow2DivisibleSigned(n1, n2 int) (bool, bool) {
// amd64:"TESTQ\t[$]63",-"DIVQ",-"SHRQ"
// arm:"AND\t[$]63",-".*udiv",-"SRA"
// arm64:"TST\t[$]63",-"UDIV",-"ASR",-"AND"
- // ppc64:"ANDCC\t[$]63",-"SRAD"
- // ppc64le:"ANDCC\t[$]63",-"SRAD"
+ // ppc64x:"ANDCC\t[$]63",-"SRAD"
a := n1%64 == 0 // signed divisible
// 386:"TESTL\t[$]63",-"DIVL",-"SHRL"
// amd64:"TESTQ\t[$]63",-"DIVQ",-"SHRQ"
// arm:"AND\t[$]63",-".*udiv",-"SRA"
// arm64:"TST\t[$]63",-"UDIV",-"ASR",-"AND"
- // ppc64:"ANDCC\t[$]63",-"SRAD"
- // ppc64le:"ANDCC\t[$]63",-"SRAD"
+ // ppc64x:"ANDCC\t[$]63",-"SRAD"
b := n2%64 != 0 // signed indivisible
return a, b
@@ -321,16 +299,14 @@ func DivisibleU(n uint) (bool, bool) {
// 386:"IMUL3L\t[$]-1431655765","ROLL\t[$]31",-"DIVQ"
// arm64:"MOVD\t[$]-6148914691236517205","MOVD\t[$]3074457345618258602","MUL","ROR",-"DIV"
// arm:"MUL","CMP\t[$]715827882",-".*udiv"
- // ppc64:"MULLD","ROTL\t[$]63"
- // ppc64le:"MULLD","ROTL\t[$]63"
+ // ppc64x:"MULLD","ROTL\t[$]63"
even := n%6 == 0
// amd64:"MOVQ\t[$]-8737931403336103397","IMULQ",-"ROLQ",-"DIVQ"
// 386:"IMUL3L\t[$]678152731",-"ROLL",-"DIVQ"
// arm64:"MOVD\t[$]-8737931403336103397","MUL",-"ROR",-"DIV"
// arm:"MUL","CMP\t[$]226050910",-".*udiv"
- // ppc64:"MULLD",-"ROTL"
- // ppc64le:"MULLD",-"ROTL"
+ // ppc64x:"MULLD",-"ROTL"
odd := n%19 == 0
return even, odd
@@ -341,20 +317,16 @@ func Divisible(n int) (bool, bool) {
// 386:"IMUL3L\t[$]-1431655765","ADDL\t[$]715827882","ROLL\t[$]31",-"DIVQ"
// arm64:"MOVD\t[$]-6148914691236517205","MOVD\t[$]3074457345618258602","MUL","ADD\tR","ROR",-"DIV"
// arm:"MUL","ADD\t[$]715827882",-".*udiv"
- // ppc64/power8:"MULLD","ADD","ROTL\t[$]63"
- // ppc64le/power8:"MULLD","ADD","ROTL\t[$]63"
- // ppc64/power9:"MADDLD","ROTL\t[$]63"
- // ppc64le/power9:"MADDLD","ROTL\t[$]63"
+ // ppc64x/power8:"MULLD","ADD","ROTL\t[$]63"
+ // ppc64x/power9:"MADDLD","ROTL\t[$]63"
even := n%6 == 0
// amd64:"IMULQ","ADD",-"ROLQ",-"DIVQ"
// 386:"IMUL3L\t[$]678152731","ADDL\t[$]113025455",-"ROLL",-"DIVQ"
// arm64:"MUL","MOVD\t[$]485440633518672410","ADD",-"ROR",-"DIV"
// arm:"MUL","ADD\t[$]113025455",-".*udiv"
- // ppc64/power8:"MULLD","ADD",-"ROTL"
- // ppc64/power9:"MADDLD",-"ROTL"
- // ppc64le/power8:"MULLD","ADD",-"ROTL"
- // ppc64le/power9:"MADDLD",-"ROTL"
+ // ppc64x/power8:"MULLD","ADD",-"ROTL"
+ // ppc64x/power9:"MADDLD",-"ROTL"
odd := n%19 == 0
return even, odd
@@ -457,8 +429,7 @@ func LenDiv1(a []int) int {
// amd64:"SHRQ\t[$]10"
// arm64:"LSR\t[$]10",-"SDIV"
// arm:"SRL\t[$]10",-".*udiv"
- // ppc64:"SRD"\t[$]10"
- // ppc64le:"SRD"\t[$]10"
+ // ppc64x:"SRD"\t[$]10"
return len(a) / 1024
}
@@ -467,8 +438,7 @@ func LenDiv2(s string) int {
// amd64:"SHRQ\t[$]11"
// arm64:"LSR\t[$]11",-"SDIV"
// arm:"SRL\t[$]11",-".*udiv"
- // ppc64:"SRD\t[$]11"
- // ppc64le:"SRD\t[$]11"
+ // ppc64x:"SRD\t[$]11"
return len(s) / (4097 >> 1)
}
@@ -478,8 +448,7 @@ func LenMod1(a []int) int {
// arm64:"AND\t[$]1023",-"SDIV"
// arm/6:"AND",-".*udiv"
// arm/7:"BFC",-".*udiv",-"AND"
- // ppc64:"ANDCC\t[$]1023"
- // ppc64le:"ANDCC\t[$]1023"
+ // ppc64x:"ANDCC\t[$]1023"
return len(a) % 1024
}
@@ -489,8 +458,7 @@ func LenMod2(s string) int {
// arm64:"AND\t[$]2047",-"SDIV"
// arm/6:"AND",-".*udiv"
// arm/7:"BFC",-".*udiv",-"AND"
- // ppc64:"ANDCC\t[$]2047"
- // ppc64le:"ANDCC\t[$]2047"
+ // ppc64x:"ANDCC\t[$]2047"
return len(s) % (4097 >> 1)
}
@@ -499,8 +467,7 @@ func CapDiv(a []int) int {
// amd64:"SHRQ\t[$]12"
// arm64:"LSR\t[$]12",-"SDIV"
// arm:"SRL\t[$]12",-".*udiv"
- // ppc64:"SRD\t[$]12"
- // ppc64le:"SRD\t[$]12"
+ // ppc64x:"SRD\t[$]12"
return cap(a) / ((1 << 11) + 2048)
}
@@ -510,8 +477,7 @@ func CapMod(a []int) int {
// arm64:"AND\t[$]4095",-"SDIV"
// arm/6:"AND",-".*udiv"
// arm/7:"BFC",-".*udiv",-"AND"
- // ppc64:"ANDCC\t[$]4095"
- // ppc64le:"ANDCC\t[$]4095"
+ // ppc64x:"ANDCC\t[$]4095"
return cap(a) % ((1 << 11) + 2048)
}
@@ -529,8 +495,7 @@ func MULA(a, b, c uint32) (uint32, uint32, uint32) {
r1 := c*79 + a
// arm:`ADD`,-`MULA`,-`MUL\s`
// arm64:`ADD`,-`MADD`,-`MULW`
- // ppc64:`ADD`,-`MULLD`
- // ppc64le:`ADD`,-`MULLD`
+ // ppc64x:`ADD`,-`MULLD`
r2 := b*64 + c
return r0, r1, r2
}
@@ -546,8 +511,7 @@ func MULS(a, b, c uint32) (uint32, uint32, uint32) {
r1 := a - c*79
// arm/7:`SUB`,-`MULS`,-`MUL\s`
// arm64:`SUB`,-`MSUBW`,-`MULW`
- // ppc64:`SUB`,-`MULLD`
- // ppc64le:`SUB`,-`MULLD`
+ // ppc64x:`SUB`,-`MULLD`
r2 := c - b*64
return r0, r1, r2
}
@@ -576,20 +540,16 @@ func divInt(v int64) int64 {
// "(z + C) -x -> C + (z - x)" can optimize the following cases.
func constantFold1(i0, j0, i1, j1, i2, j2, i3, j3 int) (int, int, int, int) {
// arm64:"SUB","ADD\t[$]2"
- // ppc64:"SUB","ADD\t[$]2"
- // ppc64le:"SUB","ADD\t[$]2"
+ // ppc64x:"SUB","ADD\t[$]2"
r0 := (i0 + 3) - (j0 + 1)
// arm64:"SUB","SUB\t[$]4"
- // ppc64:"SUB","ADD\t[$]-4"
- // ppc64le:"SUB","ADD\t[$]-4"
+ // ppc64x:"SUB","ADD\t[$]-4"
r1 := (i1 - 3) - (j1 + 1)
// arm64:"SUB","ADD\t[$]4"
- // ppc64:"SUB","ADD\t[$]4"
- // ppc64le:"SUB","ADD\t[$]4"
+ // ppc64x:"SUB","ADD\t[$]4"
r2 := (i2 + 3) - (j2 - 1)
// arm64:"SUB","SUB\t[$]2"
- // ppc64:"SUB","ADD\t[$]-2"
- // ppc64le:"SUB","ADD\t[$]-2"
+ // ppc64x:"SUB","ADD\t[$]-2"
r3 := (i3 - 3) - (j3 - 1)
return r0, r1, r2, r3
}
@@ -598,20 +558,17 @@ func constantFold1(i0, j0, i1, j1, i2, j2, i3, j3 int) (int, int, int, int) {
// "(C - z) - x -> C - (z + x)" can optimize the following cases.
func constantFold2(i0, j0, i1, j1 int) (int, int) {
// arm64:"ADD","MOVD\t[$]2","SUB"
- // ppc64le: `SUBC\tR[0-9]+,\s[$]2,\sR`
- // ppc64: `SUBC\tR[0-9]+,\s[$]2,\sR`
+ // ppc64x: `SUBC\tR[0-9]+,\s[$]2,\sR`
r0 := (3 - i0) - (j0 + 1)
// arm64:"ADD","MOVD\t[$]4","SUB"
- // ppc64le: `SUBC\tR[0-9]+,\s[$]4,\sR`
- // ppc64: `SUBC\tR[0-9]+,\s[$]4,\sR`
+ // ppc64x: `SUBC\tR[0-9]+,\s[$]4,\sR`
r1 := (3 - i1) - (j1 - 1)
return r0, r1
}
func constantFold3(i, j int) int {
// arm64: "MOVD\t[$]30","MUL",-"ADD",-"LSL"
- // ppc64:"MULLD\t[$]30","MULLD"
- // ppc64le:"MULLD\t[$]30","MULLD"
+ // ppc64x:"MULLD\t[$]30","MULLD"
r := (5 * i) * (6 * j)
return r
}