]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: move duffcopy auxint calculation out of rewrite rules
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 23 Apr 2020 20:11:00 +0000 (13:11 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 24 Apr 2020 23:56:54 +0000 (23:56 +0000)
Package amd64 is a more natural home for it.
It also makes it easier to see how many bytes
are being copied in ssa.html.

Passes toolstash-check.

Change-Id: I5ecf0f0f18e8db2faa2caf7a05028c310952bd94
Reviewed-on: https://go-review.googlesource.com/c/go/+/229703
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/amd64/ssa.go
src/cmd/compile/internal/ssa/gen/AMD64.rules
src/cmd/compile/internal/ssa/gen/AMD64Ops.go
src/cmd/compile/internal/ssa/rewriteAMD64.go

index 71b42b09a7210c5e912aad121c567b2acb56c91e..2b75bd6549900eb9370c97890119fcf65dee12cf 100644 (file)
@@ -872,7 +872,16 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p := s.Prog(obj.ADUFFCOPY)
                p.To.Type = obj.TYPE_ADDR
                p.To.Sym = gc.Duffcopy
-               p.To.Offset = v.AuxInt
+               if v.AuxInt%16 != 0 {
+                       v.Fatalf("bad DUFFCOPY AuxInt %v", v.AuxInt)
+               }
+               p.To.Offset = 14 * (64 - v.AuxInt/16)
+               // 14 and 64 are magic constants.  14 is the number of bytes to encode:
+               //      MOVUPS  (SI), X0
+               //      ADDQ    $16, SI
+               //      MOVUPS  X0, (DI)
+               //      ADDQ    $16, DI
+               // and 64 is the number of such blocks. See src/runtime/duff_amd64.s:duffcopy.
 
        case ssa.OpCopy: // TODO: use MOVQreg for reg->reg copies instead of OpCopy?
                if v.Type.IsMemory() {
index 0b02301c7d55bf349d51e5be4aa3c14ed115a69b..7538ce9f721f87e182aab0f5807082819f52dfcd 100644 (file)
 (Move [s] dst src mem)
        && s > 64 && s <= 16*64 && s%16 == 0
        && !config.noDuffDevice && logLargeCopy(v, s) =>
-       (DUFFCOPY [14*(64-s/16)] dst src mem)
-// 14 and 64 are magic constants.  14 is the number of bytes to encode:
-//     MOVUPS  (SI), X0
-//     ADDQ    $16, SI
-//     MOVUPS  X0, (DI)
-//     ADDQ    $16, DI
-// and 64 is the number of such blocks. See src/runtime/duff_amd64.s:duffcopy.
+       (DUFFCOPY [s] dst src mem)
 
 // Large copying uses REP MOVSQ.
 (Move [s] dst src mem) && (s > 16*64 || config.noDuffDevice) && s%8 == 0 && logLargeCopy(v, s) =>
index be4a0bf805d86114037d2bf8730b0a1b832992c5..144e76fea7e0e16dc3aa9535ac1d4020fb73ce84 100644 (file)
@@ -681,7 +681,7 @@ func init() {
                // arg0 = destination pointer
                // arg1 = source pointer
                // arg2 = mem
-               // auxint = offset from duffcopy symbol to call
+               // auxint = # of bytes to copy, must be multiple of 16
                // returns memory
                {
                        name:      "DUFFCOPY",
index 9f486091119bb4ee9b8b2abce9c62f8fa3d3865d..5f3d4e5b90d8a363203f17ba0a7d62905b713236 100644 (file)
@@ -31641,7 +31641,7 @@ func rewriteValueAMD64_OpMove(v *Value) bool {
        }
        // match: (Move [s] dst src mem)
        // cond: s > 64 && s <= 16*64 && s%16 == 0 && !config.noDuffDevice && logLargeCopy(v, s)
-       // result: (DUFFCOPY [14*(64-s/16)] dst src mem)
+       // result: (DUFFCOPY [s] dst src mem)
        for {
                s := auxIntToInt64(v.AuxInt)
                dst := v_0
@@ -31651,7 +31651,7 @@ func rewriteValueAMD64_OpMove(v *Value) bool {
                        break
                }
                v.reset(OpAMD64DUFFCOPY)
-               v.AuxInt = int64ToAuxInt(14 * (64 - s/16))
+               v.AuxInt = int64ToAuxInt(s)
                v.AddArg3(dst, src, mem)
                return true
        }