codegen

package
v0.0.0-...-70d8496 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2019 License: BSD-3-Clause Imports: 3 Imported by: 0

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.


- 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

This section is empty.

Variables

This section is empty.

Functions

func CapDiv

func CapDiv(a []int) int

func CapMod

func CapMod(a []int) int

func ConstDivs

func ConstDivs(n1 uint, n2 int) (uint, int)

Check that constant divisions get turned into MULs

func ConstMods

func ConstMods(n1 uint, n2 int) (uint, int)

Check that constant modulo divs get turned into MULs

func LeadingZeros

func LeadingZeros(n uint) int

func LeadingZeros16

func LeadingZeros16(n uint16) int

func LeadingZeros32

func LeadingZeros32(n uint32) int

func LeadingZeros64

func LeadingZeros64(n uint64) int

func LeadingZeros8

func LeadingZeros8(n uint8) int

func Len

func Len(n uint) int

func Len16

func Len16(n uint16) int

func Len32

func Len32(n uint32) int

func Len64

func Len64(n uint64) int

func Len8

func Len8(n uint8) int

func LenDiv1

func LenDiv1(a []int) int

func LenDiv2

func LenDiv2(s string) int

func LenMod1

func LenMod1(a []int) int

func LenMod2

func LenMod2(s string) int

func MergeMuls1

func MergeMuls1(n int) int

func MergeMuls2

func MergeMuls2(n int) int

func MergeMuls3

func MergeMuls3(a, n int) int

func MergeMuls4

func MergeMuls4(n int) int

func MergeMuls5

func MergeMuls5(a, n int) int

func OnesCount

func OnesCount(n uint) int

func OnesCount16

func OnesCount16(n uint16) int

func OnesCount32

func OnesCount32(n uint32) int

func OnesCount64

func OnesCount64(n uint64) int

func Pow2Divs

func Pow2Divs(n1 uint, n2 int) (uint, int)

func Pow2Mods

func Pow2Mods(n1 uint, n2 int) (uint, int)

func Pow2Muls

func Pow2Muls(n1, n2 int) (int, int)

func ReverseBytes

func ReverseBytes(n uint) uint

func ReverseBytes16

func ReverseBytes16(n uint16) uint16

func ReverseBytes32

func ReverseBytes32(n uint32) uint32

func ReverseBytes64

func ReverseBytes64(n uint64) uint64

func RotateLeft16

func RotateLeft16(n uint16) uint16

func RotateLeft32

func RotateLeft32(n uint32) uint32

func RotateLeft64

func RotateLeft64(n uint64) uint64

func RotateLeft8

func RotateLeft8(n uint8) uint8

func TrailingZeros

func TrailingZeros(n uint) int

func TrailingZeros16

func TrailingZeros16(n uint16) int

func TrailingZeros32

func TrailingZeros32(n uint32) int

func TrailingZeros64

func TrailingZeros64(n uint64) int

func TrailingZeros8

func TrailingZeros8(n uint8) int

Types

type I

type I interface {
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL