cmd/internal/obj/x86: small refactoring

Replace some ints with bool and use arrays istead of slices where
possible.

Change-Id: I510bdaec48f9c437685e72c4a3291cffeb7ef5fc
Reviewed-on: https://go-review.googlesource.com/83859
Run-TryBot: Ilya Tocar <ilya.tocar@intel.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Ilya Tocar 2017-12-13 16:38:02 -06:00
parent 8fc25b531b
commit 4dc25ceda4
2 changed files with 15 additions and 15 deletions

View file

@ -1118,7 +1118,7 @@ var yextractps = []ytab{
*/ */
var optab = var optab =
/* as, ytab, andproto, opcode */ /* as, ytab, andproto, opcode */
[]Optab{ [...]Optab{
{obj.AXXX, nil, 0, [23]uint8{}}, {obj.AXXX, nil, 0, [23]uint8{}},
{AAAA, ynone, P32, [23]uint8{0x37}}, {AAAA, ynone, P32, [23]uint8{0x37}},
{AAAD, ynone, P32, [23]uint8{0xd5, 0x0a}}, {AAAD, ynone, P32, [23]uint8{0xd5, 0x0a}},
@ -2822,9 +2822,9 @@ type AsmBuf struct {
buf [100]byte buf [100]byte
off int off int
rexflag int rexflag int
vexflag int vexflag bool
rep int rep bool
repn int repn bool
lock bool lock bool
} }
@ -3559,7 +3559,7 @@ var bpduff2 = []byte{
// For details about vex prefix see: // For details about vex prefix see:
// https://en.wikipedia.org/wiki/VEX_prefix#Technical_description // https://en.wikipedia.org/wiki/VEX_prefix#Technical_description
func (asmbuf *AsmBuf) asmvex(ctxt *obj.Link, rm, v, r *obj.Addr, vex, opcode uint8) { func (asmbuf *AsmBuf) asmvex(ctxt *obj.Link, rm, v, r *obj.Addr, vex, opcode uint8) {
asmbuf.vexflag = 1 asmbuf.vexflag = true
rexR := 0 rexR := 0
if r != nil { if r != nil {
rexR = regrex[r.Reg] & Rxr rexR = regrex[r.Reg] & Rxr
@ -4814,12 +4814,12 @@ func (asmbuf *AsmBuf) asmins(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog) {
if ctxt.Headtype == objabi.Hnacl && ctxt.Arch.Family == sys.AMD64 { if ctxt.Headtype == objabi.Hnacl && ctxt.Arch.Family == sys.AMD64 {
if p.As == AREP { if p.As == AREP {
asmbuf.rep++ asmbuf.rep = true
return return
} }
if p.As == AREPN { if p.As == AREPN {
asmbuf.repn++ asmbuf.repn = true
return return
} }
@ -4876,14 +4876,14 @@ func (asmbuf *AsmBuf) asmins(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog) {
asmbuf.Put(naclmovs) asmbuf.Put(naclmovs)
} }
if asmbuf.rep != 0 { if asmbuf.rep {
asmbuf.Put1(0xf3) asmbuf.Put1(0xf3)
asmbuf.rep = 0 asmbuf.rep = false
} }
if asmbuf.repn != 0 { if asmbuf.repn {
asmbuf.Put1(0xf2) asmbuf.Put1(0xf2)
asmbuf.repn = 0 asmbuf.repn = false
} }
if asmbuf.lock { if asmbuf.lock {
@ -4893,10 +4893,10 @@ func (asmbuf *AsmBuf) asmins(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog) {
} }
asmbuf.rexflag = 0 asmbuf.rexflag = 0
asmbuf.vexflag = 0 asmbuf.vexflag = false
mark := asmbuf.Len() mark := asmbuf.Len()
asmbuf.doasm(ctxt, cursym, p) asmbuf.doasm(ctxt, cursym, p)
if asmbuf.rexflag != 0 && asmbuf.vexflag == 0 { if asmbuf.rexflag != 0 && !asmbuf.vexflag {
/* /*
* as befits the whole approach of the architecture, * as befits the whole approach of the architecture,
* the rex prefix must appear before the first opcode byte * the rex prefix must appear before the first opcode byte
@ -4924,7 +4924,7 @@ func (asmbuf *AsmBuf) asmins(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog) {
if int64(r.Off) < p.Pc { if int64(r.Off) < p.Pc {
break break
} }
if asmbuf.rexflag != 0 && asmbuf.vexflag == 0 { if asmbuf.rexflag != 0 && !asmbuf.vexflag {
r.Off++ r.Off++
} }
if r.Type == objabi.R_PCREL { if r.Type == objabi.R_PCREL {

View file

@ -2,7 +2,7 @@
package x86 package x86
var vexOptab = []Optab{ var vexOptab = [...]Optab{
{AANDNL, yvex_r3, Pvex, [23]uint8{vexNDS | vexLZ | vex0F38 | vexW0, 0xF2}}, {AANDNL, yvex_r3, Pvex, [23]uint8{vexNDS | vexLZ | vex0F38 | vexW0, 0xF2}},
{AANDNQ, yvex_r3, Pvex, [23]uint8{vexNDS | vexLZ | vex0F38 | vexW1, 0xF2}}, {AANDNQ, yvex_r3, Pvex, [23]uint8{vexNDS | vexLZ | vex0F38 | vexW1, 0xF2}},
{ABEXTRL, yvex_vmr3, Pvex, [23]uint8{vexNDS | vexLZ | vex0F38 | vexW0, 0xF7}}, {ABEXTRL, yvex_vmr3, Pvex, [23]uint8{vexNDS | vexLZ | vex0F38 | vexW0, 0xF7}},