Queue<Instruction> instructions = new LinkedList<Instruction>();
Queue<Packet> dataPackets = new LinkedList<Packet>();
+
+ // HACK
+ private Queue<Instruction> instructionsBackedUpIntoSwitchFabric = new LinkedList<Instruction>();
+
boolean dataReadyForShip = false;
boolean readyForDataFromShip = true;
long dataFromShip;
requeueStageHasTailInstruction = false;
instructions.clear();
dataPackets.clear();
+ instructionsBackedUpIntoSwitchFabric.clear();
dataReadyForShip = false;
readyForDataFromShip = true;
torpedoWaiting = false;
public String toString() { return getDock()+":i"; }
public void addDataFromFabric(Packet p) {
if (p.isToken()) {
+ if (instructionsBackedUpIntoSwitchFabric.size()!=0)
+ throw new RuntimeException("torpedo arrived while instructions were backed up into switch fabric");
if (torpedoWaiting) throw new RuntimeException("two torpedoes collided!");
torpedoWaiting = true;
return;
Instruction inst =
getInterpreter().decodeInstruction(p.getValue(),
InterpreterDock.this /* this is wrong, but harmless */);
-
- // FIXME: this is a bit too conservative. In theory,
- // it's okay to dispatch new instructions to the dock
- // as long as we know that it will reach the updating
- // state without any further input from the outside
- // world -- ie that the instructions which remain to
- // be executed before the requeue stage transitions to
- // the updating state are all "non-blocking" (no moves
- // with Ti=1 or Di=1)
- if (requeueStageInCirculatingState || requeueStageHasTailInstruction)
- throw new RuntimeException("An instruction arrived while the requeue stage was circulating -- "+
- "this means that instructions have backed up into "+
- "the switch fabric, which nearly always risks deadlock! "+
- "Fix your program!"+
- "\n dock: " + InterpreterDock.this +
- "\n instruction: " + inst
- );
- if (inst instanceof Instruction.Tail) {
- requeueStageHasTailInstruction = true;
- return;
- }
- instructions.add(inst);
+ addInstruction(inst);
}
};
public InterpreterDestination dataDestination = new InterpreterDestination(this) {
public int getInstructionFifoSize() { return Integer.MAX_VALUE; }
public Interpreter getInterpreter() { return ((InterpreterShip)getShip()).getInterpreter(); }
+ boolean trace = false;
+
+ private void addInstruction(Instruction inst) {
+ if (requeueStageInCirculatingState || requeueStageHasTailInstruction) {
+ // GROSS HACK
+ instructionsBackedUpIntoSwitchFabric.add(inst);
+ return;
+ }
+ if (inst instanceof Instruction.Tail) {
+ requeueStageHasTailInstruction = true;
+ return;
+ }
+ instructions.add(inst);
+ }
+
protected final void service() {
if (dataReadyForShip || flushing) return;
} else {
bv = new BitVector(getInterpreter().getWordWidth()).set(dataFromShip);
readyForDataFromShip = true;
- flag_c = flagCFromShip;
+ if (move.latchData) flag_c = flagCFromShip;
}
if (move.latchData) dataLatch.set(bv);
if (move.latchPath) {
} else if (instructions.peek() instanceof Instruction.Abort) {
requeueStageInCirculatingState = false;
+ // HACK
+ while (instructionsBackedUpIntoSwitchFabric.size()!=0) {
+ Instruction i = instructionsBackedUpIntoSwitchFabric.remove();
+ addInstruction(i);
+ instructionsBackedUpIntoSwitchFabric.clear();
+ }
break;
} else if (instructions.peek() instanceof Instruction.Flush) {
protected long peekDataForShip() {
if (!dataReadyForShip)
throw new RuntimeException("peekDataForShip() invoked when dataReadyForShip()==false");
- BitVector bv = dataLatch;
- long val = 0;
- for(int i=0; i<bv.length(); i++)
- if (bv.get(i))
- val |= (1L << i);
- return val;
+ return dataLatch.toLong();
}
protected void addDataFromShip(long data) { addDataFromShip(data, false); }
protected void addDataFromShip(long data, boolean pending_flag_c) {