1 | module Adder(in,out);
|
2 | input [63:0] in;
|
3 | output [31:0] out;
|
4 |
|
5 | wire [31:0] a;
|
6 | wire [31:0] b;
|
7 | wire [31:0] sum;
|
8 |
|
9 | wire cin;
|
10 | wire carry;
|
11 | wire lastcarry;
|
12 | wire signoverflow_pos;
|
13 | wire signoverflow_neg;
|
14 | wire forget;
|
15 |
|
16 | assign a = in[31:0];
|
17 | assign b = in[63:32];
|
18 | assign cin = 1'b0;
|
19 |
|
20 | SingleStage s0( .a( a[0] ), .b( b[0]), .cin( cin ), .s( sum[0]), .cout( ripple0 ) );
|
21 | SingleStage s1( .a( a[1] ), .b( b[1]), .cin( ripple0 ), .s( sum[1]), .cout( ripple1 ) );
|
22 | SingleStage s2( .a( a[2] ), .b( b[2]), .cin( ripple1 ), .s( sum[2]), .cout( ripple2 ) );
|
23 | SingleStage s3( .a( a[3] ), .b( b[3]), .cin( ripple2 ), .s( sum[3]), .cout( ripple3 ) );
|
24 | SingleStage s4( .a( a[4] ), .b( b[4]), .cin( ripple3 ), .s( sum[4]), .cout( ripple4 ) );
|
25 | SingleStage s5( .a( a[5] ), .b( b[5]), .cin( ripple4 ), .s( sum[5]), .cout( ripple5 ) );
|
26 | SingleStage s6( .a( a[6] ), .b( b[6]), .cin( ripple5 ), .s( sum[6]), .cout( ripple6 ) );
|
27 | SingleStage s7( .a( a[7] ), .b( b[7]), .cin( ripple6 ), .s( sum[7]), .cout( ripple7 ) );
|
28 | SingleStage s8( .a( a[8] ), .b( b[8]), .cin( ripple7 ), .s( sum[8]), .cout( ripple8 ) );
|
29 | SingleStage s9( .a( a[9] ), .b( b[9]), .cin( ripple8 ), .s( sum[9]), .cout( ripple9 ) );
|
30 | SingleStage s10( .a( a[10] ), .b( b[10]), .cin( ripple9 ), .s( sum[10]), .cout( ripple10 ) );
|
31 | SingleStage s11( .a( a[11] ), .b( b[11]), .cin( ripple10 ), .s( sum[11]), .cout( ripple11 ) );
|
32 | SingleStage s12( .a( a[12] ), .b( b[12]), .cin( ripple11 ), .s( sum[12]), .cout( ripple12 ) );
|
33 | SingleStage s13( .a( a[13] ), .b( b[13]), .cin( ripple12 ), .s( sum[13]), .cout( ripple13 ) );
|
34 | SingleStage s14( .a( a[14] ), .b( b[14]), .cin( ripple13 ), .s( sum[14]), .cout( ripple14 ) );
|
35 | SingleStage s15( .a( a[15] ), .b( b[15]), .cin( ripple14 ), .s( sum[15]), .cout( ripple15 ) );
|
36 | SingleStage s16( .a( a[16] ), .b( b[16]), .cin( ripple15 ), .s( sum[16]), .cout( ripple16 ) );
|
37 | SingleStage s17( .a( a[17] ), .b( b[17]), .cin( ripple16 ), .s( sum[17]), .cout( ripple17 ) );
|
38 | SingleStage s18( .a( a[18] ), .b( b[18]), .cin( ripple17 ), .s( sum[18]), .cout( ripple18 ) );
|
39 | SingleStage s19( .a( a[19] ), .b( b[19]), .cin( ripple18 ), .s( sum[19]), .cout( ripple19 ) );
|
40 | SingleStage s20( .a( a[20] ), .b( b[20]), .cin( ripple19 ), .s( sum[20]), .cout( ripple20 ) );
|
41 | SingleStage s21( .a( a[21] ), .b( b[21]), .cin( ripple20 ), .s( sum[21]), .cout( ripple21 ) );
|
42 | SingleStage s22( .a( a[22] ), .b( b[22]), .cin( ripple21 ), .s( sum[22]), .cout( ripple22 ) );
|
43 | SingleStage s23( .a( a[23] ), .b( b[23]), .cin( ripple22 ), .s( sum[23]), .cout( ripple23 ) );
|
44 | SingleStage s24( .a( a[24] ), .b( b[24]), .cin( ripple23 ), .s( sum[24]), .cout( ripple24 ) );
|
45 | SingleStage s25( .a( a[25] ), .b( b[25]), .cin( ripple24 ), .s( sum[25]), .cout( ripple25 ) );
|
46 | SingleStage s26( .a( a[26] ), .b( b[26]), .cin( ripple25 ), .s( sum[26]), .cout( ripple26 ) );
|
47 | SingleStage s27( .a( a[27] ), .b( b[27]), .cin( ripple26 ), .s( sum[27]), .cout( ripple27 ) );
|
48 | SingleStage s28( .a( a[28] ), .b( b[28]), .cin( ripple27 ), .s( sum[28]), .cout( ripple28 ) );
|
49 | SingleStage s29( .a( a[29] ), .b( b[29]), .cin( ripple28 ), .s( sum[29]), .cout( ripple29 ) );
|
50 | SingleStage s30( .a( a[30] ), .b( b[30]), .cin( ripple29 ), .s( sum[30]), .cout( ripple30 ) );
|
51 | SingleStage s31( .a( a[31] ), .b( b[31]), .cin( ripple30 ), .s( sum[31]), .cout( carry ) );
|
52 |
|
53 | SingleStage slast( .a( a[30] ), .b( b[30]), .cin( ripple29 ), .s( forget ), .cout( lastcarry ) );
|
54 |
|
55 | assign signoverflow_pos = (carry ^ lastcarry) & lastcarry;
|
56 | assign signoverflow_neg = (carry ^ lastcarry) & carry;
|
57 |
|
58 | assign out[0] = (sum[0] | signoverflow_pos) & ~signoverflow_neg;
|
59 | assign out[1] = (sum[1] | signoverflow_pos) & ~signoverflow_neg;
|
60 | assign out[2] = (sum[2] | signoverflow_pos) & ~signoverflow_neg;
|
61 | assign out[3] = (sum[3] | signoverflow_pos) & ~signoverflow_neg;
|
62 | assign out[4] = (sum[4] | signoverflow_pos) & ~signoverflow_neg;
|
63 | assign out[5] = (sum[5] | signoverflow_pos) & ~signoverflow_neg;
|
64 | assign out[6] = (sum[6] | signoverflow_pos) & ~signoverflow_neg;
|
65 | assign out[7] = (sum[7] | signoverflow_pos) & ~signoverflow_neg;
|
66 | assign out[8] = (sum[8] | signoverflow_pos) & ~signoverflow_neg;
|
67 | assign out[9] = (sum[9] | signoverflow_pos) & ~signoverflow_neg;
|
68 | assign out[10] = (sum[10] | signoverflow_pos) & ~signoverflow_neg;
|
69 | assign out[11] = (sum[11] | signoverflow_pos) & ~signoverflow_neg;
|
70 | assign out[12] = (sum[12] | signoverflow_pos) & ~signoverflow_neg;
|
71 | assign out[13] = (sum[13] | signoverflow_pos) & ~signoverflow_neg;
|
72 | assign out[14] = (sum[14] | signoverflow_pos) & ~signoverflow_neg;
|
73 | assign out[15] = (sum[15] | signoverflow_pos) & ~signoverflow_neg;
|
74 | assign out[16] = (sum[16] | signoverflow_pos) & ~signoverflow_neg;
|
75 | assign out[17] = (sum[17] | signoverflow_pos) & ~signoverflow_neg;
|
76 | assign out[18] = (sum[18] | signoverflow_pos) & ~signoverflow_neg;
|
77 | assign out[19] = (sum[19] | signoverflow_pos) & ~signoverflow_neg;
|
78 | assign out[20] = (sum[20] | signoverflow_pos) & ~signoverflow_neg;
|
79 | assign out[21] = (sum[21] | signoverflow_pos) & ~signoverflow_neg;
|
80 | assign out[22] = (sum[22] | signoverflow_pos) & ~signoverflow_neg;
|
81 | assign out[23] = (sum[23] | signoverflow_pos) & ~signoverflow_neg;
|
82 | assign out[24] = (sum[24] | signoverflow_pos) & ~signoverflow_neg;
|
83 | assign out[25] = (sum[25] | signoverflow_pos) & ~signoverflow_neg;
|
84 | assign out[26] = (sum[26] | signoverflow_pos) & ~signoverflow_neg;
|
85 | assign out[27] = (sum[27] | signoverflow_pos) & ~signoverflow_neg;
|
86 | assign out[28] = (sum[28] | signoverflow_pos) & ~signoverflow_neg;
|
87 | assign out[29] = (sum[29] | signoverflow_pos) & ~signoverflow_neg;
|
88 | assign out[30] = (sum[30] | signoverflow_pos) & ~signoverflow_neg;
|
89 | assign out[31] = (sum[31] & ~signoverflow_pos) | signoverflow_neg;
|
90 |
|
91 | endmodule
|
92 |
|
93 | module SingleStage(a,b,cin,s,cout);
|
94 | input a;
|
95 | input b;
|
96 | input cin;
|
97 | output s;
|
98 | output cout;
|
99 | assign s = a ^ b ^ cin;
|
100 | assign cout = (a & b) | (a & cin) | (b & cin);
|
101 |
|
102 | endmodule
|
103 |
|