public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Eric Ries" <eries@there.com>
To: "Gabriel Paubert" <paubert@iram.es>
Cc: <linux-kernel@vger.kernel.org>
Subject: RE: FPU precision & signal handlers (bug?)
Date: Wed, 6 Mar 2002 15:32:22 -0800	[thread overview]
Message-ID: <KPEDLFEJBNHDLFEEOIIMOEOBCEAA.eries@there.com> (raw)
In-Reply-To: <Pine.LNX.4.33.0203051918520.7951-100000@gra-lx1.iram.es>

> -----Original Message-----
> From: Gabriel Paubert [mailto:paubert@iram.es]
> Sent: Wednesday, March 06, 2002 11:12 AM
> To: Eric Ries
> Cc: linux-kernel@vger.kernel.org
> Subject: Re: FPU precision & signal handlers (bug?)
>
> <Offtopic>
> Believing in getting the same floating-point results down to the last bit
> on different platforms is almost always bound to fail: for transcendental
> functions, a 486 will not give the same results as a Pentium, a PIV will
> use a library and give different results if you use SSE2 mode, and so on.
> I don't even know whether an Athlon and the PII/PIII always give the same
> results or not.
>
> Now if you have other architectures, even if they all use IEEE-[78]54
> floating point format, this becomes even more interesting. For examples
> PPC, MIPS, IA64, and perhaps others will tend to use fused
> multiply-accumulate instructions unless you tell the compiler not do do so
> (BTW after a quick look at GCC doc and sources, -mno-fused-madd is not
> even an option for IA-64).
> </Offtopic>

Yes, this is a quite tricky problem. Fortunately, in our situation we are
extremely picky about just which calculations must be bit-for-bit consistent
across machines, and try to keep those operations very simple. We have been
doing this for some time on Intel hardware, and - apart from this signal
handler issue - have never had any problems.

> Right.
> [Snipped the clear explanation showing that you've done your homework]

Thanks :) I know how annoying it can be to put up with clueless posts on
mailing lists.

> Actually, fxsave does not reset the FPU state IIRC (so it could be faster
> for signal delivery to use fxsave followed by fnsave instead of the format
> conversion routine if the FPU happens to hold the state of the current
> process).

That's an interesting thought. I didn't have a decent reference on MMX
instructions while I was tracking this bug down, so I just assumed they were
basically equivalent to their 387 counterparts.


> Very bad idea, the control word is often changed in the middle of the
> code, especially the rounding mode field for float->int conversions; have
> a look at the code that GCC generates (grep for f{nst,ld}cw). The Pentium
> IV doc even states that you can efficiently toggle between 2 values of the
> control word, but not more.

I don't see how this is a problem, because (as far as I can tell) there is
no need to use the "default" control word at all. In the solution I propose,
the FPU state is still saved before a signal handler call, and restored
afterwards. It's just that during the signal handler execution, the control
word is set to the process-global value. Keep in mind that, in the case that
your signal handler has no floating-point instructions, the control word
never has to be set, because no FINIT trap will be generated. So there's
only a performance cost to those of us who use floating point in our signal
handlers.

> Therefore you certainly don't want to inherit the control word of the
> executing thread. Now adding a prctl or something similar to say "I'd like
> to get this control word(s) value as initial value(s) in signal handlers"
> might make sense, even on other architectures or for SSE/SSE2 to control
> such things as handle denormal as zeros or change the set of exceptions
> enabled by default...

I'm afraid I don't quite follow what you're suggesting here. Don't you
always want “your” control word in any function that executes as part of
your process?

Thanks for the thoughtful reply,

Eric


  reply	other threads:[~2002-03-06 23:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-04 18:58 FPU precision & signal handlers (bug?) Eric Ries
2002-03-04 22:37 ` Alan Cox
2002-03-04 23:31   ` Eric Ries
2002-03-05 18:23   ` Gabriel Paubert
2002-03-06  0:06     ` Alan Cox
2002-03-07 17:31       ` Gabriel Paubert
2002-03-07 19:25         ` Alan Cox
2002-03-08 12:11           ` Gabriel Paubert
2002-03-06 19:11 ` Gabriel Paubert
2002-03-06 23:32   ` Eric Ries [this message]
2002-03-08 11:54     ` Gabriel Paubert

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=KPEDLFEJBNHDLFEEOIIMOEOBCEAA.eries@there.com \
    --to=eries@there.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paubert@iram.es \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox