This is the mail archive of the
mailing list for the GCC project.
Re: Patch to add __builtin_printf
- To: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Subject: Re: Patch to add __builtin_printf
- From: Todd Vierling <tv at pobox dot com>
- Date: Tue, 19 Sep 2000 13:23:30 -0400 (EDT)
- cc: gcc-patches at gcc dot gnu dot org
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 (firstname.lastname@example.org)