This is the mail archive of the 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]

On 10/25/06, Roger Sayle <> wrote:

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.

I like it as well. The only concern one could have is that we tie libgcc to the libc version used at gcc build time.

But it's only worth it to implement a -fstrict-math-errno to set errno even in
the cases the system libm doesn't.  Otherwise trading one function call for
another is not worth the hassle?


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