I'm trying to port the following function for getting LSB into plain C:
static inline int LSB(uint64_t word)
{
int dummy1, dummy2, dummy3;
asm(" bsf %2, %0 " "\n\t"
" jnz 2f " "\n\t"
" bsf %1, %0 " "\n\t"
" jnz 1f " "\n\t"
" movl $64, %0 " "\n\t"
" jmp 2f " "\n\t"
"1: addl $32,%0 " "\n\t"
"2: " "\n\t"
: "=&q"(dummy1), "=&q"(dummy2), "=&q"(dummy3)
: "1"((int) (word >> 32)), "2"((int) word)
: "cc");
return (dummy1);
}
I need to get rid of the ASM code here so that I can use it in Android, i've tried a ton of possibilities but none of them seem to work.
I'm actually not completely sure what the above function does, from the name I suspect it's getting the least significant bit, though I may be wrong.
(Editor's note: yes, BSF = find the index of the lowest set bit; this whole thing emulates a 64-bit tzcnt
= trailing zero count, including returning 64 for the all-zero case which __builtin_ctzll
won't guarantee. The asm constraints are over-complicated: the dummy2, dummy3 outputs aren't needed, the high and low halves could be pure read-only inputs with "r"
constraints.)