Skip to contentSkip to conversation

Fix absd emulation

PATCH In review Raghu Gandham 4 participants 11 messages Jul 10, 2009 – May 22, 2010 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix absd emulation

From: Robin Randhawa <[email protected]>

---

 arch/mips/math-emu/dp_simple.c |   11 ++++-------
 arch/mips/math-emu/sp_simple.c |    3 ---
 2 files changed, 4 insertions(+), 10 deletions(-)
arch/mips/math-emu/dp_simple.c +4 -7
index 1c555e6..6ff4655 100644
@@ -76,15 +76,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;
 }
arch/mips/math-emu/sp_simple.c +0 -3
index 770f0f4..cdec1a2 100644
@@ -61,9 +61,6 @@ ieee754sp ieee754sp_neg(ieee754sp x)
 		SPSIGN(y) = SPSIGN(x);
 		return ieee754sp_nanxcpt(y, "neg");
 	}
-
-	if (ieee754sp_isnan(x))	/* but not infinity */
-		return ieee754sp_nanxcpt(x, "neg", x);
 	return x;
 }
 
#1 lore raw
Quoted 23 lines · Raghu Gandham

From: Robin Randhawa <[email protected]>

---

 arch/mips/math-emu/dp_simple.c |   11 ++++-------
 arch/mips/math-emu/sp_simple.c |    3 ---
 2 files changed, 4 insertions(+), 10 deletions(-)
arch/mips/math-emu/dp_simple.c +3 -1
index 1c555e6..6ff4655 100644
@@ -76,15 +76,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");

arch/mips/math-emu/dp_simple.c ieee754dp ieee754dp_abs(ieee754dp x) · line 87

Quoted 10 lines
arch/mips/math-emu/dp_simple.c +1 -6
+		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;
 }

It seems that abs.s needs the same changes except the string constant. Or why was only abs.d changed?

(And what is the official behaviour anyway. It seems I can spend another quality night over IEEE 754 ...)

arch/mips/math-emu/sp_simple.c ieee754sp ieee754sp_neg(ieee754sp x) · line 65

Quoted 13 lines
arch/mips/math-emu/sp_simple.c +0 -3
index 770f0f4..cdec1a2 100644
@@ -61,9 +61,6 @@ ieee754sp ieee754sp_neg(ieee754sp x)
 		SPSIGN(y) = SPSIGN(x);
 		return ieee754sp_nanxcpt(y, "neg");
 	}
-
-	if (ieee754sp_isnan(x))	/* but not infinity */
-		return ieee754sp_nanxcpt(x, "neg", x);
 	return x;
 }

The subject of the patch was claiming a fix to abs.d but this is fiddling with neg.s. And why not the equivalent change to neg.d?

Ralf

#2 lore raw

It seems like the original patch got mangled somewhere along the line. It should correct the behaviour of abs.[sd] and neg.[sd]. I'll repost the correct patch.

Chris

Signature · 2 lines
Chris Dearman               Desk: +1 408 530 5092  Cell: +1 650 224 8603
MIPS Technologies Inc            955 East Arques Ave, Sunnyvale CA 94085
#3 lore raw

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

From: Nigel Stephens <[email protected]>

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

---

 arch/mips/math-emu/dp_simple.c |   13 ++++---------
 arch/mips/math-emu/sp_simple.c |   11 +++--------
 2 files changed, 7 insertions(+), 17 deletions(-)
arch/mips/math-emu/dp_simple.c +4 -9
index 1c555e6..d9ae1db 100644
@@ -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;
 }
arch/mips/math-emu/sp_simple.c +3 -8
index 770f0f4..3175477 100644
@@ -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;
 }
#4 lore raw

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

Excuse me for too late comment.

Quoted 4 lines · Chris Dearman

From: Nigel Stephens <[email protected]>

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

...

Quoted 10 lines
arch/mips/math-emu/dp_simple.c +3 -2
@@ -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");

arch/mips/math-emu/dp_simple.c ieee754dp ieee754dp_abs(ieee754dp x) · line 85

Quoted 10 lines
arch/mips/math-emu/dp_simple.c +1 -5
+		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;
 }

Is there any reason for removal of SETCX(IEEE754_INVALID_OPERATION) line here?

