From 956e8c7db1cf74582d2bec0b51728c231b09a0c7 Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 12 Feb 2008 05:26:57 +0100 Subject: [PATCH] add predicates to instruction encoder/decoder --- src/edu/berkeley/fleet/api/Instruction.java | 6 +-- src/edu/berkeley/fleet/assembler/Parser.java | 22 ++++----- src/edu/berkeley/fleet/fpga/Generator.java | 12 +++++ .../berkeley/fleet/ies44/InstructionEncoder.java | 48 ++++++++++++++------ 4 files changed, 60 insertions(+), 28 deletions(-) diff --git a/src/edu/berkeley/fleet/api/Instruction.java b/src/edu/berkeley/fleet/api/Instruction.java index 2082f03..321795a 100644 --- a/src/edu/berkeley/fleet/api/Instruction.java +++ b/src/edu/berkeley/fleet/api/Instruction.java @@ -40,7 +40,6 @@ public abstract class Instruction { public static final int P_IF_Z = 0x0004; public final int predicate; - public PredicatedInstruction(Pump pump) { super(pump); this.predicate = P_ALWAYS; } public PredicatedInstruction(Pump pump, int predicate) { super(pump); this.predicate = predicate; } public String toString() { switch(predicate) { @@ -96,7 +95,7 @@ public abstract class Instruction { } public static class DecrLoop extends PredicatedInstruction { - public DecrLoop(Pump pump) { super(pump); } + public DecrLoop(Pump pump) { super(pump, P_ALWAYS); } public DecrLoop(Pump pump, int predicate) { super(pump, predicate); } public boolean isDL() { return true; } public boolean isLooping() { return true; } @@ -228,9 +227,8 @@ public abstract class Instruction { public final long literal; public final boolean high; public boolean isRequeueing() { return true; } - public HalfLiteral(Pump pump, long literal, int count, boolean high) { this(pump, P_ALWAYS, literal, count, high); } public HalfLiteral(Pump pump, int predicate, long literal, int count, boolean high) { - super(pump); + super(pump, predicate); this.literal = literal; this.high = high; } diff --git a/src/edu/berkeley/fleet/assembler/Parser.java b/src/edu/berkeley/fleet/assembler/Parser.java index 9a0ebaf..ec0b4c6 100644 --- a/src/edu/berkeley/fleet/assembler/Parser.java +++ b/src/edu/berkeley/fleet/assembler/Parser.java @@ -291,22 +291,22 @@ public class Parser { cb.add(new Instruction.Kill(pump, count)); continue; } else if ("setflags".equals(tt.head())) { - cb.add(new Instruction.SetFlags(pump, parseFlags(tt.child(0)), parseFlags(tt.child(1)))); + cb.add(new Instruction.SetFlags(pump, predicate, parseFlags(tt.child(0)), parseFlags(tt.child(1)))); continue; } else if ("loop".equals(tt.head())) { - cb.add(new Instruction.Counter(pump, Instruction.Counter.LOOP_COUNTER, Instruction.Counter.DATA_LATCH)); + cb.add(new Instruction.Counter(pump, predicate, Instruction.Counter.LOOP_COUNTER, Instruction.Counter.DATA_LATCH)); continue; } else if ("load".equals(tt.head()) && "loop".equals(tt.child(0).head())) { - cb.add(new Instruction.Counter(pump, Instruction.Counter.DATA_LATCH, Instruction.Counter.LOOP_COUNTER)); + cb.add(new Instruction.Counter(pump, predicate, Instruction.Counter.DATA_LATCH, Instruction.Counter.LOOP_COUNTER)); continue; } else if ("load".equals(tt.head()) && "repeat".equals(tt.child(0).head())) { - cb.add(new Instruction.Counter(pump, Instruction.Counter.DATA_LATCH, Instruction.Counter.REPEAT_COUNTER)); + cb.add(new Instruction.Counter(pump, predicate, Instruction.Counter.DATA_LATCH, Instruction.Counter.REPEAT_COUNTER)); continue; } else if ("with".equals(tt.head()) && "loop".equals(tt.child(0).head())) { - cb.add(new Instruction.Counter(pump, (int)number(tt.child(1)), Instruction.Counter.LOOP_COUNTER)); + cb.add(new Instruction.Counter(pump, predicate, (int)number(tt.child(1)), Instruction.Counter.LOOP_COUNTER)); continue; } else if ("with".equals(tt.head()) && "repeat".equals(tt.child(0).head())) { - cb.add(new Instruction.Counter(pump, (int)number(tt.child(1)), Instruction.Counter.REPEAT_COUNTER)); + cb.add(new Instruction.Counter(pump, predicate, (int)number(tt.child(1)), Instruction.Counter.REPEAT_COUNTER)); continue; } else if ("massacre".equals(tt.head())) { cb.add(new Instruction.Massacre(pump)); @@ -321,12 +321,12 @@ public class Parser { CodeBag cb2 = getCodeBag("anon"+(anoncount++)); for(Tree statement : tq.child(0)) fillCodeBag(statement, cb2); - cb.add(new Instruction.CodeBagDescriptor(pump, cb2.getFakeAddress(), 0)); + cb.add(new Instruction.CodeBagDescriptor(pump, predicate, cb2.getFakeAddress(), 0)); continue OUTER; } else if (tt.child(0).head().equals("Name")) { String refname = name(tt.child(0)); CodeBag cb2 = getCodeBag(refname); - cb.add(new Instruction.CodeBagDescriptor(pump, cb2.getFakeAddress(), 0)); + cb.add(new Instruction.CodeBagDescriptor(pump, predicate, cb2.getFakeAddress(), 0)); continue OUTER; } else if (tt.child(0).head().equals("[")) { literal = parseSSL(tt.child(0)); @@ -339,8 +339,8 @@ public class Parser { } else if ("forever".equals(tt.child(1).head())) { count = 0; } - cb.add(new Instruction.HalfLiteral(pump, getField(36, 19, literal), count, true)); - cb.add(new Instruction.HalfLiteral(pump, getField(18, 0, literal), count, false)); + cb.add(new Instruction.HalfLiteral(pump, predicate, getField(36, 19, literal), count, true)); + cb.add(new Instruction.HalfLiteral(pump, predicate, getField(18, 0, literal), count, false)); continue; } Tree ttx = null; @@ -388,7 +388,7 @@ public class Parser { else if ("notify".equals(ttt.head())) { tokenOut = true; dest = portReference(ttt.child(0)); } else if ("notifyLast".equals(ttt.head())) { tokenOut = true; ignoreUntilLast = true; dest = portReference(ttt.child(0)); } } - cb.add(new Instruction.Move(pump, Instruction.PredicatedInstruction.P_ALWAYS, + cb.add(new Instruction.Move(pump, predicate, dest, count, tokenIn, dataIn, latch, dataOutDest, dataOut, tokenOut, requeue, ignoreUntilLast)); } diff --git a/src/edu/berkeley/fleet/fpga/Generator.java b/src/edu/berkeley/fleet/fpga/Generator.java index efc78e0..461ddaf 100644 --- a/src/edu/berkeley/fleet/fpga/Generator.java +++ b/src/edu/berkeley/fleet/fpga/Generator.java @@ -516,6 +516,18 @@ public class Generator { } PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(prefix+"/"+name+".v"))); fifo.dump(pw, true); + /* + pw.println("`define FIFO_LENGTH " + len); + //pw.println("`define NAME " + name); + pw.println("`include \"macros.v\""); + pw.println("module "+name+"(clk, rst "); + pw.println(" , in_r, in_a_, in"); + pw.println(" , out_r_, out_a, out_);"); + BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("src/edu/berkeley/fleet/fpga/fifo.inc"))); + String s; + while((s = br.readLine())!=null) + pw.println(s); + */ pw.flush(); return fifo; } diff --git a/src/edu/berkeley/fleet/ies44/InstructionEncoder.java b/src/edu/berkeley/fleet/ies44/InstructionEncoder.java index cbe8c76..8dc44b7 100644 --- a/src/edu/berkeley/fleet/ies44/InstructionEncoder.java +++ b/src/edu/berkeley/fleet/ies44/InstructionEncoder.java @@ -30,6 +30,10 @@ public abstract class InstructionEncoder { public static final Mask SK = new Mask("...........1........................."); public static final Mask DL = new Mask("............1........................"); public static final Mask P = new Mask(".............vv......................"); + public static final Mask P_A = new Mask(".............00......................"); + public static final Mask P_B = new Mask(".............10......................"); + public static final Mask P_Z = new Mask(".............01......................"); + public static final Mask P_ALWAYS = new Mask(".............11......................"); public static final Mask MOVE = new Mask("...............001..................."); public static final Mask STAND = new Mask("...................1................."); public static final Mask TI = new Mask("....................1................"); @@ -79,21 +83,28 @@ public abstract class InstructionEncoder { public Instruction readInstruction(long inst) { Pump name = getBoxByInstAddr(PUMP_NAME.getval(inst)); - if (LOOP_FROM_LITERAL.get(inst)) return new Counter(name, (int)LOOP_FROM_LITERAL.getval(inst), LOOP_COUNTER); - if (REPEAT_FROM_LITERAL.get(inst)) return new Counter(name, (int)REPEAT_FROM_LITERAL.getval(inst), REPEAT_COUNTER); - if (LOOP_FROM_DATA.get(inst)) return new Counter(name, DATA_LATCH, LOOP_COUNTER); - if (REPEAT_FROM_DATA.get(inst)) return new Counter(name, DATA_LATCH, REPEAT_COUNTER); - if (TAKE_LOOP.get(inst)) return new Counter(name, LOOP_COUNTER, DATA_LATCH); - - if (DL.get(inst)) return new Instruction.DecrLoop(name); - if (UNCLOG.get(inst)) return new Instruction.UnClog(name); if (CLOG.get(inst)) return new Instruction.Clog(name); if (MASSACRE.get(inst)) return new Instruction.Massacre(name); if (KILL.get(inst)) return new Instruction.Kill(name, (int)(KILL.getval(inst)+1)); - if (LITERAL_LO.get(inst)) return new Instruction.HalfLiteral(name, LITERAL_LO.getval(inst), 0, false); - if (LITERAL_HI.get(inst)) return new Instruction.HalfLiteral(name, LITERAL_HI.getval(inst), 0, true); - if (FLAGS.get(inst)) return new Instruction.SetFlags(name, (int)FLAGS_A.getval(inst), (int)FLAGS_B.getval(inst)); + + int predicate = 0; + if (P_ALWAYS.get(inst)) predicate = Instruction.PredicatedInstruction.P_ALWAYS; + if (P_A.get(inst)) predicate = Instruction.PredicatedInstruction.P_IF_A; + if (P_B.get(inst)) predicate = Instruction.PredicatedInstruction.P_IF_B; + if (P_Z.get(inst)) predicate = Instruction.PredicatedInstruction.P_IF_Z; + + if (LOOP_FROM_LITERAL.get(inst)) return new Counter(name, predicate, (int)LOOP_FROM_LITERAL.getval(inst), LOOP_COUNTER); + if (REPEAT_FROM_LITERAL.get(inst)) return new Counter(name, predicate, (int)REPEAT_FROM_LITERAL.getval(inst), REPEAT_COUNTER); + if (LOOP_FROM_DATA.get(inst)) return new Counter(name, predicate, DATA_LATCH, LOOP_COUNTER); + if (REPEAT_FROM_DATA.get(inst)) return new Counter(name, predicate, DATA_LATCH, REPEAT_COUNTER); + if (TAKE_LOOP.get(inst)) return new Counter(name, predicate, LOOP_COUNTER, DATA_LATCH); + + if (DL.get(inst)) return new Instruction.DecrLoop(name, predicate); + + if (LITERAL_LO.get(inst)) return new Instruction.HalfLiteral(name, predicate, LITERAL_LO.getval(inst), 0, false); + if (LITERAL_HI.get(inst)) return new Instruction.HalfLiteral(name, predicate, LITERAL_HI.getval(inst), 0, true); + if (FLAGS.get(inst)) return new Instruction.SetFlags(name, predicate, (int)FLAGS_A.getval(inst), (int)FLAGS_B.getval(inst)); if (!MOVE.get(inst)) throw new RuntimeException("unknown instruction: 0x" + Long.toString(inst, 16)); @@ -106,7 +117,7 @@ public abstract class InstructionEncoder { boolean standing = STAND.get(inst); boolean dataOutDest = PATH_DATA.get(inst); return new Instruction.Move(name, - Instruction.PredicatedInstruction.P_ALWAYS, /* FIXME */ + predicate, dest, standing?0:1, tokenIn, @@ -125,10 +136,21 @@ public abstract class InstructionEncoder { if (d.pump != null) instr = PUMP_NAME.setval(instr, getBoxInstAddr(d.pump)); + if (d instanceof Instruction.PredicatedInstruction) { + Instruction.PredicatedInstruction pi = (Instruction.PredicatedInstruction)d; + switch(pi.predicate) { + case Instruction.PredicatedInstruction.P_ALWAYS: instr = P_ALWAYS.set(instr); break; + case Instruction.PredicatedInstruction.P_IF_A: instr = P_A.set(instr); break; + case Instruction.PredicatedInstruction.P_IF_B: instr = P_B.set(instr); break; + case Instruction.PredicatedInstruction.P_IF_Z: instr = P_Z.set(instr); break; + } + } + if (d instanceof Instruction.CodeBagDescriptor) { Instruction.CodeBagDescriptor lc = (Instruction.CodeBagDescriptor)d; // MAJOR MAJOR FIXME: upper half here... - d = new Instruction.HalfLiteral(lc.pump, ((lc.offset << WIDTH_CODEBAG_SIZE)) | lc.size, 1, false); + d = new Instruction.HalfLiteral(lc.pump, Instruction.PredicatedInstruction.P_ALWAYS, + ((lc.offset << WIDTH_CODEBAG_SIZE)) | lc.size, 1, false); } if (d instanceof Instruction.UnClog) { -- 1.7.10.4