avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Question about code size


From: Joerg Wunsch
Subject: Re: [avr-gcc-list] Question about code size
Date: Sat, 17 Mar 2007 07:55:30 +0100 (MET)

"Dave Hylands" <address@hidden> wrote:

> 3.4.4 avr-gcc -Os -mshort-calls -mmcu=atmega168

> 4.2.0 produced:

GCC 4.1.1 expands it to:

..global getNch
        .type   getNch, @function
getNch:
/* prologue: frame size=0 */
        push r16
        push r17
/* prologue end (size=2) */
        mov r16,r24
        tst r24
        breq .L5
        ldi r17,lo8(0)
..L4:
        call getch
        subi r17,lo8(-(1))
        cp r16,r17
        brne .L4
..L5:
/* epilogue: frame size=0 */
        pop r17
        pop r16
        ret
/* epilogue end (size=3) */
/* function getNch size 14 (9) */

> The numbers are the size in bytes of the .text section for the
> function above. It appears that the compiler is promoting the
> unsigned char's to ints.

It has to do this internally, but it correctly removed the high byte
handling in all three compiler versions then, as it does not
contribute to the result.  Your disassembled code is a bit misleading,
as it does not fill in the relocatable offsets of the branches
correctly.  The difference between 4.1.x and 4.2.0 is that in your
version, instead of immediately testing the loop count against 0, it
jumps to the end of the loop first.  This is probably the consequence
of using -Os, as it is correct that way: it takes more time but one
less instruction.

The major difference is that it no longer recognizes it could reorder
the loop counter to count down rather than up.  If you manually
reorder the loop like this:

unsigned char getch(void);
void getNch(unsigned char count)
{
    for(;count > 0; count--)
        getch();
}

....you get the same result as in 3.x.

Would that be considered an optimization already that is worth a GCC
bug report?

> Aside: I've just moved my development platform from Windows to
> linux.  Where would I go to get the latest patches for
> gcc/binutils/et al.?

See Bingo600's script, it's referenced in a "sticky" article on top of
the AVR-GCC forum of http://www.avrfreaks.net/ .

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