From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14674 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: James Y Knight Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] mips: add single-instruction math functions Date: Fri, 13 Sep 2019 15:12:11 -0400 Message-ID: References: <20190911103224.504A15C44C@mx7.valuehost.ru> <20190913183123.GI9017@brightrain.aerifal.cx> <20190913185657.GJ9017@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000a313af05927409de" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="90942"; mail-complaints-to="usenet@blaine.gmane.org" To: musl@lists.openwall.com Original-X-From: musl-return-14690-gllmg-musl=m.gmane.org@lists.openwall.com Fri Sep 13 21:12:56 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1i8r02-000NXk-TG for gllmg-musl@m.gmane.org; Fri, 13 Sep 2019 21:12:55 +0200 Original-Received: (qmail 17799 invoked by uid 550); 13 Sep 2019 19:12:52 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 17775 invoked from network); 13 Sep 2019 19:12:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=sIXLsG6gI6WSoiUPBGWWnp1MuYpIb8DE171nBoGcwGg=; b=daUNH5KAAyeDykpLmOhiPBVEcw7m446SXGVAI+sh66438zjKmPfI5USoB0180O7mMz nWe2vkMQ58Uo24FuWRVWeQh+iFUFn1p19llc7bacx+++XK3m26SlNNc+DoUUxpY/cK7J emhd78NFMHKL9G9X0o6EE980SE2plbrxUB1Y6cmXHYdIoMICP1r6ohhplwKcQVnOgZsz ldVsq/I4MeCqLyIJQU3Z40MWSrIaPMGor14IxaajpQUiT7+ixRxsKFZUoH/0U3KISd+o sA7fXWlpt5bCuHpPa397lYR53YGWSyFk7wL6oh05ltggMjlsbY13sLoTH9TOSNhbuB1F QNcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=sIXLsG6gI6WSoiUPBGWWnp1MuYpIb8DE171nBoGcwGg=; b=JUlY7zfR6p7L0C2aUW9qxNSUponH7I1U+NiG4IBl8pEmHg4bgIPwfYDZWClINsZPA/ EyjGjqU5woXp15avONtUXbC8Xqp+m8CofA+YzObhF/Wq4aNl160QYWfzlv0oVEpWoRKx ZneZL6vHWGAXsCKYuuChOPSKLg7QbCa/gFZbRHnMgiIRdsmzDPFmraE31xNIPNgLFFHT 2KAsn0a2u7p6f3idyXJO/u+kzHmlikK08WvMkiYli8YIw4GkfMFRITiVzbQW4s+bsrtW h6kOp+RAxH5kEa2n0/5dG0wjuNJ1erBKUpzyIH6E5V25TwQaNX151KqPuywMzDhxQ6TQ PPGA== X-Gm-Message-State: APjAAAVBupi4kx43ZEyr8+oiT271fjWohgbEsEQspIJS40Tmd30X+4+M 4dbDE7LYInExGXbKE2bKdKDIk2s3PFPKmRMM4RaEQrSVddw= X-Google-Smtp-Source: APXvYqwonUE+O/k2pUAYJrW27yfxbDt5vCLHRwYfZifdPOWAbvJMNBEgKTZS7e6a+IR2whObF4sLBJeI3X1MH6kIe+s= X-Received: by 2002:ab0:21d7:: with SMTP id u23mr24938062uan.143.1568401959064; Fri, 13 Sep 2019 12:12:39 -0700 (PDT) In-Reply-To: <20190913185657.GJ9017@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:14674 Archived-At: --000000000000a313af05927409de Content-Type: text/plain; charset="UTF-8" I've no idea about the issues with MIPS' instruction set, but yes, to be correct, abs does need to affect only the sign bit, leaving everything else the same. It's specified as such in IEEE 754-2008: 5.5.1 Sign bit operations -- "Implementations shall provide the following homogeneous quiet-computational sign bit operations for all supported arithmetic formats; they only affect the sign bit. The operations treat floating-point numbers and NaNs alike, and signal no exception. These operations may propagate non-canonical encodings." ... "abs(x) copies a floating-point operand x to a destination in the same format, setting the sign bit to 0 (positive)." (That section also defines the copy, negate, and copySign operations) On Fri, Sep 13, 2019 at 2:57 PM Rich Felker wrote: > On Fri, Sep 13, 2019 at 02:31:23PM -0400, Rich Felker wrote: > > On Wed, Sep 11, 2019 at 01:05:04PM +0300, info@mobile-stream.com wrote: > > > > > > non-commit text: > > > gcc puts annoying nop into the delay slot for these functions, e.g.: > > > abs.d $f0,$f12 > > > jr $ra > > > nop > > > is there any way to get rid of this without using pure .S? > > > > > > > > > > > > SQRT.fmt exists on MIPS II+ (float), MIPS III+ (double). > > > > > > ABS.fmt exists on MIPS I+ but only cores with ABS2008 flag in FCSR > > > implement the required behaviour. > > > --- > > > src/math/mips/fabs.c | 16 ++++++++++++++++ > > > src/math/mips/fabsf.c | 16 ++++++++++++++++ > > > src/math/mips/sqrt.c | 16 ++++++++++++++++ > > > src/math/mips/sqrtf.c | 16 ++++++++++++++++ > > > 4 files changed, 64 insertions(+) > > > create mode 100644 src/math/mips/fabs.c > > > create mode 100644 src/math/mips/fabsf.c > > > create mode 100644 src/math/mips/sqrt.c > > > create mode 100644 src/math/mips/sqrtf.c > > > > > > diff --git a/src/math/mips/fabs.c b/src/math/mips/fabs.c > > > new file mode 100644 > > > index 00000000..0a5aa3b1 > > > --- /dev/null > > > +++ b/src/math/mips/fabs.c > > > @@ -0,0 +1,16 @@ > > > +#if !defined(__mips_soft_float) && defined(__mips_abs2008) > > > > Why is this dependent on __mips_abs2008? > > OK, I see. The macro isn't well-documented, but it corresponds to the > gcc -mabs=2008 option indicating an ISA variant that treats the > abs.[sd] instruction as bitwise rather than arithmetic. I'm somewhat > unclear on whether we should do anything like this; it's one of the > places where MIPS blurred the distinction between ISA levels and > incompatible ABIs, and seems to be able to produce code that would > silently run on the wrong type of cpu and produce the wrong result (or > maybe this is a runtime-switchable cpu mode?) > > I'm also unclear though whether fabs() actually needs to behave as > bitwise. Neither C nor Annex F nor POSIX seems to specify its behavior > for NANs except that a NAN is returned. Am I missing something? If > not, it seems the 'legacy' abs.[sd] instructions would also be fine > for implementing this, and then no conditional is needed. > > Rich > --000000000000a313af05927409de Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I've no idea about the issues with MIPS' inst= ruction set, but yes, to be correct, abs does need to affect only the sign = bit, leaving everything else the same.

