next up previous
Next: Fast Addition of Integers Up: Integer Representation and Arithmetic Previous: Addition of Integers (Ripple

Incrementing Integers

It is useful to consider how incrementing an integer works. Incrementing a number is a very common operation (e.g. updating the counter of a for loop). While incrementing is usually not implemented as an instruction separate from addition, it is useful in understanding how to speed up calculating the carry bits.

Starting from a normal addition circuit and hardwiring one of the numbers to be one, we see that each of the $1$-bit adders after the first is effectively reduced to having two inputs - one of the input bits was hardcoded to zero. One of these inputs is the bit from the number being incremented and the other is the carry bit. The $1$-bit adders being used can then be simplified like the first $1$-bit adder of normal addition. The output bit is the parity of the input bit and the carry bit so it is the XOR of the two. The carry bit is the AND of these two bits allowing us to give a recursive formulation for the carry bit.

Carry $carry_{n-1}$ $carry_{n-2}$ $carry_{n-3}$ ... $carry(2)$ $carry(1)$ $carry(0)$  
Input   $in_{n-1}$ $in_{n-2}$ ... $in_3$ $in_2$ $in_1$ $in_0$
One       ...       1
Output $out_n$ $out_{n-1}$ $out_{n-2}$ ... $out_3$ $out_2$ $out_1$ $out_0$

\begin{eqnarray*}
carry_0 & = & in_0 \\
carry_{n+1} & = & in_{n+1} \land carry_n \\
\end{eqnarray*}



The first bit of the input number which is zero causes its carry bit to be zero. In turn, this causes all of the following carry bits to also be zero. If we implement the circuit directly from the recursive description, we get a circuit of linear size ($n-1$ AND gates) and linear depth ($n-1$) similar to the ripple-carry adder. However, we can derive a faster equation for the carry bits by unwinding the recursion.

\begin{eqnarray*}
carry(n) & = & in_0 \land \ldots \land in_n \\
\end{eqnarray*}



This equation can be implemented in logarithmic depth ( $\left\lceil \lg n \right\rceil$) and linear size ($n-1$ AND gates) per carry bit. The total number of gates to implement each carry bit is quadratic since they are not sharing components any more. Similar ideas will be used to speedup calculation in carry-lookahead adders.


next up previous
Next: Fast Addition of Integers Up: Integer Representation and Arithmetic Previous: Addition of Integers (Ripple
Jeffrey Considine 2001-05-01