add AND, OR, XOR opcodes to Alu.ship
authormegacz <adam@megacz.com>
Mon, 6 Apr 2009 18:44:34 +0000 (11:44 -0700)
committermegacz <adam@megacz.com>
Mon, 6 Apr 2009 18:44:34 +0000 (11:44 -0700)
ships/Alu.ship

index 2588447..ddd3a4e 100644 (file)
@@ -14,6 +14,9 @@ data  in:   inOp
   constant DROP1: 7
   constant DROP2: 8
   constant MAXMERGE: 9
+  constant AND: 10
+  constant OR: 11
+  constant XOR: 12
 
 data  out:  out
 
@@ -123,6 +126,21 @@ public void service() {
               box_in2.removeDataForShip();      // DROP2
               break;
 */
+          case 10:
+              a = box_in1.removeDataForShip();
+              b = box_in2.removeDataForShip();
+              box_out.addDataFromShip(a & b); // CMP
+              break;
+          case 11:
+              a = box_in1.removeDataForShip();
+              b = box_in2.removeDataForShip();
+              box_out.addDataFromShip(a | b); // CMP
+              break;
+          case 12:
+              a = box_in1.removeDataForShip();
+              b = box_in2.removeDataForShip();
+              box_out.addDataFromShip(a ^ b); // CMP
+              break;
           default:
               throw new RuntimeException("invalid opcode: " + op);
       }
@@ -142,10 +160,10 @@ public void service() {
   wire                    eq;
   wire                    cout;
 
-  wire [3:0]              inOp_d_trunc;
-  assign                  inOp_d_trunc = inOp_d[3:0];
+  wire [4:0]              inOp_d_trunc;
+  assign                  inOp_d_trunc = inOp_d[4:0];
 
-  assign isplus        = inOp_d_trunc[2:0]==2;
+  assign isplus        = inOp_d_trunc[4:0]==2;
   assign cin           = isplus ? 0 : 1;
   assign in2_inverted  = isplus ? in2_d : ~in2_d;
   assign sum           = {in1_d,cin} + {in2_inverted,cin};
@@ -177,6 +195,9 @@ public void service() {
           (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)) :
+          (inOp_d_trunc==10) ? (in1_d & in2_d) :
+          (inOp_d_trunc==11) ? (in1_d | in2_d) :
+          (inOp_d_trunc==12) ? (in1_d ^ in2_d) :
           0;
 
   always @(posedge clk) begin