1
0
mirror of https://github.com/golang/go synced 2024-11-06 06:26:13 -07:00
go/test/codegen
Lynn Boger a1550d3ca3 cmd/compile: use isel with variable shifts on ppc64x
This changes the code generated for variable length shift
counts to use isel instead of instructions that set and
read the carry flag.

This reduces the generated code for shifts like this
by 1 instruction and avoids the use of instructions to
set and read the carry flag.

This sequence can be found in strconv with these results
on power9:

Atof64Decimal                          71.6ns ± 0%  68.3ns ± 0%   -4.61%
Atof64Float                            95.3ns ± 0%  90.9ns ± 0%   -4.62%
Atof64FloatExp                          153ns ± 0%   149ns ± 0%   -2.61%
Atof64Big                               234ns ± 0%   232ns ± 0%   -0.85%
Atof64RandomBits                        348ns ± 0%   369ns ± 0%   +6.03%
Atof64RandomFloats                      262ns ± 0%   262ns ± 0%     ~
Atof32Decimal                          72.0ns ± 0%  68.2ns ± 0%   -5.28%
Atof32Float                            92.1ns ± 0%  87.1ns ± 0%   -5.43%
Atof32FloatExp                          159ns ± 0%   158ns ± 0%   -0.63%
Atof32Random                            194ns ± 0%   191ns ± 0%   -1.55%

Some tests in codegen/shift.go are enabled to verify the
expected instructions are generated.

Change-Id: I968715d10ada405a8c46132bf19b8ed9b85796d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/227337
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-04-09 19:18:56 +00:00
..
addrcalc.go cmd/compile: use ADDQ instead of LEAQ when we can 2020-02-24 21:33:53 +00:00
alloc.go
arithmetic.go Revert "cmd/compile: disable mem+op operations on 386" 2020-03-24 19:06:22 +00:00
bitfield.go
bits.go cmd/compile: optimize bitset tests 2019-08-27 18:01:16 +00:00
compare_and_branch.go cmd/compile: canonicalize comparison argument order 2020-02-26 10:32:22 +00:00
comparisons.go test/codegen: fix wasm codegen breakage 2019-09-21 16:31:44 +00:00
condmove.go cmd/compile: canonicalize comparison argument order 2020-02-26 10:32:22 +00:00
copy.go cmd/compile: improve lowered moves and zeros for ppc64le 2020-04-06 12:09:39 +00:00
floats.go cmd/compile: allow floating point Ops to produce flags on s390x 2020-04-08 20:57:58 +00:00
fuse.go cmd/compile: optimize integer-in-range checks 2020-03-03 14:30:26 +00:00
issue22703.go
issue25378.go
issue31618.go
issue33580.go cmd/compile: reuse dead register before reusing register holding constant 2019-10-07 15:16:26 +00:00
mapaccess.go
maps.go
math.go cmd/compile: don't allow NaNs in floating-point constant ops 2020-03-04 04:49:54 +00:00
mathbits.go cmd/compile: add intrinsic HasCPUFeature for checking cpu features 2020-04-04 01:01:04 +00:00
memcombine.go cmd/compile: fix ephemeral pointer problem on amd64 2020-03-30 17:25:29 +00:00
memops.go cmd/compile: add indexed-load CMP instructions 2020-04-01 17:03:26 +00:00
noextend.go
race.go
README test/codegen: mention in README that tests only run on Linux without -all_codegen 2020-03-11 16:17:08 +00:00
retpoline.go cmd/asm, cmd/compile, runtime: add -spectre=ret mode 2020-03-13 19:05:54 +00:00
rotate.go
shift.go cmd/compile: use isel with variable shifts on ppc64x 2020-04-09 19:18:56 +00:00
shortcircuit.go cmd/compile: handle some additional phis in shortcircuit 2020-04-08 22:13:38 +00:00
slices.go cmd/compile: don't use statictmps for small object in slice literal 2019-10-08 06:09:26 +00:00
smallintiface.go cmd/compile: use staticuint64s instead of staticbytes 2020-03-04 21:43:01 +00:00
spectre.go cmd/compile: add spectre mitigation mode enabled by -spectre 2020-03-13 19:05:46 +00:00
stack.go misc, runtime, test: extra tests and benchmarks for defer 2019-09-25 23:27:16 +00:00
strings.go cmd/compile: apply optimization for readonly globals on wasm 2019-08-28 05:55:52 +00:00
structs.go cmd/compile, runtime: use more registers for amd64 write barrier calls 2020-03-31 21:26:33 +00:00
switch.go cmd/compile: optimize switch on strings 2019-09-18 05:33:05 +00:00
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 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, 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 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 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".