[Top][All Lists]

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

RE: [avr-chat] Atmega128, JTAG and ADC

From: Larry Barello
Subject: RE: [avr-chat] Atmega128, JTAG and ADC
Date: Sun, 17 Jul 2005 19:34:25 -0700

What may be true of a low I/O register might not be for a high one (e.g. >
32 IIRC).  CPU registers are handled similarly to low I/O registers.  I/O >
32 (64 if memory mapped) cannot use bit tests directly and will reduce to an
in/and/test sequence.  I/O > $100 can't even use the in/out instructions and
HAVE to be accessed as SRAM and will show up as lds/and/test sequence.

For all cases, I believe comparing to non-zero or zero will be the most
efficient for all the possibilities.

However it is entirely possible that the compiler "knows" about the ((A  &
bit) == bit) construct and always uses the most efficient operation

There are plenty of constructs that the compiler doesn't catch (like your
obvious one, below!).  I find it best to not stress the optimizer if I know
a more efficient (generic) way to do things.


-----Original Message-----
From: Jeff Epler [mailto:address@hidden
Sent: Sunday, July 17, 2005 6:54 PM
To: Larry Barello
Cc: Brian Dean; address@hidden
Subject: Re: [avr-chat] Atmega128, JTAG and ADC

On Sun, Jul 17, 2005 at 04:39:58PM -0700, Larry Barello wrote:
> BTW Testing for zero/non-zero takes less code than comparing to an
> bit value...

With avr-gcc 3.3.2, -Os, all these variations compile to the same thing,
using an `sbrc' instruction.
    extern void p1(void);
    extern void p2(void);

    void f1(unsigned char c) {
        if((c & 8) != 8) p1(); else p2();

    void f2(unsigned char c) {
        if((c & 8) == 0) p1(); else p2();

    void f3(unsigned char c) {
        if(!(c & 8)) p1(); else p2();

Example disassembly:
   0:   83 fd           sbrc    r24, 3
   2:   02 c0           rjmp    .+4             ; 0x8
   4:   00 d0           rcall   p1
   6:   08 95           ret
   8:   00 d0           rcall   p2
   a:   08 95           ret

I think the best code would actually be
   0:   83 fd           sbrc    r24, 3
   2:   00 d0           rjmp    p2
   4:   00 d0           rjmp    p1
but avr-gcc misses it by a factor of 2.  Do newer versions do any better?  I
know 3.3.2 is a bit old by now.


reply via email to

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