-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathALU.v
79 lines (78 loc) · 1.83 KB
/
ALU.v
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
`timescale 1ns / 1ps
`include "miriscv_defines.v"
module ALU(
input [31:0] A,
input [31:0] B,
input [4:0] ALUOp,
output reg [31:0] Result,
output reg Flag
);
always @(*) begin
case(ALUOp)
`ALU_ADD: begin
Result <= A + B;
Flag <= 0;
end
`ALU_SUB: begin
Result <= A + ~B + 1;
Flag <= 0;
end
`ALU_SLL: begin
Result <= A << B;
Flag <= 0;
end
`ALU_SLTS: begin
Result <= $signed(A) < $signed(B);
Flag <= 0;
end
`ALU_SLTU: begin
Result <= (A < B);
Flag <= 0;
end
`ALU_XOR: begin
Result <= A ^ B;
Flag <= 0;
end
`ALU_SRL: begin
Result <= A >> B;
Flag <= 0;
end
`ALU_SRA: begin
Result <= $signed(A) >>> $signed (B);
Flag <= 0;
end
`ALU_OR: begin
Result <= A | B;
Flag <= 0;
end
`ALU_AND: begin
Result <= A & B;
Flag <= 0;
end
`ALU_EQ: begin
Result <= A == B;
Flag <= A == B;
end
`ALU_NE: begin
Result <= A != B;
Flag <= A != B;
end
`ALU_LTS: begin
Result <= ($signed(A) < $signed(B));
Flag <= ($signed(A) < $signed(B));
end
`ALU_GES: begin
Result <= ($signed(A) >= $signed(B));
Flag <= ($signed(A) >= $signed(B));
end
`ALU_LTU: begin
Result <= (A < B);
Flag <= (A < B);
end
`ALU_GEU: begin
Result <= (A >= B);
Flag <= (A >= B);
end
endcase // case (sel)
end
endmodule // ALU