Skip to contentSkip to conversation

parisc: test off by one in sgl_frem() and dbl_frem()

PATCH In review Roel Kluin 3 participants 4 messages Dec 27, 2009 PA-RISC architecture

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 parisc: test off by one in sgl_frem() and dbl_frem()

With `while (stepcount-- > 0)' stepcount reaches -1 after the loop.

---
 arch/parisc/math-emu/dfrem.c |    2 +-
 arch/parisc/math-emu/sfrem.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Unless I am missing something?

arch/parisc/math-emu/dfrem.c +1 -1
index b983785..3283445 100644
@@ -234,7 +234,7 @@ dbl_frem (dbl_floating_point * srcptr1, dbl_floating_point * srcptr2,
 		Dbl_subtract(opnd1p1,opnd1p2,opnd2p1,opnd2p2,opnd1p1,opnd1p2);
 		roundup = TRUE;
 	}
-	if (stepcount > 0 || Dbl_iszero(opnd1p1,opnd1p2)) {
+	if (stepcount >= 0 || Dbl_iszero(opnd1p1,opnd1p2)) {
 		/* division is exact, remainder is zero */
 		Dbl_setzero_exponentmantissa(resultp1,resultp2);
 		Dbl_copytoptr(resultp1,resultp2,dstptr);
arch/parisc/math-emu/sfrem.c +1 -1
index 3a1b7a3..ad87832 100644
@@ -229,7 +229,7 @@ sgl_frem (sgl_floating_point * srcptr1, sgl_floating_point * srcptr2,
 		Sgl_subtract(opnd1,opnd2,opnd1);
 		roundup = TRUE;
 	}
-	if (stepcount > 0 || Sgl_iszero(opnd1)) {
+	if (stepcount >= 0 || Sgl_iszero(opnd1)) {
 		/* division is exact, remainder is zero */
 		Sgl_setzero_exponentmantissa(result);
 		*dstptr = result;
#1 lore raw
Quoted 9 lines

With `while (stepcount-- > 0)' stepcount reaches -1 after the loop.

---
 arch/parisc/math-emu/dfrem.c |    2 +-
 arch/parisc/math-emu/sfrem.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Unless I am missing something?

Are you sure the correct fix isn't to move the decrement of stepcount into the loop?

Dave

Signature · 2 lines
J. David Anglin                                  [email protected]
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)
maintainer
#2 lore raw
In reply to Roel Kluin
Quoted 1 line · Roel Kluin

With `while (stepcount-- > 0)' stepcount reaches -1 after the loop.

This is true, but seems to be by design

Quoted 26 lines
---
 arch/parisc/math-emu/dfrem.c |    2 +-
 arch/parisc/math-emu/sfrem.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Unless I am missing something?

arch/parisc/math-emu/dfrem.c +1 -1
index b983785..3283445 100644
@@ -234,7 +234,7 @@ dbl_frem (dbl_floating_point * srcptr1, dbl_floating_point * srcptr2,
 		Dbl_subtract(opnd1p1,opnd1p2,opnd2p1,opnd2p2,opnd1p1,opnd1p2);
 		roundup = TRUE;
 	}
-	if (stepcount > 0 || Dbl_iszero(opnd1p1,opnd1p2)) {
+	if (stepcount >= 0 || Dbl_iszero(opnd1p1,opnd1p2)) {
 		/* division is exact, remainder is zero */
 		Dbl_setzero_exponentmantissa(resultp1,resultp2);
 		Dbl_copytoptr(resultp1,resultp2,dstptr);
arch/parisc/math-emu/sfrem.c +0 -0
index 3a1b7a3..ad87832 100644

arch/parisc/math-emu/sfrem.c sgl_frem (sgl_floating_point * srcptr1, sgl_floating_point * srcptr2, · line 235

Quoted 8 lines
arch/parisc/math-emu/sfrem.c +1 -1
@@ -229,7 +229,7 @@ sgl_frem (sgl_floating_point * srcptr1, sgl_floating_point * srcptr2,
 		Sgl_subtract(opnd1,opnd2,opnd1);
 		roundup = TRUE;
 	}
-	if (stepcount > 0 || Sgl_iszero(opnd1)) {
+	if (stepcount >= 0 || Sgl_iszero(opnd1)) {
 		/* division is exact, remainder is zero */
 		Sgl_setzero_exponentmantissa(result);
 		*dstptr = result;

Your patch does nothing to the actual execution flow (Sgl_iszero is true if stepcount == 0) ... what's the point of applying it?

James

author
#3 lore raw

Op 27-12-09 16:30, James Bottomley schreef:

Quoted 5 lines · Roel Kluin
Quoted 1 line

With `while (stepcount-- > 0)' stepcount reaches -1 after the loop.

This is true, but seems to be by design

Quoted 8 lines

arch/parisc/math-emu/sfrem.c sgl_frem (sgl_floating_point * srcptr1, sgl_floating_point * srcptr2, · line 232

Quoted 2 lines
arch/parisc/math-emu/sfrem.c +1 -1
-	if (stepcount > 0 || Sgl_iszero(opnd1)) {
+	if (stepcount >= 0 || Sgl_iszero(opnd1)) {

Your patch does nothing to the actual execution flow (Sgl_iszero is true if stepcount == 0) ... what's the point of applying it?

James

Ok, please ignore and thanks (also to Dave) for review.

Roel