module add_full32(a,b,cin,co,s);

input signed [31:0] a,b;
input signed cin;
output co;
output signed [31:0] s;

wire psb,cinb;
wire [31:0] t, phn, h5,h4,h3,h2,h1,t4,t3,t2,t1,ps;


// partial sum

xor i0(ps[0],a[0],b[0]);
xor i1(ps[1],a[1],b[1]);
xor i2(ps[2],a[2],b[2]);
xor i3(ps[3],a[3],b[3]);
xor i4(ps[4],a[4],b[4]);
xor i5(ps[5],a[5],b[5]);
xor i6(ps[6],a[6],b[6]);
xor i7(ps[7],a[7],b[7]);
xor i8(ps[8],a[8],b[8]);
xor i9(ps[9],a[9],b[9]);
xor i10(ps[10],a[10],b[10]);
xor i11(ps[11],a[11],b[11]);
xor i12(ps[12],a[12],b[12]);
xor i13(ps[13],a[13],b[13]);
xor i14(ps[14],a[14],b[14]);
xor i15(ps[15],a[15],b[15]);
xor i16(ps[16],a[16],b[16]);
xor i17(ps[17],a[17],b[17]);
xor i18(ps[18],a[18],b[18]);
xor i19(ps[19],a[19],b[19]);
xor i20(ps[20],a[20],b[20]);
xor i21(ps[21],a[21],b[21]);
xor i22(ps[22],a[22],b[22]);
xor i23(ps[23],a[23],b[23]);
xor i24(ps[24],a[24],b[24]);
xor i25(ps[25],a[25],b[25]);
xor i26(ps[26],a[26],b[26]);
xor i27(ps[27],a[27],b[27]);
xor i28(ps[28],a[28],b[28]);
xor i29(ps[29],a[29],b[29]);
xor i30(ps[30],a[30],b[30]);
xor i31(ps[31],a[31],b[31]);

// sum

or io0(t[0],a[0],b[0]);
or io1(t[1],a[1],b[1]);
or io2(t[2],a[2],b[2]);
or io3(t[3],a[3],b[3]);
or io4(t[4],a[4],b[4]);
or io5(t[5],a[5],b[5]);
or io6(t[6],a[6],b[6]);
or io7(t[7],a[7],b[7]);
or io8(t[8],a[8],b[8]);
or io9(t[9],a[9],b[9]);
or io10(t[10],a[10],b[10]);
or io11(t[11],a[11],b[11]);
or io12(t[12],a[12],b[12]);
or io13(t[13],a[13],b[13]);
or io14(t[14],a[14],b[14]);
or io15(t[15],a[15],b[15]);
or io16(t[16],a[16],b[16]);
or io17(t[17],a[17],b[17]);
or io18(t[18],a[18],b[18]);
or io19(t[19],a[19],b[19]);
or io20(t[20],a[20],b[20]);
or io21(t[21],a[21],b[21]);
or io22(t[22],a[22],b[22]);
or io23(t[23],a[23],b[23]);
or io24(t[24],a[24],b[24]);
or io25(t[25],a[25],b[25]);
or io26(t[26],a[26],b[26]);
or io27(t[27],a[27],b[27]);
or io28(t[28],a[28],b[28]);
or io29(t[29],a[29],b[29]);
or io30(t[30],a[30],b[30]);
or io31(t[31],a[31],b[31]);

xor ix1(phn[1],t[0],ps[1]);
xor ix2(phn[2],t[1],ps[2]);
xor ix3(phn[3],t[2],ps[3]);
xor ix4(phn[4],t[3],ps[4]);
xor ix5(phn[5],t[4],ps[5]);
xor ix6(phn[6],t[5],ps[6]);
xor ix7(phn[7],t[6],ps[7]);
xor ix8(phn[8],t[7],ps[8]);
xor ix9(phn[9],t[8],ps[9]);
xor ix10(phn[10],t[9],ps[10]);
xor ix11(phn[11],t[10],ps[11]);
xor ix12(phn[12],t[11],ps[12]);
xor ix13(phn[13],t[12],ps[13]);
xor ix14(phn[14],t[13],ps[14]);
xor ix15(phn[15],t[14],ps[15]);
xor ix16(phn[16],t[15],ps[16]);
xor ix17(phn[17],t[16],ps[17]);
xor ix18(phn[18],t[17],ps[18]);
xor ix19(phn[19],t[18],ps[19]);
xor ix20(phn[20],t[19],ps[20]);
xor ix21(phn[21],t[20],ps[21]);
xor ix22(phn[22],t[21],ps[22]);
xor ix23(phn[23],t[22],ps[23]);
xor ix24(phn[24],t[23],ps[24]);
xor ix25(phn[25],t[24],ps[25]);
xor ix26(phn[26],t[25],ps[26]);
xor ix27(phn[27],t[26],ps[27]);
xor ix28(phn[28],t[27],ps[28]);
xor ix29(phn[29],t[28],ps[29]);
xor ix30(phn[30],t[29],ps[30]);
xor ix31(phn[31],t[30],ps[31]);



