go/test/codegen
Keith Randall 611706b171 cmd/compile: don't use BTS when OR works, add direct memory BTS operations
Stop using BTSconst and friends when ORLconst can be used instead.
OR can be issued by more function units than BTS can, so it could
lead to better IPC. OR might take a few more bytes to encode, but
not a lot more.

Still use BTSconst for cases where the constant otherwise wouldn't
fit and would require a separate movabs instruction to materialize
the constant. This happens when setting bits 31-63 of 64-bit targets.

Add BTS-to-memory operations so we don't need to load/bts/store.

Fixes #61694

Change-Id: I00379608df8fb0167cb01466e97d11dec7c1596c
Reviewed-on: https://go-review.googlesource.com/c/go/+/515755
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-08-04 16:40:24 +00:00
..
addrcalc.go
alloc.go
arithmetic.go cmd/compile: add rewrite rules for arithmetic operations 2023-03-20 15:42:09 +00:00
bitfield.go
bits.go cmd/compile: don't use BTS when OR works, add direct memory BTS operations 2023-08-04 16:40:24 +00:00
bmi.go
bool.go
clobberdead.go
clobberdeadreg.go
compare_and_branch.go cmd/compile: try to rewrite loops to count down 2023-07-31 18:33:29 +00:00
comparisons.go cmd/compile: remove memequal call from string compares in more cases 2023-04-18 21:31:33 +00:00
condmove.go
copy.go
floats.go test/codegen: enable Mul2 DivPow2 test for riscv64 2023-07-04 13:33:45 +00:00
fuse.go
ifaces.go
issue22703.go
issue25378.go
issue31618.go
issue33580.go
issue38554.go
issue42610.go
issue48054.go
issue52635.go
issue54467.go
issue56440.go
issue58166.go
issue60324.go cmd/compile: incorporate inlined function names into closure naming 2023-05-22 22:47:15 +00:00
issue60673.go cmd/compile: use callsite as line number for argument marshaling 2023-06-12 20:34:37 +00:00
issue61356.go cmd/compile: get rid of special case in scheduler for entry block 2023-07-26 17:19:14 +00:00
logic.go cmd/compile: add De Morgan's rewrite rule 2023-05-10 16:32:25 +00:00
mapaccess.go
maps.go
math.go cmd/compile: fix FMA negative commutativity of riscv64 2023-07-05 22:05:44 +00:00
mathbits.go cmd/compile: don't use BTS when OR works, add direct memory BTS operations 2023-08-04 16:40:24 +00:00
memcombine.go cmd/compile: memcombine if values being stored are from consecutive loads 2023-07-21 19:06:53 +00:00
memops.go cmd/compile: don't use BTS when OR works, add direct memory BTS operations 2023-08-04 16:40:24 +00:00
memops_bigoffset.go cmd/compile: update rules to generate more prefixed instructions 2023-05-15 18:20:54 +00:00
noextend.go cmd/compile: omit redundant sign/unsign extension on arm64 2023-02-28 03:16:44 +00:00
race.go
README all: fix typos 2023-07-18 19:55:29 +00:00
regabi_regalloc.go
retpoline.go
rotate.go
select.go
shift.go
shortcircuit.go
slices.go cmd/compile: inline constant sized memclrNoHeapPointers calls on PPC64 2023-02-23 18:57:27 +00:00
smallintiface.go
spectre.go
stack.go
strings.go cmd/compile: optimize s==s for strings 2023-07-26 17:17:28 +00:00
structs.go cmd/internal/testdir: pass if GOEXPERIMENT=cgocheck2 is set 2023-06-01 18:30:44 +00:00
switch.go
zerosize.go

// 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
an action within the GOROOT/test test 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, and only on GOOS=linux.

To perform comprehensive tests for all the supported architectures
(even on a non-Linux system), one can run the following command:

  $ ../../bin/go test cmd/internal/testdir -run='Test/codegen' -all_codegen -v

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 the test. 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-running 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 than 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".