Commit 78934420 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/internal/obj: simplify Optab range handling code

Use slices as slices, instead of as clumsy pointers.

Passes toolstash/buildall.

Change-Id: If09eacc2d8805d7d5eaa5566f9b6305541074371
Reviewed-on: https://go-review.googlesource.com/20322
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 42f07ff2
...@@ -58,14 +58,9 @@ type Optab struct { ...@@ -58,14 +58,9 @@ type Optab struct {
scond uint16 scond uint16
} }
type Oprange struct { var oprange [ALAST][]Optab
start []Optab
stop []Optab
}
var oprange [ALAST]Oprange
var xcmp [C_NCLASS][C_NCLASS]uint8 var xcmp [C_NCLASS][C_NCLASS]bool
const ( const (
S32 = 0 << 31 S32 = 0 << 31
...@@ -532,7 +527,7 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) { ...@@ -532,7 +527,7 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
ctxt.Cursym = cursym ctxt.Cursym = cursym
ctxt.Autosize = int32(p.To.Offset&0xffffffff) + 8 ctxt.Autosize = int32(p.To.Offset&0xffffffff) + 8
if oprange[AAND].start == nil { if oprange[AAND] == nil {
buildop(ctxt) buildop(ctxt)
} }
...@@ -1112,41 +1107,31 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab { ...@@ -1112,41 +1107,31 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
if p.Reg != 0 { if p.Reg != 0 {
a2 = rclass(p.Reg) a2 = rclass(p.Reg)
} }
r := int(p.As)
o := oprange[r].start
if o == nil {
o = oprange[r].stop /* just generate an error */
}
if false { if false {
fmt.Printf("oplook %v %d %d %d\n", obj.Aconv(int(p.As)), a1, a2, a3) fmt.Printf("oplook %v %d %d %d\n", obj.Aconv(int(p.As)), a1, a2, a3)
fmt.Printf("\t\t%d %d\n", p.From.Type, p.To.Type) fmt.Printf("\t\t%d %d\n", p.From.Type, p.To.Type)
} }
e := oprange[r].stop ops := oprange[p.As]
c1 := xcmp[a1][:] c1 := &xcmp[a1]
c2 := xcmp[a2][:] c2 := &xcmp[a2]
c3 := xcmp[a3][:] c3 := &xcmp[a3]
c4 := xcmp[p.Scond>>5][:] c4 := &xcmp[p.Scond>>5]
for ; -cap(o) < -cap(e); o = o[1:] { for i := range ops {
if int(o[0].a2) == a2 || c2[o[0].a2] != 0 { op := &ops[i]
if c4[o[0].scond>>5] != 0 { if (int(op.a2) == a2 || c2[op.a2]) && c4[op.scond>>5] && c1[op.a1] && c3[op.a3] {
if c1[o[0].a1] != 0 { p.Optab = uint16(cap(optab) - cap(ops) + i + 1)
if c3[o[0].a3] != 0 { return op
p.Optab = uint16((-cap(o) + cap(optab)) + 1)
return &o[0]
}
}
}
} }
} }
ctxt.Diag("illegal combination %v %v %v %v, %d %d", p, DRconv(a1), DRconv(a2), DRconv(a3), p.From.Type, p.To.Type) ctxt.Diag("illegal combination %v %v %v %v, %d %d", p, DRconv(a1), DRconv(a2), DRconv(a3), p.From.Type, p.To.Type)
prasm(p) prasm(p)
if o == nil { if ops == nil {
o = optab ops = optab
} }
return &o[0] return &ops[0]
} }
func cmp(a int, b int) bool { func cmp(a int, b int) bool {
...@@ -1333,7 +1318,7 @@ func buildop(ctxt *obj.Link) { ...@@ -1333,7 +1318,7 @@ func buildop(ctxt *obj.Link) {
for i := 0; i < C_GOK; i++ { for i := 0; i < C_GOK; i++ {
for n = 0; n < C_GOK; n++ { for n = 0; n < C_GOK; n++ {
if cmp(n, i) { if cmp(n, i) {
xcmp[i][n] = 1 xcmp[i][n] = true
} }
} }
} }
...@@ -1341,16 +1326,15 @@ func buildop(ctxt *obj.Link) { ...@@ -1341,16 +1326,15 @@ func buildop(ctxt *obj.Link) {
} }
sort.Sort(ocmp(optab[:n])) sort.Sort(ocmp(optab[:n]))
var r int var r int
var t Oprange
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
r = int(optab[i].as) r = int(optab[i].as)
oprange[r].start = optab[i:] start := i
for int(optab[i].as) == r { for int(optab[i].as) == r {
i++ i++
} }
oprange[r].stop = optab[i:] t := optab[start:i]
i-- i--
t = oprange[r] oprange[r] = t
switch r { switch r {
default: default:
ctxt.Diag("unknown op in build: %v", obj.Aconv(r)) ctxt.Diag("unknown op in build: %v", obj.Aconv(r))
......
...@@ -403,14 +403,9 @@ var optab = []Optab{ ...@@ -403,14 +403,9 @@ var optab = []Optab{
{obj.AXXX, C_NONE, C_NONE, C_NONE, C_NONE, 0, 4, 0}, {obj.AXXX, C_NONE, C_NONE, C_NONE, C_NONE, 0, 4, 0},
} }
type Oprang struct { var oprange [ALAST & obj.AMask][]Optab
start []Optab
stop []Optab
}
var oprange [ALAST & obj.AMask]Oprang
var xcmp [C_NCLASS][C_NCLASS]uint8 var xcmp [C_NCLASS][C_NCLASS]bool
func span9(ctxt *obj.Link, cursym *obj.LSym) { func span9(ctxt *obj.Link, cursym *obj.LSym) {
p := cursym.Text p := cursym.Text
...@@ -420,7 +415,7 @@ func span9(ctxt *obj.Link, cursym *obj.LSym) { ...@@ -420,7 +415,7 @@ func span9(ctxt *obj.Link, cursym *obj.LSym) {
ctxt.Cursym = cursym ctxt.Cursym = cursym
ctxt.Autosize = int32(p.To.Offset) ctxt.Autosize = int32(p.To.Offset)
if oprange[AANDN&obj.AMask].start == nil { if oprange[AANDN&obj.AMask] == nil {
buildop(ctxt) buildop(ctxt)
} }
...@@ -731,7 +726,7 @@ func prasm(p *obj.Prog) { ...@@ -731,7 +726,7 @@ func prasm(p *obj.Prog) {
func oplook(ctxt *obj.Link, p *obj.Prog) *Optab { func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
a1 := int(p.Optab) a1 := int(p.Optab)
if a1 != 0 { if a1 != 0 {
return &optab[a1-1:][0] return &optab[a1-1]
} }
a1 = int(p.From.Class) a1 = int(p.From.Class)
if a1 == 0 { if a1 == 0 {
...@@ -763,35 +758,24 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab { ...@@ -763,35 +758,24 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
} }
//print("oplook %v %d %d %d %d\n", p, a1, a2, a3, a4); //print("oplook %v %d %d %d %d\n", p, a1, a2, a3, a4);
r0 := p.As & obj.AMask ops := oprange[p.As&obj.AMask]
c1 := &xcmp[a1]
o := oprange[r0].start c3 := &xcmp[a3]
if o == nil { c4 := &xcmp[a4]
o = oprange[r0].stop /* just generate an error */ for i := range ops {
} op := &ops[i]
e := oprange[r0].stop if int(op.a2) == a2 && c1[op.a1] && c3[op.a3] && c4[op.a4] {
c1 := xcmp[a1][:] p.Optab = uint16(cap(optab) - cap(ops) + i + 1)
c3 := xcmp[a3][:] return op
c4 := xcmp[a4][:]
for ; -cap(o) < -cap(e); o = o[1:] {
if int(o[0].a2) == a2 {
if c1[o[0].a1] != 0 {
if c3[o[0].a3] != 0 {
if c4[o[0].a4] != 0 {
p.Optab = uint16((-cap(o) + cap(optab)) + 1)
return &o[0]
}
}
}
} }
} }
ctxt.Diag("illegal combination %v %v %v %v %v", obj.Aconv(int(p.As)), DRconv(a1), DRconv(a2), DRconv(a3), DRconv(a4)) ctxt.Diag("illegal combination %v %v %v %v %v", obj.Aconv(int(p.As)), DRconv(a1), DRconv(a2), DRconv(a3), DRconv(a4))
prasm(p) prasm(p)
if o == nil { if ops == nil {
o = optab ops = optab
} }
return &o[0] return &ops[0]
} }
func cmp(a int, b int) bool { func cmp(a int, b int) bool {
...@@ -916,7 +900,7 @@ func buildop(ctxt *obj.Link) { ...@@ -916,7 +900,7 @@ func buildop(ctxt *obj.Link) {
for i := 0; i < C_NCLASS; i++ { for i := 0; i < C_NCLASS; i++ {
for n = 0; n < C_NCLASS; n++ { for n = 0; n < C_NCLASS; n++ {
if cmp(n, i) { if cmp(n, i) {
xcmp[i][n] = 1 xcmp[i][n] = true
} }
} }
} }
...@@ -926,11 +910,11 @@ func buildop(ctxt *obj.Link) { ...@@ -926,11 +910,11 @@ func buildop(ctxt *obj.Link) {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
r := optab[i].as r := optab[i].as
r0 := r & obj.AMask r0 := r & obj.AMask
oprange[r0].start = optab[i:] start := i
for optab[i].as == r { for optab[i].as == r {
i++ i++
} }
oprange[r0].stop = optab[i:] oprange[r0] = optab[start:i]
i-- i--
switch r { switch r {
......
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