fix awful c-flag bug in Memory.ship
[fleet.git] / ships / Alu.ship
index 50fcfee..3b2117f 100644 (file)
@@ -130,7 +130,10 @@ public void service() {
   wire                    eq;
   wire                    cout;
 
-  assign isplus        = inOp_d[2:0]==2;
+  wire [3:0]              inOp_d_trunc;
+  assign                  inOp_d_trunc = inOp_d[3:0];
+
+  assign isplus        = inOp_d_trunc[2:0]==2;
   assign cin           = isplus ? 0 : 1;
   assign in2_inverted  = isplus ? in2_d : ~in2_d;
   assign sum           = {in1_d,cin} + {in2_inverted,cin};
@@ -141,25 +144,25 @@ public void service() {
   assign cout          = sum[`WORDWIDTH];
 
   assign out_d_[`WORDWIDTH] =
-          (inOp_d==0) ? 1'b0 :
-          (inOp_d==1) ? 1'b0 :
-          (inOp_d==2) ? cout :
-          (inOp_d==3) ? cout :
-          (inOp_d==4) ? ~greater :
-          (inOp_d==5) ?  greater :
-          (inOp_d==6) ?  eq :
-          (inOp_d==9) ? ~greater :
+          (inOp_d_trunc==0) ? 1'b0 :
+          (inOp_d_trunc==1) ? 1'b0 :
+          (inOp_d_trunc==2) ? cout :
+          (inOp_d_trunc==3) ? cout :
+          (inOp_d_trunc==4) ? ~greater :
+          (inOp_d_trunc==5) ?  greater :
+          (inOp_d_trunc==6) ?  eq :
+          (inOp_d_trunc==9) ? ~greater :
           0;
 
   assign out_d_[(`WORDWIDTH-1):0] =
-          (inOp_d==0) ? (in1_d)  :
-          (inOp_d==1) ? (in2_d)  :
-          (inOp_d==2) ? (res)  :
-          (inOp_d==3) ? (res)  :
-          (inOp_d==4) ? (greater ? in1_d : in2_d)  :
-          (inOp_d==5) ? (greater ? in2_d : in1_d)  :
-          (inOp_d==6) ? {{ (`WORDWIDTH-1) {1'b0 }}, eq  } :
-          (inOp_d==9) ? (both_negative ? in1_d : (greater ? in1_d : in2_d)) :
+          (inOp_d_trunc==0) ? (in1_d)  :
+          (inOp_d_trunc==1) ? (in2_d)  :
+          (inOp_d_trunc==2) ? (res)  :
+          (inOp_d_trunc==3) ? (res)  :
+          (inOp_d_trunc==4) ? (greater ? in1_d : in2_d)  :
+          (inOp_d_trunc==5) ? (greater ? in2_d : in1_d)  :
+          (inOp_d_trunc==6) ? {{ (`WORDWIDTH-1) {1'b0 }}, eq  } :
+          (inOp_d_trunc==9) ? (both_negative ? in1_d : (greater ? in1_d : in2_d)) :
           0;
 
   always @(posedge clk) begin
@@ -170,15 +173,15 @@ public void service() {
       `cleanup
       if (`out_draining) begin
         `drain_inOp
-        if      (inOp_d==0) `drain_in1
-        else if (inOp_d==1) `drain_in2
-        else if (inOp_d==9 &&  both_negative) begin `drain_in1 `drain_in2 end
-        else if (inOp_d==4 &&  greater) `drain_in1
-        else if (inOp_d==5 &&  greater) `drain_in2
-        else if (inOp_d==9 &&  greater) `drain_in1
-        else if (inOp_d==4 && !greater) `drain_in2
-        else if (inOp_d==5 && !greater) `drain_in1
-        else if (inOp_d==9 && !greater) `drain_in2
+        if      (inOp_d_trunc==0) `drain_in1
+        else if (inOp_d_trunc==1) `drain_in2
+        else if (inOp_d_trunc==9 &&  both_negative) begin `drain_in1 `drain_in2 end
+        else if (inOp_d_trunc==4 &&  greater) `drain_in1
+        else if (inOp_d_trunc==5 &&  greater) `drain_in2
+        else if (inOp_d_trunc==9 &&  greater) `drain_in1
+        else if (inOp_d_trunc==4 && !greater) `drain_in2
+        else if (inOp_d_trunc==5 && !greater) `drain_in1
+        else if (inOp_d_trunc==9 && !greater) `drain_in2
         else begin
           `drain_in1
           `drain_in2