XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
devblogs.microsoft.com
XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
1–10 of 231 posts
Re: XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
#2Re: XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
#3Re: XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
#4Probably, there are ALU pipeline designs where you don't pay an explicit penalty. But not all, and so XOR is faster.
Surely, someone as awesome as Raymond Chen knows that. The answer is so obvious and basic I must be missing something myself?
Re: XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
#5Re: XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
#6The obvious answer is that XOR is faster. To do a subtract, you have to propagate the carry bit from the least-significant bit to the most-significant bit. In XOR you don't have to do that because the output of every bit is independent of the other adjacent bits. Probably, there are ALU pipeline designs where you don't pay an explicit penalty. But not all, and so XOR is faster. Surely, someone as awesome as Raymond C…
Re: XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
#7The obvious answer is that XOR is faster. To do a subtract, you have to propagate the carry bit from the least-significant bit to the most-significant bit. In XOR you don't have to do that because the output of every bit is independent of the other adjacent bits. Probably, there are ALU pipeline designs where you don't pay an explicit penalty. But not all, and so XOR is faster. Surely, someone as awesome as Raymond C…
A tangent, but what is Obvious depends on what you know.
Often experts don't explain the things they think are Obvious, but those things are only Obvious to them, because they are the expert.
We should all kind, and explain also the Obvious things those who do not know.
Re: XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
#8The obvious answer is that XOR is faster. To do a subtract, you have to propagate the carry bit from the least-significant bit to the most-significant bit. In XOR you don't have to do that because the output of every bit is independent of the other adjacent bits. Probably, there are ALU pipeline designs where you don't pay an explicit penalty. But not all, and so XOR is faster. Surely, someone as awesome as Raymond C…
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.
Re: XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
#9The obvious answer is that XOR is faster. To do a subtract, you have to propagate the carry bit from the least-significant bit to the most-significant bit. In XOR you don't have to do that because the output of every bit is independent of the other adjacent bits. Probably, there are ALU pipeline designs where you don't pay an explicit penalty. But not all, and so XOR is faster. Surely, someone as awesome as Raymond C…
It could also be as a result of most people working in assembly being aware of the properties of logic gates, so they carry the understanding that under the hood it might somehow be better.
Re: XOR'ing a register with itself is the idiom for zeroing it out. Why not sub?
#10 Once an instruction has an edge, even if only extremely slight, that’s enough to tip the scales and rally everyone to that side.
And this, interestingly, is why life on earth uses left-handed amino acids and right-handed sugars .. and why left handed sugar is perfect for diet sodas.