I was messing around with the TSCP inline code for the first bit set:
- Code: Select all
__inline int first_one(u64 bits)
{
__asm
{
mov edx, 0
bsf eax, dword ptr bits
jnz done
mov edx, 32
bsf eax, dword ptr bits+4
jnz done
mov eax, 32
done: add eax, edx
}
}
and trying to port it into GCC inline asm code so I could compile it under Cygwin's GCC. This is what I've got:
- Code: Select all
int first_one(TBitBoard bitboard) {
int idxBit = -1;
asm(" bsfl %1, %0 \n\t" // bsf eax, dword ptr b
" jnz done \n\t" // jnz done
" movl $0x20, %2 \n\t" // mov edx, 32
" bsfl 4(%1), %0 \n\t" // bsf eax, dword ptr [b+4]
" jnz done \n\t" // jnz done
" movl $0x20, %0 \n\t" // mov eax, 32
"done: add %2 , %0 \n\t" // add edx, eax
: "=r" (idxBit) // out reg: %0=idxBit
: "r" (bitboard), "r" (0) // in regs: %1=bitboard, %2=0
: "cc" // I mess with conditions codes
);
return idxBit;
}
Quite obviously it didn't work. Now can anyone please tell me why?
Thanks!