O
Oliver Batchelor
Hi,
I have a function which I make use of assembler in order to do a bit scan
search on 64 bit numbers (Ie.. find the first 1 bit). It's used as a static
c++ function.
It works all the time without compiler optimisations. It seems to work
all of the time when I test it with optimisations (-O1 to -O3) on but
fails somewhere in practical use.
I've played around with __attribute__ ((noinline)) and some seem to help a
little but all fail for -O2 upward etc..
I've searched around and see no simple answer - gcc seems to have no way of
turning off optimisations for the function..
Has anyone ideas about how this sort of thing can be solved? (I've chucked
the code below)
Thanks,
Oliver Batchelor
Here's the code I'm using:
static int firstSet (bitboard &b) {
int position = 0;
asm volatile (
"bsf (%%edx), %%eax \n"
"jnz 1f \n"
"bsf 4(%%edx), %%eax \n"
"add $32, %%eax \n"
"jnz 1f \n"
"mov $0, %%eax \n"
"1: \n"
: "=a" (position)
: "d" (&b));
return position;
}
I have a function which I make use of assembler in order to do a bit scan
search on 64 bit numbers (Ie.. find the first 1 bit). It's used as a static
c++ function.
It works all the time without compiler optimisations. It seems to work
all of the time when I test it with optimisations (-O1 to -O3) on but
fails somewhere in practical use.
I've played around with __attribute__ ((noinline)) and some seem to help a
little but all fail for -O2 upward etc..
I've searched around and see no simple answer - gcc seems to have no way of
turning off optimisations for the function..
Has anyone ideas about how this sort of thing can be solved? (I've chucked
the code below)
Thanks,
Oliver Batchelor
Here's the code I'm using:
static int firstSet (bitboard &b) {
int position = 0;
asm volatile (
"bsf (%%edx), %%eax \n"
"jnz 1f \n"
"bsf 4(%%edx), %%eax \n"
"add $32, %%eax \n"
"jnz 1f \n"
"mov $0, %%eax \n"
"1: \n"
: "=a" (position)
: "d" (&b));
return position;
}