From 26b5a16ee2385c03f04e4926b8e19dad36f62a95 Mon Sep 17 00:00:00 2001 From: megacz Date: Sat, 14 Mar 2009 15:16:33 -0700 Subject: [PATCH] remove "looping" argument from Instruction --- src/edu/berkeley/fleet/api/Instruction.java | 48 +++++++++----------- src/edu/berkeley/fleet/assembler/Parser.java | 58 ++++++++++++------------- src/edu/berkeley/fleet/assembler/fleet.g | 1 - src/edu/berkeley/fleet/fpga/Client.java | 8 ++-- src/edu/berkeley/fleet/loops/LoopFactory.java | 18 +++----- src/edu/berkeley/fleet/two/FleetTwoFleet.java | 21 +++++---- 6 files changed, 70 insertions(+), 84 deletions(-) diff --git a/src/edu/berkeley/fleet/api/Instruction.java b/src/edu/berkeley/fleet/api/Instruction.java index 7c0719f..1dfc8b5 100644 --- a/src/edu/berkeley/fleet/api/Instruction.java +++ b/src/edu/berkeley/fleet/api/Instruction.java @@ -7,17 +7,13 @@ public abstract class Instruction { /** the dock which is to execute this instruction */ public final Dock dock; - /** true if the instruction is an outer-looping instruction */ - public final boolean looping; - /** the instruction's predicate */ public final Predicate predicate; - Instruction(Dock dock, boolean looping, Predicate predicate) { + Instruction(Dock dock, Predicate predicate) { if (dock==null) throw new RuntimeException("dock may not be null"); if (predicate==null) throw new RuntimeException("predicate may not be null"); this.dock = dock; - this.looping = looping; this.predicate = predicate; } @@ -27,7 +23,6 @@ public abstract class Instruction { public String toString() { String s = predicate.toString(); if (s.length()>0) s = "["+s+"] "; - if (looping) s += "[Rq] "; return dock+": "+s; } @@ -59,9 +54,9 @@ public abstract class Instruction { public final FlagFunction newFlagB; /** basic constructor */ - public Set(Dock dock, SetDest dest, SetSource source) { this(dock, false, Predicate.Default, dest, source); } - public Set(Dock dock, boolean looping, Predicate predicate, SetDest dest, SetSource source) { - super(dock, looping, predicate); + public Set(Dock dock, SetDest dest, SetSource source) { this(dock, Predicate.Default, dest, source); } + public Set(Dock dock, Predicate predicate, SetDest dest, SetSource source) { + super(dock, predicate); OUTER: switch(dest) { case InnerLoopCounter: switch(source) { @@ -85,9 +80,9 @@ public abstract class Instruction { } /** constructor for set instructions with immediates */ - public Set(Dock dock, SetDest dest, long immediate) { this(dock, false, Predicate.Default, dest, immediate); } - public Set(Dock dock, boolean looping, Predicate predicate, SetDest dest, long immediate) { - super(dock, looping, predicate); + public Set(Dock dock, SetDest dest, long immediate) { this(dock, Predicate.Default, dest, immediate); } + public Set(Dock dock, Predicate predicate, SetDest dest, long immediate) { + super(dock, predicate); if (dest!=SetDest.InnerLoopCounter && dest!=SetDest.OuterLoopCounter && dest!=SetDest.DataLatch) throw new RuntimeException("a set instruction with dest="+dest+" may not take an immediate"); this.source = SetSource.Immediate; @@ -98,9 +93,9 @@ public abstract class Instruction { } /** constructor for set flags instructions */ - public Set(Dock dock, FlagFunction newFlagA, FlagFunction newFlagB) { this(dock, false, Predicate.Default, newFlagA, newFlagB); } - public Set(Dock dock, boolean looping, Predicate predicate, FlagFunction newFlagA, FlagFunction newFlagB) { - super(dock, looping, predicate); + public Set(Dock dock, FlagFunction newFlagA, FlagFunction newFlagB) { this(dock, Predicate.Default, newFlagA, newFlagB); } + public Set(Dock dock, Predicate predicate, FlagFunction newFlagA, FlagFunction newFlagB) { + super(dock, predicate); this.source = SetSource.Immediate; this.dest = SetDest.Flags; this.immediate = 0; @@ -220,9 +215,9 @@ public abstract class Instruction { /** shifts an immediate into the low-order bits of the data latch */ public static class Shift extends Instruction { public final BitVector immediate; - public Shift(Dock dock, BitVector immediate) { this(dock, false, Predicate.Default, immediate); } - public Shift(Dock dock, boolean looping, Predicate predicate, BitVector immediate) { - super(dock, looping, predicate); + public Shift(Dock dock, BitVector immediate) { this(dock, Predicate.Default, immediate); } + public Shift(Dock dock, Predicate predicate, BitVector immediate) { + super(dock, predicate); this.immediate = immediate; this.immediate.setImmutable(); if (immediate.length() != dock.getShip().getFleet().getShiftWidth()) @@ -235,9 +230,9 @@ public abstract class Instruction { /** a flush instruction */ public static class Flush extends Instruction { - public Flush(Dock dock) { this(dock, false, Predicate.Default); } - public Flush(Dock dock, boolean looping, Predicate predicate) { - super(dock, looping, predicate); + public Flush(Dock dock) { this(dock, Predicate.Default); } + public Flush(Dock dock, Predicate predicate) { + super(dock, predicate); if (!dock.isInputDock()) throw new RuntimeException("Flush is only allowed at input docks"); } public String toString() { return super.toString()+"flush"; } @@ -279,9 +274,8 @@ public abstract class Instruction { boolean dataOut, boolean tokenOut ) { - this(dock, false, Predicate.Default, false, path, tokenIn, dataIn, latchData, latchPath, dataOut, tokenOut); } + this(dock, Predicate.Default, false, path, tokenIn, dataIn, latchData, latchPath, dataOut, tokenOut); } public Move(Dock dock, - boolean looping, Predicate predicate, boolean interruptible, Path path, @@ -292,7 +286,7 @@ public abstract class Instruction { boolean dataOut, boolean tokenOut ) { - super(dock, looping, predicate); + super(dock, predicate); this.path = path; this.tokenIn = tokenIn; this.dataIn = dataIn; @@ -334,19 +328,19 @@ public abstract class Instruction { /** a flush instruction */ public static class Abort extends Instruction { - public Abort(Dock dock, Predicate predicate) { super(dock, false, predicate); } + public Abort(Dock dock, Predicate predicate) { super(dock, predicate); } public String toString() { return super.toString()+"abort;"; } } /** marks the start of a loop; closes the hatch */ public static class Head extends Instruction { - public Head(Dock dock) { super(dock, false, Predicate.IgnoreFlagD); } + public Head(Dock dock) { super(dock, Predicate.IgnoreFlagD); } public String toString() { return dock+": head;"; } } /** marks the end of a loop; closes the hatch */ public static class Tail extends Instruction { - public Tail(Dock dock) { super(dock, false, Predicate.IgnoreFlagD); } + public Tail(Dock dock) { super(dock, Predicate.IgnoreFlagD); } public String toString() { return dock+": tail;"; } } diff --git a/src/edu/berkeley/fleet/assembler/Parser.java b/src/edu/berkeley/fleet/assembler/Parser.java index 700f74e..e43b035 100644 --- a/src/edu/berkeley/fleet/assembler/Parser.java +++ b/src/edu/berkeley/fleet/assembler/Parser.java @@ -106,7 +106,7 @@ public class Parser { long lit = 0; lit = ((FleetTwoFleet)fleet).CBD_SIZE.setval(lit, codeBags.get((int)old.immediate).size()); lit = ((FleetTwoFleet)fleet).CBD_OFFSET.setval(lit, codeBagMap[(int)old.immediate]); - inst = new Set(old.dock, false, IgnoreFlagD, SetDest.DataLatch, lit); + inst = new Set(old.dock, IgnoreFlagD, SetDest.DataLatch, lit); } ret.add(inst); count++; @@ -154,15 +154,15 @@ public class Parser { for(int i=0; i ihorn.getInstructionFifoSize()) throw new RuntimeException(); @@ -369,7 +369,6 @@ public class Parser { int count = 1; Predicate predicate = Default; - boolean looping = false; boolean interruptible = false; for(int i=0; i 0 && "[T]".equals(tt.child(0).head())) interruptible = true; - cb.add(new Move(dock, looping, predicate, interruptible, null, false, false, false, false, false, false)); + cb.add(new Move(dock, predicate, interruptible, null, false, false, false, false, false, false)); } else if ("shift".equals(tt.head())) { - cb.add(new Shift(dock, looping, predicate, + cb.add(new Shift(dock, predicate, new BitVector(dock.getShip().getFleet().getShiftWidth()).set(number(tt.child(0))))); continue; } else if ("flush".equals(tt.head())) { - cb.add(new Flush(dock, looping, predicate)); + cb.add(new Flush(dock, predicate)); continue; } else if ("abort".equals(tt.head())) { cb.add(new Abort(dock, predicate)); @@ -425,12 +423,12 @@ public class Parser { CodeBag cb2 = getCodeBag("anon"+(anoncount++)); for(Tree statement : tq.child(0)) fillCodeBag(statement, cb2); - cb.add(new Set(dock, looping, predicate, SetDest.DataLatch, (cb2.getFakeAddress())), true); + cb.add(new Set(dock, predicate, SetDest.DataLatch, (cb2.getFakeAddress())), true); continue OUTER; } else if (tt.child(0).head().equals("Name")) { String refname = name(tt.child(0)); CodeBag cb2 = getCodeBag(refname); - cb.add(new Set(dock, looping, predicate, SetDest.DataLatch, (cb2.getFakeAddress())), true); + cb.add(new Set(dock, predicate, SetDest.DataLatch, (cb2.getFakeAddress())), true); continue OUTER; } else if (tt.child(0).head().equals("[")) { literal = parseSSL(tt.child(0)); @@ -448,12 +446,12 @@ public class Parser { if (((FleetTwoFleet)fleet).isSmallEnoughToFit(literal)) { - cb.add(new Set(dock, looping, predicate, SetDest.DataLatch, (literal))); + cb.add(new Set(dock, predicate, SetDest.DataLatch, (literal))); } else { int counter = 0; while(counter < dock.getShip().getFleet().getWordWidth()) counter += fleet.getShiftWidth(); while(counter > 0) { - cb.add(new Shift(dock, looping, predicate, + cb.add(new Shift(dock, predicate, new BitVector(dock.getShip().getFleet().getShiftWidth()) .set(getField(counter-1, counter-fleet.getShiftWidth(), literal)))); counter -= fleet.getShiftWidth(); @@ -539,7 +537,7 @@ public class Parser { else if ("send token".equals(ttt.head())) { tokenOut = true; } else if ("send token to".equals(ttt.head())) { tokenOut = true; path = path(dock, ttt.child(0)); } } - cb.add(new Move(dock, looping, predicate, + cb.add(new Move(dock, predicate, interruptible, path, tokenIn, dataIn, latch, dispatch, dataOut, tokenOut)); } @@ -584,8 +582,8 @@ public class Parser { public Ship createShip(String shiptype, String shipname); } - private static Move discard(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, false, true, false, false, false, false); } - private static Move deliver(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, false, false, false, false, true, false); } - private static Move wait(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, true, false, false, false, false, false); } - private static Move sendto(Dock dock, Path path) { return new Move(dock, false, IgnoreFlagD, false, path, false, false, false, false, true, false); } + private static Move discard(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, false, true, false, false, false, false); } + private static Move deliver(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, false, false, false, false, true, false); } + private static Move wait(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, true, false, false, false, false, false); } + private static Move sendto(Dock dock, Path path) { return new Move(dock, IgnoreFlagD, false, path, false, false, false, false, true, false); } } diff --git a/src/edu/berkeley/fleet/assembler/fleet.g b/src/edu/berkeley/fleet/assembler/fleet.g index 90f601d..219fb21 100644 --- a/src/edu/berkeley/fleet/assembler/fleet.g +++ b/src/edu/berkeley/fleet/assembler/fleet.g @@ -19,7 +19,6 @@ Tag = ^"[a]" ws | ^"[b]" ws | ^"[!a]" ws | ^"[!b]" ws | ^"[d]" ws | ^"[*]" ws - | ^"[Rq]" ws InstructionX = (() | ^"[T]" ws) ^"nop" ";" /ws | (() | ^"[T]" ws) (Commands:: Command +/ (ws "," ws)) ^";" /ws | "olc=word":: "set" "olc" "=" "word" ";" /ws diff --git a/src/edu/berkeley/fleet/fpga/Client.java b/src/edu/berkeley/fleet/fpga/Client.java index 1a2ec3c..235e183 100644 --- a/src/edu/berkeley/fleet/fpga/Client.java +++ b/src/edu/berkeley/fleet/fpga/Client.java @@ -131,8 +131,8 @@ public class Client extends FleetProcess { new BitVector(fpga.getWordWidth()).set(fpga.writeInstruction(inst, dispatchFrom))); } - private static Move discard(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, false, true, false, false, false, false); } - private static Move deliver(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, false, false, false, false, true, false); } - private static Move wait(Dock dock) { return new Move(dock, false, IgnoreFlagD, false, null, true, false, false, false, false, false); } - private static Move sendto(Dock dock, Path path) { return new Move(dock, false, IgnoreFlagD, false, path, false, false, false, false, true, false); } + private static Move discard(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, false, true, false, false, false, false); } + private static Move deliver(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, false, false, false, false, true, false); } + private static Move wait(Dock dock) { return new Move(dock, IgnoreFlagD, false, null, true, false, false, false, false, false); } + private static Move sendto(Dock dock, Path path) { return new Move(dock, IgnoreFlagD, false, path, false, false, false, false, true, false); } } diff --git a/src/edu/berkeley/fleet/loops/LoopFactory.java b/src/edu/berkeley/fleet/loops/LoopFactory.java index d7b6648..654abd2 100644 --- a/src/edu/berkeley/fleet/loops/LoopFactory.java +++ b/src/edu/berkeley/fleet/loops/LoopFactory.java @@ -113,7 +113,6 @@ public class LoopFactory { throw new RuntimeException("abortLoopIfTorpedoPresent() must be followed immediately by a Move"); } else { instructions.add(new Move(dock, - count!=1, predicate, pending_interruptible, pending_path==null ? null : pending_path, @@ -136,7 +135,6 @@ public class LoopFactory { public void interruptibleNop() { flush_pending(); instructions.add(new Move(dock, - count!=1, predicate, true, null, @@ -206,7 +204,7 @@ public class LoopFactory { public void flush() { if (!dock.isInputDock()) throw new RuntimeException("flush() may only be used at input docks"); flush_pending(); - instructions.add(new Instruction.Flush(dock, count!=1, predicate)); + instructions.add(new Instruction.Flush(dock, predicate)); } /** [outboxes only], will fuse with previous instruction if it was a sendToken() */ @@ -229,7 +227,7 @@ public class LoopFactory { for(int i=counter-1; i>=counter-ctx.fleet.getShiftWidth(); i--) if (i 0) { - instructions.add(new Shift(dock, count!=1, predicate, + instructions.add(new Shift(dock, predicate, new BitVector(dock.getShip().getFleet().getWordWidth()) .set(getField(counter-1, counter-ctx.fleet.getShiftWidth(), literal)))); counter -= ctx.fleet.getShiftWidth(); @@ -257,7 +255,6 @@ public class LoopFactory { public void setFlags(Instruction.Set.FlagFunction newFlagA, Instruction.Set.FlagFunction newFlagB) { flush_pending(); instructions.add(new Instruction.Set(dock, - count!=1, predicate, newFlagA, newFlagB)); @@ -267,7 +264,6 @@ public class LoopFactory { public void abort() { flush_pending(); instructions.add(new Instruction.Set(dock, - count!=1, predicate, SetDest.OuterLoopCounter, 0)); @@ -308,7 +304,7 @@ public class LoopFactory { boolean blockingInstructionEncountered = false; // Set the OLC (it might previously have been zero) - ic.add(new Set(dock, false, Predicate.IgnoreFlagD, SetDest.OuterLoopCounter, count==0 ? 1 : count)); + ic.add(new Set(dock, Predicate.IgnoreFlagD, SetDest.OuterLoopCounter, count==0 ? 1 : count)); if (count!=1) { ic.add(new Instruction.Head(dock)); } @@ -327,7 +323,7 @@ public class LoopFactory { throw new RuntimeException("instruction sequence is too long for instruction fifo at " + dock); } else { if (count != 0) { - ic.add(new Instruction.Set(dock, true, Predicate.Default, SetDest.OuterLoopCounter, SetSource.Decrement)); + ic.add(new Instruction.Set(dock, Predicate.Default, SetDest.OuterLoopCounter, SetSource.Decrement)); if (blockingInstructionEncountered) numInstructionsNotIncludingNonblockingPrefix++; loopSize++; @@ -336,7 +332,7 @@ public class LoopFactory { if (count!=1) ic.add(new Instruction.Abort(dock, Predicate.FlagD)); if (ctx.autoflush && next==null && dock.isInputDock()) - ic.add(new Instruction.Flush(dock, true, Predicate.FlagD)); + ic.add(new Instruction.Flush(dock, Predicate.FlagD)); // FIXME: need to somehow deal with count!=0 loops that are // torpedoable; they need to wait for a torpedo to arrive diff --git a/src/edu/berkeley/fleet/two/FleetTwoFleet.java b/src/edu/berkeley/fleet/two/FleetTwoFleet.java index c868ded..87dcc15 100644 --- a/src/edu/berkeley/fleet/two/FleetTwoFleet.java +++ b/src/edu/berkeley/fleet/two/FleetTwoFleet.java @@ -270,29 +270,29 @@ public abstract class FleetTwoFleet extends Fleet { if (P_NOT_B.get(inst)) predicate = NotFlagB; if (FLUSH.get(inst)) - return new Flush(dock, false, predicate); + return new Flush(dock, predicate); if (ABORT.get(inst)) return new Abort(dock, predicate); - if (SHIFT.get(inst)) return new Shift(dock, false, predicate, new BitVector(dock.getShip().getFleet().getShiftWidth()).set(SHIFT.getval(inst))); + if (SHIFT.get(inst)) return new Shift(dock, predicate, new BitVector(dock.getShip().getFleet().getShiftWidth()).set(SHIFT.getval(inst))); if (SET_IMMEDIATE.get(inst)) { boolean extend = SET_IMMEDIATE_EXTEND.getval(inst) != 0; long immediate = SET_IMMEDIATE.getval(inst); if (extend) immediate |= (-1L << DataLatch_WIDTH); - return new Set(dock, false, predicate, SetDest.DataLatch, (immediate)); + return new Set(dock, predicate, SetDest.DataLatch, (immediate)); } if (SET_OLC_FROM_OLC_MINUS_ONE.get(inst)) - return new Set(dock, false, predicate, SetDest.OuterLoopCounter, SetSource.Decrement); + return new Set(dock, predicate, SetDest.OuterLoopCounter, SetSource.Decrement); if (SET_OLC_FROM_IMMEDIATE.get(inst)) - return new Set(dock, false, predicate, SetDest.OuterLoopCounter, (SET_OLC_FROM_IMMEDIATE.getval(inst))); + return new Set(dock, predicate, SetDest.OuterLoopCounter, (SET_OLC_FROM_IMMEDIATE.getval(inst))); if (SET_ILC_FROM_IMMEDIATE.get(inst)) - return new Set(dock, false, predicate, SetDest.InnerLoopCounter, (SET_ILC_FROM_IMMEDIATE.getval(inst))); + return new Set(dock, predicate, SetDest.InnerLoopCounter, (SET_ILC_FROM_IMMEDIATE.getval(inst))); if (SET_OLC_FROM_DATA_LATCH.get(inst)) - return new Set(dock, false, predicate, SetDest.OuterLoopCounter, SetSource.DataLatch); + return new Set(dock, predicate, SetDest.OuterLoopCounter, SetSource.DataLatch); if (SET_ILC_FROM_DATA_LATCH.get(inst)) - return new Set(dock, false, predicate, SetDest.InnerLoopCounter, SetSource.DataLatch); + return new Set(dock, predicate, SetDest.InnerLoopCounter, SetSource.DataLatch); if (SET_ILC_FROM_INFINITY.get(inst)) - return new Set(dock, false, predicate, SetDest.InnerLoopCounter, SetSource.Infinity); + return new Set(dock, predicate, SetDest.InnerLoopCounter, SetSource.Infinity); if (SET_FLAGS.get(inst)) { long flag_a = SET_FLAGS_A.getval(inst); long flag_b = SET_FLAGS_B.getval(inst); @@ -310,11 +310,10 @@ public abstract class FleetTwoFleet extends Fleet { if (SET_FLAGS_VALUE_NOT_B.get(flag_b)) bp = bp.add(NotFlagB ); if (SET_FLAGS_VALUE_C .get(flag_b)) bp = bp.add(FlagC ); if (SET_FLAGS_VALUE_NOT_C.get(flag_b)) bp = bp.add(NotFlagC ); - return new Set(dock, false, predicate, ap, bp); + return new Set(dock, predicate, ap, bp); } if (MOVE.get(inst)) return new Move(dock, - false, predicate, !NOT_INTERRUPTIBLE.get(inst), PATH_DATA.get(inst)?null:getPathByAddr(dock, PATH_IMMEDIATE.getvalAsBitVector(inst)), -- 1.7.10.4