linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: "Joseph S. Myers" <joseph@codesourcery.com>
To: <linuxppc-dev@lists.ozlabs.org>
Cc: Liu Yu <yu.liu@freescale.com>,
	linux-kernel@vger.kernel.org, Shan Hai <shan.hai@windriver.com>
Subject: [PATCH 3/6] math-emu: fix floating-point to integer unsigned saturation
Date: Mon, 4 Nov 2013 16:53:50 +0000	[thread overview]
Message-ID: <Pine.LNX.4.64.1311041653200.4290@digraph.polyomino.org.uk> (raw)
In-Reply-To: <Pine.LNX.4.64.1311041649250.4290@digraph.polyomino.org.uk>

From: Joseph Myers <joseph@codesourcery.com>

The math-emu macros _FP_TO_INT and _FP_TO_INT_ROUND are supposed to
saturate their results for out-of-range arguments, except in the case
rsigned == 2 (when instead the low bits of the result are taken).
However, in the case rsigned == 0 (converting to unsigned integers),
they mistakenly produce 0 for positive results and the maximum
unsigned integer for negative results, the opposite of correct
unsigned saturation.  This patch fixes the logic.

Signed-off-by: Joseph Myers <joseph@codesourcery.com>

---

Previous submission: <http://lkml.org/lkml/2013/10/8/694>.

I have made the corresponding changes to the glibc/libgcc copy of this
code, given that it would be desirable to resync the Linux and
glibc/libgcc copies (the latter has had many enhancements and bug
fixes since it was copied into Linux), although strictly this
incorrect saturation is only a bug when trying to emulate particular
instruction semantics, not when used in userspace to implement C
operations where the results of out-of-range conversions are
unspecified or undefined.

diff --git a/include/math-emu/op-common.h b/include/math-emu/op-common.h
index 9696a5e..70fe5e9 100644
--- a/include/math-emu/op-common.h
+++ b/include/math-emu/op-common.h
@@ -685,7 +685,7 @@ do {									\
 	    else								\
 	      {									\
 		r = 0;								\
-		if (X##_s)							\
+		if (!X##_s)							\
 		  r = ~r;							\
 	      }									\
 	    FP_SET_EXCEPTION(FP_EX_INVALID);					\
@@ -762,7 +762,7 @@ do {									\
 	    if (!rsigned)							\
 	      {									\
 		r = 0;								\
-		if (X##_s)							\
+		if (!X##_s)							\
 		  r = ~r;							\
 	      }									\
 	    else if (rsigned != 2)						\

-- 
Joseph S. Myers
joseph@codesourcery.com

  parent reply	other threads:[~2013-11-04 16:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-04 16:50 [PATCH 0/6] powerpc/math-emu: e500 SPE float emulation fixes Joseph S. Myers
2013-11-04 16:52 ` [PATCH 1/6] powerpc: fix exception clearing in e500 SPE float emulation Joseph S. Myers
2013-11-22 22:34   ` Scott Wood
2013-11-23  1:22     ` Joseph S. Myers
2013-12-07  0:32       ` Scott Wood
2013-12-07  0:48         ` questions: second of the 2 pcie controllers does not scan the bus Ruchika
2013-12-07 13:26           ` Ruchika
2013-12-09 22:50           ` Scott Wood
2013-12-10 23:07         ` [PATCHv2 1/6] powerpc: fix exception clearing in e500 SPE float emulation Joseph S. Myers
2013-11-04 16:53 ` [PATCH 2/6] powerpc: fix e500 SPE float rounding inexactness detection Joseph S. Myers
2013-11-04 16:53 ` Joseph S. Myers [this message]
2013-11-04 16:54 ` [PATCH 4/6] math-emu: fix floating-point to integer overflow detection Joseph S. Myers
2013-11-04 16:54 ` [PATCH 5/6] powerpc: fix e500 SPE float to integer and fixed-point conversions Joseph S. Myers
2013-11-04 16:55 ` [PATCH 6/6] powerpc: fix e500 SPE float SIGFPE generation Joseph S. Myers
2013-11-11 14:29 ` Ping Re: [PATCH 0/6] powerpc/math-emu: e500 SPE float emulation fixes Joseph S. Myers
2013-11-18 14:54   ` Ping^2 " Joseph S. Myers
2013-11-18 19:07     ` Scott Wood

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=Pine.LNX.4.64.1311041653200.4290@digraph.polyomino.org.uk \
    --to=joseph@codesourcery.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=shan.hai@windriver.com \
    --cc=yu.liu@freescale.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.
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).