Skip to content

Commit

Permalink
cmd/compile: optimize 386's assembly generator
Browse files Browse the repository at this point in the history
The ADDconstmodify has similar logic with other constmodify like
instructions. This CL optimize them to share code via fallthrough.
And the size of pkg/linux_386/cmd/compile/internal/x86.a decreases
about 0.3KB.

Change-Id: Ibdf06228afde875e8fe8e30851b50ca2be513dd9
Reviewed-on: https://go-review.googlesource.com/136398
Run-TryBot: Ben Shi <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
benshi001 committed Sep 20, 2018
1 parent 048c766 commit 9a033bf
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/cmd/compile/internal/x86/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,22 +547,22 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
p.To.Reg = v.Args[0].Reg()
gc.AddAux(&p.To, v)
case ssa.Op386ADDLconstmodify:
var p *obj.Prog = nil
sc := v.AuxValAndOff()
off := sc.Off()
val := sc.Val()
if val == 1 {
p = s.Prog(x86.AINCL)
} else if val == -1 {
p = s.Prog(x86.ADECL)
} else {
p = s.Prog(v.Op.Asm())
p.From.Type = obj.TYPE_CONST
p.From.Offset = val
if val == 1 || val == -1 {
var p *obj.Prog
if val == 1 {
p = s.Prog(x86.AINCL)
} else {
p = s.Prog(x86.ADECL)
}
off := sc.Off()
p.To.Type = obj.TYPE_MEM
p.To.Reg = v.Args[0].Reg()
gc.AddAux2(&p.To, v, off)
break
}
p.To.Type = obj.TYPE_MEM
p.To.Reg = v.Args[0].Reg()
gc.AddAux2(&p.To, v, off)
fallthrough
case ssa.Op386ANDLconstmodify, ssa.Op386ORLconstmodify, ssa.Op386XORLconstmodify:
sc := v.AuxValAndOff()
off := sc.Off()
Expand Down

0 comments on commit 9a033bf

Please sign in to comment.