I'd like to port my existing source code of chess to work on Linux using GCC.
The problem is with inline assembler code for LSB routine.
The following code works properly only in Debug mode.
If I use some kind of optimization, the result of routine is bogus:
- in Release build routine always returns 0;
- if I force inlining with __inline__ __attribute__((always_inline)) ), the result of the routine is random.
Here is the code:
Code: Select all
int LSB(unsigned long long arg1)
{
int hword = (int)(arg1 >> 32);
asm(
"bsfl %0,%%eax \n\t"
"jnz 1f \n\t"
"bsfl %1,%%eax \n\t"
"addl $32,%%eax \n\t"
"1: \n\t"
:
:"m"(arg1),"m"(hword)
:"%eax");
}