// 1st level H# and T#

h1 ih1i0(a[0],b[0],cin,cin,h1[0]);
h1s ih1i1(a[1],b[1],a[0],b[0],cin,h1[1]);
h1 ih1i2(a[2],b[2],a[1],b[1],h1[2]);
h1 ih1i3(a[3],b[3],a[2],b[2],h1[3]);
h1 ih1i4(a[4],b[4],a[3],b[3],h1[4]);
h1 ih1i5(a[5],b[5],a[4],b[4],h1[5]);
h1 ih1i6(a[6],b[6],a[5],b[5],h1[6]);
h1 ih1i7(a[7],b[7],a[6],b[6],h1[7]);
h1 ih1i8(a[8],b[8],a[7],b[7],h1[8]);
h1 ih1i9(a[9],b[9],a[8],b[8],h1[9]);
h1 ih1i10(a[10],b[10],a[9],b[9],h1[10]);
h1 ih1i11(a[11],b[11],a[10],b[10],h1[11]);
h1 ih1i12(a[12],b[12],a[11],b[11],h1[12]);
h1 ih1i13(a[13],b[13],a[12],b[12],h1[13]);
h1 ih1i14(a[14],b[14],a[13],b[13],h1[14]);
h1 ih1i15(a[15],b[15],a[14],b[14],h1[15]);
h1 ih1i16(a[16],b[16],a[15],b[15],h1[16]);
h1 ih1i17(a[17],b[17],a[16],b[16],h1[17]);
h1 ih1i18(a[18],b[18],a[17],b[17],h1[18]);
h1 ih1i19(a[19],b[19],a[18],b[18],h1[19]);
h1 ih1i20(a[20],b[20],a[19],b[19],h1[20]);
h1 ih1i21(a[21],b[21],a[20],b[20],h1[21]);
h1 ih1i22(a[22],b[22],a[21],b[21],h1[22]);
h1 ih1i23(a[23],b[23],a[22],b[22],h1[23]);
h1 ih1i24(a[24],b[24],a[23],b[23],h1[24]);
h1 ih1i25(a[25],b[25],a[24],b[24],h1[25]);
h1 ih1i26(a[26],b[26],a[25],b[25],h1[26]);
h1 ih1i27(a[27],b[27],a[26],b[26],h1[27]);
h1 ih1i28(a[28],b[28],a[27],b[27],h1[28]);
h1 ih1i29(a[29],b[29],a[28],b[28],h1[29]);
h1 ih1i30(a[30],b[30],a[29],b[29],h1[30]);
h1 ih1i31(a[31],b[31],a[30],b[30],h1[31]);

