Counter ship: set c-flag to true if this is the last action of a given count
authormegacz <adam@megacz.com>
Mon, 6 Apr 2009 18:46:58 +0000 (11:46 -0700)
committermegacz <adam@megacz.com>
Mon, 6 Apr 2009 18:46:58 +0000 (11:46 -0700)
ships/Counter.ship

index 06a87ce..803105d 100644 (file)
@@ -50,14 +50,14 @@ public void service() {
 
     } else if (box_out.readyForDataFromShip()) {
       if (op_count) {
-        box_out.addDataFromShip(temp);
+        box_out.addDataFromShip(temp, (temp - box_in2.peekDataForShip()) < 0);
         temp = temp - box_in2.peekDataForShip();
       } else if (op_v1 && box_in1.dataReadyForShip()) {
         if (op_drop) { box_in1.removeDataForShip(); temp--; }
-        else         { box_out.addDataFromShip(op_pass ? box_in1.removeDataForShip() : box_in1.peekDataForShip()); temp--; }
+        else         { box_out.addDataFromShip(op_pass ? box_in1.removeDataForShip() : box_in1.peekDataForShip(), temp<=0); temp--; }
       } else if (op_v2 && box_in2.dataReadyForShip()) {
         if (op_drop) { box_in2.removeDataForShip(); temp--; }
-        else         { box_out.addDataFromShip(op_pass ? box_in2.removeDataForShip() : box_in2.peekDataForShip()); temp--; }
+        else         { box_out.addDataFromShip(op_pass ? box_in2.removeDataForShip() : box_in2.peekDataForShip(), temp<=0); temp--; }
       }
       
     }
@@ -97,6 +97,7 @@ public void service() {
   reg     out_draining;
   reg     full;
   initial full = 0;
+  reg c_flag;
   wire    op_count;  assign op_count  = inOp_d_trunc==12;
   wire    op_repeat; assign op_repeat = inOp_d[3:2]==0;
   wire    op_pass;   assign op_pass   = inOp_d[3:2]==1;
@@ -105,20 +106,27 @@ public void service() {
   wire    op_c2;     assign op_c2     = (op_repeat || op_pass || op_drop) &&  inOp_d[1];
   wire    op_v1;     assign op_v1     = (op_repeat || op_pass || op_drop) && !inOp_d[0];
   wire    op_v2;     assign op_v2     = (op_repeat || op_pass || op_drop) &&  inOp_d[0];
-  assign  out_d_ = op_v1 ? in1_d : op_v2 ? in2_d : temp;
+
+  wire [`WORDWIDTH-1:0] pre_out;
+  assign  pre_out = op_v1 ? in1_d : op_v2 ? in2_d : temp;
+  assign  out_d_  = { c_flag, pre_out };
 
   // FIXME: REPEAT with a count of zero will not work properly
 
+  wire [`WORDWIDTH-1:0] temp_minus_in2;
+  assign temp_minus_in2 = (temp - in2_d);
+
   always @(posedge clk) begin
     if (rst) begin
       `reset
       full <= 0;
       out_draining <= 0;
+      c_flag <= 0;
     end else begin
       `cleanup
       if (`inOp_empty)         full   <= 0;
       if (out_draining && `out_empty) begin
-        if (op_count) temp   <= temp - in2_d;
+        if (op_count) temp   <= temp_minus_in2;
         else          temp   <= temp - 1;
         if (op_pass && op_v1) `drain_in1
         if (op_pass && op_v2) `drain_in2
@@ -152,12 +160,15 @@ public void service() {
           if (op_count) begin
             `fill_out
             out_draining <= 1;
+            c_flag <= temp_minus_in2[`WORDWIDTH-1];
           end else if (op_v1 && `in1_full) begin
             if (op_drop)    begin `drain_in1 temp <= temp-1; end
             else            begin `fill_out out_draining <= 1; end
+            c_flag <= (temp==0);
           end else if (op_v2 && `in2_full) begin
             if (op_drop)    begin `drain_in2 temp <= temp-1; end
             else            begin `fill_out out_draining <= 1; end
+            c_flag <= (temp==0);
           end
         end
       end
@@ -172,16 +183,20 @@ public void service() {
 #expect 6
 #expect 3
 #expect 0
+#expect -1
 #expect 2
 #expect 1
 #expect 0
+#expect -1
 #expect 2
 #expect 2
 #expect 2
 #expect 2
+#expect -1
 #expect 9
 #expect 9
 #expect 9
+#expect -1
 
 debug.in:
   set ilc=*;
@@ -216,8 +231,12 @@ counter.inOp:
   deliver;
 
 counter.out:
-  set ilc=*;
+  head;
   collect, send to debug.in;
+  set flags a=c, b=b;
+  set word=-1;
+  [a] send to debug.in;
+  tail;
 
 
 == Contributors =========================================================