It's sp= ecified as such in IEEE 754-2008: 5.5.1 Sign bit operations --=C2=A0
<= div>"Implementations shall provide the following homogeneous quiet-com= putational sign bit operations for all supported arithmetic formats; they only affect the sign bit. The operations= treat floating-point numbers and NaNs alike, and signal no exception. These operations may propagate non-can= onical encodings."
...
"abs(x) copies a float= ing-point operand x to a destination in the same format, setting the sign b= it to 0 (positive)."

(That section also defines the= copy, negate, and copySign operations)


On F= ri, Sep 13, 2019 at 2:57 PM Rich Felker <dalias@libc.org> wrote:
On Fri, Sep 13, 2019 at 02:31:23PM -0400, Rich Felker wr= ote:
> On Wed, Sep 11, 2019 at 01:05:04PM +0300, info@mobile-stream.com wrote:
> >
> > non-commit text:
> > gcc puts annoying nop into the delay slot for these functions, e.= g.:
> >=C2=A0 =C2=A0 =C2=A0abs.d=C2=A0 =C2=A0$f0,$f12
> >=C2=A0 =C2=A0 =C2=A0jr=C2=A0 =C2=A0 =C2=A0 $ra
> >=C2=A0 =C2=A0 =C2=A0 nop
> > is there any way to get rid of this without using pure .S?
> >
> >
> >
> > SQRT.fmt exists on MIPS II+ (float), MIPS III+ (double).
> >
> > ABS.fmt exists on MIPS I+ but only cores with ABS2008 flag in FCS= R
> > implement the required behaviour.
> > ---
> >=C2=A0 src/math/mips/fabs.c=C2=A0 | 16 ++++++++++++++++
> >=C2=A0 src/math/mips/fabsf.c | 16 ++++++++++++++++
> >=C2=A0 src/math/mips/sqrt.c=C2=A0 | 16 ++++++++++++++++
> >=C2=A0 src/math/mips/sqrtf.c | 16 ++++++++++++++++
> >=C2=A0 4 files changed, 64 insertions(+)
> >=C2=A0 create mode 100644 src/math/mips/fabs.c
> >=C2=A0 create mode 100644 src/math/mips/fabsf.c
> >=C2=A0 create mode 100644 src/math/mips/sqrt.c
> >=C2=A0 create mode 100644 src/math/mips/sqrtf.c
> >
> > diff --git a/src/math/mips/fabs.c b/src/math/mips/fabs.c
> > new file mode 100644
> > index 00000000..0a5aa3b1
> > --- /dev/null
> > +++ b/src/math/mips/fabs.c
> > @@ -0,0 +1,16 @@
> > +#if !defined(__mips_soft_float) && defined(__mips_abs200= 8)
>
> Why is this dependent on __mips_abs2008?

OK, I see. The macro isn't well-documented, but it corresponds to the gcc -mabs=3D2008 option indicating an ISA variant that treats the
abs.[sd] instruction as bitwise rather than arithmetic. I'm somewhat unclear on whether we should do anything like this; it's one of the
places where MIPS blurred the distinction between ISA levels and
incompatible ABIs, and seems to be able to produce code that would
silently run on the wrong type of cpu and produce the wrong result (or
maybe this is a runtime-switchable cpu mode?)

I'm also unclear though whether fabs() actually needs to behave as
bitwise. Neither C nor Annex F nor POSIX seems to specify its behavior
for NANs except that a NAN is returned. Am I missing something? If
not, it seems the 'legacy' abs.[sd] instructions would also be fine=
for implementing this, and then no conditional is needed.

Rich
--000000000000a313af05927409de--