add `reset` to Alu2
[fleet.git] / ships / Alu1.ship
index 4ef057a..1ac349d 100644 (file)
@@ -3,19 +3,30 @@ ship: Alu1
 == Ports ===========================================================
 data  in:   in
 data  in:   inOp
-data  in:   inOp.x
-data  in:   inOp.y
-data  in:   inOp.z
+  constant NEG: 0
+  constant INC: 1
+  constant DEC: 2
+  constant ABS: 3
 
 data  out:  out
 
-== Constants ========================================================
-NEG:
-INC:
-DEC:
-ABS:
-
 == TeX ==============================================================
+
+{\tt Alu1} is a ``one-input'' arithmetic logic unit.  It includes
+logic for performing arithmetic operations on a single argument.
+Currently this includes
+negate ({\sc neg}),
+increment ({\sc inc}),
+decrement ({\sc dec}), and
+absolute value ({\sc abs}).
+
+\subsection*{Semantics}
+
+When a value is present at each of {\tt in} and {\tt inOp}, these two
+values are consumed.  Based on the value consumed at {\tt inOp}, the
+requested operation is performed on the value consumed from {\tt in}.
+The result of this operation is then made available at {\tt out}.
+
 == Fleeterpreter ====================================================
     public void service() {
         if (box_in.dataReadyForShip() && box_inOp.dataReadyForShip() && box_out.readyForDataFromShip()) {
@@ -45,6 +56,11 @@ ABS:
   reg [(`PACKET_WIDTH-1):0] extrabits;
 
   always @(posedge clk) begin
+    if (!rst) begin
+      have_a = 0;
+      have_op = 0;
+      `reset
+    end else begin
     if (!have_a) begin
       `onread(in_r, in_a) have_a = 1; reg_a = in_d; end
       end
@@ -71,10 +87,12 @@ ABS:
         have_op = 0;
       end
     end
+    end
   end
 
 == Test ==============================================================================
 // expected output
+
 #expect 10
 #expect 8
 #expect 9
@@ -85,25 +103,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;
-
-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.in:
+  literal 9;
+  load repeat counter with 4; deliver;
+  take, deliver;
+
 alu1.out:
-  [3] take, sendto debug.in;
-  take;
-  sendto debug.in;
+  load repeat counter with 4; take, sendto debug.in;
   sendto alu1.in;
-  [*] take, sendto debug.in;
+  take, sendto debug.in;
+
+alu1.inOp:
+   literal 1; deliver;
+   literal 2; deliver;
+   literal 3; deliver;
+   literal 0; deliver;
+   literal 0; deliver;
 
 
 == Contributors =========================================================