[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: [rtl] Optimization question.
On Sun, 12 Jul 1998, Oleg Subbotin wrote:
> Hello, everybody.
> I have this tiny example :
>
> #define ONE 0x01
>
> int fun ()
> {
> volatile register temp=0;
>
> while ( temp&ONE ) {
> /* Do something */
> }
> }
>
This does exactly what you told it to. temp&ONE means you wanted to AND
them binary bit by bit, What I think you may have wanted to do is a
temp&&ONE which is a logical AND.
Randal
> And when I compile it with gcc -O2 -S I get this assembly code:
>
> fun:
> pushl %ebp
> movl %esp,%ebp
> subl $4,%esp
> movl $0,-4(%ebp)
> .align 4
> .L2:
> movl -4(%ebp),%eax
> testb $1,%al <--Instead of logical AND gcc generate testb
> jne .L2 <--But for test==3,5,7... it will not work
> leave <--as I expect it to
> ret
>
> Does anybody knows how to avoid this?
> I absolutely have to compile the program with -O2 flag, but with this
> "optimization" my program does not work. I am also very surprized by my
> discovery - this type of code is all over the Linux code, but it still
> works.
>
> Thanks for any help.
>
> Oleg.
>
> --- [rtl] ---
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/
>
--- [rtl] ---
For more information on Real-Time Linux see:
http://www.rtlinux.org/