Commit 4fc02d17 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/internal/obj: more Optab range simplification

Same idea as golang.org/cl/20322.

Passes toolstash/buildall.

Change-Id: Ida5960e57ff6e1e8de75c2720f21aeae56a8e415
Reviewed-on: https://go-review.googlesource.com/20352
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent b3309877
...@@ -50,11 +50,6 @@ type Optab struct { ...@@ -50,11 +50,6 @@ type Optab struct {
pcrelsiz uint8 pcrelsiz uint8
} }
type Oprang struct {
start []Optab
stop []Optab
}
type Opcross [32][2][32]uint8 type Opcross [32][2][32]uint8
const ( const (
...@@ -270,9 +265,9 @@ var pool struct { ...@@ -270,9 +265,9 @@ var pool struct {
extra uint32 extra uint32
} }
var oprange [ALAST & obj.AMask]Oprang var oprange [ALAST & obj.AMask][]Optab
var xcmp [C_GOK + 1][C_GOK + 1]uint8 var xcmp [C_GOK + 1][C_GOK + 1]bool
var deferreturn *obj.LSym var deferreturn *obj.LSym
...@@ -563,7 +558,7 @@ func span5(ctxt *obj.Link, cursym *obj.LSym) { ...@@ -563,7 +558,7 @@ func span5(ctxt *obj.Link, cursym *obj.LSym) {
return return
} }
if oprange[AAND&obj.AMask].start == nil { if oprange[AAND&obj.AMask] == nil {
buildop(ctxt) buildop(ctxt)
} }
...@@ -1174,7 +1169,7 @@ func prasm(p *obj.Prog) { ...@@ -1174,7 +1169,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 {
...@@ -1194,38 +1189,30 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab { ...@@ -1194,38 +1189,30 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
if p.Reg != 0 { if p.Reg != 0 {
a2 = C_REG a2 = C_REG
} }
r := p.As & obj.AMask
o := oprange[r].start
if o == nil {
o = oprange[r].stop /* just generate an error */
}
if false { /*debug['O']*/ if false { /*debug['O']*/
fmt.Printf("oplook %v %v %v %v\n", obj.Aconv(p.As), DRconv(a1), DRconv(a2), DRconv(a3)) fmt.Printf("oplook %v %v %v %v\n", obj.Aconv(p.As), DRconv(a1), DRconv(a2), DRconv(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&obj.AMask]
c1 := xcmp[a1][:] c1 := &xcmp[a1]
c3 := xcmp[a3][:] c3 := &xcmp[a3]
for ; -cap(o) < -cap(e); o = o[1:] { for i := range ops {
if int(o[0].a2) == a2 { op := &ops[i]
if c1[o[0].a1] != 0 { if int(op.a2) == a2 && c1[op.a1] && c3[op.a3] {
if c3[o[0].a3] != 0 { p.Optab = uint16(cap(optab) - cap(ops) + i + 1)
p.Optab = uint16((-cap(o) + cap(optab)) + 1) return op
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)
ctxt.Diag("from %d %d to %d %d\n", p.From.Type, p.From.Name, p.To.Type, p.To.Name) ctxt.Diag("from %d %d to %d %d\n", p.From.Type, p.From.Name, p.To.Type, p.To.Name)
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 {
...@@ -1329,7 +1316,7 @@ func buildop(ctxt *obj.Link) { ...@@ -1329,7 +1316,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
} }
} }
} }
...@@ -1347,11 +1334,11 @@ func buildop(ctxt *obj.Link) { ...@@ -1347,11 +1334,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 {
......
...@@ -310,14 +310,9 @@ var optab = []Optab{ ...@@ -310,14 +310,9 @@ var optab = []Optab{
{obj.AXXX, C_NONE, C_NONE, C_NONE, 0, 4, 0}, {obj.AXXX, 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 span0(ctxt *obj.Link, cursym *obj.LSym) { func span0(ctxt *obj.Link, cursym *obj.LSym) {
p := cursym.Text p := cursym.Text
...@@ -327,7 +322,7 @@ func span0(ctxt *obj.Link, cursym *obj.LSym) { ...@@ -327,7 +322,7 @@ func span0(ctxt *obj.Link, cursym *obj.LSym) {
ctxt.Cursym = cursym ctxt.Cursym = cursym
ctxt.Autosize = int32(p.To.Offset + 8) ctxt.Autosize = int32(p.To.Offset + 8)
if oprange[AOR&obj.AMask].start == nil { if oprange[AOR&obj.AMask] == nil {
buildop(ctxt) buildop(ctxt)
} }
...@@ -610,7 +605,7 @@ func prasm(p *obj.Prog) { ...@@ -610,7 +605,7 @@ func prasm(p *obj.Prog) {
} }
func oplook(ctxt *obj.Link, p *obj.Prog) *Optab { func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
if oprange[AOR&obj.AMask].start == nil { if oprange[AOR&obj.AMask] == nil {
buildop(ctxt) buildop(ctxt)
} }
...@@ -638,32 +633,24 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab { ...@@ -638,32 +633,24 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
} }
//print("oplook %P %d %d %d\n", p, a1, a2, a3); //print("oplook %P %d %d %d\n", p, a1, a2, a3);
r0 := p.As & obj.AMask
o := oprange[r0].start ops := oprange[p.As&obj.AMask]
if o == nil { c1 := &xcmp[a1]
o = oprange[r0].stop /* just generate an error */ c3 := &xcmp[a3]
} for i := range ops {
e := oprange[r0].stop op := &ops[i]
c1 := xcmp[a1][:] if int(op.a2) == a2 && c1[op.a1] && c3[op.a3] {
c3 := xcmp[a3][:] p.Optab = uint16(cap(optab) - cap(ops) + i + 1)
for ; -cap(o) < -cap(e); o = o[1:] { return op
if int(o[0].a2) == a2 {
if c1[o[0].a1] != 0 {
if c3[o[0].a3] != 0 {
p.Optab = uint16((-cap(o) + cap(optab)) + 1)
return &o[0]
}
}
} }
} }
ctxt.Diag("illegal combination %v %v %v %v", obj.Aconv(p.As), DRconv(a1), DRconv(a2), DRconv(a3)) ctxt.Diag("illegal combination %v %v %v %v", obj.Aconv(p.As), DRconv(a1), DRconv(a2), DRconv(a3))
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 {
...@@ -788,7 +775,7 @@ func buildop(ctxt *obj.Link) { ...@@ -788,7 +775,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
} }
} }
} }
...@@ -798,11 +785,11 @@ func buildop(ctxt *obj.Link) { ...@@ -798,11 +785,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