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: [PATCH v3] Change default to -fno-math-errno


On Thu, Oct 4, 2018 at 9:43 PM Joseph Myers <joseph@codesourcery.com> wrote:
>
> On Thu, 4 Oct 2018, Jeff Law wrote:
>
> > > I doubt you could prove that without LTO of the whole program because an
> > > errno value set by a libm function call could always be checked in the
> > > caller of whatever function is being compiled.
> > Right, but if you have a series of calls like
> >
> >
> >   t1 = sqrt (x);
> >   t2 = sqrt (y);
> >   t3 = sqrt (z);
> >   return t1 + t2 + t3;
> >
> > You know that errno from the first two isn't examined and you could emit
> > the hardware insn for sqrt in those cases.  You couldn't do so for the
> > 3rd because you don't necessarily have the caller context.
>
> No, you don't know that error from the first two isn't examined.  sqrt
> doesn't set errno on success.  A caller could set errno to 0 before that
> code, then check for errno == EDOM afterwards, meaning that any of the
> sqrt arguments were negative.  (The caller could also check whether the
> result is a NaN and so not need errno, of course.)

So I think it would be fine if we'd have -fno-math-errno as documented
and then the C library would annotate their math functions according
to whether they will ever set errno or not.  Once a math function is
const or pure it cannot ever set errno so -fno-math-errno shouldn't have
any effect.

Then a C library could say that if a user says -D_I_NEED_NO_ERRNO_FROM_MATH
then it could redirect to appropriate functions?

Just assuming that the latter is easier for the library itself than
from the compiler.

glibc has the ieee entry points but I'm not sure if it has any way
to use those by default.

Richard.

> --
> Joseph S. Myers
> joseph@codesourcery.com


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