update Alu3 test to use blend
[fleet.git] / ships / Memory.ship
index dc266c6..b330ecb 100644 (file)
@@ -51,6 +51,11 @@ data  out:   out
         dispatch(base, size);
     }
 
+    private long stride = 0;
+    private long count = 0;
+    private long addr = 0;
+    private boolean writing = false;
+
     public void service() {
         if (box_inCBD.dataReadyForShip()) {
             long val = box_inCBD.removeDataForShip();
@@ -58,7 +63,22 @@ data  out:   out
             long size = val & 0x3f;
             dispatch((int)addr, (int)size);
         }
-        if (box_inAddr.dataReadyForShip() && box_out.readyForDataFromShip()) {
+        if (count > 0 && writing) {
+            if (box_inData.dataReadyForShip() && box_out.readyForDataFromShip()) {
+               writeMem((int)addr, box_inData.removeDataForShip());
+               box_out.addDataFromShip(0);
+               count--;
+               addr += stride;
+            }
+
+        } else if (count > 0 && !writing) {
+            if (box_out.readyForDataFromShip()) {
+               box_out.addDataFromShip(readMem((int)addr));
+               count--;
+               addr += stride;
+            }
+
+        } else if (box_inAddr.dataReadyForShip() && box_out.readyForDataFromShip()) {
             Packet packet = box_inAddr.peekPacketForShip();
             if (packet.destination.getDestinationName().equals("read")) {
                 box_out.addDataFromShip(readMem((int)box_inAddr.removeDataForShip()));
@@ -66,6 +86,20 @@ data  out:   out
                 writeMem((int)box_inAddr.removeDataForShip(),
                          box_inData.removeDataForShip());
                 box_out.addDataFromShip(0);
+            } else if (packet.destination.getDestinationName().equals("writeMany")
+                       && box_inStride.dataReadyForShip()
+                       && box_inCount.dataReadyForShip()) {
+                addr = box_inAddr.removeDataForShip();
+                stride = box_inStride.removeDataForShip();
+                count = box_inCount.removeDataForShip();
+                writing = true;
+            } else if (packet.destination.getDestinationName().equals("readMany")
+                       && box_inStride.dataReadyForShip()
+                       && box_inCount.dataReadyForShip()) {
+                addr = box_inAddr.removeDataForShip();
+                stride = box_inStride.removeDataForShip();
+                count = box_inCount.removeDataForShip();
+                writing = false;
             }
         }
     }
@@ -261,10 +295,41 @@ endmodule
 
 
 
+== Test ==============================================================
+// expected output
+#expect 12
+#expect 13
+#expect 14
+
+// ships required in order to run this code
+#ship debug          : Debug
+#ship memory         : Memory
+
+// instructions not in any codebag are part of the "root codebag"
+// which is dispatched when the code is loaded
+
+BOB:              sendto memory.inCBD;
+memory.inCBD:     [*] take, deliver;
+debug.in:         [*] take, deliver;
+
+
+// This codebag illustrates how to do a loop.  Notice that this
+// is actually an uncontrolled data emitter -- it could clog the
+//  switch fabric!
+
+BOB: {
+  12:           sendto debug.in;
+  13:           sendto debug.in;
+  14:           sendto debug.in;
+}
 
 
 == Constants ========================================================
 == TeX ==============================================================
+\begin{verbatim}
+TODO: count/stride
+TODO: multiple interfaces to a single memory
+\end{verbatim}
 
 == Contributors =========================================================
 Adam Megacz <megacz@cs.berkeley.edu>