t1 it1i1(a[1],b[1],a[0],b[0],t1[1]);
t1 it1i2(a[2],b[2],a[1],b[1],t1[2]);
t1 it1i3(a[3],b[3],a[2],b[2],t1[3]);
t1 it1i4(a[4],b[4],a[3],b[3],t1[4]);
t1 it1i5(a[5],b[5],a[4],b[4],t1[5]);
t1 it1i6(a[6],b[6],a[5],b[5],t1[6]);
t1 it1i7(a[7],b[7],a[6],b[6],t1[7]);
t1 it1i8(a[8],b[8],a[7],b[7],t1[8]);
t1 it1i9(a[9],b[9],a[8],b[8],t1[9]);
t1 it1i10(a[10],b[10],a[9],b[9],t1[10]);
t1 it1i11(a[11],b[11],a[10],b[10],t1[11]);
t1 it1i12(a[12],b[12],a[11],b[11],t1[12]);
t1 it1i13(a[13],b[13],a[12],b[12],t1[13]);
t1 it1i14(a[14],b[14],a[13],b[13],t1[14]);
t1 it1i15(a[15],b[15],a[14],b[14],t1[15]);
t1 it1i16(a[16],b[16],a[15],b[15],t1[16]);
t1 it1i17(a[17],b[17],a[16],b[16],t1[17]);
t1 it1i18(a[18],b[18],a[17],b[17],t1[18]);
t1 it1i19(a[19],b[19],a[18],b[18],t1[19]);
t1 it1i20(a[20],b[20],a[19],b[19],t1[20]);
t1 it1i21(a[21],b[21],a[20],b[20],t1[21]);
t1 it1i22(a[22],b[22],a[21],b[21],t1[22]);
t1 it1i23(a[23],b[23],a[22],b[22],t1[23]);
t1 it1i24(a[24],b[24],a[23],b[23],t1[24]);
t1 it1i25(a[25],b[25],a[24],b[24],t1[25]);
t1 it1i26(a[26],b[26],a[25],b[25],t1[26]);
t1 it1i27(a[27],b[27],a[26],b[26],t1[27]);
t1 it1i28(a[28],b[28],a[27],b[27],t1[28]);
t1 it1i29(a[29],b[29],a[28],b[28],t1[29]);
t1 it1i30(a[30],b[30],a[29],b[29],t1[30]);

// 2nd level H and T

not ih2i0(h2[0],h1[0]);
not ih2i1(h2[1],h1[1]);
oai ih2i2(h2[2],h1[0],t1[1],h1[2]);
oai ih2i3(h2[3],h1[1],t1[2],h1[3]);
oai ih2i4(h2[4],h1[2],t1[3],h1[4]);
oai ih2i5(h2[5],h1[3],t1[4],h1[5]);
oai ih2i6(h2[6],h1[4],t1[5],h1[6]);
oai ih2i7(h2[7],h1[5],t1[6],h1[7]);
oai ih2i8(h2[8],h1[6],t1[7],h1[8]);
oai ih2i9(h2[9],h1[7],t1[8],h1[9]);
oai ih2i10(h2[10],h1[8],t1[9],h1[10]);
oai ih2i11(h2[11],h1[9],t1[10],h1[11]);
oai ih2i12(h2[12],h1[10],t1[11],h1[12]);
oai ih2i13(h2[13],h1[11],t1[12],h1[13]);
oai ih2i14(h2[14],h1[12],t1[13],h1[14]);
oai ih2i15(h2[15],h1[13],t1[14],h1[15]);
oai ih2i16(h2[16],h1[14],t1[15],h1[16]);
oai ih2i17(h2[17],h1[15],t1[16],h1[17]);
oai ih2i18(h2[18],h1[16],t1[17],h1[18]);
oai ih2i19(h2[19],h1[17],t1[18],h1[19]);
oai ih2i20(h2[20],h1[18],t1[19],h1[20]);
oai ih2i21(h2[21],h1[19],t1[20],h1[21]);
oai ih2i22(h2[22],h1[20],t1[21],h1[22]);
oai ih2i23(h2[23],h1[21],t1[22],h1[23]);
oai ih2i24(h2[24],h1[22],t1[23],h1[24]);
oai ih2i25(h2[25],h1[23],t1[24],h1[25]);
oai ih2i26(h2[26],h1[24],t1[25],h1[26]);
oai ih2i27(h2[27],h1[25],t1[26],h1[27]);
oai ih2i28(h2[28],h1[26],t1[27],h1[28]);
oai ih2i29(h2[29],h1[27],t1[28],h1[29]);
oai ih2i30(h2[30],h1[28],t1[29],h1[30]);
oai ih2i31(h2[31],h1[29],t1[30],h1[31]);

