#ARM Cortex-M3 added a CLZ #bitmanip instruction, but this is an #asm version of it for more primitive ARMs.
on 02025-09-09The CLZ #asm #bitmanip instruction is __builtin_clz on GCC, but this page claims to have a 13-instruction-time version with better #performance than all the “Hacker’s Delight” entries, with “[bisection] to find out which 8-bit chunk of the 32-bit number contains the first 1-bit, which is followed by a lookup table clz_lkup[] to find the first 1-bit within the byte.” Handy for Cortex-M0 #ARM chips without the instruction.
#ARM CPUs (bigger than Cortex-M0 or Cortex-M0+) have a CLZ #bitmanip instruction to count the number of leading zeroes, and CMSIS-CORE has a __CLZ intrinsic function for when you aren’t in #asm. Also signed saturate, unsigned saturate, rotate right with extend, wait for event, etc.
#amd64 #asm instruction TZCNT or BSF counts the number of trailing zeroes. #bitmanip
on 02025-09-09