import java.util.*;
import edu.berkeley.fleet.two.*;
import edu.berkeley.fleet.api.*;
+import edu.berkeley.sbp.util.ANSI;
/** anything that has a source (instruction horn) address on the switch fabric */
class InterpreterDock extends FleetTwoDock {
final BitVector dataLatch = new BitVector(getShip().getFleet().getWordWidth());
InterpreterPath pathLatch = null;
boolean requeueStageInCirculatingState = false;
- boolean requeueStageHasTailInstruction = false;
- boolean torpedoWaiting = false;
boolean flushing = false;
- Queue<Instruction> instructions = new LinkedList<Instruction>();
- Queue<Packet> dataPackets = new LinkedList<Packet>();
+ LinkedList<Instruction> instructions = new LinkedList<Instruction>();
+ LinkedList<Packet> dataPackets = new LinkedList<Packet>();
// HACK
- private Queue<Instruction> instructionsBackedUpIntoSwitchFabric = new LinkedList<Instruction>();
+ private LinkedList<Packet> instructionsBackedUpIntoSwitchFabric = new LinkedList<Packet>();
boolean dataReadyForShip = false;
boolean readyForDataFromShip = true;
+
+ // FIXME: should be a BitVector
long dataFromShip;
boolean flagCFromShip;
dataLatch.set(0);
pathLatch = null;
requeueStageInCirculatingState = false;
- requeueStageHasTailInstruction = false;
instructions.clear();
dataPackets.clear();
instructionsBackedUpIntoSwitchFabric.clear();
dataReadyForShip = false;
readyForDataFromShip = true;
- torpedoWaiting = false;
flushing = false;
}
/** includes the epilogue fifo */
public InterpreterDestination instructionDestination = new InterpreterDestination(this) {
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 */);
- addInstruction(inst);
- }
+ public void addDataFromFabric(Packet p) { addInstruction(p); }
};
public InterpreterDestination dataDestination = new InterpreterDestination(this) {
public String toString() { return getDock()+""; }
boolean trace = false;
- private void addInstruction(Instruction inst) {
- if (requeueStageInCirculatingState || requeueStageHasTailInstruction) {
- // GROSS HACK
- instructionsBackedUpIntoSwitchFabric.add(inst);
- return;
+ private void addInstruction(Packet p) {
+ if (p.isToken() ||
+ instructionsBackedUpIntoSwitchFabric.size()!=0 ||
+ requeueStageInCirculatingState ||
+ (p2i(p) instanceof Instruction.Tail)) {
+ instructionsBackedUpIntoSwitchFabric.add(p);
+ } else {
+ instructions.add(p2i(p));
}
- if (inst instanceof Instruction.Tail) {
- requeueStageHasTailInstruction = true;
- return;
- }
- instructions.add(inst);
}
+ private Instruction p2i(Packet p) {
+ if (p.isToken()) throw new RuntimeException();
+ return getInterpreter().decodeInstruction(p.getValue(), InterpreterDock.this /* this is wrong, but harmless */);
+ }
+
protected final void service() {
if (dataReadyForShip || flushing) return;
if (instructions.peek() instanceof Instruction.Head) {
if (requeueStageInCirculatingState) { instructions.remove(); return; }
- if (!requeueStageHasTailInstruction) return;
- requeueStageHasTailInstruction = false;
- requeueStageInCirculatingState = true;
- instructions.remove();
+ Packet p = instructionsBackedUpIntoSwitchFabric.peek();
+ if (p!=null && !p.isToken() && p2i(p) instanceof Instruction.Tail) {
+ instructionsBackedUpIntoSwitchFabric.remove();
+ requeueStageInCirculatingState = true;
+ instructions.remove();
+ }
return;
}
if (ilc==0) { ilc = 1; break; }
- if (move.interruptible && torpedoWaiting) {
- torpedoWaiting = false;
- ilc = 1;
- flag_d = true;
- break;
+ if (move.interruptible) {
+ Packet p = instructionsBackedUpIntoSwitchFabric.peek();
+ if (p!=null && p.isToken()) {
+ instructionsBackedUpIntoSwitchFabric.remove();
+ ilc = 1;
+ flag_d = true;
+ break;
+ }
}
if (move.dataIn && !isInputDock() && readyForDataFromShip) return;
} else if (instructions.peek() instanceof Instruction.Abort) {
requeueStageInCirculatingState = false;
- // HACK
- while (instructionsBackedUpIntoSwitchFabric.size()!=0) {
- Instruction i = instructionsBackedUpIntoSwitchFabric.remove();
- addInstruction(i);
- instructionsBackedUpIntoSwitchFabric.clear();
- }
+ LinkedList<Packet> temp = new LinkedList<Packet>();
+ while (instructionsBackedUpIntoSwitchFabric.size()!=0)
+ temp.add(instructionsBackedUpIntoSwitchFabric.remove());
+ while (temp.size()!=0)
+ addInstruction(temp.remove());
break;
} else if (instructions.peek() instanceof Instruction.Flush) {
case Immediate: olc = (int)set.immediate; break;
case DataLatch:
olc = 0;
- for(int i=0; i<((FleetTwoFleet)getShip().getFleet()).SET_OLC_FROM_IMMEDIATE.valmaskwidth-1; i++)
+ for(int i=0; i<getShip().getFleet().getWordWidth(); i++)
if (dataLatch.get(i))
olc |= (1 << i);
break;
dataFromShip = data;
flagCFromShip = pending_flag_c;
}
+
+
+ // Debugging //////////////////////////////////////////////////////////////////////////////
+
+ public void dumpState() {
+ if (instructions.size()==0 &&
+ dataPackets.size()==0 &&
+ instructionsBackedUpIntoSwitchFabric.size()==0 &&
+ !requeueStageInCirculatingState &&
+ !flushing &&
+ !dataReadyForShip &&
+ readyForDataFromShip)
+ return;
+ System.out.println("state of "+ANSI.green(this)+": "+
+ (ilc==1?"":("[ilc="+(ilc==-1 ? "*" : (ilc+""))+"] "))+
+ (olc==1?"":("[olc="+olc+"] "))+
+ (flag_a?"[a] ":"")+
+ (flag_b?"[b] ":"")+
+ (flag_c?"[c] ":"")+
+ (flag_d?"[d] ":"")+
+ (requeueStageInCirculatingState?"[recirculating] ":"")+
+ (flushing?"[flushing] ":"")
+ );
+ if (!readyForDataFromShip)
+ System.out.println(ANSI.cyan(" ship has proffered: " + dataFromShip));
+ if (dataReadyForShip)
+ System.out.println(ANSI.cyan(" waiting for ship to accept: " + dataLatch.toLong()));
+ for(Instruction i : instructions)
+ System.out.println(ANSI.red(" "+i));
+ for(Packet i : instructionsBackedUpIntoSwitchFabric)
+ System.out.println(ANSI.red(ANSI.bold(" "+i+" BACKED UP")));
+ for(Packet p : dataPackets)
+ System.out.println(ANSI.cyan(" "+p));
+ }
+
}