nor it2i3(t2[3],t1[1],t1[3]);
nor it2i4(t2[4],t1[2],t1[4]);
nor it2i5(t2[5],t1[3],t1[5]);
nor it2i6(t2[6],t1[4],t1[6]);
nor it2i7(t2[7],t1[5],t1[7]);
nor it2i8(t2[8],t1[6],t1[8]);
nor it2i9(t2[9],t1[7],t1[9]);
nor it2i10(t2[10],t1[8],t1[10]);
nor it2i11(t2[11],t1[9],t1[11]);
nor it2i12(t2[12],t1[10],t1[12]);
nor it2i13(t2[13],t1[11],t1[13]);
nor it2i14(t2[14],t1[12],t1[14]);
nor it2i15(t2[15],t1[13],t1[15]);
nor it2i16(t2[16],t1[14],t1[16]);
nor it2i17(t2[17],t1[15],t1[17]);
nor it2i18(t2[18],t1[16],t1[18]);
nor it2i19(t2[19],t1[17],t1[19]);
nor it2i20(t2[20],t1[18],t1[20]);
nor it2i21(t2[21],t1[19],t1[21]);
nor it2i22(t2[22],t1[20],t1[22]);
nor it2i23(t2[23],t1[21],t1[23]);
nor it2i24(t2[24],t1[22],t1[24]);
nor it2i25(t2[25],t1[23],t1[25]);
nor it2i26(t2[26],t1[24],t1[26]);
nor it2i27(t2[27],t1[25],t1[27]);
nor it2i28(t2[28],t1[26],t1[28]);
nor it2i29(t2[29],t1[27],t1[29]);
nor it2i30(t2[30],t1[28],t1[30]);

// Level 3 H# and T#

not ih3i0(h3[0],h2[0]);
not ih3i1(h3[1],h2[1]);
not ih3i2(h3[2],h2[2]);
not ih3i3(h3[3],h2[3]);
aoi ih3i4(h3[4],h2[0],t2[3],h2[4]);
aoi ih3i5(h3[5],h2[1],t2[4],h2[5]);
aoi ih3i6(h3[6],h2[2],t2[5],h2[6]);
aoi ih3i7(h3[7],h2[3],t2[6],h2[7]);
aoi ih3i8(h3[8],h2[4],t2[7],h2[8]);
aoi ih3i9(h3[9],h2[5],t2[8],h2[9]);
aoi ih3i10(h3[10],h2[6],t2[9],h2[10]);
aoi ih3i11(h3[11],h2[7],t2[10],h2[11]);
aoi ih3i12(h3[12],h2[8],t2[11],h2[12]);
aoi ih3i13(h3[13],h2[9],t2[12],h2[13]);
aoi ih3i14(h3[14],h2[10],t2[13],h2[14]);
aoi ih3i15(h3[15],h2[11],t2[14],h2[15]);
aoi ih3i16(h3[16],h2[12],t2[15],h2[16]);
aoi ih3i17(h3[17],h2[13],t2[16],h2[17]);
aoi ih3i18(h3[18],h2[14],t2[17],h2[18]);
aoi ih3i19(h3[19],h2[15],t2[18],h2[19]);
aoi ih3i20(h3[20],h2[16],t2[19],h2[20]);
aoi ih3i21(h3[21],h2[17],t2[20],h2[21]);
aoi ih3i22(h3[22],h2[18],t2[21],h2[22]);
aoi ih3i23(h3[23],h2[19],t2[22],h2[23]);
aoi ih3i24(h3[24],h2[20],t2[23],h2[24]);
aoi ih3i25(h3[25],h2[21],t2[24],h2[25]);
aoi ih3i26(h3[26],h2[22],t2[25],h2[26]);
aoi ih3i27(h3[27],h2[23],t2[26],h2[27]);
aoi ih3i28(h3[28],h2[24],t2[27],h2[28]);
aoi ih3i29(h3[29],h2[25],t2[28],h2[29]);
aoi ih3i30(h3[30],h2[26],t2[29],h2[30]);
aoi ih3i31(h3[31],h2[27],t2[30],h2[31]);

