a math library or floating point problem?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

a math library or floating point problem?

2,678 Views
Dietrich
Contributor II
This message contains an entire topic ported from the WildRice - Coldfire forum.  Freescale has received the approval from the WildRice administrator on seeding the Freescale forum with messages.  The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value as you search for answers to your questions.  Freescale assumes no responsibility whatsoever with respect to Posted Material.  For additional information, please see the Terms of Use - Message Boards and Community Forums.  Thank You and Enjoy the Forum!


Sep 26, 2005, 12:20 AM
Post #1 of 8 (76 views)
Copy Shortcut
 [ColdFire] a math library or floating point problem?  Can't Post 
--------------------------------------------------------------------------------
 
Hi, all!
Here comes another problem when I try to use the "log10" function
in math library with both version 2.4 and 2.6 LinuxBSP on MCF5475EVB.
Toolchain comes from LinuxBSP, with gcc version 3.4.0 and glibc version 2.3.2
Codes like the following:
#include <stdio.h>
#include <math.h>
int main(int argc, char **argv)
{
double a, a1, a2, a3;
a = log10(10);
a1 = log10(100);
a2 = log10(1000);
a3 = log10(10000);

printf("value: %f, %f, %f, %f\n", a, a1, a2, a3);
}
Compiled and run, Results as:
m68k-linux-gcc -mcfv4e -static -o test test.c -lm
sh-2.05# ./test
value: 1.000000, nan, -inf, -inf
Almost all incorrect.
I rarely know about gcc and glibc , please help me out.
Thanks!
BR!
Leo Liu
--------------------------------------------------------------------
Sep 26, 2005, 3:20 PM
Post #2 of 8 (76 views)
Copy Shortcut
 RE: [ColdFire] a math library or floating point problem? [In reply to]  Can't Post 
--------------------------------------------------------------------------------
 
That may be a problem with the printf routine, not the logN(), try %g if its
supported

-----Original Message-----
From: On
Behalf Of Leo Liu
Sent: Monday, September 26, 2005 12:28 AM
Subject: [ColdFire] a math library or floating point problem?

Hi, all!
Here comes another problem when I try to use the "log10" function
in math library with both version 2.4 and 2.6 LinuxBSP on MCF5475EVB.
Toolchain comes from LinuxBSP, with gcc version 3.4.0 and glibc version
2.3.2 Codes like the following:
#include <stdio.h>
#include <math.h>
int main(int argc, char **argv)
{
double a, a1, a2, a3;
a = log10(10);
a1 = log10(100);
a2 = log10(1000);
a3 = log10(10000);

printf("value: %f, %f, %f, %f\n", a, a1, a2, a3);
}
Compiled and run, Results as:
m68k-linux-gcc -mcfv4e -static -o test test.c -lm
sh-2.05# ./test
value: 1.000000, nan, -inf, -inf
Almost all incorrect.
I rarely know about gcc and glibc , please help me out.
Thanks!
BR!
Leo Liu
--------------------------------------------------------------------
Sep 26, 2005, 3:59 PM
Post #3 of 8 (76 views)
Copy Shortcut
 Re: [ColdFire] a math library or floating point problem? [In reply to]  Can't Post 
--------------------------------------------------------------------------------
 
 
>That may be a problem with the printf routine, not the logN(), try %g if its
>supported
Actually I wouldn't be supprised if its a problem with function
prologue/epilogue save/restore of FP registers.
Try:
#include
#include
int main(int argc, char **argv)
{
double a;
union {
double d;
unsigned int u[2];
} dfloat;
dfloat.d = log10(10.0);
printf("%08x %08x\n", dfloat.u[0], dfloat.u[1]);
}
The result should be:
3ff0000 00000000
which is the IEEE-754 big-endian double representation of 1.0
--
Peter Barada
--------------------------------------------------------------------
Sep 26, 2005, 7:07 PM
Post #4 of 8 (76 views)
Copy Shortcut
 Re: Re: [ColdFire] a math library or floating point problem? [In reply to]  Can't Post 
--------------------------------------------------------------------------------
 
