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 {
scond uint16
}
type Oprange struct {
start []Optab
stop []Optab
}
var oprange [ALAST]Oprange
var oprange [ALAST][]Optab
var xcmp [C_NCLASS][C_NCLASS]uint8
var xcmp [C_NCLASS][C_NCLASS]bool
const (
S32 = 0 << 31
......@@ -532,7 +527,7 @@ func span7(ctxt *obj.Link, cursym *obj.LSym) {
ctxt.Cursym = cursym
ctxt.Autosize = int32(p.To.Offset&0xffffffff) + 8
if oprange[AAND].start == nil {
if oprange[AAND] == nil {
buildop(ctxt)
}
......@@ -1112,41 +1107,31 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
if p.Reg != 0 {
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 {
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)
}
e := oprange[r].stop
c1 := xcmp[a1][:]
c2 := xcmp[a2][:]
c3 := xcmp[a3][:]
c4 := xcmp[p.Scond>>5][:]
for ; -cap(o) < -cap(e); o = o[1:] {
if int(o[0].a2) == a2 || c2[o[0].a2] != 0 {
if c4[o[0].scond>>5] != 0 {
if c1[o[0].a1] != 0 {
if c3[o[0].a3] != 0 {
p.Optab = uint16((-cap(o) + cap(optab)) + 1)
return &o[0]
}
}
}
ops := oprange[p.As]
c1 := &xcmp[a1]
c2 := &xcmp[a2]
c3 := &xcmp[a3]
c4 := &xcmp[p.Scond>>5]
for i := range ops {
op := &ops[i]
if (int(op.a2) == a2 || c2[op.a2]) && c4[op.scond>>5] && c1[op.a1] && c3[op.a3] {
p.Optab = uint16(cap(optab) - cap(ops) + i + 1)
return op
}
}
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)
if o == nil {
o = optab
if ops == nil {
ops = optab
}
return &o[0]
return &ops[0]
}
func cmp(a int, b int) bool {
......@@ -1333,7 +1318,7 @@ func buildop(ctxt *obj.Link) {
for i := 0; i < C_GOK; i++ {
for n = 0; n < C_GOK; n++ {
if cmp(n, i) {
xcmp[i][n] = 1
xcmp[i][n] = true
}
}
}
......@@ -1341,16 +1326,15 @@ func buildop(ctxt *obj.Link) {
}
sort.Sort(ocmp(optab[:n]))
var r int
var t Oprange
for i := 0; i < n; i++ {
r = int(optab[i].as)
oprange[r].start = optab[i:]
start := i
for int(optab[i].as) == r {
i++
}
oprange[r].stop = optab[i:]
t := optab[start:i]
i--
t = oprange[r]
oprange[r] = t
switch r {
default:
ctxt.Diag("unknown op in build: %v", obj.Aconv(r))
......
......@@ -403,14 +403,9 @@ var optab = []Optab{
{obj.AXXX, C_NONE, C_NONE, C_NONE, C_NONE, 0, 4, 0},
}
type Oprang struct {
start []Optab
stop []Optab
}
var oprange [ALAST & obj.AMask]Oprang
var oprange [ALAST & obj.AMask][]Optab
var xcmp [C_NCLASS][C_NCLASS]uint8
var xcmp [C_NCLASS][C_NCLASS]bool
func span9(ctxt *obj.Link, cursym *obj.LSym) {
p := cursym.Text
......@@ -420,7 +415,7 @@ func span9(ctxt *obj.Link, cursym *obj.LSym) {
ctxt.Cursym = cursym
ctxt.Autosize = int32(p.To.Offset)
if oprange[AANDN&obj.AMask].start == nil {
if oprange[AANDN&obj.AMask] == nil {
buildop(ctxt)
}
......@@ -731,7 +726,7 @@ func prasm(p *obj.Prog) {
func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
a1 := int(p.Optab)
if a1 != 0 {
return &optab[a1-1:][0]
return &optab[a1-1]
}
a1 = int(p.From.Class)
if a1 == 0 {
......@@ -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);
r0 := p.As & obj.AMask
o := oprange[r0].start
if o == nil {
o = oprange[r0].stop /* just generate an error */
}
e := oprange[r0].stop
c1 := xcmp[a1][:]
c3 := xcmp[a3][:]
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]
}
}
}
ops := oprange[p.As&obj.AMask]
c1 := &xcmp[a1]
c3 := &xcmp[a3]
c4 := &xcmp[a4]
for i := range ops {
op := &ops[i]
if int(op.a2) == a2 && c1[op.a1] && c3[op.a3] && c4[op.a4] {
p.Optab = uint16(cap(optab) - cap(ops) + i + 1)
return op
}
}
ctxt.Diag("illegal combination %v %v %v %v %v", obj.Aconv(int(p.As)), DRconv(a1), DRconv(a2), DRconv(a3), DRconv(a4))
prasm(p)
if o == nil {
o = optab
if ops == nil {
ops = optab
}
return &o[0]
return &ops[0]
}
func cmp(a int, b int) bool {
......@@ -916,7 +900,7 @@ func buildop(ctxt *obj.Link) {
for i := 0; i < C_NCLASS; i++ {
for n = 0; n < C_NCLASS; n++ {
if cmp(n, i) {
xcmp[i][n] = 1
xcmp[i][n] = true
}
}
}
......@@ -926,11 +910,11 @@ func buildop(ctxt *obj.Link) {
for i := 0; i < n; i++ {
r := optab[i].as
r0 := r & obj.AMask
oprange[r0].start = optab[i:]
start := i
for optab[i].as == r {
i++
}
oprange[r0].stop = optab[i:]
oprange[r0] = optab[start:i]
i--
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