more bugfixes to Alu3
authoradam <adam@megacz.com>
Sat, 11 Aug 2007 02:30:28 +0000 (03:30 +0100)
committeradam <adam@megacz.com>
Sat, 11 Aug 2007 02:30:28 +0000 (03:30 +0100)
ships/Alu3.ship

index a2cd62d..897a44c 100644 (file)
@@ -20,6 +20,11 @@ data  out:  outBits
 boolean mode = false;
 BitFifo.BitStorage outBits = new BitFifo.BitStorage(74);
 public void service() {
+  if (outBits.size() >= 37) {
+    if (box_outBits.readyForDataFromShip()) {
+        box_outBits.addDataFromShip(outBits.get(37));
+    }
+  } else
   if (box_in1.dataReadyForShip() &&
       box_in2.dataReadyForShip() &&
       box_in3.dataReadyForShip() &&
@@ -31,26 +36,13 @@ public void service() {
       long v2 = box_in2.removeDataForShip();
       long v3 = box_in3.removeDataForShip();
       long o1, o2, o3;
-      mode = true;
-      if (!mode) {
-        o1 = v1;
-        o2 = v2 >>> 1;
-        o3 = ((v2 & 0x1L) == 0) ? 0 : v1;
-      } else {
-        o1 = ((v1 & v2) | (v2 & v3) | (v1 & v3))/* << 1*/;
-        o2 = (v1 ^ v2 ^ v3) >> 1;
-        o3 = 0;
-        outBits.add((v1 ^ v2 ^ v3) & 0x1L, 1);
-      }
+      o1 = ((v1 & v2) | (v2 & v3) | (v1 & v3))/* << 1*/;
+      o2 = (v1 ^ v2 ^ v3) >> 1;
+      o3 = 0;
+      outBits.add((v1 ^ v2 ^ v3) & 0x1L, 1);
       box_out1.addDataFromShip(o1);
       box_out2.addDataFromShip(o2);
       box_out3.addDataFromShip(o3);
-      mode = !mode;
-  }
-
-  if (box_outBits.readyForDataFromShip() &&
-      outBits.size() >= 37) {
-      box_outBits.addDataFromShip(outBits.get(37));
   }
 }
 
@@ -68,7 +60,7 @@ public void service() {
   reg                    have_out1;    initial have_out1 = 0;
   reg                    have_out2;    initial have_out2 = 0;
   reg                    have_out3;    initial have_out3 = 0;
-  reg [73:0] bitstorage;
+  reg [73:0] bitstorage; initial bitstorage = 0;
   reg [7:0] bitstorage_count;          initial bitstorage_count = 0;
   reg wrote;                           initial wrote = 0;
 
@@ -86,38 +78,29 @@ public void service() {
       `onread(in2_r, in2_a) have_in2 <= 1; keep_in2 <= in2_d; end
     end else if (!have_in3) begin
       `onread(in3_r, in3_a) have_in3 <= 1; keep_in3 <= in3_d; end
+    end else if (bitstorage_count >= `DATAWIDTH) begin
+      outBits_d  = bitstorage[(`DATAWIDTH-1):0];
+      `onwrite(outBits_r, outBits_a)
+        bitstorage_count <= 0;
+      end
     end else begin
-        mode = 1;
-        if (mode == 0) begin
-          out1_d    <= keep_in1;
-          out2_d    <= { 1'b0, keep_in2[(`DATAWIDTH-1):1] };
-          out3_d    <= (keep_in2[0]==0) ? 0 : keep_in1;
-        end else begin
           out1_d           <= { ((keep_in1 & keep_in2) | (keep_in2 & keep_in3) | (keep_in1 & keep_in3)) };
-          out2_d                       <= (keep_in1 ^ keep_in2 ^ keep_in3) >> 1;
+          out2_d                       <= { 1'b0, (keep_in1[(`DATAWIDTH-1):1] ^
+                                                   keep_in2[(`DATAWIDTH-1):1] ^
+                                                   keep_in3[(`DATAWIDTH-1):1]) };
           out3_d                       <= 0;
+          bitstorage[bitstorage_count]  = (keep_in1[0] ^ keep_in2[0] ^ keep_in3[0]);
           bitstorage_count             <= bitstorage_count+1;
-          bitstorage[bitstorage_count] = (keep_in1[0] ^ keep_in2[0] ^ keep_in3[0]);
-          outBits_d                    = bitstorage[(`DATAWIDTH-1):0];
-          wrote = 1;
-        end
         have_out1 <= 1;
         have_out2 <= 1;
         have_out3 <= 1;
         have_in1  <= 0;
         have_in2  <= 0;
         have_in3  <= 0;
-//        mode <= ~mode;
     end
 
-    if (!wrote && bitstorage_count >= `DATAWIDTH) begin
-      `onwrite(outBits_r, outBits_a) begin
-        bitstorage_count <= bitstorage_count - `DATAWIDTH;
-        bitstorage       = bitstorage >> `DATAWIDTH;
-      end
-    end    
   end
-end
+
 
 
 == Test ========================================================================
@@ -130,39 +113,17 @@ end
 #expect 31509911677
 #expect 1855678
 
-//#expect 1855683
-//#expect 1855683
-//#expect 1855683
-//#expect 1855683
-//#expect 1855683
-//#expect 1855683
-//#expect 1200000
-//#expect 1855683
-//#expect 1855683
-//#expect 1200000
-//#expect 1855683
-//#expect 1855683
-//#expect 1855683
-//#expect 1855683
-//#expect 1200000
-//#expect 1855683
-//#expect 1200000
-//#expect 1200000
-//#expect 1200000
-//#expect 1200000
-//#expect 1855683
-
 // 0:  100100100111110000000
 // sel 011110100001001000000
 // 1:  111000101000011000011
 // r:  111000100110111000000
 
-
 1000000:            sendto bitfifo.inEnqueue;
 0:                  sendto bitfifo.inEnqueue;
 bitfifo.inEnqueue:  [*] take, deliver;
-bitfifo.outDequeue: [*] take, sendto lut3.in2;
-lut3.in2:           [74] take, deliver;
+bitfifo.outDequeue: [*] wait, take, sendto lut3.in2;
+lut3.in2:           notify bitfifo.outDequeue;
+                    [74] take, deliver, notify bitfifo.outDequeue;
 
 // mux on second input
 226:                sendto lut3.inLut;
@@ -185,7 +146,6 @@ lut3.in3:           take;
 
 lut3.out:           [*] take, sendto alu3.in2;
 
-
 0:             sendto alu3.in3;
 0:             sendto alu3.in1;
 alu3.in1:      [*] take, deliver;
@@ -194,10 +154,10 @@ alu3.in3:      [*] take, deliver;
 alu3.out1:     [74] take, sendto alu3.in1;
 alu3.out2:     [74] take, sendto alu3.in3;
 alu3.out3:     [74] take;
-alu3.outBits:  [2] take, sendto debug.in;
+alu3.outBits:  [*] take, sendto debug.in;
 
 
-debug.in:           [*] take, deliver;
+debug.in:      [*] take, deliver;
 
 
 == Contributors =========================================================