>Actually I wouldn't be supprised if its a problem with function
>prologue/epilogue save/restore of FP registers.
>
>Try:
>
>#include <stido.h>
>#include <math.h>
>
>int main(int argc, char **argv)
>{
> double a;
> union {
> double d;
> unsigned int u[2];
> } dfloat;
>
> dfloat.d = log10(10.0);
> printf("%08x %08x\n", dfloat.u[0], dfloat.u[1]);
>}
>
>The result should be:
>3ff0000 00000000
Hi,peter
Following is disassembled from your source code:
......
800003c4 <main>:
800003c4: 4e56 fff0 linkw %fp,#-16
800003c8: 42a7 clrl %sp@-
800003ca: 2f3c 3ff0 0000 movel #1072693248,%sp@-
800003d0: f21f 5444 fdmoved %sp@+,%fp0
800003d4: f22e 7400 fff0 fmoved %fp0,%fp@(-16)
800003da: 2f2e fff4 movel %fp@(-12),%sp@-
800003de: 2f2e fff0 movel %fp@(-16),%sp@-
800003e2: 4879 8000 04d2 pea 800004d2 <_IO_stdin_used+0x4>
800003e8: 61ff ffff ff02 bsrl 800002ec <_init+0x60>
800003ee: 4fef 000c lea %sp@(12),%sp
800003f2: 4e5e unlk %fp
800003f4: 4e75 rts
800003f6: 4e75 rts
......
Obviously, the result comes directly from compiler(movel #1072693248,%sp@-) not the runtime
so it is really nothing with logN function.
If you are right, the problem hides in prologue/epilogue function, could you direct me where
to make the changes or give a patch(if you have)?
Thanks!
BR!
Leo Liu

--------------------------------------------------------------------
Sep 26, 2005, 7:45 PM
Post #5 of 8 (76 views)
Copy Shortcut
 Re: [ColdFire] a math library or floating point problem? [In reply to]  Can't Post 
--------------------------------------------------------------------------------
 
 
>Hi,peter
>Following is disassembled from your source code:
>......
>800003c4 :
>800003c4: 4e56 fff0 linkw %fp,#-16
>800003c8: 42a7 clrl %sp@-
>800003ca: 2f3c 3ff0 0000 movel #1072693248,%sp@-
>800003d0: f21f 5444 fdmoved %sp@+,%fp0
>800003d4: f22e 7400 fff0 fmoved %fp0,%fp@(-16)
>800003da: 2f2e fff4 movel %fp@(-12),%sp@-
>800003de: 2f2e fff0 movel %fp@(-16),%sp@-
>800003e2: 4879 8000 04d2 pea 800004d2 <_IO_stdin_used+0x4>
>800003e8: 61ff ffff ff02 bsrl 800002ec <_init+0x60>
>800003ee: 4fef 000c lea %sp@(12),%sp
>800003f2: 4e5e unlk %fp
>800003f4: 4e75 rts
>800003f6: 4e75 rts
>......
Drats, outsmarted by the optimizer; try compiling without any
optimization. Then you should get the call to log10 (and children).
>If you are right, the problem hides in prologue/epilogue function,
>could you direct me where to make the changes or give a patch(if you have)?
I don't have a patch handy; I'll dig into and see if I can come up
with one.
--
Peter Barada
--------------------------------------------------------------------
Sep 27, 2005, 5:21 AM
Post #6 of 8 (76 views)
Copy Shortcut
 RE: [ColdFire] a math library or floating point problem? [In reply to]  Can't Post 
--------------------------------------------------------------------------------
 
I have patches against Peter's tree to fix the fp prologue/epilogue code.
There is also a bug in the msac.w instruction within the binutils.
I can dig them up if anyone wants them.
-Aaron
-----Original Message-----
From: Peter Barada [mailto:smileytongue:eter@the-baradas.com]
Subject: Re: [ColdFire] a math library or floating point problem?
 
>Hi,peter
>Following is disassembled from your source code:
>......
>800003c4 <main>:
>800003c4: 4e56 fff0 linkw %fp,#-16
>800003c8: 42a7 clrl %sp@-
>800003ca: 2f3c 3ff0 0000 movel #1072693248,%sp@-
>800003d0: f21f 5444 fdmoved %sp@+,%fp0
>800003d4: f22e 7400 fff0 fmoved %fp0,%fp@(-16)
>800003da: 2f2e fff4 movel %fp@(-12),%sp@-
>800003de: 2f2e fff0 movel %fp@(-16),%sp@-
>800003e2: 4879 8000 04d2 pea 800004d2 <_IO_stdin_used+0x4>
>800003e8: 61ff ffff ff02 bsrl 800002ec <_init+0x60>
>800003ee: 4fef 000c lea %sp@(12),%sp
>800003f2: 4e5e unlk %fp
>800003f4: 4e75 rts
>800003f6: 4e75 rts
>......
Drats, outsmarted by the optimizer; try compiling without any
optimization. Then you should get the call to log10 (and children).
>If you are right, the problem hides in prologue/epilogue function,
>could you direct me where to make the changes or give a patch(if you have)?
I don't have a patch handy; I'll dig into and see if I can come up
with one.
--
Peter Barada
--------------------------------------------------------------------
Sep 29, 2005, 12:00 AM
Post #7 of 8 (71 views)
Copy Shortcut
 Re: RE: [ColdFire] a math library or floating point problem? [In reply to]  Can't Post 
--------------------------------------------------------------------------------
 
>I have patches against Peter's tree to fix the fp prologue/epilogue code.
>There is also a bug in the msac.w instruction within the binutils.
>
>I can dig them up if anyone wants them.
Hello, Aaron
Could you please send the patches out or directly to me?
I am really anxious to get away from the fp problems.
Thanks!
BR!
Leo Liu

--------------------------------------------------------------------
Jan 19, 2006, 7:40 AM
Post #8 of 8 (47 views)
Copy Shortcut
 Re: RE: [ColdFire] a math library or floating point problem? [In reply to]  Can't Post 
--------------------------------------------------------------------------------
 
Aaron,
Can you also send these patches to me? I ran across the log10 bug
today.
-Steve
On Thu, 2005-09-29 at 15:07 +0800, Leo Liu wrote:
> >I have patches against Peter's tree to fix the fp prologue/epilogue code.
> >There is also a bug in the msac.w instruction within the binutils.
> >
> >I can dig them up if anyone wants them.
>
> Hello, Aaron
> Could you please send the patches out or directly to me?
> I am really anxious to get away from the fp problems.
>
> Thanks!
>
> BR!
> Leo Liu
>
>
 
 
 

Message Edited by Dietrich on 04-01-2006 11:38 AM

Message Edited by Dietrich on 04-04-2006 09:36 PM

Labels (1)
0 Kudos
1 Reply

480 Views
los
Contributor I
Does anyone know where I can get this patch ?

-Carlos
0 Kudos