Why Multiplication Is More Expensive Than Addition
Addition combines two numbers in a single pass through an adder circuit. Multiplication is fundamentally different: mathematically, multiplying two numbers is equivalent to performing a series of additions and bit shifts, which means multiplication hardware must either repeat simpler operations multiple times or use significantly more complex circuitry to do the work in fewer steps.
The Basic Multiplication Algorithm
The conceptual algorithm hardware follows mirrors the same process taught for decimal long multiplication, but using binary digits instead of decimal ones.
- Examine each bit of the
Multiplier, one at a time, starting from the least significant bit. - If that bit is 1, add a shifted copy of the
Multiplicandto a running total called theProduct. - If that bit is 0, no addition is needed for that step, but the multiplicand is still shifted left in preparation for the next bit.
- Repeat this process for every bit of the multiplier, accumulating the result in the product.
A simplified illustration using small 4-bit values:
Multiplicand: 0010 (2)
Multiplier: 0011 (3)
Step 1 (bit 0 = 1): Product += 0010
Step 2 (bit 1 = 1): Product += 0010 shifted left by 1 (0100)
Result: 0010 + 0100 = 0110 (6)Why the Result Needs Double the Bit Width
Multiplying two n-bit numbers can produce a result requiring up to 2n bits to represent without losing information. For example, multiplying two 32-bit values can require a full 64-bit result. This is why processors either produce a wider result register for multiplication or provide separate instructions to retrieve the upper and lower halves of a multiplication result separately.
Signed Multiplication
When multiplying Signed Numbers represented in two's complement, the sign of the result follows ordinary mathematical rules: multiplying two values with the same sign produces a positive result, while multiplying values with different signs produces a negative result. Hardware handles this correctly by working with the two's complement representation directly throughout the multiplication process, rather than needing a completely separate circuit for signed values.
Why This Matters for Software Performance
Because multiplication requires more hardware steps than addition, it is generally a slower operation on most processors. This is part of the reason why compilers apply optimizations such as replacing multiplication by a power of two with a simple bit shift, and why performance-critical code sometimes structures calculations to minimize the number of multiplication operations needed.