2025-03-02 19:34 UTC
@kenshirriff Adding two integers is slow, but multiply by 8 and subtracting 2x is fast? Why is subtraction faster than addition?
Replies (1)
-
@kenshirriff@oldbytes.space 2025-03-02 23:20
@http Subtraction is about as fast as addition; you complement the value and add it. The ×8 term is essentially free since you just multiply by one more in the next digit. Thus, subtracting ×2 is pretty quick. (These additions and subtractions would be slow if they used a regular adder, but instead they use a complicated 4:2 compressor adder tree, which I'll discuss at a later date.) https://oldbytes.space/@kenshirriff/114094310940711333