]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: intrinsify math/bits.ReverseBytes
authorKeith Randall <keithr@alum.mit.edu>
Thu, 16 Mar 2017 04:28:29 +0000 (21:28 -0700)
committerKeith Randall <khr@golang.org>
Thu, 16 Mar 2017 19:41:56 +0000 (19:41 +0000)
Update #18616

Change-Id: I0c2d643cbbeb131b4c9b12194697afa4af48e1d2
Reviewed-on: https://go-review.googlesource.com/38166
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/asm_test.go
src/cmd/compile/internal/gc/ssa.go

index 15b8fecdc4aefce15225a2b1611e80a621e95a5b..6d56cf6066caac65773c8ae8b4e89322eba50ee6 100644 (file)
@@ -183,9 +183,10 @@ var allAsmTests = []*asmTests{
                tests: linuxARMTests,
        },
        {
-               arch:  "arm64",
-               os:    "linux",
-               tests: linuxARM64Tests,
+               arch:    "arm64",
+               os:      "linux",
+               imports: []string{"math/bits"},
+               tests:   linuxARM64Tests,
        },
 }
 
@@ -576,6 +577,30 @@ var linuxAMD64Tests = []*asmTest{
                `,
                []string{"\tBSFQ\t", "\tORQ\t\\$256,"},
        },
+       {
+               `
+               func f45(a uint64) uint64 {
+                       return bits.ReverseBytes64(a)
+               }
+               `,
+               []string{"\tBSWAPQ\t"},
+       },
+       {
+               `
+               func f46(a uint32) uint32 {
+                       return bits.ReverseBytes32(a)
+               }
+               `,
+               []string{"\tBSWAPL\t"},
+       },
+       {
+               `
+               func f47(a uint16) uint16 {
+                       return bits.ReverseBytes16(a)
+               }
+               `,
+               []string{"\tROLW\t\\$8,"},
+       },
 }
 
 var linux386Tests = []*asmTest{
@@ -776,6 +801,23 @@ var linuxS390XTests = []*asmTest{
                `,
                []string{"\tFLOGR\t", "\tOR\t\\$256,"},
        },
+       // Intrinsic tests for math/bits
+       {
+               `
+               func f22(a uint64) uint64 {
+                       return bits.ReverseBytes64(a)
+               }
+               `,
+               []string{"\tMOVDBR\t"},
+       },
+       {
+               `
+               func f23(a uint32) uint32 {
+                       return bits.ReverseBytes32(a)
+               }
+               `,
+               []string{"\tMOVWBR\t"},
+       },
 }
 
 var linuxARMTests = []*asmTest{
@@ -854,6 +896,22 @@ var linuxARM64Tests = []*asmTest{
                `,
                []string{"\tRORW\t[$]25,"},
        },
+       {
+               `
+               func f22(a uint64) uint64 {
+                       return bits.ReverseBytes64(a)
+               }
+               `,
+               []string{"\tREV\t"},
+       },
+       {
+               `
+               func f23(a uint32) uint32 {
+                       return bits.ReverseBytes32(a)
+               }
+               `,
+               []string{"\tREVW\t"},
+       },
 }
 
 // TestLineNumber checks to make sure the generated assembly has line numbers
index 1791e65bf14e2ec8ac8d84239c636f4330d1d5cb..bd766a587050867b9e7dc25faa6d8acb97ecdd7c 100644 (file)
@@ -2702,6 +2702,10 @@ func init() {
                        return s.newValue1(ssa.OpCtz64, Types[TINT], y)
                },
                sys.AMD64, sys.ARM64, sys.S390X)
+       alias("math/bits", "ReverseBytes64", "runtime/internal/sys", "Bswap64", all...)
+       alias("math/bits", "ReverseBytes32", "runtime/internal/sys", "Bswap32", all...)
+       // ReverseBytes inlines correctly, no need to intrinsify it.
+       // ReverseBytes16 lowers to a rotate, no need for anything special here.
 
        /******** sync/atomic ********/