public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	Chris Wedgwood <reviews@ml.cw.f00f.org>,
	Michael Krufky <mkrufky@linuxtv.org>,
	Chuck Ebbert <cebbert@redhat.com>,
	Domenico Andreoli <cavokz@gmail.com>, Willy Tarreau <w@1wt.eu>,
	Rodrigo Rubira Branco <rbranco@la.checkpoint.com>,
	Jake Edge <jake@lwn.net>, Eugene Teo <eteo@redhat.com>,
	torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk, "David S. Miller" <davem@davemloft.net>
Subject: [patch 17/23] math-emu: Fix signalling of underflow and inexact while packing result.
Date: Fri, 7 Nov 2008 15:15:58 -0800	[thread overview]
Message-ID: <20081107231558.GR1108@kroah.com> (raw)
In-Reply-To: <20081107231457.GA1108@kroah.com>

[-- Attachment #1: 0001-math-emu-Fix-signalling-of-underflow-and-inexact-wh.patch --]
[-- Type: text/plain, Size: 3678 bytes --]


2.6.26-stable review patch.  If anyone has any objections, please let us know.

------------------

From: Kumar Gala <galak@kernel.crashing.org>

[ Upstream commit 930cc144a043ff95e56b6888fa51c618b33f89e7 ]

I'm trying to move the powerpc math-emu code to use the include/math-emu bits.

In doing so I've been using TestFloat to see how good or bad we are
doing.  For the most part the current math-emu code that PPC uses has
a number of issues that the code in include/math-emu seems to solve
(plus bugs we've had for ever that no one every realized).

Anyways, I've come across a case that we are flagging underflow and
inexact because we think we have a denormalized result from a double
precision divide:

000.FFFFFFFFFFFFF / 3FE.FFFFFFFFFFFFE
	soft: 001.0000000000000 .....  syst: 001.0000000000000 ...ux

What it looks like is the results out of FP_DIV_D are:

D:
sign:	  0
mantissa: 01000000 00000000
exp:	 -1023 (0)

The problem seems like we aren't normalizing the result and bumping the exp.

Now that I'm digging into this a bit I'm thinking my issue has to do with
the fix DaveM put in place from back in Aug 2007 (commit
405849610fd96b4f34cd1875c4c033228fea6c0f):

[MATH-EMU]: Fix underflow exception reporting.

    2) we ended up rounding back up to normal (this is the case where
       we set the exponent to 1 and set the fraction to zero), this
       should set inexact too
...

    Another example, "0x0.0000000000001p-1022 / 16.0", should signal both
    inexact and underflow.  The cpu implementations and ieee1754
    literature is very clear about this.  This is case #2 above.

Here is the distilled glibc test case from Jakub Jelinek which prompted that
commit:

--------------------
#include <float.h>
#include <fenv.h>
#include <stdio.h>

volatile double d = DBL_MIN;
volatile double e = 0x0.0000000000001p-1022;
volatile double f = 16.0;
int
main (void)
{
  printf ("%x\n", fetestexcept (FE_UNDERFLOW));
  d /= f;
  printf ("%x\n", fetestexcept (FE_UNDERFLOW));
  e /= f;
  printf ("%x\n", fetestexcept (FE_UNDERFLOW));
  return 0;
}
--------------------

It looks like the case I have we are exact before rounding, but think it
looks like the rounding case since it appears as if "overflow is set".

000.FFFFFFFFFFFFF / 3FE.FFFFFFFFFFFFE = 001.0000000000000

I think the following adds the check for my case and still works for the
issue your commit was trying to resolve.

Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 include/math-emu/op-common.h |   17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

--- a/include/math-emu/op-common.h
+++ b/include/math-emu/op-common.h
@@ -139,18 +139,27 @@ do {								\
 	if (X##_e <= _FP_WFRACBITS_##fs)			\
 	  {							\
 	    _FP_FRAC_SRS_##wc(X, X##_e, _FP_WFRACBITS_##fs);	\
-	    _FP_ROUND(wc, X);					\
 	    if (_FP_FRAC_HIGH_##fs(X)				\
 		& (_FP_OVERFLOW_##fs >> 1))			\
 	      {							\
 	        X##_e = 1;					\
 	        _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc);	\
-	        FP_SET_EXCEPTION(FP_EX_INEXACT);		\
 	      }							\
 	    else						\
 	      {							\
-		X##_e = 0;					\
-		_FP_FRAC_SRL_##wc(X, _FP_WORKBITS);		\
+		_FP_ROUND(wc, X);				\
+		if (_FP_FRAC_HIGH_##fs(X)			\
+		   & (_FP_OVERFLOW_##fs >> 1))			\
+		  {						\
+		    X##_e = 1;					\
+		    _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc);	\
+		    FP_SET_EXCEPTION(FP_EX_INEXACT);		\
+		  }						\
+		else						\
+		  {						\
+		    X##_e = 0;					\
+		    _FP_FRAC_SRL_##wc(X, _FP_WORKBITS);		\
+		  }						\
 	      }							\
 	    if ((FP_CUR_EXCEPTIONS & FP_EX_INEXACT) ||		\
 		(FP_TRAPPING_EXCEPTIONS & FP_EX_UNDERFLOW))	\

-- 

  parent reply	other threads:[~2008-11-07 23:28 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20081107224818.593212310@mini.kroah.org>
2008-11-07 23:14 ` [patch 00/23] 2.6.26.8-stable review Greg KH
2008-11-07 23:15   ` [patch 01/23] gpiolib: fix oops in gpio_get_value_cansleep() Greg KH
2008-11-07 23:15   ` [patch 02/23] ext: Avoid printk floods in the face of directory corruption (CVE-2008-3528) Greg KH
2008-11-10  2:42     ` Eugene Teo
2008-11-10 18:06       ` Greg KH
2008-11-10 18:14         ` Eric Sandeen
2008-11-07 23:15   ` [patch 03/23] edac cell: fix incorrect edac_mode Greg KH
2008-11-07 23:15   ` [patch 04/23] SCSI: qla2xxx: Skip FDMI registration on ISP21xx/22xx parts Greg KH
2008-11-07 23:15   ` [patch 05/23] net: Fix recursive descent in __scm_destroy() Greg KH
2008-11-07 23:15   ` [patch 06/23] libertas: fix buffer overrun Greg KH
2008-11-07 23:15   ` [patch 07/23] file caps: always start with clear bprm->caps_* Greg KH
2008-11-07 23:15   ` [patch 08/23] ALSA: use correct lock in snd_ctl_dev_disconnect() Greg KH
2008-11-07 23:15   ` [patch 09/23] ACPI: Always report a sync event after a lid state change Greg KH
2008-11-07 23:15   ` [patch 10/23] V4L: pvrusb2: Keep MPEG PTSs from drifting away Greg KH
2008-11-07 23:15   ` [patch 11/23] DVB: s5h1411: bugfix: Setting serial or parallel mode could destroy bits Greg KH
2008-11-07 23:15   ` [patch 12/23] DVB: s5h1411: Perform s5h1411 soft reset after tuning Greg KH
2008-11-07 23:15   ` [patch 13/23] DVB: s5h1411: Power down s5h1411 when not in use Greg KH
2008-11-07 23:15   ` [patch 14/23] scx200_i2c: Add missing class parameter Greg KH
2008-11-07 23:15   ` [patch 15/23] net: Fix netdev_run_todo dead-lock Greg KH
2008-11-07 23:15   ` [patch 16/23] tcpv6: fix option space offsets with md5 Greg KH
2008-11-07 23:15   ` Greg KH [this message]
2008-11-07 23:16   ` [patch 18/23] sparc64: Fix race in arch/sparc64/kernel/trampoline.S Greg KH
2008-11-07 23:16   ` [patch 19/23] ACPI: video: fix brightness allocation Greg KH
2008-11-07 23:16   ` [patch 20/23] ACPI: dock: avoid check _STA method Greg KH
2008-11-11 12:16     ` Holger Macht
2008-11-13 21:23       ` [stable] " Greg KH
2008-11-16 23:36         ` Holger Macht
2008-11-17  4:59           ` Greg KH
2008-11-07 23:16   ` [patch 21/23] netfilter: xt_iprange: fix range inversion match Greg KH
2008-11-07 23:16   ` [patch 22/23] netfilter: snmp nat leaks memory in case of failure Greg KH
2008-11-07 23:16   ` [patch 23/23] netfilter: restore lost ifdef guarding defrag exception Greg KH

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=20081107231558.GR1108@kroah.com \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=cavokz@gmail.com \
    --cc=cebbert@redhat.com \
    --cc=chuckw@quantumlinux.com \
    --cc=davej@redhat.com \
    --cc=davem@davemloft.net \
    --cc=eteo@redhat.com \
    --cc=jake@lwn.net \
    --cc=jmforbes@linuxtx.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkrufky@linuxtv.org \
    --cc=rbranco@la.checkpoint.com \
    --cc=rdunlap@xenotime.net \
    --cc=reviews@ml.cw.f00f.org \
    --cc=stable@kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=tytso@mit.edu \
    --cc=w@1wt.eu \
    --cc=zwane@arm.linux.org.uk \
    /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