3 == Ports ===========================================================
21 == TeX ==============================================================
23 {\tt Alu} is a ``two-input'' arithmetic logic unit. It includes
24 logic for performing arithmetic operations on a pair of arguments.
25 Currently this includes
27 subtraction ({\sc sub}),
28 maximum ({\sc max}), and
31 \subsection*{Semantics}
33 When a value is present at each of {\tt in1}, {\tt in2} and {\tt
34 inOp}, these three values are consumed. Based on the value consumed
35 at {\tt inOp}, the requested operation is performed on the values
36 consumed from {\tt in1} and {\tt in2}. The result of this operation
37 is then made available at {\tt out}.
42 IN1 - undefined; drain in1 only
43 IN2 - undefined; drain in2 only
46 MAX - if in1>in2 cflag=0 and drain in1, else cflag=1 and drain in2
47 MIN - if in1>in2 cflag=1 and drain in2, else cflag=0 and drain in1
48 CMP - if in1==in2 cflag=1, else cflag=0
49 DROP1 - consume in1, produce no output
50 DROP2 - consume in2, produce no output
51 MAXMERGE - if (in1<0 && in2<0) consume both, emit either, cflag=undef else act as MAX
56 The {\it link bit} and other features of \cite{ies31} are not yet
59 The carry-in, carry-out, zero-test, negative-test, and overflow-test
60 flags typically present in a conventional processor ALU are also not
63 == Fleeterpreter ====================================================
64 public void service() {
65 if (box_inOp.dataReadyForShip() &&
66 box_in1.dataReadyForShip() &&
67 box_in2.dataReadyForShip() &&
68 box_out.readyForDataFromShip()) {
71 long op = box_inOp.removeDataForShip();
74 a = box_in1.removeDataForShip();
75 box_out.addDataFromShip(a); // IN1
78 b = box_in2.removeDataForShip();
79 box_out.addDataFromShip(b); // IN2
82 a = box_in1.removeDataForShip();
83 b = box_in2.removeDataForShip();
84 box_out.addDataFromShip(a+b); // ADD
87 a = box_in1.removeDataForShip();
88 b = box_in2.removeDataForShip();
89 box_out.addDataFromShip(a-b); // SUB
92 a = box_in1.peekDataForShip();
93 b = box_in2.peekDataForShip();
94 box_out.addDataFromShip(Math.max(a,b)); // MAX
95 box_out.flag_c = !(a>b);
96 if (a<b) box_in1.removeDataForShip(); else box_in2.removeDataForShip();
99 a = box_in1.peekDataForShip();
100 b = box_in2.peekDataForShip();
101 box_out.addDataFromShip(Math.min(a,b)); // MIN
102 box_out.flag_c = a>b;
103 if (a>b) box_in1.removeDataForShip(); else box_in2.removeDataForShip();
106 a = box_in1.removeDataForShip();
107 b = box_in2.removeDataForShip();
108 box_out.addDataFromShip(0); // CMP
109 box_out.flag_c = a==b;
112 a = box_in1.removeDataForShip();
113 b = box_in2.removeDataForShip();
114 box_out.addDataFromShip(0);
120 == FleetSim ==============================================================
122 == FPGA ==============================================================
124 wire [`DATAWIDTH:0] sum;
126 wire [(`DATAWIDTH-1):0] in2_inverted;
128 wire [(`DATAWIDTH-1):0] res;
133 assign isplus = inOp_d[2:0]==2;
134 assign cin = isplus ? 0 : 1;
135 assign in2_inverted = isplus ? in2_d : ~in2_d;
136 assign sum = {in1_d,cin} + {in2_inverted,cin};
137 assign res = sum[`DATAWIDTH:1];
138 assign greater = !res[`DATAWIDTH-1];
139 assign both_negative = in1_d[`DATAWIDTH-1] && in2_d[`DATAWIDTH-1];
140 assign eq = in1_d == in2_d;
141 assign cout = sum[`DATAWIDTH];
143 assign out_d_[`DATAWIDTH] =
148 (inOp_d==4) ? ~greater :
149 (inOp_d==5) ? greater :
151 (inOp_d==9) ? ~greater :
154 assign out_d_[(`DATAWIDTH-1):0] =
155 (inOp_d==0) ? (in1_d) :
156 (inOp_d==1) ? (in2_d) :
157 (inOp_d==2) ? (res) :
158 (inOp_d==3) ? (res) :
159 (inOp_d==4) ? (greater ? in1_d : in2_d) :
160 (inOp_d==5) ? (greater ? in2_d : in1_d) :
161 (inOp_d==6) ? {{ (`DATAWIDTH-1) {1'b0 }}, eq } :
162 (inOp_d==9) ? (both_negative ? in1_d : (greater ? in1_d : in2_d)) :
165 always @(posedge clk) begin
170 if (!in1_r_ && in1_a) in1_a <= 0;
171 if (!in2_r_ && in2_a) in2_a <= 0;
172 if (!inOp_r_ && inOp_a) inOp_a <= 0;
173 if (out_r && out_a) begin
177 if (inOp_d==0) in1_a <= 1;
178 else if (inOp_d==1) in2_a <= 1;
179 else if (inOp_d==9 && both_negative) begin in1_a <= 1; in2_a <= 1; end
180 else if (inOp_d==4 && greater) in1_a <= 1;
181 else if (inOp_d==5 && greater) in2_a <= 1;
182 else if (inOp_d==9 && greater) in1_a <= 1;
183 else if (inOp_d==4 && !greater) in2_a <= 1;
184 else if (inOp_d==5 && !greater) in1_a <= 1;
185 else if (inOp_d==9 && !greater) in2_a <= 1;
191 if (!out_r && !out_a && in1_r && !in1_a && in2_r && !in2_a && inOp_r && !inOp_a) begin
197 == Test ==============================================================================
199 // FIXME: need test for ADD carry-out c-flag
215 debug.in: set ilc=*; recv, deliver;
232 collect, send to debug.in;
234 set word= Alu.inOp[ADD]; deliver;
235 set word= Alu.inOp[SUB]; deliver;
236 set word= Alu.inOp[IN1]; deliver;
237 set word= Alu.inOp[IN2]; deliver;
238 set word= Alu.inOp[MIN]; deliver;
239 set word= Alu.inOp[MAX]; deliver;
240 set word= Alu.inOp[CMP]; deliver;
241 set word= Alu.inOp[CMP]; deliver;
244 collect, send to debug.in; // MIN
250 collect, send to debug.in; // MAX
268 == Contributors =========================================================
269 Adam Megacz <megacz@cs.berkeley.edu>