add pump-local literals and convert Alu1 test case
authoradam <adam@megacz.com>
Sat, 25 Aug 2007 09:46:08 +0000 (10:46 +0100)
committeradam <adam@megacz.com>
Sat, 25 Aug 2007 09:46:08 +0000 (10:46 +0100)
ships/Alu1.ship
src/edu/berkeley/fleet/api/Instruction.java
src/edu/berkeley/fleet/assembler/Parser.java
src/edu/berkeley/fleet/assembler/fleet.g
src/edu/berkeley/fleet/fpga/Generator.java
src/edu/berkeley/fleet/ies44/InstructionEncoder.java
tests/pump/literal-at-pump.fleet [new file with mode: 0644]

index 4ef057a..5eb32fd 100644 (file)
@@ -85,26 +85,22 @@ ABS:
 #ship alu1         : Alu1
 
 debug.in:   [*] take, deliver;
-9:          sendto alu1.in;
-9:          sendto alu1.in;
-9:          sendto alu1.in;
-9:          sendto alu1.in;
+alu1.in:
+  literal 9;
+  [4] deliver;
+  [*] take, deliver;
 
-1:          sendto alu1.inOp;
-2:          sendto alu1.inOp;
-3:          sendto alu1.inOp;
-0:          sendto alu1.inOp;
-0:          sendto alu1.inOp;
-
-alu1.in:    [*] take, deliver;
-alu1.inOp:  [*] take, deliver;
 alu1.out:
-  [3] take, sendto debug.in;
-  take;
-  sendto debug.in;
+  [4] take, sendto debug.in;
   sendto alu1.in;
   [*] take, sendto debug.in;
 
+alu1.inOp:
+   literal 1; deliver;
+   literal 2; deliver;
+   literal 3; deliver;
+   literal 0; [2] deliver;
+
 
 == Contributors =========================================================
 Adam Megacz <megacz@cs.berkeley.edu>
index a32b8d0..8ca41b7 100644 (file)
@@ -98,6 +98,15 @@ public abstract class Instruction {
 
     }
 
+    public static class LocalLiteral extends Instruction {
+        public final Pump pump;
+        public final long literal;
+        public LocalLiteral(Pump pump, long literal) {
+            this.pump = pump;
+            this.literal = literal;
+        }
+    }
+
     public static class Literal extends Instruction {
         public final Destination dest;
         protected Literal(Destination dest) { this.dest = dest; }
index c649529..fbca63d 100644 (file)
@@ -277,6 +277,8 @@ public class Parser {
                 boolean dataOut = false;
                 boolean tokenOut = false;
                 boolean dataOutDest = false;
+                boolean localLiteral = false;
+                long literal = 0;
                 Destination dest = null;
                 for(int i=0; i<ttx.size(); i++) {
                     Tree ttt = ttx.child(i);
@@ -292,13 +294,17 @@ public class Parser {
                     else if ("Discard".equals(ttt.head())) { dataIn = true; latch = false; }
                     else if ("Take".equals(ttt.head()))    { dataIn = true; latch = true; }
                     else if ("SendTo".equals(ttt.head()))  { dataOut = true; dest = portReference(ttt.child(0)); }
+                    else if ("LocalLiteral".equals(ttt.head()))  { localLiteral = true; literal = Long.parseLong(string(ttt.child(0))); }
                     else if ("DataOutDest".equals(ttt.head()))  { dataOutDest = true; }
                     else if ("Deliver".equals(ttt.head())) { dataOut = true;  }
                     else if ("Ack".equals(ttt.head()))     { tokenOut = true; dest = portReference(ttt.child(0)); }
                 }
-                cb.add(new Instruction.Executable(pump,
-                                                  dest, count, tokenIn, dataIn,
-                                                  latch, dataOutDest, dataOut, tokenOut, requeue));
+                if (localLiteral)
+                    cb.add(new Instruction.LocalLiteral(pump, literal));
+                else
+                    cb.add(new Instruction.Executable(pump,
+                                                      dest, count, tokenIn, dataIn,
+                                                      latch, dataOutDest, dataOut, tokenOut, requeue));
             }
         }
     }
