forked from Fernsicles/RV32-verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathALU.sv
30 lines (29 loc) · 734 Bytes
/
ALU.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module ALU(
input logic [2:0] i_op,
input logic i_op2,
input logic [31:0] i_x,
input logic [31:0] i_y,
output wire [31:0] o_result,
output wire o_zero
);
always_comb begin
case(i_op)
3'b000: case(i_op2)
1'b0: o_result = i_x + i_y;
1'b1: o_result = i_x - i_y;
endcase
3'b001: o_result = i_x << i_y;
3'b010: o_result = {31'b0, $signed(i_x) < $signed(i_y)};
3'b011: o_result = {31'b0, $unsigned(i_x) < $unsigned(i_y)};
3'b100: o_result = i_x ^ i_y;
3'b101: case(i_op2)
1'b0: o_result = i_x >> i_y;
1'b1: o_result = $signed(i_x) >>> i_y;
endcase
3'b110: o_result = i_x | i_y;
3'b111: o_result = i_x & i_y;
default: o_result = 0;
endcase
o_zero = ~(|o_result);
end
endmodule