Addition is implemented in computers using a circuit of logic gates.
Do we know what is the lowest depth circuit possible for 64bits? And is it used in practice?
Addition is implemented in computers using a circuit of logic gates.
Do we know what is the lowest depth circuit possible for 64bits? And is it used in practice?
Lookup carry-select adder. An n-bit carry-select adder produces two outputs x+y and x+y+1. For a 64 bit adder, you use two 32-bit carry select adders. The lower 32 bits of the output are either xlo+ylo or xlo+ylo+1. You take the carry of the result, then the higher 32 bits are xhi+yhi or xhi+yhi+1.
You do this recursively taking a depth of c*n levels. Other operations like subtraction, min, max, shift operations take equally long. Logical operations take a constant number of levels.
You can add three 64 bit numbers with cn + d levels instead of 2cn levels, for some small constant d.
Now a few more details: You must likely build all your logic using nand-gates. For example a two bit carry-select adder has four input bits and six output bits. If you try to implement this with NAND-gates, you may find that you can get the same result if one or two inputs arrive later. Or that you produce one or two outputs a bit later. If you are clever and/or lucky you can match these bits from different rounds and get the speed.
For the time taken, you don’t just count the depth of the circuit. Usually there are different implementations of the basic logic that take different time at different cost. So 13 levels with an expensive implementation may be just as fast as 12 levels with a cheaper implementation.
And in a clocked CPU (in practice every CPU) someone decides in the cycle time. Then any operation below the cycle time takes one cycle, anything above that must likely be split. Make the cycle time longer, and more different operations can run in one cycle. Make it shorter, and all single cycle operations are faster, but there are more operations that don’t work in a single cycle. Make it just a little bit shorter, and there will be more operations that can run in a single cycle with a more expensive implementation. Picking the optimal point is hard.
lea
instruction in x86-64) with a delay of 15 FO4.
$\endgroup$