Unfortunately, even x86-64 implementations can differ – from Intel’s instruction set reference,BSF
and BSR
, with a source operand value of (0)
, leaves the destination undefined, and sets the ZF
(zero flag). So the behaviour may not be consistent between micro-architectures or, say, AMD and Intel. (I believe AMD leaves the destination unmodified.)
The newer LZCNT
and TZCNT
instructions are not ubiquitous. Both are present only as of the Haswell architecture (for Intel).