mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Using float_t and double_t in math functions
Date: Wed, 8 May 2013 21:43:27 -0400	[thread overview]
Message-ID: <20130509014327.GA6338@brightrain.aerifal.cx> (raw)

Hi all,

Today I've been doing some experimenting on the relative math
performance of musl and glibc. After eliminating a lot of bogus
results (the gcc 4.4 on my test machine (x86) was causing musl's
configure to use -ffloat-store, which kills performance) things mostly
look good. Aside from sqrt (which is more costly on musl because
glibc's violates the requirement of correct rounding), everything I'm
testing seems faster, in some cases up to five times faster.

While debugging the slowdown from -ffloat-store, one thing I ran
across is that a lot of functions end up performing store/load pairs
to drop excess precision when storing intermediate results. The
situation is much worse with -ffloat-store, but persists with modern
gcc because of -fexcess-precision=standard, which is implied anyway by
-std=c99.

As far as I can tell, in most of the affected code, keeping excess
precision does not hurt the accuracy of the result, and it might even
improve the results. Thus, nsz and I discussed (on IRC) the
possibility of changing intermediate variables in functions that can
accept excess precision from float and double to float_t and double_t.
This would not affect the generated code at all on machines without
excess precision, but on x86 (without SSE) it eliminates all the
costly store/load pairs. As an example (on my test machine), it
dropped the cost of sinf(0.25) from 180 cycles to 130 cycles (glibc
takes 140 cycles, the main difference apparently being that glibc's
math library updates errno).

Unless there are objections, I think we should change float and double
intermediate variables in the implementations of math functions to
float_t and double_t, except where it's actually important to avoid
excess precision. Comments?

Rich


             reply	other threads:[~2013-05-09  1:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-09  1:43 Rich Felker [this message]
2013-05-09 13:21 ` Szabolcs Nagy
2013-05-09 14:57   ` Rich Felker
2013-05-09 19:14     ` Szabolcs Nagy
2013-05-09 16:02   ` Rich Felker

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=20130509014327.GA6338@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).