]> Cypherpunks repositories - gostls13.git/commitdiff
test/codegen: port MULs merging tests to codegen
authorAlberto Donizetti <alb.donizetti@gmail.com>
Fri, 9 Mar 2018 13:51:30 +0000 (14:51 +0100)
committerAlberto Donizetti <alb.donizetti@gmail.com>
Fri, 9 Mar 2018 17:01:56 +0000 (17:01 +0000)
And delete them from asm_go.

Change-Id: I0057cbd90ca55fa51c596e32406e190f3866f93e
Reviewed-on: https://go-review.googlesource.com/99815
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/asm_test.go
test/codegen/arithmetic.go

index 96d0bc0d08446ac3e5c8544e19a39fed39e6ad60..bed9ba9a41bb251b0e845167bfcbe790c6f9bd3b 100644 (file)
@@ -499,43 +499,6 @@ var linuxAMD64Tests = []*asmTest{
                `,
                pos: []string{"\tBTQ\t\\$60"},
        },
-       // multiplication merging tests
-       {
-               fn: `
-               func mul1(n int) int {
-                       return 15*n + 31*n
-               }`,
-               pos: []string{"\tIMULQ\t[$]46"}, // 46*n
-       },
-       {
-               fn: `
-               func mul2(n int) int {
-                       return 5*n + 7*(n+1) + 11*(n+2)
-               }`,
-               pos: []string{"\tIMULQ\t[$]23", "\tADDQ\t[$]29"}, // 23*n + 29
-       },
-       {
-               fn: `
-               func mul3(a, n int) int {
-                       return a*n + 19*n
-               }`,
-               pos: []string{"\tADDQ\t[$]19", "\tIMULQ"}, // (a+19)*n
-       },
-       {
-               fn: `
-               func mul4(n int) int {
-                       return 23*n - 9*n
-               }`,
-               pos: []string{"\tIMULQ\t[$]14"}, // 14*n
-       },
-       {
-               fn: `
-               func mul5(a, n int) int {
-                       return a*n - 19*n
-               }`,
-               pos: []string{"\tADDQ\t[$]-19", "\tIMULQ"}, // (a-19)*n
-       },
-
        // see issue 19595.
        // We want to merge load+op in f58, but not in f59.
        {
@@ -906,21 +869,6 @@ var linuxAMD64Tests = []*asmTest{
 }
 
 var linux386Tests = []*asmTest{
-       // multiplication merging tests
-       {
-               fn: `
-               func $(n int) int {
-                       return 9*n + 14*n
-               }`,
-               pos: []string{"\tIMULL\t[$]23"}, // 23*n
-       },
-       {
-               fn: `
-               func $(a, n int) int {
-                       return 19*a + a*n
-               }`,
-               pos: []string{"\tADDL\t[$]19", "\tIMULL"}, // (n+19)*a
-       },
        {
                // check that stack store is optimized away
                fn: `
@@ -931,20 +879,6 @@ var linux386Tests = []*asmTest{
                `,
                pos: []string{"TEXT\t.*, [$]0-4"},
        },
-       {
-               fn: `
-               func mul3(n int) int {
-                       return 23*n - 9*n
-               }`,
-               pos: []string{"\tIMULL\t[$]14"}, // 14*n
-       },
-       {
-               fn: `
-               func mul4(a, n int) int {
-                       return n*a - a*19
-               }`,
-               pos: []string{"\tADDL\t[$]-19", "\tIMULL"}, // (n-19)*a
-       },
        // Check that len() and cap() div by a constant power of two
        // are compiled into SHRL.
        {
index c09fad60c811ca44b47b2c50a24a86272b3bc0a6..eecb1013957b127f47b347765a2145ffd4a3894c 100644 (file)
@@ -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
+}