Special purpose adders 
Special purpose adders 
Some arithmetic algorithms can be realized with only one modified adder. For example :
The cost and the delay are similar to a fast adder's ones. 
The special purpose adders of this page are built around the Sklansky's adder, which is recalled here for convenience of comparison. 
The "BK" cells outputs are either 'P', 'G' or 'K', nevertheless a carry c_{i} is never 'P' because in this applet the "HA" cell at the right is modified in order to exclude the value 'P' for c_{1}. 
If the output carry c_{n} is neglected then S = A + B – 2^{n} whenever A + B is too large. In order to retain the continuity of the addition, the adder with saturation is sometimes preferred to the adder modulo. It computes S = min( A + B , 2^{n} – 1) . 
Adders spontaneously calculate the addition modulo 2^{n}. To get the opposite B of a number B, all the
bits are logically complemented and a 1 is added. The addition of B with B obtained in this way gives 2^{n}
that is 0. The input carry c_{0} of an adder is used to add the bit a/s and disjunction gate to complement B. This "operations box" executes addition if a/s = '0' and subtraction if a/s = '1'. 
Just like the adder, the adder/subtractor may overflow, but it may as well underflow. If the last carry c_{n} and the carry c_{n1 }differ, then the output S is incorrect :


Addition/ subtraction with saturation 
Just as with the addition with saturation, the two carries c_{n} and c_{n1} may be used to select the largest representable positive interger or the smallest representable negative integer. S = min ( max ( A ± B , 2^{n1}) , 2^{n1}–1) . 
Comparison of signed integers 
After a subtraction S = A – B, the sign of S indicates A ³ B or otherwise A < B. A slight modification of the adder/subtractor wiring allows the output carry c_{n} to indicate A < B, A = B or A > B; necessary for comparisons. This indication is only valid with subtraction. 
In order to compare A and B, it not necessary to compute the difference A – B. Only the sign of A – B is needed, that is the carry out. This comparator is simpler (less "BK") therefore faster (less fanout) than a complete subtractor. A multiplexers row selects the max. 
If the carry in c_{0} of an adder S = A + B + c_{0 }is ready later than the inputs A and B, a carrylate adder is appropriate. The delay between input c_{0 }and outputs S is small and independent of the number of bits. 
On the contrary, if the carry in c_{0 }is ready as soon as the inputs A and B, then the approach used in the above described adder/subtractor would be more efficient because requesting less "BK" cells. 
To design this adder S = A + B + c_{0} first the output are duplicated. Then for the output S the value '0' is substituted to c_{0 }and the value '1' is substituted to c_{0} for the output S'. The obtained adder calculates simultaneously S = A + B and S' = A + B + 1 . 
The output of the "BK" is either 'P', 'G' or 'K', and the carry c_{i} must be '0' or '1'.

We want to calculate S = A + B, S' = A + B + 1 and S" = A + B + 2. To get S and S" we calculate beforehand without carry propagation two numbers X and Y such that X + Y = A + B. In that way we get the least significant bits s_{0} and s"_{0}. Then the n1 most significant bits of X and Y are added with the preceding twooutput adder . 
Where is the third output S' = A + B + 1 ? The calculation of S' from S and S", either S' = S + 1 or S' = S" – 1, only claims one inverter and some 2input multiplexers.

In much the same way as above, a twooutput adder can calculate S = A + B – 1, S' = A + B and S" = A + B + 1 by calculating two numbers X and Y such that X + Y = A + B + 2^{n} – 1 with a row of HA' cells, dual of the HA cell. An extra inverter deals with the 2^{n} . 
With four slight modifications, Sklansky's adder with a late carryin returns S = ½ A – B ½.

Let s_{a} and s_{b} be the sign of A and B respectively and M_{a} and M_{b} their
magnitude (absolute value). The addition of A and B is performed by the addition of M_{a} and M_{b}
if A and B have the same sign, and the subtraction otherwise. In any cases, the result S sign is the sign of the
addend with the larger magnitude. if (s_{a}Å s_{b}) then { M_{s} = M_{a} + M_{b} , s_{s}= s_{a} } else if M_{a} ³ M_{b} then { M_{s} = M_{a} – M_{b} , s_{s}= s_{a} } else { M_{s} = M_{b} – M_{a} , s_{s}= s_{b} } The adder in "Sign Magnitude" representation inherits from both the "adder/subtractor" and the "absolute value of the difference" operator. 
The horizontal line "feedback" controls the last row of modified "BK" cells (yellow) : if feedback = '2' then M_{s} = M_{a} + M_{b}; //identity: 'P' gives '0', 'G' gives '1' and 'K' gives '0' if feedback = '1' then M_{s} = M_{a} – M_{b}; //incr: 'P' gives '1', 'G' gives '1' and 'K' gives '0' if feedback = '0' then M_{s} = M_{b} – M_{a}; //invert: 'P' gives '1', 'G' gives '0' and 'K' gives '1' 
An adder delivers spontaneously a modulo 2^{n} sum. With a slight modification, the Sklansky's adder with a late carry delivers a modulo 2^{n} – 1 sum S.
In both cases we get S = ½ A + B ½ _{modulo (2}n_{– 1)}._{ }The condition is given by the carry out c_{n}: if c_{n} = 'K' then A + B < 2^{n} – 1, if c_{n} = 'P' then A + B = 2^{n} – 1, if c_{n} = 'G' then A + B > 2^{n} – 1. Therefore the "feedback" signal that controls the "+1" is '0' if c_{n} = 'K' and is '1' otherwise (just as before for absolute value). The yellow cells are the same as in the carrylate adder. 
The previous adder is used with two inputs X and Y such that X + Y = A + B + 2^{n} – 1 + c_{0}. A row of "HA' " cells carries on this addition propagationfree. The input_{ }carry c_{0} = '0'.
The horizontal "feedback" signal that controls the "+1" is the "nand" of x_{n} and (c_{n} = 'G' ). The result bit s_{n} is the "and" of x_{n} and (c_{n} = 'P'). 
The value range for A and B is from 0 to 2^{n}. The inputs bits a_{n} and b_{n} are missing
in the above adder. These two bits indicate whether A = 2^{n} and B = 2^{n} respectively. if A = 2^{n} and B = 2^{n} then ( A + B ) modulo 2^{n} + 1 = 2^{n} – 1. if A = 2^{n} and B < 2^{n} then A is rewritten ( 2^{n} – 1 ) + 1, all the a_{i} input bits are set to '1' as well as the input carry c_{0}. if A < 2^{n} and B = 2^{n} then B is rewritten ( 2^{n} – 1 ) + 1 thanks to the input carry c_{0}. 