From: megacz Date: Fri, 13 Mar 2009 18:11:43 +0000 (-0700) Subject: remove a bunch of obsolete junk X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=a04a5b257147b8421cbead9e972a6e609995ead5;p=fleet.git remove a bunch of obsolete junk --- diff --git a/src/edu/berkeley/fleet/ir/Counter.java b/src/edu/berkeley/fleet/ir/Counter.java deleted file mode 100644 index 059f5a6..0000000 --- a/src/edu/berkeley/fleet/ir/Counter.java +++ /dev/null @@ -1,328 +0,0 @@ -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 ai = new ArrayList(); - 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 diff --git a/src/edu/berkeley/fleet/ir/IR.java b/src/edu/berkeley/fleet/ir/IR.java deleted file mode 100644 index 40fe629..0000000 --- a/src/edu/berkeley/fleet/ir/IR.java +++ /dev/null @@ -1,87 +0,0 @@ -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 { - } - - 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 iterator() { return new SingletonIterator(this); } - } - - public abstract class Node extends Nodes { - public abstract Nodes preds(); - public abstract Nodes succs(); - public Iterator 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; - } - */ -} diff --git a/src/edu/berkeley/fleet/ir/Junk.java b/src/edu/berkeley/fleet/ir/Junk.java deleted file mode 100644 index 2df0776..0000000 --- a/src/edu/berkeley/fleet/ir/Junk.java +++ /dev/null @@ -1,519 +0,0 @@ -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 segments = new HashSet(); - private HashSet allocated = new HashSet(); - - private HashMap loops = new HashMap(); - private HashSet emitLoops = new HashSet(); - - 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 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 il) { } - public abstract void emitInstructions(ArrayList 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 il) { } - public void emitInstructions(ArrayList 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 il) { - LoopFactory lf; - lf = getLoopFactory(fifoShip.getDock("out"), 0); - lf.collectWord(); - } - public void emitInstructions(ArrayList 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 il) { - LoopFactory lf; - lf = getLoopFactory(alu.getDock("out"), 0); - lf.collectWord(); - } - public void emitInstructions(ArrayList 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 il) { - LoopFactory lf; - lf = getLoopFactory(alu.getDock("out"), 1); - lf.literal(start); - getNextLoopFactory(alu.getDock("out"), 0); - } - public void emitInstructions(ArrayList 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 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 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 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 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 il) { } - public void emitInstructions(ArrayList 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 al = new ArrayList(); - n.emit(al); - for(int i=0; i FIFO_SHIP_CAPACITY) throw new RuntimeException(); - Ship fifo = allocateShip("Fifo"); - Dock fifo_in = fifo.getDock("in"); - for(int i=0; i