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]
Other format: [Raw text]

Re: [RFC Patch]: Implement remainder() as built-in function [PR fortran/24518]


Hi Mike,

On Tue, 24 Oct 2006, Mike Stump wrote:
> :-)  Seems like we could autoconf for it.  If #include <math.h> has a
> #define for it, we can do something like:
>
>    #include <math.h>
>    __set_errno(int i) { errno = i; }
>
> in libgcc.

Now that's clever!  The middle-end has traditionally had a problem
with pseudo-global variables in libc, such as errno which are often
#defined to do wierd things with thread local storage etc...  I'd
always imagined we'd have to do something tricky with target backends
specifying the appropriate RTL to access these symbols.   But by adding
shallow/cheap accessor functions to libgcc, you've finessed the issue!

One obvious use of this scheme would be:

#include <stdio.h>
FILE *__get_stdout() { return stdout; }

The middle-end currently has no-way of manipulating the standard
streams "stdin", "stdout" and "stderr".  This is particularly
difficult as "stdout" is #defined as iobuf[0] on some platforms,
and as _impure_ptr->_stdout on others, etc...

Because of this, the middle-end can't transform printf("hello")
into fputs("hello",stdout), even though it can currently transform
printf("hello\n") into puts("hello"), and can even simplify
fprintf(fp,"hello") into fwrite("hello", 1, 5, fp).  Notice,
the first requires us to materialize stdout, whereas the latter
two don't.


It's a very cool solution.  I'm impressed.

Roger
--


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