3 == Ports ===========================================================
9 == TeX ==============================================================
11 The Carry-Save Adder computes the carry-save sum of three input
12 values, provided sequentially at {\tt in}, and produces.
15 == Fleeterpreter ====================================================
17 public void service() {
18 if (box_in.dataReadyForShip() && box_out.readyForDataFromShip()) {
23 == FPGA ==============================================================
25 reg [(`DATAWIDTH-1):0] temp;
26 reg [(`DATAWIDTH):0] out_d;
29 assign out_d_ = out_d;
31 wire [(`DATAWIDTH-1):0] majority;
32 wire [(`DATAWIDTH-1):0] xors;
35 for(i=0; i<`DATAWIDTH; i=i+1) begin : OUT
36 assign majority[i] = (temp[i] & out_d[i]) | (in_d[i] & out_d[i]) | (temp[i] & in_d[i]);
37 assign xors[i] = temp[i] ^ out_d[i] ^ in_d[i];
41 always @(posedge clk) begin
46 if (!in_r && in_a) in_a <= 0;
47 if (out_r && out_a) out_r <= 0;
48 if (!out_r && !out_a && state==3) begin
49 out_d <= { 1'b0, temp };
52 end else if (in_r && !in_a && !out_r && !out_a) begin
54 out_d <= { 1'b0, in_d };
55 end else if (state == 1) begin
57 end else if (state == 2) begin
58 out_d <= { majority[`DATAWIDTH-1:0], 1'b0 };
68 == Test ==============================================================
76 // ships required in order to run this code
78 #ship csa : CarrySaveAdder
83 set word=1018217; deliver;
84 set word=771820; deliver;
85 set word=2161521; deliver;
87 collect, send to csa.in; send to alu.in1;
88 collect, send to csa.in; send to alu.in2;
89 collect, send to csa.in; send to alu.in2;
91 alu.in1: set ilc=4; recv, deliver;
92 alu.in2: set ilc=4; recv, deliver;
94 set word=Alu.inOp[ADD];
97 collect, send to alu.in1;
98 collect; send to debug.in;
100 collect; send to debug.in;
108 collect, send to debug.in;
110 collect, send to debug.in;
115 send token to csa.out;
118 send token to alu.out;
122 == Contributors =========================================================
123 Adam Megacz <megacz@cs.berkeley.edu>