| 1 |
2 |
seanlee |
/////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//// ////
|
| 3 |
|
|
//// High Speed Adder for Large Bitsize Computation (128 Bits) ////
|
| 4 |
|
|
//// ////
|
| 5 |
|
|
//// Authors: seanlee (seanlee@opencores.org) ////
|
| 6 |
|
|
//// ////
|
| 7 |
|
|
//// http://www.opencores.org/projects/adder ////
|
| 8 |
|
|
//// ////
|
| 9 |
|
|
/////////////////////////////////////////////////////////////////////
|
| 10 |
|
|
//// ////
|
| 11 |
|
|
//// Copyright (C) 2005 Sean Lee ////
|
| 12 |
|
|
//// seanlee@opencores.org ////
|
| 13 |
|
|
//// ////
|
| 14 |
|
|
//// This source file may be used and distributed without ////
|
| 15 |
|
|
//// restriction provided that this copyright statement is not ////
|
| 16 |
|
|
//// removed from the file and that any derivative work contains ////
|
| 17 |
|
|
//// the original copyright notice and the associated disclaimer.////
|
| 18 |
|
|
//// ////
|
| 19 |
|
|
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
| 20 |
|
|
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
| 21 |
|
|
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
| 22 |
|
|
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
| 23 |
|
|
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
| 24 |
|
|
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
| 25 |
|
|
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
| 26 |
|
|
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
| 27 |
|
|
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
| 28 |
|
|
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
| 29 |
|
|
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
| 30 |
|
|
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
| 31 |
|
|
//// POSSIBILITY OF SUCH DAMAGE. ////
|
| 32 |
|
|
//// ////
|
| 33 |
|
|
/////////////////////////////////////////////////////////////////////
|
| 34 |
|
|
//// ////
|
| 35 |
|
|
//// Note: The verilog file is written based on 128 bits. ////
|
| 36 |
|
|
//// The 128 bits adder was tested on a 0.35 ////
|
| 37 |
|
|
//// micron technology and synthesis results yielded a 18% ////
|
| 38 |
|
|
//// speed improvement over conventional carry look ahead adder ////
|
| 39 |
|
|
//// and 85% improvement compared to conventional ripple adder. ////
|
| 40 |
|
|
//// ////
|
| 41 |
|
|
//// The verilog code can be expanded using the same concept ////
|
| 42 |
|
|
//// for 256 bits, 512 bits or beyond. ////
|
| 43 |
|
|
/////////////////////////////////////////////////////////////////////
|
| 44 |
|
|
|
| 45 |
|
|
module adder_128bit (A, B, Sum);
|
| 46 |
|
|
|
| 47 |
|
|
input [127:0] A,B;
|
| 48 |
|
|
output [128:0] Sum;
|
| 49 |
|
|
wire [128:0] Sum;
|
| 50 |
|
|
|
| 51 |
|
|
wire [8:0] tempSum1, tempSum2, tempSum3, tempSum4, tempSum5, tempSum6, tempSum7, tempSum8;
|
| 52 |
|
|
wire [8:0] tempSum9, tempSum10, tempSum11, tempSum12, tempSum13, tempSum14, tempSum15, tempSum16;
|
| 53 |
|
|
|
| 54 |
|
|
wire tempCarry1, tempCarry2, tempCarry3, tempCarry4, tempCarry5, tempCarry6, tempCarry7, tempCarry8;
|
| 55 |
|
|
wire tempCarry9, tempCarry10, tempCarry11, tempCarry12, tempCarry13, tempCarry14, tempCarry15, tempCarry16;
|
| 56 |
|
|
|
| 57 |
|
|
wire f2, f3, f4, f5, f6, f7, f8;
|
| 58 |
|
|
wire f9, f10, f11, f12, f13, f14, f15, f16;
|
| 59 |
|
|
|
| 60 |
|
|
wire c1, c2, c3, c4, c5, c6, c7, c8;
|
| 61 |
|
|
wire c9, c10, c11, c12, c13, c14, c15, c16;
|
| 62 |
|
|
|
| 63 |
|
|
assign tempSum1 = A[7:0] + B[7:0];
|
| 64 |
|
|
assign tempSum2 = A[15:8] + B[15:8];
|
| 65 |
|
|
assign tempSum3 = A[23:16] + B[23:16];
|
| 66 |
|
|
assign tempSum4 = A[31:24] + B[31:24];
|
| 67 |
|
|
assign tempSum5 = A[39:32] + B[39:32];
|
| 68 |
|
|
assign tempSum6 = A[47:40] + B[47:40];
|
| 69 |
|
|
assign tempSum7 = A[55:48] + B[55:48];
|
| 70 |
|
|
assign tempSum8 = A[63:56] + B[63:56];
|
| 71 |
|
|
assign tempSum9 = A[71:64] + B[71:64];
|
| 72 |
|
|
assign tempSum10 = A[79:72] + B[79:72];
|
| 73 |
|
|
assign tempSum11 = A[87:80] + B[87:80];
|
| 74 |
|
|
assign tempSum12 = A[95:88] + B[95:88];
|
| 75 |
|
|
assign tempSum13 = A[103:96] + B[103:96];
|
| 76 |
|
|
assign tempSum14 = A[111:104] + B[111:104];
|
| 77 |
|
|
assign tempSum15 = A[119:112] + B[119:112];
|
| 78 |
|
|
assign tempSum16 = A[127:120] + B[127:120];
|
| 79 |
|
|
|
| 80 |
|
|
assign tempCarry1 = tempSum1[8];
|
| 81 |
|
|
assign tempCarry2 = tempSum2[8];
|
| 82 |
|
|
assign tempCarry3 = tempSum3[8];
|
| 83 |
|
|
assign tempCarry4 = tempSum4[8];
|
| 84 |
|
|
assign tempCarry5 = tempSum5[8];
|
| 85 |
|
|
assign tempCarry6 = tempSum6[8];
|
| 86 |
|
|
assign tempCarry7 = tempSum7[8];
|
| 87 |
|
|
assign tempCarry8 = tempSum8[8];
|
| 88 |
|
|
assign tempCarry9 = tempSum9[8];
|
| 89 |
|
|
assign tempCarry10 = tempSum10[8];
|
| 90 |
|
|
assign tempCarry11 = tempSum11[8];
|
| 91 |
|
|
assign tempCarry12 = tempSum12[8];
|
| 92 |
|
|
assign tempCarry13 = tempSum13[8];
|
| 93 |
|
|
assign tempCarry14 = tempSum14[8];
|
| 94 |
|
|
assign tempCarry15 = tempSum15[8];
|
| 95 |
|
|
assign tempCarry16 = tempSum16[8];
|
| 96 |
|
|
|
| 97 |
|
|
assign f2 = (tempSum2[7:0] == 8'hff);
|
| 98 |
|
|
assign f3 = (tempSum3[7:0] == 8'hff);
|
| 99 |
|
|
assign f4 = (tempSum4[7:0] == 8'hff);
|
| 100 |
|
|
assign f5 = (tempSum5[7:0] == 8'hff);
|
| 101 |
|
|
assign f6 = (tempSum6[7:0] == 8'hff);
|
| 102 |
|
|
assign f7 = (tempSum7[7:0] == 8'hff);
|
| 103 |
|
|
assign f8 = (tempSum8[7:0] == 8'hff);
|
| 104 |
|
|
assign f9 = (tempSum9[7:0] == 8'hff);
|
| 105 |
|
|
assign f10 = (tempSum10[7:0] == 8'hff);
|
| 106 |
|
|
assign f11 = (tempSum11[7:0] == 8'hff);
|
| 107 |
|
|
assign f12 = (tempSum12[7:0] == 8'hff);
|
| 108 |
|
|
assign f13 = (tempSum13[7:0] == 8'hff);
|
| 109 |
|
|
assign f14 = (tempSum14[7:0] == 8'hff);
|
| 110 |
|
|
assign f15 = (tempSum15[7:0] == 8'hff);
|
| 111 |
|
|
assign f16 = (tempSum16[7:0] == 8'hff);
|
| 112 |
|
|
|
| 113 |
|
|
assign c1 = tempCarry1;
|
| 114 |
|
|
assign c2 = (c1 & f2) | tempCarry2;
|
| 115 |
|
|
assign c3 = (c2 & f3) | tempCarry3;
|
| 116 |
|
|
assign c4 = (c3 & f4) | tempCarry4;
|
| 117 |
|
|
assign c5 = (c4 & f5) | tempCarry5;
|
| 118 |
|
|
assign c6 = (c5 & f6) | tempCarry6;
|
| 119 |
|
|
assign c7 = (c6 & f7) | tempCarry7;
|
| 120 |
|
|
assign c8 = (c7 & f8) | tempCarry8;
|
| 121 |
|
|
assign c9 = (c8 & f9) | tempCarry9;
|
| 122 |
|
|
assign c10 = (c9 & f10) | tempCarry10;
|
| 123 |
|
|
assign c11 = (c10 & f11) | tempCarry11;
|
| 124 |
|
|
assign c12 = (c11 & f12) | tempCarry12;
|
| 125 |
|
|
assign c13 = (c12 & f13) | tempCarry13;
|
| 126 |
|
|
assign c14 = (c13 & f14) | tempCarry14;
|
| 127 |
|
|
assign c15 = (c14 & f15) | tempCarry15;
|
| 128 |
|
|
assign c16 = (c15 & f16) | tempCarry16;
|
| 129 |
|
|
|
| 130 |
|
|
assign Sum[7:0] = tempSum1[7:0];
|
| 131 |
|
|
|
| 132 |
|
|
assign Sum[15:8] = c1 ? (tempSum2[7:0] + 1) : tempSum2[7:0];
|
| 133 |
|
|
|
| 134 |
|
|
assign Sum[23:16] = c2 ? (tempSum3[7:0] + 1) : tempSum3[7:0];
|
| 135 |
|
|
|
| 136 |
|
|
assign Sum[31:24] = c3 ? (tempSum4[7:0] + 1) : tempSum4[7:0];
|
| 137 |
|
|
|
| 138 |
|
|
assign Sum[39:32] = c4 ? (tempSum5[7:0] + 1) : tempSum5[7:0];
|
| 139 |
|
|
|
| 140 |
|
|
assign Sum[47:40] = c5 ? (tempSum6[7:0] + 1) : tempSum6[7:0];
|
| 141 |
|
|
|
| 142 |
|
|
assign Sum[55:48] = c6 ? (tempSum7[7:0] + 1) : tempSum7[7:0];
|
| 143 |
|
|
|
| 144 |
|
|
assign Sum[63:56] = c7 ? (tempSum8[7:0] + 1) : tempSum8[7:0];
|
| 145 |
|
|
|
| 146 |
|
|
assign Sum[71:64] = c8 ? (tempSum9[7:0] + 1) : tempSum9[7:0];
|
| 147 |
|
|
|
| 148 |
|
|
assign Sum[79:72] = c9 ? (tempSum10[7:0] + 1) : tempSum10[7:0];
|
| 149 |
|
|
|
| 150 |
|
|
assign Sum[87:80] = c10 ? (tempSum11[7:0] + 1) : tempSum11[7:0];
|
| 151 |
|
|
|
| 152 |
|
|
assign Sum[95:88] = c11 ? (tempSum12[7:0] + 1) : tempSum12[7:0];
|
| 153 |
|
|
|
| 154 |
|
|
assign Sum[103:96] = c12 ? (tempSum13[7:0] + 1) : tempSum13[7:0];
|
| 155 |
|
|
|
| 156 |
|
|
assign Sum[111:104] = c13 ? (tempSum14[7:0] + 1) : tempSum14[7:0];
|
| 157 |
|
|
|
| 158 |
|
|
assign Sum[119:112] = c14 ? (tempSum15[7:0] + 1) : tempSum15[7:0];
|
| 159 |
|
|
|
| 160 |
|
|
assign Sum[127:120] = c15 ? (tempSum16[7:0] + 1) : tempSum16[7:0];
|
| 161 |
|
|
|
| 162 |
|
|
assign Sum[128] = c16;
|
| 163 |
|
|
|
| 164 |
|
|
endmodule
|
| 165 |
|
|
|