add Alu3 ship and tests
authoradam <adam@megacz.com>
Sun, 25 Feb 2007 04:39:07 +0000 (05:39 +0100)
committeradam <adam@megacz.com>
Sun, 25 Feb 2007 04:39:07 +0000 (05:39 +0100)
ships/Alu2.ship
ships/Alu3.ship [new file with mode: 0644]
src/edu/berkeley/fleet/slipway/Slipway.java
tests/alu3/alu3-simple-test.fleet [new file with mode: 0644]

index 5fd3e91..ae0a019 100644 (file)
@@ -22,8 +22,6 @@ FIXME: implement all the link bit stuff
 
 Use carry-in bit to create a selector?  Perhaps a waste of an ALU.
 
-Carry-save / carry completion stuff.
-
 Flags: zero, negative, overflow, ?
 
 move elsewhere:
diff --git a/ships/Alu3.ship b/ships/Alu3.ship
new file mode 100644 (file)
index 0000000..f88fbb8
--- /dev/null
@@ -0,0 +1,82 @@
+ship: Alu3
+
+== Ports ===========================================================
+data  in:   in1
+data  in:   in2
+data  in:   in3
+
+data  out:  out1
+data  out:  out2
+
+== Constants ========================================================
+== TeX ==============================================================
+
+This ship performs addition of three inputs, producing two output
+values in carry-save form.  To complete the addition, send the two
+output values to an Alu2 with opcode ADD.  For summing a set of four
+or more numbers, Alu3 followed by Alu2 is often faster than repeated
+use of Alu2.
+
+== Fleeterpreter ====================================================
+public void service() {
+  if (box_in1.dataReadyForShip() &&
+      box_in2.dataReadyForShip() &&
+      box_in3.dataReadyForShip() &&
+      box_out1.readyForDataFromShip() &&
+      box_out2.readyForDataFromShip()) {
+      long v1     = box_in1.removeDataForShip();
+      long v2     = box_in2.removeDataForShip();
+      long v3     = box_in3.removeDataForShip();
+      long o1     = ((v1 & v2) | (v2 & v3) | (v1 & v3)) << 1;
+      long o2     = v1 ^ v2 ^ v3;
+      box_out1.addDataFromShip(o1);
+      box_out2.addDataFromShip(o2);
+  }
+}
+
+== FleetSim ==============================================================
+
+== FPGA ==============================================================
+
+  reg                    have_a;
+  reg [(`DATAWIDTH-1):0] a;
+  reg                    have_b;
+  reg [(`DATAWIDTH-1):0] b;
+  reg                    have_c;
+  reg [(`DATAWIDTH-1):0] c;
+  reg                    have_out1;
+  reg                    have_out2;
+
+  always @(posedge clk) begin
+    if (have_out1) begin
+      `onwrite(out1_r, out1_a) have_out1 <= 0; end
+    end
+    if (have_out2) begin
+      `onwrite(out2_r, out2_a) have_out2 <= 0; end
+    end
+
+    if (!have_out1 && !have_out2) begin
+      if (!have_a) begin
+        `onread(in1_r, in1_a) have_a <= 1; a <= in1_d; end
+        end
+      if (!have_b) begin
+        `onread(in2_r, in2_a) have_b <= 1; b <= in2_d; end
+        end
+      if (!have_c) begin
+        `onread(in3_r, in3_a) have_c <= 1; c <= in3_d; end
+        end
+  
+      if (have_a && have_b && have_c) begin
+        out1_d    <= ((a & b) | (b & c) | (a & c)) << 1;
+        out2_d    <= a ^ b ^ c;
+        have_out1 <= 1;
+        have_out2 <= 1;
+      end
+    end
+  end
+
+
+
+
+== Contributors =========================================================
+Adam Megacz <megacz@cs.berkeley.edu>
index 9fdefaf..cb833d1 100644 (file)
@@ -42,6 +42,7 @@ public class Slipway extends Fleet {
         createShip("Memory",    "Memory");
         createShip("Lut3",      "lut3");
         createShip("Alu1",      "alu1");
+        createShip("Alu3",      "alu3");
         createShip("Choice",    "Choice");
         createShip("Choice",    "Choice");
         createShip("Choice",    "Choice");
@@ -327,7 +328,7 @@ public class Slipway extends Fleet {
             FileOutputStream out = new FileOutputStream(outf);
             PrintWriter pw = new PrintWriter(out);
 
-            boolean auto = filename.equals("alu2") || filename.equals("alu1") || filename.equals("lut3") || filename.equals("choice");
+            boolean auto = filename.equals("alu2") || filename.equals("alu1") || filename.equals("lut3") || filename.equals("choice") || filename.equals("alu3") || filename.equals("stack");
             if (auto) {
                 pw.println("`include \"macros.v\"");
                 pw.println();
diff --git a/tests/alu3/alu3-simple-test.fleet b/tests/alu3/alu3-simple-test.fleet
new file mode 100644 (file)
index 0000000..198fa9b
--- /dev/null
@@ -0,0 +1,28 @@
+#expect 25
+
+#ship alu3 : Alu3
+#ship alu2 : Alu2
+#ship debug : Debug
+
+12: sendto alu3.in1;
+4:  sendto alu3.in2;
+9:  sendto alu3.in3;
+
+
+alu3.in1:  [*] take, deliver;
+alu3.in2:  [*] take, deliver;
+alu3.in3:  [*] take, deliver;
+
+alu2.in1: [*] take, deliver;
+alu2.in2: [*] take, deliver;
+alu2.inOp: [*] take, deliver;
+
+alu3.out1: take, sendto alu2.in1;
+alu3.out2: take, sendto alu2.in2;
+Alu2.ADD:  sendto alu2.inOp;
+
+alu2.out: take, sendto debug.in;
+
+debug.in: [*] take, deliver;
+
+