2016-03-12 14:07:40 -08:00
|
|
|
// Copyright 2016 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.
|
|
|
|
|
|
|
|
|
|
package amd64
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"math"
|
|
|
|
|
|
2020-11-19 20:49:23 -05:00
|
|
|
"cmd/compile/internal/base"
|
[dev.regabi] cmd/compile: group known symbols, packages, names [generated]
There are a handful of pre-computed magic symbols known by
package gc, and we need a place to store them.
If we keep them together, the need for type *ir.Name means that
package ir is the lowest package in the import hierarchy that they
can go in. And package ir needs gopkg for methodSymSuffix
(in a later CL), so they can't go any higher either, at least not all together.
So package ir it is.
Rather than dump them all into the top-level package ir
namespace, however, we introduce global structs, Syms, Pkgs, and Names,
and make the known symbols, packages, and names fields of those.
[git-generate]
cd src/cmd/compile/internal/gc
rf '
add go.go:$ \
// Names holds known names. \
var Names struct{} \
\
// Syms holds known symbols. \
var Syms struct {} \
\
// Pkgs holds known packages. \
var Pkgs struct {} \
mv staticuint64s Names.Staticuint64s
mv zerobase Names.Zerobase
mv assertE2I Syms.AssertE2I
mv assertE2I2 Syms.AssertE2I2
mv assertI2I Syms.AssertI2I
mv assertI2I2 Syms.AssertI2I2
mv deferproc Syms.Deferproc
mv deferprocStack Syms.DeferprocStack
mv Deferreturn Syms.Deferreturn
mv Duffcopy Syms.Duffcopy
mv Duffzero Syms.Duffzero
mv gcWriteBarrier Syms.GCWriteBarrier
mv goschedguarded Syms.Goschedguarded
mv growslice Syms.Growslice
mv msanread Syms.Msanread
mv msanwrite Syms.Msanwrite
mv msanmove Syms.Msanmove
mv newobject Syms.Newobject
mv newproc Syms.Newproc
mv panicdivide Syms.Panicdivide
mv panicshift Syms.Panicshift
mv panicdottypeE Syms.PanicdottypeE
mv panicdottypeI Syms.PanicdottypeI
mv panicnildottype Syms.Panicnildottype
mv panicoverflow Syms.Panicoverflow
mv raceread Syms.Raceread
mv racereadrange Syms.Racereadrange
mv racewrite Syms.Racewrite
mv racewriterange Syms.Racewriterange
mv SigPanic Syms.SigPanic
mv typedmemclr Syms.Typedmemclr
mv typedmemmove Syms.Typedmemmove
mv Udiv Syms.Udiv
mv writeBarrier Syms.WriteBarrier
mv zerobaseSym Syms.Zerobase
mv arm64HasATOMICS Syms.ARM64HasATOMICS
mv armHasVFPv4 Syms.ARMHasVFPv4
mv x86HasFMA Syms.X86HasFMA
mv x86HasPOPCNT Syms.X86HasPOPCNT
mv x86HasSSE41 Syms.X86HasSSE41
mv WasmDiv Syms.WasmDiv
mv WasmMove Syms.WasmMove
mv WasmZero Syms.WasmZero
mv WasmTruncS Syms.WasmTruncS
mv WasmTruncU Syms.WasmTruncU
mv gopkg Pkgs.Go
mv itabpkg Pkgs.Itab
mv itablinkpkg Pkgs.Itablink
mv mappkg Pkgs.Map
mv msanpkg Pkgs.Msan
mv racepkg Pkgs.Race
mv Runtimepkg Pkgs.Runtime
mv trackpkg Pkgs.Track
mv unsafepkg Pkgs.Unsafe
mv Names Syms Pkgs symtab.go
mv symtab.go cmd/compile/internal/ir
'
Change-Id: Ic143862148569a3bcde8e70b26d75421aa2d00f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/279235
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-12-23 00:10:25 -05:00
|
|
|
"cmd/compile/internal/ir"
|
2019-10-29 14:24:43 -04:00
|
|
|
"cmd/compile/internal/logopt"
|
2021-04-11 12:42:49 -04:00
|
|
|
"cmd/compile/internal/objw"
|
2016-03-12 14:07:40 -08:00
|
|
|
"cmd/compile/internal/ssa"
|
2020-12-23 00:57:10 -05:00
|
|
|
"cmd/compile/internal/ssagen"
|
cmd/compile: change ssa.Type into *types.Type
When package ssa was created, Type was in package gc.
To avoid circular dependencies, we used an interface (ssa.Type)
to represent type information in SSA.
In the Go 1.9 cycle, gri extricated the Type type from package gc.
As a result, we can now use it in package ssa.
Now, instead of package types depending on package ssa,
it is the other way.
This is a more sensible dependency tree,
and helps compiler performance a bit.
Though this is a big CL, most of the changes are
mechanical and uninteresting.
Interesting bits:
* Add new singleton globals to package types for the special
SSA types Memory, Void, Invalid, Flags, and Int128.
* Add two new Types, TSSA for the special types,
and TTUPLE, for SSA tuple types.
ssa.MakeTuple is now types.NewTuple.
* Move type comparison result constants CMPlt, CMPeq, and CMPgt
to package types.
* We had picked the name "types" in our rules for the handy
list of types provided by ssa.Config. That conflicted with
the types package name, so change it to "typ".
* Update the type comparison routine to handle tuples and special
types inline.
* Teach gc/fmt.go how to print special types.
* We can now eliminate ElemTypes in favor of just Elem,
and probably also some other duplicated Type methods
designed to return ssa.Type instead of *types.Type.
* The ssa tests were using their own dummy types,
and they were not particularly careful about types in general.
Of necessity, this CL switches them to use *types.Type;
it does not make them more type-accurate.
Unfortunately, using types.Type means initializing a bit
of the types universe.
This is prime for refactoring and improvement.
This shrinks ssa.Value; it now fits in a smaller size class
on 64 bit systems. This doesn't have a giant impact,
though, since most Values are preallocated in a chunk.
name old alloc/op new alloc/op delta
Template 37.9MB ± 0% 37.7MB ± 0% -0.57% (p=0.000 n=10+8)
Unicode 28.9MB ± 0% 28.7MB ± 0% -0.52% (p=0.000 n=10+10)
GoTypes 110MB ± 0% 109MB ± 0% -0.88% (p=0.000 n=10+10)
Flate 24.7MB ± 0% 24.6MB ± 0% -0.66% (p=0.000 n=10+10)
GoParser 31.1MB ± 0% 30.9MB ± 0% -0.61% (p=0.000 n=10+9)
Reflect 73.9MB ± 0% 73.4MB ± 0% -0.62% (p=0.000 n=10+8)
Tar 25.8MB ± 0% 25.6MB ± 0% -0.77% (p=0.000 n=9+10)
XML 41.2MB ± 0% 40.9MB ± 0% -0.80% (p=0.000 n=10+10)
[Geo mean] 40.5MB 40.3MB -0.68%
name old allocs/op new allocs/op delta
Template 385k ± 0% 386k ± 0% ~ (p=0.356 n=10+9)
Unicode 343k ± 1% 344k ± 0% ~ (p=0.481 n=10+10)
GoTypes 1.16M ± 0% 1.16M ± 0% -0.16% (p=0.004 n=10+10)
Flate 238k ± 1% 238k ± 1% ~ (p=0.853 n=10+10)
GoParser 320k ± 0% 320k ± 0% ~ (p=0.720 n=10+9)
Reflect 957k ± 0% 957k ± 0% ~ (p=0.460 n=10+8)
Tar 252k ± 0% 252k ± 0% ~ (p=0.133 n=9+10)
XML 400k ± 0% 400k ± 0% ~ (p=0.796 n=10+10)
[Geo mean] 428k 428k -0.01%
Removing all the interface calls helps non-trivially with CPU, though.
name old time/op new time/op delta
Template 178ms ± 4% 173ms ± 3% -2.90% (p=0.000 n=94+96)
Unicode 85.0ms ± 4% 83.9ms ± 4% -1.23% (p=0.000 n=96+96)
GoTypes 543ms ± 3% 528ms ± 3% -2.73% (p=0.000 n=98+96)
Flate 116ms ± 3% 113ms ± 4% -2.34% (p=0.000 n=96+99)
GoParser 144ms ± 3% 140ms ± 4% -2.80% (p=0.000 n=99+97)
Reflect 344ms ± 3% 334ms ± 4% -3.02% (p=0.000 n=100+99)
Tar 106ms ± 5% 103ms ± 4% -3.30% (p=0.000 n=98+94)
XML 198ms ± 5% 192ms ± 4% -2.88% (p=0.000 n=92+95)
[Geo mean] 178ms 173ms -2.65%
name old user-time/op new user-time/op delta
Template 229ms ± 5% 224ms ± 5% -2.36% (p=0.000 n=95+99)
Unicode 107ms ± 6% 106ms ± 5% -1.13% (p=0.001 n=93+95)
GoTypes 696ms ± 4% 679ms ± 4% -2.45% (p=0.000 n=97+99)
Flate 137ms ± 4% 134ms ± 5% -2.66% (p=0.000 n=99+96)
GoParser 176ms ± 5% 172ms ± 8% -2.27% (p=0.000 n=98+100)
Reflect 430ms ± 6% 411ms ± 5% -4.46% (p=0.000 n=100+92)
Tar 128ms ±13% 123ms ±13% -4.21% (p=0.000 n=100+100)
XML 239ms ± 6% 233ms ± 6% -2.50% (p=0.000 n=95+97)
[Geo mean] 220ms 213ms -2.76%
Change-Id: I15c7d6268347f8358e75066dfdbd77db24e8d0c1
Reviewed-on: https://go-review.googlesource.com/42145
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2017-04-28 14:12:28 -07:00
|
|
|
"cmd/compile/internal/types"
|
2016-03-12 14:07:40 -08:00
|
|
|
"cmd/internal/obj"
|
|
|
|
|
"cmd/internal/obj/x86"
|
2025-06-18 15:14:00 -07:00
|
|
|
"internal/abi"
|
2025-08-21 14:37:18 -04:00
|
|
|
"internal/buildcfg"
|
2016-03-12 14:07:40 -08:00
|
|
|
)
|
|
|
|
|
|
2022-11-14 20:13:10 +08:00
|
|
|
// ssaMarkMoves marks any MOVXconst ops that need to avoid clobbering flags.
|
2020-12-23 00:57:10 -05:00
|
|
|
func ssaMarkMoves(s *ssagen.State, b *ssa.Block) {
|
2016-03-12 14:07:40 -08:00
|
|
|
flive := b.FlagsLiveAtEnd
|
2019-08-12 20:19:58 +01:00
|
|
|
for _, c := range b.ControlValues() {
|
|
|
|
|
flive = c.Type.IsFlags() || flive
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
|
|
|
|
for i := len(b.Values) - 1; i >= 0; i-- {
|
|
|
|
|
v := b.Values[i]
|
2016-04-22 13:09:18 -07:00
|
|
|
if flive && (v.Op == ssa.OpAMD64MOVLconst || v.Op == ssa.OpAMD64MOVQconst) {
|
2016-03-12 14:07:40 -08:00
|
|
|
// The "mark" is any non-nil Aux value.
|
2023-01-10 08:36:00 +01:00
|
|
|
v.Aux = ssa.AuxMark
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
|
|
|
|
if v.Type.IsFlags() {
|
|
|
|
|
flive = false
|
|
|
|
|
}
|
|
|
|
|
for _, a := range v.Args {
|
|
|
|
|
if a.Type.IsFlags() {
|
|
|
|
|
flive = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-07 16:44:50 -04:00
|
|
|
func isFPReg(r int16) bool {
|
|
|
|
|
return x86.REG_X0 <= r && r <= x86.REG_Z31
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-14 20:21:37 +00:00
|
|
|
func isKReg(r int16) bool {
|
|
|
|
|
return x86.REG_K0 <= r && r <= x86.REG_K7
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func isLowFPReg(r int16) bool {
|
|
|
|
|
return x86.REG_X0 <= r && r <= x86.REG_X15
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// loadByRegWidth returns the load instruction of the given register of a given width.
|
|
|
|
|
func loadByRegWidth(r int16, width int64) obj.As {
|
|
|
|
|
// Avoid partial register write for GPR
|
|
|
|
|
if !isFPReg(r) && !isKReg(r) {
|
|
|
|
|
switch width {
|
2020-10-30 11:55:18 +01:00
|
|
|
case 1:
|
2016-03-12 14:07:40 -08:00
|
|
|
return x86.AMOVBLZX
|
2020-10-30 11:55:18 +01:00
|
|
|
case 2:
|
2016-03-12 14:07:40 -08:00
|
|
|
return x86.AMOVWLZX
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Otherwise, there's no difference between load and store opcodes.
|
2025-08-14 20:21:37 +00:00
|
|
|
return storeByRegWidth(r, width)
|
2025-08-13 12:44:01 -04:00
|
|
|
}
|
|
|
|
|
|
2025-08-14 20:21:37 +00:00
|
|
|
// storeByRegWidth returns the store instruction of the given register of a given width.
|
2025-08-14 16:56:28 +00:00
|
|
|
// It's also used for loading const to a reg.
|
2025-08-14 20:21:37 +00:00
|
|
|
func storeByRegWidth(r int16, width int64) obj.As {
|
2025-08-13 12:44:01 -04:00
|
|
|
if isFPReg(r) {
|
|
|
|
|
switch width {
|
|
|
|
|
case 4:
|
|
|
|
|
return x86.AMOVSS
|
|
|
|
|
case 8:
|
|
|
|
|
return x86.AMOVSD
|
2025-08-14 20:21:37 +00:00
|
|
|
case 16:
|
|
|
|
|
// int128s are in SSE registers
|
|
|
|
|
if isLowFPReg(r) {
|
|
|
|
|
return x86.AMOVUPS
|
|
|
|
|
} else {
|
|
|
|
|
return x86.AVMOVDQU
|
|
|
|
|
}
|
|
|
|
|
case 32:
|
|
|
|
|
return x86.AVMOVDQU
|
|
|
|
|
case 64:
|
|
|
|
|
return x86.AVMOVDQU64
|
2025-08-13 12:44:01 -04:00
|
|
|
}
|
2025-08-14 16:56:28 +00:00
|
|
|
}
|
2025-08-14 20:21:37 +00:00
|
|
|
if isKReg(r) {
|
|
|
|
|
return x86.AKMOVQ
|
|
|
|
|
}
|
|
|
|
|
// gp
|
2025-08-14 16:56:28 +00:00
|
|
|
switch width {
|
|
|
|
|
case 1:
|
|
|
|
|
return x86.AMOVB
|
|
|
|
|
case 2:
|
|
|
|
|
return x86.AMOVW
|
|
|
|
|
case 4:
|
|
|
|
|
return x86.AMOVL
|
|
|
|
|
case 8:
|
|
|
|
|
return x86.AMOVQ
|
2025-08-13 12:44:01 -04:00
|
|
|
}
|
2025-08-14 20:21:37 +00:00
|
|
|
panic(fmt.Sprintf("bad store reg=%v, width=%d", r, width))
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
|
|
|
|
|
2025-08-14 20:21:37 +00:00
|
|
|
// moveByRegsWidth returns the reg->reg move instruction of the given dest/src registers of a given width.
|
|
|
|
|
func moveByRegsWidth(dest, src int16, width int64) obj.As {
|
2025-08-14 16:56:28 +00:00
|
|
|
// fp -> fp
|
|
|
|
|
if isFPReg(dest) && isFPReg(src) {
|
2016-03-12 14:07:40 -08:00
|
|
|
// Moving the whole sse2 register is faster
|
|
|
|
|
// than moving just the correct low portion of it.
|
|
|
|
|
// There is no xmm->xmm move with 1 byte opcode,
|
|
|
|
|
// so use movups, which has 2 byte opcode.
|
2025-08-14 20:21:37 +00:00
|
|
|
if isLowFPReg(dest) && isLowFPReg(src) && width <= 16 {
|
|
|
|
|
return x86.AMOVUPS
|
|
|
|
|
}
|
|
|
|
|
if width <= 32 {
|
|
|
|
|
return x86.AVMOVDQU
|
|
|
|
|
}
|
|
|
|
|
return x86.AVMOVDQU64
|
|
|
|
|
}
|
|
|
|
|
// k -> gp, gp -> k, k -> k
|
|
|
|
|
if isKReg(dest) || isKReg(src) {
|
|
|
|
|
if isFPReg(dest) || isFPReg(src) {
|
|
|
|
|
panic(fmt.Sprintf("bad move, src=%v, dest=%v, width=%d", src, dest, width))
|
|
|
|
|
}
|
|
|
|
|
return x86.AKMOVQ
|
2025-08-07 16:44:50 -04:00
|
|
|
}
|
2025-08-14 16:56:28 +00:00
|
|
|
// gp -> fp, fp -> gp, gp -> gp
|
|
|
|
|
switch width {
|
2025-08-07 16:44:50 -04:00
|
|
|
case 1:
|
|
|
|
|
// Avoids partial register write
|
|
|
|
|
return x86.AMOVL
|
|
|
|
|
case 2:
|
|
|
|
|
return x86.AMOVL
|
|
|
|
|
case 4:
|
|
|
|
|
return x86.AMOVL
|
|
|
|
|
case 8:
|
|
|
|
|
return x86.AMOVQ
|
|
|
|
|
case 16:
|
2025-08-14 20:21:37 +00:00
|
|
|
if isLowFPReg(dest) && isLowFPReg(src) {
|
|
|
|
|
// int128s are in SSE registers
|
|
|
|
|
return x86.AMOVUPS
|
|
|
|
|
} else {
|
|
|
|
|
return x86.AVMOVDQU
|
|
|
|
|
}
|
|
|
|
|
case 32:
|
|
|
|
|
return x86.AVMOVDQU
|
|
|
|
|
case 64:
|
|
|
|
|
return x86.AVMOVDQU64
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
2025-08-14 20:21:37 +00:00
|
|
|
panic(fmt.Sprintf("bad move, src=%v, dest=%v, width=%d", src, dest, width))
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// opregreg emits instructions for
|
2022-02-03 14:12:08 -05:00
|
|
|
//
|
|
|
|
|
// dest := dest(To) op src(From)
|
|
|
|
|
//
|
2016-03-12 14:07:40 -08:00
|
|
|
// and also returns the created obj.Prog so it
|
|
|
|
|
// may be further adjusted (offset, scale, etc).
|
2020-12-23 00:57:10 -05:00
|
|
|
func opregreg(s *ssagen.State, op obj.As, dest, src int16) *obj.Prog {
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(op)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = dest
|
|
|
|
|
p.From.Reg = src
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-09 12:41:34 -08:00
|
|
|
// memIdx fills out a as an indexed memory reference for v.
|
|
|
|
|
// It assumes that the base register and the index register
|
|
|
|
|
// are v.Args[0].Reg() and v.Args[1].Reg(), respectively.
|
|
|
|
|
// The caller must still use gc.AddAux/gc.AddAux2 to handle v.Aux as necessary.
|
|
|
|
|
func memIdx(a *obj.Addr, v *ssa.Value) {
|
|
|
|
|
r, i := v.Args[0].Reg(), v.Args[1].Reg()
|
|
|
|
|
a.Type = obj.TYPE_MEM
|
|
|
|
|
a.Scale = v.Op.Scale()
|
|
|
|
|
if a.Scale == 1 && i == x86.REG_SP {
|
|
|
|
|
r, i = i, r
|
|
|
|
|
}
|
|
|
|
|
a.Reg = r
|
|
|
|
|
a.Index = i
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 18:20:16 -05:00
|
|
|
func getgFromTLS(s *ssagen.State, r int16) {
|
|
|
|
|
// See the comments in cmd/internal/obj/x86/obj6.go
|
|
|
|
|
// near CanUse1InsnTLS for a detailed explanation of these instructions.
|
|
|
|
|
if x86.CanUse1InsnTLS(base.Ctxt) {
|
|
|
|
|
// MOVQ (TLS), r
|
|
|
|
|
p := s.Prog(x86.AMOVQ)
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = x86.REG_TLS
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
|
|
|
|
} else {
|
|
|
|
|
// MOVQ TLS, r
|
|
|
|
|
// MOVQ (r)(TLS*1), r
|
|
|
|
|
p := s.Prog(x86.AMOVQ)
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = x86.REG_TLS
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
|
|
|
|
q := s.Prog(x86.AMOVQ)
|
|
|
|
|
q.From.Type = obj.TYPE_MEM
|
|
|
|
|
q.From.Reg = r
|
|
|
|
|
q.From.Index = x86.REG_TLS
|
|
|
|
|
q.From.Scale = 1
|
|
|
|
|
q.To.Type = obj.TYPE_REG
|
|
|
|
|
q.To.Reg = r
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 00:57:10 -05:00
|
|
|
func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
2016-03-12 14:07:40 -08:00
|
|
|
switch v.Op {
|
2025-02-02 23:42:43 +01:00
|
|
|
case ssa.OpAMD64VFMADD231SD, ssa.OpAMD64VFMADD231SS:
|
2018-09-25 03:10:33 -04:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From = obj.Addr{Type: obj.TYPE_REG, Reg: v.Args[2].Reg()}
|
|
|
|
|
p.To = obj.Addr{Type: obj.TYPE_REG, Reg: v.Reg()}
|
2023-04-12 11:23:13 +08:00
|
|
|
p.AddRestSourceReg(v.Args[1].Reg())
|
2016-04-22 13:09:18 -07:00
|
|
|
case ssa.OpAMD64ADDQ, ssa.OpAMD64ADDL:
|
2016-09-16 09:36:00 -07:00
|
|
|
r := v.Reg()
|
|
|
|
|
r1 := v.Args[0].Reg()
|
|
|
|
|
r2 := v.Args[1].Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
switch {
|
|
|
|
|
case r == r1:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = r2
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
|
|
|
|
case r == r2:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = r1
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
|
|
|
|
default:
|
|
|
|
|
var asm obj.As
|
2016-03-29 13:53:34 +03:00
|
|
|
if v.Op == ssa.OpAMD64ADDQ {
|
2016-03-12 14:07:40 -08:00
|
|
|
asm = x86.ALEAQ
|
2016-03-29 13:53:34 +03:00
|
|
|
} else {
|
2016-03-12 14:07:40 -08:00
|
|
|
asm = x86.ALEAL
|
|
|
|
|
}
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(asm)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = r1
|
|
|
|
|
p.From.Scale = 1
|
|
|
|
|
p.From.Index = r2
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
|
|
|
|
}
|
2016-04-10 08:26:43 -07:00
|
|
|
// 2-address opcode arithmetic
|
2016-04-22 13:09:18 -07:00
|
|
|
case ssa.OpAMD64SUBQ, ssa.OpAMD64SUBL,
|
|
|
|
|
ssa.OpAMD64MULQ, ssa.OpAMD64MULL,
|
|
|
|
|
ssa.OpAMD64ANDQ, ssa.OpAMD64ANDL,
|
|
|
|
|
ssa.OpAMD64ORQ, ssa.OpAMD64ORL,
|
|
|
|
|
ssa.OpAMD64XORQ, ssa.OpAMD64XORL,
|
|
|
|
|
ssa.OpAMD64SHLQ, ssa.OpAMD64SHLL,
|
2016-04-10 08:26:43 -07:00
|
|
|
ssa.OpAMD64SHRQ, ssa.OpAMD64SHRL, ssa.OpAMD64SHRW, ssa.OpAMD64SHRB,
|
|
|
|
|
ssa.OpAMD64SARQ, ssa.OpAMD64SARL, ssa.OpAMD64SARW, ssa.OpAMD64SARB,
|
2017-03-29 10:04:17 -07:00
|
|
|
ssa.OpAMD64ROLQ, ssa.OpAMD64ROLL, ssa.OpAMD64ROLW, ssa.OpAMD64ROLB,
|
|
|
|
|
ssa.OpAMD64RORQ, ssa.OpAMD64RORL, ssa.OpAMD64RORW, ssa.OpAMD64RORB,
|
2016-04-10 08:26:43 -07:00
|
|
|
ssa.OpAMD64ADDSS, ssa.OpAMD64ADDSD, ssa.OpAMD64SUBSS, ssa.OpAMD64SUBSD,
|
|
|
|
|
ssa.OpAMD64MULSS, ssa.OpAMD64MULSD, ssa.OpAMD64DIVSS, ssa.OpAMD64DIVSD,
|
2023-07-31 14:08:42 -07:00
|
|
|
ssa.OpAMD64MINSS, ssa.OpAMD64MINSD,
|
|
|
|
|
ssa.OpAMD64POR, ssa.OpAMD64PXOR,
|
cmd/compile: add patterns for bit set/clear/complement on amd64
This patch completes implementation of BT(Q|L), and adds support
for BT(S|R|C)(Q|L).
Example of code changes from time.(*Time).addSec:
if t.wall&hasMonotonic != 0 {
0x1073465 488b08 MOVQ 0(AX), CX
0x1073468 4889ca MOVQ CX, DX
0x107346b 48c1e93f SHRQ $0x3f, CX
0x107346f 48c1e13f SHLQ $0x3f, CX
0x1073473 48f7c1ffffffff TESTQ $-0x1, CX
0x107347a 746b JE 0x10734e7
if t.wall&hasMonotonic != 0 {
0x1073435 488b08 MOVQ 0(AX), CX
0x1073438 480fbae13f BTQ $0x3f, CX
0x107343d 7363 JAE 0x10734a2
Another example:
t.wall = t.wall&nsecMask | uint64(dsec)<<nsecShift | hasMonotonic
0x10734c8 4881e1ffffff3f ANDQ $0x3fffffff, CX
0x10734cf 48c1e61e SHLQ $0x1e, SI
0x10734d3 4809ce ORQ CX, SI
0x10734d6 48b90000000000000080 MOVQ $0x8000000000000000, CX
0x10734e0 4809f1 ORQ SI, CX
0x10734e3 488908 MOVQ CX, 0(AX)
t.wall = t.wall&nsecMask | uint64(dsec)<<nsecShift | hasMonotonic
0x107348b 4881e2ffffff3f ANDQ $0x3fffffff, DX
0x1073492 48c1e61e SHLQ $0x1e, SI
0x1073496 4809f2 ORQ SI, DX
0x1073499 480fbaea3f BTSQ $0x3f, DX
0x107349e 488910 MOVQ DX, 0(AX)
Go1 benchmarks seem unaffected, and I would be surprised
otherwise:
name old time/op new time/op delta
BinaryTree17-4 2.64s ± 4% 2.56s ± 9% -2.92% (p=0.008 n=9+9)
Fannkuch11-4 2.90s ± 1% 2.95s ± 3% +1.76% (p=0.010 n=10+9)
FmtFprintfEmpty-4 35.3ns ± 1% 34.5ns ± 2% -2.34% (p=0.004 n=9+8)
FmtFprintfString-4 57.0ns ± 1% 58.4ns ± 5% +2.52% (p=0.029 n=9+10)
FmtFprintfInt-4 59.8ns ± 3% 59.8ns ± 6% ~ (p=0.565 n=10+10)
FmtFprintfIntInt-4 93.9ns ± 3% 91.2ns ± 5% -2.94% (p=0.014 n=10+9)
FmtFprintfPrefixedInt-4 107ns ± 6% 104ns ± 6% ~ (p=0.099 n=10+10)
FmtFprintfFloat-4 187ns ± 3% 188ns ± 3% ~ (p=0.505 n=10+9)
FmtManyArgs-4 410ns ± 1% 415ns ± 6% ~ (p=0.649 n=8+10)
GobDecode-4 5.30ms ± 3% 5.27ms ± 3% ~ (p=0.436 n=10+10)
GobEncode-4 4.62ms ± 5% 4.47ms ± 2% -3.24% (p=0.001 n=9+10)
Gzip-4 197ms ± 4% 193ms ± 3% ~ (p=0.123 n=10+10)
Gunzip-4 30.4ms ± 3% 30.1ms ± 3% ~ (p=0.481 n=10+10)
HTTPClientServer-4 76.3µs ± 1% 76.0µs ± 1% ~ (p=0.236 n=8+9)
JSONEncode-4 10.5ms ± 9% 10.3ms ± 3% ~ (p=0.280 n=10+10)
JSONDecode-4 42.3ms ±10% 41.3ms ± 2% ~ (p=0.053 n=9+10)
Mandelbrot200-4 3.80ms ± 2% 3.72ms ± 2% -2.15% (p=0.001 n=9+10)
GoParse-4 2.88ms ±10% 2.81ms ± 2% ~ (p=0.247 n=10+10)
RegexpMatchEasy0_32-4 69.5ns ± 4% 68.6ns ± 2% ~ (p=0.171 n=10+10)
RegexpMatchEasy0_1K-4 165ns ± 3% 162ns ± 3% ~ (p=0.137 n=10+10)
RegexpMatchEasy1_32-4 65.7ns ± 6% 64.4ns ± 2% -2.02% (p=0.037 n=10+10)
RegexpMatchEasy1_1K-4 278ns ± 2% 279ns ± 3% ~ (p=0.991 n=8+9)
RegexpMatchMedium_32-4 99.3ns ± 3% 98.5ns ± 4% ~ (p=0.457 n=10+9)
RegexpMatchMedium_1K-4 30.1µs ± 1% 30.4µs ± 2% ~ (p=0.173 n=8+10)
RegexpMatchHard_32-4 1.40µs ± 2% 1.41µs ± 4% ~ (p=0.565 n=10+10)
RegexpMatchHard_1K-4 42.5µs ± 1% 41.5µs ± 3% -2.13% (p=0.002 n=8+9)
Revcomp-4 332ms ± 4% 328ms ± 5% ~ (p=0.720 n=9+10)
Template-4 48.3ms ± 2% 49.6ms ± 3% +2.56% (p=0.002 n=8+10)
TimeParse-4 252ns ± 2% 249ns ± 3% ~ (p=0.116 n=9+10)
TimeFormat-4 262ns ± 4% 252ns ± 3% -4.01% (p=0.000 n=9+10)
name old speed new speed delta
GobDecode-4 145MB/s ± 3% 146MB/s ± 3% ~ (p=0.436 n=10+10)
GobEncode-4 166MB/s ± 5% 172MB/s ± 2% +3.28% (p=0.001 n=9+10)
Gzip-4 98.6MB/s ± 4% 100.4MB/s ± 3% ~ (p=0.123 n=10+10)
Gunzip-4 639MB/s ± 3% 645MB/s ± 3% ~ (p=0.481 n=10+10)
JSONEncode-4 185MB/s ± 8% 189MB/s ± 3% ~ (p=0.280 n=10+10)
JSONDecode-4 46.0MB/s ± 9% 47.0MB/s ± 2% +2.21% (p=0.046 n=9+10)
GoParse-4 20.1MB/s ± 9% 20.6MB/s ± 2% ~ (p=0.239 n=10+10)
RegexpMatchEasy0_32-4 460MB/s ± 4% 467MB/s ± 2% ~ (p=0.165 n=10+10)
RegexpMatchEasy0_1K-4 6.19GB/s ± 3% 6.28GB/s ± 3% ~ (p=0.165 n=10+10)
RegexpMatchEasy1_32-4 487MB/s ± 5% 497MB/s ± 2% +2.00% (p=0.043 n=10+10)
RegexpMatchEasy1_1K-4 3.67GB/s ± 2% 3.67GB/s ± 3% ~ (p=0.963 n=8+9)
RegexpMatchMedium_32-4 10.1MB/s ± 3% 10.1MB/s ± 4% ~ (p=0.435 n=10+9)
RegexpMatchMedium_1K-4 34.0MB/s ± 1% 33.7MB/s ± 2% ~ (p=0.173 n=8+10)
RegexpMatchHard_32-4 22.9MB/s ± 2% 22.7MB/s ± 4% ~ (p=0.565 n=10+10)
RegexpMatchHard_1K-4 24.0MB/s ± 3% 24.7MB/s ± 3% +2.64% (p=0.001 n=9+9)
Revcomp-4 766MB/s ± 4% 775MB/s ± 5% ~ (p=0.720 n=9+10)
Template-4 40.2MB/s ± 2% 39.2MB/s ± 3% -2.47% (p=0.002 n=8+10)
The rules match ~1800 times during all.bash.
Fixes #18943
Change-Id: I64be1ada34e89c486dfd935bf429b35652117ed4
Reviewed-on: https://go-review.googlesource.com/94766
Run-TryBot: Giovanni Bajo <rasky@develer.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2018-02-17 13:54:03 +01:00
|
|
|
ssa.OpAMD64BTSL, ssa.OpAMD64BTSQ,
|
|
|
|
|
ssa.OpAMD64BTCL, ssa.OpAMD64BTCQ,
|
2024-11-04 12:41:33 -05:00
|
|
|
ssa.OpAMD64BTRL, ssa.OpAMD64BTRQ,
|
|
|
|
|
ssa.OpAMD64PCMPEQB, ssa.OpAMD64PSIGNB,
|
|
|
|
|
ssa.OpAMD64PUNPCKLBW:
|
2021-01-07 19:08:37 -08:00
|
|
|
opregreg(s, v.Op.Asm(), v.Reg(), v.Args[1].Reg())
|
2016-03-12 14:07:40 -08:00
|
|
|
|
2024-11-04 12:41:33 -05:00
|
|
|
case ssa.OpAMD64PSHUFLW:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
imm := v.AuxInt
|
|
|
|
|
if imm < 0 || imm > 255 {
|
|
|
|
|
v.Fatalf("Invalid source selection immediate")
|
|
|
|
|
}
|
|
|
|
|
p.From.Offset = imm
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.AddRestSourceReg(v.Args[0].Reg())
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
|
|
|
|
|
|
|
|
|
case ssa.OpAMD64PSHUFBbroadcast:
|
|
|
|
|
// PSHUFB with a control mask of zero copies byte 0 to all
|
|
|
|
|
// bytes in the register.
|
|
|
|
|
//
|
|
|
|
|
// X15 is always zero with ABIInternal.
|
|
|
|
|
if s.ABI != obj.ABIInternal {
|
|
|
|
|
// zero X15 manually
|
|
|
|
|
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
|
|
|
|
p.From.Reg = x86.REG_X15
|
|
|
|
|
|
2021-01-07 19:25:05 -08:00
|
|
|
case ssa.OpAMD64SHRDQ, ssa.OpAMD64SHLDQ:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
lo, hi, bits := v.Args[0].Reg(), v.Args[1].Reg(), v.Args[2].Reg()
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = bits
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = lo
|
2023-04-12 11:23:13 +08:00
|
|
|
p.AddRestSourceReg(hi)
|
2021-01-07 19:25:05 -08:00
|
|
|
|
2021-07-02 21:02:30 -07:00
|
|
|
case ssa.OpAMD64BLSIQ, ssa.OpAMD64BLSIL,
|
|
|
|
|
ssa.OpAMD64BLSMSKQ, ssa.OpAMD64BLSMSKL,
|
2021-12-06 18:46:25 +03:00
|
|
|
ssa.OpAMD64BLSRQ, ssa.OpAMD64BLSRL:
|
2021-07-02 21:02:30 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
2022-11-06 06:37:13 +01:00
|
|
|
switch v.Op {
|
|
|
|
|
case ssa.OpAMD64BLSRQ, ssa.OpAMD64BLSRL:
|
|
|
|
|
p.To.Reg = v.Reg0()
|
|
|
|
|
default:
|
|
|
|
|
p.To.Reg = v.Reg()
|
|
|
|
|
}
|
2021-07-02 21:02:30 -07:00
|
|
|
|
|
|
|
|
case ssa.OpAMD64ANDNQ, ssa.OpAMD64ANDNL:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
2023-04-12 11:23:13 +08:00
|
|
|
p.AddRestSourceReg(v.Args[1].Reg())
|
2021-07-02 21:02:30 -07:00
|
|
|
|
2022-04-09 14:40:40 +08:00
|
|
|
case ssa.OpAMD64SARXL, ssa.OpAMD64SARXQ,
|
|
|
|
|
ssa.OpAMD64SHLXL, ssa.OpAMD64SHLXQ,
|
|
|
|
|
ssa.OpAMD64SHRXL, ssa.OpAMD64SHRXQ:
|
2022-04-08 16:44:13 +08:00
|
|
|
p := opregreg(s, v.Op.Asm(), v.Reg(), v.Args[1].Reg())
|
2023-04-12 11:23:13 +08:00
|
|
|
p.AddRestSourceReg(v.Args[0].Reg())
|
2022-04-08 16:44:13 +08:00
|
|
|
|
2022-03-02 16:32:16 +08:00
|
|
|
case ssa.OpAMD64SHLXLload, ssa.OpAMD64SHLXQload,
|
2022-04-08 17:33:50 +08:00
|
|
|
ssa.OpAMD64SHRXLload, ssa.OpAMD64SHRXQload,
|
|
|
|
|
ssa.OpAMD64SARXLload, ssa.OpAMD64SARXQload:
|
2022-03-02 16:32:16 +08:00
|
|
|
p := opregreg(s, v.Op.Asm(), v.Reg(), v.Args[1].Reg())
|
|
|
|
|
m := obj.Addr{Type: obj.TYPE_MEM, Reg: v.Args[0].Reg()}
|
|
|
|
|
ssagen.AddAux(&m, v)
|
2023-04-12 11:23:13 +08:00
|
|
|
p.AddRestSource(m)
|
2022-03-02 16:32:16 +08:00
|
|
|
|
|
|
|
|
case ssa.OpAMD64SHLXLloadidx1, ssa.OpAMD64SHLXLloadidx4, ssa.OpAMD64SHLXLloadidx8,
|
|
|
|
|
ssa.OpAMD64SHRXLloadidx1, ssa.OpAMD64SHRXLloadidx4, ssa.OpAMD64SHRXLloadidx8,
|
2022-04-08 17:33:50 +08:00
|
|
|
ssa.OpAMD64SARXLloadidx1, ssa.OpAMD64SARXLloadidx4, ssa.OpAMD64SARXLloadidx8,
|
2022-03-02 16:32:16 +08:00
|
|
|
ssa.OpAMD64SHLXQloadidx1, ssa.OpAMD64SHLXQloadidx8,
|
2022-04-08 17:33:50 +08:00
|
|
|
ssa.OpAMD64SHRXQloadidx1, ssa.OpAMD64SHRXQloadidx8,
|
|
|
|
|
ssa.OpAMD64SARXQloadidx1, ssa.OpAMD64SARXQloadidx8:
|
2022-03-02 16:32:16 +08:00
|
|
|
p := opregreg(s, v.Op.Asm(), v.Reg(), v.Args[2].Reg())
|
|
|
|
|
m := obj.Addr{Type: obj.TYPE_MEM}
|
|
|
|
|
memIdx(&m, v)
|
|
|
|
|
ssagen.AddAux(&m, v)
|
2023-04-12 11:23:13 +08:00
|
|
|
p.AddRestSource(m)
|
2022-03-02 16:32:16 +08:00
|
|
|
|
2016-07-18 10:18:12 -07:00
|
|
|
case ssa.OpAMD64DIVQU, ssa.OpAMD64DIVLU, ssa.OpAMD64DIVWU:
|
|
|
|
|
// Arg[0] (the dividend) is in AX.
|
|
|
|
|
// Arg[1] (the divisor) can be in any other register.
|
|
|
|
|
// Result[0] (the quotient) is in AX.
|
|
|
|
|
// Result[1] (the remainder) is in DX.
|
2016-09-16 09:36:00 -07:00
|
|
|
r := v.Args[1].Reg()
|
2016-07-18 10:18:12 -07:00
|
|
|
|
|
|
|
|
// Zero extend dividend.
|
2021-12-06 11:46:57 +03:00
|
|
|
opregreg(s, x86.AXORL, x86.REG_DX, x86.REG_DX)
|
2016-07-18 10:18:12 -07:00
|
|
|
|
|
|
|
|
// Issue divide.
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-07-18 10:18:12 -07:00
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = r
|
2016-03-12 14:07:40 -08:00
|
|
|
|
2016-07-18 10:18:12 -07:00
|
|
|
case ssa.OpAMD64DIVQ, ssa.OpAMD64DIVL, ssa.OpAMD64DIVW:
|
|
|
|
|
// Arg[0] (the dividend) is in AX.
|
|
|
|
|
// Arg[1] (the divisor) can be in any other register.
|
|
|
|
|
// Result[0] (the quotient) is in AX.
|
|
|
|
|
// Result[1] (the remainder) is in DX.
|
2016-09-16 09:36:00 -07:00
|
|
|
r := v.Args[1].Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
|
2023-04-06 06:11:10 +10:00
|
|
|
var opCMP, opNEG, opSXD obj.As
|
|
|
|
|
switch v.Op {
|
|
|
|
|
case ssa.OpAMD64DIVQ:
|
|
|
|
|
opCMP, opNEG, opSXD = x86.ACMPQ, x86.ANEGQ, x86.ACQO
|
|
|
|
|
case ssa.OpAMD64DIVL:
|
|
|
|
|
opCMP, opNEG, opSXD = x86.ACMPL, x86.ANEGL, x86.ACDQ
|
|
|
|
|
case ssa.OpAMD64DIVW:
|
|
|
|
|
opCMP, opNEG, opSXD = x86.ACMPW, x86.ANEGW, x86.ACWD
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-18 10:18:12 -07:00
|
|
|
// CPU faults upon signed overflow, which occurs when the most
|
|
|
|
|
// negative int is divided by -1. Handle divide by -1 as a special case.
|
cmd/compile/internal/amd64: improve fix up code for signed division
In order to avoid a CPU exception resulting from signed overflow, the signed
division code tests if the divisor is -1 and if it is, runs fix up code to
manually compute the quotient and remainder (thus avoiding IDIV and potential
signed overflow).
However, the way that this is currently structured means that the normal code
path for the case where the divisor is not -1 results in five instructions
and two branches (CMP, JEQ, followed by sign extension, IDIV and another JMP
to skip over the fix up code).
Rework the fix up code such that the final JMP is incurred by the less likely
divisor is -1 code path, rather than more likely code path (which is already
more expensive due to IDIV). This result in a four instruction sequence
(CMP, JNE, sign extension, IDIV), with only a single branch.
Updates #59089
Change-Id: Ie8d065750a178518d7397e194920b201afeb0530
Reviewed-on: https://go-review.googlesource.com/c/go/+/482658
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-04-06 06:11:14 +10:00
|
|
|
var j1, j2 *obj.Prog
|
2020-01-23 22:18:30 -08:00
|
|
|
if ssa.DivisionNeedsFixUp(v) {
|
2023-04-06 06:11:10 +10:00
|
|
|
c := s.Prog(opCMP)
|
2018-08-06 19:50:38 +10:00
|
|
|
c.From.Type = obj.TYPE_REG
|
|
|
|
|
c.From.Reg = r
|
|
|
|
|
c.To.Type = obj.TYPE_CONST
|
|
|
|
|
c.To.Offset = -1
|
2016-03-12 14:07:40 -08:00
|
|
|
|
cmd/compile/internal/amd64: improve fix up code for signed division
In order to avoid a CPU exception resulting from signed overflow, the signed
division code tests if the divisor is -1 and if it is, runs fix up code to
manually compute the quotient and remainder (thus avoiding IDIV and potential
signed overflow).
However, the way that this is currently structured means that the normal code
path for the case where the divisor is not -1 results in five instructions
and two branches (CMP, JEQ, followed by sign extension, IDIV and another JMP
to skip over the fix up code).
Rework the fix up code such that the final JMP is incurred by the less likely
divisor is -1 code path, rather than more likely code path (which is already
more expensive due to IDIV). This result in a four instruction sequence
(CMP, JNE, sign extension, IDIV), with only a single branch.
Updates #59089
Change-Id: Ie8d065750a178518d7397e194920b201afeb0530
Reviewed-on: https://go-review.googlesource.com/c/go/+/482658
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-04-06 06:11:14 +10:00
|
|
|
// Divisor is not -1, proceed with normal division.
|
|
|
|
|
j1 = s.Prog(x86.AJNE)
|
|
|
|
|
j1.To.Type = obj.TYPE_BRANCH
|
2016-07-18 10:18:12 -07:00
|
|
|
|
cmd/compile/internal/amd64: improve fix up code for signed division
In order to avoid a CPU exception resulting from signed overflow, the signed
division code tests if the divisor is -1 and if it is, runs fix up code to
manually compute the quotient and remainder (thus avoiding IDIV and potential
signed overflow).
However, the way that this is currently structured means that the normal code
path for the case where the divisor is not -1 results in five instructions
and two branches (CMP, JEQ, followed by sign extension, IDIV and another JMP
to skip over the fix up code).
Rework the fix up code such that the final JMP is incurred by the less likely
divisor is -1 code path, rather than more likely code path (which is already
more expensive due to IDIV). This result in a four instruction sequence
(CMP, JNE, sign extension, IDIV), with only a single branch.
Updates #59089
Change-Id: Ie8d065750a178518d7397e194920b201afeb0530
Reviewed-on: https://go-review.googlesource.com/c/go/+/482658
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-04-06 06:11:14 +10:00
|
|
|
// Divisor is -1, manually compute quotient and remainder via fixup code.
|
2018-08-06 19:50:38 +10:00
|
|
|
// n / -1 = -n
|
2023-04-06 06:11:10 +10:00
|
|
|
n1 := s.Prog(opNEG)
|
2018-08-06 19:50:38 +10:00
|
|
|
n1.To.Type = obj.TYPE_REG
|
|
|
|
|
n1.To.Reg = x86.REG_AX
|
2016-07-18 10:18:12 -07:00
|
|
|
|
2018-08-06 19:50:38 +10:00
|
|
|
// n % -1 == 0
|
2021-12-06 11:46:57 +03:00
|
|
|
opregreg(s, x86.AXORL, x86.REG_DX, x86.REG_DX)
|
2016-07-18 10:18:12 -07:00
|
|
|
|
2018-08-06 19:50:38 +10:00
|
|
|
// TODO(khr): issue only the -1 fixup code we need.
|
|
|
|
|
// For instance, if only the quotient is used, no point in zeroing the remainder.
|
2016-07-18 10:18:12 -07:00
|
|
|
|
cmd/compile/internal/amd64: improve fix up code for signed division
In order to avoid a CPU exception resulting from signed overflow, the signed
division code tests if the divisor is -1 and if it is, runs fix up code to
manually compute the quotient and remainder (thus avoiding IDIV and potential
signed overflow).
However, the way that this is currently structured means that the normal code
path for the case where the divisor is not -1 results in five instructions
and two branches (CMP, JEQ, followed by sign extension, IDIV and another JMP
to skip over the fix up code).
Rework the fix up code such that the final JMP is incurred by the less likely
divisor is -1 code path, rather than more likely code path (which is already
more expensive due to IDIV). This result in a four instruction sequence
(CMP, JNE, sign extension, IDIV), with only a single branch.
Updates #59089
Change-Id: Ie8d065750a178518d7397e194920b201afeb0530
Reviewed-on: https://go-review.googlesource.com/c/go/+/482658
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-04-06 06:11:14 +10:00
|
|
|
// Skip over normal division.
|
|
|
|
|
j2 = s.Prog(obj.AJMP)
|
|
|
|
|
j2.To.Type = obj.TYPE_BRANCH
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sign extend dividend and perform division.
|
|
|
|
|
p := s.Prog(opSXD)
|
|
|
|
|
if j1 != nil {
|
|
|
|
|
j1.To.SetTarget(p)
|
|
|
|
|
}
|
|
|
|
|
p = s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = r
|
|
|
|
|
|
|
|
|
|
if j2 != nil {
|
2020-08-28 17:10:32 +00:00
|
|
|
j2.To.SetTarget(s.Pc())
|
2018-08-06 19:50:38 +10:00
|
|
|
}
|
2016-03-12 14:07:40 -08:00
|
|
|
|
2017-03-03 11:35:44 -08:00
|
|
|
case ssa.OpAMD64HMULQ, ssa.OpAMD64HMULL, ssa.OpAMD64HMULQU, ssa.OpAMD64HMULLU:
|
2016-03-12 14:07:40 -08:00
|
|
|
// the frontend rewrites constant division by 8/16/32 bit integers into
|
|
|
|
|
// HMUL by a constant
|
|
|
|
|
// SSA rewrites generate the 64 bit versions
|
|
|
|
|
|
|
|
|
|
// Arg[0] is already in AX as it's the only register we allow
|
|
|
|
|
// and DX is the only output we care about (the high bits)
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[1].Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
|
|
|
|
|
// IMULB puts the high portion in AH instead of DL,
|
|
|
|
|
// so move it to DL for consistency
|
2017-04-28 00:19:49 +00:00
|
|
|
if v.Type.Size() == 1 {
|
2017-03-20 08:01:28 -07:00
|
|
|
m := s.Prog(x86.AMOVB)
|
2016-03-12 14:07:40 -08:00
|
|
|
m.From.Type = obj.TYPE_REG
|
|
|
|
|
m.From.Reg = x86.REG_AH
|
|
|
|
|
m.To.Type = obj.TYPE_REG
|
|
|
|
|
m.To.Reg = x86.REG_DX
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 11:55:34 +01:00
|
|
|
case ssa.OpAMD64MULQU, ssa.OpAMD64MULLU:
|
|
|
|
|
// Arg[0] is already in AX as it's the only register we allow
|
|
|
|
|
// results lo in AX
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[1].Reg()
|
|
|
|
|
|
2016-10-06 15:43:47 -04:00
|
|
|
case ssa.OpAMD64MULQU2:
|
|
|
|
|
// Arg[0] is already in AX as it's the only register we allow
|
|
|
|
|
// results hi in DX, lo in AX
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-10-06 15:43:47 -04:00
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[1].Reg()
|
|
|
|
|
|
|
|
|
|
case ssa.OpAMD64DIVQU2:
|
|
|
|
|
// Arg[0], Arg[1] are already in Dx, AX, as they're the only registers we allow
|
|
|
|
|
// results q in AX, r in DX
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-10-06 15:43:47 -04:00
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[2].Reg()
|
|
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64AVGQU:
|
|
|
|
|
// compute (x+y)/2 unsigned.
|
|
|
|
|
// Do a 64-bit add, the overflow goes into the carry.
|
|
|
|
|
// Shift right once and pull the carry back into the 63rd bit.
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(x86.AADDQ)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
p.To.Reg = v.Reg()
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[1].Reg()
|
2017-03-20 08:01:28 -07:00
|
|
|
p = s.Prog(x86.ARCRQ)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = 1
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
p.To.Reg = v.Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
|
2018-10-23 14:05:38 -07:00
|
|
|
case ssa.OpAMD64ADDQcarry, ssa.OpAMD64ADCQ:
|
|
|
|
|
r := v.Reg0()
|
|
|
|
|
r0 := v.Args[0].Reg()
|
|
|
|
|
r1 := v.Args[1].Reg()
|
|
|
|
|
switch r {
|
|
|
|
|
case r0:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = r1
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
|
|
|
|
case r1:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = r0
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
|
|
|
|
default:
|
|
|
|
|
v.Fatalf("output not in same register as an input %s", v.LongString())
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-23 14:38:22 -07:00
|
|
|
case ssa.OpAMD64SUBQborrow, ssa.OpAMD64SBBQ:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[1].Reg()
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg0()
|
|
|
|
|
|
|
|
|
|
case ssa.OpAMD64ADDQconstcarry, ssa.OpAMD64ADCQconst, ssa.OpAMD64SUBQconstborrow, ssa.OpAMD64SBBQconst:
|
2018-10-23 14:05:38 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = v.AuxInt
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg0()
|
|
|
|
|
|
2016-04-22 13:09:18 -07:00
|
|
|
case ssa.OpAMD64ADDQconst, ssa.OpAMD64ADDLconst:
|
2016-09-16 09:36:00 -07:00
|
|
|
r := v.Reg()
|
|
|
|
|
a := v.Args[0].Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
if r == a {
|
2019-03-19 12:26:22 -07:00
|
|
|
switch v.AuxInt {
|
|
|
|
|
case 1:
|
2016-03-12 14:07:40 -08:00
|
|
|
var asm obj.As
|
|
|
|
|
// Software optimization manual recommends add $1,reg.
|
|
|
|
|
// But inc/dec is 1 byte smaller. ICC always uses inc
|
|
|
|
|
// Clang/GCC choose depending on flags, but prefer add.
|
|
|
|
|
// Experiments show that inc/dec is both a little faster
|
|
|
|
|
// and make a binary a little smaller.
|
2016-03-29 13:53:34 +03:00
|
|
|
if v.Op == ssa.OpAMD64ADDQconst {
|
2016-03-12 14:07:40 -08:00
|
|
|
asm = x86.AINCQ
|
2016-03-29 13:53:34 +03:00
|
|
|
} else {
|
2016-03-12 14:07:40 -08:00
|
|
|
asm = x86.AINCL
|
|
|
|
|
}
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(asm)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
|
|
|
|
return
|
2019-03-19 12:26:22 -07:00
|
|
|
case -1:
|
2016-03-12 14:07:40 -08:00
|
|
|
var asm obj.As
|
2016-03-29 13:53:34 +03:00
|
|
|
if v.Op == ssa.OpAMD64ADDQconst {
|
2016-03-12 14:07:40 -08:00
|
|
|
asm = x86.ADECQ
|
2016-03-29 13:53:34 +03:00
|
|
|
} else {
|
2016-03-12 14:07:40 -08:00
|
|
|
asm = x86.ADECL
|
|
|
|
|
}
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(asm)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
|
|
|
|
return
|
2019-03-19 12:26:22 -07:00
|
|
|
case 0x80:
|
|
|
|
|
// 'SUBQ $-0x80, r' is shorter to encode than
|
|
|
|
|
// and functionally equivalent to 'ADDQ $0x80, r'.
|
|
|
|
|
asm := x86.ASUBL
|
|
|
|
|
if v.Op == ssa.OpAMD64ADDQconst {
|
|
|
|
|
asm = x86.ASUBQ
|
|
|
|
|
}
|
|
|
|
|
p := s.Prog(asm)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = -0x80
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
|
|
|
|
return
|
|
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-04-10 08:26:43 -07:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = v.AuxInt
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
|
|
|
|
return
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
|
|
|
|
var asm obj.As
|
2016-03-29 13:53:34 +03:00
|
|
|
if v.Op == ssa.OpAMD64ADDQconst {
|
2016-03-12 14:07:40 -08:00
|
|
|
asm = x86.ALEAQ
|
2016-03-29 13:53:34 +03:00
|
|
|
} else {
|
2016-03-12 14:07:40 -08:00
|
|
|
asm = x86.ALEAL
|
|
|
|
|
}
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(asm)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = a
|
2016-03-29 16:39:53 -07:00
|
|
|
p.From.Offset = v.AuxInt
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
2016-03-11 00:10:52 -05:00
|
|
|
|
2018-03-05 20:59:40 +01:00
|
|
|
case ssa.OpAMD64CMOVQEQ, ssa.OpAMD64CMOVLEQ, ssa.OpAMD64CMOVWEQ,
|
|
|
|
|
ssa.OpAMD64CMOVQLT, ssa.OpAMD64CMOVLLT, ssa.OpAMD64CMOVWLT,
|
|
|
|
|
ssa.OpAMD64CMOVQNE, ssa.OpAMD64CMOVLNE, ssa.OpAMD64CMOVWNE,
|
|
|
|
|
ssa.OpAMD64CMOVQGT, ssa.OpAMD64CMOVLGT, ssa.OpAMD64CMOVWGT,
|
|
|
|
|
ssa.OpAMD64CMOVQLE, ssa.OpAMD64CMOVLLE, ssa.OpAMD64CMOVWLE,
|
|
|
|
|
ssa.OpAMD64CMOVQGE, ssa.OpAMD64CMOVLGE, ssa.OpAMD64CMOVWGE,
|
|
|
|
|
ssa.OpAMD64CMOVQHI, ssa.OpAMD64CMOVLHI, ssa.OpAMD64CMOVWHI,
|
|
|
|
|
ssa.OpAMD64CMOVQLS, ssa.OpAMD64CMOVLLS, ssa.OpAMD64CMOVWLS,
|
|
|
|
|
ssa.OpAMD64CMOVQCC, ssa.OpAMD64CMOVLCC, ssa.OpAMD64CMOVWCC,
|
|
|
|
|
ssa.OpAMD64CMOVQCS, ssa.OpAMD64CMOVLCS, ssa.OpAMD64CMOVWCS,
|
|
|
|
|
ssa.OpAMD64CMOVQGTF, ssa.OpAMD64CMOVLGTF, ssa.OpAMD64CMOVWGTF,
|
|
|
|
|
ssa.OpAMD64CMOVQGEF, ssa.OpAMD64CMOVLGEF, ssa.OpAMD64CMOVWGEF:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-11 00:10:52 -05:00
|
|
|
p.From.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[1].Reg()
|
2016-03-11 00:10:52 -05:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
p.To.Reg = v.Reg()
|
2016-03-11 00:10:52 -05:00
|
|
|
|
2018-03-05 20:59:40 +01:00
|
|
|
case ssa.OpAMD64CMOVQNEF, ssa.OpAMD64CMOVLNEF, ssa.OpAMD64CMOVWNEF:
|
|
|
|
|
// Flag condition: ^ZERO || PARITY
|
|
|
|
|
// Generate:
|
|
|
|
|
// CMOV*NE SRC,DST
|
|
|
|
|
// CMOV*PS SRC,DST
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[1].Reg()
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
p.To.Reg = v.Reg()
|
2018-03-05 20:59:40 +01:00
|
|
|
var q *obj.Prog
|
|
|
|
|
if v.Op == ssa.OpAMD64CMOVQNEF {
|
|
|
|
|
q = s.Prog(x86.ACMOVQPS)
|
|
|
|
|
} else if v.Op == ssa.OpAMD64CMOVLNEF {
|
|
|
|
|
q = s.Prog(x86.ACMOVLPS)
|
|
|
|
|
} else {
|
|
|
|
|
q = s.Prog(x86.ACMOVWPS)
|
|
|
|
|
}
|
|
|
|
|
q.From.Type = obj.TYPE_REG
|
|
|
|
|
q.From.Reg = v.Args[1].Reg()
|
|
|
|
|
q.To.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
q.To.Reg = v.Reg()
|
2018-03-05 20:59:40 +01:00
|
|
|
|
|
|
|
|
case ssa.OpAMD64CMOVQEQF, ssa.OpAMD64CMOVLEQF, ssa.OpAMD64CMOVWEQF:
|
|
|
|
|
// Flag condition: ZERO && !PARITY
|
|
|
|
|
// Generate:
|
2022-04-05 15:07:29 -07:00
|
|
|
// MOV SRC,TMP
|
|
|
|
|
// CMOV*NE DST,TMP
|
|
|
|
|
// CMOV*PC TMP,DST
|
2018-03-05 20:59:40 +01:00
|
|
|
//
|
|
|
|
|
// TODO(rasky): we could generate:
|
|
|
|
|
// CMOV*NE DST,SRC
|
|
|
|
|
// CMOV*PC SRC,DST
|
|
|
|
|
// But this requires a way for regalloc to know that SRC might be
|
|
|
|
|
// clobbered by this instruction.
|
2022-04-05 15:07:29 -07:00
|
|
|
t := v.RegTmp()
|
2025-08-14 20:21:37 +00:00
|
|
|
opregreg(s, moveByRegsWidth(t, v.Args[1].Reg(), v.Type.Size()), t, v.Args[1].Reg())
|
2022-04-05 15:07:29 -07:00
|
|
|
|
2018-03-05 20:59:40 +01:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
p.From.Reg = v.Reg()
|
2018-03-05 20:59:40 +01:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2022-04-05 15:07:29 -07:00
|
|
|
p.To.Reg = t
|
2018-03-05 20:59:40 +01:00
|
|
|
var q *obj.Prog
|
|
|
|
|
if v.Op == ssa.OpAMD64CMOVQEQF {
|
|
|
|
|
q = s.Prog(x86.ACMOVQPC)
|
|
|
|
|
} else if v.Op == ssa.OpAMD64CMOVLEQF {
|
|
|
|
|
q = s.Prog(x86.ACMOVLPC)
|
|
|
|
|
} else {
|
|
|
|
|
q = s.Prog(x86.ACMOVWPC)
|
|
|
|
|
}
|
|
|
|
|
q.From.Type = obj.TYPE_REG
|
2022-04-05 15:07:29 -07:00
|
|
|
q.From.Reg = t
|
2018-03-05 20:59:40 +01:00
|
|
|
q.To.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
q.To.Reg = v.Reg()
|
2018-03-05 20:59:40 +01:00
|
|
|
|
2016-04-22 13:09:18 -07:00
|
|
|
case ssa.OpAMD64MULQconst, ssa.OpAMD64MULLconst:
|
2016-09-16 09:36:00 -07:00
|
|
|
r := v.Reg()
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
2016-03-29 16:39:53 -07:00
|
|
|
p.From.Offset = v.AuxInt
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
2023-04-12 11:23:13 +08:00
|
|
|
p.AddRestSourceReg(v.Args[0].Reg())
|
2016-03-12 14:07:40 -08:00
|
|
|
|
2021-10-10 17:56:16 +02:00
|
|
|
case ssa.OpAMD64ANDQconst:
|
|
|
|
|
asm := v.Op.Asm()
|
|
|
|
|
// If the constant is positive and fits into 32 bits, use ANDL.
|
|
|
|
|
// This saves a few bytes of encoding.
|
|
|
|
|
if 0 <= v.AuxInt && v.AuxInt <= (1<<32-1) {
|
|
|
|
|
asm = x86.AANDL
|
|
|
|
|
}
|
|
|
|
|
p := s.Prog(asm)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = v.AuxInt
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
|
|
|
|
|
2016-04-22 13:09:18 -07:00
|
|
|
case ssa.OpAMD64SUBQconst, ssa.OpAMD64SUBLconst,
|
2021-10-10 17:56:16 +02:00
|
|
|
ssa.OpAMD64ANDLconst,
|
2016-04-22 13:09:18 -07:00
|
|
|
ssa.OpAMD64ORQconst, ssa.OpAMD64ORLconst,
|
|
|
|
|
ssa.OpAMD64XORQconst, ssa.OpAMD64XORLconst,
|
|
|
|
|
ssa.OpAMD64SHLQconst, ssa.OpAMD64SHLLconst,
|
2016-04-10 08:26:43 -07:00
|
|
|
ssa.OpAMD64SHRQconst, ssa.OpAMD64SHRLconst, ssa.OpAMD64SHRWconst, ssa.OpAMD64SHRBconst,
|
|
|
|
|
ssa.OpAMD64SARQconst, ssa.OpAMD64SARLconst, ssa.OpAMD64SARWconst, ssa.OpAMD64SARBconst,
|
|
|
|
|
ssa.OpAMD64ROLQconst, ssa.OpAMD64ROLLconst, ssa.OpAMD64ROLWconst, ssa.OpAMD64ROLBconst:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
2016-03-29 16:39:53 -07:00
|
|
|
p.From.Offset = v.AuxInt
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
p.To.Reg = v.Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64SBBQcarrymask, ssa.OpAMD64SBBLcarrymask:
|
2016-09-16 09:36:00 -07:00
|
|
|
r := v.Reg()
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = r
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = r
|
2018-02-26 07:04:32 -08:00
|
|
|
case ssa.OpAMD64LEAQ1, ssa.OpAMD64LEAQ2, ssa.OpAMD64LEAQ4, ssa.OpAMD64LEAQ8,
|
|
|
|
|
ssa.OpAMD64LEAL1, ssa.OpAMD64LEAL2, ssa.OpAMD64LEAL4, ssa.OpAMD64LEAL8,
|
|
|
|
|
ssa.OpAMD64LEAW1, ssa.OpAMD64LEAW2, ssa.OpAMD64LEAW4, ssa.OpAMD64LEAW8:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
2019-03-09 12:41:34 -08:00
|
|
|
memIdx(&p.From, v)
|
|
|
|
|
o := v.Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2018-05-11 08:01:31 +02:00
|
|
|
p.To.Reg = o
|
|
|
|
|
if v.AuxInt != 0 && v.Aux == nil {
|
|
|
|
|
// Emit an additional LEA to add the displacement instead of creating a slow 3 operand LEA.
|
|
|
|
|
switch v.Op {
|
|
|
|
|
case ssa.OpAMD64LEAQ1, ssa.OpAMD64LEAQ2, ssa.OpAMD64LEAQ4, ssa.OpAMD64LEAQ8:
|
|
|
|
|
p = s.Prog(x86.ALEAQ)
|
|
|
|
|
case ssa.OpAMD64LEAL1, ssa.OpAMD64LEAL2, ssa.OpAMD64LEAL4, ssa.OpAMD64LEAL8:
|
|
|
|
|
p = s.Prog(x86.ALEAL)
|
|
|
|
|
case ssa.OpAMD64LEAW1, ssa.OpAMD64LEAW2, ssa.OpAMD64LEAW4, ssa.OpAMD64LEAW8:
|
|
|
|
|
p = s.Prog(x86.ALEAW)
|
|
|
|
|
}
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = o
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = o
|
|
|
|
|
}
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.From, v)
|
2018-02-26 07:04:32 -08:00
|
|
|
case ssa.OpAMD64LEAQ, ssa.OpAMD64LEAL, ssa.OpAMD64LEAW:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_MEM
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[0].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.From, v)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64CMPQ, ssa.OpAMD64CMPL, ssa.OpAMD64CMPW, ssa.OpAMD64CMPB,
|
2017-02-06 10:55:39 -08:00
|
|
|
ssa.OpAMD64TESTQ, ssa.OpAMD64TESTL, ssa.OpAMD64TESTW, ssa.OpAMD64TESTB,
|
|
|
|
|
ssa.OpAMD64BTL, ssa.OpAMD64BTQ:
|
2017-03-20 08:01:28 -07:00
|
|
|
opregreg(s, v.Op.Asm(), v.Args[1].Reg(), v.Args[0].Reg())
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64UCOMISS, ssa.OpAMD64UCOMISD:
|
|
|
|
|
// Go assembler has swapped operands for UCOMISx relative to CMP,
|
|
|
|
|
// must account for that right here.
|
2017-03-20 08:01:28 -07:00
|
|
|
opregreg(s, v.Op.Asm(), v.Args[0].Reg(), v.Args[1].Reg())
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64CMPQconst, ssa.OpAMD64CMPLconst, ssa.OpAMD64CMPWconst, ssa.OpAMD64CMPBconst:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[0].Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_CONST
|
2016-03-29 16:39:53 -07:00
|
|
|
p.To.Offset = v.AuxInt
|
2018-09-08 14:23:14 +00:00
|
|
|
case ssa.OpAMD64BTLconst, ssa.OpAMD64BTQconst,
|
|
|
|
|
ssa.OpAMD64TESTQconst, ssa.OpAMD64TESTLconst, ssa.OpAMD64TESTWconst, ssa.OpAMD64TESTBconst,
|
2023-08-01 14:32:56 -07:00
|
|
|
ssa.OpAMD64BTSQconst,
|
|
|
|
|
ssa.OpAMD64BTCQconst,
|
|
|
|
|
ssa.OpAMD64BTRQconst:
|
2018-03-10 11:17:05 +01:00
|
|
|
op := v.Op
|
|
|
|
|
if op == ssa.OpAMD64BTQconst && v.AuxInt < 32 {
|
|
|
|
|
// Emit 32-bit version because it's shorter
|
|
|
|
|
op = ssa.OpAMD64BTLconst
|
|
|
|
|
}
|
|
|
|
|
p := s.Prog(op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = v.AuxInt
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Args[0].Reg()
|
2018-05-08 09:11:00 -07:00
|
|
|
case ssa.OpAMD64CMPQload, ssa.OpAMD64CMPLload, ssa.OpAMD64CMPWload, ssa.OpAMD64CMPBload:
|
2018-01-03 14:38:55 -08:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.From, v)
|
2018-01-03 14:38:55 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Args[1].Reg()
|
2018-05-08 09:11:00 -07:00
|
|
|
case ssa.OpAMD64CMPQconstload, ssa.OpAMD64CMPLconstload, ssa.OpAMD64CMPWconstload, ssa.OpAMD64CMPBconstload:
|
2018-01-03 14:38:55 -08:00
|
|
|
sc := v.AuxValAndOff()
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
2021-03-05 11:22:13 +01:00
|
|
|
ssagen.AddAux2(&p.From, v, sc.Off64())
|
2018-01-03 14:38:55 -08:00
|
|
|
p.To.Type = obj.TYPE_CONST
|
2021-03-05 11:22:13 +01:00
|
|
|
p.To.Offset = sc.Val64()
|
2020-03-19 17:48:42 -07:00
|
|
|
case ssa.OpAMD64CMPQloadidx8, ssa.OpAMD64CMPQloadidx1, ssa.OpAMD64CMPLloadidx4, ssa.OpAMD64CMPLloadidx1, ssa.OpAMD64CMPWloadidx2, ssa.OpAMD64CMPWloadidx1, ssa.OpAMD64CMPBloadidx1:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
memIdx(&p.From, v)
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.From, v)
|
2020-03-19 17:48:42 -07:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Args[2].Reg()
|
|
|
|
|
case ssa.OpAMD64CMPQconstloadidx8, ssa.OpAMD64CMPQconstloadidx1, ssa.OpAMD64CMPLconstloadidx4, ssa.OpAMD64CMPLconstloadidx1, ssa.OpAMD64CMPWconstloadidx2, ssa.OpAMD64CMPWconstloadidx1, ssa.OpAMD64CMPBconstloadidx1:
|
|
|
|
|
sc := v.AuxValAndOff()
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
memIdx(&p.From, v)
|
2021-03-05 11:22:13 +01:00
|
|
|
ssagen.AddAux2(&p.From, v, sc.Off64())
|
2020-03-19 17:48:42 -07:00
|
|
|
p.To.Type = obj.TYPE_CONST
|
2021-03-05 11:22:13 +01:00
|
|
|
p.To.Offset = sc.Val64()
|
2016-04-22 13:09:18 -07:00
|
|
|
case ssa.OpAMD64MOVLconst, ssa.OpAMD64MOVQconst:
|
2016-09-16 09:36:00 -07:00
|
|
|
x := v.Reg()
|
2017-10-24 13:24:14 -07:00
|
|
|
|
|
|
|
|
// If flags aren't live (indicated by v.Aux == nil),
|
|
|
|
|
// then we can rewrite MOV $0, AX into XOR AX, AX.
|
|
|
|
|
if v.AuxInt == 0 && v.Aux == nil {
|
2021-12-06 11:46:57 +03:00
|
|
|
opregreg(s, x86.AXORL, x, x)
|
2017-10-24 13:24:14 -07:00
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-24 08:13:17 +01:00
|
|
|
asm := v.Op.Asm()
|
|
|
|
|
// Use MOVL to move a small constant into a register
|
|
|
|
|
// when the constant is positive and fits into 32 bits.
|
|
|
|
|
if 0 <= v.AuxInt && v.AuxInt <= (1<<32-1) {
|
|
|
|
|
// The upper 32bit are zeroed automatically when using MOVL.
|
|
|
|
|
asm = x86.AMOVL
|
|
|
|
|
}
|
|
|
|
|
p := s.Prog(asm)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
2016-03-29 16:39:53 -07:00
|
|
|
p.From.Offset = v.AuxInt
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = x
|
2025-08-07 16:44:50 -04:00
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64MOVSSconst, ssa.OpAMD64MOVSDconst:
|
2016-09-16 09:36:00 -07:00
|
|
|
x := v.Reg()
|
2025-08-14 16:56:28 +00:00
|
|
|
if !isFPReg(x) && v.AuxInt == 0 && v.Aux == nil {
|
|
|
|
|
opregreg(s, x86.AXORL, x, x)
|
|
|
|
|
break
|
2025-08-07 16:44:50 -04:00
|
|
|
}
|
2025-08-14 20:21:37 +00:00
|
|
|
p := s.Prog(storeByRegWidth(x, v.Type.Size()))
|
2025-08-14 16:56:28 +00:00
|
|
|
p.From.Type = obj.TYPE_FCONST
|
|
|
|
|
p.From.Val = math.Float64frombits(uint64(v.AuxInt))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = x
|
2021-10-19 19:39:21 +08:00
|
|
|
case ssa.OpAMD64MOVQload, ssa.OpAMD64MOVLload, ssa.OpAMD64MOVWload, ssa.OpAMD64MOVBload, ssa.OpAMD64MOVOload,
|
|
|
|
|
ssa.OpAMD64MOVSSload, ssa.OpAMD64MOVSDload, ssa.OpAMD64MOVBQSXload, ssa.OpAMD64MOVWQSXload, ssa.OpAMD64MOVLQSXload,
|
|
|
|
|
ssa.OpAMD64MOVBEQload, ssa.OpAMD64MOVBELload:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_MEM
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[0].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.From, v)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Reg()
|
2018-10-06 03:35:17 +00:00
|
|
|
case ssa.OpAMD64MOVBloadidx1, ssa.OpAMD64MOVWloadidx1, ssa.OpAMD64MOVLloadidx1, ssa.OpAMD64MOVQloadidx1, ssa.OpAMD64MOVSSloadidx1, ssa.OpAMD64MOVSDloadidx1,
|
2022-03-24 22:53:41 +08:00
|
|
|
ssa.OpAMD64MOVQloadidx8, ssa.OpAMD64MOVSDloadidx8, ssa.OpAMD64MOVLloadidx8, ssa.OpAMD64MOVLloadidx4, ssa.OpAMD64MOVSSloadidx4, ssa.OpAMD64MOVWloadidx2,
|
|
|
|
|
ssa.OpAMD64MOVBELloadidx1, ssa.OpAMD64MOVBELloadidx4, ssa.OpAMD64MOVBELloadidx8, ssa.OpAMD64MOVBEQloadidx1, ssa.OpAMD64MOVBEQloadidx8:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2019-03-09 12:41:34 -08:00
|
|
|
memIdx(&p.From, v)
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.From, v)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Reg()
|
2018-06-29 02:11:53 +00:00
|
|
|
case ssa.OpAMD64MOVQstore, ssa.OpAMD64MOVSSstore, ssa.OpAMD64MOVSDstore, ssa.OpAMD64MOVLstore, ssa.OpAMD64MOVWstore, ssa.OpAMD64MOVBstore, ssa.OpAMD64MOVOstore,
|
|
|
|
|
ssa.OpAMD64ADDQmodify, ssa.OpAMD64SUBQmodify, ssa.OpAMD64ANDQmodify, ssa.OpAMD64ORQmodify, ssa.OpAMD64XORQmodify,
|
2021-10-19 19:39:21 +08:00
|
|
|
ssa.OpAMD64ADDLmodify, ssa.OpAMD64SUBLmodify, ssa.OpAMD64ANDLmodify, ssa.OpAMD64ORLmodify, ssa.OpAMD64XORLmodify,
|
2022-03-30 19:27:21 +08:00
|
|
|
ssa.OpAMD64MOVBEQstore, ssa.OpAMD64MOVBELstore, ssa.OpAMD64MOVBEWstore:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[1].Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_MEM
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Args[0].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.To, v)
|
2018-10-06 03:35:17 +00:00
|
|
|
case ssa.OpAMD64MOVBstoreidx1, ssa.OpAMD64MOVWstoreidx1, ssa.OpAMD64MOVLstoreidx1, ssa.OpAMD64MOVQstoreidx1, ssa.OpAMD64MOVSSstoreidx1, ssa.OpAMD64MOVSDstoreidx1,
|
2020-04-13 09:59:20 -07:00
|
|
|
ssa.OpAMD64MOVQstoreidx8, ssa.OpAMD64MOVSDstoreidx8, ssa.OpAMD64MOVLstoreidx8, ssa.OpAMD64MOVSSstoreidx4, ssa.OpAMD64MOVLstoreidx4, ssa.OpAMD64MOVWstoreidx2,
|
|
|
|
|
ssa.OpAMD64ADDLmodifyidx1, ssa.OpAMD64ADDLmodifyidx4, ssa.OpAMD64ADDLmodifyidx8, ssa.OpAMD64ADDQmodifyidx1, ssa.OpAMD64ADDQmodifyidx8,
|
|
|
|
|
ssa.OpAMD64SUBLmodifyidx1, ssa.OpAMD64SUBLmodifyidx4, ssa.OpAMD64SUBLmodifyidx8, ssa.OpAMD64SUBQmodifyidx1, ssa.OpAMD64SUBQmodifyidx8,
|
|
|
|
|
ssa.OpAMD64ANDLmodifyidx1, ssa.OpAMD64ANDLmodifyidx4, ssa.OpAMD64ANDLmodifyidx8, ssa.OpAMD64ANDQmodifyidx1, ssa.OpAMD64ANDQmodifyidx8,
|
|
|
|
|
ssa.OpAMD64ORLmodifyidx1, ssa.OpAMD64ORLmodifyidx4, ssa.OpAMD64ORLmodifyidx8, ssa.OpAMD64ORQmodifyidx1, ssa.OpAMD64ORQmodifyidx8,
|
2022-03-24 22:53:41 +08:00
|
|
|
ssa.OpAMD64XORLmodifyidx1, ssa.OpAMD64XORLmodifyidx4, ssa.OpAMD64XORLmodifyidx8, ssa.OpAMD64XORQmodifyidx1, ssa.OpAMD64XORQmodifyidx8,
|
|
|
|
|
ssa.OpAMD64MOVBEWstoreidx1, ssa.OpAMD64MOVBEWstoreidx2, ssa.OpAMD64MOVBELstoreidx1, ssa.OpAMD64MOVBELstoreidx4, ssa.OpAMD64MOVBELstoreidx8, ssa.OpAMD64MOVBEQstoreidx1, ssa.OpAMD64MOVBEQstoreidx8:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[2].Reg()
|
2019-03-09 12:41:34 -08:00
|
|
|
memIdx(&p.To, v)
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.To, v)
|
2018-05-08 09:11:00 -07:00
|
|
|
case ssa.OpAMD64ADDQconstmodify, ssa.OpAMD64ADDLconstmodify:
|
2017-08-09 15:43:25 -05:00
|
|
|
sc := v.AuxValAndOff()
|
2021-03-05 11:22:13 +01:00
|
|
|
off := sc.Off64()
|
2017-08-09 15:43:25 -05:00
|
|
|
val := sc.Val()
|
2018-10-29 08:34:42 +00:00
|
|
|
if val == 1 || val == -1 {
|
2017-08-09 15:43:25 -05:00
|
|
|
var asm obj.As
|
2018-05-08 09:11:00 -07:00
|
|
|
if v.Op == ssa.OpAMD64ADDQconstmodify {
|
2018-10-29 08:34:42 +00:00
|
|
|
if val == 1 {
|
|
|
|
|
asm = x86.AINCQ
|
|
|
|
|
} else {
|
|
|
|
|
asm = x86.ADECQ
|
|
|
|
|
}
|
2017-08-09 15:43:25 -05:00
|
|
|
} else {
|
2018-10-29 08:34:42 +00:00
|
|
|
if val == 1 {
|
|
|
|
|
asm = x86.AINCL
|
|
|
|
|
} else {
|
|
|
|
|
asm = x86.ADECL
|
|
|
|
|
}
|
2017-08-09 15:43:25 -05:00
|
|
|
}
|
|
|
|
|
p := s.Prog(asm)
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = v.Args[0].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux2(&p.To, v, off)
|
2018-09-18 01:53:42 +00:00
|
|
|
break
|
2017-08-09 15:43:25 -05:00
|
|
|
}
|
2018-09-18 01:53:42 +00:00
|
|
|
fallthrough
|
2018-06-27 02:46:17 +00:00
|
|
|
case ssa.OpAMD64ANDQconstmodify, ssa.OpAMD64ANDLconstmodify, ssa.OpAMD64ORQconstmodify, ssa.OpAMD64ORLconstmodify,
|
2023-08-01 14:32:56 -07:00
|
|
|
ssa.OpAMD64XORQconstmodify, ssa.OpAMD64XORLconstmodify,
|
|
|
|
|
ssa.OpAMD64BTSQconstmodify, ssa.OpAMD64BTRQconstmodify, ssa.OpAMD64BTCQconstmodify:
|
2018-06-27 02:46:17 +00:00
|
|
|
sc := v.AuxValAndOff()
|
2021-03-05 11:22:13 +01:00
|
|
|
off := sc.Off64()
|
|
|
|
|
val := sc.Val64()
|
2018-06-27 02:46:17 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = val
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = v.Args[0].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux2(&p.To, v, off)
|
2020-04-13 09:59:20 -07:00
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64MOVQstoreconst, ssa.OpAMD64MOVLstoreconst, ssa.OpAMD64MOVWstoreconst, ssa.OpAMD64MOVBstoreconst:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
sc := v.AuxValAndOff()
|
2021-03-05 11:22:13 +01:00
|
|
|
p.From.Offset = sc.Val64()
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_MEM
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Args[0].Reg()
|
2021-03-05 11:22:13 +01:00
|
|
|
ssagen.AddAux2(&p.To, v, sc.Off64())
|
2021-08-30 22:42:17 +02:00
|
|
|
case ssa.OpAMD64MOVOstoreconst:
|
|
|
|
|
sc := v.AuxValAndOff()
|
|
|
|
|
if sc.Val() != 0 {
|
|
|
|
|
v.Fatalf("MOVO for non zero constants not implemented: %s", v.LongString())
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 14:29:20 -04:00
|
|
|
if s.ABI != obj.ABIInternal {
|
all: explode GOEXPERIMENT=regabi into 5 sub-experiments
This separates GOEXPERIMENT=regabi into five sub-experiments:
regabiwrappers, regabig, regabireflect, regabidefer, and regabiargs.
Setting GOEXPERIMENT=regabi now implies the working subset of these
(currently, regabiwrappers, regabig, and regabireflect).
This simplifies testing, helps derisk the register ABI project,
and will also help with performance comparisons.
This replaces the -abiwrap flag to the compiler and linker with
the regabiwrappers experiment.
As part of this, regabiargs now enables registers for all calls
in the compiler. Previously, this was statically disabled in
regabiEnabledForAllCompilation, but now that we can control it
independently, this isn't necessary.
For #40724.
Change-Id: I5171e60cda6789031f2ef034cc2e7c5d62459122
Reviewed-on: https://go-review.googlesource.com/c/go/+/302070
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
2021-03-15 16:48:54 -04:00
|
|
|
// zero X15 manually
|
2021-01-29 13:46:34 -05:00
|
|
|
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
|
|
|
|
|
}
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = x86.REG_X15
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = v.Args[0].Reg()
|
2021-08-30 22:42:17 +02:00
|
|
|
ssagen.AddAux2(&p.To, v, sc.Off64())
|
|
|
|
|
|
2020-04-13 09:59:20 -07:00
|
|
|
case ssa.OpAMD64MOVQstoreconstidx1, ssa.OpAMD64MOVQstoreconstidx8, ssa.OpAMD64MOVLstoreconstidx1, ssa.OpAMD64MOVLstoreconstidx4, ssa.OpAMD64MOVWstoreconstidx1, ssa.OpAMD64MOVWstoreconstidx2, ssa.OpAMD64MOVBstoreconstidx1,
|
|
|
|
|
ssa.OpAMD64ADDLconstmodifyidx1, ssa.OpAMD64ADDLconstmodifyidx4, ssa.OpAMD64ADDLconstmodifyidx8, ssa.OpAMD64ADDQconstmodifyidx1, ssa.OpAMD64ADDQconstmodifyidx8,
|
|
|
|
|
ssa.OpAMD64ANDLconstmodifyidx1, ssa.OpAMD64ANDLconstmodifyidx4, ssa.OpAMD64ANDLconstmodifyidx8, ssa.OpAMD64ANDQconstmodifyidx1, ssa.OpAMD64ANDQconstmodifyidx8,
|
|
|
|
|
ssa.OpAMD64ORLconstmodifyidx1, ssa.OpAMD64ORLconstmodifyidx4, ssa.OpAMD64ORLconstmodifyidx8, ssa.OpAMD64ORQconstmodifyidx1, ssa.OpAMD64ORQconstmodifyidx8,
|
|
|
|
|
ssa.OpAMD64XORLconstmodifyidx1, ssa.OpAMD64XORLconstmodifyidx4, ssa.OpAMD64XORLconstmodifyidx8, ssa.OpAMD64XORQconstmodifyidx1, ssa.OpAMD64XORQconstmodifyidx8:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
sc := v.AuxValAndOff()
|
2021-03-05 11:22:13 +01:00
|
|
|
p.From.Offset = sc.Val64()
|
2020-04-13 09:59:20 -07:00
|
|
|
switch {
|
|
|
|
|
case p.As == x86.AADDQ && p.From.Offset == 1:
|
|
|
|
|
p.As = x86.AINCQ
|
|
|
|
|
p.From.Type = obj.TYPE_NONE
|
|
|
|
|
case p.As == x86.AADDQ && p.From.Offset == -1:
|
|
|
|
|
p.As = x86.ADECQ
|
|
|
|
|
p.From.Type = obj.TYPE_NONE
|
|
|
|
|
case p.As == x86.AADDL && p.From.Offset == 1:
|
|
|
|
|
p.As = x86.AINCL
|
|
|
|
|
p.From.Type = obj.TYPE_NONE
|
|
|
|
|
case p.As == x86.AADDL && p.From.Offset == -1:
|
|
|
|
|
p.As = x86.ADECL
|
|
|
|
|
p.From.Type = obj.TYPE_NONE
|
|
|
|
|
}
|
2019-03-09 12:41:34 -08:00
|
|
|
memIdx(&p.To, v)
|
2021-03-05 11:22:13 +01:00
|
|
|
ssagen.AddAux2(&p.To, v, sc.Off64())
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64MOVLQSX, ssa.OpAMD64MOVWQSX, ssa.OpAMD64MOVBQSX, ssa.OpAMD64MOVLQZX, ssa.OpAMD64MOVWQZX, ssa.OpAMD64MOVBQZX,
|
|
|
|
|
ssa.OpAMD64CVTTSS2SL, ssa.OpAMD64CVTTSD2SL, ssa.OpAMD64CVTTSS2SQ, ssa.OpAMD64CVTTSD2SQ,
|
2024-11-04 12:41:33 -05:00
|
|
|
ssa.OpAMD64CVTSS2SD, ssa.OpAMD64CVTSD2SS, ssa.OpAMD64VPBROADCASTB, ssa.OpAMD64PMOVMSKB:
|
2017-03-20 08:01:28 -07:00
|
|
|
opregreg(s, v.Op.Asm(), v.Reg(), v.Args[0].Reg())
|
2016-10-19 20:21:42 +03:00
|
|
|
case ssa.OpAMD64CVTSL2SD, ssa.OpAMD64CVTSQ2SD, ssa.OpAMD64CVTSQ2SS, ssa.OpAMD64CVTSL2SS:
|
|
|
|
|
r := v.Reg()
|
|
|
|
|
// Break false dependency on destination register.
|
2017-03-20 08:01:28 -07:00
|
|
|
opregreg(s, x86.AXORPS, r, r)
|
|
|
|
|
opregreg(s, v.Op.Asm(), r, v.Args[0].Reg())
|
2018-10-08 02:20:03 +00:00
|
|
|
case ssa.OpAMD64MOVQi2f, ssa.OpAMD64MOVQf2i, ssa.OpAMD64MOVLi2f, ssa.OpAMD64MOVLf2i:
|
|
|
|
|
var p *obj.Prog
|
|
|
|
|
switch v.Op {
|
|
|
|
|
case ssa.OpAMD64MOVQi2f, ssa.OpAMD64MOVQf2i:
|
|
|
|
|
p = s.Prog(x86.AMOVQ)
|
|
|
|
|
case ssa.OpAMD64MOVLi2f, ssa.OpAMD64MOVLf2i:
|
|
|
|
|
p = s.Prog(x86.AMOVL)
|
|
|
|
|
}
|
cmd/compile,math: improve code generation for math.Abs
Implement int reg <-> fp reg moves on amd64.
If we see a load to int reg followed by an int->fp move, then we can just
load to the fp reg instead. Same for stores.
math.Abs is now:
MOVQ "".x+8(SP), AX
SHLQ $1, AX
SHRQ $1, AX
MOVQ AX, "".~r1+16(SP)
math.Copysign is now:
MOVQ "".x+8(SP), AX
SHLQ $1, AX
SHRQ $1, AX
MOVQ "".y+16(SP), CX
SHRQ $63, CX
SHLQ $63, CX
ORQ CX, AX
MOVQ AX, "".~r2+24(SP)
math.Float64bits is now:
MOVSD "".x+8(SP), X0
MOVSD X0, "".~r1+16(SP)
(it would be nicer to use a non-SSE reg for this, nothing is perfect)
And due to the fix for #21440, the inlined version of these improve as well.
name old time/op new time/op delta
Abs 1.38ns ± 5% 0.89ns ±10% -35.54% (p=0.000 n=10+10)
Copysign 1.56ns ± 7% 1.35ns ± 6% -13.77% (p=0.000 n=9+10)
Fixes #13095
Change-Id: Ibd7f2792412a6668608780b0688a77062e1f1499
Reviewed-on: https://go-review.googlesource.com/58732
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ilya Tocar <ilya.tocar@intel.com>
2017-08-24 13:19:40 -07:00
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
2018-05-08 09:11:00 -07:00
|
|
|
case ssa.OpAMD64ADDQload, ssa.OpAMD64ADDLload, ssa.OpAMD64SUBQload, ssa.OpAMD64SUBLload,
|
|
|
|
|
ssa.OpAMD64ANDQload, ssa.OpAMD64ANDLload, ssa.OpAMD64ORQload, ssa.OpAMD64ORLload,
|
|
|
|
|
ssa.OpAMD64XORQload, ssa.OpAMD64XORLload, ssa.OpAMD64ADDSDload, ssa.OpAMD64ADDSSload,
|
2018-06-21 10:14:18 +00:00
|
|
|
ssa.OpAMD64SUBSDload, ssa.OpAMD64SUBSSload, ssa.OpAMD64MULSDload, ssa.OpAMD64MULSSload,
|
|
|
|
|
ssa.OpAMD64DIVSDload, ssa.OpAMD64DIVSSload:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2017-02-10 13:17:20 -06:00
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[1].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.From, v)
|
2017-02-10 13:17:20 -06:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
2020-04-11 22:15:58 -07:00
|
|
|
case ssa.OpAMD64ADDLloadidx1, ssa.OpAMD64ADDLloadidx4, ssa.OpAMD64ADDLloadidx8, ssa.OpAMD64ADDQloadidx1, ssa.OpAMD64ADDQloadidx8,
|
|
|
|
|
ssa.OpAMD64SUBLloadidx1, ssa.OpAMD64SUBLloadidx4, ssa.OpAMD64SUBLloadidx8, ssa.OpAMD64SUBQloadidx1, ssa.OpAMD64SUBQloadidx8,
|
|
|
|
|
ssa.OpAMD64ANDLloadidx1, ssa.OpAMD64ANDLloadidx4, ssa.OpAMD64ANDLloadidx8, ssa.OpAMD64ANDQloadidx1, ssa.OpAMD64ANDQloadidx8,
|
|
|
|
|
ssa.OpAMD64ORLloadidx1, ssa.OpAMD64ORLloadidx4, ssa.OpAMD64ORLloadidx8, ssa.OpAMD64ORQloadidx1, ssa.OpAMD64ORQloadidx8,
|
2020-07-27 09:45:21 -07:00
|
|
|
ssa.OpAMD64XORLloadidx1, ssa.OpAMD64XORLloadidx4, ssa.OpAMD64XORLloadidx8, ssa.OpAMD64XORQloadidx1, ssa.OpAMD64XORQloadidx8,
|
|
|
|
|
ssa.OpAMD64ADDSSloadidx1, ssa.OpAMD64ADDSSloadidx4, ssa.OpAMD64ADDSDloadidx1, ssa.OpAMD64ADDSDloadidx8,
|
|
|
|
|
ssa.OpAMD64SUBSSloadidx1, ssa.OpAMD64SUBSSloadidx4, ssa.OpAMD64SUBSDloadidx1, ssa.OpAMD64SUBSDloadidx8,
|
|
|
|
|
ssa.OpAMD64MULSSloadidx1, ssa.OpAMD64MULSSloadidx4, ssa.OpAMD64MULSDloadidx1, ssa.OpAMD64MULSDloadidx8,
|
|
|
|
|
ssa.OpAMD64DIVSSloadidx1, ssa.OpAMD64DIVSSloadidx4, ssa.OpAMD64DIVSDloadidx1, ssa.OpAMD64DIVSDloadidx8:
|
2020-04-11 22:15:58 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
|
|
|
|
|
r, i := v.Args[1].Reg(), v.Args[2].Reg()
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Scale = v.Op.Scale()
|
|
|
|
|
if p.From.Scale == 1 && i == x86.REG_SP {
|
|
|
|
|
r, i = i, r
|
|
|
|
|
}
|
|
|
|
|
p.From.Reg = r
|
|
|
|
|
p.From.Index = i
|
|
|
|
|
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.From, v)
|
2020-04-11 22:15:58 -07:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
2025-06-03 16:23:02 -07:00
|
|
|
|
|
|
|
|
case ssa.OpAMD64LoweredZero:
|
2021-06-09 14:29:20 -04:00
|
|
|
if s.ABI != obj.ABIInternal {
|
all: explode GOEXPERIMENT=regabi into 5 sub-experiments
This separates GOEXPERIMENT=regabi into five sub-experiments:
regabiwrappers, regabig, regabireflect, regabidefer, and regabiargs.
Setting GOEXPERIMENT=regabi now implies the working subset of these
(currently, regabiwrappers, regabig, and regabireflect).
This simplifies testing, helps derisk the register ABI project,
and will also help with performance comparisons.
This replaces the -abiwrap flag to the compiler and linker with
the regabiwrappers experiment.
As part of this, regabiargs now enables registers for all calls
in the compiler. Previously, this was statically disabled in
regabiEnabledForAllCompilation, but now that we can control it
independently, this isn't necessary.
For #40724.
Change-Id: I5171e60cda6789031f2ef034cc2e7c5d62459122
Reviewed-on: https://go-review.googlesource.com/c/go/+/302070
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
2021-03-15 16:48:54 -04:00
|
|
|
// zero X15 manually
|
2021-01-29 13:46:34 -05:00
|
|
|
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
|
|
|
|
|
}
|
2025-06-03 16:23:02 -07:00
|
|
|
ptrReg := v.Args[0].Reg()
|
|
|
|
|
n := v.AuxInt
|
|
|
|
|
if n < 16 {
|
|
|
|
|
v.Fatalf("Zero too small %d", n)
|
2016-07-28 12:22:49 -04:00
|
|
|
}
|
2025-06-03 16:23:02 -07:00
|
|
|
zero16 := func(off int64) {
|
|
|
|
|
zero16(s, ptrReg, off)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate zeroing instructions.
|
|
|
|
|
var off int64
|
|
|
|
|
for n >= 16 {
|
|
|
|
|
zero16(off)
|
|
|
|
|
off += 16
|
|
|
|
|
n -= 16
|
|
|
|
|
}
|
|
|
|
|
if n != 0 {
|
|
|
|
|
// use partially overlapped write.
|
|
|
|
|
// TODO: n <= 8, use smaller write?
|
|
|
|
|
zero16(off + n - 16)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case ssa.OpAMD64LoweredZeroLoop:
|
|
|
|
|
if s.ABI != obj.ABIInternal {
|
|
|
|
|
// zero X15 manually
|
|
|
|
|
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
|
|
|
|
|
}
|
|
|
|
|
ptrReg := v.Args[0].Reg()
|
|
|
|
|
countReg := v.RegTmp()
|
|
|
|
|
n := v.AuxInt
|
|
|
|
|
loopSize := int64(64)
|
|
|
|
|
if n < 3*loopSize {
|
|
|
|
|
// - a loop count of 0 won't work.
|
|
|
|
|
// - a loop count of 1 is useless.
|
|
|
|
|
// - a loop count of 2 is a code size ~tie
|
|
|
|
|
// 4 instructions to implement the loop
|
|
|
|
|
// 4 instructions in the loop body
|
|
|
|
|
// vs
|
|
|
|
|
// 8 instructions in the straightline code
|
|
|
|
|
// Might as well use straightline code.
|
|
|
|
|
v.Fatalf("ZeroLoop size too small %d", n)
|
|
|
|
|
}
|
|
|
|
|
zero16 := func(off int64) {
|
|
|
|
|
zero16(s, ptrReg, off)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Put iteration count in a register.
|
|
|
|
|
// MOVL $n, countReg
|
|
|
|
|
p := s.Prog(x86.AMOVL)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = n / loopSize
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = countReg
|
|
|
|
|
cntInit := p
|
|
|
|
|
|
|
|
|
|
// Zero loopSize bytes starting at ptrReg.
|
|
|
|
|
for i := range loopSize / 16 {
|
|
|
|
|
zero16(i * 16)
|
|
|
|
|
}
|
|
|
|
|
// ADDQ $loopSize, ptrReg
|
|
|
|
|
p = s.Prog(x86.AADDQ)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = loopSize
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = ptrReg
|
|
|
|
|
// DECL countReg
|
|
|
|
|
p = s.Prog(x86.ADECL)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = countReg
|
|
|
|
|
// Jump to first instruction in loop if we're not done yet.
|
|
|
|
|
// JNE head
|
|
|
|
|
p = s.Prog(x86.AJNE)
|
|
|
|
|
p.To.Type = obj.TYPE_BRANCH
|
|
|
|
|
p.To.SetTarget(cntInit.Link)
|
|
|
|
|
|
|
|
|
|
// Multiples of the loop size are now done.
|
|
|
|
|
n %= loopSize
|
|
|
|
|
|
|
|
|
|
// Write any fractional portion.
|
|
|
|
|
var off int64
|
|
|
|
|
for n >= 16 {
|
|
|
|
|
zero16(off)
|
|
|
|
|
off += 16
|
|
|
|
|
n -= 16
|
|
|
|
|
}
|
|
|
|
|
if n != 0 {
|
|
|
|
|
// Use partially-overlapping write.
|
|
|
|
|
// TODO: n <= 8, use smaller write?
|
|
|
|
|
zero16(off + n - 16)
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-13 09:41:17 -07:00
|
|
|
case ssa.OpAMD64LoweredMove:
|
|
|
|
|
dstReg := v.Args[0].Reg()
|
|
|
|
|
srcReg := v.Args[1].Reg()
|
|
|
|
|
if dstReg == srcReg {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
tmpReg := int16(x86.REG_X14)
|
|
|
|
|
n := v.AuxInt
|
|
|
|
|
if n < 16 {
|
|
|
|
|
v.Fatalf("Move too small %d", n)
|
|
|
|
|
}
|
|
|
|
|
// move 16 bytes from srcReg+off to dstReg+off.
|
|
|
|
|
move16 := func(off int64) {
|
|
|
|
|
move16(s, srcReg, dstReg, tmpReg, off)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Generate copying instructions.
|
|
|
|
|
var off int64
|
|
|
|
|
for n >= 16 {
|
|
|
|
|
move16(off)
|
|
|
|
|
off += 16
|
|
|
|
|
n -= 16
|
|
|
|
|
}
|
|
|
|
|
if n != 0 {
|
|
|
|
|
// use partially overlapped read/write.
|
|
|
|
|
// TODO: use smaller operations when we can?
|
|
|
|
|
move16(off + n - 16)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case ssa.OpAMD64LoweredMoveLoop:
|
|
|
|
|
dstReg := v.Args[0].Reg()
|
|
|
|
|
srcReg := v.Args[1].Reg()
|
|
|
|
|
if dstReg == srcReg {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
countReg := v.RegTmp()
|
|
|
|
|
tmpReg := int16(x86.REG_X14)
|
|
|
|
|
n := v.AuxInt
|
|
|
|
|
loopSize := int64(64)
|
|
|
|
|
if n < 3*loopSize {
|
|
|
|
|
// - a loop count of 0 won't work.
|
|
|
|
|
// - a loop count of 1 is useless.
|
|
|
|
|
// - a loop count of 2 is a code size ~tie
|
|
|
|
|
// 4 instructions to implement the loop
|
|
|
|
|
// 4 instructions in the loop body
|
|
|
|
|
// vs
|
|
|
|
|
// 8 instructions in the straightline code
|
|
|
|
|
// Might as well use straightline code.
|
|
|
|
|
v.Fatalf("ZeroLoop size too small %d", n)
|
|
|
|
|
}
|
|
|
|
|
// move 16 bytes from srcReg+off to dstReg+off.
|
|
|
|
|
move16 := func(off int64) {
|
|
|
|
|
move16(s, srcReg, dstReg, tmpReg, off)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Put iteration count in a register.
|
|
|
|
|
// MOVL $n, countReg
|
|
|
|
|
p := s.Prog(x86.AMOVL)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = n / loopSize
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = countReg
|
|
|
|
|
cntInit := p
|
|
|
|
|
|
|
|
|
|
// Copy loopSize bytes starting at srcReg to dstReg.
|
|
|
|
|
for i := range loopSize / 16 {
|
|
|
|
|
move16(i * 16)
|
|
|
|
|
}
|
|
|
|
|
// ADDQ $loopSize, srcReg
|
|
|
|
|
p = s.Prog(x86.AADDQ)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = loopSize
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = srcReg
|
|
|
|
|
// ADDQ $loopSize, dstReg
|
|
|
|
|
p = s.Prog(x86.AADDQ)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = loopSize
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = dstReg
|
|
|
|
|
// DECL countReg
|
|
|
|
|
p = s.Prog(x86.ADECL)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = countReg
|
|
|
|
|
// Jump to loop header if we're not done yet.
|
|
|
|
|
// JNE head
|
|
|
|
|
p = s.Prog(x86.AJNE)
|
|
|
|
|
p.To.Type = obj.TYPE_BRANCH
|
|
|
|
|
p.To.SetTarget(cntInit.Link)
|
|
|
|
|
|
|
|
|
|
// Multiples of the loop size are now done.
|
|
|
|
|
n %= loopSize
|
|
|
|
|
|
|
|
|
|
// Copy any fractional portion.
|
|
|
|
|
var off int64
|
|
|
|
|
for n >= 16 {
|
|
|
|
|
move16(off)
|
|
|
|
|
off += 16
|
|
|
|
|
n -= 16
|
|
|
|
|
}
|
|
|
|
|
if n != 0 {
|
|
|
|
|
// Use partially-overlapping copy.
|
|
|
|
|
move16(off + n - 16)
|
2020-04-23 13:11:00 -07:00
|
|
|
}
|
2016-03-12 14:07:40 -08:00
|
|
|
|
2017-08-24 11:31:58 -07:00
|
|
|
case ssa.OpCopy: // TODO: use MOVQreg for reg->reg copies instead of OpCopy?
|
2016-04-21 10:02:36 -07:00
|
|
|
if v.Type.IsMemory() {
|
|
|
|
|
return
|
|
|
|
|
}
|
2016-09-16 09:36:00 -07:00
|
|
|
x := v.Args[0].Reg()
|
|
|
|
|
y := v.Reg()
|
2025-03-31 10:45:23 +11:00
|
|
|
if v.Type.IsSIMD() {
|
2025-07-09 22:33:25 +00:00
|
|
|
x = simdOrMaskReg(v.Args[0])
|
|
|
|
|
y = simdOrMaskReg(v)
|
2025-03-31 10:45:23 +11:00
|
|
|
}
|
2016-03-12 14:07:40 -08:00
|
|
|
if x != y {
|
2025-08-14 20:21:37 +00:00
|
|
|
opregreg(s, moveByRegsWidth(y, x, v.Type.Size()), y, x)
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
|
|
|
|
case ssa.OpLoadReg:
|
|
|
|
|
if v.Type.IsFlags() {
|
2016-09-14 10:01:05 -07:00
|
|
|
v.Fatalf("load flags not implemented: %v", v.LongString())
|
2016-03-12 14:07:40 -08:00
|
|
|
return
|
|
|
|
|
}
|
2025-08-13 12:44:01 -04:00
|
|
|
r := v.Reg()
|
2025-08-14 20:21:37 +00:00
|
|
|
p := s.Prog(loadByRegWidth(r, v.Type.Size()))
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddrAuto(&p.From, v.Args[0])
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2025-03-31 10:45:23 +11:00
|
|
|
if v.Type.IsSIMD() {
|
2025-07-09 22:33:25 +00:00
|
|
|
r = simdOrMaskReg(v)
|
2025-03-31 10:45:23 +11:00
|
|
|
}
|
|
|
|
|
p.To.Reg = r
|
2016-03-12 14:07:40 -08:00
|
|
|
|
|
|
|
|
case ssa.OpStoreReg:
|
|
|
|
|
if v.Type.IsFlags() {
|
2016-09-14 10:01:05 -07:00
|
|
|
v.Fatalf("store flags not implemented: %v", v.LongString())
|
2016-03-12 14:07:40 -08:00
|
|
|
return
|
|
|
|
|
}
|
2025-03-31 10:45:23 +11:00
|
|
|
r := v.Args[0].Reg()
|
|
|
|
|
if v.Type.IsSIMD() {
|
2025-07-09 22:33:25 +00:00
|
|
|
r = simdOrMaskReg(v.Args[0])
|
2025-03-31 10:45:23 +11:00
|
|
|
}
|
2025-08-14 20:21:37 +00:00
|
|
|
p := s.Prog(storeByRegWidth(r, v.Type.Size()))
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
2025-03-31 10:45:23 +11:00
|
|
|
p.From.Reg = r
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddrAuto(&p.To, v)
|
2019-12-19 10:58:28 -08:00
|
|
|
case ssa.OpAMD64LoweredHasCPUFeature:
|
2022-09-11 14:47:36 +02:00
|
|
|
p := s.Prog(x86.AMOVBLZX)
|
2019-12-19 10:58:28 -08:00
|
|
|
p.From.Type = obj.TYPE_MEM
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.From, v)
|
2019-12-19 10:58:28 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
2021-02-19 17:11:40 -05:00
|
|
|
case ssa.OpArgIntReg, ssa.OpArgFloatReg:
|
|
|
|
|
// The assembler needs to wrap the entry safepoint/stack growth code with spill/unspill
|
|
|
|
|
// The loop only runs once.
|
|
|
|
|
for _, ap := range v.Block.Func.RegArgs {
|
|
|
|
|
// Pass the spill/unspill information along to the assembler, offset by size of return PC pushed on stack.
|
2021-04-16 00:15:31 -04:00
|
|
|
addr := ssagen.SpillSlotAddr(ap, x86.REG_SP, v.Block.Func.Config.PtrSize)
|
2025-09-18 23:46:41 -04:00
|
|
|
reg := ap.Reg
|
|
|
|
|
t := ap.Type
|
|
|
|
|
sz := t.Size()
|
|
|
|
|
if t.IsSIMD() {
|
|
|
|
|
reg = simdRegBySize(reg, sz)
|
|
|
|
|
}
|
2021-02-19 17:11:40 -05:00
|
|
|
s.FuncInfo().AddSpill(
|
2025-09-18 23:46:41 -04:00
|
|
|
obj.RegSpill{Reg: reg, Addr: addr, Unspill: loadByRegWidth(reg, sz), Spill: storeByRegWidth(reg, sz)})
|
2021-02-19 17:11:40 -05:00
|
|
|
}
|
|
|
|
|
v.Block.Func.RegArgs = nil
|
|
|
|
|
ssagen.CheckArgReg(v)
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64LoweredGetClosurePtr:
|
2016-07-03 13:40:03 -07:00
|
|
|
// Closure pointer is DX.
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.CheckLoweredGetClosurePtr(v)
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64LoweredGetG:
|
2021-06-09 14:29:20 -04:00
|
|
|
if s.ABI == obj.ABIInternal {
|
2021-04-01 11:11:04 -04:00
|
|
|
v.Fatalf("LoweredGetG should not appear in ABIInternal")
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
2021-02-02 18:20:16 -05:00
|
|
|
r := v.Reg()
|
|
|
|
|
getgFromTLS(s, r)
|
cmd/compile: restore tail call for method wrappers
For certain type of method wrappers we used to generate a tail
call. That was disabled in CL 307234 when register ABI is used,
because with the current IR it was difficult to generate a tail
call with the arguments in the right places. The problem was that
the IR does not contain a CALL-like node with arguments; instead,
it contains an OAS node that adjusts the receiver, than an
OTAILCALL node that just contains the target, but no argument
(with the assumption that the OAS node will put the adjusted
receiver in the right place). With register ABI, putting
arguments in registers are done in SSA. The assignment (OAS)
doesn't put the receiver in register.
This CL changes the IR of a tail call to take an actual OCALL
node. Specifically, a tail call is represented as
OTAILCALL (OCALL target args...)
This way, the call target and args are connected through the OCALL
node. So the call can be analyzed in SSA and the args can be passed
in the right places.
(Alternatively, we could have OTAILCALL node directly take the
target and the args, without the OCALL node. Using an OCALL node is
convenient as there are existing code that processes OCALL nodes
which do not need to be changed. Also, a tail call is similar to
ORETURN (OCALL target args...), except it doesn't preserve the
frame. I did the former but I'm open to change.)
The SSA representation is similar. Previously, the IR lowers to
a Store the receiver then a BlockRetJmp which jumps to the target
(without putting the arg in register). Now we use a TailCall op,
which takes the target and the args. The call expansion pass and
the register allocator handles TailCall pretty much like a
StaticCall, and it will do the right ABI analysis and put the args
in the right places. (Args other than the receiver are already in
the right places. For register args it generates no code for them.
For stack args currently it generates a self copy. I'll work on
optimize that out.) BlockRetJmp is still used, signaling it is a
tail call. The actual call is made in the TailCall op so
BlockRetJmp generates no code (we could use BlockExit if we like).
This slightly reduces binary size:
old new
cmd/go 14003088 13953936
cmd/link 6275552 6271456
Change-Id: I2d16d8d419fe1f17554916d317427383e17e27f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/350145
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
2021-09-10 22:05:55 -04:00
|
|
|
case ssa.OpAMD64CALLstatic, ssa.OpAMD64CALLtail:
|
2021-06-09 14:29:20 -04:00
|
|
|
if s.ABI == obj.ABI0 && v.Aux.(*ssa.AuxCall).Fn.ABI() == obj.ABIInternal {
|
2021-01-29 13:46:34 -05:00
|
|
|
// zeroing X15 when entering ABIInternal from ABI0
|
2025-08-21 14:37:18 -04:00
|
|
|
zeroX15(s)
|
2021-02-02 18:20:16 -05:00
|
|
|
// set G register from TLS
|
|
|
|
|
getgFromTLS(s, x86.REG_R14)
|
2021-01-29 13:46:34 -05:00
|
|
|
}
|
cmd/compile: restore tail call for method wrappers
For certain type of method wrappers we used to generate a tail
call. That was disabled in CL 307234 when register ABI is used,
because with the current IR it was difficult to generate a tail
call with the arguments in the right places. The problem was that
the IR does not contain a CALL-like node with arguments; instead,
it contains an OAS node that adjusts the receiver, than an
OTAILCALL node that just contains the target, but no argument
(with the assumption that the OAS node will put the adjusted
receiver in the right place). With register ABI, putting
arguments in registers are done in SSA. The assignment (OAS)
doesn't put the receiver in register.
This CL changes the IR of a tail call to take an actual OCALL
node. Specifically, a tail call is represented as
OTAILCALL (OCALL target args...)
This way, the call target and args are connected through the OCALL
node. So the call can be analyzed in SSA and the args can be passed
in the right places.
(Alternatively, we could have OTAILCALL node directly take the
target and the args, without the OCALL node. Using an OCALL node is
convenient as there are existing code that processes OCALL nodes
which do not need to be changed. Also, a tail call is similar to
ORETURN (OCALL target args...), except it doesn't preserve the
frame. I did the former but I'm open to change.)
The SSA representation is similar. Previously, the IR lowers to
a Store the receiver then a BlockRetJmp which jumps to the target
(without putting the arg in register). Now we use a TailCall op,
which takes the target and the args. The call expansion pass and
the register allocator handles TailCall pretty much like a
StaticCall, and it will do the right ABI analysis and put the args
in the right places. (Args other than the receiver are already in
the right places. For register args it generates no code for them.
For stack args currently it generates a self copy. I'll work on
optimize that out.) BlockRetJmp is still used, signaling it is a
tail call. The actual call is made in the TailCall op so
BlockRetJmp generates no code (we could use BlockExit if we like).
This slightly reduces binary size:
old new
cmd/go 14003088 13953936
cmd/link 6275552 6271456
Change-Id: I2d16d8d419fe1f17554916d317427383e17e27f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/350145
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
2021-09-10 22:05:55 -04:00
|
|
|
if v.Op == ssa.OpAMD64CALLtail {
|
|
|
|
|
s.TailCall(v)
|
|
|
|
|
break
|
|
|
|
|
}
|
2021-01-29 13:46:34 -05:00
|
|
|
s.Call(v)
|
2021-06-09 14:29:20 -04:00
|
|
|
if s.ABI == obj.ABIInternal && v.Aux.(*ssa.AuxCall).Fn.ABI() == obj.ABI0 {
|
2021-01-29 13:46:34 -05:00
|
|
|
// zeroing X15 when entering ABIInternal from ABI0
|
2025-08-21 14:37:18 -04:00
|
|
|
zeroX15(s)
|
2021-02-02 18:20:16 -05:00
|
|
|
// set G register from TLS
|
|
|
|
|
getgFromTLS(s, x86.REG_R14)
|
2021-01-29 13:46:34 -05:00
|
|
|
}
|
|
|
|
|
case ssa.OpAMD64CALLclosure, ssa.OpAMD64CALLinter:
|
2017-03-10 18:34:41 -08:00
|
|
|
s.Call(v)
|
2016-10-24 10:25:05 -04:00
|
|
|
|
|
|
|
|
case ssa.OpAMD64LoweredGetCallerPC:
|
|
|
|
|
p := s.Prog(x86.AMOVQ)
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Offset = -8 // PC is stored 8 bytes below first parameter.
|
|
|
|
|
p.From.Name = obj.NAME_PARAM
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
|
|
|
|
|
2017-10-09 15:33:29 -04:00
|
|
|
case ssa.OpAMD64LoweredGetCallerSP:
|
|
|
|
|
// caller's SP is the address of the first arg
|
|
|
|
|
mov := x86.AMOVQ
|
2020-12-23 00:39:45 -05:00
|
|
|
if types.PtrSize == 4 {
|
2017-10-09 15:33:29 -04:00
|
|
|
mov = x86.AMOVL
|
|
|
|
|
}
|
|
|
|
|
p := s.Prog(mov)
|
|
|
|
|
p.From.Type = obj.TYPE_ADDR
|
2022-04-18 13:41:08 -04:00
|
|
|
p.From.Offset = -base.Ctxt.Arch.FixedFrameSize // 0 on amd64, just to be consistent with other architectures
|
2017-10-09 15:33:29 -04:00
|
|
|
p.From.Name = obj.NAME_PARAM
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
|
|
|
|
|
2017-10-26 12:33:04 -04:00
|
|
|
case ssa.OpAMD64LoweredWB:
|
|
|
|
|
p := s.Prog(obj.ACALL)
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Name = obj.NAME_EXTERN
|
2022-11-01 16:46:43 -07:00
|
|
|
// AuxInt encodes how many buffer entries we need.
|
|
|
|
|
p.To.Sym = ir.Syms.GCWriteBarrier[v.AuxInt-1]
|
2017-10-26 12:33:04 -04:00
|
|
|
|
2025-06-18 15:14:00 -07:00
|
|
|
case ssa.OpAMD64LoweredPanicBoundsRR, ssa.OpAMD64LoweredPanicBoundsRC, ssa.OpAMD64LoweredPanicBoundsCR, ssa.OpAMD64LoweredPanicBoundsCC:
|
|
|
|
|
// Compute the constant we put in the PCData entry for this call.
|
|
|
|
|
code, signed := ssa.BoundsKind(v.AuxInt).Code()
|
|
|
|
|
xIsReg := false
|
|
|
|
|
yIsReg := false
|
|
|
|
|
xVal := 0
|
|
|
|
|
yVal := 0
|
|
|
|
|
switch v.Op {
|
|
|
|
|
case ssa.OpAMD64LoweredPanicBoundsRR:
|
|
|
|
|
xIsReg = true
|
|
|
|
|
xVal = int(v.Args[0].Reg() - x86.REG_AX)
|
|
|
|
|
yIsReg = true
|
|
|
|
|
yVal = int(v.Args[1].Reg() - x86.REG_AX)
|
|
|
|
|
case ssa.OpAMD64LoweredPanicBoundsRC:
|
|
|
|
|
xIsReg = true
|
|
|
|
|
xVal = int(v.Args[0].Reg() - x86.REG_AX)
|
|
|
|
|
c := v.Aux.(ssa.PanicBoundsC).C
|
|
|
|
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
|
|
|
|
yVal = int(c)
|
|
|
|
|
} else {
|
|
|
|
|
// Move constant to a register
|
|
|
|
|
yIsReg = true
|
|
|
|
|
if yVal == xVal {
|
|
|
|
|
yVal = 1
|
|
|
|
|
}
|
|
|
|
|
p := s.Prog(x86.AMOVQ)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = c
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = x86.REG_AX + int16(yVal)
|
|
|
|
|
}
|
|
|
|
|
case ssa.OpAMD64LoweredPanicBoundsCR:
|
|
|
|
|
yIsReg = true
|
2025-09-08 22:04:40 -07:00
|
|
|
yVal = int(v.Args[0].Reg() - x86.REG_AX)
|
2025-06-18 15:14:00 -07:00
|
|
|
c := v.Aux.(ssa.PanicBoundsC).C
|
|
|
|
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
|
|
|
|
xVal = int(c)
|
|
|
|
|
} else {
|
|
|
|
|
// Move constant to a register
|
|
|
|
|
xIsReg = true
|
|
|
|
|
if xVal == yVal {
|
|
|
|
|
xVal = 1
|
|
|
|
|
}
|
|
|
|
|
p := s.Prog(x86.AMOVQ)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = c
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = x86.REG_AX + int16(xVal)
|
|
|
|
|
}
|
|
|
|
|
case ssa.OpAMD64LoweredPanicBoundsCC:
|
|
|
|
|
c := v.Aux.(ssa.PanicBoundsCC).Cx
|
|
|
|
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
|
|
|
|
xVal = int(c)
|
|
|
|
|
} else {
|
|
|
|
|
// Move constant to a register
|
|
|
|
|
xIsReg = true
|
|
|
|
|
p := s.Prog(x86.AMOVQ)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = c
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = x86.REG_AX + int16(xVal)
|
|
|
|
|
}
|
|
|
|
|
c = v.Aux.(ssa.PanicBoundsCC).Cy
|
|
|
|
|
if c >= 0 && c <= abi.BoundsMaxConst {
|
|
|
|
|
yVal = int(c)
|
|
|
|
|
} else {
|
|
|
|
|
// Move constant to a register
|
|
|
|
|
yIsReg = true
|
|
|
|
|
yVal = 1
|
|
|
|
|
p := s.Prog(x86.AMOVQ)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = c
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = x86.REG_AX + int16(yVal)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
c := abi.BoundsEncode(code, signed, xIsReg, yIsReg, xVal, yVal)
|
|
|
|
|
|
|
|
|
|
p := s.Prog(obj.APCDATA)
|
|
|
|
|
p.From.SetConst(abi.PCDATA_PanicBounds)
|
|
|
|
|
p.To.SetConst(int64(c))
|
|
|
|
|
p = s.Prog(obj.ACALL)
|
2019-02-06 14:12:36 -08:00
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Name = obj.NAME_EXTERN
|
2025-06-18 15:14:00 -07:00
|
|
|
p.To.Sym = ir.Syms.PanicBounds
|
2019-02-06 14:12:36 -08:00
|
|
|
|
2016-04-22 13:09:18 -07:00
|
|
|
case ssa.OpAMD64NEGQ, ssa.OpAMD64NEGL,
|
2016-03-11 00:10:52 -05:00
|
|
|
ssa.OpAMD64BSWAPQ, ssa.OpAMD64BSWAPL,
|
2016-04-22 13:09:18 -07:00
|
|
|
ssa.OpAMD64NOTQ, ssa.OpAMD64NOTL:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
p.To.Reg = v.Reg()
|
2018-10-23 14:05:38 -07:00
|
|
|
|
|
|
|
|
case ssa.OpAMD64NEGLflags:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
p.To.Reg = v.Reg0()
|
2018-10-23 14:05:38 -07:00
|
|
|
|
2025-05-04 10:34:41 -07:00
|
|
|
case ssa.OpAMD64ADDQconstflags, ssa.OpAMD64ADDLconstflags:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = v.AuxInt
|
|
|
|
|
// Note: the inc/dec instructions do not modify
|
|
|
|
|
// the carry flag like add$1 / sub$1 do.
|
|
|
|
|
// We currently never use the CF/OF flags from
|
|
|
|
|
// these instructions, so that is ok.
|
|
|
|
|
switch {
|
|
|
|
|
case p.As == x86.AADDQ && p.From.Offset == 1:
|
|
|
|
|
p.As = x86.AINCQ
|
|
|
|
|
p.From.Type = obj.TYPE_NONE
|
|
|
|
|
case p.As == x86.AADDQ && p.From.Offset == -1:
|
|
|
|
|
p.As = x86.ADECQ
|
|
|
|
|
p.From.Type = obj.TYPE_NONE
|
|
|
|
|
case p.As == x86.AADDL && p.From.Offset == 1:
|
|
|
|
|
p.As = x86.AINCL
|
|
|
|
|
p.From.Type = obj.TYPE_NONE
|
|
|
|
|
case p.As == x86.AADDL && p.From.Offset == -1:
|
|
|
|
|
p.As = x86.ADECL
|
|
|
|
|
p.From.Type = obj.TYPE_NONE
|
|
|
|
|
}
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg0()
|
|
|
|
|
|
2020-12-07 19:15:15 +08:00
|
|
|
case ssa.OpAMD64BSFQ, ssa.OpAMD64BSRQ, ssa.OpAMD64BSFL, ssa.OpAMD64BSRL, ssa.OpAMD64SQRTSD, ssa.OpAMD64SQRTSS:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[0].Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2018-10-08 02:20:03 +00:00
|
|
|
switch v.Op {
|
|
|
|
|
case ssa.OpAMD64BSFQ, ssa.OpAMD64BSRQ:
|
|
|
|
|
p.To.Reg = v.Reg0()
|
2020-12-07 19:15:15 +08:00
|
|
|
case ssa.OpAMD64BSFL, ssa.OpAMD64BSRL, ssa.OpAMD64SQRTSD, ssa.OpAMD64SQRTSS:
|
2018-10-08 02:20:03 +00:00
|
|
|
p.To.Reg = v.Reg()
|
|
|
|
|
}
|
2025-02-02 23:42:43 +01:00
|
|
|
case ssa.OpAMD64LoweredRound32F, ssa.OpAMD64LoweredRound64F:
|
|
|
|
|
// input is already rounded
|
2017-10-05 15:45:46 -05:00
|
|
|
case ssa.OpAMD64ROUNDSD:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
val := v.AuxInt
|
2017-10-31 16:49:27 -05:00
|
|
|
// 0 means math.RoundToEven, 1 Floor, 2 Ceil, 3 Trunc
|
2020-10-30 11:55:18 +01:00
|
|
|
if val < 0 || val > 3 {
|
2017-10-05 15:45:46 -05:00
|
|
|
v.Fatalf("Invalid rounding mode")
|
|
|
|
|
}
|
|
|
|
|
p.From.Offset = val
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
2023-04-12 11:23:13 +08:00
|
|
|
p.AddRestSourceReg(v.Args[0].Reg())
|
2017-10-05 15:45:46 -05:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
2021-12-06 18:46:25 +03:00
|
|
|
case ssa.OpAMD64POPCNTQ, ssa.OpAMD64POPCNTL,
|
2022-03-30 21:44:44 +08:00
|
|
|
ssa.OpAMD64TZCNTQ, ssa.OpAMD64TZCNTL,
|
|
|
|
|
ssa.OpAMD64LZCNTQ, ssa.OpAMD64LZCNTL:
|
2017-03-16 21:33:03 -07:00
|
|
|
if v.Args[0].Reg() != v.Reg() {
|
2021-12-06 18:46:25 +03:00
|
|
|
// POPCNT/TZCNT/LZCNT have a false dependency on the destination register on Intel cpus.
|
|
|
|
|
// TZCNT/LZCNT problem affects pre-Skylake models. See discussion at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62011#c7.
|
2017-12-07 10:56:45 -06:00
|
|
|
// Xor register with itself to break the dependency.
|
2021-12-06 11:46:57 +03:00
|
|
|
opregreg(s, x86.AXORL, v.Reg(), v.Reg())
|
2017-03-16 21:33:03 -07:00
|
|
|
}
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
2017-10-03 14:12:00 -05:00
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64SETEQ, ssa.OpAMD64SETNE,
|
|
|
|
|
ssa.OpAMD64SETL, ssa.OpAMD64SETLE,
|
|
|
|
|
ssa.OpAMD64SETG, ssa.OpAMD64SETGE,
|
|
|
|
|
ssa.OpAMD64SETGF, ssa.OpAMD64SETGEF,
|
|
|
|
|
ssa.OpAMD64SETB, ssa.OpAMD64SETBE,
|
|
|
|
|
ssa.OpAMD64SETORD, ssa.OpAMD64SETNAN,
|
2018-01-27 11:55:34 +01:00
|
|
|
ssa.OpAMD64SETA, ssa.OpAMD64SETAE,
|
|
|
|
|
ssa.OpAMD64SETO:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Reg()
|
2016-03-12 14:07:40 -08:00
|
|
|
|
2018-05-08 09:11:00 -07:00
|
|
|
case ssa.OpAMD64SETEQstore, ssa.OpAMD64SETNEstore,
|
|
|
|
|
ssa.OpAMD64SETLstore, ssa.OpAMD64SETLEstore,
|
|
|
|
|
ssa.OpAMD64SETGstore, ssa.OpAMD64SETGEstore,
|
|
|
|
|
ssa.OpAMD64SETBstore, ssa.OpAMD64SETBEstore,
|
|
|
|
|
ssa.OpAMD64SETAstore, ssa.OpAMD64SETAEstore:
|
2017-10-03 14:12:00 -05:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = v.Args[0].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.To, v)
|
2017-10-03 14:12:00 -05:00
|
|
|
|
2023-07-17 10:21:07 -07:00
|
|
|
case ssa.OpAMD64SETEQstoreidx1, ssa.OpAMD64SETNEstoreidx1,
|
|
|
|
|
ssa.OpAMD64SETLstoreidx1, ssa.OpAMD64SETLEstoreidx1,
|
|
|
|
|
ssa.OpAMD64SETGstoreidx1, ssa.OpAMD64SETGEstoreidx1,
|
|
|
|
|
ssa.OpAMD64SETBstoreidx1, ssa.OpAMD64SETBEstoreidx1,
|
|
|
|
|
ssa.OpAMD64SETAstoreidx1, ssa.OpAMD64SETAEstoreidx1:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
memIdx(&p.To, v)
|
|
|
|
|
ssagen.AddAux(&p.To, v)
|
|
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64SETNEF:
|
2022-04-05 15:07:29 -07:00
|
|
|
t := v.RegTmp()
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Reg()
|
2017-03-20 08:01:28 -07:00
|
|
|
q := s.Prog(x86.ASETPS)
|
2016-03-12 14:07:40 -08:00
|
|
|
q.To.Type = obj.TYPE_REG
|
2022-04-05 15:07:29 -07:00
|
|
|
q.To.Reg = t
|
2016-03-12 14:07:40 -08:00
|
|
|
// ORL avoids partial register write and is smaller than ORQ, used by old compiler
|
2022-04-05 15:07:29 -07:00
|
|
|
opregreg(s, x86.AORL, v.Reg(), t)
|
2016-03-12 14:07:40 -08:00
|
|
|
|
|
|
|
|
case ssa.OpAMD64SETEQF:
|
2022-04-05 15:07:29 -07:00
|
|
|
t := v.RegTmp()
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Reg()
|
2017-03-20 08:01:28 -07:00
|
|
|
q := s.Prog(x86.ASETPC)
|
2016-03-12 14:07:40 -08:00
|
|
|
q.To.Type = obj.TYPE_REG
|
2022-04-05 15:07:29 -07:00
|
|
|
q.To.Reg = t
|
2016-03-12 14:07:40 -08:00
|
|
|
// ANDL avoids partial register write and is smaller than ANDQ, used by old compiler
|
2022-04-05 15:07:29 -07:00
|
|
|
opregreg(s, x86.AANDL, v.Reg(), t)
|
2016-03-12 14:07:40 -08:00
|
|
|
|
|
|
|
|
case ssa.OpAMD64InvertFlags:
|
2016-03-11 00:10:52 -05:00
|
|
|
v.Fatalf("InvertFlags should never make it to codegen %v", v.LongString())
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64FlagEQ, ssa.OpAMD64FlagLT_ULT, ssa.OpAMD64FlagLT_UGT, ssa.OpAMD64FlagGT_ULT, ssa.OpAMD64FlagGT_UGT:
|
2016-03-11 00:10:52 -05:00
|
|
|
v.Fatalf("Flag* ops should never make it to codegen %v", v.LongString())
|
2016-08-28 11:17:37 -07:00
|
|
|
case ssa.OpAMD64AddTupleFirst32, ssa.OpAMD64AddTupleFirst64:
|
|
|
|
|
v.Fatalf("AddTupleFirst* should never make it to codegen %v", v.LongString())
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64REPSTOSQ:
|
2017-03-20 08:01:28 -07:00
|
|
|
s.Prog(x86.AREP)
|
|
|
|
|
s.Prog(x86.ASTOSQ)
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64REPMOVSQ:
|
2017-03-20 08:01:28 -07:00
|
|
|
s.Prog(x86.AREP)
|
|
|
|
|
s.Prog(x86.AMOVSQ)
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.OpAMD64LoweredNilCheck:
|
|
|
|
|
// Issue a load which will fault if the input is nil.
|
|
|
|
|
// TODO: We currently use the 2-byte instruction TESTB AX, (reg).
|
2017-08-19 22:33:51 +02:00
|
|
|
// Should we use the 3-byte TESTB $0, (reg) instead? It is larger
|
2016-03-12 14:07:40 -08:00
|
|
|
// but it doesn't have false dependency on AX.
|
|
|
|
|
// Or maybe allocate an output register and use MOVL (reg),reg2 ?
|
|
|
|
|
// That trades clobbering flags for clobbering a register.
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(x86.ATESTB)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = x86.REG_AX
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Args[0].Reg()
|
cmd/compile: add framework for logging optimizer (non)actions to LSP
This is intended to allow IDEs to note where the optimizer
was not able to improve users' code. There may be other
applications for this, for example in studying effectiveness
of optimizer changes more quickly than running benchmarks,
or in verifying that code changes did not accidentally disable
optimizations in performance-critical code.
Logging of nilcheck (bad) for amd64 is implemented as
proof-of-concept. In general, the intent is that optimizations
that didn't happen are what will be logged, because that is
believed to be what IDE users want.
Added flag -json=version,dest
Check that version=0. (Future compilers will support a
few recent versions, I hope that version is always <=3.)
Dest is expected to be one of:
/path (or \path in Windows)
will create directory /path and fill it w/ json files
file://path
will create directory path, intended either for
I:\dont\know\enough\about\windows\paths
trustme_I_know_what_I_am_doing_probably_testing
Not passing an absolute path name usually leads to
json splattered all over source directories,
or failure when those directories are not writeable.
If you want a foot-gun, you have to ask for it.
The JSON output is directed to subdirectories of dest,
where each subdirectory is net/url.PathEscape of the
package name, and each for each foo.go in the package,
net/url.PathEscape(foo).json is created. The first line
of foo.json contains version and context information,
and subsequent lines contains LSP-conforming JSON
describing the missing optimizations.
Change-Id: Ib83176a53a8c177ee9081aefc5ae05604ccad8a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/204338
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-10-24 13:48:17 -04:00
|
|
|
if logopt.Enabled() {
|
|
|
|
|
logopt.LogOpt(v.Pos, "nilcheck", "genssa", v.Block.Func.Name)
|
|
|
|
|
}
|
2020-11-19 20:49:23 -05:00
|
|
|
if base.Debug.Nil != 0 && v.Pos.Line() > 1 { // v.Pos.Line()==1 in generated wrappers
|
|
|
|
|
base.WarnfAt(v.Pos, "generated nil check")
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
2019-03-28 14:58:06 -04:00
|
|
|
case ssa.OpAMD64MOVBatomicload, ssa.OpAMD64MOVLatomicload, ssa.OpAMD64MOVQatomicload:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-08-23 16:49:28 -07:00
|
|
|
p.From.Type = obj.TYPE_MEM
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[0].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.From, v)
|
2016-08-23 16:49:28 -07:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Reg0()
|
2019-10-23 10:20:49 -04:00
|
|
|
case ssa.OpAMD64XCHGB, ssa.OpAMD64XCHGL, ssa.OpAMD64XCHGQ:
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-08-23 16:49:28 -07:00
|
|
|
p.From.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
p.From.Reg = v.Reg0()
|
2016-08-23 16:49:28 -07:00
|
|
|
p.To.Type = obj.TYPE_MEM
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Args[1].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.To, v)
|
2016-08-25 16:02:57 -07:00
|
|
|
case ssa.OpAMD64XADDLlock, ssa.OpAMD64XADDQlock:
|
2017-03-20 08:01:28 -07:00
|
|
|
s.Prog(x86.ALOCK)
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-08-25 16:02:57 -07:00
|
|
|
p.From.Type = obj.TYPE_REG
|
2021-01-07 19:08:37 -08:00
|
|
|
p.From.Reg = v.Reg0()
|
2016-08-25 16:02:57 -07:00
|
|
|
p.To.Type = obj.TYPE_MEM
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Args[1].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.To, v)
|
2016-08-25 16:02:57 -07:00
|
|
|
case ssa.OpAMD64CMPXCHGLlock, ssa.OpAMD64CMPXCHGQlock:
|
2016-09-16 09:36:00 -07:00
|
|
|
if v.Args[1].Reg() != x86.REG_AX {
|
2016-08-25 16:02:57 -07:00
|
|
|
v.Fatalf("input[1] not in AX %s", v.LongString())
|
|
|
|
|
}
|
2017-03-20 08:01:28 -07:00
|
|
|
s.Prog(x86.ALOCK)
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-08-25 16:02:57 -07:00
|
|
|
p.From.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[2].Reg()
|
2016-08-25 16:02:57 -07:00
|
|
|
p.To.Type = obj.TYPE_MEM
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Args[0].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.To, v)
|
2017-03-20 08:01:28 -07:00
|
|
|
p = s.Prog(x86.ASETEQ)
|
2016-08-25 16:02:57 -07:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Reg0()
|
2024-06-25 14:56:11 -07:00
|
|
|
case ssa.OpAMD64ANDBlock, ssa.OpAMD64ANDLlock, ssa.OpAMD64ANDQlock, ssa.OpAMD64ORBlock, ssa.OpAMD64ORLlock, ssa.OpAMD64ORQlock:
|
|
|
|
|
// Atomic memory operations that don't need to return the old value.
|
2017-03-20 08:01:28 -07:00
|
|
|
s.Prog(x86.ALOCK)
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
2016-08-25 16:02:57 -07:00
|
|
|
p.From.Type = obj.TYPE_REG
|
2016-09-16 09:36:00 -07:00
|
|
|
p.From.Reg = v.Args[1].Reg()
|
2016-08-25 16:02:57 -07:00
|
|
|
p.To.Type = obj.TYPE_MEM
|
2016-09-16 09:36:00 -07:00
|
|
|
p.To.Reg = v.Args[0].Reg()
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.To, v)
|
2024-06-25 14:56:11 -07:00
|
|
|
case ssa.OpAMD64LoweredAtomicAnd64, ssa.OpAMD64LoweredAtomicOr64, ssa.OpAMD64LoweredAtomicAnd32, ssa.OpAMD64LoweredAtomicOr32:
|
|
|
|
|
// Atomic memory operations that need to return the old value.
|
|
|
|
|
// We need to do these with compare-and-exchange to get access to the old value.
|
|
|
|
|
// loop:
|
|
|
|
|
// MOVQ mask, tmp
|
|
|
|
|
// MOVQ (addr), AX
|
|
|
|
|
// ANDQ AX, tmp
|
|
|
|
|
// LOCK CMPXCHGQ tmp, (addr) : note that AX is implicit old value to compare against
|
|
|
|
|
// JNE loop
|
|
|
|
|
// : result in AX
|
|
|
|
|
mov := x86.AMOVQ
|
|
|
|
|
op := x86.AANDQ
|
|
|
|
|
cmpxchg := x86.ACMPXCHGQ
|
|
|
|
|
switch v.Op {
|
|
|
|
|
case ssa.OpAMD64LoweredAtomicOr64:
|
|
|
|
|
op = x86.AORQ
|
|
|
|
|
case ssa.OpAMD64LoweredAtomicAnd32:
|
|
|
|
|
mov = x86.AMOVL
|
|
|
|
|
op = x86.AANDL
|
|
|
|
|
cmpxchg = x86.ACMPXCHGL
|
|
|
|
|
case ssa.OpAMD64LoweredAtomicOr32:
|
|
|
|
|
mov = x86.AMOVL
|
|
|
|
|
op = x86.AORL
|
|
|
|
|
cmpxchg = x86.ACMPXCHGL
|
|
|
|
|
}
|
|
|
|
|
addr := v.Args[0].Reg()
|
|
|
|
|
mask := v.Args[1].Reg()
|
|
|
|
|
tmp := v.RegTmp()
|
|
|
|
|
p1 := s.Prog(mov)
|
|
|
|
|
p1.From.Type = obj.TYPE_REG
|
|
|
|
|
p1.From.Reg = mask
|
|
|
|
|
p1.To.Type = obj.TYPE_REG
|
|
|
|
|
p1.To.Reg = tmp
|
|
|
|
|
p2 := s.Prog(mov)
|
|
|
|
|
p2.From.Type = obj.TYPE_MEM
|
|
|
|
|
p2.From.Reg = addr
|
|
|
|
|
ssagen.AddAux(&p2.From, v)
|
|
|
|
|
p2.To.Type = obj.TYPE_REG
|
|
|
|
|
p2.To.Reg = x86.REG_AX
|
|
|
|
|
p3 := s.Prog(op)
|
|
|
|
|
p3.From.Type = obj.TYPE_REG
|
|
|
|
|
p3.From.Reg = x86.REG_AX
|
|
|
|
|
p3.To.Type = obj.TYPE_REG
|
|
|
|
|
p3.To.Reg = tmp
|
|
|
|
|
s.Prog(x86.ALOCK)
|
|
|
|
|
p5 := s.Prog(cmpxchg)
|
|
|
|
|
p5.From.Type = obj.TYPE_REG
|
|
|
|
|
p5.From.Reg = tmp
|
|
|
|
|
p5.To.Type = obj.TYPE_MEM
|
|
|
|
|
p5.To.Reg = addr
|
|
|
|
|
ssagen.AddAux(&p5.To, v)
|
|
|
|
|
p6 := s.Prog(x86.AJNE)
|
|
|
|
|
p6.To.Type = obj.TYPE_BRANCH
|
|
|
|
|
p6.To.SetTarget(p1)
|
2021-06-15 14:04:30 +00:00
|
|
|
case ssa.OpAMD64PrefetchT0, ssa.OpAMD64PrefetchNTA:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
2016-06-08 22:02:08 -07:00
|
|
|
case ssa.OpClobber:
|
|
|
|
|
p := s.Prog(x86.AMOVL)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = 0xdeaddead
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = x86.REG_SP
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.To, v)
|
2016-06-08 22:02:08 -07:00
|
|
|
p = s.Prog(x86.AMOVL)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = 0xdeaddead
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = x86.REG_SP
|
2020-12-23 00:57:10 -05:00
|
|
|
ssagen.AddAux(&p.To, v)
|
2016-06-08 22:02:08 -07:00
|
|
|
p.To.Offset += 4
|
2021-03-17 19:15:38 -04:00
|
|
|
case ssa.OpClobberReg:
|
|
|
|
|
x := uint64(0xdeaddeaddeaddead)
|
|
|
|
|
p := s.Prog(x86.AMOVQ)
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = int64(x)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
2025-03-31 10:45:23 +11:00
|
|
|
|
2025-08-22 11:25:07 -04:00
|
|
|
// SIMD ops
|
2025-07-09 19:06:13 +00:00
|
|
|
case ssa.OpAMD64VZEROUPPER, ssa.OpAMD64VZEROALL:
|
|
|
|
|
s.Prog(v.Op.Asm())
|
2025-08-14 17:31:09 -04:00
|
|
|
|
|
|
|
|
case ssa.OpAMD64Zero128, ssa.OpAMD64Zero256, ssa.OpAMD64Zero512: // no code emitted
|
|
|
|
|
|
|
|
|
|
case ssa.OpAMD64VMOVSSf2v, ssa.OpAMD64VMOVSDf2v:
|
|
|
|
|
// These are for initializing the least 32/64 bits of a SIMD register from a "float".
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
p.AddRestSourceReg(x86.REG_X15)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
|
2025-08-21 17:07:13 -04:00
|
|
|
case ssa.OpAMD64VMOVQload, ssa.OpAMD64VMOVDload,
|
|
|
|
|
ssa.OpAMD64VMOVSSload, ssa.OpAMD64VMOVSDload:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
ssagen.AddAux(&p.From, v)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
|
|
|
|
|
case ssa.OpAMD64VMOVSSconst, ssa.OpAMD64VMOVSDconst:
|
|
|
|
|
// for loading constants directly into SIMD registers
|
|
|
|
|
x := simdReg(v)
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_FCONST
|
|
|
|
|
p.From.Val = math.Float64frombits(uint64(v.AuxInt))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = x
|
|
|
|
|
|
2025-08-14 17:31:09 -04:00
|
|
|
case ssa.OpAMD64VMOVD, ssa.OpAMD64VMOVQ:
|
|
|
|
|
// These are for initializing the least 32/64 bits of a SIMD register from an "int".
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
|
2025-10-10 19:10:31 +00:00
|
|
|
case ssa.OpAMD64VMOVDQUload128, ssa.OpAMD64VMOVDQUload256, ssa.OpAMD64VMOVDQUload512,
|
|
|
|
|
ssa.OpAMD64KMOVBload, ssa.OpAMD64KMOVWload, ssa.OpAMD64KMOVDload, ssa.OpAMD64KMOVQload:
|
2025-03-31 10:45:23 +11:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
ssagen.AddAux(&p.From, v)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
2025-07-18 04:26:59 +00:00
|
|
|
p.To.Reg = simdOrMaskReg(v)
|
2025-10-10 19:10:31 +00:00
|
|
|
case ssa.OpAMD64VMOVDQUstore128, ssa.OpAMD64VMOVDQUstore256, ssa.OpAMD64VMOVDQUstore512,
|
|
|
|
|
ssa.OpAMD64KMOVBstore, ssa.OpAMD64KMOVWstore, ssa.OpAMD64KMOVDstore, ssa.OpAMD64KMOVQstore:
|
2025-03-31 10:45:23 +11:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
2025-07-23 07:37:14 +00:00
|
|
|
p.From.Reg = simdOrMaskReg(v.Args[1])
|
2025-03-31 10:45:23 +11:00
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = v.Args[0].Reg()
|
|
|
|
|
ssagen.AddAux(&p.To, v)
|
|
|
|
|
|
2025-07-16 13:29:14 -04:00
|
|
|
case ssa.OpAMD64VPMASK32load128, ssa.OpAMD64VPMASK64load128, ssa.OpAMD64VPMASK32load256, ssa.OpAMD64VPMASK64load256:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
ssagen.AddAux(&p.From, v)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1])) // masking simd reg
|
|
|
|
|
|
|
|
|
|
case ssa.OpAMD64VPMASK32store128, ssa.OpAMD64VPMASK64store128, ssa.OpAMD64VPMASK32store256, ssa.OpAMD64VPMASK64store256:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[2])
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = v.Args[0].Reg()
|
|
|
|
|
ssagen.AddAux(&p.To, v)
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1])) // masking simd reg
|
|
|
|
|
|
2025-07-23 21:04:38 -04:00
|
|
|
case ssa.OpAMD64VPMASK64load512, ssa.OpAMD64VPMASK32load512, ssa.OpAMD64VPMASK16load512, ssa.OpAMD64VPMASK8load512:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
ssagen.AddAux(&p.From, v)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
p.AddRestSourceReg(v.Args[1].Reg()) // simd mask reg
|
|
|
|
|
x86.ParseSuffix(p, "Z") // must be zero if not in mask
|
|
|
|
|
|
|
|
|
|
case ssa.OpAMD64VPMASK64store512, ssa.OpAMD64VPMASK32store512, ssa.OpAMD64VPMASK16store512, ssa.OpAMD64VPMASK8store512:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[2])
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = v.Args[0].Reg()
|
|
|
|
|
ssagen.AddAux(&p.To, v)
|
|
|
|
|
p.AddRestSourceReg(v.Args[1].Reg()) // simd mask reg
|
|
|
|
|
|
2025-03-31 10:45:23 +11:00
|
|
|
case ssa.OpAMD64VPMOVMToVec8x16,
|
|
|
|
|
ssa.OpAMD64VPMOVMToVec8x32,
|
|
|
|
|
ssa.OpAMD64VPMOVMToVec8x64,
|
|
|
|
|
ssa.OpAMD64VPMOVMToVec16x8,
|
|
|
|
|
ssa.OpAMD64VPMOVMToVec16x16,
|
|
|
|
|
ssa.OpAMD64VPMOVMToVec16x32,
|
|
|
|
|
ssa.OpAMD64VPMOVMToVec32x4,
|
|
|
|
|
ssa.OpAMD64VPMOVMToVec32x8,
|
|
|
|
|
ssa.OpAMD64VPMOVMToVec32x16,
|
|
|
|
|
ssa.OpAMD64VPMOVMToVec64x2,
|
|
|
|
|
ssa.OpAMD64VPMOVMToVec64x4,
|
|
|
|
|
ssa.OpAMD64VPMOVMToVec64x8:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
|
|
|
|
|
case ssa.OpAMD64VPMOVVec8x16ToM,
|
|
|
|
|
ssa.OpAMD64VPMOVVec8x32ToM,
|
|
|
|
|
ssa.OpAMD64VPMOVVec8x64ToM,
|
|
|
|
|
ssa.OpAMD64VPMOVVec16x8ToM,
|
|
|
|
|
ssa.OpAMD64VPMOVVec16x16ToM,
|
|
|
|
|
ssa.OpAMD64VPMOVVec16x32ToM,
|
|
|
|
|
ssa.OpAMD64VPMOVVec32x4ToM,
|
|
|
|
|
ssa.OpAMD64VPMOVVec32x8ToM,
|
|
|
|
|
ssa.OpAMD64VPMOVVec32x16ToM,
|
|
|
|
|
ssa.OpAMD64VPMOVVec64x2ToM,
|
|
|
|
|
ssa.OpAMD64VPMOVVec64x4ToM,
|
|
|
|
|
ssa.OpAMD64VPMOVVec64x8ToM:
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[0])
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
|
|
|
|
|
2025-08-06 19:03:52 +00:00
|
|
|
case ssa.OpAMD64KMOVQk, ssa.OpAMD64KMOVDk, ssa.OpAMD64KMOVWk, ssa.OpAMD64KMOVBk,
|
|
|
|
|
ssa.OpAMD64KMOVQi, ssa.OpAMD64KMOVDi, ssa.OpAMD64KMOVWi, ssa.OpAMD64KMOVBi:
|
2025-07-23 13:47:08 -04:00
|
|
|
// See also ssa.OpAMD64KMOVQload
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
2025-09-09 16:29:38 +00:00
|
|
|
case ssa.OpAMD64VPTEST:
|
|
|
|
|
// Some instructions setting flags put their second operand into the destination reg.
|
|
|
|
|
// See also CMP[BWDQ].
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[0])
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v.Args[1])
|
2025-07-23 13:47:08 -04:00
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
default:
|
2025-03-31 10:45:23 +11:00
|
|
|
if !ssaGenSIMDValue(s, v) {
|
|
|
|
|
v.Fatalf("genValue not implemented: %s", v.LongString())
|
|
|
|
|
}
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-21 14:37:18 -04:00
|
|
|
// zeroX15 zeroes the X15 register.
|
|
|
|
|
func zeroX15(s *ssagen.State) {
|
|
|
|
|
vxorps := func(s *ssagen.State) {
|
|
|
|
|
p := s.Prog(x86.AVXORPS)
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = x86.REG_X15
|
|
|
|
|
p.AddRestSourceReg(x86.REG_X15)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = x86.REG_X15
|
|
|
|
|
}
|
|
|
|
|
if buildcfg.GOAMD64 >= 3 {
|
|
|
|
|
vxorps(s)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// AVX may not be available, check before zeroing the high bits.
|
|
|
|
|
p := s.Prog(x86.ACMPB)
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Name = obj.NAME_EXTERN
|
|
|
|
|
p.From.Sym = ir.Syms.X86HasAVX
|
|
|
|
|
p.To.Type = obj.TYPE_CONST
|
|
|
|
|
p.To.Offset = 1
|
|
|
|
|
jmp := s.Prog(x86.AJNE)
|
|
|
|
|
jmp.To.Type = obj.TYPE_BRANCH
|
|
|
|
|
vxorps(s)
|
|
|
|
|
sse := opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
|
|
|
|
|
jmp.To.SetTarget(sse)
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-11 17:32:00 +00:00
|
|
|
// Example instruction: VRSQRTPS X1, X1
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV11(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-03-31 10:45:23 +11:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[0])
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
2025-06-11 17:32:00 +00:00
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VPSUBD X1, X2, X3
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV21(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-11 17:32:00 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
// Vector registers operands follows a right-to-left order.
|
|
|
|
|
// e.g. VPSUBD X1, X2, X3 means X3 = X2 - X1.
|
|
|
|
|
p.From.Reg = simdReg(v.Args[1])
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-24 03:59:30 +00:00
|
|
|
// This function is to accustomize the shifts.
|
|
|
|
|
// The 2nd arg is an XMM, and this function merely checks that.
|
|
|
|
|
// Example instruction: VPSLLQ Z1, X1, Z2
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdVfpv(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-24 03:59:30 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
// Vector registers operands follows a right-to-left order.
|
|
|
|
|
// e.g. VPSUBD X1, X2, X3 means X3 = X2 - X1.
|
|
|
|
|
p.From.Reg = v.Args[1].Reg()
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-11 17:32:00 +00:00
|
|
|
// Example instruction: VPCMPEQW Z26, Z30, K4
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV2k(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[1])
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = maskReg(v)
|
|
|
|
|
return p
|
2025-03-31 10:45:23 +11:00
|
|
|
}
|
|
|
|
|
|
2025-06-11 17:32:00 +00:00
|
|
|
// Example instruction: VPMINUQ X21, X3, K3, X31
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV2kv(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-11 17:32:00 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[1])
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
// These "simd*" series of functions assumes:
|
|
|
|
|
// Any "K" register that serves as the write-mask
|
|
|
|
|
// or "predicate" for "predicated AVX512 instructions"
|
|
|
|
|
// sits right at the end of the operand list.
|
|
|
|
|
// TODO: verify this assumption.
|
2025-07-08 20:12:24 +00:00
|
|
|
p.AddRestSourceReg(maskReg(v.Args[2]))
|
2025-06-11 17:32:00 +00:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-05 19:25:00 +00:00
|
|
|
// Example instruction: VPABSB X1, X2, K3 (masking merging)
|
|
|
|
|
func simdV2kvResultInArg0(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[1])
|
|
|
|
|
// These "simd*" series of functions assumes:
|
|
|
|
|
// Any "K" register that serves as the write-mask
|
|
|
|
|
// or "predicate" for "predicated AVX512 instructions"
|
|
|
|
|
// sits right at the end of the operand list.
|
|
|
|
|
// TODO: verify this assumption.
|
|
|
|
|
p.AddRestSourceReg(maskReg(v.Args[2]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-24 03:59:30 +00:00
|
|
|
// This function is to accustomize the shifts.
|
|
|
|
|
// The 2nd arg is an XMM, and this function merely checks that.
|
|
|
|
|
// Example instruction: VPSLLQ Z1, X1, K1, Z2
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdVfpkv(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-24 03:59:30 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = v.Args[1].Reg()
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
2025-07-08 20:12:24 +00:00
|
|
|
p.AddRestSourceReg(maskReg(v.Args[2]))
|
2025-06-24 03:59:30 +00:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-11 17:32:00 +00:00
|
|
|
// Example instruction: VPCMPEQW Z26, Z30, K1, K4
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV2kk(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[1])
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.AddRestSourceReg(maskReg(v.Args[2]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = maskReg(v)
|
|
|
|
|
return p
|
2025-06-11 17:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VPOPCNTB X14, K4, X16
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdVkv(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-03-31 10:45:23 +11:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[0])
|
2025-07-08 20:12:24 +00:00
|
|
|
p.AddRestSourceReg(maskReg(v.Args[1]))
|
2025-03-31 10:45:23 +11:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
2025-06-11 17:32:00 +00:00
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VROUNDPD $7, X2, X2
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV11Imm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-11 17:32:00 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2025-08-08 17:31:45 +00:00
|
|
|
p.From.Offset = int64(v.AuxUInt8())
|
2025-06-11 17:32:00 +00:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VREDUCEPD $126, X1, K3, X31
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdVkvImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-11 17:32:00 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2025-08-08 17:31:45 +00:00
|
|
|
p.From.Offset = int64(v.AuxUInt8())
|
2025-06-11 17:32:00 +00:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
2025-07-08 20:12:24 +00:00
|
|
|
p.AddRestSourceReg(maskReg(v.Args[1]))
|
2025-06-11 17:32:00 +00:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
2025-03-31 10:45:23 +11:00
|
|
|
}
|
|
|
|
|
|
2025-06-11 17:32:00 +00:00
|
|
|
// Example instruction: VCMPPS $7, X2, X9, X2
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV21Imm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-03-31 10:45:23 +11:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2025-08-08 17:31:45 +00:00
|
|
|
p.From.Offset = int64(v.AuxUInt8())
|
2025-03-31 10:45:23 +11:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
2025-06-11 17:32:00 +00:00
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
2025-03-31 10:45:23 +11:00
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
2025-06-11 17:32:00 +00:00
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-20 15:18:03 -04:00
|
|
|
// Example instruction: VPINSRB $3, DX, X0, X0
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdVgpvImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-20 15:18:03 -04:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2025-08-08 17:31:45 +00:00
|
|
|
p.From.Offset = int64(v.AuxUInt8())
|
2025-06-20 15:18:03 -04:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.AddRestSourceReg(v.Args[1].Reg())
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-11 17:32:00 +00:00
|
|
|
// Example instruction: VPCMPD $1, Z1, Z2, K1
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV2kImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
2025-08-08 17:31:45 +00:00
|
|
|
p.From.Offset = int64(v.AuxUInt8())
|
2025-07-08 20:12:24 +00:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = maskReg(v)
|
|
|
|
|
return p
|
2025-03-31 10:45:23 +11:00
|
|
|
}
|
|
|
|
|
|
2025-06-11 17:32:00 +00:00
|
|
|
// Example instruction: VPCMPD $1, Z1, Z2, K2, K1
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV2kkImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-03-31 10:45:23 +11:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2025-08-08 17:31:45 +00:00
|
|
|
p.From.Offset = int64(v.AuxUInt8())
|
2025-03-31 10:45:23 +11:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
2025-06-11 17:32:00 +00:00
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
2025-07-08 20:12:24 +00:00
|
|
|
p.AddRestSourceReg(maskReg(v.Args[2]))
|
2025-06-11 17:32:00 +00:00
|
|
|
p.To.Type = obj.TYPE_REG
|
2025-07-08 20:12:24 +00:00
|
|
|
p.To.Reg = maskReg(v)
|
2025-06-11 17:32:00 +00:00
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV2kvImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-08-08 17:31:45 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Offset = int64(v.AuxUInt8())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.AddRestSourceReg(maskReg(v.Args[2]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
2025-06-24 03:59:30 +00:00
|
|
|
}
|
|
|
|
|
|
2025-06-11 17:32:00 +00:00
|
|
|
// Example instruction: VFMADD213PD Z2, Z1, Z0
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV31ResultInArg0(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-11 17:32:00 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[2])
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 14:44:59 -04:00
|
|
|
func simdV31ResultInArg0Imm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Offset = int64(v.AuxUInt8())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[2]))
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
|
|
|
|
// p.AddRestSourceReg(x86.REG_K0)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v31loadResultInArg0Imm8
|
|
|
|
|
// Example instruction:
|
|
|
|
|
// for (VPTERNLOGD128load {sym} [makeValAndOff(int32(int8(c)),off)] x y ptr mem)
|
|
|
|
|
func simdV31loadResultInArg0Imm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
sc := v.AuxValAndOff()
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = sc.Val64()
|
|
|
|
|
|
|
|
|
|
m := obj.Addr{Type: obj.TYPE_MEM, Reg: v.Args[2].Reg()}
|
|
|
|
|
ssagen.AddAux2(&m, v, sc.Off64())
|
|
|
|
|
p.AddRestSource(m)
|
|
|
|
|
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-11 17:32:00 +00:00
|
|
|
// Example instruction: VFMADD213PD Z2, Z1, K1, Z0
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV3kvResultInArg0(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-11 17:32:00 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[2])
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
2025-07-08 20:12:24 +00:00
|
|
|
p.AddRestSourceReg(maskReg(v.Args[3]))
|
2025-06-11 17:32:00 +00:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdVgpImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-24 16:26:47 -04:00
|
|
|
p := s.Prog(v.Op.Asm())
|
2025-08-08 17:31:45 +00:00
|
|
|
p.From.Offset = int64(v.AuxUInt8())
|
2025-06-24 16:26:47 -04:00
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = v.Reg()
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-11 17:32:00 +00:00
|
|
|
// Currently unused
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV31(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-11 17:32:00 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[2])
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
2025-03-31 10:45:23 +11:00
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
2025-06-11 17:32:00 +00:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Currently unused
|
2025-07-08 20:12:24 +00:00
|
|
|
func simdV3kv(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
2025-06-11 17:32:00 +00:00
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[2])
|
2025-03-31 10:45:23 +11:00
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
2025-06-11 17:32:00 +00:00
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
2025-07-08 20:12:24 +00:00
|
|
|
p.AddRestSourceReg(maskReg(v.Args[3]))
|
2025-03-31 10:45:23 +11:00
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
2025-06-11 17:32:00 +00:00
|
|
|
return p
|
2025-03-31 10:45:23 +11:00
|
|
|
}
|
|
|
|
|
|
2025-09-04 18:20:59 +00:00
|
|
|
// Example instruction: VRCP14PS (DI), K6, X22
|
|
|
|
|
func simdVkvload(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
ssagen.AddAux(&p.From, v)
|
|
|
|
|
p.AddRestSourceReg(maskReg(v.Args[1]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VPSLLVD (DX), X7, X18
|
|
|
|
|
func simdV21load(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[1].Reg()
|
|
|
|
|
ssagen.AddAux(&p.From, v)
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VPDPWSSD (SI), X24, X18
|
|
|
|
|
func simdV31loadResultInArg0(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[2].Reg()
|
|
|
|
|
ssagen.AddAux(&p.From, v)
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VPDPWSSD (SI), X24, K1, X18
|
|
|
|
|
func simdV3kvloadResultInArg0(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[2].Reg()
|
|
|
|
|
ssagen.AddAux(&p.From, v)
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
|
|
|
|
p.AddRestSourceReg(maskReg(v.Args[3]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VPSLLVD (SI), X1, K1, X2
|
|
|
|
|
func simdV2kvload(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[1].Reg()
|
|
|
|
|
ssagen.AddAux(&p.From, v)
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.AddRestSourceReg(maskReg(v.Args[2]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VPCMPEQD (SI), X1, K1
|
|
|
|
|
func simdV2kload(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[1].Reg()
|
|
|
|
|
ssagen.AddAux(&p.From, v)
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = maskReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VCVTTPS2DQ (BX), X2
|
|
|
|
|
func simdV11load(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = v.Args[0].Reg()
|
|
|
|
|
ssagen.AddAux(&p.From, v)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-12 16:43:30 +00:00
|
|
|
// Example instruction: VPSHUFD $7, (BX), X11
|
|
|
|
|
func simdV11loadImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
sc := v.AuxValAndOff()
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = sc.Val64()
|
|
|
|
|
m := obj.Addr{Type: obj.TYPE_MEM, Reg: v.Args[0].Reg()}
|
|
|
|
|
ssagen.AddAux2(&m, v, sc.Off64())
|
|
|
|
|
p.AddRestSource(m)
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VPRORD $81, -15(R14), K7, Y1
|
|
|
|
|
func simdVkvloadImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
sc := v.AuxValAndOff()
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = sc.Val64()
|
|
|
|
|
m := obj.Addr{Type: obj.TYPE_MEM, Reg: v.Args[0].Reg()}
|
|
|
|
|
ssagen.AddAux2(&m, v, sc.Off64())
|
|
|
|
|
p.AddRestSource(m)
|
|
|
|
|
p.AddRestSourceReg(maskReg(v.Args[1]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VPSHLDD $82, 7(SI), Y21, Y3
|
|
|
|
|
func simdV21loadImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
sc := v.AuxValAndOff()
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = sc.Val64()
|
|
|
|
|
m := obj.Addr{Type: obj.TYPE_MEM, Reg: v.Args[1].Reg()}
|
|
|
|
|
ssagen.AddAux2(&m, v, sc.Off64())
|
|
|
|
|
p.AddRestSource(m)
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VCMPPS $81, -7(DI), Y16, K3
|
|
|
|
|
func simdV2kloadImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
sc := v.AuxValAndOff()
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = sc.Val64()
|
|
|
|
|
m := obj.Addr{Type: obj.TYPE_MEM, Reg: v.Args[1].Reg()}
|
|
|
|
|
ssagen.AddAux2(&m, v, sc.Off64())
|
|
|
|
|
p.AddRestSource(m)
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = maskReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VCMPPS $81, -7(DI), Y16, K1, K3
|
|
|
|
|
func simdV2kkloadImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
sc := v.AuxValAndOff()
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = sc.Val64()
|
|
|
|
|
m := obj.Addr{Type: obj.TYPE_MEM, Reg: v.Args[1].Reg()}
|
|
|
|
|
ssagen.AddAux2(&m, v, sc.Off64())
|
|
|
|
|
p.AddRestSource(m)
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.AddRestSourceReg(maskReg(v.Args[2]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = maskReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: VGF2P8AFFINEINVQB $64, -17(BP), X31, K3, X26
|
|
|
|
|
func simdV2kvloadImm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
sc := v.AuxValAndOff()
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.From.Offset = sc.Val64()
|
|
|
|
|
m := obj.Addr{Type: obj.TYPE_MEM, Reg: v.Args[1].Reg()}
|
|
|
|
|
ssagen.AddAux2(&m, v, sc.Off64())
|
|
|
|
|
p.AddRestSource(m)
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[0]))
|
|
|
|
|
p.AddRestSourceReg(maskReg(v.Args[2]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-16 16:07:32 +00:00
|
|
|
// Example instruction: SHA1NEXTE X2, X2
|
|
|
|
|
func simdV21ResultInArg0(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = simdReg(v.Args[1])
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: SHA1RNDS4 $1, X2, X2
|
|
|
|
|
func simdV21ResultInArg0Imm8(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
p := s.Prog(v.Op.Asm())
|
|
|
|
|
p.From.Offset = int64(v.AuxUInt8())
|
|
|
|
|
p.From.Type = obj.TYPE_CONST
|
|
|
|
|
p.AddRestSourceReg(simdReg(v.Args[1]))
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = simdReg(v)
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Example instruction: SHA256RNDS2 X0, X11, X2
|
|
|
|
|
func simdV31x0AtIn2ResultInArg0(s *ssagen.State, v *ssa.Value) *obj.Prog {
|
|
|
|
|
return simdV31ResultInArg0(s, v)
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
var blockJump = [...]struct {
|
|
|
|
|
asm, invasm obj.As
|
|
|
|
|
}{
|
|
|
|
|
ssa.BlockAMD64EQ: {x86.AJEQ, x86.AJNE},
|
|
|
|
|
ssa.BlockAMD64NE: {x86.AJNE, x86.AJEQ},
|
|
|
|
|
ssa.BlockAMD64LT: {x86.AJLT, x86.AJGE},
|
|
|
|
|
ssa.BlockAMD64GE: {x86.AJGE, x86.AJLT},
|
|
|
|
|
ssa.BlockAMD64LE: {x86.AJLE, x86.AJGT},
|
|
|
|
|
ssa.BlockAMD64GT: {x86.AJGT, x86.AJLE},
|
2018-01-27 11:55:34 +01:00
|
|
|
ssa.BlockAMD64OS: {x86.AJOS, x86.AJOC},
|
|
|
|
|
ssa.BlockAMD64OC: {x86.AJOC, x86.AJOS},
|
2016-03-12 14:07:40 -08:00
|
|
|
ssa.BlockAMD64ULT: {x86.AJCS, x86.AJCC},
|
|
|
|
|
ssa.BlockAMD64UGE: {x86.AJCC, x86.AJCS},
|
|
|
|
|
ssa.BlockAMD64UGT: {x86.AJHI, x86.AJLS},
|
|
|
|
|
ssa.BlockAMD64ULE: {x86.AJLS, x86.AJHI},
|
|
|
|
|
ssa.BlockAMD64ORD: {x86.AJPC, x86.AJPS},
|
|
|
|
|
ssa.BlockAMD64NAN: {x86.AJPS, x86.AJPC},
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-23 00:57:10 -05:00
|
|
|
var eqfJumps = [2][2]ssagen.IndexJump{
|
2016-04-29 09:02:27 -07:00
|
|
|
{{Jump: x86.AJNE, Index: 1}, {Jump: x86.AJPS, Index: 1}}, // next == b.Succs[0]
|
|
|
|
|
{{Jump: x86.AJNE, Index: 1}, {Jump: x86.AJPC, Index: 0}}, // next == b.Succs[1]
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
2020-12-23 00:57:10 -05:00
|
|
|
var nefJumps = [2][2]ssagen.IndexJump{
|
2016-04-29 09:02:27 -07:00
|
|
|
{{Jump: x86.AJNE, Index: 0}, {Jump: x86.AJPC, Index: 1}}, // next == b.Succs[0]
|
|
|
|
|
{{Jump: x86.AJNE, Index: 0}, {Jump: x86.AJPS, Index: 0}}, // next == b.Succs[1]
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
|
|
|
|
|
2020-12-23 00:57:10 -05:00
|
|
|
func ssaGenBlock(s *ssagen.State, b, next *ssa.Block) {
|
2016-03-12 14:07:40 -08:00
|
|
|
switch b.Kind {
|
2025-02-19 16:47:31 -05:00
|
|
|
case ssa.BlockPlain, ssa.BlockDefer:
|
2016-04-28 16:52:47 -07:00
|
|
|
if b.Succs[0].Block() != next {
|
2017-03-20 08:01:28 -07:00
|
|
|
p := s.Prog(obj.AJMP)
|
2016-03-12 14:07:40 -08:00
|
|
|
p.To.Type = obj.TYPE_BRANCH
|
2020-12-23 00:57:10 -05:00
|
|
|
s.Branches = append(s.Branches, ssagen.Branch{P: p, B: b.Succs[0].Block()})
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
cmd/compile: restore tail call for method wrappers
For certain type of method wrappers we used to generate a tail
call. That was disabled in CL 307234 when register ABI is used,
because with the current IR it was difficult to generate a tail
call with the arguments in the right places. The problem was that
the IR does not contain a CALL-like node with arguments; instead,
it contains an OAS node that adjusts the receiver, than an
OTAILCALL node that just contains the target, but no argument
(with the assumption that the OAS node will put the adjusted
receiver in the right place). With register ABI, putting
arguments in registers are done in SSA. The assignment (OAS)
doesn't put the receiver in register.
This CL changes the IR of a tail call to take an actual OCALL
node. Specifically, a tail call is represented as
OTAILCALL (OCALL target args...)
This way, the call target and args are connected through the OCALL
node. So the call can be analyzed in SSA and the args can be passed
in the right places.
(Alternatively, we could have OTAILCALL node directly take the
target and the args, without the OCALL node. Using an OCALL node is
convenient as there are existing code that processes OCALL nodes
which do not need to be changed. Also, a tail call is similar to
ORETURN (OCALL target args...), except it doesn't preserve the
frame. I did the former but I'm open to change.)
The SSA representation is similar. Previously, the IR lowers to
a Store the receiver then a BlockRetJmp which jumps to the target
(without putting the arg in register). Now we use a TailCall op,
which takes the target and the args. The call expansion pass and
the register allocator handles TailCall pretty much like a
StaticCall, and it will do the right ABI analysis and put the args
in the right places. (Args other than the receiver are already in
the right places. For register args it generates no code for them.
For stack args currently it generates a self copy. I'll work on
optimize that out.) BlockRetJmp is still used, signaling it is a
tail call. The actual call is made in the TailCall op so
BlockRetJmp generates no code (we could use BlockExit if we like).
This slightly reduces binary size:
old new
cmd/go 14003088 13953936
cmd/link 6275552 6271456
Change-Id: I2d16d8d419fe1f17554916d317427383e17e27f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/350145
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
2021-09-10 22:05:55 -04:00
|
|
|
case ssa.BlockExit, ssa.BlockRetJmp:
|
2016-03-12 14:07:40 -08:00
|
|
|
case ssa.BlockRet:
|
2017-03-20 08:01:28 -07:00
|
|
|
s.Prog(obj.ARET)
|
2016-03-12 14:07:40 -08:00
|
|
|
|
|
|
|
|
case ssa.BlockAMD64EQF:
|
cmd/compile: fix incorrect rewriting to if condition
Some ARM64 rewriting rules convert 'comparing to zero' conditions of if
statements to a simplified version utilizing CMN and CMP instructions to
branch over condition flags, in order to save one Add or Sub caculation.
Such optimizations lead to wrong branching in case an overflow/underflow
occurs when executing CMN or CMP.
Fix the issue by introducing new block opcodes that don't honor the
overflow/underflow flag, in the following categories:
Block-Op Meaning ARM condition codes
1. LTnoov less than MI
2. GEnoov greater than or equal PL
3. LEnoov less than or equal MI || EQ
4. GTnoov greater than NEQ & PL
The backend generates two consecutive branch instructions for 'LEnoov'
and 'GTnoov' to model their expected behavior. A slight change to 'gc'
and amd64/386 backends is made to unify the code generation.
Add a test 'TestCondRewrite' as justification, it covers 32 incorrect rules
identified on arm64, more might be needed on other arches, like 32-bit arm.
Add two benchmarks profiling the aforementioned category 1&2 and category
3&4 separetely, we expect the first two categories will show performance
improvement and the second will not result in visible regression compared with
the non-optimized version.
This change also updates TestFormats to support using %#x.
Examples exhibiting where does the issue come from:
1: 'if x + 3 < 0' might be converted to:
before:
CMN $3, R0
BGE <else branch> // wrong branch is taken if 'x+3' overflows
after:
CMN $3, R0
BPL <else branch>
2: 'if y - 3 > 0' might be converted to:
before:
CMP $3, R0
BLE <else branch> // wrong branch is taken if 'y-3' underflows
after:
CMP $3, R0
BMI <else branch>
BEQ <else branch>
Benchmark data from different kinds of arm64 servers, 'old' is the non-optimized
version (not the parent commit), generally the optimization version outperforms.
S1:
name old time/op new time/op delta
CondRewrite/SoloJump 13.6ns ± 0% 12.9ns ± 0% -5.15% (p=0.000 n=10+10)
CondRewrite/CombJump 13.8ns ± 1% 12.9ns ± 0% -6.32% (p=0.000 n=10+10)
S2:
name old time/op new time/op delta
CondRewrite/SoloJump 11.6ns ± 0% 10.9ns ± 0% -6.03% (p=0.000 n=10+10)
CondRewrite/CombJump 11.4ns ± 0% 10.8ns ± 1% -5.53% (p=0.000 n=10+10)
S3:
name old time/op new time/op delta
CondRewrite/SoloJump 7.36ns ± 0% 7.50ns ± 0% +1.79% (p=0.000 n=9+10)
CondRewrite/CombJump 7.35ns ± 0% 7.75ns ± 0% +5.51% (p=0.000 n=8+9)
S4:
name old time/op new time/op delta
CondRewrite/SoloJump-224 11.5ns ± 1% 10.9ns ± 0% -4.97% (p=0.000 n=10+10)
CondRewrite/CombJump-224 11.9ns ± 0% 11.5ns ± 0% -2.95% (p=0.000 n=10+10)
S5:
name old time/op new time/op delta
CondRewrite/SoloJump 10.0ns ± 0% 10.0ns ± 0% -0.45% (p=0.000 n=9+10)
CondRewrite/CombJump 9.93ns ± 0% 9.77ns ± 0% -1.53% (p=0.000 n=10+9)
Go1 perf. data:
name old time/op new time/op delta
BinaryTree17 6.29s ± 1% 6.30s ± 1% ~ (p=1.000 n=5+5)
Fannkuch11 5.40s ± 0% 5.40s ± 0% ~ (p=0.841 n=5+5)
FmtFprintfEmpty 97.9ns ± 0% 98.9ns ± 3% ~ (p=0.937 n=4+5)
FmtFprintfString 171ns ± 3% 171ns ± 2% ~ (p=0.754 n=5+5)
FmtFprintfInt 212ns ± 0% 217ns ± 6% +2.55% (p=0.008 n=5+5)
FmtFprintfIntInt 296ns ± 1% 297ns ± 2% ~ (p=0.516 n=5+5)
FmtFprintfPrefixedInt 371ns ± 2% 374ns ± 7% ~ (p=1.000 n=5+5)
FmtFprintfFloat 435ns ± 1% 439ns ± 2% ~ (p=0.056 n=5+5)
FmtManyArgs 1.37µs ± 1% 1.36µs ± 1% ~ (p=0.730 n=5+5)
GobDecode 14.6ms ± 4% 14.4ms ± 4% ~ (p=0.690 n=5+5)
GobEncode 11.8ms ±20% 11.6ms ±15% ~ (p=1.000 n=5+5)
Gzip 507ms ± 0% 491ms ± 0% -3.22% (p=0.008 n=5+5)
Gunzip 73.8ms ± 0% 73.9ms ± 0% ~ (p=0.690 n=5+5)
HTTPClientServer 116µs ± 0% 116µs ± 0% ~ (p=0.686 n=4+4)
JSONEncode 21.8ms ± 1% 21.6ms ± 2% ~ (p=0.151 n=5+5)
JSONDecode 104ms ± 1% 103ms ± 1% -1.08% (p=0.016 n=5+5)
Mandelbrot200 9.53ms ± 0% 9.53ms ± 0% ~ (p=0.421 n=5+5)
GoParse 7.55ms ± 1% 7.51ms ± 1% ~ (p=0.151 n=5+5)
RegexpMatchEasy0_32 158ns ± 0% 158ns ± 0% ~ (all equal)
RegexpMatchEasy0_1K 606ns ± 1% 608ns ± 3% ~ (p=0.937 n=5+5)
RegexpMatchEasy1_32 143ns ± 0% 144ns ± 1% ~ (p=0.095 n=5+4)
RegexpMatchEasy1_1K 927ns ± 2% 944ns ± 2% ~ (p=0.056 n=5+5)
RegexpMatchMedium_32 16.0ns ± 0% 16.0ns ± 0% ~ (all equal)
RegexpMatchMedium_1K 69.3µs ± 2% 69.7µs ± 0% ~ (p=0.690 n=5+5)
RegexpMatchHard_32 3.73µs ± 0% 3.73µs ± 1% ~ (p=0.984 n=5+5)
RegexpMatchHard_1K 111µs ± 1% 110µs ± 0% ~ (p=0.151 n=5+5)
Revcomp 1.91s ±47% 1.77s ±68% ~ (p=1.000 n=5+5)
Template 138ms ± 1% 138ms ± 1% ~ (p=1.000 n=5+5)
TimeParse 787ns ± 2% 785ns ± 1% ~ (p=0.540 n=5+5)
TimeFormat 729ns ± 1% 726ns ± 1% ~ (p=0.151 n=5+5)
Updates #38740
Change-Id: I06c604874acdc1e63e66452dadee5df053045222
Reviewed-on: https://go-review.googlesource.com/c/go/+/233097
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
2020-05-06 09:54:40 +00:00
|
|
|
s.CombJump(b, next, &eqfJumps)
|
2016-03-12 14:07:40 -08:00
|
|
|
|
|
|
|
|
case ssa.BlockAMD64NEF:
|
cmd/compile: fix incorrect rewriting to if condition
Some ARM64 rewriting rules convert 'comparing to zero' conditions of if
statements to a simplified version utilizing CMN and CMP instructions to
branch over condition flags, in order to save one Add or Sub caculation.
Such optimizations lead to wrong branching in case an overflow/underflow
occurs when executing CMN or CMP.
Fix the issue by introducing new block opcodes that don't honor the
overflow/underflow flag, in the following categories:
Block-Op Meaning ARM condition codes
1. LTnoov less than MI
2. GEnoov greater than or equal PL
3. LEnoov less than or equal MI || EQ
4. GTnoov greater than NEQ & PL
The backend generates two consecutive branch instructions for 'LEnoov'
and 'GTnoov' to model their expected behavior. A slight change to 'gc'
and amd64/386 backends is made to unify the code generation.
Add a test 'TestCondRewrite' as justification, it covers 32 incorrect rules
identified on arm64, more might be needed on other arches, like 32-bit arm.
Add two benchmarks profiling the aforementioned category 1&2 and category
3&4 separetely, we expect the first two categories will show performance
improvement and the second will not result in visible regression compared with
the non-optimized version.
This change also updates TestFormats to support using %#x.
Examples exhibiting where does the issue come from:
1: 'if x + 3 < 0' might be converted to:
before:
CMN $3, R0
BGE <else branch> // wrong branch is taken if 'x+3' overflows
after:
CMN $3, R0
BPL <else branch>
2: 'if y - 3 > 0' might be converted to:
before:
CMP $3, R0
BLE <else branch> // wrong branch is taken if 'y-3' underflows
after:
CMP $3, R0
BMI <else branch>
BEQ <else branch>
Benchmark data from different kinds of arm64 servers, 'old' is the non-optimized
version (not the parent commit), generally the optimization version outperforms.
S1:
name old time/op new time/op delta
CondRewrite/SoloJump 13.6ns ± 0% 12.9ns ± 0% -5.15% (p=0.000 n=10+10)
CondRewrite/CombJump 13.8ns ± 1% 12.9ns ± 0% -6.32% (p=0.000 n=10+10)
S2:
name old time/op new time/op delta
CondRewrite/SoloJump 11.6ns ± 0% 10.9ns ± 0% -6.03% (p=0.000 n=10+10)
CondRewrite/CombJump 11.4ns ± 0% 10.8ns ± 1% -5.53% (p=0.000 n=10+10)
S3:
name old time/op new time/op delta
CondRewrite/SoloJump 7.36ns ± 0% 7.50ns ± 0% +1.79% (p=0.000 n=9+10)
CondRewrite/CombJump 7.35ns ± 0% 7.75ns ± 0% +5.51% (p=0.000 n=8+9)
S4:
name old time/op new time/op delta
CondRewrite/SoloJump-224 11.5ns ± 1% 10.9ns ± 0% -4.97% (p=0.000 n=10+10)
CondRewrite/CombJump-224 11.9ns ± 0% 11.5ns ± 0% -2.95% (p=0.000 n=10+10)
S5:
name old time/op new time/op delta
CondRewrite/SoloJump 10.0ns ± 0% 10.0ns ± 0% -0.45% (p=0.000 n=9+10)
CondRewrite/CombJump 9.93ns ± 0% 9.77ns ± 0% -1.53% (p=0.000 n=10+9)
Go1 perf. data:
name old time/op new time/op delta
BinaryTree17 6.29s ± 1% 6.30s ± 1% ~ (p=1.000 n=5+5)
Fannkuch11 5.40s ± 0% 5.40s ± 0% ~ (p=0.841 n=5+5)
FmtFprintfEmpty 97.9ns ± 0% 98.9ns ± 3% ~ (p=0.937 n=4+5)
FmtFprintfString 171ns ± 3% 171ns ± 2% ~ (p=0.754 n=5+5)
FmtFprintfInt 212ns ± 0% 217ns ± 6% +2.55% (p=0.008 n=5+5)
FmtFprintfIntInt 296ns ± 1% 297ns ± 2% ~ (p=0.516 n=5+5)
FmtFprintfPrefixedInt 371ns ± 2% 374ns ± 7% ~ (p=1.000 n=5+5)
FmtFprintfFloat 435ns ± 1% 439ns ± 2% ~ (p=0.056 n=5+5)
FmtManyArgs 1.37µs ± 1% 1.36µs ± 1% ~ (p=0.730 n=5+5)
GobDecode 14.6ms ± 4% 14.4ms ± 4% ~ (p=0.690 n=5+5)
GobEncode 11.8ms ±20% 11.6ms ±15% ~ (p=1.000 n=5+5)
Gzip 507ms ± 0% 491ms ± 0% -3.22% (p=0.008 n=5+5)
Gunzip 73.8ms ± 0% 73.9ms ± 0% ~ (p=0.690 n=5+5)
HTTPClientServer 116µs ± 0% 116µs ± 0% ~ (p=0.686 n=4+4)
JSONEncode 21.8ms ± 1% 21.6ms ± 2% ~ (p=0.151 n=5+5)
JSONDecode 104ms ± 1% 103ms ± 1% -1.08% (p=0.016 n=5+5)
Mandelbrot200 9.53ms ± 0% 9.53ms ± 0% ~ (p=0.421 n=5+5)
GoParse 7.55ms ± 1% 7.51ms ± 1% ~ (p=0.151 n=5+5)
RegexpMatchEasy0_32 158ns ± 0% 158ns ± 0% ~ (all equal)
RegexpMatchEasy0_1K 606ns ± 1% 608ns ± 3% ~ (p=0.937 n=5+5)
RegexpMatchEasy1_32 143ns ± 0% 144ns ± 1% ~ (p=0.095 n=5+4)
RegexpMatchEasy1_1K 927ns ± 2% 944ns ± 2% ~ (p=0.056 n=5+5)
RegexpMatchMedium_32 16.0ns ± 0% 16.0ns ± 0% ~ (all equal)
RegexpMatchMedium_1K 69.3µs ± 2% 69.7µs ± 0% ~ (p=0.690 n=5+5)
RegexpMatchHard_32 3.73µs ± 0% 3.73µs ± 1% ~ (p=0.984 n=5+5)
RegexpMatchHard_1K 111µs ± 1% 110µs ± 0% ~ (p=0.151 n=5+5)
Revcomp 1.91s ±47% 1.77s ±68% ~ (p=1.000 n=5+5)
Template 138ms ± 1% 138ms ± 1% ~ (p=1.000 n=5+5)
TimeParse 787ns ± 2% 785ns ± 1% ~ (p=0.540 n=5+5)
TimeFormat 729ns ± 1% 726ns ± 1% ~ (p=0.151 n=5+5)
Updates #38740
Change-Id: I06c604874acdc1e63e66452dadee5df053045222
Reviewed-on: https://go-review.googlesource.com/c/go/+/233097
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
2020-05-06 09:54:40 +00:00
|
|
|
s.CombJump(b, next, &nefJumps)
|
2016-03-12 14:07:40 -08:00
|
|
|
|
|
|
|
|
case ssa.BlockAMD64EQ, ssa.BlockAMD64NE,
|
|
|
|
|
ssa.BlockAMD64LT, ssa.BlockAMD64GE,
|
|
|
|
|
ssa.BlockAMD64LE, ssa.BlockAMD64GT,
|
2018-01-27 11:55:34 +01:00
|
|
|
ssa.BlockAMD64OS, ssa.BlockAMD64OC,
|
2016-03-12 14:07:40 -08:00
|
|
|
ssa.BlockAMD64ULT, ssa.BlockAMD64UGT,
|
|
|
|
|
ssa.BlockAMD64ULE, ssa.BlockAMD64UGE:
|
|
|
|
|
jmp := blockJump[b.Kind]
|
|
|
|
|
switch next {
|
2016-04-28 16:52:47 -07:00
|
|
|
case b.Succs[0].Block():
|
2018-04-05 16:14:42 -04:00
|
|
|
s.Br(jmp.invasm, b.Succs[1].Block())
|
2016-04-28 16:52:47 -07:00
|
|
|
case b.Succs[1].Block():
|
2018-04-05 16:14:42 -04:00
|
|
|
s.Br(jmp.asm, b.Succs[0].Block())
|
2016-03-12 14:07:40 -08:00
|
|
|
default:
|
2018-04-05 16:14:42 -04:00
|
|
|
if b.Likely != ssa.BranchUnlikely {
|
|
|
|
|
s.Br(jmp.asm, b.Succs[0].Block())
|
|
|
|
|
s.Br(obj.AJMP, b.Succs[1].Block())
|
|
|
|
|
} else {
|
|
|
|
|
s.Br(jmp.invasm, b.Succs[1].Block())
|
|
|
|
|
s.Br(obj.AJMP, b.Succs[0].Block())
|
|
|
|
|
}
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: implement jump tables
Performance is kind of hard to exactly quantify.
One big difference between jump tables and the old binary search
scheme is that there's only 1 branch statement instead of O(n) of
them. That can be both a blessing and a curse, and can make evaluating
jump tables very hard to do.
The single branch can become a choke point for the hardware branch
predictor. A branch table jump must fit all of its state in a single
branch predictor entry (technically, a branch target predictor entry).
With binary search that predictor state can be spread among lots of
entries. In cases where the case selection is repetitive and thus
predictable, binary search can perform better.
The big win for a jump table is that it doesn't consume so much of the
branch predictor's resources. But that benefit is essentially never
observed in microbenchmarks, because the branch predictor can easily
keep state for all the binary search branches in a microbenchmark. So
that benefit is really hard to measure.
So predictable switch microbenchmarks are ~useless - they will almost
always favor the binary search scheme. Fully unpredictable switch
microbenchmarks are better, as they aren't lying to us quite so
much. In a perfectly unpredictable situation, a jump table will expect
to incur 1-1/N branch mispredicts, where a binary search would incur
lg(N)/2 of them. That makes the crossover point at about N=4. But of
course switches in real programs are seldom fully unpredictable, so
we'll use a higher crossover point.
Beyond the branch predictor, jump tables tend to execute more
instructions per switch but have no additional instructions per case,
which also argues for a larger crossover.
As far as code size goes, with this CL cmd/go has a slightly smaller
code segment and a slightly larger overall size (from the jump tables
themselves which live in the data segment).
This is a case where some FDO (feedback-directed optimization) would
be really nice to have. #28262
Some large-program benchmarks might help make the case for this
CL. Especially if we can turn on branch mispredict counters so we can
see how much using jump tables can free up branch prediction resources
that can be gainfully used elsewhere in the program.
name old time/op new time/op delta
Switch8Predictable 1.89ns ± 2% 1.27ns ± 3% -32.58% (p=0.000 n=9+10)
Switch8Unpredictable 9.33ns ± 1% 7.50ns ± 1% -19.60% (p=0.000 n=10+9)
Switch32Predictable 2.20ns ± 2% 1.64ns ± 1% -25.39% (p=0.000 n=10+9)
Switch32Unpredictable 10.0ns ± 2% 7.6ns ± 2% -24.04% (p=0.000 n=10+10)
Fixes #5496
Update #34381
Change-Id: I3ff56011d02be53f605ca5fd3fb96b905517c34f
Reviewed-on: https://go-review.googlesource.com/c/go/+/357330
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2021-10-04 12:17:46 -07:00
|
|
|
case ssa.BlockAMD64JUMPTABLE:
|
|
|
|
|
// JMP *(TABLE)(INDEX*8)
|
|
|
|
|
p := s.Prog(obj.AJMP)
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = b.Controls[1].Reg()
|
|
|
|
|
p.To.Index = b.Controls[0].Reg()
|
|
|
|
|
p.To.Scale = 8
|
|
|
|
|
// Save jump tables for later resolution of the target blocks.
|
|
|
|
|
s.JumpTables = append(s.JumpTables, b)
|
|
|
|
|
|
2016-03-12 14:07:40 -08:00
|
|
|
default:
|
2019-08-12 20:19:58 +01:00
|
|
|
b.Fatalf("branch not implemented: %s", b.LongString())
|
2016-03-12 14:07:40 -08:00
|
|
|
}
|
|
|
|
|
}
|
2021-04-03 20:09:15 -04:00
|
|
|
|
2021-05-25 18:05:02 -04:00
|
|
|
func loadRegResult(s *ssagen.State, f *ssa.Func, t *types.Type, reg int16, n *ir.Name, off int64) *obj.Prog {
|
2025-08-14 20:21:37 +00:00
|
|
|
p := s.Prog(loadByRegWidth(reg, t.Size()))
|
2021-05-25 18:05:02 -04:00
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Name = obj.NAME_AUTO
|
|
|
|
|
p.From.Sym = n.Linksym()
|
|
|
|
|
p.From.Offset = n.FrameOffset() + off
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = reg
|
|
|
|
|
return p
|
2021-04-03 20:09:15 -04:00
|
|
|
}
|
2021-04-11 12:42:49 -04:00
|
|
|
|
|
|
|
|
func spillArgReg(pp *objw.Progs, p *obj.Prog, f *ssa.Func, t *types.Type, reg int16, n *ir.Name, off int64) *obj.Prog {
|
2025-08-14 20:21:37 +00:00
|
|
|
p = pp.Append(p, storeByRegWidth(reg, t.Size()), obj.TYPE_REG, reg, 0, obj.TYPE_MEM, 0, n.FrameOffset()+off)
|
2021-04-11 12:42:49 -04:00
|
|
|
p.To.Name = obj.NAME_PARAM
|
|
|
|
|
p.To.Sym = n.Linksym()
|
cmd/compile: spos handling fixes to improve prolog debuggability
With the new register ABI, the compiler sometimes introduces spills of
argument registers in function prologs; depending on the positions
assigned to these spills and whether they have the IsStmt flag set,
this can degrade the debugging experience. For example, in this
function from one of the Delve regression tests:
L13: func foo((eface interface{}) {
L14: if eface != nil {
L15: n++
L16: }
L17 }
we wind up with a prolog containing two spill instructions, the first
with line 14, the second with line 13. The end result for the user
is that if you set a breakpoint in foo and run to it, then do "step",
execution will initially stop at L14, then jump "backwards" to L13.
The root of the problem in this case is that an ArgIntReg pseudo-op is
introduced during expand calls, then promoted (due to lowering) to a
first-class statement (IsStmt flag set), which in turn causes
downstream handling to propagate its position to the first of the register
spills in the prolog.
To help improve things, this patch changes the rewriter to avoid
moving an "IsStmt" flag from a deleted/replaced instruction to an
Arg{Int,Float}Reg value, and adds Arg{Int,Float}Reg to the list of
opcodes not suitable for selection as statement boundaries, and
suppresses generation of additional register spills in defframe() when
optimization is disabled (since in that case things will get spilled
in any case).
This is not a comprehensive/complete fix; there are still cases where
we get less-than-ideal source position markers (ex: issue 45680).
Updates #40724.
Change-Id: Ica8bba4940b2291bef6b5d95ff0cfd84412a2d40
Reviewed-on: https://go-review.googlesource.com/c/go/+/312989
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2021-04-21 16:21:30 -04:00
|
|
|
p.Pos = p.Pos.WithNotStmt()
|
2021-04-11 12:42:49 -04:00
|
|
|
return p
|
|
|
|
|
}
|
2025-03-31 10:45:23 +11:00
|
|
|
|
2025-06-03 16:23:02 -07:00
|
|
|
// zero 16 bytes at reg+off.
|
|
|
|
|
func zero16(s *ssagen.State, reg int16, off int64) {
|
|
|
|
|
// MOVUPS X15, off(ptrReg)
|
|
|
|
|
p := s.Prog(x86.AMOVUPS)
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = x86.REG_X15
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = reg
|
|
|
|
|
p.To.Offset = off
|
|
|
|
|
}
|
[dev.simd] all: merge master (7a1679d) into dev.simd
Conflicts:
- src/cmd/compile/internal/amd64/ssa.go
- src/cmd/compile/internal/ssa/rewriteAMD64.go
- src/internal/buildcfg/exp.go
- src/internal/cpu/cpu.go
- src/internal/cpu/cpu_x86.go
- src/internal/goexperiment/flags.go
Merge List:
+ 2025-08-04 7a1679d7ae cmd/compile: move s390x over to new bounds check strategy
+ 2025-08-04 95693816a5 cmd/compile: move riscv64 over to new bounds check strategy
+ 2025-08-04 d7bd7773eb go/parser: remove safePos
+ 2025-08-04 4b6cbc377f cmd/cgo/internal/test: use (syntactic) constant for C array bound
+ 2025-08-03 b2960e3580 cmd/internal/obj/loong64: add {V,XV}{BITCLR/BITSET/BITREV}[I].{B/H/W/D} instructions support
+ 2025-08-03 abeeef1c08 cmd/compile/internal/test: fix typo in comments
+ 2025-08-03 d44749b65b cmd/internal/obj/loong64: add [X]VLDREPL.{B/H/W/D} instructions support
+ 2025-08-03 d6beda863e runtime: add reference to debugPinnerV1
+ 2025-08-01 4ab1aec007 cmd/go: modload should use a read-write lock to improve concurrency
+ 2025-08-01 e666972a67 runtime: deduplicate Windows stdcall
+ 2025-08-01 ef40549786 runtime,syscall: move loadlibrary and getprocaddress to syscall
+ 2025-08-01 336931a4ca cmd/go: use os.Rename to move files on Windows
+ 2025-08-01 eef5f8d930 cmd/compile: enforce that locals are always accessed with SP base register
+ 2025-08-01 e071617222 cmd/compile: optimize multiplication rules on loong64
+ 2025-07-31 eb7f515c4d cmd/compile: use generated loops instead of DUFFZERO on amd64
+ 2025-07-31 c0ee2fd4e3 cmd/go: explicitly reject module paths "go" and "toolchain"
+ 2025-07-30 a4d99770c0 runtime/metrics: add cleanup and finalizer queue metrics
+ 2025-07-30 70a2ff7648 runtime: add cgo call benchmark
+ 2025-07-30 69338a335a cmd/go/internal/gover: fix ModIsPrerelease for toolchain versions
+ 2025-07-30 cedf63616a cmd/compile: add floating point min/max intrinsics on s390x
+ 2025-07-30 82a1921c3b all: remove redundant Swiss prefixes
+ 2025-07-30 2ae059ccaf all: remove GOEXPERIMENT=swissmap
+ 2025-07-30 cc571dab91 cmd/compile: deduplicate instructions when rewrite func results
+ 2025-07-30 2174a7936c crypto/tls: use standard chacha20-poly1305 cipher suite names
+ 2025-07-30 8330fb48a6 cmd/compile: move mips32 over to new bounds check strategy
+ 2025-07-30 9f9d7b50e8 cmd/compile: move mips64 over to new bounds check strategy
+ 2025-07-30 5216fd570e cmd/compile: move loong64 over to new bounds check strategy
+ 2025-07-30 89a0af86b8 cmd/compile: allow ops to specify clobbering input registers
+ 2025-07-30 5e94d72158 cmd/compile: simplify zerorange on arm64
+ 2025-07-30 8cd85e602a cmd/compile: check domination of loop return in both controls
+ 2025-07-30 cefaed0de0 reflect: fix noswiss builder
+ 2025-07-30 3aa1b00081 regexp: fix compiling alternate patterns of different fold case literals
+ 2025-07-30 b1e933d955 cmd/compile: avoid extending when already sufficiently masked on loong64
+ 2025-07-29 880ca333d7 cmd/compile: removing log2uint32 function
+ 2025-07-29 1513661dc3 cmd/compile: simplify logX implementations
+ 2025-07-29 bd94ae8903 cmd/compile: use unsigned power-of-two detector for unsigned mod
+ 2025-07-29 f3582fc80e cmd/compile: add unsigned power-of-two detector
+ 2025-07-29 f7d167fe71 internal/abi: move direct/indirect flag from Kind to TFlag
+ 2025-07-29 e0b07dc22e os/exec: fix incorrect expansion of "", "." and ".." in LookPath
+ 2025-07-29 25816d401c internal/goexperiment: delete RangeFunc goexperiment
+ 2025-07-29 7961bf71f8 internal/goexperiment: delete CacheProg goexperiment
+ 2025-07-29 e15a14c4dd sync: remove synchashtriemap GOEXPERIMENT
+ 2025-07-29 7dccd6395c cmd/compile: move arm32 over to new bounds check strategy
+ 2025-07-29 d79405a344 runtime: only deduct assist credit for arenas during GC
+ 2025-07-29 19a086f716 cmd/go/internal/telemetrystats: count goexperiments
+ 2025-07-29 aa95ab8215 image: fix formatting of godoc link
+ 2025-07-29 4c854b7a3e crypto/elliptic: change a variable name that have the same name as keywords
+ 2025-07-28 b10eb1d042 cmd/compile: simplify zerorange on amd64
+ 2025-07-28 f8eae7a3c3 os/user: fix tests to pass on non-english Windows
+ 2025-07-28 0984264471 internal/poll: remove msg field from Windows' poll.operation
+ 2025-07-28 d7b4114346 internal/poll: remove rsan field from Windows' poll.operation
+ 2025-07-28 361b1ab41f internal/poll: remove sa field from Windows' poll.operation
+ 2025-07-28 9b6bd64e46 internal/poll: remove qty and flags fields from Windows' poll.operation
+ 2025-07-28 cd3655a824 internal/runtime/maps: fix spelling errors in comments
+ 2025-07-28 d5dc36af45 runtime: remove openbsd/mips64 related code
+ 2025-07-28 64ba72474d errors: omit redundant nil check in type assertion for Join
+ 2025-07-28 e151db3e06 all: omit unnecessary type conversions
+ 2025-07-28 4569255f8c cmd/compile: cleanup SelectN rules by indexing into args
+ 2025-07-28 94645d2413 cmd/compile: rewrite cmov(x, x, cond) into x
+ 2025-07-28 10c5cf68d4 net/http: add proper panic message
+ 2025-07-28 46b5839231 test/codegen: fix failing condmove wasm tests
+ 2025-07-28 98f301cf68 runtime,syscall: move SyscallX implementations from runtime to syscall
+ 2025-07-28 c7ed3a1c5a internal/runtime/syscall/windows: factor out code from runtime
+ 2025-07-28 e81eac19d3 hash/crc32: fix incorrect checksums with avx512+race
+ 2025-07-25 6fbad4be75 cmd/compile: remove no-longer-necessary call to calculateDepths
+ 2025-07-25 5045fdd8ff cmd/compile: fix containsUnavoidableCall computation
+ 2025-07-25 d28b27cd8e go/types, types2: use nil to represent incomplete explicit aliases
+ 2025-07-25 7b53d8d06e cmd/compile/internal/types2: add loaded state between loader calls and constraint expansion
+ 2025-07-25 374e3be2eb os/user: user random name for the test user account
+ 2025-07-25 1aa154621d runtime: rename scanobject to scanObject
+ 2025-07-25 41b429881a runtime: duplicate scanobject in greentea and non-greentea files
+ 2025-07-25 aeb256e98a cmd/compile: remove unused arg from gorecover
+ 2025-07-25 08376e1a9c runtime: iterate through inlinings when processing recover()
+ 2025-07-25 c76c3abc54 encoding/json: fix truncated Token error regression in goexperiment.jsonv2
+ 2025-07-25 ebdbfccd98 encoding/json/jsontext: preserve buffer capacity in Encoder.Reset
+ 2025-07-25 91c4f0ccd5 reflect: avoid a bounds check in stack-constrained code
+ 2025-07-24 3636ced112 encoding/json: fix extra data regression under goexperiment.jsonv2
+ 2025-07-24 a6eec8bdc7 encoding/json: reduce error text regressions under goexperiment.jsonv2
+ 2025-07-24 0fa88dec1e time: remove redundant uint32 conversion in split
+ 2025-07-24 ada30b8248 internal/buildcfg: add ability to get GORISCV64 variable in GOGOARCH
+ 2025-07-24 6f6c6c5782 cmd/internal/obj: rip out argp adjustment for wrapper frames
+ 2025-07-24 7b50024330 runtime: detect successful recovers differently
+ 2025-07-24 7b9de668bd unicode/utf8: skip ahead during ascii runs in Valid/ValidString
+ 2025-07-24 076eae436e cmd/compile: move amd64 and 386 over to new bounds check strategy
+ 2025-07-24 f703dc5bef cmd/compile: add missing StringLen rule in prove
+ 2025-07-24 394d0bee8d cmd/compile: move arm64 over to new bounds check strategy
+ 2025-07-24 3024785b92 cmd/compile,runtime: remember idx+len for bounds check failure with less code
+ 2025-07-24 741a19ab41 runtime: move bounds check constants to internal/abi
+ 2025-07-24 ce05ad448f cmd/compile: rewrite condselects into doublings and halvings
+ 2025-07-24 fcd28070fe cmd/compile: add opt branchelim to rewrite some CondSelect into math
+ 2025-07-24 f32cf8e4b0 cmd/compile: learn transitive proofs for safe unsigned subs
+ 2025-07-24 d574856482 cmd/compile: learn transitive proofs for safe negative signed adds
+ 2025-07-24 1a72920f09 cmd/compile: learn transitive proofs for safe positive signed adds
+ 2025-07-24 e5f202bb60 cmd/compile: learn transitive proofs for safe unsigned adds
+ 2025-07-24 bd80f74bc1 cmd/compile: fold shift through AND for slice operations
+ 2025-07-24 5c45fe1385 internal/runtime/syscall: rename to internal/runtime/syscall/linux
+ 2025-07-24 592c2db868 cmd/compile: improve loopRotate to handle nested loops
+ 2025-07-24 dcb479c2f9 cmd/compile: optimize slice bounds checking with SUB/SUBconst comparisons
+ 2025-07-24 f11599b0b9 internal/poll: remove handle field from Windows' poll.operation
+ 2025-07-24 f7432e0230 internal/poll: remove fd field from Windows' poll.operation
+ 2025-07-24 e84ed38641 runtime: add benchmark for small-size memmory operation
+ 2025-07-24 18dbe5b941 hash/crc32: add AVX512 IEEE CRC32 calculation
+ 2025-07-24 c641900f72 cmd/compile: prefer base.Fatalf to panic in dwarfgen
+ 2025-07-24 d71d8aeafd cmd/internal/obj/s390x: add MVCLE instruction
+ 2025-07-24 b6cf1d94dc runtime: optimize memclr on mips64x
+ 2025-07-24 a8edd99479 runtime: improvement in memclr for s390x
+ 2025-07-24 bd04f65511 internal/runtime/exithook: fix a typo
+ 2025-07-24 5c8624a396 cmd/internal/goobj: make error output clear
+ 2025-07-24 44d73dfb4e cmd/go/internal/doc: clean up after merge with cmd/internal/doc
+ 2025-07-24 bd446662dd cmd/internal/doc: merge with cmd/go/internal/doc
+ 2025-07-24 da8b50c830 cmd/doc: delete
+ 2025-07-24 6669aa3b14 runtime: randomize heap base address
+ 2025-07-24 26338a7f69 cmd/compile: use better fatal message for staticValue1
+ 2025-07-24 8587ba272e cmd/cgo: compare malloc return value to NULL instead of literal 0
+ 2025-07-24 cae45167b7 go/types, types2: better error messages for certain type mismatches
+ 2025-07-24 2ddf542e4c cmd/compile: use ,ok return idiom for sparsemap.get
+ 2025-07-24 6505fcbd0a cmd/compile: use generics for sparse map
+ 2025-07-24 14f5eb7812 cmd/api: rerun updategolden
+ 2025-07-24 52b6d7f67a runtime: drop NetBSD kernel bug sysmon workaround fixed in NetBSD 9.2
+ 2025-07-24 1ebebf1cc1 cmd/go: clean should respect workspaces
+ 2025-07-24 6536a93547 encoding/json/jsontext: preserve buffer capacity in Decoder.Reset
+ 2025-07-24 efc37e97c0 cmd/go: always return the cached path from go tool -n
+ 2025-07-23 98a031193b runtime: check TestUsingVDSO ExitError type assertion
+ 2025-07-23 6bb42997c8 doc/next: initialize
+ 2025-07-23 2696a11a97 internal/goversion: update Version to 1.26
+ 2025-07-23 489868f776 cmd/link: scope test to linux & net.sendFile
+ 2025-07-22 71c2bf5513 cmd/compile: fix loclist for heap return vars without optimizations
+ 2025-07-22 c74399e7f5 net: correct comment for ListenConfig.ListenPacket
+ 2025-07-22 4ed9943b26 all: go fmt
+ 2025-07-22 1aaf7422f1 cmd/internal/objabi: remove redundant word in comment
+ 2025-07-21 d5ec0815e6 runtime: relax TestMemoryLimitNoGCPercent a bit
+ 2025-07-21 f7cc61e7d7 cmd/compile: for arm64 epilog, do SP increment with a single instruction
+ 2025-07-21 5dac42363b runtime: fix asan wrapper for riscv64
+ 2025-07-21 e5502e0959 cmd/go: check subcommand properties
+ 2025-07-19 2363897932 cmd/internal/obj: enable got pcrel itype in fips140 for riscv64
+ 2025-07-19 e32255fcc0 cmd/compile/internal/ssa: restrict architectures for TestDebugLines_74576
+ 2025-07-18 0451816430 os: revert the use of AddCleanup to close files and roots
+ 2025-07-18 34b70684ba go/types: infer correct type for y in append(bytes, y...)
+ 2025-07-17 66536242fc cmd/compile/internal/escape: improve DWARF .debug_line numbering for literal rewriting optimizations
+ 2025-07-16 385000b004 runtime: fix idle time double-counting bug
+ 2025-07-16 f506ad2644 cmd/compile/internal/escape: speed up analyzing some functions with many closures
+ 2025-07-16 9c507e7942 cmd/link, runtime: on Wasm, put only function index in method table and func table
+ 2025-07-16 9782dcfd16 runtime: use 32-bit function index on Wasm
+ 2025-07-16 c876bf9346 cmd/internal/obj/wasm: use 64-bit instructions for indirect calls
+ 2025-07-15 b4309ece66 cmd/internal/doc: upgrade godoc pkgsite to 01b046e
+ 2025-07-15 75a19dbcd7 runtime: use memclrNoHeapPointers to clear inline mark bits
+ 2025-07-15 6d4a91c7a5 runtime: only clear inline mark bits on span alloc if necessary
+ 2025-07-15 0c6296ab12 runtime: have mergeInlineMarkBits also clear the inline mark bits
+ 2025-07-15 397d2117ec runtime: merge inline mark bits with gcmarkBits 8 bytes at a time
+ 2025-07-15 7dceabd3be runtime/maps: fix typo in group.go comment (instrinsified -> intrinsified)
+ 2025-07-15 d826bf4d74 os: remove useless error check
+ 2025-07-14 bb07e55aff runtime: expand GOMAXPROCS documentation
+ 2025-07-14 9159cd4ec6 encoding/json: decompose legacy options
+ 2025-07-14 c6556b8eb3 encoding/json/v2: add security section to doc
+ 2025-07-11 6ebb5f56d9 runtime: gofmt after CL 643897 and CL 662455
+ 2025-07-11 1e48ca7020 encoding/json: remove legacy option to EscapeInvalidUTF8
+ 2025-07-11 a0a99cb22b encoding/json/v2: report wrapped io.ErrUnexpectedEOF
+ 2025-07-11 9d04122d24 crypto/rsa: drop contradictory promise to keep PublicKey modulus secret
+ 2025-07-11 1ca23682dd crypto/rsa: fix documentation formatting
+ 2025-07-11 4bc3373c8e runtime: turn off large memmove tests under asan/msan
Change-Id: I1e32d964eba770b85421efb86b305a2242f24466
2025-08-04 15:07:05 -04:00
|
|
|
|
2025-08-13 09:41:17 -07:00
|
|
|
// move 16 bytes from src+off to dst+off using temporary register tmp.
|
|
|
|
|
func move16(s *ssagen.State, src, dst, tmp int16, off int64) {
|
|
|
|
|
// MOVUPS off(srcReg), tmpReg
|
|
|
|
|
// MOVUPS tmpReg, off(dstReg)
|
|
|
|
|
p := s.Prog(x86.AMOVUPS)
|
|
|
|
|
p.From.Type = obj.TYPE_MEM
|
|
|
|
|
p.From.Reg = src
|
|
|
|
|
p.From.Offset = off
|
|
|
|
|
p.To.Type = obj.TYPE_REG
|
|
|
|
|
p.To.Reg = tmp
|
|
|
|
|
p = s.Prog(x86.AMOVUPS)
|
|
|
|
|
p.From.Type = obj.TYPE_REG
|
|
|
|
|
p.From.Reg = tmp
|
|
|
|
|
p.To.Type = obj.TYPE_MEM
|
|
|
|
|
p.To.Reg = dst
|
|
|
|
|
p.To.Offset = off
|
|
|
|
|
}
|
[dev.simd] all: merge master (924fe98) into dev.simd
Conflicts:
- src/cmd/compile/internal/amd64/ssa.go
- src/cmd/compile/internal/ssa/expand_calls.go
- src/cmd/compile/internal/ssagen/ssa.go
- src/internal/buildcfg/exp.go
- src/internal/cpu/cpu.go
- src/internal/cpu/cpu_x86.go
- src/runtime/mkpreempt.go
- src/runtime/preempt_amd64.go
- src/runtime/preempt_amd64.s
Merge List:
+ 2025-08-14 924fe98902 cmd/internal/obj/riscv: add encoding for compressed riscv64 instructions
+ 2025-08-13 320df537cc cmd/compile: emit classify instructions for infinity tests on riscv64
+ 2025-08-13 ca66f907dd cmd/compile: use generated loops instead of DUFFCOPY on amd64
+ 2025-08-13 4b1800e476 encoding/json/v2: cleanup error constructors
+ 2025-08-13 af8870708b encoding/json/v2: fix incorrect marshaling of NaN in float64 any
+ 2025-08-13 0a75e5a07b encoding/json/v2: fix wrong type with cyclic marshal error in map[string]any
+ 2025-08-13 de9b6f9875 cmd/pprof: update vendored github.com/google/pprof
+ 2025-08-13 674c5f0edd os/exec: fix incorrect expansion of ".." in LookPath on plan9
+ 2025-08-13 9bbea0f21a cmd/compile: during regalloc, fixedreg values are always available
+ 2025-08-13 08eef97500 runtime/trace: fix documentation typo
+ 2025-08-13 2fe5d51d04 internal/trace: fix wrong scope for Event.Range or EvGCSweepActive
+ 2025-08-13 9fcb87c352 cmd/compile: teach prove about len's & cap's max based on the element size
+ 2025-08-13 9763ece873 cmd/compile: absorb NEGV into branch on loong64
+ 2025-08-13 f10a82b76f all: update vendored dependencies [generated]
+ 2025-08-13 3bea95b277 cmd/link/internal/ld: remove OpenBSD buildid workaround
+ 2025-08-12 90b7d7aaa2 cmd/compile/internal: optimize multiplication use new operation 'ADDshiftLLV' on loong64
+ 2025-08-12 1b263fc604 runtime/race: restore previous version of LLVM TSAN on macOS
+ 2025-08-12 b266318cf7 cmd/compile/internal/ssa: use BEQ/BNE to optimize the combination of XOR and EQ/NE on loong64
+ 2025-08-12 adbf59525c internal/runtime/gc/scan: avoid -1 index when cache sizes unavailable
+ 2025-08-12 4e182db5fc Revert "cmd/compile: use generated loops instead of DUFFCOPY on amd64"
+ 2025-08-12 d2b3c1a504 internal/trace: clarify which StateTransition events have stacks
+ 2025-08-12 f63e12d0e0 internal/trace: fix Sync.ClockSnapshot comment
+ 2025-08-12 8e317da77d internal/trace: remove unused StateTransition.id field
+ 2025-08-12 f67d8ff34a internal/trace/tracev2: adjust comment for consistency
+ 2025-08-12 fe4d445c36 internal/trace/tracev2: fix EvSTWBegin comment to include stack ID
+ 2025-08-12 750789fab7 internal/trace/internal/testgen: fix missing stacks nframes arg
+ 2025-08-12 889ab74169 internal/runtime/gc/scan: import scan kernel from gclab [green tea]
+ 2025-08-12 182336bf05 net/http: fix data race in client
+ 2025-08-12 f04421ea9a cmd/compile: soften test for 74788
+ 2025-08-12 28aa529c99 cmd/compile: use generated loops instead of DUFFZERO on arm64
+ 2025-08-12 ec9e1176c3 cmd/compile: use generated loops instead of DUFFCOPY on amd64
+ 2025-08-12 d0a64f7969 Revert "cmd/compile/internal/ssa: Use transitive properties for len/cap"
+ 2025-08-12 00a7bdcb55 all: delete aliastypeparams GOEXPERIMENT
+ 2025-08-11 74421a305b Revert "cmd/compile: allow multi-field structs to be stored directly in interfaces"
+ 2025-08-11 c31359138c Revert "cmd/compile: allow StructSelect [x] of interface data fields for x>0"
+ 2025-08-11 7248995b60 Revert "cmd/compile: allow more args in StructMake folding rule"
+ 2025-08-11 caf9fc3ccd Revert "reflect: handle zero-sized fields of directly-stored structures correctly"
+ 2025-08-11 ce3f3e2ae7 cmd/link/internal/ld, internal/syscall/unix: use posix_fallocate on netbsd
+ 2025-08-11 3dbef65bf3 database/sql: allow drivers to override Scan behavior
+ 2025-08-11 2b804abf07 net: context aware Dialer.Dial functions
+ 2025-08-11 6abfe7b0de cmd/dist: require Go 1.24.6 as minimum bootstrap toolchain
+ 2025-08-11 691af6ca28 encoding/json: fix Indent trailing whitespace regression in goexperiment.jsonv2
+ 2025-08-11 925149da20 net/http: add example for CrossOriginProtection
+ 2025-08-11 cf4af0b2f3 encoding/json/v2: fix UnmarshalDecode regression with EOF
+ 2025-08-11 b096ddb9ea internal/runtime/maps: loop invariant code motion with h2(hash) by hand
+ 2025-08-11 a2431776eb net, os, file/filepath, syscall: use slices.Equal in tests
+ 2025-08-11 a7f05b38f7 cmd/compile: convert branch with zero to more optimal branch zero on loong64
+ 2025-08-11 1718828c81 internal/sync: warn about incorrect unsafe usage in HashTrieMap
+ 2025-08-11 084c0f8494 cmd/compile: allow InlMark operations to be speculatively executed
+ 2025-08-10 a62f72f7a7 cmd/compile/internal/ssa: optimise more branches with SGTconst/SGTUconst on loong64
+ 2025-08-08 fbac94a799 internal/sync: rename Store parameter from old to new
+ 2025-08-08 317be4cfeb cmd/compile/internal/staticinit: remove deadcode
+ 2025-08-08 bce5601cbb cmd/go: fix fips doc link
+ 2025-08-08 777d76c4f2 text/template: use sync.OnceValue for builtinFuncs
+ 2025-08-08 0201524c52 math: remove redundant infinity tests
+ 2025-08-08 dcc77f9e3c cmd/go: fix get -tool when multiple packages are provided
+ 2025-08-08 c7b85e9ddc all: update blog link
+ 2025-08-08 a8dd771e13 crypto/tls: check if quic conn can send session ticket
+ 2025-08-08 bdb2d50fdf net: fix WriteMsgUDPAddrPort addr handling on IPv4 sockets
+ 2025-08-08 768c51e368 internal/runtime/maps: remove unused var bitsetDeleted
+ 2025-08-08 b3388569a1 reflect: handle zero-sized fields of directly-stored structures correctly
+ 2025-08-08 d83b16fcb8 internal/bytealg: vector implementation of compare for riscv64
+ 2025-08-07 dd3abf6bc5 internal/bytealg: optimize Index/IndexString on loong64
+ 2025-08-07 73ff6d1480 cmd/internal/obj/loong64: change the immediate range of ALSL{W/WU/V}
+ 2025-08-07 f3606b0825 cmd/compile/internal/ssa: fix typo in LOONG64Ops.go comment
+ 2025-08-07 ee7bb8969a cmd/internal/obj/loong64: add support for FSEL instruction
+ 2025-08-07 1f7ffca171 time: skip TestLongAdjustTimers on plan9 (too slow)
+ 2025-08-06 8282b72d62 runtime/race: update darwin race syso
+ 2025-08-06 dc54d7b607 all: remove support for windows/arm
+ 2025-08-06 e0a1ea431c cmd/compile: make panicBounds stack frame smaller on ppc64
+ 2025-08-06 2747f925dd debug/macho: support reading imported symbols without LC_DYSYMTAB
+ 2025-08-06 025d36917c cmd/internal/testdir: pass -buildid to link command
+ 2025-08-06 f53dcb6280 cmd/internal/testdir: unify link command
+ 2025-08-06 a3895fe9f1 database/sql: avoid closing Rows while scan is in progress
+ 2025-08-06 608e9fac90 go/types, types2: flip on position tracing
+ 2025-08-06 72e8237cc1 cmd/compile: allow more args in StructMake folding rule
+ 2025-08-06 3406a617d9 internal/bytealg: vector implementation of indexbyte for riscv64
+ 2025-08-06 75ea2d05c0 internal/bytealg: vector implementation of equal for riscv64
+ 2025-08-05 17a8be7117 crypto/sha512: use const table for key loading on loong64
+ 2025-08-05 dda9d780e2 crypto/sha256: use const table for key loading on loong64
+ 2025-08-05 5defe8ebb3 internal/chacha8rand: replace WORD with instruction VMOVQ
+ 2025-08-05 4c7362e41c cmd/internal/obj/loong64: add new instructions ALSL{W/WU/V} for loong64
+ 2025-08-05 a552737418 cmd/compile: fold negation into multiplication on loong64
+ 2025-08-05 e1fd4faf91 runtime: fix godoc comment for inVDSOPage
+ 2025-08-05 bcd25c79aa cmd/compile: allow StructSelect [x] of interface data fields for x>0
+ 2025-08-05 b0945a54b5 cmd/dist, internal/platform: mark freebsd/riscv64 broken
+ 2025-08-05 55d961b202 runtime: save AVX2 and AVX-512 state on asynchronous preemption
+ 2025-08-05 af0c4fe2ca runtime: save scalar registers off stack in amd64 async preemption
+ 2025-08-05 e73afaae69 internal/cpu: add AVX-512-CD and DQ, and derived "basic AVX-512"
+ 2025-08-05 cef381ba60 runtime: eliminate global state in mkpreempt.go
+ 2025-08-05 c0025d5e0b go/parser: correct comment in expectedErrors
+ 2025-08-05 4ee0df8c46 cmd: remove dead code
+ 2025-08-05 a2c45f0eb1 runtime: test VDSO symbol hash values
+ 2025-08-05 cd55f86b8d cmd/compile: allow multi-field structs to be stored directly in interfaces
+ 2025-08-05 21ab0128b6 cmd/compile: remove support for old-style bounds check calls
+ 2025-08-05 802d056c78 cmd/compile: move ppc64 over to new bounds check strategy
+ 2025-08-05 a3295df873 cmd/compile/internal/ssa: Use transitive properties for len/cap
+ 2025-08-05 bd082857a5 doc: fix typo in go memory model doc
+ 2025-08-05 2b622b05a9 cmd/compile: remove isUintXPowerOfTwo functions
+ 2025-08-05 72147ffa75 cmd/compile: simplify isUintXPowerOfTwo implementation
+ 2025-08-05 26da1199eb cmd/compile: make isUint{32,64}PowerOfTwo implementations clearer
+ 2025-08-05 5ab9f23977 cmd/compile, runtime: add checkptr instrumentation for unsafe.Add
+ 2025-08-05 fcc036f03b cmd/compile: optimise float <-> int register moves on riscv64
Change-Id: Ie94f29d9b0cc14a52a536866f5abaef27b5c52d7
2025-08-14 11:43:15 -04:00
|
|
|
|
2025-03-31 10:45:23 +11:00
|
|
|
// XXX maybe make this part of v.Reg?
|
|
|
|
|
// On the other hand, it is architecture-specific.
|
|
|
|
|
func simdReg(v *ssa.Value) int16 {
|
|
|
|
|
t := v.Type
|
|
|
|
|
if !t.IsSIMD() {
|
2025-06-28 11:05:44 -04:00
|
|
|
base.Fatalf("simdReg: not a simd type; v=%s, b=b%d, f=%s", v.LongString(), v.Block.ID, v.Block.Func.Name)
|
2025-03-31 10:45:23 +11:00
|
|
|
}
|
2025-09-18 23:46:41 -04:00
|
|
|
return simdRegBySize(v.Reg(), t.Size())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func simdRegBySize(reg int16, size int64) int16 {
|
|
|
|
|
switch size {
|
2025-03-31 10:45:23 +11:00
|
|
|
case 16:
|
2025-09-18 23:46:41 -04:00
|
|
|
return reg
|
2025-03-31 10:45:23 +11:00
|
|
|
case 32:
|
2025-09-18 23:46:41 -04:00
|
|
|
return reg + (x86.REG_Y0 - x86.REG_X0)
|
2025-03-31 10:45:23 +11:00
|
|
|
case 64:
|
2025-09-18 23:46:41 -04:00
|
|
|
return reg + (x86.REG_Z0 - x86.REG_X0)
|
2025-03-31 10:45:23 +11:00
|
|
|
}
|
2025-09-18 23:46:41 -04:00
|
|
|
panic("simdRegBySize: bad size")
|
2025-03-31 10:45:23 +11:00
|
|
|
}
|
|
|
|
|
|
2025-07-08 20:12:24 +00:00
|
|
|
// XXX k mask
|
|
|
|
|
func maskReg(v *ssa.Value) int16 {
|
|
|
|
|
t := v.Type
|
|
|
|
|
if !t.IsSIMD() {
|
2025-07-09 22:33:25 +00:00
|
|
|
base.Fatalf("maskReg: not a simd type; v=%s, b=b%d, f=%s", v.LongString(), v.Block.ID, v.Block.Func.Name)
|
2025-07-08 20:12:24 +00:00
|
|
|
}
|
|
|
|
|
switch t.Size() {
|
|
|
|
|
case 8:
|
|
|
|
|
return v.Reg()
|
|
|
|
|
}
|
|
|
|
|
panic("unreachable")
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-09 22:33:25 +00:00
|
|
|
// XXX k mask + vec
|
|
|
|
|
func simdOrMaskReg(v *ssa.Value) int16 {
|
|
|
|
|
t := v.Type
|
|
|
|
|
if t.Size() <= 8 {
|
|
|
|
|
return maskReg(v)
|
|
|
|
|
}
|
|
|
|
|
return simdReg(v)
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-24 03:59:30 +00:00
|
|
|
// XXX this is used for shift operations only.
|
|
|
|
|
// regalloc will issue OpCopy with incorrect type, but the assigned
|
|
|
|
|
// register should be correct, and this function is merely checking
|
|
|
|
|
// the sanity of this part.
|
|
|
|
|
func simdCheckRegOnly(v *ssa.Value, regStart, regEnd int16) int16 {
|
|
|
|
|
if v.Reg() > regEnd || v.Reg() < regStart {
|
|
|
|
|
panic("simdCheckRegOnly: not the desired register")
|
|
|
|
|
}
|
|
|
|
|
return v.Reg()
|
|
|
|
|
}
|