public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Joseph Myers <joseph@codesourcery.com>
To: Szabolcs Nagy <szabolcs.nagy@arm.com>
Cc: Wilco Dijkstra <Wilco.Dijkstra@arm.com>, <nd@arm.com>,
	"libc-alpha@sourceware.org" <libc-alpha@sourceware.org>
Subject: Re: Improving math function wrappers
Date: Thu, 16 Mar 2017 18:24:00 -0000	[thread overview]
Message-ID: <alpine.DEB.2.20.1703161816370.18031@digraph.polyomino.org.uk> (raw)
In-Reply-To: <58CAD45E.6050601@arm.com>

On Thu, 16 Mar 2017, Szabolcs Nagy wrote:

> On 16/03/17 14:29, Joseph Myers wrote:
> > On Thu, 16 Mar 2017, Wilco Dijkstra wrote:
> > 
> >> Given other languages don't even have the concept of errno, C99 doesn't 
> >> require it, and no application ever reads errno, it is inefficient to 
> >> force the use of the wrappers in almost all cases.
> > 
> > C99 not requiring it was an incompatible quiet change from C90.
> 
> i think glibc only has to set errno when user code is
> compiled with c89 compatibility and even then only for
> math functions that were defined in c89 and then only
> guarantee correct errno setting in default rounding mode
> (c89 code cannot access the fenv).

Incompatible quiet change means a good idea to implement the compatible 
mode ((math_errhandling & MATH_ERRNO) != 0) as far as possible.  Just like 
it's a good idea to avoid size_t wider than unsigned long.

Compilers for non-C languages without the concept of these functions 
setting errno can of course default to -fno-math-errno by default (and 
built-in no-errno functions that can be used with -fmath-errno is 
otherwise enabled would also be desirable for fma, sqrt, etc.).

> > (There may be cases where errno setting in the main implementations will 
> > require adding checks there not currently present, if e.g. the function 
> > does "return x - x;" in the non-finite argument case to return NaN and 
> > also raise "invalid" for Inf arguments - but such cases should not 
> > generally be significant for performance; the performance relevant cases 
> > are those involving finite arguments and results, not error cases or NaNs 
> > as arguments.)
> 
> i don't think setting errno in asm would be necessary,
> just turn "return x-x;" into "return specialcase1(x);"
> where specialcase1 is generic c code shared by targets,
> these are only called in cold code paths (if the errno
> setting is in a hot path then wrapper vs no wrapper
> does not make much difference and a wrapper can always
> be in c)

Whether the asm code calls a special-case function or __errno_location or 
sets TLS errno directly doesn't make much difference, you still need lots 
of target-specific checks for NaNs / overflow etc.  (Some cases may 
already be inside cold paths, some, e.g. overflow / underflow where the 
exception is implicit from the calculation but errno needs an extra check, 
may not, although the value to check should at least already be in a 
register.)

-- 
Joseph S. Myers
joseph@codesourcery.com

  reply	other threads:[~2017-03-16 18:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <AM5PR0802MB2610AA7EDC518B39F6D7152683260@AM5PR0802MB2610.eurprd08.prod.outlook.com>
2017-03-16 13:53 ` Wilco Dijkstra
2017-03-16 14:39   ` Joseph Myers
2017-03-16 14:41     ` Joseph Myers
2017-03-16 18:07     ` Szabolcs Nagy
2017-03-16 18:24       ` Joseph Myers [this message]
2017-04-04 17:25         ` Szabolcs Nagy
2017-04-04 17:34           ` Joseph Myers
2017-04-07 15:54           ` Szabolcs Nagy
2017-04-04 17:41         ` Zack Weinberg
2017-03-16 21:22   ` Florian Weimer
2017-03-16 21:36     ` Joseph Myers
2017-03-16 22:49       ` Wilco Dijkstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.20.1703161816370.18031@digraph.polyomino.org.uk \
    --to=joseph@codesourcery.com \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=libc-alpha@sourceware.org \
    --cc=nd@arm.com \
    --cc=szabolcs.nagy@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).