[Mono-dev] floating point arithmetic on ARMv4t (arm920t)
Dennis Krzyzaniak
dkml at conworx.com
Mon Jun 11 12:56:12 UTC 2012
No progress with my floating point issue.
I switch to double in my short test application because they can be at least
correctly printed (but operations like multiplication does not work).
using System;
namespace foobar {
public class foo {
public static void Main(string[] args) {
double fa = 1.4;
double fb = 1.3;
double fab = fa * fb;
Console.WriteLine("fa * fb = {0}", fab);
}
}
}
If I am using float instead of double I got very strange results like
-3.513059E-06. Maybe interesting is that each time I invoke the app I got a
different result for floats.
With double I can also print the values with Console.WriteLine which is not
possible with float. The result here is
fa * fb = 1.4
whereby the result is always fa (if I change fa to 1.7 I get 1.7 as result).
Following this thread here
http://software.1713.n2.nabble.com/Arm9-NS9215-floating-point-troubles-td519
1588.html I could see that I have the same swapped 32bit high/low problem on
my target. Unfortunately it did not fix my problem. I could see with my
debugger (I am able to remote debug on the target) that several calls to
mono_method_to_ir are executed before mono_decompose_soft_float is called
where the fix is done in the link above. So I added the fix to
mono_method_to_ir in the switch case statement for (*ip) case CEE_LDC_R8 (I
tested both variants without success).
The double value in ip is:
(gdb) p/x ip[0]@8
$4 = {0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0xf6, 0x3f}
With the fix/hack I got the correct order as it is represented on the target
system:
(gdb) p/x tmp[0]@8
$8 = {0x66, 0x66, 0xf6, 0x3f, 0x66, 0x66, 0x66, 0x66}
6447 readr8 (tmp, d);
(gdb) n
6451 ip += 8;
(gdb) p *d
$7 = 1.3999999999999999
This change seems to have no effect on the result but at least I can see the
correct values for 'double *d' in mono_method_to_ir and 'DVal d.vald' in
mono_decompose_soft_float.
In fact I am completely out of ideas where to continue the search for an
error (Mono is completely new for me).
What happens for 'fa * fb', where can I break in the code to check some
values?
Can I dump out the intermediate representation at some place? Would this
help?
Any idea why I get different outputs using floats for each run of the test
app?
Any idea why I got the first value fa as result for each run using double?
Any idea, comment, hint would be helpful.
Best regards,
Dennis Krzyzaniak
Von: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com] Im Auftrag von Dennis
Krzyzaniak
Gesendet: Donnerstag, 7. Juni 2012 09:14
An: mono-devel-list at lists.ximian.com
Betreff: [Mono-dev] floating point arithmetic on ARMv4t (arm920t)
Hi all,
I am still working to get Mono running on an ARM920t (ARMv4t). Currently I
am hitting a problem with broken floating point arithmetic on my device.
Using this little test app:
namespace foobar {
public class foo {
public static void Main(string[] args) {
int i = 0;
float fa = 1.0001F;
float fb = 0.0001F;
float fs = 0;
for (i=0; i<5; i++)
{
fs = fs * fa + fb;
Console.WriteLine("float loop {0} {1}", i, fs);
}
}
}
}
Gives the result:
/host/bin # ./mono hello_world.exe
float loop 0 -3.513059E-06
float loop 1 -3.513059E-06
float loop 2 -3.513059E-06
float loop 3 -3.513059E-06
float loop 4 -3.513059E-06
The processor has no FPU so I used the soft float configuration. I also
tried little and big endian build with the same behavior.
I described my configuration settings in this post:
http://lists.ximian.com/pipermail/mono-devel-list/2012-June/038922.html .
The only new thing is that I am using CFLAGS now to avoid the default
optimization level O2 which also breaks my runtime.
I am completely new to Mono and need some help to find the correct place
where the error could result from. I guess it is somewhere in
method-to-ir.c? Can you point me to the source code places where maybe some
adaptions could be needed that I can test a little bit? I think it is
something related to my ARM architecture but I am not sure.
Best regards,
Dennis Krzyzaniak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120611/946f5100/attachment.html>
More information about the Mono-devel-list
mailing list