1
0
mirror of https://github.com/golang/go synced 2024-11-06 02:26:17 -07:00
go/test/codegen
Lynn Boger ebe49f98c8 cmd/compile: inline constant sized memclrNoHeapPointers calls on PPC64
Update the function isInlinableMemclr for ppc64 and ppc64le
to enable inlining for the constant sized cases < 512.

Larger cases can use dcbz which performs better but requires
alignment checking so it is best to continue using memclrNoHeapPointers
for those cases.

Results on p10:

MemclrKnownSize1         2.07ns ± 0%     0.57ns ± 0%   -72.59%
MemclrKnownSize2         2.56ns ± 5%     0.57ns ± 0%   -77.82%
MemclrKnownSize4         5.15ns ± 0%     0.57ns ± 0%   -89.00%
MemclrKnownSize8         2.23ns ± 0%     0.57ns ± 0%   -74.57%
MemclrKnownSize16        2.23ns ± 0%     0.50ns ± 0%   -77.74%
MemclrKnownSize32        2.28ns ± 0%     0.56ns ± 0%   -75.28%
MemclrKnownSize64        2.49ns ± 0%     0.72ns ± 0%   -70.95%
MemclrKnownSize112       2.97ns ± 2%     1.14ns ± 0%   -61.72%
MemclrKnownSize128       4.64ns ± 6%     2.45ns ± 1%   -47.17%
MemclrKnownSize192       5.45ns ± 5%     2.79ns ± 0%   -48.87%
MemclrKnownSize248       4.51ns ± 0%     2.83ns ± 0%   -37.12%
MemclrKnownSize256       6.34ns ± 1%     3.58ns ± 0%   -43.53%
MemclrKnownSize512       3.64ns ± 0%     3.64ns ± 0%    -0.03%
MemclrKnownSize1024      4.73ns ± 0%     4.73ns ± 0%    +0.01%
MemclrKnownSize4096      17.1ns ± 0%     17.1ns ± 0%    +0.07%
MemclrKnownSize512KiB    2.12µs ± 0%     2.12µs ± 0%      ~     (all equal)

Change-Id: If1abf5749f4802c64523a41fe0058bd144d0ea46
Reviewed-on: https://go-review.googlesource.com/c/go/+/464340
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: Archana Ravindar <aravind5@in.ibm.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Carlos Eduardo Seo <carlos.seo@linaro.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2023-02-23 18:57:27 +00:00
..
addrcalc.go
alloc.go
arithmetic.go test/codegen: merge identical ppc64 and ppc64le tests 2023-01-27 19:03:02 +00:00
bitfield.go cmd/internal/obj/arm64: remove the transition from $0 to ZR 2022-08-23 06:11:32 +00:00
bits.go cmd/compile: add late lower pass for last rules to run 2022-10-05 02:40:56 +00:00
bmi.go cmd/compile: AMD64v3 remove unnecessary TEST comparision in isPowerOfTwo 2023-01-20 04:58:59 +00:00
bool.go cmd/compile: add rules to emit SETBC/R instructions on power10 2023-02-06 12:49:53 +00:00
clobberdead.go cmd/compile: set LocalPkg.Path to -p flag 2022-05-16 18:19:47 +00:00
clobberdeadreg.go
compare_and_branch.go
comparisons.go test/codegen: combine trivial PPC64 tests into ppc64x 2023-01-27 18:24:12 +00:00
condmove.go test/codegen: accept ppc64x as alias for ppc64le and ppc64 arches 2023-01-24 22:55:18 +00:00
copy.go test/codegen: merge identical ppc64 and ppc64le tests 2023-01-27 19:03:02 +00:00
floats.go test/codegen: combine trivial PPC64 tests into ppc64x 2023-01-27 18:24:12 +00:00
fuse.go
ifaces.go cmd/compile/internal/noder: allow OCONVNOP for identical iface conversions 2022-09-02 18:26:02 +00:00
issue22703.go
issue25378.go
issue31618.go
issue33580.go
issue38554.go
issue42610.go test/codegen: combine trivial PPC64 tests into ppc64x 2023-01-27 18:24:12 +00:00
issue48054.go
issue52635.go cmd/compile: inline known-size memclrNoHeapPointers calls 2023-01-31 18:11:24 +00:00
issue54467.go cmd/compile: use stricter rule for possible partial overlap 2022-09-27 20:09:33 +00:00
issue56440.go cmd/compile: add rule for post-decomposed growslice optimization 2022-10-31 21:40:49 +00:00
issue58166.go cmd/compile: schedule values with no in-block uses later 2023-02-01 18:41:07 +00:00
logic.go test/codegen: combine trivial PPC64 tests into ppc64x 2023-01-27 18:24:12 +00:00
mapaccess.go cmd/compile: stop using VARKILL 2022-08-18 17:36:38 +00:00
maps.go internal/abi,runtime: refactor map constants into one place 2023-01-23 15:51:32 +00:00
math.go test/codegen: combine trivial PPC64 tests into ppc64x 2023-01-27 18:24:12 +00:00
mathbits.go cmd/compile: intrinsify math/bits/ReverseBytes{32|64} for 386 2023-02-08 03:43:23 +00:00
memcombine.go cmd/compile: combine more constant stores on amd64 2022-08-15 16:19:21 +00:00
memops.go cmd/compile: set LocalPkg.Path to -p flag 2022-05-16 18:19:47 +00:00
noextend.go test/codegen: combine trivial PPC64 tests into ppc64x 2023-01-27 18:24:12 +00:00
race.go
README
regabi_regalloc.go
retpoline.go cmd/compile: turn off jump tables when spectre retpolines are on 2022-12-06 05:12:12 +00:00
rotate.go test/codegen: combine trivial PPC64 tests into ppc64x 2023-01-27 18:24:12 +00:00
select.go cmd/compile: set LocalPkg.Path to -p flag 2022-05-16 18:19:47 +00:00
shift.go test/codegen: merge identical ppc64 and ppc64le tests 2023-01-27 19:03:02 +00:00
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 test/codegen: combine trivial PPC64 tests into ppc64x 2023-01-27 18:24:12 +00:00
strings.go cmd/compile/internal/ssa: optimize memory moving on arm64 2022-08-23 03:09:07 +00:00
structs.go
switch.go cmd/compile: add late lower pass for last rules to run 2022-10-05 02:40:56 +00:00
zerosize.go cmd/compile: set LocalPkg.Path to -p flag 2022-05-16 18:19:47 +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
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".