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] Considering x86-64 fenv.s to C
Date: Sat, 18 Jan 2020 00:29:41 -0500	[thread overview]
Message-ID: <20200118052941.GW30412@brightrain.aerifal.cx> (raw)
In-Reply-To: <alpine.LRH.2.02.2001181011130.11425@key0.esi.com.au>

On Sat, Jan 18, 2020 at 03:45:27PM +1100, Damian McGuckin wrote:
> >C specifies it as:
> >
> >   "The feraiseexcept function returns zero if the excepts argument
> >   is zero or if all the specified exceptions were successfully
> >   raised. Otherwise, it returns a nonzero value."
> 
> Pretty vague. This is not why the M68K routines return (-1).
> 
> No routine currently checks that the exceptions were successfully
> raised. They assume that a write to the status register works. If we
> are going to check each instruction such as storing into a register
> works, we have a lot of work to do.

If the ISA has instructions to set status word then we can assume they
actually work. The idea of the possibility that they can fail is to
admit different implementation choices: rather than declining to
define exceptions and rounding modes on softfloat ABI variants, we
could have defined them but make the functions to set them always
report failure. I think this would have been a worse choice which is
why it wasn't done.

In the future if softfloat implementations add fenv, but it's only
conditionally available at runtime depending on [something], then it
would make sense to have possibility of failure at runtime.

> >>	double to a union and then extract the data as a long.
> >>
> >>		return (union {double f; long i;}) {get_fpscr_f()}.i;
> >>
> >>	Is this style of coding universally accepted within MUSL? From my
> >>	reading of other routines, it is normally done as
> >>
> >>		union {double f; long i;} f = { get_fpscr_f() };
> >>
> >>		return f.i;
> >>
> >>	Just curious.
> >
> >Yes, the compound literal form is preferred since it avoids a
> >gratuitous named variable.
> 
> I would humbly suggest initially using the longer form, and then
> once the architecture of the routine is complete, we revert to the
> compound literal form where the code is simple enough to make it
> possible.

I don't follow why this is better.

> >>x86_64
> >>
> >>*	In assembler
> >>
> >>*	Why does 'feclearexcept' disrespect the flags by clearing ALL x86 bits?
> >
> >As you said above, updating x87 status register is expensive because
> >the only way to write it is to read-modify-write the whole fenv. But
> >since we know on x86_64 we have sse registers, we can just move all
> >the flags to the sse register, then use fnclex to clear the x87 one
> >inexpensively, and the effective set of raised flags remains the same.
> 
> Thanks for the explanation. Neat.
> 
> >I think we could do this on i386 too with a couple tricks:
> >
> >1. Do the same thing if sse is available (hwcap check).
> >
> >2. If sse is not available, clear all flags then re-raise the desired
> >set via arithmetic operations.
> 
> Simple. I like it. But more code.
> 
> Also, playing devil's advocate for a minute ....
> 
> Are we, or should we, be aiming to have
> 
> 	fetestexcept(int excepts)
> 
> and (even also)
> 
> 	feraiseexcept(int excepts)
> 
> being expanded inline so their use does not compromise optimization?

Only if LTO is in use, and then as you mention you may run into bugs
with the compiler not considering side effects of floating point
operations correctly, so LTO isn't really practical to use until
compilers are fixed. Otherwise we don't put implementations of stuff
like this in public headers.

Rich

  reply	other threads:[~2020-01-18  5:29 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16  4:30 Damian McGuckin
2020-01-16 15:11 ` Markus Wichmann
2020-01-16 16:14 ` Rich Felker
2020-01-16 18:56   ` Damian McGuckin
2020-01-16 19:33     ` Rich Felker
2020-01-16 21:31       ` Damian McGuckin
2020-01-17  3:36       ` Damian McGuckin
2020-01-17  3:48         ` Damian McGuckin
2020-01-17  3:53         ` David Edelsohn
2020-01-17 14:13           ` Rich Felker
2020-01-17 14:19             ` David Edelsohn
2020-01-17 14:53         ` Rich Felker
2020-01-18  4:45           ` Damian McGuckin
2020-01-18  5:29             ` Rich Felker [this message]
2020-01-19  8:50               ` Damian McGuckin
2020-01-19  9:07           ` Damian McGuckin
2020-01-19 10:42             ` Szabolcs Nagy
2020-01-19 12:25               ` Damian McGuckin
2020-01-20  5:32           ` Damian McGuckin
2020-01-20 17:38             ` Rich Felker
2020-01-20 21:11               ` [musl] Triggering Overflow (or Underflow) without triggering Inexact on i386 Damian McGuckin
2020-01-20 22:32                 ` Szabolcs Nagy
2020-01-21  3:53           ` [musl] Considering x86-64 fenv.s to C Damian McGuckin
2020-01-21  4:22             ` Rich Felker
2020-01-21  4:46               ` Damian McGuckin
2020-01-21  7:26                 ` Damian McGuckin
2020-01-17 16:41         ` Markus Wichmann
2020-01-18  1:15           ` Szabolcs Nagy
2020-01-18  5:03             ` Damian McGuckin
2020-01-18  5:37               ` Rich Felker
2020-01-18  9:40                 ` Szabolcs Nagy
2020-01-24  0:42                   ` Damian McGuckin
2020-01-24  1:11                     ` Rich Felker
2020-01-24  4:13                       ` Damian McGuckin
2020-01-24  4:55                         ` Rich Felker
2020-01-24  6:08                           ` Damian McGuckin
2020-01-24 13:44                             ` Rich Felker
2020-01-24 14:45                               ` Damian McGuckin
2020-01-24 23:59                               ` Damian McGuckin
2020-01-25  0:11                                 ` Rich Felker
2020-01-26  3:28                                   ` Damian McGuckin
2020-01-26  3:28                                   ` Damian McGuckin
2020-01-26  3:30                                   ` Damian McGuckin
2020-01-26  3:32                                   ` Damian McGuckin
2020-01-26  5:25                                   ` Damian McGuckin
2020-01-27  3:32                                   ` Damian McGuckin
2020-01-27  5:39                                   ` Damian McGuckin
2020-02-02  0:47                                   ` Damian McGuckin
2020-02-03  0:54                                   ` Damian McGuckin
2020-02-03  2:09                                     ` Rich Felker
2020-02-03  2:12                                       ` Damian McGuckin
2020-02-22 20:17                                         ` Rich Felker
2020-02-22 20:53                                           ` Damian McGuckin
2020-02-23  5:41                                           ` Damian McGuckin
2020-02-23  6:25                                             ` Rich Felker
2020-02-23  8:35                                               ` Damian McGuckin
2020-02-07 21:25                                   ` Damian McGuckin
2020-02-07 21:38                                     ` Rich Felker
2020-02-07 23:53                                       ` Damian McGuckin
2020-02-09  5:04                                       ` Damian McGuckin
2020-01-24  7:10                           ` Damian McGuckin
2020-01-18  5:04             ` Markus Wichmann
2020-02-03 14:16 [musl] PPC64(LE) support in musl requires ALTIVEC Romain Naour
2020-02-03 14:50 ` Rich Felker
2020-02-05  1:32   ` [musl] Considering x86-64 fenv.s to C Damian McGuckin

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=20200118052941.GW30412@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).