This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Questions about the ATTRS field of builtins.def
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: roger at eyesopen dot com
- Cc: gcc at gcc dot gnu dot org, jsm28 at cam dot ac dot uk
- Date: Thu, 31 Jul 2003 23:38:20 -0400 (EDT)
- Subject: Re: Questions about the ATTRS field of builtins.def
- References: <Pine.LNX.4.44.0307311753100.16085-100000@www.eyesopen.com>
> From: Roger Sayle <roger@eyesopen.com>
>
> Hi Kaveh,
> > I'm trying to make sense of the ATTRS field in builtins.def. For the
> > math functions, I see several variants:
> >
> > 1. ATTR_CONST_NOTHROW_LIST
> >
> > 2. flag_unsafe_math_optimizations ? ATTR_CONST_NOTHROW_LIST
> > : ATTR_PURE_NOTHROW_LIST
> >
> > 3. flag_errno_math ? ATTR_NOTHROW_LIST
> > : (flag_unsafe_math_optimizations
> > ? ATTR_CONST_NOTHROW_LIST
> > : ATTR_PURE_NOTHROW_LIST)
> >
> > I understand 1 and I understand 3's errno check. What I don't
> > understand is number 2, or why 3 contains 2 in one of its clauses.
> > When is 2 necessary and why?
>
> I've been using the 2 form to model the effects of changing the
> rounding modes or other FPU control bits between calls. Hence,
> if -ffast-math, two calls to cos with the same argument are
> considered equivalent independent of mysterious function calls
> between them. When being "safe", however, we only consider cos
> to be const if there can't be a call to _setfpucw between them,
> treated as a mysterious write to memory, i.e. cos(x)*cos(x) is
> always safe. You can see how FPU state can be emulated by a
> hidden global variable, using the "pure" attribute.
Ah, ok got it, thanks. But it seems a bit obscure, IMHO this fact
could sure use a comment somewhere in the code. I'm going to try
defining macros for the different ATTR cases above to make the
builtins.def easier to read. Maybe these macros are a good place to
add some verbiage explaining this. (Care to help name the macros? :-)
> > I also see many discrepancies. E.g. "cos" uses 2, but "round" and
> > others use case 1. What makes "cos" need case 2? What's odd is that
> > the man page on x86-linux says "round" may set errno to EDOM so
> > shouldn't it (and perhaps others) use number 3?
>
> Yes, anthing that sets errno should use version 3. If FP rounding
> isn't a factor, there could even be an argument for a fourth version
> which is flag_errno_math ? NOTHROW : CONST_NOTHROW (i.e. a hybrid of
> of 1 and 3 rather than 2 and 3).
Yes, I'd guess that the place where this fourth ATTR case would be
appropriate is for rounding functions that ignore the mode and always
round a particular way. (?) Anywhere else?
> I hope this explains my understanding of the distinctions.
Yes, thank you.
> Thanks for the renaming of LONG_DOUBLE, btw.
> Roger
You're welcome!
--Kaveh
--
Kaveh R. Ghazi ghazi@caip.rutgers.edu