nand it3i7(t3[7],t2[3],t2[7]);
nand it3i8(t3[8],t2[4],t2[8]);
nand it3i9(t3[9],t2[5],t2[9]);
nand it3i10(t3[10],t2[6],t2[10]);
nand it3i11(t3[11],t2[7],t2[11]);
nand it3i12(t3[12],t2[8],t2[12]);
nand it3i13(t3[13],t2[9],t2[13]);
nand it3i14(t3[14],t2[10],t2[14]);
nand it3i15(t3[15],t2[11],t2[15]);
nand it3i16(t3[16],t2[12],t2[16]);
nand it3i17(t3[17],t2[13],t2[17]);
nand it3i18(t3[18],t2[14],t2[18]);
nand it3i19(t3[19],t2[15],t2[19]);
nand it3i20(t3[20],t2[16],t2[20]);
nand it3i21(t3[21],t2[17],t2[21]);
nand it3i22(t3[22],t2[18],t2[22]);
nand it3i23(t3[23],t2[19],t2[23]);
nand it3i24(t3[24],t2[20],t2[24]);
nand it3i25(t3[25],t2[21],t2[25]);
nand it3i26(t3[26],t2[22],t2[26]);
nand it3i27(t3[27],t2[23],t2[27]);
nand it3i28(t3[28],t2[24],t2[28]);
nand it3i29(t3[29],t2[25],t2[29]);
nand it3i30(t3[30],t2[26],t2[30]);

// Level 4 H and T

not ih4i0(h4[0],h3[0]);
not ih4i1(h4[1],h3[1]);
not ih4i2(h4[2],h3[2]);
not ih4i3(h4[3],h3[3]);
not ih4i4(h4[4],h3[4]);
not ih4i5(h4[5],h3[5]);
not ih4i6(h4[6],h3[6]);
not ih4i7(h4[7],h3[7]);
oai ih4i8(h4[8],h3[0],t3[7],h3[8]);
oai ih4i9(h4[9],h3[1],t3[8],h3[9]);
oai ih4i10(h4[10],h3[2],t3[9],h3[10]);
oai ih4i11(h4[11],h3[3],t3[10],h3[11]);
oai ih4i12(h4[12],h3[4],t3[11],h3[12]);
oai ih4i13(h4[13],h3[5],t3[12],h3[13]);
oai ih4i14(h4[14],h3[6],t3[13],h3[14]);
oai ih4i15(h4[15],h3[7],t3[14],h3[15]);
oai ih4i16(h4[16],h3[8],t3[15],h3[16]);
oai ih4i17(h4[17],h3[9],t3[16],h3[17]);
oai ih4i18(h4[18],h3[10],t3[17],h3[18]);
oai ih4i19(h4[19],h3[11],t3[18],h3[19]);
oai ih4i20(h4[20],h3[12],t3[19],h3[20]);
oai ih4i21(h4[21],h3[13],t3[20],h3[21]);
oai ih4i22(h4[22],h3[14],t3[21],h3[22]);
oai ih4i23(h4[23],h3[15],t3[22],h3[23]);
oai ih4i24(h4[24],h3[16],t3[23],h3[24]);
oai ih4i25(h4[25],h3[17],t3[24],h3[25]);
oai ih4i26(h4[26],h3[18],t3[25],h3[26]);
oai ih4i27(h4[27],h3[19],t3[26],h3[27]);
oai ih4i28(h4[28],h3[20],t3[27],h3[28]);
oai ih4i29(h4[29],h3[21],t3[28],h3[29]);
oai ih4i30(h4[30],h3[22],t3[29],h3[30]);
oai ih4i31(h4[31],h3[23],t3[30],h3[31]);

nor it4i15(t4[15],t3[7],t3[15]);
nor it4i16(t4[16],t3[8],t3[16]);
nor it4i17(t4[17],t3[9],t3[17]);
nor it4i18(t4[18],t3[10],t3[18]);
nor it4i19(t4[19],t3[11],t3[19]);
nor it4i20(t4[20],t3[12],t3[20]);
nor it4i21(t4[21],t3[13],t3[21]);
nor it4i22(t4[22],t3[14],t3[22]);
nor it4i23(t4[23],t3[15],t3[23]);
nor it4i24(t4[24],t3[16],t3[24]);
nor it4i25(t4[25],t3[17],t3[25]);
nor it4i26(t4[26],t3[18],t3[26]);
nor it4i27(t4[27],t3[19],t3[27]);
nor it4i28(t4[28],t3[20],t3[28]);
nor it4i29(t4[29],t3[21],t3[29]);
nor it4i30(t4[30],t3[22],t3[30]);

// Level 5 H# 

