add Rotator ship
authoradam <adam@megacz.com>
Mon, 4 Feb 2008 02:12:35 +0000 (03:12 +0100)
committeradam <adam@megacz.com>
Mon, 4 Feb 2008 02:12:35 +0000 (03:12 +0100)
ships/Rotator.ship [new file with mode: 0644]
src/edu/berkeley/fleet/fpga/Fpga.java
src/edu/berkeley/fleet/interpreter/Interpreter.java

diff --git a/ships/Rotator.ship b/ships/Rotator.ship
new file mode 100644 (file)
index 0000000..c9b5790
--- /dev/null
@@ -0,0 +1,74 @@
+ship: Rotator
+
+== Ports ===========================================================
+in:   in
+in:   inAmount
+
+out:  out
+
+  
+== TeX ==============================================================
+
+The Rotator performs bitwise rotations of words.  When a value is
+present at both {\tt in} and {\tt inAmount}, both values are consumed,
+the value {\tt in} is rotated {\it towards the most significant bit}
+by {\tt inAmount} bits and emitted at {\tt out}.
+
+The output is undefined if {\tt inAmount} is greater than or equal to
+the number of bits in a word.
+
+
+== Fleeterpreter ====================================================
+
+public void service() {
+  if (box_inAmount.dataReadyForShip() && box_in.dataReadyForShip() && box_out.readyForDataFromShip()) {
+    long amount = box_inAmount.removeDataForShip();
+    long data   = box_in.removeDataForShip();
+    long mask = ~((-1L) << getInterpreter().getWordSize());
+    data = data & mask;
+    box_out.addDataFromShip(((data << amount) | (data >> (getInterpreter().getWordSize()-amount))) & mask);
+  }
+}
+
+
+== FPGA ==============================================================
+
+  wire [`DATAWIDTH*2-1:0] double;
+  assign double = { in_d[`DATAWIDTH-1:0], in_d[`DATAWIDTH-1:0] };
+
+  always @(posedge clk) begin
+    if (!rst) begin
+      `reset
+    end else begin
+      if (!in_r        && in_a)       in_a    <= 0;
+      if (!inAmount_r  && inAmount_a) inAmount_a  <= 0;
+      if (out_r        && out_a)      out_r   <= 0;
+      if (in_r && !in_a && inAmount_r && !inAmount_a && !out_r && !out_a) begin
+        in_a <= 1;
+        inAmount_a <= 1;
+        out_r <= 1;
+        out_d <= double >> (`DATAWIDTH - inAmount_d);
+      end
+    end
+  end
+
+== Test ==============================================================
+
+// expected output
+#expect 2
+#expect 44627559471
+
+
+// ships required in order to run this code
+#ship debug        : Debug
+#ship rotator      : Rotator
+
+rotator.in:         literal 1; deliver; literal 21615257152;  deliver;
+rotator.inAmount:   literal 1; deliver; literal 20;           deliver;
+rotator.out:        [*] take, sendto debug.in;
+debug.in:           [*] take, deliver;
+
+
+== Contributors =========================================================
+Amir Kamil <kamil@cs.berkeley.edu>
+Adam Megacz <megacz@cs.berkeley.edu>
index bc97213..3198d88 100644 (file)
@@ -27,15 +27,17 @@ public class Fpga extends Fleet {
     public Fpga() { this("gaspified.bit"); }
     public Fpga(String bitfile) {
         this.bitfile = bitfile;
-        createShip("Debug",   "debug");
+        createShip("Debug",     "debug");
         createShip("Memory",    "memory");
         createShip("Memory",    "memory2");  // need this to avoid a bug
-        createShip("Fifo",    "fifo1");
-        createShip("Fifo",    "fifo2");
-        createShip("Alu2",    "alu2a");
+
+        createShip("Fifo",      "fifo1");
+        createShip("Fifo",      "fifo2");
+        createShip("Alu2",      "alu2a");
         createShip("BitFifo",   "bitfifo");
+        createShip("Rotator",   "rotator");
         // above is the minimal ship set needed to run the regression suite, excluding "ships" tests
-        createShip("Alu1",    "alu1");
+        createShip("Alu1",      "alu1");
         createShip("Lut3",      "lut3");
         createShip("Alu3",      "alu3");
 
index 3a25f4a..b82ac4d 100644 (file)
@@ -15,6 +15,8 @@ public class Interpreter extends Fleet implements Fleet.WithDynamicShips {
     private HashMap<String,InterpreterShip> ships       = new HashMap<String,InterpreterShip>();
     private BlockingQueue<Long>             debugStream = new LinkedBlockingQueue<Long>();
 
+    public int getWordSize() { return 37; }
+
     public FleetProcess run(final byte[] instructions) {
         try {
             final FleetProcess fp = new FleetProcess() {