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 matches the generated assembly (the output of `go tool compile -S`) against a set of regexps to be 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 harness is part of the all.bash test suite, but for performance reasons only the codegen tests for the host machine's GOARCH are enabled by default. To perform comprehensive tests for all the supported architectures, one can run the following command $ ../bin/go run run.go -all_codegen -v codegen in the top-level test directory. This is recommended after any change that affect the compiler's code. 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 ¶
- Constants
- 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 Add(x, y, ci uint) (r, co uint)
- func Add64(x, y, ci uint64) (r, co uint64)
- func Add64C(x, ci uint64) (r, co uint64)
- func Add64M(p, q, r *[3]uint64)
- func Add64R(x, y, ci uint64) uint64
- func Add64Z(x, y uint64) (r, co uint64)
- func AddC(x, ci uint) (r, co uint)
- func AddM(p, q, r *[3]uint)
- func AddMul(x int) int
- func AddR(x, y, ci uint) uint
- func AddZ(x, y uint) (r, co uint)
- 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 Cmp(f float64) bool
- func CmpFold(x uint32) bool
- func CmpLogicalToZero(a, b, c uint32, d, e uint64) uint64
- 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, d int32, e, f int64) 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 ConstantLoad()
- func CountRunes(s string) int
- func Defer()
- func Div(hi, lo, x uint) (q, r uint)
- func Div32(hi, lo, x uint32) (q, r uint32)
- func Div64(hi, lo, x uint64) (q, r uint64)
- func Div64degenerate(x uint64) (q, r uint64)
- func DivMemSrc(a []float64)
- func DivPow2(f1, f2, f3 float64) (float64, float64, float64)
- func Divisible(n1 uint, n2 int) (bool, bool, bool, bool)
- func FloatDivs(a []float32) float32
- func FusedAdd32(x, y, z float32) float32
- func FusedAdd64(x, y, z float64) float64
- func FusedSub32_a(x, y, z float32) float32
- func FusedSub32_b(x, y, z float32) float32
- func FusedSub64_a(x, y, z float64) float64
- func FusedSub64_b(x, y, z float64) float64
- func Init1(p *I1)
- func InitNotSmallSliceLiteral() []int
- func InitSmallSliceLiteral() []int
- 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 LookupStringConversionArrayLit(m map[[2]string]int, bytes []byte) int
- func LookupStringConversionKeyedArrayLit(m map[[2]string]int, bytes []byte) int
- func LookupStringConversionNestedLit(m map[[1]struct{ ... }]int, bytes []byte) int
- func LookupStringConversionSimple(m map[string]int, bytes []byte) int
- func LookupStringConversionStructLit(m map[struct{ ... }]int, bytes []byte) int
- func MULA(a, b, c uint32) (uint32, uint32, uint32)
- func MULS(a, b, c uint32) (uint32, uint32, uint32)
- 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 MightPanic(a []int, i, j, k, s int)
- func Mul(x, y uint) (hi, lo uint)
- func Mul2(f float64) float64
- func Mul64(x, y uint64) (hi, lo uint64)
- func MulMemSrc(a []uint32, b []float32)
- func Mul_96(n int) int
- func NoFix16A(divr int16) (int16, int16)
- func NoFix16B(divd int16) (int16, int16)
- func NoFix32A(divr int32) (int32, int32)
- func NoFix32B(divd int32) (int32, int32)
- func NoFix64A(divr int64) (int64, int64)
- func NoFix64B(divd int64) (int64, int64)
- func OnesCount(n uint) int
- func OnesCount16(n uint16) int
- func OnesCount32(n uint32) int
- func OnesCount64(n uint64) int
- func OnesCount8(n uint8) int
- func Pow2DivisibleSigned(n int) bool
- func Pow2Divs(n1 uint, n2 int) (uint, int)
- func Pow2Mods(n1 uint, n2 int) (uint, int)
- func Pow2Muls(n1, n2 int) (int, int)
- func RaceMightPanic(a []int, i, j, k, s 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 RotateLeftVariable(n uint, m int) uint
- func RotateLeftVariable32(n uint32, m int) uint32
- func RotateLeftVariable64(n uint64, m int) uint64
- func SliceClear(s []int) []int
- func SliceClearPointers(s []*int) []*int
- func SliceExtensionConst(s []int) []int
- func SliceExtensionConstInt64(s []int) []int
- func SliceExtensionConstUint(s []int) []int
- func SliceExtensionConstUint64(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 SliceExtensionVarInt64(s []byte, l int64) []byte
- func SliceExtensionVarUint(s []byte, l uint) []byte
- func SliceExtensionVarUint64(s []byte, l uint64) []byte
- func SliceNilCheck(s []int)
- func StackStore() int
- func Sub(x, y, ci uint) (r, co uint)
- func Sub64(x, y, ci uint64) (r, co uint64)
- func Sub64C(x, ci uint64) (r, co uint64)
- func Sub64M(p, q, r *[3]uint64)
- func Sub64R(x, y, ci uint64) uint64
- func Sub64Z(x, y uint64) (r, co uint64)
- func SubC(x, ci uint) (r, co uint)
- func SubM(p, q, r *[3]uint)
- func SubMem(arr []int, b, c, d int) int
- func SubR(x, y, ci uint) uint
- func SubZ(x, y uint) (r, co uint)
- func ToByteSlice() []byte
- 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 ¶
const ( A = 7777777777777777 B = 8888888888888888 )
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.*, [$]0-" ppc64:"TEXT\t.*, [$]0-" 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.*, [$]0-" mips:"TEXT\t.*, [$]-4-" ppc64:"TEXT\t.*, [$]0-" ppc64le:"TEXT\t.*, [$]0-" s390x:"TEXT\t.*, [$]0-"
func CmpLogicalToZero ¶
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 ConstantLoad ¶
func ConstantLoad()
Loading from read-only symbols should get transformed into constants.
func CountRunes ¶
func Div64degenerate ¶
func FusedAdd32 ¶
func FusedAdd64 ¶
func FusedSub32_a ¶
func FusedSub32_b ¶
func FusedSub64_a ¶
func FusedSub64_b ¶
func InitNotSmallSliceLiteral ¶
func InitNotSmallSliceLiteral() []int
func InitSmallSliceLiteral ¶
func InitSmallSliceLiteral() []int
---------------------- //
Init slice literal //
---------------------- // See issue 21561
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.*, [$]0-" ppc64:"TEXT\t.*, [$]0-" 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 MightPanic ¶
Check that simple functions get promoted to nosplit, even when they might panic in various ways. See issue 31219. amd64:"TEXT\t.*NOSPLIT.*"
func NoFix64A ¶
Check that fix-up code is not generated for divisions where it has been proven that that the divisor is not -1 or that the dividend is > MinIntNN.
func OnesCount16 ¶
func OnesCount32 ¶
func OnesCount64 ¶
func OnesCount8 ¶
func Pow2DivisibleSigned ¶
Check that signed divisibility checks get converted to AND on low bits
func RaceMightPanic ¶
Check that we elide racefuncenter/racefuncexit for functions with no calls (but which might panic in various ways). See issue 31219. amd64:-"CALL.*racefuncenter.*"
func ReverseBytes ¶
func ReverseBytes16 ¶
func ReverseBytes32 ¶
func ReverseBytes64 ¶
func RotateLeft16 ¶
func RotateLeft32 ¶
func RotateLeft64 ¶
func RotateLeft8 ¶
func RotateLeftVariable ¶
func RotateLeftVariable32 ¶
func RotateLeftVariable64 ¶
func SliceClear ¶
func SliceClearPointers ¶
func SliceExtensionConst ¶
func SliceExtensionConstUint ¶
func SliceExtensionInt64 ¶
func SliceExtensionPointer ¶
func SliceExtensionVar ¶
func SliceExtensionVarInt64 ¶
func SliceExtensionVarUint ¶
func SliceExtensionVarUint64 ¶
func SliceNilCheck ¶
func SliceNilCheck(s []int)
---------------------- //
Nil check of &s[0] //
---------------------- // See issue 30366
func StackStore ¶
func StackStore() int
386:"TEXT\t.*, [$]0-" amd64:"TEXT\t.*, [$]0-" arm:"TEXT\t.*, [$]-4-" arm64:"TEXT\t.*, [$]0-" mips:"TEXT\t.*, [$]-4-" ppc64:"TEXT\t.*, [$]0-" ppc64le:"TEXT\t.*, [$]0-" s390x:"TEXT\t.*, [$]0-"
func ToByteSlice ¶
func ToByteSlice() []byte
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.*, [$]0-" mips:"TEXT\t.*, [$]-4-" ppc64:"TEXT\t.*, [$]0-" ppc64le:"TEXT\t.*, [$]0-" s390x:"TEXT\t.*, [$]0-"
Types ¶
Source Files ¶
- alloc.go
- arithmetic.go
- bitfield.go
- bits.go
- compare_and_branch.go
- comparisons.go
- condmove.go
- copy.go
- floats.go
- issue22703.go
- issue25378.go
- issue31618.go
- issue33580.go
- mapaccess.go
- maps.go
- math.go
- mathbits.go
- memcombine.go
- memops.go
- noextend.go
- race.go
- rotate.go
- shift.go
- slices.go
- stack.go
- strings.go
- structs.go
- switch.go
- zerosize.go