1 |
3 |
m99 |
//Carry look-ahead adder
|
2 |
|
|
|
3 |
|
|
module operator_A(
|
4 |
|
|
input A,
|
5 |
|
|
input B,
|
6 |
|
|
output P,
|
7 |
|
|
output G
|
8 |
|
|
);
|
9 |
|
|
|
10 |
|
|
assign P=A^B;
|
11 |
|
|
assign G=A&B;
|
12 |
|
|
|
13 |
|
|
endmodule
|
14 |
|
|
|
15 |
|
|
module operator_B(
|
16 |
|
|
input P,G,P1,G1,
|
17 |
|
|
output Po,Go
|
18 |
|
|
);
|
19 |
|
|
|
20 |
|
|
assign Po=P&P1;
|
21 |
|
|
assign Go=G|(P&G1);
|
22 |
|
|
|
23 |
|
|
endmodule
|
24 |
|
|
|
25 |
|
|
module operator_C(
|
26 |
|
|
input P,G,G1,
|
27 |
|
|
output Go
|
28 |
|
|
);
|
29 |
|
|
|
30 |
|
|
assign Go=G|(P&G1);
|
31 |
|
|
|
32 |
|
|
endmodule
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
/* 32-bit prefix-2 Han-Carlson adder
|
36 |
|
|
stage 0: Number of Generation=32, NP=32, NOA=32, NOB=0, NOC=0.
|
37 |
|
|
stage 1: NG=16, NP=15, NOA=0, NOB=15, NOC=1.
|
38 |
|
|
stage 2: NG=16, NP=14, NOA=0, NOB=14, NOC=1.
|
39 |
|
|
stage 3: NG=16, NP=12, NOA=0, NOB=12, NOC=2.
|
40 |
|
|
stage 4: NG=16, NP=8, NOA=0, NOB=8, NOC=4.
|
41 |
|
|
stage 5: NG=16, NP=0, NOA=0, NOB=0, NOC=8.
|
42 |
|
|
stage 6; NG=32, NP=0, NOA=0, NOB=0, NOC=16.
|
43 |
|
|
*/
|
44 |
|
|
module adder_32bit(
|
45 |
|
|
input [31:0]i_a,i_b,
|
46 |
|
|
input i_c,
|
47 |
|
|
output [31:0]o_s,
|
48 |
|
|
output o_c
|
49 |
|
|
);
|
50 |
|
|
|
51 |
|
|
//stage 0
|
52 |
|
|
wire [31:0]P0,G0;
|
53 |
|
|
operator_A operator_A_0(i_a[0],i_b[0],P0[0],G0[0]);
|
54 |
|
|
operator_A operator_A_1(i_a[1],i_b[1],P0[1],G0[1]);
|
55 |
|
|
operator_A operator_A_2(i_a[2],i_b[2],P0[2],G0[2]);
|
56 |
|
|
operator_A operator_A_3(i_a[3],i_b[3],P0[3],G0[3]);
|
57 |
|
|
operator_A operator_A_4(i_a[4],i_b[4],P0[4],G0[4]);
|
58 |
|
|
operator_A operator_A_5(i_a[5],i_b[5],P0[5],G0[5]);
|
59 |
|
|
operator_A operator_A_6(i_a[6],i_b[6],P0[6],G0[6]);
|
60 |
|
|
operator_A operator_A_7(i_a[7],i_b[7],P0[7],G0[7]);
|
61 |
|
|
operator_A operator_A_8(i_a[8],i_b[8],P0[8],G0[8]);
|
62 |
|
|
operator_A operator_A_9(i_a[9],i_b[9],P0[9],G0[9]);
|
63 |
|
|
operator_A operator_A_10(i_a[10],i_b[10],P0[10],G0[10]);
|
64 |
|
|
operator_A operator_A_11(i_a[11],i_b[11],P0[11],G0[11]);
|
65 |
|
|
operator_A operator_A_12(i_a[12],i_b[12],P0[12],G0[12]);
|
66 |
|
|
operator_A operator_A_13(i_a[13],i_b[13],P0[13],G0[13]);
|
67 |
|
|
operator_A operator_A_14(i_a[14],i_b[14],P0[14],G0[14]);
|
68 |
|
|
operator_A operator_A_15(i_a[15],i_b[15],P0[15],G0[15]);
|
69 |
|
|
operator_A operator_A_16(i_a[16],i_b[16],P0[16],G0[16]);
|
70 |
|
|
operator_A operator_A_17(i_a[17],i_b[17],P0[17],G0[17]);
|
71 |
|
|
operator_A operator_A_18(i_a[18],i_b[18],P0[18],G0[18]);
|
72 |
|
|
operator_A operator_A_19(i_a[19],i_b[19],P0[19],G0[19]);
|
73 |
|
|
operator_A operator_A_20(i_a[20],i_b[20],P0[20],G0[20]);
|
74 |
|
|
operator_A operator_A_21(i_a[21],i_b[21],P0[21],G0[21]);
|
75 |
|
|
operator_A operator_A_22(i_a[22],i_b[22],P0[22],G0[22]);
|
76 |
|
|
operator_A operator_A_23(i_a[23],i_b[23],P0[23],G0[23]);
|
77 |
|
|
operator_A operator_A_24(i_a[24],i_b[24],P0[24],G0[24]);
|
78 |
|
|
operator_A operator_A_25(i_a[25],i_b[25],P0[25],G0[25]);
|
79 |
|
|
operator_A operator_A_26(i_a[26],i_b[26],P0[26],G0[26]);
|
80 |
|
|
operator_A operator_A_27(i_a[27],i_b[27],P0[27],G0[27]);
|
81 |
|
|
operator_A operator_A_28(i_a[28],i_b[28],P0[28],G0[28]);
|
82 |
|
|
operator_A operator_A_29(i_a[29],i_b[29],P0[29],G0[29]);
|
83 |
|
|
operator_A operator_A_30(i_a[30],i_b[30],P0[30],G0[30]);
|
84 |
|
|
operator_A operator_A_31(i_a[31],i_b[31],P0[31],G0[31]);
|
85 |
|
|
|
86 |
|
|
//stage 1
|
87 |
|
|
wire [15:0]G1;
|
88 |
|
|
wire [15:1]P1;
|
89 |
|
|
operator_C operator_C_stage_1_0(P0[0],G0[0],i_c,G1[0]);
|
90 |
|
|
operator_B operator_B_stage_1_1(P0[2],G0[2],P0[1],G0[1],P1[1],G1[1]);
|
91 |
|
|
operator_B operator_B_stage_1_2(P0[4],G0[4],P0[3],G0[3],P1[2],G1[2]);
|
92 |
|
|
operator_B operator_B_stage_1_3(P0[6],G0[6],P0[5],G0[5],P1[3],G1[3]);
|
93 |
|
|
operator_B operator_B_stage_1_4(P0[8],G0[8],P0[7],G0[7],P1[4],G1[4]);
|
94 |
|
|
operator_B operator_B_stage_1_5(P0[10],G0[10],P0[9],G0[9],P1[5],G1[5]);
|
95 |
|
|
operator_B operator_B_stage_1_6(P0[12],G0[12],P0[11],G0[11],P1[6],G1[6]);
|
96 |
|
|
operator_B operator_B_stage_1_7(P0[14],G0[14],P0[13],G0[13],P1[7],G1[7]);
|
97 |
|
|
operator_B operator_B_stage_1_8(P0[16],G0[16],P0[15],G0[15],P1[8],G1[8]);
|
98 |
|
|
operator_B operator_B_stage_1_9(P0[18],G0[18],P0[17],G0[17],P1[9],G1[9]);
|
99 |
|
|
operator_B operator_B_stage_1_10(P0[20],G0[20],P0[19],G0[19],P1[10],G1[10]);
|
100 |
|
|
operator_B operator_B_stage_1_11(P0[22],G0[22],P0[21],G0[21],P1[11],G1[11]);
|
101 |
|
|
operator_B operator_B_stage_1_12(P0[24],G0[24],P0[23],G0[23],P1[12],G1[12]);
|
102 |
|
|
operator_B operator_B_stage_1_13(P0[26],G0[26],P0[25],G0[25],P1[13],G1[13]);
|
103 |
|
|
operator_B operator_B_stage_1_14(P0[28],G0[28],P0[27],G0[27],P1[14],G1[14]);
|
104 |
|
|
operator_B operator_B_stage_1_15(P0[30],G0[30],P0[29],G0[29],P1[15],G1[15]);
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
//stage 2
|
109 |
|
|
wire [15:0]G2;
|
110 |
|
|
wire [15:2]P2;
|
111 |
|
|
assign G2[0]=G1[0];
|
112 |
|
|
operator_C operator_C_stage_2_1(P1[1],G1[1],G1[0],G2[1]);
|
113 |
|
|
operator_B operator_B_stage_2_2(P1[2], G1[2],P1[1],G1[1],P2[2],G2[2]);
|
114 |
|
|
operator_B operator_B_stage_2_3(P1[3], G1[3],P1[2],G1[2],P2[3],G2[3]);
|
115 |
|
|
operator_B operator_B_stage_2_4(P1[4], G1[4],P1[3],G1[3],P2[4],G2[4]);
|
116 |
|
|
operator_B operator_B_stage_2_5(P1[5], G1[5],P1[4],G1[4],P2[5],G2[5]);
|
117 |
|
|
operator_B operator_B_stage_2_6(P1[6], G1[6],P1[5],G1[5],P2[6],G2[6]);
|
118 |
|
|
operator_B operator_B_stage_2_7(P1[7], G1[7],P1[6],G1[6],P2[7],G2[7]);
|
119 |
|
|
operator_B operator_B_stage_2_8(P1[8], G1[8],P1[7],G1[7],P2[8],G2[8]);
|
120 |
|
|
operator_B operator_B_stage_2_9(P1[9], G1[9],P1[8],G1[8],P2[9],G2[9]);
|
121 |
|
|
operator_B operator_B_stage_2_10(P1[10], G1[10],P1[9],G1[9],P2[10],G2[10]);
|
122 |
|
|
operator_B operator_B_stage_2_11(P1[11], G1[11],P1[10],G1[10],P2[11],G2[11]);
|
123 |
|
|
operator_B operator_B_stage_2_12(P1[12], G1[12],P1[11],G1[11],P2[12],G2[12]);
|
124 |
|
|
operator_B operator_B_stage_2_13(P1[13], G1[13],P1[12],G1[12],P2[13],G2[13]);
|
125 |
|
|
operator_B operator_B_stage_2_14(P1[14], G1[14],P1[13],G1[13],P2[14],G2[14]);
|
126 |
|
|
operator_B operator_B_stage_2_15(P1[15], G1[15],P1[14],G1[14],P2[15],G2[15]);
|
127 |
|
|
|
128 |
|
|
//stage 3
|
129 |
|
|
wire [15:0]G3;
|
130 |
|
|
wire [15:4]P3;
|
131 |
|
|
assign G3[0]=G2[0];
|
132 |
|
|
assign G3[1]=G2[1];
|
133 |
|
|
operator_C operator_C_stage_3_2(P2[2],G2[2],G2[0],G3[2]);
|
134 |
|
|
operator_C operator_C_stage_3_3(P2[3],G2[3],G2[1],G3[3]);
|
135 |
|
|
operator_B operator_B_stage_3_4(P2[4], G2[4],P2[2],G2[2],P3[4],G3[4]);
|
136 |
|
|
operator_B operator_B_stage_3_5(P2[5], G2[5],P2[3],G2[3],P3[5],G3[5]);
|
137 |
|
|
operator_B operator_B_stage_3_6(P2[6], G2[6],P2[4],G2[4],P3[6],G3[6]);
|
138 |
|
|
operator_B operator_B_stage_3_7(P2[7], G2[7],P2[5],G2[5],P3[7],G3[7]);
|
139 |
|
|
operator_B operator_B_stage_3_8(P2[8], G2[8],P2[6],G2[6],P3[8],G3[8]);
|
140 |
|
|
operator_B operator_B_stage_3_9(P2[9], G2[9],P2[7],G2[7],P3[9],G3[9]);
|
141 |
|
|
operator_B operator_B_stage_3_10(P2[10], G2[10],P2[8],G2[8],P3[10],G3[10]);
|
142 |
|
|
operator_B operator_B_stage_3_11(P2[11], G2[11],P2[9],G2[9],P3[11],G3[11]);
|
143 |
|
|
operator_B operator_B_stage_3_12(P2[12], G2[12],P2[10],G2[10],P3[12],G3[12]);
|
144 |
|
|
operator_B operator_B_stage_3_13(P2[13], G2[13],P2[11],G2[11],P3[13],G3[13]);
|
145 |
|
|
operator_B operator_B_stage_3_14(P2[14], G2[14],P2[12],G2[12],P3[14],G3[14]);
|
146 |
|
|
operator_B operator_B_stage_3_15(P2[15], G2[15],P2[13],G2[13],P3[15],G3[15]);
|
147 |
|
|
|
148 |
|
|
//stage 4
|
149 |
|
|
wire [15:0]G4;
|
150 |
|
|
wire [15:8]P4;
|
151 |
|
|
assign G4[0]=G3[0];
|
152 |
|
|
assign G4[1]=G3[1];
|
153 |
|
|
assign G4[2]=G3[2];
|
154 |
|
|
assign G4[3]=G3[3];
|
155 |
|
|
operator_C operator_C_stage_4_4(P3[4],G3[4],G3[0],G4[4]);
|
156 |
|
|
operator_C operator_C_stage_4_5(P3[5],G3[5],G3[1],G4[5]);
|
157 |
|
|
operator_C operator_C_stage_4_6(P3[6],G3[6],G3[2],G4[6]);
|
158 |
|
|
operator_C operator_C_stage_4_7(P3[7],G3[7],G3[3],G4[7]);
|
159 |
|
|
operator_B operator_B_stage_4_8(P3[8], G3[8],P3[4],G3[4],P4[8],G4[8]);
|
160 |
|
|
operator_B operator_B_stage_4_9(P3[9], G3[9],P3[5],G3[5],P4[9],G4[9]);
|
161 |
|
|
operator_B operator_B_stage_4_10(P3[10], G3[10],P3[6],G3[6],P4[10],G4[10]);
|
162 |
|
|
operator_B operator_B_stage_4_11(P3[11], G3[11],P3[7],G3[7],P4[11],G4[11]);
|
163 |
|
|
operator_B operator_B_stage_4_12(P3[12], G3[12],P3[8],G3[8],P4[12],G4[12]);
|
164 |
|
|
operator_B operator_B_stage_4_13(P3[13], G3[13],P3[9],G3[9],P4[13],G4[13]);
|
165 |
|
|
operator_B operator_B_stage_4_14(P3[14], G3[14],P3[10],G3[10],P4[14],G4[14]);
|
166 |
|
|
operator_B operator_B_stage_4_15(P3[15], G3[15],P3[11],G3[11],P4[15],G4[15]);
|
167 |
|
|
|
168 |
|
|
//stage 5
|
169 |
|
|
wire [15:0]G5;
|
170 |
|
|
assign G5[0]=G4[0];
|
171 |
|
|
assign G5[1]=G4[1];
|
172 |
|
|
assign G5[2]=G4[2];
|
173 |
|
|
assign G5[3]=G4[3];
|
174 |
|
|
assign G5[4]=G4[4];
|
175 |
|
|
assign G5[5]=G4[5];
|
176 |
|
|
assign G5[6]=G4[6];
|
177 |
|
|
assign G5[7]=G4[7];
|
178 |
|
|
operator_C operator_C_stage_5_8(P4[8],G4[8],G4[0],G5[8]);
|
179 |
|
|
operator_C operator_C_stage_5_9(P4[9],G4[9],G4[1],G5[9]);
|
180 |
|
|
operator_C operator_C_stage_5_10(P4[10],G4[10],G4[2],G5[10]);
|
181 |
|
|
operator_C operator_C_stage_5_11(P4[11],G4[11],G4[3],G5[11]);
|
182 |
|
|
operator_C operator_C_stage_5_12(P4[12],G4[12],G4[4],G5[12]);
|
183 |
|
|
operator_C operator_C_stage_5_13(P4[13],G4[13],G4[5],G5[13]);
|
184 |
|
|
operator_C operator_C_stage_5_14(P4[14],G4[14],G4[6],G5[14]);
|
185 |
|
|
operator_C operator_C_stage_5_15(P4[15],G4[15],G4[7],G5[15]);
|
186 |
|
|
|
187 |
|
|
//stage 6
|
188 |
|
|
wire [31:0]G6;
|
189 |
|
|
assign G6[0]=G5[0];
|
190 |
|
|
assign G6[2]=G5[1];
|
191 |
|
|
assign G6[4]=G5[2];
|
192 |
|
|
assign G6[6]=G5[3];
|
193 |
|
|
assign G6[8]=G5[4];
|
194 |
|
|
assign G6[10]=G5[5];
|
195 |
|
|
assign G6[12]=G5[6];
|
196 |
|
|
assign G6[14]=G5[7];
|
197 |
|
|
assign G6[16]=G5[8];
|
198 |
|
|
assign G6[18]=G5[9];
|
199 |
|
|
assign G6[20]=G5[10];
|
200 |
|
|
assign G6[22]=G5[11];
|
201 |
|
|
assign G6[24]=G5[12];
|
202 |
|
|
assign G6[26]=G5[13];
|
203 |
|
|
assign G6[28]=G5[14];
|
204 |
|
|
assign G6[30]=G5[15];
|
205 |
|
|
operator_C operator_C_stage_6_0(P0[1],G0[1],G5[0],G6[1]);
|
206 |
|
|
operator_C operator_C_stage_6_1(P0[3],G0[3],G5[1],G6[3]);
|
207 |
|
|
operator_C operator_C_stage_6_2(P0[5],G0[5],G5[2],G6[5]);
|
208 |
|
|
operator_C operator_C_stage_6_3(P0[7],G0[7],G5[3],G6[7]);
|
209 |
|
|
operator_C operator_C_stage_6_4(P0[9],G0[9],G5[4],G6[9]);
|
210 |
|
|
operator_C operator_C_stage_6_5(P0[11],G0[11],G5[5],G6[11]);
|
211 |
|
|
operator_C operator_C_stage_6_6(P0[13],G0[13],G5[6],G6[13]);
|
212 |
|
|
operator_C operator_C_stage_6_7(P0[15],G0[15],G5[7],G6[15]);
|
213 |
|
|
operator_C operator_C_stage_6_8(P0[17],G0[17],G5[8],G6[17]);
|
214 |
|
|
operator_C operator_C_stage_6_9(P0[19],G0[19],G5[9],G6[19]);
|
215 |
|
|
operator_C operator_C_stage_6_10(P0[21],G0[21],G5[10],G6[21]);
|
216 |
|
|
operator_C operator_C_stage_6_11(P0[23],G0[23],G5[11],G6[23]);
|
217 |
|
|
operator_C operator_C_stage_6_12(P0[25],G0[25],G5[12],G6[25]);
|
218 |
|
|
operator_C operator_C_stage_6_13(P0[27],G0[27],G5[13],G6[27]);
|
219 |
|
|
operator_C operator_C_stage_6_14(P0[29],G0[29],G5[14],G6[29]);
|
220 |
|
|
operator_C operator_C_stage_6_15(P0[31],G0[31],G5[15],G6[31]);
|
221 |
|
|
|
222 |
|
|
assign o_s[0]=P0[0]^i_c;
|
223 |
|
|
assign o_s[1]=P0[1]^G6[0];
|
224 |
|
|
assign o_s[2]=P0[2]^G6[1];
|
225 |
|
|
assign o_s[3]=P0[3]^G6[2];
|
226 |
|
|
assign o_s[4]=P0[4]^G6[3];
|
227 |
|
|
assign o_s[5]=P0[5]^G6[4];
|
228 |
|
|
assign o_s[6]=P0[6]^G6[5];
|
229 |
|
|
assign o_s[7]=P0[7]^G6[6];
|
230 |
|
|
assign o_s[8]=P0[8]^G6[7];
|
231 |
|
|
assign o_s[9]=P0[9]^G6[8];
|
232 |
|
|
assign o_s[10]=P0[10]^G6[9];
|
233 |
|
|
assign o_s[11]=P0[11]^G6[10];
|
234 |
|
|
assign o_s[12]=P0[12]^G6[11];
|
235 |
|
|
assign o_s[13]=P0[13]^G6[12];
|
236 |
|
|
assign o_s[14]=P0[14]^G6[13];
|
237 |
|
|
assign o_s[15]=P0[15]^G6[14];
|
238 |
|
|
assign o_s[16]=P0[16]^G6[15];
|
239 |
|
|
assign o_s[17]=P0[17]^G6[16];
|
240 |
|
|
assign o_s[18]=P0[18]^G6[17];
|
241 |
|
|
assign o_s[19]=P0[19]^G6[18];
|
242 |
|
|
assign o_s[20]=P0[20]^G6[19];
|
243 |
|
|
assign o_s[21]=P0[21]^G6[20];
|
244 |
|
|
assign o_s[22]=P0[22]^G6[21];
|
245 |
|
|
assign o_s[23]=P0[23]^G6[22];
|
246 |
|
|
assign o_s[24]=P0[24]^G6[23];
|
247 |
|
|
assign o_s[25]=P0[25]^G6[24];
|
248 |
|
|
assign o_s[26]=P0[26]^G6[25];
|
249 |
|
|
assign o_s[27]=P0[27]^G6[26];
|
250 |
|
|
assign o_s[28]=P0[28]^G6[27];
|
251 |
|
|
assign o_s[29]=P0[29]^G6[28];
|
252 |
|
|
assign o_s[30]=P0[30]^G6[29];
|
253 |
|
|
assign o_s[31]=P0[31]^G6[30];
|
254 |
|
|
assign o_c=G6[31];
|
255 |
|
|
|
256 |
|
|
endmodule
|