1 package edu.berkeley.fleet.marina;
2 import com.sun.electric.tool.simulation.test.*;
3 import edu.berkeley.fleet.api.*;
4 import edu.berkeley.fleet.api.BitVector;
5 import edu.berkeley.fleet.two.*;
6 import edu.berkeley.fleet.*;
9 public class Marina extends FleetTwoFleet {
11 MarinaShip fakeShip = new MarinaShip(this);
12 MarinaDock onlyDock = new MarinaDock(fakeShip, true);
14 public BitVector encodeInstruction(Dock dispatchFrom, Instruction instruction) {
15 return encodeInstruction(instruction, dispatchFrom);
18 public Iterator<Ship> iterator() {
19 HashSet hs = new HashSet<Ship>();
24 public Ship getShip(String type, int ordinal) {
25 throw new RuntimeException("not implemented");
28 public FleetProcess run(Instruction[] instructions) {
29 throw new RuntimeException("not implemented");
32 public BitVector getDestAddr(Path path) {
33 if (path==null) return new BitVector(0);
34 return ((MarinaPath)path).bv;
37 public Dock getOnlyDock() {
41 ////////////////////////////////////////////////////////////////////////////////
45 private final Indenter indenter;
47 public final ChainControl controlChain;
48 public final ChainControl dataChain;
49 public final ChainControl dukeChain;
50 public final ChainControl reportChain;
52 private final ChipModel model;
53 public final ProperStopper northRing;
54 public final InstructionStopper southRing;
58 public Marina(ChainControl controlChain,
59 ChainControl dataChain,
60 ChainControl dukeChain,
61 ChainControl reportChain,
65 // use "internal encoding"
68 this.controlChain = controlChain;
69 this.dataChain = dataChain;
70 this.dukeChain = dukeChain;
71 this.reportChain = reportChain;
73 this.indenter = indenter;
74 northRing = new ProperStopper(prefix+"northFif@1.fillDrai@1",
81 southRing = new InstructionStopper(prefix+"southFif@1.tapPropS@1",
90 public static final int INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE = 5;
91 public static final int INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO = MarinaPath.SIGNAL_BIT_INDEX;
93 private static final int COUNTER_LENGTH = 34;
94 public static final int INSTRUCTION_LENGTH = 36;
95 public static final int SOUTH_RING_CAPACITY = 11;
96 public static final int TOKEN_FIFO_CAPACITY = 3;
97 public static final boolean kesselsCounter = false;
98 public static final boolean omegaCounter = false;
99 public static final String DATA_CHAIN = kesselsCounter ? "marina.marina_data" : "marina.ivan_data";
100 public static final String CONTROL_CHAIN = kesselsCounter ? "marina.marina_control" : "marina.ivan_control";
101 public static final String REPORT_CHAIN = kesselsCounter ? "marina.marina_report" : "marina.ivan_report";
102 public static final String DUKE_CHAIN = "marina.duke";
104 public static String prefix = "marinaGu@0.outDockW@"+(kesselsCounter?"3":"0")+".marinaOu@"+(kesselsCounter?"1":"0")+".";
105 public static String MASTER_CLEAR = "mc";
107 private static final String CENTER_PATH = prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0";
108 private static final String OLC_PATH_EVEN = CENTER_PATH+".olcWcont@0.scanEx3h@1"; // bits 2,4,6
109 private static final String OLC_PATH_ODD = CENTER_PATH+".olcWcont@0.scanEx3h@2"; // bits 1,3,5
110 private static final String OLC_PATH_KESSEL = CENTER_PATH+".counte@0.adamScan@1.scanEx6h@";
111 private static final String ILC_PATH_ODD = CENTER_PATH+".ilcMoveO@0.scanEx4h@0"; // bits 1,3,5,7
112 private static final String ILC_PATH_EVEN = CENTER_PATH+".ilcMoveO@0.scanEx4h@1"; // bits 2,4,6,8
113 private static final String FLAGS_PATH = CENTER_PATH+".flags@0.scanEx3h@0";
114 private static final String TOK_FIFO_PATH = prefix+"tokenFIF@1";
115 private static final String INSTRUCTION_COUNTER_PATH = prefix+"southFif@1.tapPropS@1.instruct@0";
116 private static final String DATA_COUNTER_PATH =prefix+"northFif@1.fillDrai@1.instruct@0";
117 private static final String TOK_PRED_PATH = CENTER_PATH+".ilcMoveO@0.scanEx2h@0.scanCell@10";
119 // ILC appears in scan chain as "count[1:6], zLo, i, dLo"
121 // value is bit reversed and complemented
124 reportChain.shift(REPORT_CHAIN, true, false);
125 com.sun.electric.tool.simulation.test.BitVector odd = reportChain.getOutBits(REPORT_CHAIN+"."+ILC_PATH_ODD).bitReverse().not();
126 com.sun.electric.tool.simulation.test.BitVector even = reportChain.getOutBits(REPORT_CHAIN+"."+ILC_PATH_EVEN).bitReverse().not();
127 com.sun.electric.tool.simulation.test.BitVector ret = new com.sun.electric.tool.simulation.test.BitVector(8, "olc");
128 for(int i=0; i<4; i++) {
129 ret.set(i*2+1, odd.get(i));
130 ret.set(i*2, even.get(i));
132 value = (int)ret.toLong();
134 /** Get the inner loop counter done bit. */
135 public boolean getDone() {
136 return (value & 0x40) != 0;
138 /** Get the inner loop counter infinity bit */
139 public boolean getInfinity() {
140 return (value & 0x80) != 0;
142 /** Get the 6 bits of count of the inner loop counter */
143 public int getCount() {
146 public String toString() {
147 return "[ilc, count="+getCount()+", infinity="+getInfinity()+", done="+getDone()+"]";
151 public void stopAndResetCounters() {
152 southRing.setCounterEnable(false);
153 northRing.setCounterEnable(false);
154 dataChain.shift(DATA_CHAIN, true, false);
155 northCount = northRing.getCounterValue();
156 southCount = southRing.getCounterValue();
157 northRing.setCounterValue(0);
158 southRing.setCounterValue(0);
160 public void startCounters() { startCounters(true, true); }
161 public void startCounters(boolean south, boolean north) {
162 southRing.setCounterEnable(south);
163 northRing.setCounterEnable(north);
165 public int getNorthCount() { return northCount; }
166 public int getSouthCount() { return southCount; }
168 public void masterClear() {
169 final double WIDTH = 10; // ns
170 // Put a high going pulse on the internal chip master clear signal
171 if (model instanceof VerilogModel) {
176 VerilogModel vm = (VerilogModel)model;
178 // In real life the flags come up with some undefined
179 // value. In verilog we need to prevent the X'es from
180 // propagating, so we force the flags to a known value
182 vm.setNodeState(CENTER_PATH+".flag_A__set_", 0);
183 vm.setNodeState(CENTER_PATH+".flag_A__clr_", 1);
184 vm.setNodeState(CENTER_PATH+".flag_B__set_", 0);
185 vm.setNodeState(CENTER_PATH+".flag_B__clr_", 1);
187 vm.setNodeState(CENTER_PATH+".flag_D__set_", 1);
188 vm.setNodeState(CENTER_PATH+".flag_D__clr_", 0);
190 vm.setNodeState(CENTER_PATH+".flags@0.aFlag@0.net_50", 0); // A
191 vm.setNodeState(CENTER_PATH+".flags@0.aFlag@1.net_50", 0); // B
192 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.litDandP@0.latch2in@0.hi2inLat@0.latchKee@0.out_B_", 0); // C
194 // possible C-flag inputs
195 vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE+1)+"]", 0);
196 vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO+1)+"]", 0);
198 // force the OLC to zero
200 for(int i=1; i<=6; i++)
201 vm.setNodeState(CENTER_PATH+".olcWcont@0.olc@0.inLO["+i+"]", (i==1)?0:1);
203 // set the ILC input to 1
204 for(int i=1; i<=8; i++) {
206 vm.setNodeState(CENTER_PATH+".ilcMoveO@0.ilc@0.\\inLO["+i+"]", (i==1)?0:1);
209 vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire", 1);
211 vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire", 0);
214 vm.setNodeState(MASTER_CLEAR, 1);
216 vm.setNodeState(MASTER_CLEAR, 0);
219 // pulse ilc[load] and olc[load]
220 vm.setNodeState(CENTER_PATH+".ilcMoveO@0.ilc@0.ilc_load_", 1);
221 vm.setNodeState(CENTER_PATH+".ilcMoveO@0.ilc@0.ilc_decLO_", 1);
222 vm.setNodeState(CENTER_PATH+".ilcMoveO@0.ilc@0.ilc_torpLO_", 1);
224 vm.setNodeState(CENTER_PATH+".olcWcont@0.olc@0.olc_load_", 1);
227 vm.releaseNode(CENTER_PATH+".ilcMoveO@0.ilc@0.ilc_load_");
228 vm.releaseNode(CENTER_PATH+".ilcMoveO@0.ilc@0.ilc_decLO_");
229 vm.releaseNode(CENTER_PATH+".ilcMoveO@0.ilc@0.ilc_torpLO_");
231 vm.releaseNode(CENTER_PATH+".olcWcont@0.olc@0.olc_load_");
233 vm.releaseNode(CENTER_PATH+".flag_A__set_");
234 vm.releaseNode(CENTER_PATH+".flag_A__clr_");
235 vm.releaseNode(CENTER_PATH+".flag_B__set_");
236 vm.releaseNode(CENTER_PATH+".flag_B__clr_");
238 vm.releaseNode(CENTER_PATH+".flag_D__set_");
239 vm.releaseNode(CENTER_PATH+".flag_D__clr_");
241 vm.releaseNode(CENTER_PATH+".flags@0.aFlag@0.net_50");
242 vm.releaseNode(CENTER_PATH+".flags@0.aFlag@1.net_50");
244 // Every move instruction, even those with Ti=0,Di=0,
245 // loads the C-flag. It will get loaded with an "X",
246 // which will then leak into the flags and from there the
248 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.litDandP@0.latch2in@0.hi2inLat@0.latchKee@0.out_B_");
249 vm.releaseNode(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE+1)+"]");
250 vm.releaseNode(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO+1)+"]");
251 vm.releaseNode(prefix+"northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire");
253 for(int i=1; i<=8; i++) {
255 vm.releaseNode(CENTER_PATH+".ilcMoveO@0.ilc@0.\\inLO["+i+"] ");
260 for(int i=1; i<=6; i++)
261 vm.releaseNode(CENTER_PATH+".olcWcont@0.olc@0.inLO["+i+"]");
263 // the proper stopper states come up in an undefined ("X")
264 // state, so under Verilog we need to force them to a
270 } else if (model instanceof NanosimModel) {
271 NanosimModel nModel = (NanosimModel) model;
273 nModel.setNodeVoltage(prefix+"sid[9]",1.0);
274 nModel.setNodeVoltage(prefix+"sic[9]",1.0);
275 nModel.setNodeVoltage(prefix+"sir[9]",1.0);
276 nModel.waitNS(WIDTH);
277 nModel.setNodeVoltage(prefix+"sid[9]",0.0);
278 nModel.setNodeVoltage(prefix+"sic[9]",0.0);
279 nModel.setNodeVoltage(prefix+"sir[9]",0.0);
282 nModel.setNodeVoltage(MASTER_CLEAR,1.0);
283 nModel.waitNS(WIDTH);
284 nModel.setNodeVoltage(MASTER_CLEAR,0.0);
288 mc0.setLogicState(true);
289 mc1.setLogicState(true);
291 mc0.setLogicState(false);
292 mc1.setLogicState(false);
297 // The following call to ChainControl.resetInBits() is vital!
298 // If you forget, then the inBits member initializes
299 // with random northRing. Then when you do your first write,
300 // some bits are written randomly.
301 controlChain.resetInBits();
302 dataChain.resetInBits();
303 dukeChain.resetInBits();
304 reportChain.resetInBits();
313 /** Get the 6 bit outer loop counter. */
314 public int getOLC() {
315 reportChain.shift(REPORT_CHAIN, true, false);
317 com.sun.electric.tool.simulation.test.BitVector bits = null;
318 for(int i=0; i<4; i++) {
319 com.sun.electric.tool.simulation.test.BitVector x = reportChain.getOutBits(REPORT_CHAIN+"."+OLC_PATH_KESSEL+i);
320 //System.out.println("bits are: " + x);
321 bits = bits==null ? x : bits.cat(x);
323 System.out.print(" kesselsCounter = ");
327 for(int bit=5; bit>=0; bit--) {
328 boolean zeroOrTwo = bits.get(4+bit*3);
329 boolean zeroOrDone = bits.get(4+bit*3+1);
330 if ( zeroOrTwo && !zeroOrDone) {
332 System.out.print("2");
334 } else if (!zeroOrTwo && !zeroOrDone) {
336 System.out.print("1");
338 } else if ( zeroOrTwo && zeroOrDone) {
339 System.out.print("0");
342 } else if (!zeroOrTwo && zeroOrDone) {
343 System.out.print("_");
344 if (!done) bad = true;
346 // FIXME: check for unreduced counter and warn about it
348 if (bad) System.out.print(" WARNING: UNREDUCED COUNTER VALUE!!!!!!");
349 System.out.println();
351 } else if (kesselsCounter) {
352 com.sun.electric.tool.simulation.test.BitVector bits = null;
353 for(int i=0; i<4; i++) {
354 com.sun.electric.tool.simulation.test.BitVector x = reportChain.getOutBits(REPORT_CHAIN+"."+OLC_PATH_KESSEL+i);
355 //System.out.println("bits are: " + x);
356 bits = bits==null ? x : bits.cat(x);
358 //System.out.println("kesselsCounter = " + bits);
365 for(int i=0; i<6; i++) {
366 first |= bits.get(4+i*3) ? (1<<i) : 0;
367 second |= bits.get(4+i*3+2) ? (1<<i) : 0;
368 hi = (bits.get(4+i*3) ? "1" : "0") + hi;
369 lo = (bits.get(4+i*3+2) ? "1" : "0") + lo;
371 ( bits.get(4+i*3) && !bits.get(4+i*3+2) ? "X"
372 : !bits.get(4+i*3) && !bits.get(4+i*3+2) ? "0"
373 : !bits.get(4+i*3) && bits.get(4+i*3+2) ? "1"
376 latched = (bits.get(4+i*3+1) ? "0" : "1") + latched;
378 System.out.println("kesselsCounter: "+
381 " latched="+latched +
383 " do[ins]="+(bits.get(0) ? "1" : "0")+
384 " dec="+(bits.get(1) ? "1" : "0")+
385 " flag[D][set]="+(bits.get(2) ? "1" : "0")+
386 " resetting="+(bits.get(3) ? "1" : "0")+
389 return (first+second);
391 com.sun.electric.tool.simulation.test.BitVector odd = reportChain.getOutBits(REPORT_CHAIN+"."+OLC_PATH_ODD).bitReverse();
392 com.sun.electric.tool.simulation.test.BitVector even = reportChain.getOutBits(REPORT_CHAIN+"."+OLC_PATH_EVEN).bitReverse();
395 com.sun.electric.tool.simulation.test.BitVector bv = new com.sun.electric.tool.simulation.test.BitVector(6, "olc");
396 for(int i=0; i<3; i++) {
397 bv.set(i*2, odd.get(i));
398 bv.set(i*2+1, even.get(i));
400 return (int)bv.toLong();
403 public boolean getILCInfinity() { return new Ilc().getInfinity(); }
404 public boolean getILCDone() { return new Ilc().getDone(); }
405 public int getILC() { return new Ilc().getCount(); }
406 public boolean getFlagA() {
407 reportChain.shift(REPORT_CHAIN, true, false);
408 return reportChain.getOutBits(REPORT_CHAIN+"."+FLAGS_PATH).get(0);
410 public boolean getFlagB() {
411 reportChain.shift(REPORT_CHAIN, true, false);
412 return reportChain.getOutBits(REPORT_CHAIN+"."+FLAGS_PATH).get(1);
414 /** get the number of tokens in the token FIFO.
415 * This includes the Token successor wire, the token FIFO wires,
416 * and Token predecessor wire.
417 * Master clear clears the token FIFO. */
418 public int getNumTokens() {
419 reportChain.shift(REPORT_CHAIN, true, false);
420 // get the token successor and token FIFO wires
421 com.sun.electric.tool.simulation.test.BitVector bv = reportChain.getOutBits(REPORT_CHAIN+"."+TOK_FIFO_PATH);
422 int sz = bv.getNumBits();
423 MarinaTest.fatal(sz!=3, "wrong token FIFO size: "+sz+" expected: 3");
425 // get the token predecessor wire
426 com.sun.electric.tool.simulation.test.BitVector pred = reportChain.getOutBits(REPORT_CHAIN+"."+TOK_PRED_PATH);
427 sz = pred.getNumBits();
428 MarinaTest.fatal(sz!=1, "wrong token predecessor size: "+sz+" expected: 1");
432 sz = bv.getNumBits();
435 for (int i=0; i<sz; i++) if (bv.get(i)) nbTok++;