1 package com.sun.vlsi.chips.marina.test;
2 /* -*- tab-width: 4 -*- */
3 import java.util.ArrayList;
6 import com.sun.async.test.BitVector;
7 import com.sun.async.test.ChainControl;
8 import com.sun.async.test.ChainG;
9 import com.sun.async.test.ChainTest;
10 import com.sun.async.test.ChipModel;
11 import com.sun.async.test.HP34401A;
12 import com.sun.async.test.Infrastructure;
13 import com.sun.async.test.JtagSubchainTesterModel;
14 import com.sun.async.test.JtagTester;
15 import com.sun.async.test.ManualPowerChannel;
16 import com.sun.async.test.NanosimModel;
17 import com.sun.async.test.NanosimLogicSettable;
18 import com.sun.async.test.HsimModel;
19 import com.sun.async.test.VerilogModel;
20 import com.sun.async.test.Netscan4;
21 import com.sun.async.test.PowerChannel;
22 import com.sun.async.test.Pst3202Channel;
23 import com.sun.async.test.SiliconChip;
24 import com.sun.async.test.SimulationModel;
25 import com.sun.async.test.VoltageReadable;
26 import com.sun.vlsi.chips.marina.test.Marina.Ilc;
27 import com.sun.vlsi.chips.marina.test.CmdArgs;
28 import com.sun.vlsi.chips.marina.test.CmdArgs.Mode;
30 import edu.berkeley.fleet.api.Dock;
31 import edu.berkeley.fleet.api.Instruction;
32 import edu.berkeley.fleet.api.Predicate;
33 import edu.berkeley.fleet.api.Instruction.Set.SetDest;
34 import edu.berkeley.fleet.api.Instruction.Set.SetSource;
35 import edu.berkeley.fleet.marina.MarinaFleet;
36 import edu.berkeley.fleet.marina.MarinaPath;
37 import com.sun.async.test.*;
42 public class MarinaTest {
43 public static final MarinaFleet marinaFleet = new MarinaFleet();
44 public static final Dock dock = marinaFleet.getOnlyInputDock();
46 //-------------------------- constants -----------------------------------
47 private static final String SCAN_CHAIN_XML = "marina.xml";
48 private static final String NET_LIST = "marina.spi";
50 public static final int INSTR_SZ = 36;
53 public static final Instruction.Set.FlagFunction CLEAR_FLAG
54 = Instruction.Set.FlagFunction.ZERO;
55 public static final Instruction.Set.FlagFunction SET_FLAG
56 = Instruction.Set.FlagFunction.ZERO.add(Predicate.FlagA)
57 .add(Predicate.NotFlagA);
58 public static final Instruction.Set.FlagFunction A_FLAG
59 = Instruction.Set.FlagFunction.ZERO.add(Predicate.FlagA);
61 public static final Instruction.Set.FlagFunction B_FLAG
62 = Instruction.Set.FlagFunction.ZERO.add(Predicate.FlagB);
64 // COLUMN_LATENCY is a delay that is larger than the latency through an Infinity column
65 private static final int COLUMN_LATENCY = 10; // nanoseconds
68 // Officially, this should be the number of requeueing no-ops that
69 // can be inserted into an idle dock whose OLC is nonzero.
71 // Less formally, this is roughly the number of stages of
72 // buffering between the instruction insertion point and the
73 // instruction ring, plus the capacity of the instruction ring.
74 private static final int INSTRUCTION_IN_SATURATION_AMOUNT = 19;
76 // This is some number which is significantly greater than
77 // INSTRUCTION_IN_SATURATION_AMOUNT. Increasing it may slow the tests down, but
78 // will never cause them to operate incorrectly.
79 private static final int MORE_THAN_INSTRUCTION_IN_SATURATION_AMOUNT = 25;
81 // This is the number of items which can be in the instruction
82 // fifo ring WITHOUT causing it to stop circulating.
83 private static final int INSTRUCTION_RING_CAPACITY = 13;
85 // Officially, this should be the number of data items which can
86 // be sent from the dock while the "data" proper stopper is in
87 // the "stopped" state
89 // Less formally, this is roughly the number of stages of
90 // buffering between the dock's data successor and the "data"
93 FIXME: what is the correct value here?
94 private static final int DATA_OUT_SATURATION_AMOUNT = XXX;
97 // This is some number which is greater than
98 // DATA_OUT_SATURATION_AMOUNT, but less than the capacity of the
100 private static final int MORE_THAN_DATA_OUT_SATURATION_AMOUNT = 10;
102 // Nominal cycle time assuming 4 GHz throughput
103 public static double CYCLE_TIME_NS;
105 //-------------------------------- types ---------------------------------
107 //-------------------------- private data --------------------------------
108 private static long startTime;
110 public static Indenter indenter = new Indenter();
111 private Marina marina;
112 private ChipModel model;
113 //private ChainControl cc;
114 //private JtagTester tester;
115 private CmdArgs cmdArgs;
116 private PowerChannel corePowerSupply, padsPowerSupply;
117 private VoltageReadable coreVoltmeter, voltmeterForCurrent;
119 private ChainTest ctD, ctR, ctC, ct;
120 private ChainControl ccD, ccR, ccC, cc;
122 //-------------------------- private methods -----------------------------
123 /** @return true if simulation. Return false if we're testing silicon. */
124 private boolean sim() {return model instanceof SimulationModel;}
126 private void prln(String msg) {indenter.prln(msg);}
127 private void pr(String msg) {indenter.pr(msg);}
128 private void adjustIndent(int n) {indenter.adjustIndent(n);}
130 public static void fatal(boolean pred, String msg) { MarinaUtils.fatal(pred, msg); }
132 public static void fatalIfBitVectorsDoNotMatch(BitVector bv1, BitVector bv2) {
133 // FIXME: better error reporting needed here
135 fatal(bv1.getNumBits()!=bv2.getNumBits(), "lengths do not match");
137 boolean mismatch = false;
139 for(int i=0; i<bv1.getNumBits(); i++) {
140 if (bv1.get(i) != bv2.get(i)) {
145 fatal(mismatch, "bit vectors do not match on bits " + err + "\n "+bv1+"\n "+bv2);
148 private static void printTestTime() {
149 long endTime = System.currentTimeMillis();
150 System.out.println("Test took: "+(endTime-startTime)/1000.0+" sec");
153 // Tell user what we're about to do
154 private static void reportTask(CmdArgs args) {
155 System.out.println("Begin testing Marina");
157 case WHOLE_CHIP_SCHEMATIC_PARASITICS:
158 System.out.println(" Simulate whole chip, schematic parasitics");
160 case WHOLE_CHIP_LAYOUT_PARASITICS:
161 System.out.println(" Simulate whole chip, layout parasitics");
164 System.out.println(" Test silicon");
167 fatal(true, "unrecognized CmdArgs.Mode");
171 private void setUpSuppliesAndMeters(Station station) {
172 // set up power supplies and meters
174 prln("Testing station: "+station);
175 Infrastructure.gpibControllers = new int[] {0};
176 switch (cmdArgs.station) {
178 corePowerSupply = new Pst3202Channel("ch1", "HPST3202", 1);
179 padsPowerSupply = new Pst3202Channel("ch2", "HPST3202", 2);
182 corePowerSupply = new Pst3202Channel("ch1", "HPST3202B", 1);
183 padsPowerSupply = new Pst3202Channel("ch2", "HPST3202B", 2);
186 fatal(true, "Unrecognized station: "+cmdArgs.station);
188 corePowerSupply.setCurrent((float)1.7);
189 corePowerSupply.setVoltageWait((float)1.0);
191 padsPowerSupply.setCurrent((float)0.100);
192 padsPowerSupply.setVoltageWait((float)1.8);
194 coreVoltmeter = new HP34401A(station.coreVoltmeter);
195 voltmeterForCurrent = new HP34401A(station.currentVoltmenter);
199 private MarinaTest(String[] args) {
200 cmdArgs = new CmdArgs(args);
202 if (cmdArgs.mode==Mode.TEST_SILICON) doSilicon(); else doSim();
205 private void doSim() {
207 switch (cmdArgs.mode) {
208 case WHOLE_CHIP_SCHEMATIC_PARASITICS:
209 netListName = NET_LIST;
211 case WHOLE_CHIP_LAYOUT_PARASITICS:
212 netListName = "marina_pads_guts.spi";
215 fatal(true, "unrecognized CmdArgs.Mode");
219 model = cmdArgs.useVerilog
225 : new NanosimModel();
227 if (model instanceof SimulationModel)
228 ((SimulationModel)model).setOptimizedDirectReadsWrites(true);
230 CYCLE_TIME_NS = cmdArgs.useVerilog ? (100*20) : 0.250;
232 model instanceof VerilogModel
236 : model instanceof ChipModel
240 System.err.println("constructing jtag controller");
242 model instanceof SimulationModel
243 ? ((SimulationModel)model).createJtagTester("TCK", "TMS", "TRSTb", "TDI", "TDO")
244 : new Netscan4("jtag3", 2);
245 if (tester instanceof Netscan4) {
246 ((Netscan4)tester).reset();
248 // not sure if "GPIO1" means "index 0" or not
249 JtagLogicLevel mc0 = new JtagLogicLevel(tester, 0);
250 JtagLogicLevel mc1 = new JtagLogicLevel(tester, 1);
251 mc0.setLogicState(true);
252 mc1.setLogicState(true);
254 Logger.setLogInits(true);
255 tester.setLogSets(true);
256 tester.setLogOthers(true);
257 tester.setAllLogging(true);
258 tester.printInfo = true;
260 ChainControls ccs = new ChainControls();
261 PowerChannel pc = new ManualPowerChannel("pc", false);
263 JtagTester testerD, testerR, testerC;
264 testerD = ((SimulationModel)model).createJtagSubchainTester("sid[1:9]", null);
265 testerR = ((SimulationModel)model).createJtagSubchainTester("sir[1:9]", null);
266 testerC = ((SimulationModel)model).createJtagSubchainTester("sic[1:9]", null);
267 testerD.printInfo = testerR.printInfo = testerC.printInfo = false;
269 ccD = new ChainControl(SCAN_CHAIN_XML, testerD, 1.8f, khz);
270 ccR = new ChainControl(SCAN_CHAIN_XML, testerR, 1.8f, khz);
271 ccC = new ChainControl(SCAN_CHAIN_XML, testerC, 1.8f, khz);
272 ccD.noTestSeverity = ccR.noTestSeverity = ccC.noTestSeverity = Infrastructure.SEVERITY_NOMESSAGE;
275 ctD = new ChainTest(ccD, pc);
276 ctR = new ChainTest(ccR, pc);
277 ctC = new ChainTest(ccC, pc);
280 ccs.addChain(Marina.DATA_CHAIN, ccD);
281 ccs.addChain(Marina.REPORT_CHAIN, ccR);
282 ccs.addChain(Marina.CONTROL_CHAIN, ccC);
285 cc = new ChainControl(SCAN_CHAIN_XML, tester, 1.8f, khz);
286 cc.noTestSeverity = Infrastructure.SEVERITY_NOMESSAGE;
287 ct = new ChainTest(cc, pc);
288 ccs.addChain(Marina.DATA_CHAIN, cc);
289 ccs.addChain(Marina.REPORT_CHAIN, cc);
290 ccs.addChain(Marina.CONTROL_CHAIN, cc);
292 marina = new Marina(ccs, model, !cmdArgs.jtagShift, indenter);
294 if (model instanceof NanosimModel) {
295 NanosimLogicSettable mc = (NanosimLogicSettable)
296 ((SimulationModel)model).createLogicSettable(Marina.MASTER_CLEAR);
297 mc.setInitState(true);
300 prln("starting model");
301 if (model instanceof VerilogModel)
302 ((SimulationModel)model).start("verilog", "marina.v", VerilogModel.DUMPVARS, !cmdArgs.jtagShift);
303 else if (model instanceof HsimModel)
304 ((SimulationModel)model).start("hsim64", netListName, 0, !cmdArgs.jtagShift);
305 else if (model instanceof NanosimModel)
306 ((SimulationModel)model).start("nanosim -c cfg", netListName, 0, !cmdArgs.jtagShift);
309 prln("model started");
312 prln("deasserting master clear");
313 if (model instanceof SimulationModel)
314 ((SimulationModel)model).setNodeState(Marina.MASTER_CLEAR, 0);
316 prln("FIXME: need to deassert master clear");
319 if (cmdArgs.testNum!=0 && cmdArgs.testNum!=1) {
321 cc.shift(Marina.CONTROL_CHAIN, false, true);
324 doOneTest(cmdArgs.testNum);
326 if (model instanceof SimulationModel)
327 ((SimulationModel)model).finish();
329 private void doSilicon() {
330 model = new SiliconChip();
331 String ip = cmdArgs.station.ipAddr;
332 JtagTester tester = new Netscan4(ip, cmdArgs.station.jtagChannel);
333 tester.printInfo = false;
335 ChainControl cc = new ChainControl("???", tester, 1.8f, khz);
336 cc.noTestSeverity = Infrastructure.SEVERITY_NOMESSAGE;
337 ChainControls ccs = new ChainControls();
338 ccs.addChain(Marina.DATA_CHAIN, cc);
339 ccs.addChain(Marina.REPORT_CHAIN, cc);
340 ccs.addChain(Marina.CONTROL_CHAIN, cc);
341 marina = new Marina(ccs, model, false, indenter);
342 PowerChannel pc = new ManualPowerChannel("pc", false);
343 ChainTest ct = new ChainTest(cc, pc);
344 ct.testAllChains("marina", Infrastructure.SEVERITY_WARNING);
345 doOneTest(cmdArgs.testNum);
346 setUpSuppliesAndMeters(cmdArgs.station);
349 /** In the absence of looping, the longest path through Infinity is 4 column delays */
350 private void waitUntilQuiescent() {
351 model.waitNS(4*COLUMN_LATENCY);
354 private double readCurrent() {
355 return voltmeterForCurrent.readVoltage() / cmdArgs.station.ammeterShuntResistance;
358 /** Generate List of BitVectors where Token=true, high 25 data bits
359 * are alternating ones and zeros, low 12 data bits increment from
360 * zero, and address is given by addr. */
361 private List<BitVector> makeIncrDataConstAdr(int num, int addr) {
362 List<BitVector> ans = new ArrayList<BitVector>();
363 BitVector dHi = new BitVector(25, "dataHi");
364 BitVector dLo = new BitVector(12, "dataLo");
365 BitVector t = new BitVector("1", "token");
366 BitVector a = new BitVector(14, "addr");
367 dHi.setFromLong(0x00aaaaa);
369 for (int i=0; i<num; i++) {
371 ans.add(dHi.cat(dLo).cat(t).cat(a));
376 private void stopToStop(ProperStopper s1, ProperStopper s2,
378 List<BitVector> din) {
379 prln("Begin stopToStop");
384 long ctrStart = ctr==null ? 0 : ctr.getCount();
387 waitUntilQuiescent();
389 List<BitVector> dout = s2.drainMany();
391 MarinaUtils.compareItemsOrdered(din, dout);
394 long ctrEnd = ctr.getCount();
395 long delta = ctrEnd - ctrStart;
396 long expect = din.size();
398 "counter delta wrong: expected delta: "+expect+
399 " counter before:"+ctrStart+" counter after:"+ctrEnd);
403 prln("End stopToStop");
405 /** Burst data from src to dst. gate is stopped while loading src. gate
406 * is then run to allow the burst to flow. */
407 private void stopToStopBurst(ProperStopper src, ProperStopper gate,
410 List<BitVector> din) {
411 prln("Begin stopToStopBurst test");
417 long ctrStart = ctr==null ? 0 : ctr.getCount();
420 waitUntilQuiescent();
422 // open the gate to start the burst
424 waitUntilQuiescent();
426 List<BitVector> dout = dst.drainMany();
428 MarinaUtils.compareItemsOrdered(din, dout);
431 long ctrEnd = ctr.getCount();
432 long delta = ctrEnd - ctrStart;
434 long expectA = din.size();
435 fatal(delta!=expectA,
436 "counter delta wrong: expected delta: "+expectA+
437 " counter before:"+ctrStart+" counter after:"+ctrEnd);
441 prln("End stopToStopBurst test");
444 private void stopToStopOne(ProperStopper s1, ProperStopper s2,
445 Counter ctr, int adr) {
446 prln("Begin stopToStopOne");
449 List<BitVector> din = makeIncrDataConstAdr(1, adr);
450 stopToStop(s1, s2, ctr, din);
453 prln("End stopToStopOne");
456 private void stopToStopThree(ProperStopper s1, ProperStopper s2,
457 Counter ctr, int adr) {
458 prln("Begin stopToStopOne");
461 List<BitVector> din = makeIncrDataConstAdr(3, adr);
462 stopToStop(s1, s2, ctr, din);
465 prln("End stopToStopOne");
468 private int indexOf(BitVector o, List<BitVector> dIn) {
469 for (int i=0; i<dIn.size(); i++) {
470 if (o.equals(dIn.get(i))) return i;
474 private String ringDump(List<BitVector> dIn, List<BitVector> dOut) {
475 StringBuffer sb = new StringBuffer();
476 sb.append(" ring dump: ");
477 for (BitVector o : dOut) {
478 sb.append(indexOf(o, dIn)+" ");
480 return sb.toString();
483 private int[][] makeIntArray2D(int a, int b) {
484 int[][] ans = new int[a][];
485 for (int i=0; i<a; i++) ans[i] = new int[b];
489 //=========================================================================
490 // Put top level tests here
492 private void testChains(Marina marina) {
494 prln("Testing control chain...");
495 ctC.testOneChain(Marina.CONTROL_CHAIN, Infrastructure.SEVERITY_WARNING);
497 ccC.shift(Marina.CONTROL_CHAIN, false, true);
501 prln("Testing data chain...");
502 ctD.testOneChain(Marina.DATA_CHAIN, Infrastructure.SEVERITY_WARNING);
504 //ccD.shift(Marina.DATA_CHAIN, false, true);
508 prln("Testing report chain...");
509 ctR.testOneChain(Marina.REPORT_CHAIN, Infrastructure.SEVERITY_WARNING);
511 //ccR.shift(Marina.REPORT_CHAIN, false, true);
515 prln("Testing control chain...");
516 ct.testOneChain(Marina.CONTROL_CHAIN, Infrastructure.SEVERITY_WARNING);
518 cc.shift(Marina.CONTROL_CHAIN, false, true);
519 prln("Testing data chain...");
520 ct.testOneChain(Marina.DATA_CHAIN, Infrastructure.SEVERITY_WARNING);
521 prln("Testing report chain...");
522 ct.testOneChain(Marina.REPORT_CHAIN, Infrastructure.SEVERITY_WARNING);
526 private void testProperStoppers(Marina marina) {
527 prln("Begin testProperStoppers");
530 for(ProperStopper ps : new ProperStopper[] { marina.data, marina.instrIn }) {
532 prln("testing " + (ps == marina.data ? "data" : "instruction") + " stopper");
535 prln("un-stopping stopper");
537 fatal( ps.getStopped(), "stopper should not have been stopped, but was");
539 prln("stopping stopper");
541 fatal( !ps.getStopped(), "stopper should have been stopped, but was not");
549 private void sendInstructions(Marina marina) {
550 prln("Begin sendInstructions");
553 List<BitVector> din = new ArrayList<BitVector>();
555 BitVector count = new BitVector(MarinaPacket.WORD_WIDTH,"count");
556 BitVector one = new BitVector(MarinaPacket.WORD_WIDTH, "one");
557 count.setFromLong(0);
559 for (int i=0; i<3; i++) {
561 count = count.add(one);
564 for(BitVector d : din)
565 marina.instrIn.fill(new MarinaPacket(d, false, MarinaPacket.null_path));
568 prln("End sendInstructions");
571 private void sendToken(Marina marina) {
572 prln("Begin sendToken");
575 //getCtrsFlags(marina);
577 int nbToks = marina.getNumTokens();
578 fatal(nbToks!=0, "Expected no tokens on initialization but got: "+nbToks+" tokens");
580 marina.instrIn.fill(setIlc(1));
581 marina.instrIn.fill(SEND_TOKEN);
582 nbToks = marina.getNumTokens();
583 fatal(nbToks!=1, "Expected one token to emerge but got: "+nbToks+" tokens");
586 prln("End sendToken");
589 private void sendData(Marina marina) {
590 prln("Begin sendData");
593 edu.berkeley.fleet.api.BitVector bv = new edu.berkeley.fleet.api.BitVector(13);
594 for(int i=0; i<bv.length(); i+=2) bv.set(i, false);
595 MarinaPath path = new MarinaPath((MarinaFleet)dock.getShip().getFleet(), bv);
597 marina.instrIn.fill(setIlc(1));
598 marina.instrIn.fill(SEND_DATA);
600 List<BitVector> dataItems = marina.data.drainMany();
601 fatal(dataItems.size()!=1, "Expected one data item to emerge but got: "+dataItems.size()+" data items");
603 MarinaPacket mp = new MarinaPacket(dataItems.get(0));
604 fatal(mp.tokenhood, "Expected tokenhood=data, but got tokenhood=token");
607 prln("End sendData");
610 private void sendDataIlcInfinite(Marina marina) {
611 prln("Begin sendDataIlcInfinite");
614 marina.fillSouthProperStopper(new Instruction[] {
615 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter,SetSource.Infinity),
621 List<BitVector> dataItems = marina.data.drainMany(howmany);
622 fatal(dataItems.size()!=howmany,
623 "Expected an unending supply of data items to emerge but only got got: "+dataItems.size());
626 prln("End sendDataIlcInfinite");
629 private Instruction setOlc(int olc) {
630 return new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, olc);
632 private Instruction setOlcIfZero(int olc) {
633 return new Instruction.Set(dock,Predicate.Default,SetDest.OuterLoopCounter, olc);
635 private Instruction setIlc(int ilc) {
636 return new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter, ilc);
639 private void testFlagD(Marina marina) {
640 prln("Begin testFlagD");
643 List<BitVector> toks;
645 Predicate only_if_olc_zero = Predicate.FlagD;
646 Predicate only_if_olc_nonzero = Predicate.Default;
648 marina.instrIn.fill(setIlc(1));
650 for(int olc : new int[] { 1, 0 }) {
651 for(boolean predicate_olc_nonzero : new boolean[] { true, false }) {
652 prln("Attempting send data item with "+
654 "predicate olc"+(predicate_olc_nonzero?"!=0":"==0"));
657 marina.fillSouthProperStopper(new Instruction[] {
659 new Instruction.Move(dock,
660 predicate_olc_nonzero // predicate
661 ? only_if_olc_nonzero
664 false, // torpedoable
674 expectNorthFifoExactly((predicate_olc_nonzero == (olc!=0)) ? 1 : 0);
676 for(int i=0; i<olc; i++)
677 marina.instrIn.fill(DEC);
683 prln("End testFlagD");
686 private void testPredicationOnAB(Marina marina) {
687 prln("Begin testPredicationOnAB");
690 List<BitVector> dItems;
692 marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, 1));
693 marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter, 1));
695 for(boolean flag_a : new boolean[] { false, true }) {
696 for(boolean flag_b : new boolean[] { false, true }) {
697 prln("Setting flags, a="+flag_a+" b="+flag_b);
698 marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD,
700 ? Instruction.Set.FlagFunction.ONE
701 : Instruction.Set.FlagFunction.ZERO,
703 ? Instruction.Set.FlagFunction.ONE
704 : Instruction.Set.FlagFunction.ZERO
706 getCtrsFlags(marina);
709 for(Predicate predicate : new Predicate[] {
717 prln("Attempting send data with a="+flag_a+", b="+flag_b+", predicate="+predicate);
719 marina.instrIn.fill(new Instruction.Move(dock,
720 predicate, // predicate
721 false, // torpedoable
731 dItems = marina.data.drainMany();
732 int expected = predicate.evaluate(flag_a, flag_b, false, false) ? 1 : 0;
733 fatal(dItems.size()!=expected, "Expected "+expected+" data items to emerge but got: "+
734 dItems.size()+" items(s)");
740 prln("End testPredicationOnAB");
744 private void showOlc() {
745 prln("OLC=="+marina.getOLC());
747 private void expectOlc(int x) {
748 int olc = marina.getOLC();
749 fatal(x!=olc, "expected OLC=="+x+", but scanned out OLC=="+olc);
752 private void getCtrsFlags(Marina marina) {
753 prln("begin getCtrsFlags");
757 Ilc ilc = marina.getILC();
758 prln("ILC.done=="+ilc.getDone()+
759 " ILC.infinity=="+ilc.getInfinity()+
760 " ILC.count=="+ilc.getCount());
761 prln("flagA=="+marina.getFlagA());
762 prln("flagB=="+marina.getFlagB());
764 prln("end getCtrsFlags");
767 private void walkOneOLC(Marina marina) {
768 prln("Begin walkOneOLC");
770 for (int i=0; i<6; i++) {
772 if (marina.kesselsCounter) {
773 System.out.println("master-clearing...");
774 // master clear on each iteration; otherwise we'd need to "run down" the olc
775 marina.masterClear();
776 marina.enableInstructionSend(true);
779 int inOlc = i==-1 ? 0 : (1<<i);
780 marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, inOlc));
782 model.waitNS(128 * CYCLE_TIME_NS);
785 prln("walkOneOLC: "+inOlc+" checks out");
788 prln("End walkOneOLC");
790 private void walkOneILC(Marina marina) {
791 prln("Begin walkOneILC");
793 for (int i=0; i<6; i++) {
794 // Mask off the "zero" bit position
796 prln("inIlc="+inIlc);
797 marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter, inIlc));
798 Ilc ilc = marina.getILC();
799 int outIlc = ilc.getCount();
800 fatal(outIlc!=inIlc, "bad ILC count: "+outIlc+" expected: "+inIlc);
801 fatal(ilc.getInfinity(), "bad Infinity bit: true");
803 prln("Now test the infinity bit");
804 marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter, SetSource.Infinity));
805 Ilc ilc = marina.getILC();
806 fatal(!ilc.getInfinity(), "bad Infinity bit: false");
808 prln("End walkOneILC");
810 private void countIlc(Marina marina) {
811 final int maxIlc = 63;
812 prln("Begin countIlc");
815 marina.instrIn.fill(new
816 Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter, maxIlc));
818 int ilc = marina.getILC().getCount();
819 fatal(ilc!=maxIlc, "bad ILC count: "+ilc+" expected: "+maxIlc);
821 prln("execute a move instruction that does nothing except decrement the ILC to zero");
823 new Instruction.Move(dock,
824 Predicate.IgnoreFlagD, // predicate
825 false, // torpedoable
835 // wait for ILC to count from 63 to 0
836 model.waitNS(128 * CYCLE_TIME_NS);
837 //model.waitNS(10000);
839 prln("Check that ILC==0");
840 ilc = marina.getILC().getCount();
841 fatal(ilc!=0, "bad ILC count: "+ilc+" expected: "+0);
844 prln("End countIlc");
846 // Note: countOlc takes 44 minutes to run on nanosim
847 private void countOlc(Marina marina) {
849 prln("Begin countOlc");
852 marina.instrIn.fill(setOlc(maxOlc));
854 for (int i=maxOlc; i>=0; i--) {
855 model.waitNS(128 * CYCLE_TIME_NS);
856 prln("OLC should be: "+i);
858 marina.instrIn.fill(new
859 Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, SetSource.Decrement));
863 prln("End countOlc");
865 private void loadEveryValueOLC(Marina marina) {
867 for (int i=0; i<(1<<6); i++) {
869 if (marina.kesselsCounter) {
870 System.out.println("master-clearing...");
871 // master clear on each iteration; otherwise we'd need to "run down" the olc
872 marina.masterClear();
873 marina.enableInstructionSend(true);
877 marina.fillSouthProperStopper(new Instruction[] {
881 // to ensure that instruction is bubble-limited
884 // the Set-OLC instruction
885 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, inOlc),
887 // put a Set-ILC instruction right behind it with inverted bits to be sure we're
888 // not capturing the instruction-latch value too late in the cycle
889 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter, (inOlc ^ (~(-1<<6)))),
893 model.waitNS(128 * CYCLE_TIME_NS);
894 marina.fillNorthProperStopper();
895 model.waitNS(128 * CYCLE_TIME_NS);
898 prln("loadEveryValueOLC: "+inOlc+" checks out");
903 private void saturateInstructionFifo(Marina marina, Instruction instruction, int quantity, boolean expect_it_to_jam_up) {
904 prln("Inserting "+quantity+" copies of \"" + instruction + "\"");
907 for(i=0; i<quantity; i++) {
908 prln("Inserting instruction " + (i+1) +"/"+ quantity);
909 marina.instrIn.fill(instruction);
910 boolean jammed = (marina.instrIn.getFillStateWire()==MarinaUtils.StateWireState.FULL);
911 if (jammed && expect_it_to_jam_up) {
912 prln("Stopper remained full after inserting instruction; this was expected; we are happy.");
916 fatal(jammed, "Instruction stopper did not drain after inserting " + (i+1) + " instructions; not good!");
918 fatal(expect_it_to_jam_up, "Expected instruction stopper to jam up, but it did not");
920 prln("Successfully inserted " + i + " instructions");
923 private static MarinaPath null_path = new MarinaPath((MarinaFleet)dock.getShip().getFleet(),
924 MarinaUtils.sunToBerk(MarinaPacket.null_path));
926 private static final Instruction DEC =
927 new Instruction.Set(dock,Predicate.Default,SetDest.OuterLoopCounter, SetSource.Decrement);
929 private static final Instruction FLAG_NOP =
930 new Instruction.Set(dock, Predicate.IgnoreFlagD,
931 CLEAR_FLAG.add(Predicate.FlagA),
932 CLEAR_FLAG.add(Predicate.FlagB));
934 private static final Instruction NOP =
935 new Instruction.Move(dock,
936 Predicate.IgnoreFlagD, /* predicate */
937 false, /* torpedoable */
941 false, /* latchData */
942 false, /* latchPath */
947 private static final Instruction SEND_DATA =
948 new Instruction.Move(dock,
949 Predicate.IgnoreFlagD, /* predicate */
950 false, /* torpedoable */
951 null_path, /* path */
954 false, /* latchData */
955 false, /* latchPath */
960 private static final Instruction SEND_DATA_IF_D_NOT_SET =
961 new Instruction.Move(dock,
962 Predicate.Default, /* predicate */
963 false, /* torpedoable */
964 null_path, /* path */
967 false, /* latchData */
968 false, /* latchPath */
973 private static final Instruction SEND_DATA_IF_D_SET =
974 new Instruction.Move(dock,
975 Predicate.FlagD, /* predicate */
976 false, /* torpedoable */
977 null_path, /* path */
980 false, /* latchData */
981 false, /* latchPath */
986 private static final Instruction TORPEDOABLE_RECV_DATA =
987 new Instruction.Move(dock,
988 Predicate.IgnoreFlagD, /* predicate */
989 true, /* torpedoable */
993 true, /* latchData */
994 false, /* latchPath */
999 private static final Instruction RECV_DATA =
1000 new Instruction.Move(dock,
1001 Predicate.IgnoreFlagD, /* predicate */
1002 false, /* torpedoable */
1004 false, /* tokenIn */
1006 true, /* latchData */
1007 false, /* latchPath */
1008 false, /* dataOut */
1009 false /* tokenOut */
1012 private static final Instruction SEND_TOKEN =
1013 new Instruction.Move(dock,
1014 Predicate.IgnoreFlagD, /* predicate */
1015 false, /* torpedoable */
1016 null_path, /* path */
1017 false, /* tokenIn */
1019 false, /* latchData */
1020 false, /* latchPath */
1021 false, /* dataOut */
1025 private static final Instruction RECV_TOKEN =
1026 new Instruction.Move(dock,
1027 Predicate.IgnoreFlagD, /* predicate */
1028 false, /* torpedoable */
1032 false, /* latchData */
1033 false, /* latchPath */
1034 false, /* dataOut */
1035 false /* tokenOut */
1039 private void expectNorthFifoNoMoreThan(int num) {
1040 model.waitNS(128 * CYCLE_TIME_NS);
1041 List<BitVector> dataItems = marina.data.drainMany(num+1);
1042 fatal(dataItems.size()>num,
1043 "Expected no more than "+num+
1044 " data items to emerge but got at least: "+dataItems.size());
1046 private void expectNorthFifoExactly(int num) {
1047 model.waitNS(128 * CYCLE_TIME_NS);
1048 List<BitVector> dataItems = marina.data.drainMany(num+1);
1049 fatal(dataItems.size()!=num,
1050 "Expected exactly "+num+
1051 " data items to emerge but got at least: "+dataItems.size());
1053 private void expectNorthFifoAtLeast(int num) {
1054 model.waitNS(128 * CYCLE_TIME_NS);
1055 List<BitVector> dataItems = marina.data.drainMany(num);
1056 fatal(dataItems.size()<num,
1057 "Expected at least "+num+
1058 " data items to emerge but got only: "+dataItems.size());
1060 private void expectTokensNoMoreThan(int num) {
1061 int x = marina.getNumTokens();
1062 List<BitVector> dataItems = marina.data.drainMany(num+1);
1064 "Expected no more than "+num+
1065 " tokens to emerge but got at least: "+x);
1067 private void expectTokensExactly(int num) {
1068 int x = marina.getNumTokens();
1070 "Expected exactly "+num+
1071 " tokens but got at least: "+x);
1074 private void testFlagDRecomputationTime(Marina marina) {
1075 marina.instrIn.fill(setIlc(1));
1076 marina.fillSouthProperStopper(new Instruction[] {
1078 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter,0),
1079 SEND_DATA_IF_D_NOT_SET
1081 marina.fillNorthProperStopper();
1082 expectNorthFifoNoMoreThan(0);
1084 marina.fillSouthProperStopper(new Instruction[] {
1086 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter,1),
1087 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter,SetSource.Decrement),
1088 SEND_DATA_IF_D_NOT_SET
1090 marina.fillNorthProperStopper();
1091 expectNorthFifoNoMoreThan(0);
1093 marina.fillSouthProperStopper(new Instruction[] {
1095 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter,2),
1096 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter,SetSource.Decrement),
1097 SEND_DATA_IF_D_NOT_SET
1099 marina.fillNorthProperStopper();
1100 expectNorthFifoExactly(1);
1101 marina.instrIn.fill(DEC);
1103 marina.fillSouthProperStopper(new Instruction[] {
1105 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter,0),
1106 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter,1),
1107 SEND_DATA_IF_D_NOT_SET
1109 marina.fillNorthProperStopper();
1110 expectNorthFifoExactly(1);
1113 private void testTailWaitsForHead(Marina marina) {
1114 marina.instrIn.fill(setIlc(1));
1115 marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, 63));
1117 marina.enableInstructionSend(false);
1118 marina.enableInstructionRecirculate(true);
1120 marina.instrIn.fill(TORPEDOABLE_RECV_DATA);
1121 marina.instrIn.fill(new Instruction.Head(dock));
1122 marina.instrIn.fill(SEND_DATA);
1123 marina.instrIn.fill(TORPEDOABLE_RECV_DATA);
1124 marina.instrIn.fill(SEND_TOKEN);
1125 marina.instrIn.fill(TORPEDOABLE_RECV_DATA);
1126 marina.instrIn.fill(new Instruction.Tail(dock));
1127 marina.instrIn.fillTorpedo();
1129 marina.enableInstructionRecirculate(false);
1130 marina.enableInstructionSend(true);
1131 marina.instrIn.run();
1133 expectNorthFifoNoMoreThan(0);
1134 prln("inserting into north proper stopper");
1135 marina.fillNorthProperStopper();
1136 expectNorthFifoExactly(1);
1137 int nbToks = marina.getNumTokens();
1138 fatal(nbToks!=1, "Expected one token to emerge but got: "+nbToks+" tokens");
1142 marina.instrIn.fill(setIlc(1));
1143 marina.instrIn.fill(setOlc(1));
1145 // this makes the head wait for the torpedo
1146 marina.instrIn.fill(TORPEDOABLE_RECV_DATA);
1148 // the head should wait for the tail
1149 marina.instrIn.fill(new Instruction.Head(dock));
1150 marina.instrIn.fill(NOP);
1151 marina.instrIn.fill(SEND_DATA);
1152 marina.instrIn.fill(RECV_DATA);
1154 expectNorthFifoNoMoreThan(0);
1156 marina.instrIn.fillTorpedo();
1157 expectNorthFifoNoMoreThan(0);
1159 marina.instrIn.fill(new Instruction.Tail(dock));
1160 expectNorthFifoExactly(1);
1163 private void testTailWithoutHead(Marina marina) {
1164 marina.instrIn.fill(setIlc(1));
1165 marina.fillSouthProperStopper(new Instruction[] {
1166 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, 63),
1167 new Instruction.Tail(dock),
1170 List<BitVector> dataItems = marina.data.drainMany(1);
1171 fatal(dataItems.size()!=0, "Expected exactly no data items to emerge but got at least: "+dataItems.size());
1174 private void testHeadWaitsForTail(Marina marina) {
1175 List<BitVector> dataItems;
1177 prln("Begin testHeadWaitsForTail");
1180 marina.instrIn.fill(setIlc(1));
1181 marina.fillSouthProperStopper(new Instruction[] {
1182 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, 63),
1183 new Instruction.Head(dock),
1184 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter,1),
1188 expectNorthFifoExactly(0);
1189 marina.instrIn.fill(new Instruction.Tail(dock));
1190 expectNorthFifoAtLeast(1);
1193 prln("End testHeadWaitsForTail");
1196 private void testNonTorpedoableMoveDoesNotResetDFlag(Marina marina) {
1197 marina.instrIn.fill(setIlc(1));
1198 marina.fillSouthProperStopper(new Instruction[] {
1199 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter,63),
1200 new Instruction.Move(dock,
1201 Predicate.IgnoreFlagD, // predicate
1202 true, // torpedoable
1211 new Instruction.Move(dock,
1212 Predicate.FlagD, // predicate
1213 false, // torpedoable
1223 marina.instrIn.fillTorpedo();
1224 expectNorthFifoExactly(1);
1225 marina.fillSouthProperStopper(new Instruction[] {
1226 new Instruction.Move(dock,
1227 Predicate.Default, // predicate
1228 false, // torpedoable
1238 expectNorthFifoNoMoreThan(0);
1241 private void testAbort(Marina marina) {
1243 marina.instrIn.fill(setIlc(1));
1244 marina.fillSouthProperStopper(new Instruction[] {
1245 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.DataLatch,1),
1246 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter,2),
1247 SEND_DATA_IF_D_NOT_SET,
1248 new Instruction.Head(dock),
1249 SEND_DATA_IF_D_NOT_SET,
1250 new Instruction.Set(dock,Predicate.Default,SetDest.DataLatch,2),
1251 new Instruction.Abort(dock, Predicate.FlagD),
1252 new Instruction.Set(dock,Predicate.Default,SetDest.OuterLoopCounter,SetSource.Decrement),
1253 new Instruction.Tail(dock),
1256 for(int i=0; i<4; i++) {
1259 model.waitNS(128 * CYCLE_TIME_NS);
1260 bv = new MarinaPacket(marina.data.drain()).data.bitReverse();
1261 fatal(bv==null, "no data item found");
1262 prln("got " + bv.toLong());
1263 fatal(bv.toLong()!=1, "expected 1, got " + bv.toLong());
1265 model.waitNS(128 * CYCLE_TIME_NS);
1266 bv = new MarinaPacket(marina.data.drain()).data.bitReverse();
1267 fatal(bv==null, "no data item found");
1268 prln("got " + bv.toLong());
1269 fatal(bv.toLong()!=1, "expected 1, got " + bv.toLong());
1271 model.waitNS(128 * CYCLE_TIME_NS);
1272 bv = new MarinaPacket(marina.data.drain()).data.bitReverse();
1273 fatal(bv==null, "no data item found");
1274 prln("got " + bv.toLong());
1275 fatal(bv.toLong()!=2, "expected 2, got " + bv.toLong());
1280 private void testAbortOutsideOfLoop(Marina marina) {
1281 marina.instrIn.fill(setIlc(1));
1282 marina.fillSouthProperStopper(new Instruction[] {
1283 // ensure that an abort doesn't cause problems if no loop is in progress
1284 new Instruction.Abort(dock, Predicate.IgnoreFlagD),
1287 expectNorthFifoExactly(1);
1290 private void testFlagAB(Marina marina) {
1291 prln("Begin testFlagAB");
1294 Instruction.Set.FlagFunction zero = Instruction.Set.FlagFunction.ZERO;
1295 Instruction.Set.FlagFunction one = zero;
1298 // we should be able to use any pair of FlagX+NotFlagX,
1299 // but we toss them all in to maximize the chances of the
1300 // test passing (later we will try the individual
1301 // combinations to maximize the chances of failure).
1302 one = one.add(Predicate.FlagA);
1303 one = one.add(Predicate.NotFlagA);
1304 one = one.add(Predicate.FlagB);
1305 one = one.add(Predicate.NotFlagB);
1306 one = one.add(Predicate.FlagC);
1307 one = one.add(Predicate.NotFlagC);
1309 marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter,1));
1310 for(boolean fast : new boolean[] { true, false }) {
1311 // clear the flags to a known state, then check both 0->1 and 1->0 transitions
1312 for(boolean b : new boolean[] { false, true, false }) {
1313 prln("state: a="+marina.getFlagA()+", b="+marina.getFlagB());
1314 prln((b?"Setting":"Clearing")+" flags");
1316 Instruction inst = new Instruction.Set(dock,Predicate.IgnoreFlagD,
1321 marina.fillSouthProperStopper(new Instruction[] {
1326 model.waitNS(64 * CYCLE_TIME_NS);
1327 marina.fillNorthProperStopper();
1329 marina.instrIn.fill(inst);
1332 fatal(marina.getFlagA()!=b,
1333 "after "+(b?"setting":"clearing")+" FlagA, it was still "+(b?"clear":"set"));
1334 fatal(marina.getFlagB()!=b,
1335 "after "+(b?"setting":"clearing")+" FlagB, it was still "+(b?"clear":"set"));
1340 prln("End testFlagAB");
1344 * WARNING: this is a very, very, very long test case -- it goes
1345 * through 216 iterations.
1347 private void testFlagTruthTable(Marina marina) {
1348 prln("Begin testFlagTruthTable");
1351 marina.instrIn.fill(setIlc(1));
1352 Instruction.Set.FlagFunction zero = Instruction.Set.FlagFunction.ZERO;
1353 Instruction.Set.FlagFunction one = zero.add(Predicate.FlagA).add(Predicate.NotFlagA);
1355 for(Predicate a_input : new Predicate[] { null, Predicate.FlagA, Predicate.NotFlagA })
1356 for(Predicate b_input : new Predicate[] { null, Predicate.FlagB, Predicate.NotFlagB })
1357 for(Predicate c_input : new Predicate[] { null, Predicate.FlagC, Predicate.NotFlagC })
1358 for(boolean a_state : new boolean[] { false, true })
1359 for(boolean b_state : new boolean[] { false, true })
1360 for(boolean c_state : new boolean[] { false, true }) {
1361 for(boolean which : new boolean[] { false, true }) {
1363 prln("before instruction: a="+a_state+", b="+b_state+", c="+c_state);
1364 // set A,B flags to a_state and b_state
1365 marina.instrIn.fill(new
1366 Instruction.Set(dock,Predicate.IgnoreFlagD,
1367 a_state ? one : zero,
1368 b_state ? one : zero
1371 // set C flag to c_state
1372 BitVector data = new BitVector(37, "empty");
1373 BitVector addr = new BitVector(14, "empty");
1374 for(int i=0; i<data.getNumBits(); i++) data.set(i, false);
1375 for(int i=0; i<addr.getNumBits(); i++) addr.set(i, false);
1376 addr.set(Marina.INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE, c_state);
1377 marina.fillNorthProperStopper(new MarinaPacket(data, false, addr));
1378 marina.instrIn.fill(RECV_DATA);
1380 Instruction.Set.FlagFunction func = zero;
1381 if (a_input!=null) func = func.add(a_input);
1382 if (b_input!=null) func = func.add(b_input);
1383 if (c_input!=null) func = func.add(c_input);
1385 Instruction inst = new
1386 Instruction.Set(dock,Predicate.IgnoreFlagD,
1387 !which ? func : zero.add(Predicate.FlagA),
1388 which ? func : zero.add(Predicate.FlagB)
1391 marina.instrIn.fill(inst);
1393 boolean expected_a = !which ? func.evaluate(a_state, b_state, c_state, false) : a_state;
1394 boolean expected_b = which ? func.evaluate(a_state, b_state, c_state, false) : b_state;
1395 fatal(expected_a != marina.getFlagA(),
1396 "expected A="+expected_a+", but got "+marina.getFlagA());
1397 fatal(expected_b != marina.getFlagB(),
1398 "expected B="+expected_b+", but got "+marina.getFlagB());
1402 prln("End testFlagTruthTable");
1405 private void recvData(Marina marina) {
1406 prln("Begin recvData");
1409 marina.instrIn.fill(setIlc(1));
1410 marina.fillSouthProperStopper(new Instruction[] {
1411 new Instruction.Set(dock,Predicate.IgnoreFlagD, CLEAR_FLAG, CLEAR_FLAG),
1412 new Instruction.Move(dock,
1413 Predicate.IgnoreFlagD, // predicate
1414 false, // torpedoable
1423 new Instruction.Set(dock,Predicate.IgnoreFlagD, SET_FLAG, SET_FLAG),
1425 model.waitNS(64 * CYCLE_TIME_NS);
1427 prln("checking to confirm that A flag is cleared");
1428 fatal(marina.getFlagA(), "bad A flag: "+marina.getFlagA());
1430 prln("inserting data item in north fifo ring");
1431 BitVector data = new BitVector(37, "empty");
1432 BitVector addr = new BitVector(14, "empty");
1433 for(int i=0; i<data.getNumBits(); i++) data.set(i, false);
1434 for(int i=0; i<addr.getNumBits(); i++) addr.set(i, false);
1435 marina.fillNorthProperStopper(new MarinaPacket(data, false, addr));
1436 model.waitNS(64 * CYCLE_TIME_NS);
1438 prln("checking to see if A flag got set");
1439 fatal(!marina.getFlagA(), "bad A flag: "+marina.getFlagA());
1442 prln("End recvData");
1446 private void testRecvAndSendWalkingOne(Marina marina) {
1447 prln("Begin testRecvAndSendWalkingOne");
1450 marina.instrIn.fill(setIlc(1));
1452 List<BitVector> dataItems;
1453 for(int bit=0; bit<37; bit++) {
1455 BitVector data = new BitVector(37, "empty");
1456 BitVector addr = new BitVector(14, "empty");
1457 for(int i=0; i<data.getNumBits(); i++) data.set(i, false);
1458 for(int i=0; i<addr.getNumBits(); i++) addr.set(i, false);
1459 data.set(bit, true);
1460 prln("testing with bit pattern " + data);
1462 prln("inserting data item into north fifo ring");
1463 marina.fillNorthProperStopper(new MarinaPacket(data, false, addr));
1465 prln("stopping the north proper stopper");
1468 dataItems = marina.data.drainMany(1);
1469 fatal(dataItems.size()!=0,
1470 "found a data item waiting in the north proper stopper, but should not have");
1472 marina.instrIn.fill(new Instruction.Move(dock,
1473 Predicate.IgnoreFlagD, // predicate
1474 false, // torpedoable
1484 dataItems = marina.data.drainMany(2);
1485 fatal(dataItems.size()!=1,
1486 "found "+dataItems.size()+" data items in north fifo; expected one");
1487 MarinaPacket mp = new MarinaPacket(dataItems.get(0));
1488 fatalIfBitVectorsDoNotMatch(mp.data, data);
1492 prln("End testRecvAndSendWalkingOne");
1497 private void setOlcFromDataLatch(Marina marina) {
1498 prln("Begin setOlcFromDataLatch");
1501 marina.instrIn.fill(setIlc(1));
1503 // walk a bit from 0 to 5
1504 for(int bit=0; bit<6; bit++) {
1505 prln("inserting data item in north fifo ring");
1506 BitVector data = new BitVector(37, "empty");
1507 BitVector addr = new BitVector(14, "empty");
1508 for(int i=0; i<data.getNumBits(); i++) data.set(i, false);
1509 for(int i=0; i<addr.getNumBits(); i++) addr.set(i, false);
1510 data.set(bit, true);
1511 marina.fillNorthProperStopper(new MarinaPacket(data, false, addr));
1513 marina.fillSouthProperStopper(new Instruction[] {
1515 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter,SetSource.DataLatch),
1516 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.DataLatch,-1),
1519 model.waitNS(CYCLE_TIME_NS * 64);
1523 if (marina.kesselsCounter) {
1524 // master clear on each iteration; otherwise we'd need to "run down" the olc
1525 marina.masterClear();
1526 marina.enableInstructionSend(true);
1531 prln("End setOlcFromDataLatch");
1534 private void setIlcFromDataLatch(Marina marina) {
1535 prln("Begin setIlcFromDataLatch");
1538 marina.instrIn.fill(setIlc(1));
1540 // walk a bit from 0 to 5
1541 for(int bit=5; bit>=0; bit--) {
1542 prln("inserting data item in north fifo ring");
1543 BitVector data = new BitVector(37, "empty");
1544 BitVector addr = new BitVector(14, "empty");
1545 for(int i=0; i<data.getNumBits(); i++) data.set(i, false);
1546 for(int i=0; i<addr.getNumBits(); i++) addr.set(i, false);
1547 data.set(bit, true);
1548 marina.fillNorthProperStopper(new MarinaPacket(data, false, addr));
1550 marina.fillSouthProperStopper(new Instruction[] {
1551 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter,1),
1553 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter,SetSource.DataLatch),
1555 model.waitNS(CYCLE_TIME_NS * 64);
1557 int ilc = marina.getILC().getCount();
1558 fatal(ilc != (1<<bit), "expected ilc to be " + (1<<bit) + ", but got " + ilc);
1562 prln("End setIlcFromDataLatch");
1565 private void testSendAndRecvToken(Marina marina) {
1566 prln("Begin testSendAndRecvToken");
1569 marina.instrIn.fill(setIlc(1));
1570 marina.fillSouthProperStopper(new Instruction[] {
1575 expectNorthFifoExactly(1);
1578 prln("End testSendAndRecvToken");
1581 private void testSignExtendedLiteral(Marina marina) {
1582 prln("Begin testSignExtendedLiteral");
1585 marina.instrIn.fill(setIlc(1));
1586 for(long val : new long[] { (-1L << 14), -1, 0, 1 }) {
1588 marina.fillSouthProperStopper(new Instruction[] {
1589 new Instruction.Set(dock,Predicate.IgnoreFlagD,
1590 Instruction.Set.SetDest.DataLatch,
1594 model.waitNS(CYCLE_TIME_NS * 64);
1596 List<BitVector> dataItems = marina.data.drainMany(3);
1597 fatal(dataItems.size()!=1, "expected exactly one data item, got " + dataItems.size());
1599 MarinaPacket mp = new MarinaPacket(dataItems.get(0));
1600 BitVector bv = mp.data;
1601 prln("got back " + mp);
1603 boolean mismatch = false;
1605 for(int i=0; i<37; i++) {
1606 if (bv.get(i) != ( (val & (1L << i)) != 0 )) {
1611 fatal(mismatch, "data read back did not match inserted literal; mismatch on bits " + err);
1615 prln("End testSignExtendedLiteral");
1618 private void testShiftedLiteral(Marina marina) {
1619 prln("Begin testShiftedLiteral");
1622 marina.instrIn.fill(setIlc(1));
1623 marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD,
1624 Instruction.Set.SetDest.DataLatch,
1627 BitVector dreg = new BitVector(37, "what we think is in the d-register");
1628 for(int i=0; i<37; i++) dreg.set(i, false);
1630 for(long val : new long[] { -1, 0, 1, (-1L << 18) }) {
1632 edu.berkeley.fleet.api.BitVector immediate =
1633 new edu.berkeley.fleet.api.BitVector(19);
1634 for(int i=0; i<immediate.length(); i++)
1635 immediate.set(i, (val & (1L << i)) != 0);
1637 // shift over 19 LSB's towards MSB
1638 for(int i=0; i<19; i++)
1639 if (i+19 <= 36) dreg.set(i+19, dreg.get(i));
1640 for(int i=0; i<19; i++)
1641 dreg.set(i, immediate.get(i));
1643 marina.fillSouthProperStopper(new Instruction[] {
1644 new Instruction.Shift(dock,Predicate.IgnoreFlagD,immediate),
1648 model.waitNS(CYCLE_TIME_NS * 64);
1649 List<BitVector> dataItems = marina.data.drainMany(3);
1650 fatal(dataItems.size()!=1, "expected exactly one data item, got " + dataItems.size());
1652 BitVector bv = new MarinaPacket(dataItems.get(0)).data;
1653 fatal(!bv.equals(dreg), "data read back did not match inserted literal.\n" +
1654 "got: "+bv.bitReverse().getState()+"\n"+
1655 "expected:"+dreg.bitReverse().getState());
1659 prln("End testShiftedLiteral");
1662 private void testFlagC(Marina marina) {
1663 prln("Begin testFlagC");
1671 // Dc=1 => sigS is copied into C-flag
1672 // Dc=0 => sigA is copied into C-flag
1674 marina.instrIn.fill(setIlc(1));
1675 for(boolean dc : new boolean[] { false, true }) {
1676 for(boolean c_flag : new boolean[] { true, false, true }) {
1679 prln("****** checking case where dc="+dc+", cflag="+c_flag);
1680 BitVector data = new BitVector(37, "empty");
1681 BitVector addr = new BitVector(14, "empty");
1682 for(int i=0; i<data.getNumBits(); i++) data.set(i, false);
1683 for(int i=0; i<addr.getNumBits(); i++) addr.set(i, false);
1686 ? Marina.INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE
1687 : Marina.INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO;
1688 prln("setting addr["+whichbit+"] to "+(c_flag?"1":"0"));
1689 addr.set(whichbit, c_flag);
1691 prln("... and filling north fifo proper stopper");
1692 marina.fillNorthProperStopper(new MarinaPacket(data, false, addr));
1694 prln("clearing flags");
1695 prln("executing recv data with Dc="+dc);
1696 prln("copying c-flag to a-flag");
1697 marina.fillSouthProperStopper(new Instruction[] {
1698 new Instruction.Set(dock,Predicate.IgnoreFlagD, CLEAR_FLAG, CLEAR_FLAG),
1699 new Instruction.Move(dock,
1700 Predicate.IgnoreFlagD, /* predicate */
1701 true, /* torpedoable */
1703 false, /* tokenIn */
1706 false, /* latchPath */
1707 false, /* dataOut */
1708 false /* tokenOut */
1711 new Instruction.Set(dock,Predicate.IgnoreFlagD,
1712 Instruction.Set.FlagFunction.ZERO.add(Predicate.FlagC),
1717 model.waitNS(CYCLE_TIME_NS * 64);
1719 prln("checking to confirm that A flag is " + c_flag);
1720 fatal(marina.getFlagA()!=c_flag, "bad A flag: "+marina.getFlagA());
1724 prln("End testFlagC");
1727 private void sendDataWithPath(Marina marina) {
1728 prln("Begin sendDataWithPath");
1731 edu.berkeley.fleet.api.BitVector bv = new edu.berkeley.fleet.api.BitVector(13);
1732 marina.instrIn.fill(setIlc(1));
1734 // alternating ones and zeroes
1735 for(int i=0; i<bv.length(); i+=2)
1737 // and then ones in the lower four bits so it's not symmetric
1738 for(int i=0; i<4; i++)
1741 MarinaPath path = new MarinaPath((MarinaFleet)dock.getShip().getFleet(), bv);
1743 marina.fillSouthProperStopper(new Instruction[] {
1744 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter,1),
1745 new Instruction.Move(dock,
1746 Predicate.IgnoreFlagD, /* predicate */
1747 false, /* torpedoable */
1749 false, /* tokenIn */
1751 false, /* latchData */
1752 false, /* latchPath */
1754 false /* tokenOut */
1758 List<BitVector> dataItems;
1761 dataItems = marina.data.drainMany();
1762 fatal(dataItems.size()!=1, "Expected one data item to emerge but got: "+dataItems.size()+" data items");
1763 mp = new MarinaPacket(dataItems.get(0));
1765 // the 14th bit of the outbound address cannot be set by the
1766 // ship, so we don't care about it
1767 fatalIfBitVectorsDoNotMatch(MarinaUtils.berkToSun(bv), mp.path.get(0,13));
1769 prln("send data with no change to path");
1770 marina.instrIn.fill(new Instruction.Move(dock,
1771 Predicate.IgnoreFlagD, /* predicate */
1772 false, /* torpedoable */
1774 false, /* tokenIn */
1776 false, /* latchData */
1777 false, /* latchPath */
1779 false /* tokenOut */
1782 dataItems = marina.data.drainMany();
1783 fatal(dataItems.size()!=1, "Expected one data item to emerge but got: "+dataItems.size()+" data items");
1784 mp = new MarinaPacket(dataItems.get(0));
1786 // the 14th bit of the outbound address cannot be set by the
1787 // ship, so we don't care about it
1788 fatalIfBitVectorsDoNotMatch(MarinaUtils.berkToSun(bv), mp.path.get(0,13));
1791 prln("End sendDataWithPath");
1794 private void recvPath(Marina marina) {
1795 prln("Begin recvPath");
1798 marina.instrIn.fill(setIlc(1));
1799 for(int bit=0; bit<11; bit++) {
1800 BitVector packet_data = new BitVector(37, "inbound data item");
1801 for(int i=0; i<37; i++) packet_data.set(i, false);
1802 packet_data.set(27+bit, true);
1803 BitVector packet_path = new BitVector(14, "inbound data item");
1804 for(int i=0; i<14; i++) packet_path.set(i, false);
1806 marina.fillNorthProperStopper(new MarinaPacket(packet_data, false, packet_path));
1808 prln("recv path, send data (using recv'd path)");
1809 marina.instrIn.fill(new Instruction.Move(dock,
1810 Predicate.IgnoreFlagD, /* predicate */
1811 false, /* torpedoable */
1813 false, /* tokenIn */
1815 true, /* latchData */
1816 true, /* latchPath */
1818 false /* tokenOut */
1821 List<BitVector> dataItems = marina.data.drainMany();
1822 fatal(dataItems.size()!=1, "Expected one data item to emerge but got: "+dataItems.size()+" data items");
1823 MarinaPacket mp = new MarinaPacket(dataItems.get(0));
1825 fatalIfBitVectorsDoNotMatch(packet_data.get(25,11), mp.path.get(0,11));
1826 fatalIfBitVectorsDoNotMatch(packet_data, mp.data);
1830 prln("End recvPath");
1833 private void testILC(Marina marina) {
1834 prln("Begin testILC");
1837 for(int bit=0; bit<6; bit++) {
1838 int ilc = bit<0 ? 0 : (1<<bit);
1839 marina.fillSouthProperStopper(new Instruction[] {
1840 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter,ilc),
1843 List<BitVector> dataItems = marina.data.drainMany();
1844 fatal(dataItems.size()!=ilc, "Expected "+ilc+" data item(s) to emerge but got: "+dataItems.size()+" data items");
1848 prln("End testILC");
1851 private void testILCZero(Marina marina) {
1853 marina.fillSouthProperStopper(new Instruction[] {
1854 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter,0),
1858 expectNorthFifoNoMoreThan(0);
1859 expectTokensExactly(1);
1863 private void sendTorpedo(Marina marina) {
1864 prln("Begin sendTorpedo");
1866 marina.instrIn.fill(setIlc(1));
1867 marina.instrIn.fill(setOlc(63));
1869 model.waitNS(128 * CYCLE_TIME_NS);
1872 marina.instrIn.fill(new
1873 Instruction.Set(dock,Predicate.IgnoreFlagD, CLEAR_FLAG, CLEAR_FLAG));
1874 fatal(marina.getFlagA(), "bad A flag: true");
1875 fatal(marina.getFlagB(), "bad B flag: true");
1877 prln("execute a move instruction that does nothing but loops until torpedo arrives");
1878 prln("A=1, B=B This instruction should not execute because D-flag is set");
1879 prln("Set A=A, B=1 This instruction should execute because D-flag is set");
1881 model.waitNS(128 * CYCLE_TIME_NS);
1883 marina.fillSouthProperStopper(new Instruction[] {
1884 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter, SetSource.Infinity),
1885 new Instruction.Move(dock,
1886 Predicate.IgnoreFlagD, // predicate
1887 true, // torpedoable
1896 new Instruction.Set(dock,Predicate.Default,
1898 Instruction.Set.FlagFunction.ZERO.add(Predicate.FlagB)
1900 new Instruction.Set(dock, Predicate.FlagD,
1901 Instruction.Set.FlagFunction.ZERO.add(Predicate.FlagA),
1906 model.waitNS(128 * CYCLE_TIME_NS);
1908 prln("send torpedo. This should clear the OLC");
1909 marina.instrIn.fillTorpedo();
1910 model.waitNS(128 * CYCLE_TIME_NS);
1912 model.waitNS(128 * CYCLE_TIME_NS);
1914 prln("A should remain false, B should be true");
1915 fatal(marina.getFlagA(), "bad A flag: true");
1916 fatal(!marina.getFlagB(), "bad B flag: false");
1918 model.waitNS(128 * CYCLE_TIME_NS);
1920 prln("Reload OLC after torpedo, clears D-flag");
1921 marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, 63));
1923 // FIXME: find another way to test this
1924 model.waitNS(128 * CYCLE_TIME_NS);
1927 prln("Set A=1, B=1 This instruction should execute because OLC!=0");
1928 marina.instrIn.fill(new
1929 Instruction.Set(dock,Predicate.Default, SET_FLAG, SET_FLAG));
1931 prln("A and B should be true");
1932 fatal(!marina.getFlagA(), "bad A flag: false");
1933 fatal(!marina.getFlagB(), "bad B flag: false");
1936 prln("End sendTorpedo");
1939 private void testTorpedoOnAnInfinite(Marina marina) {
1940 prln("Begin testTorpedoOnAnInfinite");
1943 List<BitVector> dataItems;
1945 marina.instrIn.fill(setIlc(1));
1946 for(boolean torpedoable : new boolean[] { true, false }) {
1948 marina.fillSouthProperStopper(new Instruction[] {
1949 new Instruction.Move(dock,
1950 Predicate.IgnoreFlagD, // predicate
1951 false, // torpedoable
1960 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter,SetSource.Infinity),
1961 new Instruction.Move(dock,
1962 Predicate.IgnoreFlagD, // predicate
1963 torpedoable, // torpedoable
1972 // FIXME: this probably should be removed, unless Ivan doesn't want to change the behavior
1973 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter,1),
1978 // expect nothing to come out, because the NOP is executing
1979 dataItems = marina.data.drainMany(2);
1980 fatal(dataItems.size()!=0, "Expected no data item(s) to emerge but got at least: "+dataItems.size()+" data items");
1982 marina.instrIn.fillTorpedo();
1984 int expected = torpedoable?1:0;
1985 dataItems = marina.data.drainMany(2);
1986 fatal(dataItems.size()!=expected, "Expected "+expected+" item to emerge but got: "+dataItems.size()+" data items");
1988 fatal(!marina.getILC().getDone(), "Expected ilc=done, but got "+marina.getILC());
1992 prln("End testTorpedoOnAnInfinite");
1995 private void testDFlagWhenTorpedoLyingInWait(Marina marina) {
1996 marina.fillSouthProperStopper(new Instruction[] {
1998 TORPEDOABLE_RECV_DATA,
1999 marina.kesselsCounter ? null : FLAG_NOP,
2002 marina.instrIn.fillTorpedo();
2003 model.waitNS(64 * CYCLE_TIME_NS);
2004 marina.fillNorthProperStopper();
2005 model.waitNS(64 * CYCLE_TIME_NS);
2006 expectNorthFifoExactly(1);
2009 private void testSetOlcFollowedByDPredicated(Marina marina) {
2010 for(boolean d_set : new boolean[] { false, true }) {
2012 marina.fillSouthProperStopper(new Instruction[] {
2014 marina.kesselsCounter ? null : FLAG_NOP,
2015 d_set ? SEND_DATA_IF_D_SET : SEND_DATA_IF_D_NOT_SET,
2017 expectNorthFifoExactly(d_set ? 1 : 0);
2020 marina.fillSouthProperStopper(new Instruction[] {
2022 marina.kesselsCounter ? null : FLAG_NOP,
2023 d_set ? SEND_DATA_IF_D_SET : SEND_DATA_IF_D_NOT_SET,
2025 expectNorthFifoExactly(d_set ? 0 : 1);
2027 if (marina.kesselsCounter) {
2028 marina.masterClear();
2029 marina.enableInstructionSend(true);
2034 private void testOlcDecrementAtHighSpeed(Marina marina) {
2035 prln("Begin testOlcDecrementAtHighSpeed");
2038 List<BitVector> dataItems;
2040 // Each element of the following pair of arrays is one "test".
2041 // The OLC will be loaded with olcs[i] and then decremented
2042 // decr_amounts[i] times; after that has happened the zeroness
2043 // of the OLC will be checked by executing a MOVE with
2044 // [olc!=0] as the predicate.
2046 int[] olcs = new int[] { 3, 3, 3, 10, 41 };
2047 int[] decr_amounts = new int[] { 2, 3, 4, 9, 9 };
2049 for(int which=0; which<olcs.length; which++) {
2050 int olc = olcs[which];
2051 int decr_amount = decr_amounts[which];
2053 prln("inserting set olc="+olc);
2054 prln("inserting set ilc=1");
2055 marina.fillSouthProperStopper(new Instruction[] {
2056 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter,1),
2057 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter,olc),
2060 // commenting the following four lines causes this test to pass
2062 prln("inserting: "+decr_amount+" olc-- instructions");
2063 prln("inserting: [!d] send data");
2064 Instruction[] instructions = new Instruction[decr_amount+1];
2065 for(int i=0; i<decr_amount; i++)
2067 new Instruction.Set(dock,
2069 SetDest.OuterLoopCounter,
2070 SetSource.Decrement);
2071 instructions[instructions.length-1] =
2072 new Instruction.Move(dock,
2073 Predicate.Default, // predicate
2074 false, // torpedoable
2084 marina.fillSouthProperStopper(instructions);
2085 model.waitNS(64 * CYCLE_TIME_NS);
2087 int expected = decr_amount>=olc ? 0 : 1;
2088 dataItems = marina.data.drainMany(2);
2089 fatal(dataItems.size()!=expected, "Expected "+expected+" item to emerge but got: "+dataItems.size()+" data items");
2091 if (marina.kesselsCounter) {
2092 // master clear on each iteration; otherwise we'd need to "run down" the olc
2093 marina.masterClear();
2094 marina.enableInstructionSend(true);
2099 prln("End testOlcDecrementAtHighSpeed");
2102 private void flipIlcBit(Marina marina) {
2103 prln("Begin flipIlcBit");
2105 prln("Using the set ILC instruction, toggle a single bit between zero and one. \n" +
2106 "Check correct setting of the ILC zero bit");
2108 for (int i=0; i<6; i++) {
2111 prln("Then immediately set ILC="+notZero);
2112 marina.fillSouthProperStopper(new Instruction[] {
2113 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter, 0),
2114 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter, notZero),
2117 model.waitNS(64 * CYCLE_TIME_NS);
2119 prln("Verify ILC using scan chain");
2120 Ilc ilc = marina.getILC();
2121 int ilcCount = ilc.getCount();
2122 fatal(ilcCount!=notZero, "bad ILC count: "+ilcCount+" expected: "+notZero);
2123 fatal(ilc.getInfinity(), "bad ILC Infinity bit: true");
2125 marina.fillSouthProperStopper(new Instruction[] {
2126 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter, notZero),
2127 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.InnerLoopCounter, 0),
2130 model.waitNS(64 * CYCLE_TIME_NS);
2132 prln("Verify ILC using scan chain");
2133 ilc = marina.getILC();
2134 ilcCount = ilc.getCount();
2135 fatal(ilcCount!=0, "bad ILC count: "+ilcCount+" expected: 0");
2136 fatal(ilc.getInfinity(), "bad ILC Infinity bit: true");
2140 prln("End flipIlcBit");
2142 private void flipOlcBit(Marina marina) {
2143 prln("Begin flipOlcBit");
2145 prln("Using the set OLC instruction, toggle a single bit between zero and one. \n" +
2146 "Check correct setting of the OLC zero bit");
2148 marina.instrIn.fill(new Instruction.Set(dock,Predicate.IgnoreFlagD, CLEAR_FLAG, CLEAR_FLAG));
2150 for (int i=0; i<6; i++) {
2151 int notZero = 32 >> i;
2153 if (marina.kesselsCounter) {
2154 // master clear on each iteration; otherwise we'd need to "run down" the olc
2155 marina.masterClear();
2156 marina.enableInstructionSend(true);
2161 prln("Then immediately set OLC="+notZero);
2162 marina.fillSouthProperStopper(new Instruction[] {
2163 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, 0),
2164 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, notZero),
2167 model.waitNS(64 * CYCLE_TIME_NS);
2168 prln("Verify OLC count using scan chain");
2171 if (!marina.kesselsCounter) {
2172 prln("Set OLC="+notZero);
2173 prln("Then immediately set OLC=0");
2174 marina.fillSouthProperStopper(new Instruction[] {
2175 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, notZero),
2176 new Instruction.Set(dock,Predicate.IgnoreFlagD,SetDest.OuterLoopCounter, 0),
2179 model.waitNS(64 * CYCLE_TIME_NS);
2180 prln("Verify OLC count using scan chain");
2186 prln("End flipOlcBit");
2188 private void testSouthRecirculate(Marina marina, int AMOUNT) {
2189 prln("Begin testSouthRecirculate("+AMOUNT+")");
2192 marina.enableInstructionSend(false);
2193 marina.enableInstructionRecirculate(true);
2195 prln("Completely fill south ring");
2197 for (int i=0; i<AMOUNT; i++) {
2198 prln("inserting item " + (i+1) + " / " + AMOUNT);
2199 BitVector path = new BitVector(MarinaPacket.PATH_WIDTH, "path");
2200 BitVector data = new BitVector(MarinaPacket.WORD_WIDTH, "path");
2201 path.set(0, MarinaPacket.PATH_WIDTH, false);
2202 data.setFromLong(i+9);
2203 marina.instrIn.fill(new MarinaPacket(data, false, path));
2207 prln("Drain south ring and check contents");
2209 List<BitVector> out = marina.instrIn.drainMany();
2210 boolean bad = false;
2211 for (int i=0; i<AMOUNT; i++) {
2212 prln("extracting item " + (i+1) + " / " + AMOUNT);
2213 //int expect = (i+Marina.SOUTH_RING_CAPACITY-1) % Marina.SOUTH_RING_CAPACITY;
2215 long got = new MarinaPacket(out.get(i)).data.toLong();
2218 prln(" bad instruction: "+got+" expected: "+expect);
2220 prln(" good instruction.");
2223 fatal(bad, "data inserted does not match data retrieved");
2226 for (int i=0; i<5; i++) {}
2229 prln("End testSouthRecirculate("+AMOUNT+")");
2233 private void testOverfillTokens(Marina marina) {
2234 prln("Begin testOverfillTokens");
2237 for(int i=0; i<marina.TOKEN_FIFO_CAPACITY + 3; i++)
2238 marina.instrIn.fill(SEND_TOKEN);
2239 marina.instrIn.fill(SEND_DATA);
2240 expectNorthFifoExactly(0);
2243 prln("End testSouthRecirculate");
2248 private void doOneTest(int testNum) {
2250 prln("============================================================");
2251 prln("MarinaTest: performing test: "+testNum);
2254 marina.masterClear();
2255 marina.enableInstructionSend(true);
2262 doOneTest(1); // passes extracted parasitics
2263 doOneTest(2); // passes extracted parasitics
2264 doOneTest(3); // passes extracted parasitics
2265 doOneTest(4); // passes extracted parasitics
2266 doOneTest(5); // passes extracted parasitics
2269 doOneTest(1000); // passes extracted parasitics
2270 doOneTest(1001); // passes extracted parasitics
2271 doOneTest(1003); // passes extracted parasitics
2273 doOneTest(3000); // passes extracted parasitics
2274 doOneTest(3001); // passes extracted parasitics
2275 doOneTest(3003); // passes extracted parasitics
2276 doOneTest(3004); // passes extracted parasitics
2277 doOneTest(3005); // passes extracted parasitics
2278 doOneTest(3006); // passes extracted parasitics
2279 doOneTest(3007); // passes extracted parasitics
2280 doOneTest(3008); // passes extracted parasitics
2281 doOneTest(3009); // passes extracted parasitics
2282 doOneTest(3010); // passes extracted parasitics
2283 doOneTest(3011); // passes extracted parasitics
2284 doOneTest(3012); // passes extracted parasitics
2285 doOneTest(3013); // passes extracted parasitics
2286 doOneTest(3014); // passes extracted parasitics
2287 doOneTest(3015); // passes extracted parasitics
2288 doOneTest(3019); // passes extracted parasitics
2289 doOneTest(3020); // passes extracted parasitics
2290 doOneTest(3022); // passes extracted parasitics
2291 doOneTest(3023); // passes extracted parasitics
2292 doOneTest(3025); // passes extracted parasitics
2293 doOneTest(3026); // passes extracted parasitics
2294 doOneTest(3027); // passes extracted parasitics
2295 doOneTest(3028); // passes extracted parasitics
2296 doOneTest(3029); // passes extracted parasitics
2297 doOneTest(3030); // passes extracted parasitics
2298 doOneTest(3031); // passes extracted parasitics
2300 // these tests take a while and usually pass
2312 // this takes an insanely long time
2316 case 1: testChains(marina); break; // passes, 24-Mar (+verilog)
2317 case 2: testProperStoppers(marina); break; // passes, 24-Mar (+verilog)
2318 case 3: testSouthRecirculate(marina, 1); break; // passes, 24-Mar (+verilog)
2319 case 4: getCtrsFlags(marina); break; // 20-Apr (+verilog)
2320 case 5: sendInstructions(marina); break; // passes, 24-Mar (+verilog)
2321 case 6: walkOneOLC(marina); break; // 21-Apr (+verilog)
2323 // Russell's tests begin with 1000
2324 case 1000: walkOneILC(marina); break; // 20-Apr (+verilog)
2325 case 1001: countIlc(marina); break; // 20-Apr (+verilog)
2326 case 1002: countOlc(marina); break; // 23-Apr (+verilog)
2328 case 1003: sendTorpedo(marina); break; // 23-Apr (+verilog) [with wor-hack]
2330 case 1004: flipIlcBit(marina); break; // 20-Apr (+verilog)
2331 case 1005: flipOlcBit(marina); break; // 21-Apr (+verilog)
2333 case 1006: testSouthRecirculate(marina, Marina.SOUTH_RING_CAPACITY-1); break; // passes, 24-Mar (+verilog)
2335 // Adam's tests begin with 3000
2336 case 3000: sendToken(marina); break; // passes, 24-Mar (+verilog)
2337 case 3001: testFlagAB(marina); break; // passes, 08-Apr (+verilog)
2338 case 3002: testPredicationOnAB(marina); break; // 22-Apr (+verilog)
2339 case 3003: testFlagC(marina); break; // 23-Apr (+verilog)
2340 case 3004: testFlagD(marina); break; // 23-Apr (+verilog)
2341 case 3005: testFlagDRecomputationTime(marina); break;
2343 case 3006: testTailWaitsForHead(marina); break;
2344 case 3007: testTailWithoutHead(marina); break;
2345 case 3008: testHeadWaitsForTail(marina); break; // 22-Apr (+verilog)
2346 case 3009: testAbort(marina); break; // 22-Apr (+verilog)
2348 case 3010: sendData(marina); break; // passes, 24-Mar (+verilog)
2349 case 3011: recvData(marina); break; // 21-Apr (+verilog)
2350 case 3012: sendDataWithPath(marina); break; // passes, 13-Apr (+verilog)
2352 case 3013: testSignExtendedLiteral(marina); break; // 20-Apr (+verilog)
2353 case 3014: testShiftedLiteral(marina); break; // 20-Apr (+verilog)
2354 case 3015: testSendAndRecvToken(marina); break; // 21-Apr (+verilog)
2356 case 3016: sendDataIlcInfinite(marina); break; // 22-Apr (+verilog)
2357 case 3017: testFlagTruthTable(marina); break; // 23-Apr (+verilog)
2359 case 3019: setOlcFromDataLatch(marina); break; // 23-Apr (+verilog)
2360 case 3020: setIlcFromDataLatch(marina); break; // 23-Apr (+verilog)
2361 case 3021: recvPath(marina); break; // 22-Apr (+verilog)
2362 case 3022: testILC(marina); break; // 23-Apr (+verilog)
2363 case 3023: testTorpedoOnAnInfinite(marina); break; // 23-Apr (+verilog)
2364 case 3024: testRecvAndSendWalkingOne(marina); break; // 21-Apr (+verilog)
2365 case 3025: testOlcDecrementAtHighSpeed(marina); break; // 23-Apr (+verilog)
2367 case 3026: testNonTorpedoableMoveDoesNotResetDFlag(marina); break; // 23-Apr (+verilog)
2368 case 3027: testILCZero(marina); break;
2369 case 3028: testAbortOutsideOfLoop(marina); break;
2370 case 3029: testDFlagWhenTorpedoLyingInWait(marina); break;
2371 case 3030: testSetOlcFollowedByDPredicated(marina); break;
2372 case 3031: testOverfillTokens(marina); break;
2374 case 3040: loadEveryValueOLC(marina); break;
2377 fatal(true, "Test number: "+testNum+" doesn't exist.");
2380 // If we get here then test passed
2381 prln("Test Result: Passed");
2383 //Infrastructure.exit(0);
2384 } catch (MarinaUtils.FailureException fe) {
2385 System.out.println("******************************************************************************");
2386 System.out.println("******************************************************************************");
2387 System.out.println("******************************************************************************");
2388 System.out.println("******************************************************************************");
2389 fe.printStackTrace();
2394 //============================ for public use =============================
2397 * 0: test detected success
2398 * 2: test detected failure
2401 public static void main(String[] args) {
2402 startTime = System.currentTimeMillis();
2403 new MarinaTest(args);