This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: nexttoward/nextafter attribute question
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Steve Ellcey <sellcey at cavium dot com>
- Cc: gcc <gcc at gcc dot gnu dot org>
- Date: Mon, 11 Dec 2017 22:34:12 +0000
- Subject: Re: nexttoward/nextafter attribute question
- Authentication-results: sourceware.org; auth=none
- References: <1513025974.23303.44.camel@cavium.com>
On Mon, 11 Dec 2017, Steve Ellcey wrote:
> the attribute. The other is why the function would be pure with
> -fno-math-errno but const otherwise. I would think that the -fno-math-errno
> version would be const (stricter than pure) since it is not setting
> errno. Finally, how can I check if -frounding-mode is set in the compiler
Using -fno-math-errno does not mean that a function does not set errno; it
means that it's not required to set errno. If it does set errno (in a
case where permitted to do so), it's not const or pure and using those
attributes is not valid. Those attributes would imply that a read of
errno before a call to the function could be moved after the call to the
function, which is not true for these functions.
This is generally the case for more libm function than just these ones -
it's incorrect and unsafe to have const / pure attributes on them for
-fno-math-errno. (It's safe if a particular implementation guarantees as
part of its ABI that the function will never set errno - or if GCC will
always inline the function for -fno-math-errno, as with sqrt on some
architectures but not all. And of course many libm functions do not have
any domain / range / pole errors so should never set errno at all and can
safely be considered const / pure.)
Separately, specifically for the nextafter and nexttoward functions, Annex
F specifies that they are independent of the rounding mode. Thus it is
not correct for anything about those functions' attributes to depend on
-frounding-math.
--
Joseph S. Myers
joseph@codesourcery.com