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
Posted on 2001-05-16 16:30:00 by karim
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.
Posted on 2001-05-16 16:53:00 by karim
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.
Posted on 2001-05-17 02:19:00 by f0dder
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?
Posted on 2001-05-17 07:46:00 by beaster
IIrc, PPro and upwards support the conditional move instructions. And I think CPUID is supposed to tell you if the CPU supports it.
Posted on 2001-05-17 09:33:00 by f0dder
Use the CPUID instruction to check if the CPU supports CMOV instruction.
Posted on 2001-05-17 09:35:00 by karim