I would like to avoid jmp instructions and use the CMOV instruction in the following code : Method 1 : .IF ( eax > Memory32 ) mov Memory32, eax .ENDIF Method 2 : cmp eax, Memory32 cmova eax, Memory32 mov Memory32, eax What's better in terms of pipeline stall, branch predictions, etc... ? Thanks
It's a Conditional Move if Above. Here is an extract from the Intel manual :
The CMOVcc instructions check the state of one or more of the status flags in the EFLAGS register (CF, OF, PF, SF, and ZF) and perform a move operation if the flags are in a specified state (or condition). A condition code (cc) is associated with each instruction to indicate the condition being tested for. If the condition is not satisfied, a move is not performed and execution continues with the instruction following the CMOVcc instruction.The instruction is only available when you use the .586 directive.
I dunno what is fastest in your case. But the conditional move instructions can definitely speed up your code. I got a very large improvement in a brute-forcer I wrote once, about 2-3 times speed increase or so - the conditional jumps were the major bottlenecks.
not all Pentium CPUs support the CMOVcc instructions. Does anybody know, which do and which not? And what about these rare clones, like Cyrix or IDT?
IIrc, PPro and upwards support the conditional move instructions. And I think CPUID is supposed to tell you if the CPU supports it.
Use the CPUID instruction to check if the CPU supports CMOV instruction.