/** the dock which is to execute this instruction */
public final Dock dock;
- /** true if the instruction is an outer-looping instruction */
- public final boolean looping;
-
/** the instruction's predicate */
public final Predicate predicate;
- Instruction(Dock dock, boolean looping, Predicate predicate) {
+ Instruction(Dock dock, Predicate predicate) {
if (dock==null) throw new RuntimeException("dock may not be null");
if (predicate==null) throw new RuntimeException("predicate may not be null");
this.dock = dock;
- this.looping = looping;
this.predicate = predicate;
}
public String toString() {
String s = predicate.toString();
if (s.length()>0) s = "["+s+"] ";
- if (looping) s += "[Rq] ";
return dock+": "+s;
}
public final FlagFunction newFlagB;
/** basic constructor */
- public Set(Dock dock, SetDest dest, SetSource source) { this(dock, false, Predicate.Default, dest, source); }
- public Set(Dock dock, boolean looping, Predicate predicate, SetDest dest, SetSource source) {
- super(dock, looping, predicate);
+ public Set(Dock dock, SetDest dest, SetSource source) { this(dock, Predicate.Default, dest, source); }
+ public Set(Dock dock, Predicate predicate, SetDest dest, SetSource source) {
+ super(dock, predicate);
OUTER: switch(dest) {
case InnerLoopCounter:
switch(source) {
}
/** constructor for set instructions with immediates */
- public Set(Dock dock, SetDest dest, long immediate) { this(dock, false, Predicate.Default, dest, immediate); }
- public Set(Dock dock, boolean looping, Predicate predicate, SetDest dest, long immediate) {
- super(dock, looping, predicate);
+ public Set(Dock dock, SetDest dest, long immediate) { this(dock, Predicate.Default, dest, immediate); }
+ public Set(Dock dock, Predicate predicate, SetDest dest, long immediate) {
+ super(dock, predicate);
if (dest!=SetDest.InnerLoopCounter && dest!=SetDest.OuterLoopCounter && dest!=SetDest.DataLatch)
throw new RuntimeException("a set instruction with dest="+dest+" may not take an immediate");
this.source = SetSource.Immediate;
}
/** constructor for <tt>set flags</tt> instructions */
- public Set(Dock dock, FlagFunction newFlagA, FlagFunction newFlagB) { this(dock, false, Predicate.Default, newFlagA, newFlagB); }
- public Set(Dock dock, boolean looping, Predicate predicate, FlagFunction newFlagA, FlagFunction newFlagB) {
- super(dock, looping, predicate);
+ public Set(Dock dock, FlagFunction newFlagA, FlagFunction newFlagB) { this(dock, Predicate.Default, newFlagA, newFlagB); }
+ public Set(Dock dock, Predicate predicate, FlagFunction newFlagA, FlagFunction newFlagB) {
+ super(dock, predicate);
this.source = SetSource.Immediate;
this.dest = SetDest.Flags;
this.immediate = 0;
/** shifts an immediate into the low-order bits of the data latch */
public static class Shift extends Instruction {
public final BitVector immediate;
- public Shift(Dock dock, BitVector immediate) { this(dock, false, Predicate.Default, immediate); }
- public Shift(Dock dock, boolean looping, Predicate predicate, BitVector immediate) {
- super(dock, looping, predicate);
+ public Shift(Dock dock, BitVector immediate) { this(dock, Predicate.Default, immediate); }
+ public Shift(Dock dock, Predicate predicate, BitVector immediate) {
+ super(dock, predicate);
this.immediate = immediate;
this.immediate.setImmutable();
if (immediate.length() != dock.getShip().getFleet().getShiftWidth())
/** a flush instruction */
public static class Flush extends Instruction {
- public Flush(Dock dock) { this(dock, false, Predicate.Default); }
- public Flush(Dock dock, boolean looping, Predicate predicate) {
- super(dock, looping, predicate);
+ public Flush(Dock dock) { this(dock, Predicate.Default); }
+ public Flush(Dock dock, Predicate predicate) {
+ super(dock, predicate);
if (!dock.isInputDock()) throw new RuntimeException("Flush is only allowed at input docks");
}
public String toString() { return super.toString()+"flush"; }
boolean dataOut,
boolean tokenOut
) {
- this(dock, false, Predicate.Default, false, path, tokenIn, dataIn, latchData, latchPath, dataOut, tokenOut); }
+ this(dock, Predicate.Default, false, path, tokenIn, dataIn, latchData, latchPath, dataOut, tokenOut); }
public Move(Dock dock,
- boolean looping,
Predicate predicate,
boolean interruptible,
Path path,
boolean dataOut,
boolean tokenOut
) {
- super(dock, looping, predicate);
+ super(dock, predicate);
this.path = path;
this.tokenIn = tokenIn;
this.dataIn = dataIn;
/** a flush instruction */
public static class Abort extends Instruction {
- public Abort(Dock dock, Predicate predicate) { super(dock, false, predicate); }
+ public Abort(Dock dock, Predicate predicate) { super(dock, predicate); }
public String toString() { return super.toString()+"abort;"; }
}
/** marks the start of a loop; closes the hatch */
public static class Head extends Instruction {
- public Head(Dock dock) { super(dock, false, Predicate.IgnoreFlagD); }
+ public Head(Dock dock) { super(dock, Predicate.IgnoreFlagD); }
public String toString() { return dock+": head;"; }
}
/** marks the end of a loop; closes the hatch */
public static class Tail extends Instruction {
- public Tail(Dock dock) { super(dock, false, Predicate.IgnoreFlagD); }
+ public Tail(Dock dock) { super(dock, Predicate.IgnoreFlagD); }
public String toString() { return dock+": tail;"; }
}
long lit = 0;
lit = ((FleetTwoFleet)fleet).CBD_SIZE.setval(lit, codeBags.get((int)old.immediate).size());
lit = ((FleetTwoFleet)fleet).CBD_OFFSET.setval(lit, codeBagMap[(int)old.immediate]);
- inst = new Set(old.dock, false, IgnoreFlagD, SetDest.DataLatch, lit);
+ inst = new Set(old.dock, IgnoreFlagD, SetDest.DataLatch, lit);
}
ret.add(inst);
count++;
for(int i=0; i<instructions.length; i++) {
long lit = ((FleetTwoFleet)fpga).writeInstruction(instructions[i], out);
ret.add(discard(out));
- ret.add(new Instruction.Shift(inDataWrite, false, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(36, 19, lit))));
- ret.add(new Instruction.Shift(inDataWrite, false, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(18, 0, lit))));
+ ret.add(new Instruction.Shift(inDataWrite, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(36, 19, lit))));
+ ret.add(new Instruction.Shift(inDataWrite, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(18, 0, lit))));
ret.add(deliver(inDataWrite));
- ret.add(new Instruction.Shift(inAddrWrite, false, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(36, 19, i))));
- ret.add(new Instruction.Shift(inAddrWrite, false, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(18, 0, i))));
+ ret.add(new Instruction.Shift(inAddrWrite, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(36, 19, i))));
+ ret.add(new Instruction.Shift(inAddrWrite, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(18, 0, i))));
ret.add(deliver(inAddrWrite));
}
- ret.add(new Instruction.Shift(inCBD, false, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(36, 19, startcbd))));
- ret.add(new Instruction.Shift(inCBD, false, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(18, 0, startcbd))));
+ ret.add(new Instruction.Shift(inCBD, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(36, 19, startcbd))));
+ ret.add(new Instruction.Shift(inCBD, IgnoreFlagD, new BitVector(fpga.getShiftWidth()).set(getField(18, 0, startcbd))));
ret.add(wait(inCBD));
ret.add(deliver(inCBD));
ret.add(sendto(out, out.getPath(inCBD.getDataDestination(),null)));
int num = Math.min(count, MAX_ILC);
num_instrs+=2;
count -= num;
- ret.add(new Instruction.Set(ihorn, false, IgnoreFlagD, SetDest.InnerLoopCounter, num));
- ret.add(new Instruction.Move(ihorn, false, IgnoreFlagD, false, null,false,true,true,true,true,false));
+ ret.add(new Instruction.Set(ihorn, IgnoreFlagD, SetDest.InnerLoopCounter, num));
+ ret.add(new Instruction.Move(ihorn, IgnoreFlagD, false, null,false,true,true,true,true,false));
}
if (num_instrs > ihorn.getInstructionFifoSize()) throw new RuntimeException();
int count = 1;
Predicate predicate = Default;
- boolean looping = false;
boolean interruptible = false;
for(int i=0; i<tt.child(0).size(); i++) {
Tree ttt = tt.child(0).child(i);
if ("[!c]".equals(ttt.head())) predicate = NotFlagC;
if ("[*]".equals(ttt.head())) predicate = IgnoreFlagD;
if ("[d]".equals(ttt.head())) predicate = FlagD;
- if ("[Rq]".equals(ttt.head())) looping = true;
}
tt = tt.child(1);
if ("flags".equals(tt.head())) {
- cb.add(new Set(dock, looping, predicate, parseFlags(tt.child(0)), parseFlags(tt.child(1))));
+ cb.add(new Set(dock, predicate, parseFlags(tt.child(0)), parseFlags(tt.child(1))));
continue;
} else if ("olc=word".equals(tt.head())) {
- cb.add(new Set(dock, looping, predicate, SetDest.OuterLoopCounter, SetSource.DataLatch));
+ cb.add(new Set(dock, predicate, SetDest.OuterLoopCounter, SetSource.DataLatch));
continue;
} else if ("ilc=word".equals(tt.head())) {
- cb.add(new Set(dock, looping, predicate, SetDest.InnerLoopCounter, SetSource.DataLatch));
+ cb.add(new Set(dock, predicate, SetDest.InnerLoopCounter, SetSource.DataLatch));
continue;
} else if ("*".equals(tt.head())) {
- cb.add(new Set(dock, looping, predicate, SetDest.InnerLoopCounter, SetSource.Infinity));
+ cb.add(new Set(dock, predicate, SetDest.InnerLoopCounter, SetSource.Infinity));
continue;
} else if ("olc=int".equals(tt.head())) {
- cb.add(new Set(dock, looping, predicate, SetDest.OuterLoopCounter, (number(tt.child(0)))));
+ cb.add(new Set(dock, predicate, SetDest.OuterLoopCounter, (number(tt.child(0)))));
continue;
} else if ("ilc=int".equals(tt.head())) {
- cb.add(new Set(dock, looping, predicate, SetDest.InnerLoopCounter, (number(tt.child(0)))));
+ cb.add(new Set(dock, predicate, SetDest.InnerLoopCounter, (number(tt.child(0)))));
continue;
} else if ("--".equals(tt.head())) {
- cb.add(new Set(dock, looping, predicate, SetDest.OuterLoopCounter, SetSource.Decrement));
+ cb.add(new Set(dock, predicate, SetDest.OuterLoopCounter, SetSource.Decrement));
continue;
} else if ("nop".equals(tt.head())) {
if (tt.size() > 0 && "[T]".equals(tt.child(0).head())) interruptible = true;
- cb.add(new Move(dock, looping, predicate, interruptible, null, false, false, false, false, false, false));
+ cb.add(new Move(dock, predicate, interruptible, null, false, false, false, false, false, false));
} else if ("shift".equals(tt.head())) {
- cb.add(new Shift(dock, looping, predicate,
+ cb.add(new Shift(dock, predicate,
new BitVector(dock.getShip().getFleet().getShiftWidth()).set(number(tt.child(0)))));
continue;
} else if ("flush".equals(tt.head())) {
- cb.add(new Flush(dock, looping, predicate));
+ cb.add(new Flush(dock, predicate));
continue;
} else if ("abort".equals(tt.head())) {
cb.add(new Abort(dock, predicate));
CodeBag cb2 = getCodeBag("anon"+(anoncount++));
for(Tree<String> statement : tq.child(0))
fillCodeBag(statement, cb2);
- cb.add(new Set(dock, looping, predicate, SetDest.DataLatch, (cb2.getFakeAddress())), true);
+ cb.add(new Set(dock, predicate, SetDest.DataLatch, (cb2.getFakeAddress())), true);
continue OUTER;
} else if (tt.child(0).head().equals("Name")) {
String refname = name(tt.child(0));
CodeBag cb2 = getCodeBag(refname);
- cb.add(new Set(dock, looping, predicate, SetDest.DataLatch, (cb2.getFakeAddress())), true);
+ cb.add(new Set(dock, predicate, SetDest.DataLatch, (cb2.getFakeAddress())), true);
continue OUTER;
} else if (tt.child(0).head().equals("[")) {
literal = parseSSL(tt.child(0));
if (((FleetTwoFleet)fleet).isSmallEnoughToFit(literal)) {
- cb.add(new Set(dock, looping, predicate, SetDest.DataLatch, (literal)));
+ cb.add(new Set(dock, predicate, SetDest.DataLatch, (literal)));
} else {
int counter = 0;
while(counter < dock.getShip().getFleet().getWordWidth()) counter += fleet.getShiftWidth();
while(counter > 0) {
- cb.add(new Shift(dock, looping, predicate,
+ cb.add(new Shift(dock, predicate,
new BitVector(dock.getShip().getFleet().getShiftWidth())
.set(getField(counter-1, counter-fleet.getShiftWidth(), literal))));
counter -= fleet.getShiftWidth();
else if ("send token".equals(ttt.head())) { tokenOut = true; }
else if ("send token to".equals(ttt.head())) { tokenOut = true; path = path(dock, ttt.child(0)); }
}
- cb.add(new Move(dock, looping, predicate,
+ cb.add(new Move(dock, predicate,
interruptible, path, tokenIn, dataIn,
latch, dispatch, dataOut, tokenOut));
}
public Ship createShip(String shiptype, String shipname);
}
- private static Move discard(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, false, true, false, false, false, false); }
- private static Move deliver(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, false, false, false, false, true, false); }
- private static Move wait(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, true, false, false, false, false, false); }
- private static Move sendto(Dock dock, Path path) { return new Move(dock, false, IgnoreFlagD, false, path, false, false, false, false, true, false); }
+ private static Move discard(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, false, true, false, false, false, false); }
+ private static Move deliver(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, false, false, false, false, true, false); }
+ private static Move wait(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, true, false, false, false, false, false); }
+ private static Move sendto(Dock dock, Path path) { return new Move(dock, IgnoreFlagD, false, path, false, false, false, false, true, false); }
}
| ^"[!a]" ws | ^"[!b]" ws
| ^"[d]" ws
| ^"[*]" ws
- | ^"[Rq]" ws
InstructionX = (() | ^"[T]" ws) ^"nop" ";" /ws
| (() | ^"[T]" ws) (Commands:: Command +/ (ws "," ws)) ^";" /ws
| "olc=word":: "set" "olc" "=" "word" ";" /ws
new BitVector(fpga.getWordWidth()).set(fpga.writeInstruction(inst, dispatchFrom)));
}
- private static Move discard(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, false, true, false, false, false, false); }
- private static Move deliver(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, false, false, false, false, true, false); }
- private static Move wait(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, true, false, false, false, false, false); }
- private static Move sendto(Dock dock, Path path) { return new Move(dock, false, IgnoreFlagD, false, path, false, false, false, false, true, false); }
+ private static Move discard(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, false, true, false, false, false, false); }
+ private static Move deliver(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, false, false, false, false, true, false); }
+ private static Move wait(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, true, false, false, false, false, false); }
+ private static Move sendto(Dock dock, Path path) { return new Move(dock, IgnoreFlagD, false, path, false, false, false, false, true, false); }
}
throw new RuntimeException("abortLoopIfTorpedoPresent() must be followed immediately by a Move");
} else {
instructions.add(new Move(dock,
- count!=1,
predicate,
pending_interruptible,
pending_path==null ? null : pending_path,
public void interruptibleNop() {
flush_pending();
instructions.add(new Move(dock,
- count!=1,
predicate,
true,
null,
public void flush() {
if (!dock.isInputDock()) throw new RuntimeException("flush() may only be used at input docks");
flush_pending();
- instructions.add(new Instruction.Flush(dock, count!=1, predicate));
+ instructions.add(new Instruction.Flush(dock, predicate));
}
/** [outboxes only], will fuse with previous instruction if it was a sendToken() */
for(int i=counter-1; i>=counter-ctx.fleet.getShiftWidth(); i--)
if (i<literal.length())
temp.set(i-(counter-ctx.fleet.getShiftWidth()), literal.get(i));
- instructions.add(new Shift(dock, count!=1, predicate, temp));
+ instructions.add(new Shift(dock, predicate, temp));
counter -= ctx.fleet.getShiftWidth();
}
}
public void literal(long literal) {
flush_pending();
if (((FleetTwoFleet)ctx.fleet).isSmallEnoughToFit(literal)) {
- instructions.add(new Instruction.Set(dock, count!=1, predicate, SetDest.DataLatch, literal));
+ instructions.add(new Instruction.Set(dock, predicate, SetDest.DataLatch, literal));
} else {
int counter = 0;
int extra = 0;
while(counter < dock.getShip().getFleet().getWordWidth()) { extra++; counter += ctx.fleet.getShiftWidth(); }
warn("literal " + literal + " requires " + extra + " instructions");
while(counter > 0) {
- instructions.add(new Shift(dock, count!=1, predicate,
+ instructions.add(new Shift(dock, predicate,
new BitVector(dock.getShip().getFleet().getWordWidth())
.set(getField(counter-1, counter-ctx.fleet.getShiftWidth(), literal))));
counter -= ctx.fleet.getShiftWidth();
public void setFlags(Instruction.Set.FlagFunction newFlagA, Instruction.Set.FlagFunction newFlagB) {
flush_pending();
instructions.add(new Instruction.Set(dock,
- count!=1,
predicate,
newFlagA,
newFlagB));
public void abort() {
flush_pending();
instructions.add(new Instruction.Set(dock,
- count!=1,
predicate,
SetDest.OuterLoopCounter,
0));
boolean blockingInstructionEncountered = false;
// Set the OLC (it might previously have been zero)
- ic.add(new Set(dock, false, Predicate.IgnoreFlagD, SetDest.OuterLoopCounter, count==0 ? 1 : count));
+ ic.add(new Set(dock, Predicate.IgnoreFlagD, SetDest.OuterLoopCounter, count==0 ? 1 : count));
if (count!=1) {
ic.add(new Instruction.Head(dock));
}
throw new RuntimeException("instruction sequence is too long for instruction fifo at " + dock);
} else {
if (count != 0) {
- ic.add(new Instruction.Set(dock, true, Predicate.Default, SetDest.OuterLoopCounter, SetSource.Decrement));
+ ic.add(new Instruction.Set(dock, Predicate.Default, SetDest.OuterLoopCounter, SetSource.Decrement));
if (blockingInstructionEncountered)
numInstructionsNotIncludingNonblockingPrefix++;
loopSize++;
if (count!=1)
ic.add(new Instruction.Abort(dock, Predicate.FlagD));
if (ctx.autoflush && next==null && dock.isInputDock())
- ic.add(new Instruction.Flush(dock, true, Predicate.FlagD));
+ ic.add(new Instruction.Flush(dock, Predicate.FlagD));
// FIXME: need to somehow deal with count!=0 loops that are
// torpedoable; they need to wait for a torpedo to arrive
if (P_NOT_B.get(inst)) predicate = NotFlagB;
if (FLUSH.get(inst))
- return new Flush(dock, false, predicate);
+ return new Flush(dock, predicate);
if (ABORT.get(inst))
return new Abort(dock, predicate);
- if (SHIFT.get(inst)) return new Shift(dock, false, predicate, new BitVector(dock.getShip().getFleet().getShiftWidth()).set(SHIFT.getval(inst)));
+ if (SHIFT.get(inst)) return new Shift(dock, predicate, new BitVector(dock.getShip().getFleet().getShiftWidth()).set(SHIFT.getval(inst)));
if (SET_IMMEDIATE.get(inst)) {
boolean extend = SET_IMMEDIATE_EXTEND.getval(inst) != 0;
long immediate = SET_IMMEDIATE.getval(inst);
if (extend) immediate |= (-1L << DataLatch_WIDTH);
- return new Set(dock, false, predicate, SetDest.DataLatch, (immediate));
+ return new Set(dock, predicate, SetDest.DataLatch, (immediate));
}
if (SET_OLC_FROM_OLC_MINUS_ONE.get(inst))
- return new Set(dock, false, predicate, SetDest.OuterLoopCounter, SetSource.Decrement);
+ return new Set(dock, predicate, SetDest.OuterLoopCounter, SetSource.Decrement);
if (SET_OLC_FROM_IMMEDIATE.get(inst))
- return new Set(dock, false, predicate, SetDest.OuterLoopCounter, (SET_OLC_FROM_IMMEDIATE.getval(inst)));
+ return new Set(dock, predicate, SetDest.OuterLoopCounter, (SET_OLC_FROM_IMMEDIATE.getval(inst)));
if (SET_ILC_FROM_IMMEDIATE.get(inst))
- return new Set(dock, false, predicate, SetDest.InnerLoopCounter, (SET_ILC_FROM_IMMEDIATE.getval(inst)));
+ return new Set(dock, predicate, SetDest.InnerLoopCounter, (SET_ILC_FROM_IMMEDIATE.getval(inst)));
if (SET_OLC_FROM_DATA_LATCH.get(inst))
- return new Set(dock, false, predicate, SetDest.OuterLoopCounter, SetSource.DataLatch);
+ return new Set(dock, predicate, SetDest.OuterLoopCounter, SetSource.DataLatch);
if (SET_ILC_FROM_DATA_LATCH.get(inst))
- return new Set(dock, false, predicate, SetDest.InnerLoopCounter, SetSource.DataLatch);
+ return new Set(dock, predicate, SetDest.InnerLoopCounter, SetSource.DataLatch);
if (SET_ILC_FROM_INFINITY.get(inst))
- return new Set(dock, false, predicate, SetDest.InnerLoopCounter, SetSource.Infinity);
+ return new Set(dock, predicate, SetDest.InnerLoopCounter, SetSource.Infinity);
if (SET_FLAGS.get(inst)) {
long flag_a = SET_FLAGS_A.getval(inst);
long flag_b = SET_FLAGS_B.getval(inst);
if (SET_FLAGS_VALUE_NOT_B.get(flag_b)) bp = bp.add(NotFlagB );
if (SET_FLAGS_VALUE_C .get(flag_b)) bp = bp.add(FlagC );
if (SET_FLAGS_VALUE_NOT_C.get(flag_b)) bp = bp.add(NotFlagC );
- return new Set(dock, false, predicate, ap, bp);
+ return new Set(dock, predicate, ap, bp);
}
if (MOVE.get(inst))
return new Move(dock,
- false,
predicate,
!NOT_INTERRUPTIBLE.get(inst),
PATH_DATA.get(inst)?null:getPathByAddr(dock, PATH_IMMEDIATE.getvalAsBitVector(inst)),