News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Smallest way to cmp

Started by Ghirai, May 30, 2006, 01:11:24 PM

Previous topic - Next topic

Ghirai

Hey,

What's the smallest way (byte-wise) to do a cmp reg,0?
MASM32 Project/RadASM mirror - http://ghirai.com/hutch/mmi.html

hutch--

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Ossa

"or reg, reg" is the same size... and for some reason also seems to be used more often, speed maybe?

Ossa
Website (very old): ossa.the-wot.co.uk

Ghirai

MASM32 Project/RadASM mirror - http://ghirai.com/hutch/mmi.html

Ratch

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

Vortex

Some compilers ( at least VC++ ) are preferring test reg,reg

Ossa

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
Website (very old): ossa.the-wot.co.uk