]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/x86: slightly optimize ADJSP encoding
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 19 Mar 2019 17:40:52 +0000 (10:40 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 19 Mar 2019 22:10:06 +0000 (22:10 +0000)
This shaves a few bytes off here and there.

file    before    after     Δ       %
buildid 2865992   2861896   -4096   -0.143%
pprof   14744060  14739964  -4096   -0.028%
trace   11680644  11676548  -4096   -0.035%
vet     8448240   8444144   -4096   -0.048%

Change-Id: I799034afabc06a37b535301cd1380d63b4461095
Reviewed-on: https://go-review.googlesource.com/c/go/+/168343
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <martisch@uos.de>
src/cmd/internal/obj/x86/asm6.go

index 305fcc49525ada2b4bd9c2b6de4e60d73e00d272..91a2fc22ff368b2a398a97c6494e8193ca139d79 100644 (file)
@@ -1864,10 +1864,14 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
                if p.As == AADJSP {
                        p.To.Type = obj.TYPE_REG
                        p.To.Reg = REG_SP
+                       // Generate 'ADDQ $x, SP' or 'SUBQ $x, SP', with x positive.
+                       // One exception: It is smaller to encode $-0x80 than $0x80.
+                       // For that case, flip the sign and the op:
+                       // Instead of 'ADDQ $0x80, SP', generate 'SUBQ $-0x80, SP'.
                        switch v := p.From.Offset; {
                        case v == 0:
                                p.As = obj.ANOP
-                       case v < 0:
+                       case v == 0x80 || (v < 0 && v != -0x80):
                                p.As = spadjop(ctxt, AADDL, AADDQ)
                                p.From.Offset *= -1
                        default: