+++ /dev/null
-package edu.berkeley.fleet.ir;
-import edu.berkeley.fleet.loops.*;
-import java.util.concurrent.Semaphore;
-import java.util.*;
-import java.net.*;
-import edu.berkeley.fleet.two.*;
-import edu.berkeley.fleet.fpga.*;
-import edu.berkeley.fleet.api.*;
-import edu.berkeley.fleet.api.Instruction.*;
-import edu.berkeley.fleet.api.Instruction.Set;
-import edu.berkeley.fleet.api.Instruction.Set.*;
-import static edu.berkeley.fleet.util.BitManipulations.*;
-import edu.berkeley.fleet.api.Instruction.Set.FlagFunction;
-import edu.berkeley.fleet.api.Instruction.Set;
-import edu.berkeley.fleet.api.Instruction.Set.SetDest;
-import edu.berkeley.fleet.api.Instruction.Set.FlagFunction;
-import static edu.berkeley.fleet.api.Predicate.*;
-
-public class Counter {
-
-
- /**
- * Merge two sorted streams; it will issue tokens to provoke inputs
- */
- public static Dock merger(Context ctx,
- Ship alu,
- Destination in1_ack,
- int inflight_in1,
- Destination in2_ack,
- int inflight_in2,
- Destination d) {
-
- Dock out = alu.getDock("out");
- Dock inOp = alu.getDock("inOp");
- Dock in1 = alu.getDock("in1");
- Dock in2 = alu.getDock("in2");
-
- LoopFactory lf_in1 = new LoopFactory(ctx, in1, 1);
- LoopFactory lf_in2 = new LoopFactory(ctx, in2, 1);
- LoopFactory lf_inOp = new LoopFactory(ctx, inOp, 1);
-
- for(int i=0; i<inflight_in1; i++) lf_in1.sendToken(in1_ack);
- for(int i=0; i<inflight_in2; i++) lf_in2.sendToken(in2_ack);
-
- lf_inOp.literal(4); // MAX
-
- lf_in1 = lf_in1.makeNext(0);
- lf_in2 = lf_in2.makeNext(0);
- lf_inOp = lf_inOp.makeNext(0);
-
- lf_in1.recvWord();
- lf_in1.deliver();
- lf_in1.sendToken(in1_ack);
-
- lf_in2.recvWord();
- lf_in2.deliver();
- lf_in2.sendToken(in2_ack);
-
- lf_inOp.deliver();
-
- LoopFactory lf_out = new LoopFactory(ctx, out, 0);
- lf_out.recvToken();
- lf_out.collectWord();
- lf_out.sendWord(d);
-
- return out;
- }
-
-
- // FEATURE: optimize for short runs (use ILC counter, perhaps ILC+OLC combo)
- // FEATURE: stop-at-zero when counting downward
- /**
- * A downward counter; returns the output dock that produces
- * the values.
- *
- * For each token sent to the output dock, a value will be sent
- * to dest.
- */
- public static Dock counter(Context ctx,
- Ship alu,
- long start,
- long incr,
- int inflight,
- Destination dest,
- BitVector signal) {
-
- if (inflight < 1) throw new RuntimeException();
-
- boolean incr_is_positive = false;
- boolean compile_time_start = true;
- boolean compile_time_incr = true;
-
- Dock out = alu.getDock("out");
- Dock inOp = alu.getDock("inOp");
- Dock in1 = alu.getDock("in1");
- Dock in2 = alu.getDock("in2");
- LoopFactory lf;
-
- //
- // FIXME: make sure we cope properly with getting torpedoed
- // before inflight-many tokens have arrived
- //
-
- // FIXME: update Alu to "take-one" behavior, then fix stuff below
-
- LoopFactory lf_in1 = new LoopFactory(ctx, in1, 1);
- LoopFactory lf_in2 = new LoopFactory(ctx, in2, 1);
- LoopFactory lf_inOp = new LoopFactory(ctx, inOp, 1);
- LoopFactory lf_out = new LoopFactory(ctx, out, 1);
-
- // Phase 1 //////////////////////////////////////////////////////////////////////////////
-
- if (compile_time_incr) lf_in1.literal(incr); else lf_in1.recvWord();
- if (compile_time_start) lf_in2.literal(start); else lf_in2.recvWord();
- for(int i=0; i<inflight; i++) {
- lf_in1.deliver();
- lf_inOp.literal(0 /*IN1*/);
- lf_inOp.deliver();
- lf_out.collectWord();
- lf_out.sendWord(in1.getDataDestination());
-
- lf_in2.deliver();
- lf_inOp.literal(1 /*IN2*/);
- lf_inOp.deliver();
- lf_out.collectWord();
- lf_out.sendWord(in1.getDataDestination());
- }
-
- // Phase 2 //////////////////////////////////////////////////////////////////////////////
-
- // FIXME: tokens for flow control here
- lf_inOp.literal(incr_is_positive ? 3/*SUB*/ : 2/*ADD*/);
- lf_inOp = lf_inOp.makeNext(0);
- lf_inOp.deliver();
-
- lf_in2.literal(0);
- for(int i=0; i<inflight; i++) {
- lf_in1.recvWord();
- lf_in1.deliver();
- lf_in2.deliver();
- lf_out.collectWord();
- lf_out.sendWord(in2.getDataDestination());
-
- lf_in1.recvWord();
- lf_in1.deliver();
- lf_in2.deliver();
-
- lf_out.collectWord();
- lf_out.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf_out.setPredicate(Predicate.FlagA);
- lf_out.abort();
- lf_out.setPredicate(null);
- lf_out.sendWord(in1.getDataDestination());
- lf_out.recvToken();
- lf_out.sendWord(dest, signal);
-
- lf_in2.recvWord();
- }
-
- // Phase 3 //////////////////////////////////////////////////////////////////////////////
-
- lf_in1 = lf_in1.makeNext(0);
- lf_in1.recvWord();
- lf_in1.deliver();
-
- // FIXME: tokens for flow control here
- lf_in2 = lf_in2.makeNext(0);
- lf_in2.deliver();
-
- lf_out = lf_out.makeNext(0);
- lf_out.collectWord();
- lf_out.sendWord(in1.getDataDestination());
- lf_out.recvToken();
- lf_out.sendWord(dest, signal);
-
- // FIXME: ensure that if torpedoes arrive in phase1 or phase2 we deal with them properly
-
- return out;
- }
-
- /**
- * A memory read with two address inputs.
- *
- * Returns the address input dock of the memory ship. Assumes
- * that addresses will be sent to this dock from two distinct
- * sources (in0 and in1), distinguished by the signal bit.
- * Values read from memory will be routed to out0 or out1
- * depending on which input source the address came from.
- *
- * This widget does not send acknowledgement tokens; the
- * recipients at out0 and out1 should send their tokens to in0
- * and in1.
- */
- public static Dock memReadTwo(Context ctx,
- Ship mem,
- Destination out0,
- Destination out1) {
-
- Dock inAddrRead = mem.getDock("inAddrRead");
- Dock out = mem.getDock("out");
-
- LoopFactory lf_inAddrRead = new LoopFactory(ctx, inAddrRead, 0);
- LoopFactory lf_out = new LoopFactory(ctx, out, 0);
-
- lf_inAddrRead.recvWord();
- lf_inAddrRead.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf_inAddrRead.setPredicate(Predicate.FlagA);
- lf_inAddrRead.sendToken(out.getDataDestination(), new BitVector(1).set(1));
- lf_inAddrRead.setPredicate(Predicate.NotFlagA);
- lf_inAddrRead.sendToken(out.getDataDestination(), new BitVector(1).set(0));
- lf_inAddrRead.setPredicate(null);
- lf_inAddrRead.deliver();
-
- lf_out.recvToken();
- lf_out.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf_out.collectWord();
- lf_out.setPredicate(Predicate.FlagA);
- lf_out.sendWord(out1);
- lf_out.setPredicate(Predicate.NotFlagA);
- lf_out.sendWord(out0);
- lf_out.setPredicate(null);
-
- return inAddrRead;
- }
-
- public static void fillMemRandom(Fleet fleet, Ship memory, FleetProcess fp) {
- Random random = new Random(System.currentTimeMillis());
-
- int SIZE = 256;
-
- int[] ints = new int[SIZE/2];
- int[] intsbig = new int[SIZE];
- BitVector[] vals = new BitVector[SIZE];
- BitVector[] vals2 = new BitVector[SIZE];
-
- for(int j=0; j<2; j++) {
- for(int i=0; i<ints.length; i++) {
- ints[i] = Math.abs(random.nextInt());
- }
- ints[ints.length-1] = Integer.MAX_VALUE;
- Arrays.sort(ints);
- for(int i=0; i<ints.length; i++) {
- vals[i+j*ints.length] = new BitVector(fleet.getWordWidth()).set(ints[i]);
- intsbig[i+j*ints.length] = ints[i];
- }
- }
- Arrays.sort(intsbig);
-
- Gadgets.writeMem(fp, memory, 0, vals);
- }
-
- public static void main(String[] s) throws Exception {
- Random random = new Random(System.currentTimeMillis());
- Fleet fleet = new Fpga();
- FleetProcess fp = fleet.run(new Instruction[0]);
-
- int SIZE = 128;
-
- Ship memory = fleet.getShip("DRAM",0);
- int[] ints = new int[SIZE/2];
- int[] intsbig = new int[SIZE];
- BitVector[] vals = new BitVector[SIZE];
- BitVector[] vals2 = new BitVector[SIZE];
-
- for(int j=0; j<2; j++) {
- for(int i=0; i<ints.length; i++) {
- ints[i] = Math.abs(random.nextInt());
- }
- ints[ints.length-1] = Integer.MAX_VALUE;
- Arrays.sort(ints);
- for(int i=0; i<ints.length; i++) {
- vals[i+j*ints.length] = new BitVector(fleet.getWordWidth()).set(ints[i]);
- intsbig[i+j*ints.length] = ints[i];
- }
- }
- Arrays.sort(intsbig);
-
- Gadgets.writeMem(fp, memory, 0, vals);
- Gadgets.readMem(fp, memory, 0, vals2);
- for(int i=0; i<vals.length; i++)
- if (!vals[i].equals(vals2[i]))
- System.out.println("disagreement! on index " + i + "\n "+vals[i]+"\n "+vals2[i]);
- System.out.println("done reading and verifying!");
- System.out.println();
- System.out.println();
-
- Context ctx = new Context(fp.getFleet());
- Ship debug = fleet.getShip("Debug", 0);
-
- Ship merger_alu = ctx.allocateShip("Alu");
-
- Dock mem_in = memReadTwo(ctx, memory,
- merger_alu.getDock("in1").getDataDestination(),
- merger_alu.getDock("in2").getDataDestination());
-
- Dock counter_0_ack = counter(ctx, ctx.allocateShip("Alu"), SIZE/2-1, -1, 1, mem_in.getDataDestination(), new BitVector(1).set(0));
-
- Dock counter_1_ack = counter(ctx, ctx.allocateShip("Alu"), SIZE-1, -1, 1, mem_in.getDataDestination(), new BitVector(1).set(1));
-
- Dock d3 = merger(ctx, merger_alu,
- counter_0_ack.getDataDestination(), 1,
- counter_1_ack.getDataDestination(), 1,
- debug.getDock("in").getDataDestination());
-
-
- LoopFactory lf;
- lf = new LoopFactory(ctx, debug.getDock("in"), 0);
- lf.sendToken(d3.getDataDestination());
- lf.recvWord();
- lf.deliver();
-
- ArrayList<Instruction> ai = new ArrayList<Instruction>();
- ctx.emit(ai);
- for(Instruction ins : ai)
- fp.sendInstruction(ins);
- fp.flush();
-
- System.out.println("reading sorted words...");
- for(int i=intsbig.length-1; i>=0; i--) {
- BitVector bv = fp.recvWord();
- int x = (int)bv.toLong();
- if (x==intsbig[i]) System.out.println("agree " + x);
- else System.out.println("DISAGREE " + x + " " + intsbig[i]);
- }
- System.out.println("done.");
- }
-
-}
\ No newline at end of file
+++ /dev/null
-package edu.berkeley.fleet;
-import edu.berkeley.fleet.loops.*;
-
-// EXPERIMENTAL. Do not use.
-
-// interesting primitive: an "atomic"
-// take-from-fred-and-deliver-to-mary transition; you can give it
-// predecessors and successors.
-// -- hitch: this artificially causes fred's successor to wait until
-// mary has gotten the data item
-
-
-// Literal gets folded into anything involving a UsesData
-// Repeat-literal-count appears to the programmer just as repeat with a separate literal
-// FEATURE: apply tachio analysis to ensure kills never get stuck
-// FEATURE: ability to save the MSB flag for later use
-public class IR {
- /*
- public interface Nodes extends Iterable<Node> {
- }
-
- public class NodesImpl extends Nodes {
- public NodesImpl(Node[] ns) { } // FIXME
- public NodesImpl(Node n1, Node n2) { this(new Node[] { n1, n2 }); }
- public NodesImpl() { this(new Node[0]); }
- //public Iterator<Node> iterator() { return new SingletonIterator(this); }
- }
-
- public abstract class Node extends Nodes {
- public abstract Nodes preds();
- public abstract Nodes succs();
- public Iterator<Node> iterator() { return new SingletonIterator(this); }
- }
-
- public class Join extends Node {
- public Node succ;
- public Nodes preds;
- public Nodes preds() { return preds; }
- public Nodes succs() { return succ; }
- }
- public class Fork extends Node {
- public Node pred;
- public Nodes succs;
- public Nodes preds() { return pred; }
- public Nodes succs() { return succs; }
- }
-
- public abstract class Linear extends Node {
- public Node pred;
- public Node succ;
- public Nodes preds() { return pred; }
- public Nodes succs() { return succ; }
- }
-
- // Actual Instructions //////////////////////////////////////////////////////////////////////////////
-
- public class Repeat extends Linear {
- public Node bodyFirst;
- public Node bodyLast;
- public Nodes preds() { return new Nodes(pred, bodyLast); }
- public Nodes succs() { return new Nodes(succ, bodyFirst); }
- }
-
- public class RepeatCount extends Repeat implements UsesData {
- }
-
- // if nonnegative then...else...
- public class IfThenElse extends Linear implements UsesData {
- public Node thenFirst;
- public Node thenLast;
- public Node elseFirst;
- public Node elseLast;
- public Join impliedJoin;
- }
-
- public class Break extends Linear { }
-
- public class Deliver extends Linear implements UsesData { }
- public class Recv extends Linear implements UsesData { } // is marked killable if any torpedo "points at" it
- public class Collect extends Linear { }
- public class Send extends Linear {
- public Ship dest; // if null, then this is a "dispatch"
- public boolean token;
- public boolean torpedo;
- }
- */
-}
+++ /dev/null
-package edu.berkeley.fleet.ir;
-import edu.berkeley.fleet.loops.*;
-import java.util.*;
-import java.net.*;
-import edu.berkeley.fleet.two.*;
-import edu.berkeley.fleet.api.*;
-import edu.berkeley.fleet.fpga.*;
-import edu.berkeley.fleet.api.Instruction.*;
-import edu.berkeley.fleet.api.Instruction.Set;
-import edu.berkeley.fleet.api.Instruction.Set.*;
-import static edu.berkeley.fleet.api.Predicate.*;
-import static edu.berkeley.fleet.util.BitManipulations.*;
-
-public class Junk {
-
- /*
- public class RepeatModule extends Module {
- private final Ship alu;
- public final InPort count = new InPort("count") {
- public void recvToken(Context.LoopFactory lf) { lf.recvToken(); }
- public void sendWord(Context.LoopFactory lf) { lf.sendWord(alu.getDock("in1").getDataDestination(), new BitVector(1).set(0)); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("in1"), 0);
- lf.abortLoopIfTorpedoPresent();
- lf.recvWord();
- lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf.setPredicate(Predicate.FlagA);
- peer.sendToken(lf);
- lf.abortLoopIfTorpedoPresent();
- peer.recvWord(lf);
- lf.setPredicate(null);
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- // RECV_AFTER_TORPEDO == 1
- return lf;
- }
- };
- public final InPort val = new InPort("val") {
- public void recvToken(Context.LoopFactory lf) { lf.recvToken(); }
- public void sendWord(Context.LoopFactory lf) { lf.sendWord(alu.getDock("in2").getDataDestination(), new BitVector(1).set(0)); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("in2"), 1);
-
- peer.sendToken(lf);
- lf.literal(1);
- lf.deliver();
- lf.setFlags(FlagFunction.ONE, FlagFunction.ZERO);
-
- lf = lf.makeNext(0);
- lf.setPredicate(Predicate.FlagA);
- lf.abortLoopIfTorpedoPresent();
- peer.recvWord(lf);
- lf.setPredicate(null);
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- lf.literal(1);
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- lf.recvWord();
- lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf.setPredicate(Predicate.FlagA);
- peer.sendToken(lf);
- return lf;
- }
- };
- public final OutPort out = new OutPort("out") {
- public void sendToken(Context.LoopFactory lf) { lf.sendToken(alu.getDock("out").getDataDestination()); }
- public void recvWord(Context.LoopFactory lf) { lf.recvWord(); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("out"), 1);
- lf.sendToken(alu.getDock("in1").getDataDestination(), new BitVector(1).set(1));
-
- lf = lf.makeNext(0);
- lf.abortLoopIfTorpedoPresent();
- lf.collectWord();
- lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf.setPredicate(Predicate.FlagA);
- lf.sendToken(alu.getDock("in1").getDataDestination(), new BitVector(1).set(1));
- lf.setPredicate(null);
- lf.setPredicate(Predicate.NotFlagA);
- lf.sendWord(alu.getDock("in1").getDataDestination(), new BitVector(1).set(0));
- lf.setPredicate(null);
- lf.abortLoopIfTorpedoPresent();
- lf.collectWord();
- lf.setPredicate(Predicate.FlagA);
- lf.sendToken(alu.getDock("in2").getDataDestination(), new BitVector(1).set(1));
- lf.setPredicate(null);
- lf.setPredicate(Predicate.NotFlagA);
- lf.sendWord(alu.getDock("in2").getDataDestination(), new BitVector(1).set(0));
- peer.recvToken(lf);
- peer.sendWord(lf);
- lf.setPredicate(null);
- return lf;
- }
- };
- public RepeatModule() {
- this.alu = ctx.allocateShip("Alu");
- }
- public void build() {
- super.build();
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("inOp"), 0);
- lf.literal(3); // SUB
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- lf.literal(1); // IN2
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- }
- }
- */
-
- /*
- public class PunctuatorModule extends Module {
- private final Ship alu;
- private final long punctuator;
- private final boolean unpunctuate;
- public final InPort count = new InPort("count") {
- public void recvToken(Context.LoopFactory lf) { lf.recvToken(); }
- public void sendWord(Context.LoopFactory lf) { lf.sendWord(alu.getDock("in1").getDataDestination(), new BitVector(1).set(0)); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("in1"), 0);
- lf.recvWord();
- lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf.setPredicate(Predicate.FlagA);
- peer.sendToken(lf);
- //lf.abortLoopIfTorpedoPresent(); FIXME
- peer.recvWord(lf);
- lf.setPredicate(null);
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- return lf;
- }
- };
- public final InPort val = new InPort("val") {
- public void recvToken(Context.LoopFactory lf) { lf.recvToken(); }
- public void sendWord(Context.LoopFactory lf) { lf.sendWord(alu.getDock("in2").getDataDestination(), new BitVector(1).set(0)); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("in2"), 0);
- lf.literal(0);
- lf.deliver();
- lf.literal(1);
- lf.deliver();
- lf.abortLoopIfTorpedoPresent();
- lf.recvWord();
- lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf.setPredicate(Predicate.FlagA);
- peer.sendToken(lf);
- lf.abortLoopIfTorpedoPresent();
- peer.recvWord(lf);
- lf.setPredicate(null);
- lf.deliver();
- return lf;
- }
- };
- public final OutPort out = new OutPort("out") {
- public void sendToken(Context.LoopFactory lf) { lf.sendToken(alu.getDock("out").getDataDestination()); }
- public void recvWord(Context.LoopFactory lf) { lf.recvWord(); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("out"), 1);
- lf.sendToken(alu.getDock("in1").getDataDestination(), new BitVector(1).set(1));
-
- lf = lf.makeNext(0);
-
- lf.abortLoopIfTorpedoPresent();
- lf.collectWord();
- lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf.abortLoopIfTorpedoPresent();
- lf.collectWord();
-
- if (unpunctuate) {
- lf.setPredicate(Predicate.FlagA);
- lf.sendWord(alu.getDock("in1").getDataDestination(), new BitVector(1).set(1));
- lf.setPredicate(Predicate.NotFlagA);
- lf.sendWord(alu.getDock("in1").getDataDestination(), new BitVector(1).set(0));
- lf.setPredicate(null);
- lf.sendToken(alu.getDock("in2").getDataDestination(), new BitVector(1).set(1));
- } else {
- // if count==0, issue punctuation and tell in1 to get a new count
- lf.setPredicate(Predicate.FlagA);
- lf.literal(punctuator);
- lf.abortLoopIfTorpedoPresent();
- peer.recvToken(lf);
- peer.sendWord(lf);
- lf.sendToken(alu.getDock("in1").getDataDestination(), new BitVector(1).set(1));
- lf.sendToken(alu.getDock("in2").getDataDestination(), new BitVector(1).set(0));
- lf.setPredicate(null);
-
- // if count!=0, cycle around the decremented count and pass a value through
- lf.setPredicate(Predicate.NotFlagA);
- lf.sendWord(alu.getDock("in1").getDataDestination(), new BitVector(1).set(0));
- lf.sendToken(alu.getDock("in2").getDataDestination(), new BitVector(1).set(1));
- lf.setPredicate(null);
- }
-
- lf.abortLoopIfTorpedoPresent();
- lf.collectWord();
-
- if (unpunctuate) {
- lf.setPredicate(Predicate.NotFlagA);
- lf.abortLoopIfTorpedoPresent();
- peer.recvToken(lf);
- peer.sendWord(lf);
- lf.setPredicate(null);
- } else {
- lf.setPredicate(Predicate.NotFlagA);
- lf.abortLoopIfTorpedoPresent();
- peer.recvToken(lf);
- peer.sendWord(lf);
- lf.setPredicate(null);
- }
-
- return lf;
- }
- };
- public PunctuatorModule(long punctuator, boolean unpunctuate) {
- this.alu = ctx.allocateShip("Alu");
- this.punctuator = punctuator;
- this.unpunctuate = unpunctuate;
- }
- public void build() {
- super.build();
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("inOp"), 0);
- lf.literal(6); // CMP
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- lf.literal(3); // SUB
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- lf.literal(1); // IN2
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- }
- }
-*/
- /*
- public class DownCounterModule extends Module {
- private final int internal_inflight;
- private final boolean incr_is_already_negative;
- private final Ship alu;
- public final InPort start = new InPort("start") {
- public void recvToken(Context.LoopFactory lf) { lf.recvToken(); }
- public void sendWord(Context.LoopFactory lf) { lf.sendWord(alu.getDock("in1").getDataDestination(), new BitVector(1).set(0)); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("in1"), 0);
- lf.recvWord();
- lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf.setPredicate(Predicate.FlagA);
- peer.sendToken(lf);
- lf.abortLoopIfTorpedoPresent();
- peer.recvWord(lf);
- lf.setPredicate(null);
- lf.deliver();
- return lf;
- }
- };
- public final InPort incr = new InPort("incr") {
- public void recvToken(Context.LoopFactory lf) { lf.recvToken(); }
- public void sendWord(Context.LoopFactory lf) { lf.sendWord(alu.getDock("in2").getDataDestination(), new BitVector(1).set(0)); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("in2"), 0);
- lf.recvToken();
- lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf.setPredicate(Predicate.FlagA);
- peer.sendToken(lf);
- lf.abortLoopIfTorpedoPresent();
- peer.recvWord(lf);
- lf.deliver();
- lf.setPredicate(Predicate.NotFlagA);
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- return lf;
- }
- };
- public final OutPort out = new OutPort("out") {
- public void sendToken(Context.LoopFactory lf) { lf.sendToken(alu.getDock("out").getDataDestination()); }
- public void recvWord(Context.LoopFactory lf) { lf.recvWord(); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("out"), 1);
- lf.setFlags(FlagFunction.ONE, FlagFunction.ZERO);
-
- lf = lf.makeNext(0);
- lf.setPredicate(Predicate.FlagA);
- lf.sendToken(alu.getDock("in1").getDataDestination(), new BitVector(1).set(1));
- lf.sendToken(alu.getDock("in2").getDataDestination(), new BitVector(1).set(1));
- lf.setPredicate(Predicate.NotFlagA);
- lf.sendWord(alu.getDock("in1").getDataDestination(), new BitVector(1).set(0));
- lf.sendToken(alu.getDock("in2").getDataDestination(), new BitVector(1).set(0));
- lf.setPredicate(null);
- lf.abortLoopIfTorpedoPresent();
- lf.collectWord();
- lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf.setPredicate(Predicate.NotFlagA);
- lf.abortLoopIfTorpedoPresent();
- peer.recvToken(lf);
- peer.sendWord(lf);
- lf.setPredicate(null);
- return lf;
- }
- };
- public DownCounterModule(boolean incr_is_already_negative, int internal_inflight) {
- this.alu = ctx.allocateShip("Alu");
- this.incr_is_already_negative = incr_is_already_negative;
- this.internal_inflight = internal_inflight;
- if (internal_inflight != 0) throw new RuntimeException("not yet supported");
- }
- public void build() {
- super.build();
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("inOp"), 1);
- // Phase 2 (FIXME: tokens for flow control here)
- lf.literal(incr_is_already_negative
- ? 2 // ADD
- : 3 // SUB
- );
- lf = lf.makeNext(0);
- lf.abortLoopIfTorpedoPresent();
- lf.deliver();
- }
- }
- */
- /**
- * A "vector register" which is initialized holding zero or more
- * elements and which will expect to receive count-many elements
- * before going idle
- */
- /*
-DOES NOT HANDLE TORPEDOES
- public class VectorRegisterModule extends Module {
- public final InPort in;
- public final OutPort out;
- public final int count;
- private final Ship ship;
- public VectorRegisterModule(final long[] initialValues, final int count) {
- this(longsToBitVectors(initialValues), count);
- }
- public VectorRegisterModule(final BitVector[] initialValues, final int count) {
- this.count = count;
- ship = ctx.allocateShip("Fifo");
- in = new PlainInPort("in", ship.getDock("in"), count) {
- public Context.LoopFactory build(Context.LoopFactory lf) {
- lf.disableInstructionFifoOverflowCheck();
- for(int i=0; i<initialValues.length; i++) {
- lf.literal(initialValues[i]);
- lf.deliver();
- }
- return super.build(lf.makeNext(1));
- }
- };
- out = new PlainOutPort("out", ship.getDock("out"), initialValues.length);
- }
- }
- */
-
-/*
- public class DownCounterModule extends Module {
- private final int internal_inflight;
- private final boolean incr_is_already_negative;
- private final Ship alu;
- public final InPort incr = new InPort("incr") {
- public void recvToken(Context.LoopFactory lf) { lf.recvToken(); }
- public void sendWord(Context.LoopFactory lf) { lf.sendWord(alu.getDock("in1").getDataDestination()); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("in1"), 1);
-
- // Phase 1
- peer.sendToken(lf);
- peer.recvWord(lf);
- for(int i=0; i<internal_inflight; i++) lf.deliver();
-
- // Phase 2
- for(int i=0; i<internal_inflight*2; i++) {
- lf.recvWord();
- lf.deliver();
- }
-
- // Phase 3 (FIXME: tokens for flow control here)
- lf = lf.makeNext(0);
- lf.recvWord();
- lf.deliver();
-
- return lf;
- }
- };
- public final InPort start = new InPort("start") {
- public void recvToken(Context.LoopFactory lf) { lf.recvToken(); }
- public void sendWord(Context.LoopFactory lf) { lf.sendWord(alu.getDock("in2").getDataDestination()); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("in2"), 1);
-
- // Phase 1
- peer.sendToken(lf);
- peer.recvWord(lf);
- for(int i=0; i<internal_inflight; i++) lf.deliver();
-
- // Phase 2
- lf.literal(0);
- for(int i=0; i<internal_inflight; i++) {
- lf.deliver();
- lf.deliver();
- lf.recvWord();
- }
-
- // Phase 3 (FIXME: tokens for flow control here)
- lf = lf.makeNext(0);
- lf.deliver();
-
- return lf;
- }
- };
- public final OutPort out = new OutPort("out") {
- public void sendToken(Context.LoopFactory lf) { lf.sendToken(alu.getDock("out").getDataDestination()); }
- public void recvWord(Context.LoopFactory lf) { lf.recvWord(); }
- public Context.LoopFactory build() {
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("out"), 1);
-
- // Phase 1
- for(int i=0; i<internal_inflight*2; i++) {
- lf.collectWord();
- lf.sendWord(alu.getDock("in1").getDataDestination());
- }
-
- // Phase 2
- for(int i=0; i<internal_inflight; i++) {
- lf.collectWord();
- lf.sendWord(alu.getDock("in2").getDataDestination());
-
- lf.collectWord();
-
- //lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- //lf.setPredicate(Predicate.FlagA);
- //lf.abort();
- //lf.setPredicate(null);
-
- lf.sendWord(alu.getDock("in1").getDataDestination());
- peer.recvToken(lf);
- peer.sendWord(lf);
- }
-
- // Phase 3
- lf = lf.makeNext(0);
-
- lf.collectWord();
- lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf.setPredicate(Predicate.FlagA);
- lf.abort();
- lf.setPredicate(null);
- lf.sendWord(alu.getDock("in1").getDataDestination());
- peer.recvToken(lf);
- peer.sendWord(lf);
-
- return lf;
- }
- };
- public DownCounterModule(boolean incr_is_already_negative, int internal_inflight) {
- this.alu = ctx.allocateShip("Alu");
- this.incr_is_already_negative = incr_is_already_negative;
- this.internal_inflight = internal_inflight;
- if (!incr_is_already_negative) throw new RuntimeException("this is broken right now");
- }
- public void build() {
- super.build();
-
- Context.LoopFactory lf = ctx.new LoopFactory(alu.getDock("inOp"), 1);
-
- // Phase 1
- for(int i=0; i<internal_inflight; i++) {
- lf.literal(0); // IN1
- lf.deliver();
- lf.literal(1); // IN2
- lf.deliver();
- }
-
- // Phase 2 (FIXME: tokens for flow control here)
- lf.literal(incr_is_already_negative
- ? 2 // ADD
- : 3 // SUB
- );
- lf = lf.makeNext(0);
- lf.deliver();
- }
- }
- */
-
- /*
- VectorRegisterModule cm1 = proc.new VectorRegisterModule(new long[] { 12, 14, 18, 15 }, 0);
- VectorRegisterModule cm2 = proc.new VectorRegisterModule(new long[] { 13, 17, 1, 3 }, 0);
- VectorRegisterModule cm3 = proc.new VectorRegisterModule(new long[] { 2, 2, 2, 2 }, 0);
-
- AluModule alu = proc.new AluModule();
-
- ForeverModule fmm = proc.new ForeverModule(2);
- fmm.in.connect(cm2.out);
- fmm.out.connect(alu.in2);
- fmm.out_const.connect(alu.inOp);
- alu.in1.connect(cm1.out);
- alu.out.connect(dm.in);
- */
-
- /*
- VectorRegisterModule cm1 = proc.new VectorRegisterModule(new long[] { 43, 10, 5, 5, 5 }, 0);
- VectorRegisterModule cm2 = proc.new VectorRegisterModule(new long[] { 2, 1, 1, 2, 3 }, 0);
- DownCounterModule dcm = proc.new DownCounterModule(false, 0);
- dcm.start.connect(cm1.out);
- dcm.incr.connect(cm2.out);
- dcm.out.connect(dm.in);
- */
-
- /*
- VectorRegisterModule cm1 = proc.new VectorRegisterModule(new long[] { 43, 10, 5, 8, 5 }, 0);
- VectorRegisterModule cm2 = proc.new VectorRegisterModule(new long[] { 7, 1, 1, 2, 3 }, 0);
- RepeatModule rm = proc.new RepeatModule();
- rm.val.connect(cm1.out);
- rm.count.connect(cm2.out);
- rm.out.connect(dm.in);
- */
-
-}
-
+++ /dev/null
-package edu.berkeley.fleet.ir;
-import edu.berkeley.fleet.loops.*;
-import edu.berkeley.fleet.api.*;
-import edu.berkeley.fleet.api.Instruction.*;
-import edu.berkeley.fleet.fpga.*;
-import edu.berkeley.fleet.interpreter.*;
-import edu.berkeley.fleet.api.Instruction.Set.FlagFunction;
-import edu.berkeley.fleet.api.Instruction.Set;
-import edu.berkeley.fleet.api.Instruction.Set.SetDest;
-import edu.berkeley.fleet.api.Instruction.Set.FlagFunction;
-import static edu.berkeley.fleet.api.Predicate.*;
-import java.io.*;
-import java.util.*;
-import java.net.*;
-
-public class New {
-
- public final Fleet fleet;
- 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>();
-
- private HashMap<Dock,LoopFactory> loops = new HashMap<Dock,LoopFactory>();
- private HashSet<LoopFactory> emitLoops = new HashSet<LoopFactory>();
-
- public LoopFactory getLoopFactory(Dock d) { return getLoopFactory(d, 0); }
- public LoopFactory getNextLoopFactory(Dock d, int count) {
- LoopFactory lf = loops.get(d);
- if (lf!=null) loops.put(d, lf = lf.makeNext(count, d+""));
- return getLoopFactory(d, count);
- }
- public LoopFactory getLoopFactory(Dock d, int count) {
- LoopFactory lf = loops.get(d);
- if (lf==null) {
- loops.put(d, lf = new LoopFactory(context, d, count, d+""));
- emitLoops.add(lf);
- }
- if (lf.count != count) throw new RuntimeException();
- return lf;
- }
-
- Ship allocate(String shipType) {
- for(Ship ship : fleet)
- if (shipType.equals(ship.getType()) && !allocated.contains(ship)) {
- allocated.add(ship);
- return ship;
- }
- throw new RuntimeException("no more ships of type " + shipType);
- }
-
- public void emit(ArrayList<Instruction> al) {
- for(Segment s : segments) s.emitPrologue(al);
- for(Segment s : segments) s.emitInstructions(al);
- for(LoopFactory lf : emitLoops) lf.emit(al);
- }
-
- public abstract class Segment {
-
- public final int inputWidth;
- public final int outputWidth;
- protected Dock[] inputs;
-
- public Segment(int inputWidth, int outputWidth) {
- this.inputWidth = inputWidth;
- this.outputWidth = outputWidth;
- segments.add(this);
- }
-
- /** sets input docks, returns output docks */
- public final Dock[] setInputs(Dock[] inputs) {
- if (inputs.length != inputWidth) throw new RuntimeException();
- this.inputs = inputs;
- Dock[] ret = _setInputs();
- if (ret.length != outputWidth) throw new RuntimeException();
- return ret;
- }
-
- public abstract Dock[] _setInputs();
- public void emitPrologue(ArrayList<Instruction> il) { }
- public abstract void emitInstructions(ArrayList<Instruction> il);
- }
-
- public class Debug extends Segment {
- Ship debugShip;
- public Debug() {
- super(1, 0);
- debugShip = allocate("Debug");
- }
- public Dock[] _setInputs() { return new Dock[0]; }
- public void emitPrologue(ArrayList<Instruction> il) { }
- public void emitInstructions(ArrayList<Instruction> il) {
- LoopFactory lf;
- lf = new LoopFactory(context, debugShip.getDock("in"), 0, "debug.in");
- lf.recvWord();
- lf.deliver();
- }
- }
-
- public class Constant extends Segment {
- Ship fifoShip = null;
- public final long constant;
- public Constant(long constant) {
- super(0, 1);
- this.constant = constant;
- }
- public Dock[] _setInputs() {
- if (fifoShip == null) fifoShip = allocate("Fifo");
- return new Dock[] { fifoShip.getDock("out") };
- }
- public void emitPrologue(ArrayList<Instruction> il) {
- LoopFactory lf;
- lf = getLoopFactory(fifoShip.getDock("out"), 0);
- lf.collectWord();
- }
- public void emitInstructions(ArrayList<Instruction> il) {
- LoopFactory lf;
- lf = getLoopFactory(fifoShip.getDock("in"), 1);
- lf.literal(constant);
- lf = getNextLoopFactory(fifoShip.getDock("in"), 0);
- lf.deliver();
- }
- }
-
- public class Alu extends Segment {
- Ship alu = null;
- public final int opcode;
- public Alu(int opcode) {
- super((opcode==-1) ? 3 : 2, 1);
- this.opcode = opcode;
- }
- public Dock[] _setInputs() {
- if (alu == null) alu = allocate("Alu");
- return new Dock[] { alu.getDock("out") };
- }
- public void emitPrologue(ArrayList<Instruction> il) {
- LoopFactory lf;
- lf = getLoopFactory(alu.getDock("out"), 0);
- lf.collectWord();
- }
- public void emitInstructions(ArrayList<Instruction> il) {
- Dock inOp = alu.getDock("inOp");
-
- if (opcode==-1) {
- recvSendTokenDeliver(alu.getDock("inOp"), inputs[2].getDataDestination());
- LoopFactory lf;
- lf = getLoopFactory(inputs[2], 0);
- lf.sendWord(alu.getDock("inOp").getDataDestination());
- lf.recvToken();
- } else {
- LoopFactory lf;
- lf = getLoopFactory(alu.getDock("inOp"), 1);
- lf.literal(opcode);
- lf = getNextLoopFactory(alu.getDock("inOp"), 0);
- lf.deliver();
- }
-
- recvSendTokenDeliver(alu.getDock("in1"), inputs[0].getDataDestination());
- LoopFactory lf;
- lf = getLoopFactory(inputs[0], 0);
- lf.sendWord(alu.getDock("in1").getDataDestination());
- lf.recvToken();
-
- recvSendTokenDeliver(alu.getDock("in2"), inputs[1].getDataDestination());
- lf = getLoopFactory(inputs[1], 0);
- lf.sendWord(alu.getDock("in2").getDataDestination());
- lf.recvToken();
- }
- }
-
- public class Counter extends Segment {
- Ship alu = null;
- public final long start;
- public final long incr;
- public Counter(long start, long incr) {
- super(0, 1);
- this.start = start;
- this.incr = incr;
- }
- public Dock[] _setInputs() {
- if (alu == null) alu = allocate("Alu");
- return new Dock[] { alu.getDock("out") };
- }
- public void emitPrologue(ArrayList<Instruction> il) {
- LoopFactory lf;
- lf = getLoopFactory(alu.getDock("out"), 1);
- lf.literal(start);
- getNextLoopFactory(alu.getDock("out"), 0);
- }
- public void emitInstructions(ArrayList<Instruction> il) {
- LoopFactory lf;
- lf = getLoopFactory(alu.getDock("inOp"), 1);
- lf.literal(2);
- lf = getNextLoopFactory(alu.getDock("inOp"), 0);
- lf.deliver();
-
- lf = getLoopFactory(alu.getDock("in1"), 0);
- lf.recvWord();
- lf.deliver();
-
- lf = getLoopFactory(alu.getDock("in2"), 1);
- lf.literal(incr);
- lf = getNextLoopFactory(alu.getDock("in2"), 0);
- lf.deliver();
-
- lf = getLoopFactory(alu.getDock("out"), 0);
- lf.sendWord(alu.getDock("in1").getDataDestination());
- lf.collectWord();
- }
- }
-
- public class Between extends Segment {
- Ship alu = null;
- public final long min;
- public final long max;
- public Between(long min, long max) {
- super(1, 1);
- this.min = min;
- this.max = max;
- }
- public Dock[] _setInputs() {
- if (alu == null) alu = allocate("Alu");
- return new Dock[] { alu.getDock("out") };
- }
- public void emitPrologue(ArrayList<Instruction> il) {
- getLoopFactory(alu.getDock("in1"), 0);
- getLoopFactory(alu.getDock("in2"), 0);
-
- LoopFactory lf;
- lf = getLoopFactory(alu.getDock("out"), 0);
- lf.collectWord();
- lf.setFlags(FlagFunction.ZERO.add(FlagC), FlagFunction.ZERO);
- lf.collectWord();
- lf.setFlags(FlagFunction.ZERO.add(FlagC).add(FlagA), FlagFunction.ZERO);
- lf.setPredicate(Predicate.NotFlagA);
- lf.literal(1);
- lf.setPredicate(Predicate.FlagA);
- lf.literal(0);
- lf.setPredicate(null);
- }
-
- public void emitInstructions(ArrayList<Instruction> il) {
- LoopFactory lf;
- lf = getLoopFactory(alu.getDock("inOp"), 1);
- lf.literal(4); // MAX
- lf = getNextLoopFactory(alu.getDock("inOp"), 0);
- lf.deliver();
-
- lf = getLoopFactory(alu.getDock("in1"), 0);
- lf.recvWord();
- lf.sendToken(inputs[0].getDataDestination());
- lf.deliver();
- lf.literal(max);
- lf.deliver();
-
- lf = getLoopFactory(alu.getDock("in2"), 0);
- lf.literal(min);
- lf.deliver();
- lf.recvWord();
- lf.sendToken(inputs[0].getDataDestination());
- lf.deliver();
-
- lf = getLoopFactory(inputs[0], 0);
- lf.sendWord(alu.getDock("in2").getDataDestination());
- lf.sendWord(alu.getDock("in1").getDataDestination());
- lf.recvToken();
- lf.recvToken();
- }
- }
-
- public class FifoWithInit extends Segment {
- Ship fifoShip = null;
- public final long init;
- public FifoWithInit(long init) {
- super(1, 1);
- this.init = init;
- }
- public Dock[] _setInputs() {
- if (fifoShip == null) fifoShip = allocate("Fifo");
- return new Dock[] { fifoShip.getDock("out") };
- }
- public void emitPrologue(ArrayList<Instruction> il) {
- LoopFactory lf;
- lf = getLoopFactory(fifoShip.getDock("in"), 1);
- lf.literal(init);
- lf.deliver();
- lf = getNextLoopFactory(fifoShip.getDock("in"), 0);
-
- lf = getLoopFactory(fifoShip.getDock("out"), 0);
- lf.collectWord();
- }
- public void emitInstructions(ArrayList<Instruction> il) {
- LoopFactory lf;
- lf = getLoopFactory(inputs[0], 0);
- lf.sendWord(fifoShip.getDock("in").getDataDestination());
- lf.recvToken();
-
- recvSendTokenDeliver(fifoShip.getDock("in"), inputs[0].getDataDestination());
- }
- }
-
- public class Video extends Segment {
- Ship videoShip = null;
- public Video() {
- super(3, 0);
- }
- public Dock[] _setInputs() {
- if (videoShip == null) videoShip = allocate("Video");
- return new Dock[0];
- }
- public void emitPrologue(ArrayList<Instruction> il) { }
- public void emitInstructions(ArrayList<Instruction> il) {
- recvSendTokenDeliver(videoShip.getDock("inX"), inputs[0].getDataDestination());
- recvSendTokenDeliver(videoShip.getDock("inY"), inputs[1].getDataDestination());
- recvSendTokenDeliver(videoShip.getDock("inData"), inputs[2].getDataDestination());
-
- LoopFactory lf;
- lf = getLoopFactory(inputs[0]);
- lf.sendWord(videoShip.getDock("inX").getDataDestination());
- lf.recvToken();
-
- lf = getLoopFactory(inputs[1]);
- lf.sendWord(videoShip.getDock("inY").getDataDestination());
- lf.recvToken();
-
- lf = getLoopFactory(inputs[2]);
- lf.sendWord(videoShip.getDock("inData").getDataDestination());
- lf.recvToken();
- }
- }
-
- public static Dock bouncer(New n, int delt, int start, int min, int max) throws Exception {
- Constant zeroes = n.new Constant(0);
- FifoWithInit pos = n.new FifoWithInit(start);
- FifoWithInit delta = n.new FifoWithInit(delt);
-
- Dock pos_i = pos._setInputs()[0];
- Dock delta_i = delta._setInputs()[0];
-
- Alu negator = n.new Alu(3);
- Dock zero_minus_delta_i = negator.setInputs(new Dock[] { zeroes.setInputs(new Dock[0])[0], delta_i })[0];
-
- Between bet = n.new Between(min, max);
- Dock selector_input = bet.setInputs(new Dock[] { pos_i })[0];
-
- Alu selector = n.new Alu(-1);
- Dock selected = selector.setInputs(new Dock[] { zero_minus_delta_i, delta_i, selector_input })[0];
-
- Alu sum_alu = n.new Alu(2);
- Dock sum = sum_alu.setInputs(new Dock[] { selected, pos_i })[0];
-
- Dock pos_out = pos.setInputs(new Dock[] { sum })[0];
- Dock delta_out = delta.setInputs(new Dock[] { selected })[0];
- return pos_out;
- }
-
- public static void main(String[] s) throws Exception {
- New n = s[0].equals("fpga")
- ? new New(new Fpga())
- : new New(new Interpreter(new String[] {
- "Debug",
- "Fifo", "Fifo",
- "Fifo", "Fifo",
- "Fifo", "Fifo",
- "Fifo", "Fifo",
- "Fifo", "Fifo",
- "Fifo", "Fifo",
- "Alu", "Alu",
- "Alu", "Alu",
- "Alu", "Alu",
- "Alu", "Alu",
- "Alu", "Alu",
- "Alu", "Alu",
- "Video"
- }, false));
-
- Dock x_pos = bouncer(n, 1, 6, 5, 634);
- Dock y_pos = bouncer(n, 1, 6, 5, 474);
- Dock color = n.new Constant(2).setInputs(new Dock[0])[0];
- //Dock color = n.new Counter(0,1).setInputs(new Dock[0])[0];
-
- //debug.setInputs(new Dock[] { x_pos });
- Video vid = n.new Video();
- vid.setInputs(new Dock[] { x_pos, y_pos, color });
-
- ArrayList<Instruction> al = new ArrayList<Instruction>();
- n.emit(al);
- for(int i=0; i<al.size(); i++) System.out.println(al.get(i));
-
- FleetProcess fp = n.fleet.run((Instruction[])al.toArray(new Instruction[0]));
- System.out.println("launching...");
- while(true) System.out.println(fp.recvWord().toLong());
- }
-
- private void recvSendTokenDeliver(Dock dock, Destination dest) {
- LoopFactory lf = getLoopFactory(dock);
- lf.recvWord();
- lf.sendToken(dest);
- lf.deliver();
- }
-}
+++ /dev/null
-package edu.berkeley.fleet.ir;
-import edu.berkeley.fleet.loops.*;
-
-// ScanRows+Fix: HARD!
-/**
- * How do we know when a stream is done? In the case of Equalize?
- */
-public class Sheets {
-
- public static final int NUM_LANES = 3;
- public static final int FIFO_SHIP_CAPACITY = 8;
-
- /**
- * A block is a set of statements which may be dispatched
- * concurrently; no memory may be both read from and written to
- * within a Block, each block may have at most one ReadBack, and
- * each Block will completely finish before starting the next
- * Block.
- */
- public static class Block {
-
- private int var_idx = 0;
-
- public Statement[] statements;
- public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append("block {\n");
- for(int i=0; i<statements.length; i++) {
- sb.append(" ");
- sb.append(statements[i].toString());
- sb.append('\n');
- }
- sb.append("}\n");
- return sb.toString();
- }
-
- /**
- * Each variable is single-assignment, single-use. When
- * compiling, each Var maps to an outbox at which the values
- * in question will be made available.
- */
- public class Var {
- private Statement assigner;
- private Statement user;
- public final int lane;
- public final int idx;
- public Var() { this(0); }
- public Var(int lane) { this.lane = lane; this.idx = var_idx++; }
- public String toString() { return "v"+idx; }
- public Statement getAssigner() { return assigner; }
- public void setAssigner(Statement assigner) {
- if (this.assigner!=null) throw new RuntimeException();
- this.assigner = assigner;
- }
- public Statement getUser() { return user; }
- public void setUser(Statement user) {
- if (this.user!=null) throw new RuntimeException();
- this.user = user;
- }
- }
-
- // Statements //////////////////////////////////////////////////////////////////////////////
-
- public class Statement {
- }
-
- public class Literal extends Statement {
- Var dest;
- long[] vals;
- public Literal(Var dest, long[] vals) {
- this.dest = dest;
- this.vals = vals;
- dest.setAssigner(this);
- }
- /*
- public void emitSetupInstructions() {
- if (vals.length > FIFO_SHIP_CAPACITY) throw new RuntimeException();
- Ship fifo = allocateShip("Fifo");
- Dock fifo_in = fifo.getDock("in");
- for(int i=0; i<vals.length; i++) {
-
- }
- dest.setOutbox(fifo.getDock("out"));
- }
- public void emitTeardownInstructions() {
-
- }
- */
- }
-
- public class ReadBack extends Statement {
- Var values;
- public ReadBack(Var values) {
- this.values = values;
- values.setUser(this);
- }
- }
-
- public class Fanout extends Statement {
- public final Var[] dests;
- public final Var source;
- public Fanout(Var[] dests, Var source) {
- this.dests = dests;
- this.source = source;
- }
- }
-
- /** mainly used to relocate a value from one lane to another */
- public class Move extends Statement {
- public Move(Var dest, Var source) {
- }
- }
-
- /**
- * Repeat the first item from val enough times to match the
- * length of mimic. [val] MUST be a single-element stream.
- */
- public class Equalize extends Statement {
- public Equalize(Var dest, Var val, Var mimic) { }
- }
-
- // technically we could "fan out" tokens instead of fanning out counts, but...
- /** Like VRep, but for the single-column case */
- public class Replicate extends Statement {
- public Replicate(Var dest, Var counts, Var vals) { }
- }
-
- public class Alu extends Statement {
- public Alu(Var dest, Var opcodes, Var in1, Var in2) { }
- }
-
- public class Lut extends Statement {
- public Lut(Var dest, Var table, Var in1, Var in2) { }
- }
-
- public class ReadMem extends Statement {
- public ReadMem(Var dest, long whichMem, Var addresses) { }
- }
-
- public class WriteMem extends Statement {
- public WriteMem(long whichMem, Var addresses, Var values) { }
- }
-
- }
-
-
-}
\ No newline at end of file