-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalu.sv
More file actions
49 lines (30 loc) · 1.19 KB
/
Copy pathalu.sv
File metadata and controls
49 lines (30 loc) · 1.19 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
`include "def.sv"
module alu #(
parameter DATA_WIDTH = 32
)(
input logic [DATA_WIDTH-1:0] ALUop1,
input logic [DATA_WIDTH-1:0] ALUop2,
input logic [3:0] ALUctrl,
output logic [DATA_WIDTH-1:0] ALUout,
output logic branch_l
);
always_comb begin
case (ALUctrl)
`ALU_OPCODE_ADD: ALUout = ALUop1 + ALUop2;
`ALU_OPCODE_SUB: ALUout = ALUop1 - ALUop2;
`ALU_OPCODE_AND: ALUout = ALUop1 & ALUop2;
`ALU_OPCODE_OR: ALUout = ALUop1 | ALUop2;
`ALU_OPCODE_XOR: ALUout = ALUop1 ^ ALUop2;
`ALU_OPCODE_SLT: ALUout = ($signed(ALUop1) < $signed(ALUop2)) ? 1 : 0;
// Shift operations:
`ALU_OPCODE_LUI: ALUout = ALUop2;
`ALU_OPCODE_SLL: ALUout = ALUop1 << ALUop2;
`ALU_OPCODE_SRL: ALUout = ALUop1 >> ALUop2;
`ALU_OPCODE_SRA: ALUout = ALUop1 >>> ALUop2;
// Branch instructions:
//`ALU_OPCODE_BLTU: branch_l = (ALUop1 < ALUop2);
default: ALUout = 0;
endcase
branch_l = (ALUout == 0) ? 1 : 0;
end
endmodule