avr-chat
[Top][All Lists]
Advanced

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

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


From: Jeff Epler
Subject: Re: [avr-chat] Atmega128, JTAG and ADC
Date: Sun, 17 Jul 2005 20:54:05 -0500
User-agent: Mutt/1.5.9i

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

Jeff

Attachment: pgpeGJZd7hcyw.pgp
Description: PGP signature


reply via email to

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