--- /dev/null
+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>
createShip("Memory", "Memory");
createShip("Lut3", "lut3");
createShip("Alu1", "alu1");
+ createShip("Alu3", "alu3");
createShip("Choice", "Choice");
createShip("Choice", "Choice");
createShip("Choice", "Choice");
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();
--- /dev/null
+#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;
+
+