From: Josh Bleecher Snyder Date: Tue, 19 Mar 2019 17:40:52 +0000 (-0700) Subject: cmd/internal/obj/x86: slightly optimize ADJSP encoding X-Git-Tag: go1.13beta1~971 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cb8aefd3b06f39679ebe1abbd38abef52cbd76b7;p=gostls13.git cmd/internal/obj/x86: slightly optimize ADJSP encoding 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 TryBot-Result: Gobot Gobot Reviewed-by: Martin Möhrmann --- diff --git a/src/cmd/internal/obj/x86/asm6.go b/src/cmd/internal/obj/x86/asm6.go index 305fcc4952..91a2fc22ff 100644 --- a/src/cmd/internal/obj/x86/asm6.go +++ b/src/cmd/internal/obj/x86/asm6.go @@ -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: