Fix rounding bug in emulation for double float operating
PATCH 1/1 Fix rounding bug in emulation for double float operating
This patch fixes rounding bug in emulation for double float operating on PowerPC platform.
When pack double float operand, it need to truncate the tail due to the limited precision. If the truncated part is not zero, the last bit of work bit (totally 3 bits) need to '|' 1.
This patch is completed in _FP_FRAC_SRS_2(X,N,sz) (arch/powerpc/math-emu/op-2.h). Originally the code leftwards rotates the operand to just keep the truncated part, then check whether it is zero. However, the number it rotates is not correct when N is not smaller than _FP_W_TYPE_SIZE, and it will cause the work bit '|' 1 in the improper case.
This patch fixes this issue.
--- arch/powerpc/math-emu/op-2.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
arch/powerpc/math-emu/op-2.h +2 -1
@@ -59,7 +59,8 @@ else \ { \ X##_f0 = (X##_f1 >> ((N) - _FP_W_TYPE_SIZE) | \ - (((X##_f1 << (sz - (N))) | X##_f0) != 0)); \ + (((X##_f1 << (2 * _FP_W_TYPE_SIZE - (N))) | \ + X##_f0) != 0)); \ X##_f1 = 0; \ } \ }while (0 )
Signature · 1 line
1.5.2
Quoted 6 lines · Liu Yu
This patch fixes rounding bug in emulation for double float operating on PowerPC platform.
When pack double float operand, it need to truncate the tail due to the limited precision. If the truncated part is not zero, the last bit of work bit (totally 3 bits) need to '|' 1.
Quoted 8 lines
This patch is completed in
_FP_FRAC_SRS_2(X,N,sz)(arch/powerpc/math-emu/op-2.h). Originally the code leftwards rotates the operand to just keep the truncated part, then check whether it is zero. However, the number it rotates is not correct when N is not smaller than_FP_W_TYPE_SIZE, and it will cause the work bit '|' 1 in the improper case.This patch fixes this issue.
Signed-off-by Liu Yu <[email protected]>
Wow someone deciphered the hideous macro hell of the math emulation code enough to fix a bug. I don't suppose you'd care to fix the millions of warnings that the math-emu code generates...?
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
RE: [PATCH] Fix rounding bug in emulation for double floatoperating
=20
Quoted 31 lines
-----Original Message-----
From: David Gibson [mailto:[email protected]]=20
Sent: Monday, December 10, 2007 12:56 PM
To: Liu Yu
Cc: [email protected]
Subject: Re: [PATCH] Fix rounding bug in emulation for double=20 floatoperating
=20
=20Quoted 2 lines · Liu Yu
=20
This patch fixes rounding bug in emulation for double float=20operating on PowerPC platform.
Quoted 2 lines
=20
When pack double float operand, it need to truncate the=20tail due to the limited precision.
Quoted 1 line
If the truncated part is not zero, the last bit of work bit=20
(totally 3 bits) need to '|' 1.
Quoted 2 lines
=20
This patch is completed in _FP_FRAC_SRS_2(X,N,sz)=20(
arch/powerpc/math-emu/op-2.h).Quoted 2 lines
Originally the code leftwards rotates the operand to just keep the=20 truncated part, then check whether it is zero. However, the=20
number it=20
Quoted 1 line
rotates is not correct when N is not smaller than=20
_FP_W_TYPE_SIZE, and it will cause the work bit '|' 1 in the=20 improper case.Quoted 4 lines
=20
This patch fixes this issue.
=20Signed-off-by Liu Yu <[email protected]>
Quoted 5 lines
=20
Wow someone deciphered the hideous macro hell of the math=20 emulation code enough to fix a bug. I don't suppose you'd=20 care to fix the millions of warnings that the math-emu code=20 generates...?
Oh, I don't like macro define either. But it's really a bug...
Re: [PATCH] Fix rounding bug in emulation for double floatoperating
Quoted 35 lines · Liu Yu
Quoted 35 lines
-----Original Message-----
From: David Gibson [mailto:[email protected]]
Sent: Monday, December 10, 2007 12:56 PM
To: Liu Yu
Cc: [email protected]
Subject: Re: [PATCH] Fix rounding bug in emulation for double floatoperatingQuoted 2 lines · Liu Yu
This patch fixes rounding bug in emulation for double float
operating on PowerPC platform.
Quoted 2 lines
When pack double float operand, it need to truncate the
tail due to the limited precision.
Quoted 1 line
If the truncated part is not zero, the last bit of work bit
(totally 3 bits) need to '|' 1.
Quoted 2 lines
This patch is completed in
_FP_FRAC_SRS_2(X,N,sz)(
arch/powerpc/math-emu/op-2.h).Quoted 2 lines
Originally the code leftwards rotates the operand to just keep the truncated part, then check whether it is zero. However, the
number it
Quoted 1 line
rotates is not correct when N is not smaller than
_FP_W_TYPE_SIZE, and it will cause the work bit '|' 1 in the improper case.Quoted 3 lines
This patch fixes this issue.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Liu Yu <[email protected]>Wow someone deciphered the hideous macro hell of the math emulation code enough to fix a bug. I don't suppose you'd care to fix the millions of warnings that the math-emu code generates...?
Oh, I don't like macro define either. But it's really a bug...
how did you find this?
- k
RE: [PATCH] Fix rounding bug in emulation for double floatoperating
Quoted 46 lines
-----Original Message-----
From: Kumar Gala [mailto:[email protected]]=20
Sent: Monday, December 10, 2007 11:01 PM
To: Liu Yu
Cc: David Gibson; [email protected]
Subject: Re: [PATCH] Fix rounding bug in emulation for double=20 floatoperating
=20
=20Quoted 14 lines · Liu Yu
Quoted 14 lines
-----Original Message-----
From: David Gibson [mailto:[email protected]]
Sent: Monday, December 10, 2007 12:56 PM
To: Liu Yu
Cc: [email protected]
Subject: Re: [PATCH] Fix rounding bug in emulation for double=20 floatoperatingQuoted 2 lines · Liu Yu
This patch fixes rounding bug in emulation for double float
operating on PowerPC platform.
Quoted 1 line
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
When pack double float operand, it need to truncate the
tail due to the limited precision.
Quoted 1 line
If the truncated part is not zero, the last bit of work bit
(totally 3 bits) need to '|' 1.
Quoted 2 lines
This patch is completed in
_FP_FRAC_SRS_2(X,N,sz)(
arch/powerpc/math-emu/op-2.h).Quoted 1 line
Originally the code leftwards rotates the operand to just=20
keep the=20
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
truncated part, then check whether it is zero. However, the
number it
Quoted 1 line
rotates is not correct when N is not smaller than
_FP_W_TYPE_SIZE, and it will cause the work bit '|' 1 in=20the improper=20
Quoted 7 lines
Quoted 7 lines
case.
Quoted 4 lines
This patch fixes this issue.
Signed-off-by Liu Yu <[email protected]>Wow someone deciphered the hideous macro hell of the math=20
Quoted 8 lines
emulation=20
Quoted 4 lines
Quoted 2 lines
code enough to fix a bug. I don't suppose you'd care to fix the=20 millions of warnings that the math-emu code generates...?
Oh, I don't like macro define either. But it's really a bug...
=20
=20
how did you find this?
Well, when divide the min positive number by 2, you will get the work bit "101" which is supposed to be "100".
And the wrong result will influent the succedent rounding operation.
In fact, the similar macro _FP_FRAC_SRS_1 and _FP_FRAC_SRS_4 are correct. This bug just exists in _FP_FRAC_SRS_2.
Quoted 3 lines
=20
- k
=20
Re: [PATCH] Fix rounding bug in emulation for double floatoperating
In reply to Kumar GalaQuoted 39 lines · Kumar Gala
Quoted 38 lines · Liu Yu
Quoted 37 lines
-----Original Message-----
From: David Gibson [mailto:[email protected]]
Sent: Monday, December 10, 2007 12:56 PM
To: Liu Yu
Cc: [email protected]
Subject: Re: [PATCH] Fix rounding bug in emulation for double floatoperatingQuoted 2 lines · Liu Yu
This patch fixes rounding bug in emulation for double float
operating on PowerPC platform.
Quoted 2 lines
When pack double float operand, it need to truncate the
tail due to the limited precision.
Quoted 1 line
If the truncated part is not zero, the last bit of work bit
(totally 3 bits) need to '|' 1.
Quoted 2 lines
This patch is completed in
_FP_FRAC_SRS_2(X,N,sz)(
arch/powerpc/math-emu/op-2.h).Quoted 2 lines
Originally the code leftwards rotates the operand to just keep the truncated part, then check whether it is zero. However, the
number it
Quoted 1 line
rotates is not correct when N is not smaller than
_FP_W_TYPE_SIZE, and it will cause the work bit '|' 1 in the improper case.Quoted 4 lines
This patch fixes this issue.
Signed-off-by Liu Yu <[email protected]>Wow someone deciphered the hideous macro hell of the math emulation code enough to fix a bug. I don't suppose you'd care to fix the millions of warnings that the math-emu code generates...?
Quoted 5 lines
Quoted 1 line
Oh, I don't like macro define either. But it's really a bug...
how did you find this?
It supposed to run the following test case on a powerpc platform. Yu's patch fixes the issue.
Could you help to merge this patch in your tree?
---
#include <stdio.h>
#include <math.h>
#include <bits/nan.h>
#ifdef __SPE__
#include <spe.h>
intgetSPEFSCR()
{
return __builtin_spe_mfspefscr();
}void
setSPEFSCR(int i)
{
__builtin_spe_mtspefscr(i);
}
#else
int
getSPEFSCR()
{
return 0;
}void
setSPEFSCR(int i)
{
}
#endif
voiddmul(double d, double d1, double expected)
{
double d2;
int before, after;
before = getSPEFSCR();
d2 = d * d1;
after = getSPEFSCR();
printf("dmul %llx * %llx = %llx expected %llx %s [0x%x 0x%x]\n", d, d1, d2, expected,
(d2 == expected) ? "(PASS)" : "(FAIL)", before, after);
}voidddiv(double d, double d1, double expected)
{
register double d2;
int before, after;
before = getSPEFSCR();
d2 = d / d1;
after = getSPEFSCR();
printf("ddiv %llx / %llx = %llx expected %llx %s [0x%x 0x%x]\n", d, d1, d2, expected,
(d2 == expected) ? "(PASS)" : "(FAIL)", before, after);
}main()
{
const double min_double = 4.9406564584124654e-324L;
printf("\n");
dmul(0.5L, min_double, 0.0L);
dmul(-0.5L, min_double, 0.0L);
dmul(-min_double, -0.5L, 0.0L);
printf("\n");
ddiv(min_double, 2.0L, 0.0L);
}Re: [PATCH] Fix rounding bug in emulation for double floatoperating
Quoted 67 lines
Quoted 3 lines
how did you find this?
It supposed to run the following test case on a powerpc platform. Yu's patch fixes the issue.
Could you help to merge this patch in your tree?
---
#include <stdio.h>
#include <math.h>
#include <bits/nan.h>
#ifdef__SPE__
#include <spe.h>
intgetSPEFSCR(){ return __builtin_spe_mfspefscr(); }void
setSPEFSCR(int i){ __builtin_spe_mtspefscr(i); } #else int getSPEFSCR() { return 0; }void
setSPEFSCR(int i)
{
}
#endifvoid
dmul(double d, double d1, double expected){ double d2; int before, after; before = getSPEFSCR(); d2 = d * d1; after = getSPEFSCR(); printf("dmul %llx * %llx = %llx expected %llx %s [0x%x 0x%x]\n", d, d1, d2, expected, (d2 == expected) ? "(PASS)" : "(FAIL)", before, after); }void
ddiv(double d, double d1, double expected){ register double d2; int before, after; before = getSPEFSCR(); d2 = d / d1; after = getSPEFSCR(); printf("ddiv %llx / %llx = %llx expected %llx %s [0x%x 0x%x]\n", d, d1, d2, expected, (d2 == expected) ? "(PASS)" : "(FAIL)", before, after); }
main()
Quoted 10 lines
{
const double min_double = 4.9406564584124654e-324L;
printf("\n");
dmul(0.5L, min_double, 0.0L);
dmul(-0.5L, min_double, 0.0L);
dmul(-min_double, -0.5L, 0.0L);
printf("\n");
ddiv(min_double, 2.0L, 0.0L);
}When I run this on a G5 (w/HW FP) I get:
dmul 3fe0000000000000 * 1 = 0 expected 0 (PASS)
dmul bfe0000000000000 * 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 * bfe0000000000000 = 0 expected 0 (PASS)
ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
and on the 85xx w/FP emu:
dmul 3fe0000000000000 * 1 = 0 expected 0 (PASS)
dmul bfe0000000000000 * 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 * bfe0000000000000 = 0 expected 0 (PASS)
ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
Maybe I'm missing where the error is.
- k
Re: [PATCH] Fix rounding bug in emulation for double floatoperating
Quoted 88 lines · Kumar Gala
Quoted 67 lines
Quoted 3 lines
how did you find this?
It supposed to run the following test case on a powerpc platform. Yu's patch fixes the issue.
Could you help to merge this patch in your tree?
---
#include <stdio.h>
#include <math.h>
#include <bits/nan.h>
#ifdef__SPE__
#include <spe.h>
intgetSPEFSCR(){ return __builtin_spe_mfspefscr(); }void
setSPEFSCR(int i){ __builtin_spe_mtspefscr(i); } #else int getSPEFSCR() { return 0; }void
setSPEFSCR(int i)
{
}
#endifvoid
dmul(double d, double d1, double expected){ double d2; int before, after; before = getSPEFSCR(); d2 = d * d1; after = getSPEFSCR(); printf("dmul %llx * %llx = %llx expected %llx %s [0x%x 0x%x]\n", d, d1, d2, expected, (d2 == expected) ? "(PASS)" : "(FAIL)", before, after); }void
ddiv(double d, double d1, double expected){ register double d2; int before, after; before = getSPEFSCR(); d2 = d / d1; after = getSPEFSCR(); printf("ddiv %llx / %llx = %llx expected %llx %s [0x%x 0x%x]\n", d, d1, d2, expected, (d2 == expected) ? "(PASS)" : "(FAIL)", before, after); }
main()Quoted 10 lines
{ const double min_double = 4.9406564584124654e-324L; printf("\n"); dmul(0.5L, min_double, 0.0L); dmul(-0.5L, min_double, 0.0L); dmul(-min_double, -0.5L, 0.0L); printf("\n"); ddiv(min_double, 2.0L, 0.0L); }When I run this on a G5 (w/HW FP) I get:
dmul
3fe0000000000000* 1 = 0 expected 0 (PASS)
dmulbfe0000000000000* 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 *bfe0000000000000= 0 expected 0 (PASS)ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
and on the 85xx w/FP emu:
Quoted 7 lines
dmul
3fe0000000000000* 1 = 0 expected 0 (PASS)
dmulbfe0000000000000* 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 *bfe0000000000000= 0 expected 0 (PASS)ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
Maybe I'm missing where the error is.
I am missing ...
It is supposed to run based on previous IEEE 754 patch.
http://ozlabs.org/pipermail/linuxppc-dev/2007-February/031351.html
Roy
Re: [PATCH] Fix rounding bug in emulation for double floatoperating
Quoted 14 lines
Quoted 14 lines
When I run this on a G5 (w/HW FP) I get:
dmul
3fe0000000000000* 1 = 0 expected 0 (PASS)
dmulbfe0000000000000* 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 *bfe0000000000000= 0 expected 0 (PASS)ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
and on the 85xx w/FP emu:
dmul
3fe0000000000000* 1 = 0 expected 0 (PASS)
dmulbfe0000000000000* 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 *bfe0000000000000= 0 expected 0 (PASS)
Quoted 6 lines
Quoted 3 lines
ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
Maybe I'm missing where the error is.
I am missing ...
It is supposed to run based on previous IEEE 754 patch.
http://ozlabs.org/pipermail/linuxppc-dev/2007-February/031351.html
Ok, but the test case should care if we are doing full "classic" emulation or fixup of e500 FP.
- k
Re: [PATCH] Fix rounding bug in emulation for double floatoperating
In reply to Zang Roy-r61911Quoted 14 lines
Quoted 14 lines
When I run this on a G5 (w/HW FP) I get:
dmul
3fe0000000000000* 1 = 0 expected 0 (PASS)
dmulbfe0000000000000* 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 *bfe0000000000000= 0 expected 0 (PASS)ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
and on the 85xx w/FP emu:
dmul
3fe0000000000000* 1 = 0 expected 0 (PASS)
dmulbfe0000000000000* 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 *bfe0000000000000= 0 expected 0 (PASS)
Quoted 6 lines
Quoted 3 lines
ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
Maybe I'm missing where the error is.
I am missing ...
It is supposed to run based on previous IEEE 754 patch.
http://ozlabs.org/pipermail/linuxppc-dev/2007-February/031351.html
I'd really like to see to see a testcase show the issue with "classic FP emu" on a 85xx system.
(seems like it should be pretty straight forward).
- k
Re: [PATCH] Fix rounding bug in emulation for double floatoperating
Quoted 16 lines · Kumar Gala
Quoted 16 lines
Quoted 16 lines
When I run this on a G5 (w/HW FP) I get:
dmul
3fe0000000000000* 1 = 0 expected 0 (PASS)
dmulbfe0000000000000* 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 *bfe0000000000000= 0 expected 0 (PASS)ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
and on the 85xx w/FP emu:
dmul
3fe0000000000000* 1 = 0 expected 0 (PASS)
dmulbfe0000000000000* 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 *bfe0000000000000= 0 expected 0 (PASS)ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Maybe I'm missing where the error is.
I am missing ...
It is supposed to run based on previous IEEE 754 patch.
http://ozlabs.org/pipermail/linuxppc-dev/2007-February/031351.htmlI'd really like to see to see a testcase show the issue with "classic FP emu" on a 85xx system.
I can understand.
You know, For a 85xx system without the previous patch or other 'classic' powerpc, it is hard to trigger this issue. Although I believe it is a problem fixed up.
Do you have any idea?
Roy
Re: [PATCH] Fix rounding bug in emulation for double floatoperating
Quoted 22 lines · On Dec 14, 2007, at 12:06 AM, Zang Roy-r61911 wrote:
Quoted 21 lines · Kumar Gala
Quoted 20 lines
Quoted 10 lines
When I run this on a G5 (w/HW FP) I get:
dmul
3fe0000000000000* 1 = 0 expected 0 (PASS)
dmulbfe0000000000000* 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 *bfe0000000000000= 0 expected 0 (PASS)ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
and on the 85xx w/FP emu:
Quoted 7 lines
dmul
3fe0000000000000* 1 = 0 expected 0 (PASS)
dmulbfe0000000000000* 1 = 8000000000000000 expected 0 (PASS) dmul 8000000000000001 *bfe0000000000000= 0 expected 0 (PASS)ddiv 1 / 4000000000000000 = 0 expected 0 (PASS)
Maybe I'm missing where the error is.
I am missing ...
It is supposed to run based on previous IEEE 754 patch.
http://ozlabs.org/pipermail/linuxppc-dev/2007-February/031351.html
Quoted 7 lines
Quoted 2 lines
I'd really like to see to see a testcase show the issue with "classic FP emu" on a 85xx system.
I can understand.
You know, For a 85xx system without the previous patch or other 'classic' powerpc, it is hard to trigger this issue. Although I believe it is a problem fixed up.
Do you have any idea?
maybe I'm missing it, but can we not do the same operation w/classic FP that you are doing w/SPE fp?
is this in standard rounding mode, etc?
- k
Kumar Gala
AppliedQuoted 11 lines · Liu Yu
This patch fixes rounding bug in emulation for double float operating on PowerPC platform.
When pack double float operand, it need to truncate the tail due to the limited precision. If the truncated part is not zero, the last bit of work bit (totally 3 bits) need to '|' 1.
This patch is completed in
_FP_FRAC_SRS_2(X,N,sz)(arch/powerpc/math-emu/op-2.h). Originally the code leftwards rotates the operand to just keep the truncated part, then check whether it is zero. However, the number it rotates is not correct when N is not smaller than_FP_W_TYPE_SIZE, and it will cause the work bit '|' 1 in the improper case.
Quoted 7 lines
This patch fixes this issue.
Signed-off-by Liu Yu <[email protected]>---
arch/powerpc/math-emu/op-2.h| 3 ++-1 files changed, 2 insertions(+), 1 deletions(-)
applied.
- k