| ▲ | dreamcompiler 5 hours ago | |
I vaguely remember we used the XOR trick on processors other than Intel, so it may not be Intel-specific. In principle, sub requires 4 steps: 1. Move both operands to the ALU 2. Invert second operand (twos complement convert) 3. Add (which internally is just XOR plus carry propagate) 4. Move result to proper result register. This is absolutely not how modern processors do it in practice; there are many shortcuts, but at least with pure XOR you don't need twos complement conversion or carry propagation. Source: Wrote microcode at work a million years ago when designing a GPU. | ||
| ▲ | bonzini 2 hours ago | parent | next [-] | |
You don't do twos complement negation for sub in an integer ALU. You do ones complement (A + ~B) and set the input carry to 1. The difference is that you don't need two carry propagations and therefore you can just add a fancy A + ~B function to the ALU. Floating point is different because what matters is same sign or different sign (for same sign you cannot have cancellation and the exponent will always be the same or one than the largest input's. So the FP mantissa tends to use sign magnitude representation. | ||
| ▲ | rep_lodsb 2 hours ago | parent | prev [-] | |
These two steps usually run in parallel though, with transistors to enable them depending on what operation should be performed. | ||