1 package edu.berkeley.fleet.dataflow;
3 import edu.berkeley.fleet.loops.*;
4 import edu.berkeley.fleet.api.*;
5 import edu.berkeley.fleet.api.Instruction.Set.FlagFunction;
8 * Takes an item from the "count" port, then passes/drops through count-1
9 * items from "val" to "out" and drops/passes the count-th item.
11 public class UnPunctuatorNode extends Node {
12 private final Ship ship = dfg.pool.allocateShip("Counter");
13 private final InPort op = new DockInPort("op", ship.getDock("inOp"), "PASS_C2_V1");
14 public final InPort val = new DockInPort("val", ship.getDock("in1"));
15 public final InPort count = new DockInPort("count", ship.getDock("in2"));
16 public final OutPort out = new DockOutPort("out", ship.getDock("out")) {
17 protected void build(CodeBag ctx, LoopFactory lf) {
19 lf.abortLoopIfTorpedoPresent();
21 lf.setFlags(FlagFunction.ZERO.add(Predicate.FlagC), FlagFunction.ZERO);
22 lf.setPredicate(passPunctuationInsteadOfValues ? Predicate.FlagA : Predicate.NotFlagA);
23 lf.abortLoopIfTorpedoPresent();
26 lf.setPredicate(null);
30 private boolean passPunctuationInsteadOfValues;
31 public UnPunctuatorNode(DataFlowGraph dfg) { this(dfg, false); }
32 public UnPunctuatorNode(DataFlowGraph dfg, boolean passPunctuationInsteadOfValues) {
34 this.passPunctuationInsteadOfValues = passPunctuationInsteadOfValues;
38 private final Ship ship = dfg.pool.allocateShip("Alu");
39 public final InPort val = new DockInPort("val", ship.getDock("in1"));
40 public final OutPort out = new DockOutPort("out", ship.getDock("out"));
41 public final InPort val2 = new DockInPort("val2", ship.getDock("in2"));
42 public final InPort count = new DockInPort("count", ship.getDock("inOp")) {
43 protected void _build(LoopFactory lf) {
45 // FlagA set means we have a count value ready to use
46 // FlagB+FlagD means a torpedo has struck
47 // therefore, every recieve is folowed by if-flag-d-then-set-FlagB
48 // therefore, every set/dec olc is folowed by if-flag-d-then-copy-NotFlagB-to-FlagA ; if-flag-d-then-clear-FlagD ; if-FlagB-then-set-FlagD
50 lf.setFlags(FlagFunction.ZERO, FlagFunction.ZERO);
53 // new iteration or decrement
54 lf.setPredicate(Predicate.NotFlagA);
55 sendTokenAndRecvWord(lf);
56 lf.setPredicate(Predicate.FlagD);
57 lf.setFlags(FlagFunction.ZERO.add(Predicate.FlagA), FlagFunction.ONE);
58 lf.setPredicate(Predicate.FlagA);
60 lf.setPredicate(Predicate.NotFlagA);
62 lf.setFlags(FlagFunction.ONE, FlagFunction.ZERO.add(Predicate.FlagB));
63 lf.setPredicate(Predicate.FlagD);
64 lf.setFlags(FlagFunction.ZERO, FlagFunction.ZERO.add(Predicate.FlagB));
66 lf.setPredicate(Predicate.FlagB);
68 lf.setPredicate(null);
70 lf.setPredicate(Predicate.NotFlagA);
71 lf.literal(passPunctuationInsteadOfValues ? "IN1" : "DROP1");
72 lf.setPredicate(Predicate.FlagA);
73 lf.literal(passPunctuationInsteadOfValues ? "DROP1" : "IN1");
74 lf.setPredicate(null);
75 lf.abortLoopIfTorpedoPresent();
77 lf.setPredicate(Predicate.FlagD);
78 lf.setFlags(FlagFunction.ZERO.add(Predicate.FlagA), FlagFunction.ONE);
79 lf.setPredicate(null);
83 private boolean passPunctuationInsteadOfValues;
84 public UnPunctuatorNode2(DataFlowGraph dfg) { this(dfg, false); }
85 public UnPunctuatorNode2(DataFlowGraph dfg, boolean passPunctuationInsteadOfValues) {
87 this.passPunctuationInsteadOfValues = passPunctuationInsteadOfValues;
90 public static void main(String[] s) throws Exception {
91 Fleet fleet = new Fpga();
92 ShipPool pool = new ShipPool(fleet);
93 DataFlowGraph dfg = new DataFlowGraph(fleet, pool);
94 DebugNode dn = new DebugNode(dfg);
95 DownCounterNode fn = new DownCounterNode(dfg);
96 fn.start.connect(new OnceNode(dfg, 100).out);
97 fn.incr.connect(new OnceNode(dfg, 1).out);
98 UnPunctuatorNode2 up = new UnPunctuatorNode2(dfg);
99 up.val.connect(fn.out);
100 up.count.connect(new ForeverNode(dfg, 12).out);
101 up.out.connect(dn.in);
102 CodeBag cb = new CodeBag(fleet);
104 FleetProcess fp = fleet.run(new Instruction[0]);
108 System.out.println("word = " + fp.recvWord().toLong());