-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathALU.v
More file actions
107 lines (91 loc) · 1.78 KB
/
Copy pathALU.v
File metadata and controls
107 lines (91 loc) · 1.78 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
module ALU(
input [31:0]YMuxOut,
input [31:0]BusMuxOut,
input [4:0]ALUControl,
output wire [63:0]ZMuxIn
);
reg [31:0]A;
reg [31:0]B;
reg [63:0]C;
wire [63:0]boothOutput;
wire [31:0]lookaheadOut;
wire [31:0] Q, R;
integer i, x;
lookaheadadder addSub(A,B,ALUControl[2],lookaheadOut);
BoothAlgorithm mul(A, B, boothOutput);
NonRestoringDivision div(A, B, Q, R);
always @ (*) begin
A = YMuxOut;
B = BusMuxOut;
C = 64'd0;
/*
//add
if (ALUControl == 5'b00011) begin
C = A + B;
end
//sub
else if (ALUControl)
*/
case(ALUControl)
5'b00011 : begin//add
C = lookaheadOut;
end
5'b00100 : begin //sub
C = lookaheadOut;
end
5'b00101 : begin //and
for (i =0; i < 32; i = i+ 1) C[i] = A[i] & B[i];
//C = A & B;
end
5'b00110 : begin //or
for (i =0; i < 32; i = i+ 1) C[i] = A[i] | B[i];
//C = A | B;
end
5'b00111 : begin //shr
C = A >> B;
end
5'b01000 : begin //shra
C = $signed(A) >>> B;
end
5'b01001 : begin //shl
C = A << B;
end
5'b01010 : begin //ror
//C = A >> B;
//C[31] = YMuxOut[0];
/*for (x = 0; x < B; x = x+1)begin
for (i = 0 ; i < 31 ; i = i + 1) begin
C[i] = A[i+1];
end
C[31] = A[0];
end*/
C = (A >> B) | (A << 32-B);
end
5'b01011 : begin //rol
//C = A << B;
//C[0] = YMuxOut[31];
/*for (i = 1 ; i < 32 ; i = i + 1) begin
C[i] = A[i-1];
end
C[0] = A[31];*/
C = (A << B) | (A >> 32-B);
end
5'b01111 : begin //mul
C = boothOutput;
end
5'b10000 : begin //div
C = {R, Q};
end
5'b10001 : begin //negate
for (i =0; i < 32; i = i+ 1) C[i] = ~A[i];
//C = ~A;
C = C + 1;
end
5'b10010 : begin //not
for (i =0; i < 32; i = i+ 1) C[i] = ~A[i];
//C = ~A;
end
endcase
end
assign ZMuxIn = C;
endmodule