improve BitFifo
authoradam <adam@megacz.com>
Fri, 10 Aug 2007 12:08:21 +0000 (13:08 +0100)
committeradam <adam@megacz.com>
Fri, 10 Aug 2007 12:08:21 +0000 (13:08 +0100)
ships/BitFifo.ship

index acb9e33..67b8e0b 100644 (file)
@@ -77,16 +77,16 @@ was actually {\tt 37-Offset-Count} for all directions below.
 }
 
 \begin{itemize}
-   \item [\tt Until]  ({\bf Shift until you see a (0, 1)})
-   \item [\tt Sort]   ({\bf Sort the Bits})
-   \item [\tt Get]    ({\bf Get the value of the counter})
-   \item [\tt Rev]    ({\bf Reverse Before Enqueue})
-   \item [\tt Inv]    ({\bf Invert Count}) -- treat {\tt Count} as {\tt 37-Offset-Count}
-   \item [\tt Rst]    ({\bf Reset Counter Before Operation})
-   \item [\tt Left Fill]  ({\bf Left Fill (0, 1, sign)})
+   \item [\tt Until]       ({\bf Shift until you see a (0, 1)})
+   \item [\tt Sort]        ({\bf Sort the Bits})
+   \item [\tt Get]         ({\bf Get the value of the counter})
+   \item [\tt Rev]         ({\bf Reverse Before Enqueue})
+   \item [\tt Inv]         ({\bf Invert Count}) -- treat {\tt Count} as {\tt 37-Offset-Count}
+   \item [\tt Rst]         ({\bf Reset Counter Before Operation})
+   \item [\tt Left Fill]   ({\bf Left Fill (0, 1, sign)})
    \item [\tt Right Fill]  ({\bf Right Fill (0, 1, sign)})
-   \item [\tt Count]  ({\bf Count of Bits To Enqueue})
-   \item [\tt Offset] ({\bf Offset of Bits To Enqueue})
+   \item [\tt Count]       ({\bf Count of Bits To Dequeue})
+   \item [\tt Offset]      ({\bf Offset of Bits To Dequeue})
 \end{itemize}
 
 
@@ -308,6 +308,22 @@ private static final int MAXBITS = 128;
 private static final int WORDSIZE = 37;
 private BitStorage bits = new BitStorage(MAXBITS);
 
+// dummy routine used for Alu3 test -- FIXME later but keep this functionality somehow!
+public void service() {
+  if (!box_outDequeue.readyForDataFromShip() && !box_inEnqueue.dataReadyForShip()) return;
+  if (box_inEnqueue.dataReadyForShip() && bits.hasSpace(WORDSIZE)) {
+    long data = box_inEnqueue.removeDataForShip();
+    bits.add(data, WORDSIZE);
+    return;
+  }
+  if (box_outDequeue.readyForDataFromShip() && bits.size() > 0) {
+    long data = bits.get(1) == 0 ? 0L : 0x1FFFFFFFFFL;
+    box_outDequeue.addDataFromShip(data);
+    return;
+  }
+}
+
+/*
 public void service() {
   if (!box_outDequeue.readyForDataFromShip() && !box_inEnqueue.dataReadyForShip()) return;
   if (box_inEnqueue.dataReadyForShip() && bits.hasSpace(WORDSIZE)) {
@@ -344,10 +360,81 @@ public void service() {
     return;
   }
 }
+*/
 
 == FleetSim ==============================================================
 
 == FPGA ==============================================================
+  reg [73:0] bitstorage;
+  reg [7:0] bitstorage_count;          initial bitstorage_count = 0;
+
+  always @(posedge clk) begin
+    if (bitstorage == 0) begin
+      `onread(inEnqueue_r, inEnqueue_a)
+        bitstorage       <= inEnqueue_d;
+        bitstorage_count <= 37;
+        outDequeue_d     <= inEnqueue_d[0] ? 1'b1111111111111111111111111111111111111 : 0;
+      end
+    end else begin
+      `onwrite(outDequeue_r, outDequeue_a)
+        bitstorage_count <= bitstorage_count - 1;
+        outDequeue_d     <= bitstorage[1] ? 1'b1111111111111111111111111111111111111 : 0;
+        bitstorage       <= bitstorage >> 1;
+      end
+    end
+  end
+
+
+== Test ==============================================================
+
+// expected output
+#expect 137438953471
+#expect 137438953471
+#expect 0
+#expect 0
+#expect 0
+#expect 137438953471
+#expect 137438953471
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+#expect 0
+
+// ships required in order to run this code
+#ship debug        : Debug
+#ship bitfifo      : BitFifo
+
+debug.in:           [*] take, deliver;
+99:                 sendto bitfifo.inEnqueue;
+bitfifo.inEnqueue:  take, deliver;
+bitfifo.outDequeue: [*] take, sendto debug.in;
 
 == Contributors =========================================================
 Amir Kamil <kamil@cs.berkeley.edu>
+Adam Megacz <megacz@cs.berkeley.edu>