mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [musl] Q: dealing with missing removal of excess precision
Date: Sun, 22 Mar 2020 15:10:19 -0400	[thread overview]
Message-ID: <20200322191019.GP11469@brightrain.aerifal.cx> (raw)
In-Reply-To: <alpine.LNX.2.20.13.2003222136510.2534@monopod.intra.ispras.ru>

On Sun, Mar 22, 2020 at 09:51:09PM +0300, Alexander Monakov wrote:
> On Sun, 22 Mar 2020, Rich Felker wrote:
> 
> > > Nack for sqrt 'unsigned short' fix, I recommend to consider
> > > 'unsigned fpsr = 0' and "+a" constraint, the resulting assembly is
> > > much better (GCC doesn't seem to do a good job optimizing the 'unsigned short'
> > > variant at all).
> > 
> > Sorry, I forgot to disassemble and check after making that change, and
> > indeed it is very bad.
> > 
> > How about just leaving it as-is? The value is masked such that upper
> > bits don't matter, and "whatever the register happened to contain
> > before" is a valid albeit ugly output from inline asm -- it doesn't
> > admit any compiler transformations that would cause inconsistent value
> > to be observed or other problems.
> 
> Yes, I guess it's acceptable.
> 
> > > Actually, may I ask why the initial commit did not mention that it relies
> > > on this nontrivial property?
> > 
> > The need for fixup of double was only realized later, in commit
> > 809556e60a3359f646946879dd94c4760e5b8e84. It was discussed at the time
> > that no action was needed for single, but it seems since there was no
> > change there wasn't any mention of it in log.
> 
> Are you sure? single-precision sqrtf received a change just two days
> prior to that in commit e0a54e6725 ("correct rounding for i387 sqrtf function")
> which is the same day as when Stephen Canon supplied his answer in
> https://stackoverflow.com/questions/9678224/is-there-any-way-to-get-correct-rounding-with-the-i387-fsqrt-instruction
> (and also the same day you asked the question)

I just dug through the old gcc and glibc bz's it was mentioned on
(52593 and 14032 resp.) and didn't find anything, but I'm pretty sure
it was known in 2012 that it was a non-issue for single-precision.
What I didn't understand then was that the callee was responsible for
dropping the excess precision; I wrongly believed that "something" in
the caller would make it not-matter/get collapsed down to nominal
precision and rounded correctly. Commit e0a54e6725 and related commits
were fixing that mistake, which I'd since recognized was wrong but
hadn't yet recognized the urgency of fixing until I started seeing how
bad it could break the compiler.

Rich

  reply	other threads:[~2020-03-22 19:10 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-05 16:35 math patches for moving bare asm to C inline asm Alexander Monakov
2020-01-05 16:36 ` [PATCH] math: move x86_64 fabs, fabsf to C with " Alexander Monakov
2020-01-05 20:05   ` Rich Felker
2020-01-05 21:32     ` Alexander Monakov
2020-01-05 22:43       ` Rich Felker
2020-01-06  8:17         ` Alexander Monakov
2020-01-06  8:40 ` [PATCH] math: move more x86-family fabs functions to C Alexander Monakov
2020-03-21 17:06   ` [musl] " Rich Felker
2020-01-06 16:50 ` [PATCH] math: move trivial x86-family sqrt " Alexander Monakov
2020-01-06 17:43 ` [PATCH] math: move i386 sqrtf " Alexander Monakov
2020-01-06 18:32   ` Pascal Cuoq
2020-01-09 15:55   ` Alexander Monakov
2020-01-09 17:00     ` Rich Felker
2020-01-09 21:00       ` Szabolcs Nagy
2020-01-09 22:00         ` Rich Felker
2020-01-09 23:18           ` Szabolcs Nagy
2020-01-10  2:07             ` Rich Felker
2020-01-10  9:17               ` Szabolcs Nagy
2020-01-14 17:59         ` [musl] " Alexander Monakov
2020-01-14 18:47           ` Szabolcs Nagy
2020-01-07 13:06 ` [PATCH] math: move i386 sqrt " Alexander Monakov
2020-01-08  7:26   ` Rich Felker
2020-03-21 17:53   ` [musl] " Rich Felker
2020-03-21 17:57     ` Rich Felker
2020-03-21 20:30       ` Alexander Monakov
2020-01-11 15:06 ` [PATCH] math: move x86_64 (l)lrint(f) functions " Alexander Monakov
2020-01-11 15:23 ` [PATCH] math: move more x86-family lrint " Alexander Monakov
2020-01-11 16:07   ` Rich Felker
2020-01-11 16:22     ` Rich Felker
2020-01-14 11:54 ` [musl] [PATCH] math: move x86-family rint " Alexander Monakov
2020-01-14 18:17 ` [musl] Q: dealing with missing removal of excess precision Alexander Monakov
2020-01-14 18:50   ` Szabolcs Nagy
2020-01-14 18:58     ` Rich Felker
2020-01-14 19:53       ` Alexander Monakov
2020-02-06 14:51         ` Rich Felker
2020-02-06 17:15           ` Alexander Monakov
2020-02-06 17:46             ` Rich Felker
2020-02-06 19:03               ` Rich Felker
2020-02-06 20:02                 ` Rich Felker
2020-02-06 22:08                   ` Szabolcs Nagy
2020-02-22 19:59             ` Rich Felker
2020-02-22 20:21               ` Alexander Monakov
2020-02-23  0:19                 ` Rich Felker
2020-02-23 16:14                   ` Alexander Monakov
2020-03-20 18:12                     ` Rich Felker
2020-03-22  1:19                       ` Rich Felker
2020-03-22 17:40                         ` Alexander Monakov
2020-03-22 17:53                           ` Rich Felker
2020-03-22 18:51                             ` Alexander Monakov
2020-03-22 19:10                               ` Rich Felker [this message]
2020-03-22 19:46                                 ` Alexander Monakov
2020-01-14 20:41 ` [musl] [PATCH] math: move x86-family remainder functions to C Alexander Monakov
2020-01-15  6:54   ` Szabolcs Nagy
2020-01-15 15:44 ` [musl] [PATCH] math: move x86-family fmod " Alexander Monakov
2020-01-16 21:00 ` [musl] [PATCH] math: add x86_64 remquol Alexander Monakov

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=20200322191019.GP11469@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --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).