--- 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