public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: Joseph Myers <joseph@codesourcery.com>,
	Florian Weimer <fweimer@redhat.com>
Cc: Szabolcs Nagy <Szabolcs.Nagy@arm.com>,
	"libc-alpha@sourceware.org" <libc-alpha@sourceware.org>,
	nd <nd@arm.com>
Subject: Re: Improving math function wrappers
Date: Thu, 16 Mar 2017 22:49:00 -0000	[thread overview]
Message-ID: <AM5PR0802MB2610DC1E94506F5D8463EC5083260@AM5PR0802MB2610.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1703162127040.6157@digraph.polyomino.org.uk>

Joseph Myers <joseph@codesourcery.com> wrote:

> Code in glibc's libraries should already be setting the TLS initial-exec 
> errno variable directly (that's how __set_errno is defined in 
> include/errno.h).  But any case that sets errno should not be 
> performance-critical; the issue is the effects on performance of non-error 
> cases with finite arguments (which should just be checking if the result 
> is non-finite or zero, depending on the function - but the issue raised 
> here was consequent need to save the arguments for subsequent checks in 
> the unlikely case to see whether e.g. a NaN result was an error or from a 
> NaN argument, and it's possible the code in the error case might have 
> other prologue/epilogue effects that don't get shrink-wrapped away).

Setting errno is not in any way performance critical indeed - even a function
call would be fast enough. It is cases like this that show up as having a high
overhead:

double
__pow (double x, double y)
{
  double z = __ieee754_pow (x, y);
  if (__glibc_unlikely (!isfinite (z)))
     ...
  else if (__builtin_expect (z == 0.0, 0)
	   && isfinite (x) && x != 0 && isfinite (y)
	   && _LIB_VERSION != _IEEE_)
     ...

This means saving and restoring x and y across the call (ie. setting up a stack
frame with 3-4 callee-saves) and 2 if statements on the critical path - all
completely unnecessary.

Inlining __ieee754_pow would help but still keep the extra checks - so moving
them into existing checks for special cases is best if we can't remove errno support.

> If we set errno in some main function implementations I think we should be 
> clear that adding a wrapper is still a fine way to fix one of the 
> remaining bugs about missing errno setting in cases where 
> architecture-specific implementations are involved, with the option of 
> optimizing later by moving away from that wrapper.

Yes, we'd still have to keep the wrapper if there are any targets that require it.
It could be removed once such code has been updated or if the generic
implementation ends up faster (quite likely given this happened for several string
functions)...

Wilco
    

      reply	other threads:[~2017-03-16 22:49 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
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 [this message]

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=AM5PR0802MB2610DC1E94506F5D8463EC5083260@AM5PR0802MB2610.eurprd08.prod.outlook.com \
    --to=wilco.dijkstra@arm.com \
    --cc=Szabolcs.Nagy@arm.com \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=nd@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).