Optimisation problems when mixing asm with C++

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;
}
 
F

Frank Schmitt

Oliver Batchelor said:
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.

Please don't repost within 2 hours - Usenet isn't instant messaging, answers
can take hours or days to reach you.

Your question is OT in comp.lang.c++, you should try one of the gcc groups
or perhaps comp.lang.asm.x86

HTH & kind regards
frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top