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*: Roger Sayle <roger at eyesopen dot com>
*To*: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
*Cc*: gcc at gcc dot gnu dot org, <jsm28 at cam dot ac dot uk>
*Date*: Thu, 31 Jul 2003 18:05:37 -0600 (MDT)
*Subject*: Re: Questions about the ATTRS field of builtins.def

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.
> 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).
I hope this explains my understanding of the distinctions.
Thanks for the renaming of LONG_DOUBLE, btw.
Roger
--