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: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent b3309877
......@@ -50,11 +50,6 @@ type Optab struct {
pcrelsiz uint8
}
type Oprang struct {
start []Optab
stop []Optab
}
type Opcross [32][2][32]uint8
const (
......@@ -270,9 +265,9 @@ var pool struct {
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
......@@ -563,7 +558,7 @@ func span5(ctxt *obj.Link, cursym *obj.LSym) {
return
}
if oprange[AAND&obj.AMask].start == nil {
if oprange[AAND&obj.AMask] == nil {
buildop(ctxt)
}
......@@ -1174,7 +1169,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 {
......@@ -1194,38 +1189,30 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
if p.Reg != 0 {
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']*/
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)
}
e := oprange[r].stop
c1 := xcmp[a1][:]
c3 := xcmp[a3][:]
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 {
p.Optab = uint16((-cap(o) + cap(optab)) + 1)
return &o[0]
}
}
ops := oprange[p.As&obj.AMask]
c1 := &xcmp[a1]
c3 := &xcmp[a3]
for i := range ops {
op := &ops[i]
if int(op.a2) == a2 && 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)
ctxt.Diag("from %d %d to %d %d\n", p.From.Type, p.From.Name, p.To.Type, p.To.Name)
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 {
......@@ -1329,7 +1316,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
}
}
}
......@@ -1347,11 +1334,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 {
......
......@@ -310,14 +310,9 @@ var optab = []Optab{
{obj.AXXX, 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 span0(ctxt *obj.Link, cursym *obj.LSym) {
p := cursym.Text
......@@ -327,7 +322,7 @@ func span0(ctxt *obj.Link, cursym *obj.LSym) {
ctxt.Cursym = cursym
ctxt.Autosize = int32(p.To.Offset + 8)
if oprange[AOR&obj.AMask].start == nil {
if oprange[AOR&obj.AMask] == nil {
buildop(ctxt)
}
......@@ -610,7 +605,7 @@ func prasm(p *obj.Prog) {
}
func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
if oprange[AOR&obj.AMask].start == nil {
if oprange[AOR&obj.AMask] == nil {
buildop(ctxt)
}
......@@ -638,32 +633,24 @@ func oplook(ctxt *obj.Link, p *obj.Prog) *Optab {
}
//print("oplook %P %d %d %d\n", p, a1, a2, a3);
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][:]
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 {
p.Optab = uint16((-cap(o) + cap(optab)) + 1)
return &o[0]
}
}
ops := oprange[p.As&obj.AMask]
c1 := &xcmp[a1]
c3 := &xcmp[a3]
for i := range ops {
op := &ops[i]
if int(op.a2) == a2 && 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", obj.Aconv(p.As), DRconv(a1), DRconv(a2), DRconv(a3))
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 {
......@@ -788,7 +775,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
}
}
}
......@@ -798,11 +785,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