not ih5i0(h5[0],h4[0]);
not ih5i1(h5[1],h4[1]);
not ih5i2(h5[2],h4[2]);
not ih5i3(h5[3],h4[3]);
not ih5i4(h5[4],h4[4]);
not ih5i5(h5[5],h4[5]);
not ih5i6(h5[6],h4[6]);
not ih5i7(h5[7],h4[7]);
not ih5i8(h5[8],h4[8]);
not ih5i9(h5[9],h4[9]);
not ih5i10(h5[10],h4[10]);
not ih5i11(h5[11],h4[11]);
not ih5i12(h5[12],h4[12]);
not ih5i13(h5[13],h4[13]);
not ih5i14(h5[14],h4[14]);
not ih5i15(h5[15],h4[15]);
aoi ih5i16(h5[16],h4[0],t4[15],h4[16]);
aoi ih5i17(h5[17],h4[1],t4[16],h4[17]);
aoi ih5i18(h5[18],h4[2],t4[17],h4[18]);
aoi ih5i19(h5[19],h4[3],t4[18],h4[19]);
aoi ih5i20(h5[20],h4[4],t4[19],h4[20]);
aoi ih5i21(h5[21],h4[5],t4[20],h4[21]);
aoi ih5i22(h5[22],h4[6],t4[21],h4[22]);
aoi ih5i23(h5[23],h4[7],t4[22],h4[23]);
aoi ih5i24(h5[24],h4[8],t4[23],h4[24]);
aoi ih5i25(h5[25],h4[9],t4[24],h4[25]);
aoi ih5i26(h5[26],h4[10],t4[25],h4[26]);
aoi ih5i27(h5[27],h4[11],t4[26],h4[27]);
aoi ih5i28(h5[28],h4[12],t4[27],h4[28]);
aoi ih5i29(h5[29],h4[13],t4[28],h4[29]);
aoi ih5i30(h5[30],h4[14],t4[29],h4[30]);
aoi ih5i31(h5[31],h4[15],t4[30],h4[31]);

not ibbb0(psb,ps[0]);
not ibbb1(cinb,cin);
mux21 im0(s[0],ps[0],psb,cinb);
mux21 im1(s[1],ps[1],phn[1],h5[0]);
mux21 im2(s[2],ps[2],phn[2],h5[1]);
mux21 im3(s[3],ps[3],phn[3],h5[2]);
mux21 im4(s[4],ps[4],phn[4],h5[3]);
mux21 im5(s[5],ps[5],phn[5],h5[4]);
mux21 im6(s[6],ps[6],phn[6],h5[5]);
mux21 im7(s[7],ps[7],phn[7],h5[6]);
mux21 im8(s[8],ps[8],phn[8],h5[7]);
mux21 im9(s[9],ps[9],phn[9],h5[8]);
mux21 im10(s[10],ps[10],phn[10],h5[9]);
mux21 im11(s[11],ps[11],phn[11],h5[10]);
mux21 im12(s[12],ps[12],phn[12],h5[11]);
mux21 im13(s[13],ps[13],phn[13],h5[12]);
mux21 im14(s[14],ps[14],phn[14],h5[13]);
mux21 im15(s[15],ps[15],phn[15],h5[14]);
mux21 im16(s[16],ps[16],phn[16],h5[15]);
mux21 im17(s[17],ps[17],phn[17],h5[16]);
mux21 im18(s[18],ps[18],phn[18],h5[17]);
mux21 im19(s[19],ps[19],phn[19],h5[18]);
mux21 im20(s[20],ps[20],phn[20],h5[19]);
mux21 im21(s[21],ps[21],phn[21],h5[20]);
mux21 im22(s[22],ps[22],phn[22],h5[21]);
mux21 im23(s[23],ps[23],phn[23],h5[22]);
mux21 im24(s[24],ps[24],phn[24],h5[23]);
mux21 im25(s[25],ps[25],phn[25],h5[24]);
mux21 im26(s[26],ps[26],phn[26],h5[25]);
mux21 im27(s[27],ps[27],phn[27],h5[26]);
mux21 im28(s[28],ps[28],phn[28],h5[27]);
mux21 im29(s[29],ps[29],phn[29],h5[28]);
mux21 im30(s[30],ps[30],phn[30],h5[29]);
mux21 im31(s[31],ps[31],phn[31],h5[30]);

endmodule
