Is there branchless way to clear 32-bit register depending on status register state? It can be achieved using additional clear register and CMOVcc, but it is too expensive on x86 in 32bit mode for me. Sadly CMOVcc have no version with immediate operand. Reading from memory is also bad variant.
There is SETcc (though, operand is 1 byte) but not "CLEARcc" instruction on x86.
This may disappoint you, but
CMOVccis very good in that regard. Using it with a variableddZEROwith the value0is not that bad, especially in a loop.resets the
rTargetregister to zero if theccconditions are met.Otherwise (there is an otherwise) you can invert the scenario and
CMOVccon a NOT MATCHING condition. Which choice would be better depends on the frequency of the occurrence.If you have a register with the value
0you should use that instead. But if you can't spare a register using a (cached) memory location is not that bad. This estimation is based on experience and IIRC using a constant in a L1 cached memory location has a practically negligible latency in a loop.