avr-libc-dev
[Top][All Lists]
Advanced

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

[avr-libc-dev] Definition of putchar/getchar causes code growth


From: Wouter van Gulik
Subject: [avr-libc-dev] Definition of putchar/getchar causes code growth
Date: Fri, 04 Jul 2008 12:07:51 +0200
User-agent: Thunderbird 2.0.0.14 (Windows/20080421)

Hi list,

Currently putchar is defined as
#define         putchar(__c)   fputc(__c, stdout)

which causes C code like this:
putchar(' ')

To generate assembler like this:
lds r22,__iob+2
lds r23,(__iob+2)+1
ldi r24,lo8(32)
ldi r25,hi8(32)
call fputc

This is 8 bytes (lds == 4 bytes) for loading the stream pointer.
If we change this to a "real" putchar call we would save 8 bytes per putchar call. the putchar call would then load the correct stream:

int putchar(int c)
{       
        return fputc(stdout, c);
}

The cycle penalty would be the extra call and return.
IMHO losing 7,8 or 10 cycles per call for a gain of 8 bytes per call seems very acceptable to me. Especially if it concerns functions like putchar and friends.

Other opinions? Otherwise I will file a bug report.

Wouter





reply via email to

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