linux-mips
[Top] [All Lists]

[PATCH] Fix abs.[sd] and neg.[sd] emulation for NaN operands

To: linux-mips@linux-mips.org
Subject: [PATCH] Fix abs.[sd] and neg.[sd] emulation for NaN operands
From: Chris Dearman <chris@mips.com>
Date: Mon, 12 Oct 2009 14:57:18 -0700
In-reply-to: <20091012215522.30362.49399.stgit@localhost.localdomain>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <20091012215522.30362.49399.stgit@localhost.localdomain>
Sender: linux-mips-bounce@linux-mips.org
User-agent: StGIT/0.14.2
From: Nigel Stephens <nigel@mips.com>

This patch ensures that the sign bit is always updated
for NaN operands.

Signed-off-by: Chris Dearman <chris@mips.com>
---

 arch/mips/math-emu/dp_simple.c |   13 ++++---------
 arch/mips/math-emu/sp_simple.c |   11 +++--------
 2 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/arch/mips/math-emu/dp_simple.c b/arch/mips/math-emu/dp_simple.c
index 1c555e6..d9ae1db 100644
--- a/arch/mips/math-emu/dp_simple.c
+++ b/arch/mips/math-emu/dp_simple.c
@@ -62,8 +62,6 @@ ieee754dp ieee754dp_neg(ieee754dp x)
                return ieee754dp_nanxcpt(y, "neg");
        }
 
-       if (ieee754dp_isnan(x)) /* but not infinity */
-               return ieee754dp_nanxcpt(x, "neg", x);
        return x;
 }
 
@@ -76,15 +74,12 @@ ieee754dp ieee754dp_abs(ieee754dp x)
        CLEARCX;
        FLUSHXDP;
 
+       /* Clear sign ALWAYS, irrespective of NaN */
+       DPSIGN(x) = 0;
+
        if (xc == IEEE754_CLASS_SNAN) {
-               SETCX(IEEE754_INVALID_OPERATION);
-               return ieee754dp_nanxcpt(ieee754dp_indef(), "neg");
+               return ieee754dp_nanxcpt(ieee754dp_indef(), "abs");
        }
 
-       if (ieee754dp_isnan(x)) /* but not infinity */
-               return ieee754dp_nanxcpt(x, "abs", x);
-
-       /* quick fix up */
-       DPSIGN(x) = 0;
        return x;
 }
diff --git a/arch/mips/math-emu/sp_simple.c b/arch/mips/math-emu/sp_simple.c
index 770f0f4..3175477 100644
--- a/arch/mips/math-emu/sp_simple.c
+++ b/arch/mips/math-emu/sp_simple.c
@@ -62,8 +62,6 @@ ieee754sp ieee754sp_neg(ieee754sp x)
                return ieee754sp_nanxcpt(y, "neg");
        }
 
-       if (ieee754sp_isnan(x)) /* but not infinity */
-               return ieee754sp_nanxcpt(x, "neg", x);
        return x;
 }
 
@@ -76,15 +74,12 @@ ieee754sp ieee754sp_abs(ieee754sp x)
        CLEARCX;
        FLUSHXSP;
 
+       /* Clear sign ALWAYS, irrespective of NaN */
+       SPSIGN(x) = 0;
+
        if (xc == IEEE754_CLASS_SNAN) {
-               SETCX(IEEE754_INVALID_OPERATION);
                return ieee754sp_nanxcpt(ieee754sp_indef(), "abs");
        }
 
-       if (ieee754sp_isnan(x)) /* but not infinity */
-               return ieee754sp_nanxcpt(x, "abs", x);
-
-       /* quick fix up */
-       SPSIGN(x) = 0;
        return x;
 }


<Prev in Thread] Current Thread [Next in Thread>