Commit cb8aefd3 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMartin Möhrmann <martisch@uos.de>
parent 250b96a7
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment