help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with inline assembly and -O2 or -O3


From: Guy Harrison
Subject: Re: Problem with inline assembly and -O2 or -O3
Date: Wed, 11 Aug 2004 01:00:27 GMT
User-agent: KNode/0.7.7

Jeremy Friesner wrote:

> Hi all,
> 
> I have a problem with some simple inline assembly -- I wrote a function to
> byte swap a 64-bit integer under x86, but it only works when compiled with
> -O0 or -O1.  When compiled with -O2 or -O3, it gives the wrong result.  Is
> this a compiler bug or have I done something wrong?

Philosophy ;-)

If you're gonna hand-code asm why let an optimiser anywhere near it? Either
write it in C/C++ and let the optimiser loose or "don't" to both.

> I'm using gcc/g++ 3.3.3 on a dual P3 under SUSE 9.1, FWIW.
> 
> Here is the correct output I get when compiling with -O0 or -O1:
> 
> $ ./swap
> Test completed successfully.
> 
> and here is the (unexpected) output I get when compiling with -O2 or -O3:
> 
> $ ./swap
> Error!  backagain=0 orig=1
> 
> And finally, here is the test program that demonstrates the problem... can
> anyone give me a suggestion?

Pass -S and look at the resultant *.s file. Optimisations flags you pass in
will be reflected in the output. I'm sure the cause will be blindly obvious
(to you, I'm an x86 ignoramus!).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]