[Top][All Lists]

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

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

From: Joerg Wunsch
Subject: Re: [avr-libc-dev] [bugs #12040] sbi in FAQ
Date: Tue, 1 Mar 2005 06:41:49 +0100
User-agent: Mutt/

As Erik Walthinsen wrote:

> >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

So it never happened before.  The previous sbi() macro was a wrapper
around the |= operation only anyway.  Your above demonstration is
actually one of the reasons why we removed that macro: because it gave
people the false feeling of getting an SBI instruction when it could
not actually guarantee that.

(The pre-2002 version of the sbi() macro, when the compiler could not
handle direct assignments to IO registers, would translate directly
into SBI instructions, but would have barfed about the above with
assembler errors most people could not have handled at all.)

> This insistence on people using the least readable form of all
> possible ways of doing bit manipulation because the compiler is
> really smart doesn't seem to have actual grounding.

If you find this the least readable form, then stop using C, or
complain to Brian Kernighan and Denis Ritchie for inventing the bit
manipulation macros that way.  Sorry.  Why did I never see that
complaint from anyone else but only from AVR developers?

You might blame Atmel for inventing bit names instead of bit masks
which is what most C programmers would have done, i.e. PORTB7 would
not have been defined to 7 but to 0x80.  My guess is they did it in
order to also cover assembler programming by the same names.  With bit
masks, we could have avoided all that 1<< cruft (aka. the _BV()

I agree that the move of twi.h has not been done appropriately, no
argument there.  I'm even not opposed for reverting that move

cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)

reply via email to

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