From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: [musl] Q: dealing with missing removal of excess precision
Date: Sat, 21 Mar 2020 21:19:58 -0400 [thread overview]
Message-ID: <20200322011958.GM11469@brightrain.aerifal.cx> (raw)
In-Reply-To: <20200320181250.GC11469@brightrain.aerifal.cx>
[-- Attachment #1: Type: text/plain, Size: 2760 bytes --]
On Fri, Mar 20, 2020 at 02:12:50PM -0400, Rich Felker wrote:
> On Sun, Feb 23, 2020 at 07:14:08PM +0300, Alexander Monakov wrote:
> > On Sat, 22 Feb 2020, Rich Felker wrote:
> >
> > > I'm not well acquainted with SSE, and only so-so with x87, so pretty
> > > much I'm reading them for higher-level issues with tooling
> > > compatibility (like the concerns I already raised and looked up and
> > > seem to have resolved about x87 constraints and non-GCC compilers) and
> > > logic, then planning to apply and test them. I think being aware of
> > > non-obvious mistake modes that have already been found would be a lot
> > > more useful than staring at things, especially if the bugs you've
> > > found are in subtleties of the insn behavior or constraint behavior.
> >
> > Okay, thanks. I found two issues:
> >
> > 1. i386 lrint* functions mistakenly used fistpll instead of fistpl (I
> > posted the fix for x32 asm after noticing my own mistake).
> >
> > 2. Some functions bind a 32-bit lvalue as output for fnstsw %ax, which
> > as the operand says writes only 16 bits. They should be changed to either
> > use a 16-bit lvalue, or a zero-initialized 32-bit lvalue with "+a" constraint.
> >
> > Plus, not bugs, but still worth mentioning:
> >
> > 3. The new remquol in C could alternatively be implemented by using fxam
> > to extract sign bits instead of loading them from stack slots. The current
> > approach makes sense given the ABI, but an implementation aiming for better
> > code after inlining could choose to use fxam instead of forcing a spill.
> >
> > 4. I did not manage to find a copy of Figueroa's "When is double rounding
> > innocuous", but I could cite e.g. "Innocuous Double Rounding of Basic
> > Arithmetic Operations" by Pierre Roux instead (in i386/sqrtf.c).
> >
> > If you like you can fetch a Git tree with my patches from
> >
> > https://git.sr.ht/~amonakov/musl
> >
> > (issue 1 is already corrected in that repo)
>
> Hi. I'm trying to catch up on this and other patches after being sick
> and not getting much done for a while. Is there anything else I should
> be aware of before going forward with these?
>
> One minor cosmetic change I'd like to make to commit names if you
> don't object is changing "x86-family" to "x87-family" for the commits
> that are "i386 + long double functions on x86_64" since I found it
> confusing when there's one commit for "x86 family" then a separate one
> for x86_64 versions of the same function. Let me know if you think of
> any alternative that might be more clear than "x87"
With the fixups mentioned (included in attached patches), i386 and
x86_64 are passing libc-test and seem fine. OK if I merge them
(rebasing the fixups in as fixups)? With s/x86/x87/ naming?
Rich
[-- Attachment #2: 0001-fabsf-i386-fixup.patch --]
[-- Type: text/plain, Size: 552 bytes --]
From 3f99f4595aa3ce528008ee22d65512768376a9a6 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Sat, 21 Mar 2020 16:23:51 -0400
Subject: [PATCH 1/3] fabsf i386 fixup
---
src/math/i386/fabsf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/math/i386/fabsf.c b/src/math/i386/fabsf.c
index d07be321..d882eee3 100644
--- a/src/math/i386/fabsf.c
+++ b/src/math/i386/fabsf.c
@@ -1,6 +1,6 @@
#include <math.h>
-float fabs(float x)
+float fabsf(float x)
{
__asm__ ("fabs" : "+t"(x));
return x;
--
2.21.0
[-- Attachment #3: 0002-sqrt-i386-fixup.patch --]
[-- Type: text/plain, Size: 747 bytes --]
From 7fd1bc3b8ecf61d758498edd7f4a75a079ee8df5 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Sat, 21 Mar 2020 16:24:04 -0400
Subject: [PATCH 2/3] sqrt i386 fixup
---
src/math/i386/sqrt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/math/i386/sqrt.c b/src/math/i386/sqrt.c
index 619df056..934fbcca 100644
--- a/src/math/i386/sqrt.c
+++ b/src/math/i386/sqrt.c
@@ -10,6 +10,6 @@ double sqrt(double x)
/* Rounding to double would have encountered an exact halfway case.
Adjust mantissa downwards if fsqrt rounded up, else upwards.
(result of fsqrt could not have been exact) */
- ux.i.m ^= (fpsr & 0x200) + 0x200;
+ ux.i.m ^= (fpsr & 0x200) + 0x300;
return (double)ux.f;
}
--
2.21.0
[-- Attachment #4: 0003-sqrt-i386-fixup-2.patch --]
[-- Type: text/plain, Size: 649 bytes --]
From b60ddebd251ff28559b48aa758026da8fbbab3f7 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Sat, 21 Mar 2020 16:57:38 -0400
Subject: [PATCH 3/3] sqrt i386 fixup 2
---
src/math/i386/sqrt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/math/i386/sqrt.c b/src/math/i386/sqrt.c
index 934fbcca..a34f4ce8 100644
--- a/src/math/i386/sqrt.c
+++ b/src/math/i386/sqrt.c
@@ -3,7 +3,7 @@
double sqrt(double x)
{
union ldshape ux;
- unsigned fpsr;
+ unsigned short fpsr;
__asm__ ("fsqrt; fnstsw %%ax": "=t"(ux.f), "=a"(fpsr) : "0"(x));
if ((ux.i.m & 0x7ff) != 0x400)
return (double)ux.f;
--
2.21.0
next prev parent reply other threads:[~2020-03-22 1:20 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 [this message]
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
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=20200322011958.GM11469@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).