Commit 21fa1481 authored by quasilyte's avatar quasilyte Committed by Brad Fitzpatrick

cmd/internal/obj/x86: add named consts for Prog.Back flags

Passes toolstash-check.

Change-Id: I7232ba43895a54b03cc328bb2e99c05c44eb6e8e
Reviewed-on: https://go-review.googlesource.com/107057Reviewed-by: default avatarIlya Tocar <ilya.tocar@intel.com>
Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com>
parent 393f84a1
...@@ -65,6 +65,19 @@ const ( ...@@ -65,6 +65,19 @@ const (
maxLoopPad = 0 maxLoopPad = 0
) )
// Bit flags that are used to express jump target properties.
const (
// branchBackwards marks targets that are located behind.
// Used to express jumps to loop headers.
branchBackwards = (1 << iota)
// branchShort marks branches those target is close,
// with offset is in -128..127 range.
branchShort
// branchLoopHead marks loop entry.
// Used to insert padding for misaligned loops.
branchLoopHead
)
type Optab struct { type Optab struct {
as obj.As as obj.As
ytab []ytab ytab []ytab
...@@ -2125,11 +2138,11 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) { ...@@ -2125,11 +2138,11 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
var count int64 // rough count of number of instructions var count int64 // rough count of number of instructions
for p := s.Func.Text; p != nil; p = p.Link { for p := s.Func.Text; p != nil; p = p.Link {
count++ count++
p.Back = 2 // use short branches first time through p.Back = branchShort // use short branches first time through
q = p.Pcond q = p.Pcond
if q != nil && (q.Back&2 != 0) { if q != nil && (q.Back&branchShort != 0) {
p.Back |= 1 // backward jump p.Back |= branchBackwards
q.Back |= 4 // loop head q.Back |= branchLoopHead
} }
if p.As == AADJSP { if p.As == AADJSP {
...@@ -2197,7 +2210,7 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) { ...@@ -2197,7 +2210,7 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
} }
} }
if (p.Back&4 != 0) && c&(loopAlign-1) != 0 { if (p.Back&branchLoopHead != 0) && c&(loopAlign-1) != 0 {
// pad with NOPs // pad with NOPs
v := -c & (loopAlign - 1) v := -c & (loopAlign - 1)
...@@ -2213,10 +2226,10 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) { ...@@ -2213,10 +2226,10 @@ func span6(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
// process forward jumps to p // process forward jumps to p
for q = p.Rel; q != nil; q = q.Forwd { for q = p.Rel; q != nil; q = q.Forwd {
v := int32(p.Pc - (q.Pc + int64(q.Isize))) v := int32(p.Pc - (q.Pc + int64(q.Isize)))
if q.Back&2 != 0 { // short if q.Back&branchShort != 0 {
if v > 127 { if v > 127 {
loop++ loop++
q.Back ^= 2 q.Back ^= branchShort
} }
if q.As == AJCXZL || q.As == AXBEGIN { if q.As == AJCXZL || q.As == AXBEGIN {
...@@ -4328,7 +4341,7 @@ func (ab *AsmBuf) doasm(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog) { ...@@ -4328,7 +4341,7 @@ func (ab *AsmBuf) doasm(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog) {
log.Fatalf("bad code") log.Fatalf("bad code")
} }
if p.Back&1 != 0 { if p.Back&branchBackwards != 0 {
v = q.Pc - (p.Pc + 2) v = q.Pc - (p.Pc + 2)
if v >= -128 && p.As != AXBEGIN { if v >= -128 && p.As != AXBEGIN {
if p.As == AJCXZL { if p.As == AJCXZL {
...@@ -4358,7 +4371,7 @@ func (ab *AsmBuf) doasm(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog) { ...@@ -4358,7 +4371,7 @@ func (ab *AsmBuf) doasm(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog) {
p.Forwd = q.Rel p.Forwd = q.Rel
q.Rel = p q.Rel = p
if p.Back&2 != 0 && p.As != AXBEGIN { // short if p.Back&branchShort != 0 && p.As != AXBEGIN {
if p.As == AJCXZL { if p.As == AJCXZL {
ab.Put1(0x67) ab.Put1(0x67)
} }
......
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