This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Patch to add __builtin_printf


On Tue, 19 Sep 2000, Kaveh R. Ghazi wrote:

: This patch adds __builtin_printf.  It uses the same mechanism for
: obtaining the FUNCTION_DECL for the replacements as does builtin
: fputs, namely declare stub replacement builtins and cache the result.

Would it be possible to do similar replacements for fprintf?

: printf("%s\n", foo) -> puts(foo)
: printf("%c", foo) -> putchar(foo)
: printf("c") -> putchar('c')  (where `c' is any one character.)

fprintf(file, "%s", foo) -> fputs(foo, file) [*]
fprintf(file, "%c", foo) -> fputc(foo, file) [**]
fprintf(file, "c") -> fputc('c', file) [**]

[*] fprintf(file, "%s", foo) is used in so much code that I tend to wonder
    where these people learned to program.  8^)  That much aside, this
    optimization alone would be a wonderful addition.  Note that there is
    no \n in ths format string.  If desired, an additional optimization for
    "%s\n" could consist of a builtin_fputs followed by a builtin_fputc,
    likely still faster than the fprintf.

[**] Though not as fast as the typical macro putc() due to the function call
     overhead, fputc() is quicker than fprintf() in these cases, and the
     function call was there to begin with anyway.  If a builtin fputc()
     takes over at this point, that's an added bonus.

-- 
-- Todd Vierling (tv@pobox.com)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]