Re:XOR'ing a register with itself is the idiom for zeroing i...
by asQuirreL on Wednesday April 22, 2026 @04:27AM
(#47860698)
A carry lookahead adder makes your circuit depth logarithmic in the width of the inputs vs linear for a ripple carry adder, but that is still asymptotically worse than XORs constant depth.
(But this does not discount the fact that basically all CPUs treat them both as one cycle)
Re:XOR'ing a register with itself is the idiom for zeroing i...
by bonzini on Wednesday April 22, 2026 @09:14AM
(#47863132)
OF/CF/AF are always cleared anyway by SUB r,r. So there's absolutely no difference.
Re:XOR'ing a register with itself is the idiom for zeroing i...
by themafia on Wednesday April 22, 2026 @01:01PM
(#47866254)
The point is OF/CF are sometimes dependent on the inputs for SUB. They never are for XOR.
Re:XOR'ing a register with itself is the idiom for zeroing i...
by bonzini on Wednesday April 22, 2026 @02:09PM
(#47867142)
Ah, you mean in terms of complexity of the calculation. Thanks for clarifying.
In practice AF and CF can be computed from the carry out vector which is already available, and OF is a single XOR (of the two most significant bits of the carry out vector). The same circuitry works for XOR and SUB if the carry out vector of XOR is simply all zeroes.
https://en.wikipedia.org/wiki/Carry-lookahead_adder
The only minor difference between the two on x86, really, is SUB sets OF and CF according to the result while XOR always clears them.