index e22fa02..e4f5387 100644 (file)
@@ -35,6 +35,7 @@ Command         = Nop::      "nop"
                 | SendTo::   "sendto" ws! Port
                 | DataOutDest::   "send"
                 | Deliver::  "deliver"
+                | LocalLiteral:: "literal" ws! int
                 | Ack::      "notify" ws! Port
 
 Source         = Port
index ba0bc7e..eca0197 100644 (file)
@@ -630,11 +630,26 @@ public class Generator {
 
         Assignable data_latch = new SimpleAssignable(inbox ? data_out.getName() : "`packet_data("+data_out.getName()+")");
         String data_latch_input = inbox ? "`packet_data("+data_in.getName()+")" : data_in.getName();
+
+        // Literal
+        box.new Event(
+                      new Object[] {
+                          ondeckFull.isFull(),
+                          "`instruction_is_literal(ondeck)"
+                      },
+                      new Action[] {
+                          new SimpleAction("ondeck_full<=0;"),
+                          new AssignAction(data_latch, "`instruction_literal(ondeck)"),
+                          newMayProceed.doFill()
+                      }
+                      );
+
         box.new Event(
                       new Object[] { ondeckFull.isFull(),
                                      data_out,
                                      token_out,
                                      ififo_in,
+                                     "!`instruction_is_literal(ondeck)",
                                      new ConditionalTrigger("`instruction_bit_datain(ondeck)", data_in),
                                      new ConditionalTrigger("`instruction_bit_tokenin(ondeck)", token_in)
                               },
@@ -683,6 +698,8 @@ public class Generator {
         pw.println("`define instruction_bit_dest(instruction)     instruction["+(OFFSET_DEST+WIDTH_DEST_ADDR-1)+":"+OFFSET_DEST+"]");
         pw.println("`define instruction_count(instruction)        instruction["+(OFFSET_COUNT+WIDTH_COUNT-1)+":"+OFFSET_COUNT+"]");
         pw.println("`define instruction_is_kill(i)                (`instruction_bit_latch(i) && (!(`instruction_bit_datain(i))))");
+        pw.println("`define instruction_is_literal(i)             (`instruction_bit_tokenout(i) && `instruction_bit_tokenin(i) && !`instruction_bit_dataout(i))");
+        pw.println("`define instruction_literal(i)                i["+(OFFSET_LITERAL+WIDTH_LITERAL-1)+":"+OFFSET_LITERAL+"]");
         pw.println("`define instruction_bit_kill_only_standing(i) (`instruction_bit_tokenin(i))");
         pw.println("`define instruction_is_clog(instruction)      (`instruction_count(instruction)==0 && !`instruction_bit_tokenin(instruction) && !`instruction_bit_datain(instruction) && !`instruction_bit_tokenout(instruction) && !`instruction_bit_dataout(instruction))");
         pw.println("`define instruction_is_unclog(instruction)    (`instruction_bit_kill_only_standing(instruction) && `instruction_is_kill(instruction))");
index 722338b..767ada7 100644 (file)
@@ -23,6 +23,9 @@ public abstract class InstructionEncoder {
     public static final int OFFSET_TI           = OFFSET_CONTROL+5;
     public static final int OFFSET_PUMP_ADDR    = OFFSET_TI+1;
 
+    public static final int OFFSET_LITERAL      = OFFSET_COUNT;
+    public static final int WIDTH_LITERAL       = WIDTH_COUNT+WIDTH_DEST_ADDR;
+
     /** get the bits describing this box's location on the DESTINATION HORN */
     protected abstract long getDestAddr(Destination box);
 
@@ -55,9 +58,9 @@ public abstract class InstructionEncoder {
         long inst = instr;
         switch((int)getField(WIDTH_WORD-1, WIDTH_WORD-2, inst)) {
             case 0: {
-                Pump name    = getBoxByInstAddr(getIntField(OFFSET_PUMP_ADDR+WIDTH_PUMP_ADDR-1, OFFSET_PUMP_ADDR, inst));
-                Destination dest = getDestByAddr   (getIntField(OFFSET_DEST+WIDTH_DEST_ADDR-1,      OFFSET_DEST,      inst));
-                int count        = getIntField(                 OFFSET_COUNT+WIDTH_COUNT-1,         OFFSET_COUNT,     inst);
+                Pump name           = getBoxByInstAddr(getIntField(OFFSET_PUMP_ADDR+WIDTH_PUMP_ADDR-1, OFFSET_PUMP_ADDR, inst));
+                Destination dest    = getDestByAddr   (getIntField(OFFSET_DEST+WIDTH_DEST_ADDR-1,      OFFSET_DEST,      inst));
+                int count           = getIntField(                 OFFSET_COUNT+WIDTH_COUNT-1,         OFFSET_COUNT,     inst);
                 boolean tokenIn     = getBit(OFFSET_TI, instr);
                 boolean dataIn      = getBit(OFFSET_DI, instr);
                 boolean latch       = getBit(OFFSET_DL, instr);
@@ -65,6 +68,9 @@ public abstract class InstructionEncoder {
                 boolean tokenOut    = getBit(OFFSET_TO, instr);
                 boolean requeue     = getBit(OFFSET_RQ, instr);
                 boolean dataOutDest = dataOut && tokenOut;
+                boolean isLiteral   = tokenIn && tokenOut && !dataOutDest;
+                if (isLiteral)
+                    return new Instruction.LocalLiteral(name, getIntField(OFFSET_LITERAL+WIDTH_LITERAL-1, OFFSET_LITERAL, inst));
                 if (latch & !dataIn) return new Instruction.Kill(name, count, tokenIn);
                 return new Instruction.Executable(name, dest, count, tokenIn, dataIn, latch, dataOutDest,
                                                   dataOut, tokenOut, requeue);
@@ -72,8 +78,8 @@ public abstract class InstructionEncoder {
 
             case 1: {
                 Destination name = getDestByAddr(getField(WIDTH_WORD-3, WIDTH_WORD-3-WIDTH_DEST_ADDR+1, inst));
-                long offset = getSignedField(WIDTH_WORD-3-WIDTH_DEST_ADDR, WIDTH_CODEBAG_SIZE, instr);
-                long size   = getSignedField(WIDTH_CODEBAG_SIZE-1,        0,                 instr);
+                long offset      = getSignedField(WIDTH_WORD-3-WIDTH_DEST_ADDR, WIDTH_CODEBAG_SIZE, instr);
+                long size        = getSignedField(WIDTH_CODEBAG_SIZE-1,        0,                 instr);
                 return new Instruction.Literal.CodeBagDescriptor(name, offset, size);
             }
 
@@ -101,8 +107,14 @@ public abstract class InstructionEncoder {
             d = new Instruction.Executable(k.pump, null, k.count, k.killOnlyStandingInstructions,
                                            false, true, false, false, false, false);
         }
+        if (d instanceof Instruction.LocalLiteral) {
+            Instruction.LocalLiteral inst = (Instruction.LocalLiteral)d;
+            instr |= putField(OFFSET_PUMP_ADDR+WIDTH_PUMP_ADDR-1, OFFSET_PUMP_ADDR,   getBoxInstAddr(inst.pump));
+            instr |= putField(OFFSET_TI,                          OFFSET_TI,          1);
+            instr |= putField(OFFSET_TO,                          OFFSET_TO,          1);
+            instr |= putField(OFFSET_LITERAL+WIDTH_LITERAL-1, OFFSET_LITERAL,         inst.literal);
 
-        if (d instanceof Instruction.Executable) {
+        } else if (d instanceof Instruction.Executable) {
             Instruction.Executable inst = (Instruction.Executable)d;
             instr |= putField(OFFSET_PUMP_ADDR+WIDTH_PUMP_ADDR-1, OFFSET_PUMP_ADDR,   getBoxInstAddr(inst.pump));
             instr |= putField(OFFSET_DEST+WIDTH_DEST_ADDR-1,      OFFSET_DEST,        inst.dest==null?0:getDestAddr(inst.dest));
diff --git a/tests/pump/literal-at-pump.fleet b/tests/pump/literal-at-pump.fleet
new file mode 100644 (file)
index 0000000..10255e0
--- /dev/null
@@ -0,0 +1,3 @@
+#expect 21
+#ship debug : Debug
+debug.in: literal 21; deliver;