[Bug c/39085] New: Floating point errors on Arm9 processor

2009-02-03 Thread mp2 at ladybridge dot com
On an Arm9 processor running Debian the following program gives the results
indicated...
#include 
#include 
#include 

int main()
{
 double in, out;
 in = 2.0;
 out = sqrt(in);
 printf("%f\n", out);   // 2.
 printf("%f\n", sqrt(in));  // 1.414214
 printf("%f\n", sqrt(2.0)); // 1.414214
 return 0;
}

It works for most values but some obvious ones, all of which seem to be powers
of two, fail though not all powers of two.

This also seems to affect other floating point operations.


-- 
   Summary: Floating point errors on Arm9 processor
   Product: gcc
   Version: 4.1.2
Status: UNCONFIRMED
  Severity: major
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
    ReportedBy: mp2 at ladybridge dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39085



[Bug target/39085] Floating point errors on Arm9 processor

2009-02-15 Thread mp2 at ladybridge dot com


--- Comment #2 from mp2 at ladybridge dot com  2009-02-15 12:14 ---
(In reply to comment #1)
> sqrt is usually implemented as a library function and GCC does not implement 
> it
> for you.  Do you use newlib?

My previous reply doesn't seem to have made it into the system. Here it is
again...
As far as I can see, there is no library named newlib or anything near it on
this system. What is this library and where do I get it?

I am not convinced that this is a library issue as two of the sqrt() functions
in the program work though the last has been pre-evaluated to a constant by the
gcc compiler. The problem only happens when the result is stored in a variable.

I cannot find any good documentation for the Arm9 assembler but by inspired
guesswork interpreting the instruction names, the code generated for the
program looks very odd as there appears to be a conditional jump around the
sqrt() function.

int main()
{
 double in, out;
 in = 2.0;
 out = sqrt(in);
 printf("%f\n", out);
 printf("%f\n", sqrt(in));
 printf("%f\n", sqrt(2.0));
 return 0;
}

Assembler code...

  .file "a.c"
  .section  .rodata
  .align2
.LC0:
  .ascii"%f\012\000"
  .text
  .align2
  .global   main
  .type main, %function
main:
  @ args = 0, pretend = 0, frame = 24
  @ frame_needed = 1, uses_anonymous_args = 0
  mov   ip, sp
  stmfd sp!, {r4, fp, ip, lr, pc}
  sub   fp, ip, #4
  sub   sp, sp, #24
  adr   r3, .L4
  ldmia r3, {r3-r4}
  str   r3, [fp, #-32]
  str   r4, [fp, #-28]
  ldfd  f0, [fp, #-32]
  sqtd  f0, f0
  stfd  f0, [fp, #-40]
  ldfd  f0, [fp, #-40]
  ldfd  f0, [fp, #-40]
  cmf   f0, f0
  beq   .L2<
  sub   r0, fp, #32
  ldmia r0, {r0-r1}
  blsqrt
  stfd  f0, [fp, #-40]
.L2:
  sub   r3, fp, #40
  ldmia r3, {r3-r4}
  str   r3, [fp, #-24]
  str   r4, [fp, #-20]
  ldr   r0, .L4+16
  sub   r1, fp, #24
  ldmia r1, {r1-r2}
  blprintf
  sub   r0, fp, #32
  ldmia r0, {r0-r1}
  blsqrt
  stfd  f0, [sp, #-8]!
  ldmfd sp!, {r3, r4}
  ldr   r0, .L4+16
  mov   r1, r3
  mov   r2, r4
  blprintf
  ldr   r0, .L4+16
  adr   r1, .L4+8
  ldmia r1, {r1-r2}
  blprintf
  mov   r3, #0
  mov   r0, r3
  sub   sp, fp, #16
  ldmfd sp, {r4, fp, sp, pc}
.L5:
  .align2
.L4:
  .word 1073741824
  .word 0
  .word 1073127582
  .word 1719614413
  .word .LC0
  .size main, .-main
  .ident"GCC: (GNU) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)"


Martin Phillips
Ladybridge Systems Ltd
17b Coldstream Lane, Hardingstone, Northampton, NN4 6DB
+44-(0)1604-709200


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39085



[Bug target/39085] Floating point errors on Arm9 processor

2009-02-16 Thread mp2 at ladybridge dot com


--- Comment #4 from mp2 at ladybridge dot com  2009-02-16 09:10 ---
(In reply to comment #3)
> I would generate the assembly by using a local function name rather than
> using main().
The original problem was deep in a complex program. I was trying to bring it
down to the shortest program that demonstrated the issue.

> From what I'm seeing, I don't know if it might be a typecasting issue
>did you try something like this? " (float)out = sqrt((float)in); "

Tried this and it still fails.

Also, the problem affects many mathematical functions, not just sqrt(). I first
saw it with sin().

Thanks for your help.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39085



[Bug target/39085] Floating point errors on Arm9 processor

2009-03-13 Thread mp2 at ladybridge dot com


--- Comment #5 from mp2 at ladybridge dot com  2009-03-13 17:36 ---
Is there any progress on looking at this problem? It is causing a delay in
releasing software on the Arm9 processor.

Thanks.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39085