README ¶
// Copyright 2018 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. The codegen directory contains code generation tests for the gc compiler. - Introduction The test harness compiles Go code inside files in this directory and then matches the generated assembly (the output of `go tool compile -S`) against a set of regexps specified in comments that follow a special syntax (described below). The test driver is implemented as a step of the top-level test/run.go suite, called "asmcheck". The codegen tests run during all.bash, but can also be run in isolation by using $ ../bin/go run run.go -v codegen in the top-level test directory. The test harness compiles the tests with the same go toolchain that is used to run run.go. After writing tests for a newly added codegen transformation, it can be useful to first run the test harness with a toolchain from a released Go version (and verify that the new tests fail), and then re-runnig the tests using the devel toolchain. - Regexps comments syntax Instructions to match are specified inside plain comments that start with an architecture tag, followed by a colon and a quoted Go-style regexp to be matched. For example, the following test: func Sqrt(x float64) float64 { // amd64:"SQRTSD" // arm64:"FSQRTD" return math.Sqrt(x) } verifies that math.Sqrt calls are intrinsified to a SQRTSD instruction on amd64, and to a FSQRTD instruction on arm64. It is possible to put multiple architectures checks into the same line, as: // amd64:"SQRTSD" arm64:"FSQRTD" although this form should be avoided when doing so would make the regexps line excessively long and difficult to read. Comments that are on their own line will be matched against the first subsequent non-comment line. Inline comments are also supported; the regexp will be matched against the code found on the same line: func Sqrt(x float64) float64 { return math.Sqrt(x) // arm:"SQRTD" } It's possible to specify a comma-separated list of regexps to be matched. For example, the following test: func TZ8(n uint8) int { // amd64:"BSFQ","ORQ\t\\$256" return bits.TrailingZeros8(n) } verifies that the code generated for a bits.TrailingZeros8 call on amd64 contains both a "BSFQ" instruction and an "ORQ $256". Note how the ORQ regex includes a tab char (\t). In the Go assembly syntax, operands are separated from opcodes by a tabulation. Regexps can be quoted using either " or `. Special characters must be escaped accordingly. Both of these are accepted, and equivalent: // amd64:"ADDQ\t\\$3" // amd64:`ADDQ\t\$3` and they'll match this assembly line: ADDQ $3 Negative matches can be specified using a - before the quoted regexp. For example: func MoveSmall() { x := [...]byte{1, 2, 3, 4, 5, 6, 7} copy(x[1:], x[:]) // arm64:-".*memmove" } verifies that NO memmove call is present in the assembly generated for the copy() line. - Architecture specifiers There are three different ways to specify on which architecture a test should be run: * Specify only the architecture (eg: "amd64"). This indicates that the check should be run on all the supported architecture variants. For instance, arm checks will be run against all supported GOARM variations (5,6,7). * Specify both the architecture and a variant, separated by a slash (eg: "arm/7"). This means that the check will be run only on that specific variant. * Specify the operating system, the architecture and the variant, separated by slashes (eg: "plan9/386/sse2", "plan9/amd64/"). This is needed in the rare case that you need to do a codegen test affected by a specific operating system; by default, tests are compiled only targeting linux. - Remarks, and Caveats -- Write small test functions As a general guideline, test functions should be small, to avoid possible interactions between unrelated lines of code that may be introduced, for example, by the compiler's optimization passes. Any given line of Go code could get assigned more instructions that it may appear from reading the source. In particular, matching all MOV instructions should be avoided; the compiler may add them for unrelated reasons and this may render the test ineffective. -- Line matching logic Regexps are always matched from the start of the instructions line. This means, for example, that the "MULQ" regexp is equivalent to "^MULQ" (^ representing the start of the line), and it will NOT match the following assembly line: IMULQ $99, AX To force a match at any point of the line, ".*MULQ" should be used. For the same reason, a negative regexp like -"memmove" is not enough to make sure that no memmove call is included in the assembly. A memmove call looks like this: CALL runtime.memmove(SB) To make sure that the "memmove" symbol does not appear anywhere in the assembly, the negative regexp to be used is -".*memmove".
Documentation ¶
Index ¶
- func AccessInt1(m map[int]int) int
- func AccessInt2(m map[int]int) bool
- func AccessString1(m map[string]int) int
- func AccessString2(m map[string]int) bool
- func AddMul(x int) int
- func ArrayAdd64(a, b [4]float64) [4]float64
- func ArrayCopy(a [16]byte) (b [16]byte)
- func ArrayInit(i, j int) [4]int
- func ArrayZero() [16]byte
- func CapDiv(a []int) int
- func CapMod(a []int) int
- func CmpFold(x uint32) bool
- func CmpMem1(p int, q *int) bool
- func CmpMem2(p *int, q int) bool
- func CmpMem3(p *int) bool
- func CmpMem4(p *int) bool
- func CmpMem5(p **int)
- func CmpMem6(a []int) int
- func CmpToZero(a, b int32) int32
- func CmpZero1(a int32, ptr *int)
- func CmpZero2(a int64, ptr *int)
- func CmpZero3(a int32, ptr *int)
- func CmpZero4(a int64, ptr *int)
- func CompareArray1(a, b [2]byte) bool
- func CompareArray2(a, b [3]uint16) bool
- func CompareArray3(a, b [3]int16) bool
- func CompareArray4(a, b [12]int8) bool
- func CompareArray5(a, b [15]byte) bool
- func CompareArray6(a, b unsafe.Pointer) bool
- func CompareString1(s string) bool
- func CompareString2(s string) bool
- func CompareString3(s string) bool
- func ConstDivs(n1 uint, n2 int) (uint, int)
- func ConstMods(n1 uint, n2 int) (uint, int)
- func CountRunes(s string) int
- func DivMemSrc(a []float64)
- func DivPow2(f1, f2, f3 float64) (float64, float64, float64)
- func FloatDivs(a []float32) float32
- func FusedAdd32(x, y, z float32) float32
- func FusedAdd64(x, y, z float64) float64
- func FusedSub32(x, y, z float32) float32
- func FusedSub64(x, y, z float64) float64
- func Init1(p *I1)
- func IterateBits(n uint) int
- func IterateBits16(n uint16) int
- func IterateBits32(n uint32) int
- func IterateBits64(n uint64) int
- func IterateBits8(n uint8) int
- func KeepWanted(t *T)
- func LeadingZeros(n uint) int
- func LeadingZeros16(n uint16) int
- func LeadingZeros32(n uint32) int
- func LeadingZeros64(n uint64) int
- func LeadingZeros8(n uint8) int
- func Len(n uint) int
- func Len16(n uint16) int
- func Len32(n uint32) int
- func Len64(n uint64) int
- func Len8(n uint8) int
- func LenDiv1(a []int) int
- func LenDiv2(s string) int
- func LenMod1(a []int) int
- func LenMod2(s string) int
- func MapClearIndirect(m map[int]int)
- func MapClearInterface(m map[interface{}]int)
- func MapClearNotReflexive(m map[float64]int)
- func MapClearPointer(m map[*byte]int)
- func MapClearReflexive(m map[int]int)
- func MapClearSideEffect(m map[int]int) int
- func MergeMuls1(n int) int
- func MergeMuls2(n int) int
- func MergeMuls3(a, n int) int
- func MergeMuls4(n int) int
- func MergeMuls5(a, n int) int
- func Mul2(f float64) float64
- func MulMemSrc(a []uint32, b []float32)
- func Mul_96(n int) int
- func OnesCount(n uint) int
- func OnesCount16(n uint16) int
- func OnesCount32(n uint32) int
- func OnesCount64(n uint64) int
- func Pow2Divs(n1 uint, n2 int) (uint, int)
- func Pow2Mods(n1 uint, n2 int) (uint, int)
- func Pow2Muls(n1, n2 int) (int, int)
- func ReverseBytes(n uint) uint
- func ReverseBytes16(n uint16) uint16
- func ReverseBytes32(n uint32) uint32
- func ReverseBytes64(n uint64) uint64
- func RotateLeft16(n uint16) uint16
- func RotateLeft32(n uint32) uint32
- func RotateLeft64(n uint64) uint64
- func RotateLeft8(n uint8) uint8
- func SliceClear(s []int) []int
- func SliceClearPointers(s []*int) []*int
- func SliceExtensionConst(s []int) []int
- func SliceExtensionInt64(s []int, l64 int64) []int
- func SliceExtensionPointer(s []*int, l int) []*int
- func SliceExtensionVar(s []byte, l int) []byte
- func StackStore() int
- func SubMem(arr []int, b int) int
- func TrailingZeros(n uint) int
- func TrailingZeros16(n uint16) int
- func TrailingZeros32(n uint32) int
- func TrailingZeros64(n uint64) int
- func TrailingZeros8(n uint8) int
- func Zero1(t *Z1)
- func Zero2(t *Z2)
- func ZeroLargeStruct(x *T)
- type I
- type I1
- type T
- type Z1
- type Z2
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessInt1 ¶
func AccessInt2 ¶
func AccessString1 ¶
func AccessString2 ¶
func ArrayAdd64 ¶
Notes: - 386 fails due to spilling a register - arm & mips fail due to softfloat calls amd64:"TEXT\t.*, [$]0-" arm64:"TEXT\t.*, [$]-8-" ppc64le:"TEXT\t.*, [$]0-" s390x:"TEXT\t.*, [$]0-"
func ArrayInit ¶
386:"TEXT\t.*, [$]0-" amd64:"TEXT\t.*, [$]0-" arm:"TEXT\t.*, [$]0-" (spills return address) arm64:"TEXT\t.*, [$]-8-" mips:"TEXT\t.*, [$]-4-" ppc64le:"TEXT\t.*, [$]0-" s390x:"TEXT\t.*, [$]0-"
func CompareArray1 ¶
func CompareArray2 ¶
func CompareArray3 ¶
func CompareArray4 ¶
func CompareArray5 ¶
func CompareArray6 ¶
This was a TODO in mapaccess1_faststr
func CompareString1 ¶
func CompareString2 ¶
func CompareString3 ¶
func CountRunes ¶
func FusedAdd32 ¶
func FusedAdd64 ¶
func FusedSub32 ¶
func FusedSub64 ¶
func IterateBits ¶
func IterateBits16 ¶
func IterateBits32 ¶
func IterateBits64 ¶
func IterateBits8 ¶
func KeepWanted ¶
func KeepWanted(t *T)
Notes: - 386 fails due to spilling a register amd64:"TEXT\t.*, [$]0-" arm:"TEXT\t.*, [$]0-" (spills return address) arm64:"TEXT\t.*, [$]-8-" ppc64le:"TEXT\t.*, [$]0-" s390x:"TEXT\t.*, [$]0-" Note: that 386 currently has to spill a register.
func LeadingZeros ¶
func LeadingZeros16 ¶
func LeadingZeros32 ¶
func LeadingZeros64 ¶
func LeadingZeros8 ¶
func MapClearIndirect ¶
func MapClearInterface ¶
func MapClearInterface(m map[interface{}]int)
func MapClearNotReflexive ¶
func MapClearPointer ¶
func MapClearReflexive ¶
func MapClearSideEffect ¶
func MergeMuls1 ¶
func MergeMuls2 ¶
func MergeMuls3 ¶
func MergeMuls4 ¶
func MergeMuls5 ¶
func OnesCount16 ¶
func OnesCount32 ¶
func OnesCount64 ¶
func ReverseBytes ¶
func ReverseBytes16 ¶
func ReverseBytes32 ¶
func ReverseBytes64 ¶
func RotateLeft16 ¶
func RotateLeft32 ¶
func RotateLeft64 ¶
func RotateLeft8 ¶
func SliceClear ¶
func SliceClearPointers ¶
func SliceExtensionConst ¶
func SliceExtensionInt64 ¶
func SliceExtensionPointer ¶
func SliceExtensionVar ¶
func StackStore ¶
func StackStore() int
386:"TEXT\t.*, [$]0-" amd64:"TEXT\t.*, [$]0-" arm:"TEXT\t.*, [$]-4-" arm64:"TEXT\t.*, [$]-8-" mips:"TEXT\t.*, [$]-4-" ppc64le:"TEXT\t.*, [$]0-" s390x:"TEXT\t.*, [$]0-"
func TrailingZeros ¶
func TrailingZeros16 ¶
func TrailingZeros32 ¶
func TrailingZeros64 ¶
func TrailingZeros8 ¶
func ZeroLargeStruct ¶
func ZeroLargeStruct(x *T)
386:"TEXT\t.*, [$]0-" amd64:"TEXT\t.*, [$]0-" arm:"TEXT\t.*, [$]0-" (spills return address) arm64:"TEXT\t.*, [$]-8-" mips:"TEXT\t.*, [$]-4-" ppc64le:"TEXT\t.*, [$]0-" s390x:"TEXT\t.*, [$]0-"