How does a 32 bit processor support 64 bit integers?

Most processors include a carry flag and an overflow flag to support operations on multi-word integers. The carry flag is used for unsigned math, and the overflow flag for signed math.

For example, on an x86 you could add two unsigned 64-bit numbers (which we’ll assume are in EDX:EAX and EBX:ECX) something like this:

add eax, ecx  ; this does an add, ignoring the carry flag
adc edx, ebx  ; this adds the carry flag along with the numbers
; sum in edx:eax

It’s possible to implement this sort of thing in higher level languages like C++ as well, but they do a lot less to support it, so the code typically ends up substantially slower than when it’s written in assembly language.

Most operations are basically serial in nature. When you’re doing addition at the binary level, you take two input bits and produce one result bit and one carry bit. The carry bit is then used as an input when adding the next least significant bit, and so on across the word (known as a “ripple adder”, because the addition “ripples” across the word).

There are more sophisticated ways to do addition that can reduce that dependency between one bit and another when a particular addition doesn’t produce a dependency, and most current hardware uses such things.

In the worst case, however, adding 1 to a number that’s already the largest a given word size supports will result in generating a carry from every bit to the next, all the way across the word.

That means that (to at least some extent) the word width a CPU supports imposes a limit on the maximum clock speed at which it can run. If somebody wanted to badly enough, they could build a CPU that worked with, say, 1024-bit operands. If they did that, however, they’d have two choices: either run it at a lower clock speed, or else take multiple clocks to add a single pair of operands.

Also note that as you widen operands like that, you need more storage (e.g., larger cache) to store as many operands, more gates to carry out each individual operation, and so on.

So given identical technology, you could have a 64-bit processor that ran at 4 GHz and had, say, 4 megabytes of cache, or a 1024-bit processor that ran at about 250 MHz and had, perhaps, 2 megabytes of cache.

The latter would probably be a win if most of your work was on 1024-bit (or larger) operands. Most people don’t do math on 1024-bit operands very often at all though. In fact, 64-bit numbers are large enough for most purposes. As such, supporting wider operands would probably turn out to be a net loss for most people most of the time.

Leave a Comment