import edu.berkeley.fleet.api.Instruction.Set;
import edu.berkeley.fleet.api.Instruction.Set.*;
import static edu.berkeley.fleet.util.BitManipulations.*;
-import static edu.berkeley.fleet.two.FleetTwoFleet.SHIFT;
+
+// QUESTION: does each dock mentioned by a context have a linear chain
+// of loops, or can it branch?
+
+// - or should we use "sub-contexts" for that
+// - advantage: it lets us convey the fact that a bunch of loops are dispatched together
+// - should loops have an "invoke context" opcode?
/**
* A Context is a collection of Loops which obey these rules:
private HashSet<LoopFactory> loopFactories = new HashSet<LoopFactory>();
- public Context() { }
+ public final Fleet fleet;
+ public Context(Fleet fleet) { this.fleet = fleet; }
/**
*
/** sets the data latch to a literal value */
public void literal(long literal) {
flush_pending();
- if (FleetTwoFleet.isSmallEnoughToFit(literal)) {
+ if (((FleetTwoFleet)fleet).isSmallEnoughToFit(literal)) {
instructions.add(new Instruction.Set(dock, count!=1, predicate, SetDest.DataLatch, literal));
} else {
int counter = 0;
- while(counter < dock.getShip().getFleet().getWordWidth()) counter += SHIFT.valmaskwidth;
- warn("literal " + literal + " requires " + counter + " instructions");
+ int extra = 0;
+ while(counter < dock.getShip().getFleet().getWordWidth()) { extra++; counter += fleet.getShiftWidth(); }
+ warn("literal " + literal + " requires " + extra + " instructions");
while(counter > 0) {
instructions.add(new Shift(dock, count!=1, predicate,
new BitVector(dock.getShip().getFleet().getWordWidth())
- .set(getField(counter-1, counter-SHIFT.valmaskwidth, literal))));
- counter -= SHIFT.valmaskwidth;
+ .set(getField(counter-1, counter-fleet.getShiftWidth(), literal))));
+ counter -= fleet.getShiftWidth();
}
}
}
public class New {
public final Fleet fleet;
- public New(Fleet fleet) { this.fleet = fleet; }
-
- private Context context = new Context();
+ private Context context;
+ public New(Fleet fleet) {
+ this.fleet = fleet;
+ this.context = new Context(fleet);
+ }
private HashSet<Segment> segments = new HashSet<Segment>();
private HashSet<Ship> allocated = new HashSet<Ship>();