go/test/codegen
Alberto Donizetti 467eca6076 test/codegen: port last stack and memcombining tests
And delete them from asm_test.

Also delete an arm64 cmov test has been already ported to the new test
harness.

Change-Id: I4458721e1f512bc9ecbbe1c22a2c9c7109ad68fe
Reviewed-on: https://go-review.googlesource.com/106335
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Giovanni Bajo <rasky@develer.com>
2018-04-11 16:08:04 +00:00
..
arithmetic.go test/codegen: port last remaining misc bit/arithmetic tests 2018-04-10 07:58:35 +00:00
bitfield.go test/codegen: port last remaining misc bit/arithmetic tests 2018-04-10 07:58:35 +00:00
bits.go test/codegen: port arm64 BIC/EON/ORN and masking tests 2018-04-10 10:57:50 +00:00
comparisons.go cmd/compile: optimize comparisons using load merging where available 2018-04-09 21:16:47 +00:00
condmove.go cmd/compile: implement CMOV on amd64 2018-03-15 16:41:59 +00:00
floats.go test/codegen: match 387 ops too for GOARCH=386 2018-03-29 20:05:40 +00:00
issue22703.go test: port a nil-check interface test from asm_test 2018-03-03 20:20:54 +00:00
mapaccess.go cmd/compile: avoid mapaccess at m[k]=append(m[k].. 2018-03-20 01:47:07 +00:00
maps.go test/codegen: port maps test to codegen 2018-03-19 13:39:34 +00:00
math.go cmd/compile: add patterns for bit set/clear/complement on amd64 2018-03-24 02:38:50 +00:00
mathbits.go cmd/compile: add patterns for bit set/clear/complement on amd64 2018-03-24 02:38:50 +00:00
memcombine.go test/codegen: port last stack and memcombining tests 2018-04-11 16:08:04 +00:00
movesmall.go test/codegen: port all small memmove tests to codegen 2018-03-14 15:57:07 +00:00
README test/codegen: add README file for the codegen test harness 2018-03-09 18:38:53 +00:00
rotate.go test: move rotate tests to top-level testsuite. 2018-03-11 10:08:18 +00:00
stack.go test/codegen: port last stack and memcombining tests 2018-04-11 16:08:04 +00:00
structs.go test/codegen: port structs test to codegen 2018-03-18 16:53:53 +00:00

// 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".