This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Count Leading Zeros?

Expert 1215 points

Hi,

Is there an instruction or function in rts or fastmath lib for Counting Leading Zeros, like CLZ on ARM9?

Thanks

 

  • The closest thing I know about is a "norm" instruction that is more like "count leading sign bits".  It's documented in sprufe8.  The corresponding intrinsic to use this instruction from C would be unsigned _norm(int src2) as documented in spru187.

  • The LMBD assembly instruction and _lmbd() C intrinsic are the "Leftmost Bit Detection" instruction. This will tell you how many bits to skip from the left-hand or Most Significant end of a 32-bit source register to reach the bit value you seek. This can be done to get the number of leading 0s or the number of leading 1s.

    To understand more detail about the instruction and how to use it, please refer to the "CPU & Instruction Reference Guide" for the processor you are using.