IFUPLAInstrDecodeAux.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Don Curry March 15, 1987 12:52:53 pm PST
DIRECTORY Core, CoreOps, IFUPLAInstrDecode, IO, PLAOps, REFBit, Rope, TerminalIO, WireIconExtras;
IFUPLAInstrDecodeAux: CEDAR PROGRAM
IMPORTS CoreOps, IO, PLAOps, REFBit, Rope, TerminalIO, WireIconExtras =
BEGIN
log:   IO.STREAM ← TerminalIO.CreateStream[];
PLA:   TYPE = PLAOps.PLA;
Term:   TYPE = PLAOps.Term;
ROPE:   TYPE = Rope.ROPE;
root:   ROPE = "InstrDecode";
plaRoot:  ROPE = Rope.Cat["IFUPLA", root];
PLAs:   TYPE = REF PLAsRec;
PLAsRec:  TYPE = RECORD[seq: SEQUENCE size: CARDINAL OF PLA];
main:   PLA ← InitMain[];
subs:   PLAs ← InitSubs[];
fields:   PLAs ← InitFields[];
nofSubPlas: INT = IFUPLAInstrDecode.InstrDecodeOutCount; -- 1;
InitMain: PROC RETURNS[pla: PLA] = {
pla ← PLAOps.ReadPLAFile[plaRoot.Cat[".ttt"], log, TRUE];
ShowPLA["Main ", pla];
TerminalIO.PutF["\n"]};
InitSubs: PROC RETURNS[plas: PLAs] = {
subTerms:  INT ← 0;
maxOuts:   INT ← 0;
phSize:   INT ← 0;
plas      ← NEW[PLAsRec[nofSubPlas]];
FOR index: INT IN [0..nofSubPlas) DO
plaName: ROPE ← IO.PutFR["%g%g", IO.rope[plaRoot], IO.int[index] ];
subpla: PLA ← PLAOps.ReadPLAFile[plaName.Cat[".ttt"], log, TRUE];
outs:  INT ← REFBit.Desc[subpla.out].bitForm.size;
terms:  INT ← subpla.termList.length;
plas[index]  ← subpla;
maxOuts   ← MAX[maxOuts, outs];
subTerms   ← subTerms + terms;
phSize   ← phSize  + PhSize[outs, terms];
ENDLOOP;
FOR index: INT IN [0..nofSubPlas) DO
ShowPLA[IO.PutFR["Sub%g ", IO.int[index]], plas[index]] ENDLOOP;
TerminalIO.PutF["MaxOuts: %3g\n", IO.int[maxOuts]];
TerminalIO.PutF["PhSize: %3g\n", IO.int[phSize]];
TerminalIO.PutF["SubTerms: %3g\n", IO.int[subTerms]];
TerminalIO.PutF["\n"]};
InitFields: PROC RETURNS[plas: PLAs] = {
subTerms:  INT ← 0;
maxOuts:   INT ← 0;
phSize:   INT ← 0;
format: PLAOps.Format ← REFBit.Desc[main.out].fieldForm;
plas      ← NEW[PLAsRec[format.size]];
TerminalIO.PutF["\n"];
FOR field: INT IN [0..format.size) DO
plas[field]   ← PLAOps.NewPLA[main.data, main.out];
plas[field].time  ← main.time;
plas[field].termList ← PLAOps.CopyTermListForField
[main.termList, format[field].firstBit, format[field].bitSize];
maxOuts   ← MAX[maxOuts, format[field].bitSize];
subTerms   ← subTerms + plas[field].termList.length;
phSize   ← phSize + PhSize[format[field].bitSize, plas[field].termList.length];
TerminalIO.PutF[(IF (field+1 MOD 10)=0 THEN "!" ELSE ".")];
ENDLOOP;
TerminalIO.PutF["\n"];
FOR field: INT IN [0..format.size) DO
ShowPLA[
IO.PutFR["Field%g", IO.int[field]], plas[field],
1, format[field].bitSize] ENDLOOP;
TerminalIO.PutF["MaxOuts: %3g\n", IO.int[maxOuts]];
TerminalIO.PutF["PhSize: %3g\n", IO.int[phSize]];
TerminalIO.PutF["SubTerms: %3g\n", IO.int[subTerms]];
TerminalIO.PutF["\n"]};
InitFields: PROC RETURNS[tLists: TLists] = {
subTerms:  INT ← 0;
maxOuts:   INT ← 0;
phSize:   INT ← 0;
maxOutTerms: INT ← 0;
maxTerms:  INT ← 0;
fields:    INT ← REFBit.Desc[main.out].fieldForm.size;
tLists      ← NEW[TListsRec[fields]];
format:    PLAOps.Format ← REFBit.Desc[main.out].fieldForm;
FOR field: INT IN [0..fields) DO
tLists[index]  ← PLAOps.CopyTermListForField
[main.termList, format[field].firstBit, format[field].bitSize];
maxOuts   ← MAX[maxOuts, format[field].bitSize];
subTerms   ← subTerms + tLists[index].length;
phSize   ← phSize + PhSize[format[field].bitSize, tLists[index].length];
ENDLOOP;
FOR index: INT IN [0..nofSubPlas) DO
ShowPLA[IO.PutFR["Sub%g", IO.int[index]], plas[index]] ENDLOOP;
TerminalIO.PutF["MaxOuts: %3g\n", IO.int[maxOuts]];
TerminalIO.PutF["PhSize: %3g\n", IO.int[phSize]];
TerminalIO.PutF["SubTerms: %3g\n", IO.int[subTerms]]};
ShowPLA: PROC[name: ROPE, pla: PLA, fields, outs: INT ← 0] = {
terms: INT ← pla.termList.length;
IF fields=0 THEN fields ← REFBit.Desc[pla.out].fieldForm.size;
IF outs=0  THEN outs ← REFBit.Desc[pla.out].bitForm.size;
TerminalIO.PutF["PLA:%5g Terms:%3g Outs:%3g/%3g PhSz:%3g",
IO.rope[name],
IO.int[terms],
IO.int[fields],
IO.int[outs],
IO.int[PhSize[outs, terms] ] ];
TerminalIO.PutF[" MxI/T:%2g MxT/O:%2g\n",
IO.int[MaxInsPerTerm[pla]],
IO.int[MaxTermsPerOut[pla]]]};
PhSize: PROC[outs, terms: INT] RETURNS[max: INT ← 0] =
{RETURN[outs + MAX[outs*2, terms]]};
MaxInsPerTerm: PROC[pla: PLA] RETURNS[max: INT ← 0] = {
bitFormat: PLAOps.Format ← REFBit.Desc[pla.data].bitForm;
FOR term: Term ← pla.termList.begin, term.next WHILE term#NIL DO
thisTermMax: INT ← 0;
FOR in: INT IN [0..bitFormat.size) DO
IF PLAOps.GetInQrt[term, bitFormat[in].firstBit]#dontcare
THEN thisTermMax ← thisTermMax+1 ENDLOOP;
max ← MAX[max, thisTermMax] ENDLOOP};
MaxTermsPerOut: PROC[pla: PLA] RETURNS[max: INT ← 0] = {
bitFormat: PLAOps.Format ← REFBit.Desc[pla.out].bitForm;
FOR out: INT IN [0..bitFormat.size) DO
thisOutMax: INT ← 0;
FOR term: Term ← pla.termList.begin, term.next WHILE term#NIL DO
IF PLAOps.GetOutQrt[term, bitFormat[out].firstBit]=one
THEN thisOutMax ← thisOutMax+1 ENDLOOP;
max ← MAX[max, thisOutMax] ENDLOOP};
CheckConsistancyOfInstrDecodePLAs: PROC[plas: PLAs] = {
DeCONS: PROC[rope: ROPE, list: LIST OF ROPE]
RETURNS[LIST OF ROPE] = {
IF Rope.Equal[rope, list.first] THEN RETURN[list.rest];
FOR temp: LIST OF ROPE ← list, temp.rest WHILE temp.rest#NIL DO
IF NOT Rope.Equal[rope, temp.rest.first] THEN LOOP;
temp.rest ← temp.rest.rest;
EXIT REPEAT FINISHED => TerminalIO.PutF
["\n ERROR: %g not driven by any of the Instruction Decode PLA's", IO.rope[rope]]
ENDLOOP;
RETURN[list]};
main:  Core.Wire ← WireIconExtras.RecWire[plaRoot.Cat[".", root, "Out"]];
outlist: LIST OF ROPE;
FOR index: INT IN [0..nofSubPlas) DO
sub: Core.Wire ← WireIconExtras.RefWire[plas[index].out, "SubPLAOut"];
FOR field: INT IN [0..sub.size) DO
outlist ← CONS[CoreOps.GetShortWireName[sub[field]], outlist] ENDLOOP ENDLOOP;
FOR field: INT IN [0..main.size) DO
outlist ← DeCONS[CoreOps.GetShortWireName[main[field]], outlist] ENDLOOP;
IF outlist#NIL THEN ERROR}; -- main pla did not define these outputs
END.