avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] [bugs #12040] sbi in FAQ


From: David Brown
Subject: Re: [avr-libc-dev] [bugs #12040] sbi in FAQ
Date: Tue, 1 Mar 2005 08:54:51 +0100

> > Should be removed or replaced with "The compiler optimizes '|=' to use
> > sbi when appropriate" (does he?)
>
> Just to clarify, no it does not (avr-gcc-3.4.3, as built by rod.info's
> script, aka a very recent stable compiler used by the vast majority of
> people actually making products):
>
>     4:test.c        ****   PORTB |= 0x03;
>    67                    .LM2:
>    68 0008 88B3                  in r24,56-0x20
>    69 000a 8360                  ori r24,lo8(3)
>    70 000c 88BB                  out 56-0x20,r24
>
> vs.
>
>     4:test.c        ****   PORTB |= 0x01;
>    67                    .LM2:
>    68 0008 C09A                  sbi 56-0x20,0
>     5:test.c        ****   PORTB |= 0x02;
>    70                    .LM3:
>    71 000a C19A                  sbi 56-0x20,1
>

All other arguments aside, this code shows clearly that avr-gcc *does*
produce the best code possible for bit manipulation, and *does* use cbi/sbi
*where appropriate*.  The first case here asks the compiler to set two bits
high at the same time, and it does that - something that cannot be expressed
with sbi/cbi.  The second case asks the compiler to set the bits one after
the other, and again it provides optimal correct code.  I can't see how the
compiler could produce anything better.






reply via email to

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