The older version of this fix ("Fix absd emulation" by Raghu Gandham) did not remove the line.

Without this line, a signaling NaN will not raise a signal. It seems not expected behaviour.

---
Atsushi Nemoto

#5 lore raw

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

Quoted 32 lines · Atsushi Nemoto

Excuse me for too late comment.

Quoted 4 lines · Chris Dearman

From: Nigel Stephens <[email protected]>

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

...

Quoted 10 lines
arch/mips/math-emu/dp_simple.c +3 -2
@@ -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");

arch/mips/math-emu/dp_simple.c ieee754dp ieee754dp_abs(ieee754dp x) · line 85

Quoted 10 lines
arch/mips/math-emu/dp_simple.c +1 -5
+		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;
 }

Is there any reason for removal of SETCX(IEEE754_INVALID_OPERATION) line here?

Quoted 5 lines

The older version of this fix ("Fix absd emulation" by Raghu Gandham) did not remove the line.

Without this line, a signaling NaN will not raise a signal. It seems not expected behaviour.

ieee754dp/sp_nanxcpt also sets the invalid exception bit so I think this is duplicated code. I think the same fix should have been applied to ieee754sp_neg/ieee754dp_neg for consistency.

Chris

Signature · 2 lines
Chris Dearman               Desk: +1 408 530 5092  Cell: +1 408 398 5531
MIPS Technologies Inc            955 East Arques Ave, Sunnyvale CA 94085
#6 lore raw

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

Quoted 5 lines · Chris Dearman
Quoted 5 lines
Quoted 5 lines
arch/mips/math-emu/dp_simple.c +1 -2
 	if (xc == IEEE754_CLASS_SNAN) {
-		SETCX(IEEE754_INVALID_OPERATION);
-		return ieee754dp_nanxcpt(ieee754dp_indef(), "neg");
+		return ieee754dp_nanxcpt(ieee754dp_indef(), "abs");
 	}

...

Quoted 3 lines

ieee754dp/sp_nanxcpt also sets the invalid exception bit so I think this is duplicated code. I think the same fix should have been applied to ieee754sp_neg/ieee754dp_neg for consistency.

ieee754d/sp_nanxcpt will set the invalid exception bit if its first argument was a signaling NaN. And ieee754dp/sp_indef() is a quiet NaN.

---
Atsushi Nemoto

#7 lore raw

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

Quoted 4 lines · Atsushi Nemoto

ieee754d/sp_nanxcpt will set the invalid exception bit if its first argument was a signaling NaN. And ieee754dp/sp_indef() is a quiet NaN.

You're right! I'll send a separate patch with an appropriate subject to correct this.

Thanks
Chris

Signature · 2 lines
Chris Dearman               Desk: +1 408 530 5092  Cell: +1 408 398 5531
MIPS Technologies Inc            955 East Arques Ave, Sunnyvale CA 94085
#8 lore raw

PATCH 1/1 Restore signalling NaN behaviour for abs.[sd]

In reply to Atsushi Nemoto

Atsushi Nemoto <[email protected]> spotted that this had been incorrectly removed in a previous patch

---

 arch/mips/math-emu/dp_simple.c |    1 +
 arch/mips/math-emu/sp_simple.c |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
arch/mips/math-emu/dp_simple.c +1 -0
index d9ae1db..b909742 100644
@@ -78,6 +78,7 @@ ieee754dp ieee754dp_abs(ieee754dp x)
 	DPSIGN(x) = 0;
 
 	if (xc == IEEE754_CLASS_SNAN) {
+		SETCX(IEEE754_INVALID_OPERATION);
 		return ieee754dp_nanxcpt(ieee754dp_indef(), "abs");
 	}
 
arch/mips/math-emu/sp_simple.c +1 -0
index 3175477..2fd53c9 100644
@@ -78,6 +78,7 @@ ieee754sp ieee754sp_abs(ieee754sp x)
 	SPSIGN(x) = 0;
 
 	if (xc == IEEE754_CLASS_SNAN) {
+		SETCX(IEEE754_INVALID_OPERATION);
 		return ieee754sp_nanxcpt(ieee754sp_indef(), "abs");
 	}