-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_unit.v
More file actions
33 lines (31 loc) · 1.07 KB
/
Copy pathfunction_unit.v
File metadata and controls
33 lines (31 loc) · 1.07 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
module function_unit (
input [31:0] A, B,
input [4:0] FS, SH,
output reg C, V,
output Z, N,
output reg [31:0] F
);
assign Z = ~|F;
assign N = F[31];
always @(*) begin
case (FS)
5'b00000: {C, F} = A;
5'b00001: {C, F} = A + 1;
5'b00010: {C, F} = A + B;
5'b00011: {C, F} = A + B + 1;
5'b00100: {C, F} = A + (~B);
5'b00101: {C, F} = A - B;
5'b00110: {C, F} = A - 1;
5'b00111: {C, F} = A;
5'b01000: {C, F} = A & B;
5'b01010: {C, F} = A | B;
5'b01100: {C, F} = A ^ B;
5'b01110: {C, F} = ~A;
5'b10000: {C, F} = A << SH;
5'b10001: {C, F} = A >> SH;
default: {C, F} = 0;
endcase
V = ( (FS == 5'b00001 | FS == 5'b00010 ) & ( (~A[31] & ~B[31] & F[31]) | (A[31] & B[31] & ~F[31])) ) | // For addition and inc
( (FS == 5'b00101 | FS == 5'b00110 ) & ( (~A[31] & B[31] & F[31]) | (A[31] & ~B[31] & ~F[31])) ) ; // For subtraction and dec
end
endmodule