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: Dmitry K.
Subject: Re: [avr-libc-dev] [bugs #12040] sbi in FAQ
Date: Tue, 1 Mar 2005 18:24:43 +1000
User-agent: KMail/1.5

On Tuesday 01 March 2005 17:06, Erik Walthinsen wrote:
> John Altstadt wrote:
> > Out of curiosity on my part, why do you think that
> >    PORTB |= 0x03;
> > and
> >    PORTB |= 0x01;
> >    PORTB |= 0x02;
> > are equivalent statements?
>
> They either are or aren't depending on what register you're
> manipulating.  You are totally correct, in certain registers or in
> hardware where PORTB timings are critical, the effects would different.
>
> However, in the |= 0x03 case, the compiler read the register first,
> modifies it, then writes it out.  That can also cause improper operation
> and side effects depending on the register being accessed.
>
> So the question is can the compiler optimize the case where two bits are
> set or cleared by using sbi/cbi, without stomping on certain usages?  I
> can see that either method can cause problems, the question is which one
> is more potentially harmful vs. the instruction savings?
>
...
> Comments?

In case of 'PORTB |= 3' compiler MUST USE sequency, like 'in/or/out'.
Example: pins 0 and 1 are connected together to drive high current load.





reply via email to

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