Hey,
What's the smallest way (byte-wise) to do a cmp reg,0?
Try "test reg, reg".
"or reg, reg" is the same size... and for some reason also seems to be used more often, speed maybe?
Ossa
Thanks :bg
Ossa,
Every time I see OR REG,REG used for a test, I ask if the CPU's are smart enough to avoid writing back into the register when it doesn't have to do so. If not, it is going to take longer to do the write than TEST REG,REG which does not involve a write. So far, no one has given me a definitive answer. Ratch
Some compilers ( at least VC++ ) are preferring test reg,reg
Quote from: Ratch on May 31, 2006, 12:00:59 AM
Ossa,
Every time I see OR REG,REG used for a test, I ask if the CPU's are smart enough to avoid writing back into the register when it doesn't have to do so. If not, it is going to take longer to do the write than TEST REG,REG which does not involve a write. So far, no one has given me a definitive answer. Ratch
It seems that you are right, from the Intel Optimisation Manual (for and, not or, but I should imagine the same things apply):
QuoteUse test when comparing a value in a register with zero. Test essentially ands the operands together without writing to a destination register. Test is preferred over and because and produces an extra result register. Test is better than cmp ..., 0 because the instruction size is smaller.
Ossa