------- Comment #3 from rbala at coresfoundation dot com 2009-02-15 20:43 ------- Hi all,
Correct me if I'm wrong. @mp2 - newlib is a source of 'C' libraries for various arch's. You won't find a directory as such called newlib. While building your toolchain, you compile all the files in the newlib source. Coming to your issue, I shall verify it again. I don't think it is a GCC issue., but I shall verify it. I saw the assembly code, but I shall again generate the assembly myself., atleast from my perspective, I would generate the assembly by using a local function name rather than using main(). I mean I wouldn't use the fn.name as main() when I was to debug a function's assembly, because main() being a generic fn. Name might induce some other fn.calls(I may be wrong here) but what I'm saying is, its just a good practice. >From what I'm seeing, I don't know if it might be a typecasting issue, (don't know for sure), did you try something like this? " (float)out = sqrt((float)in); " (In reply to comment #2) > (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 > .align 2 > .LC0: > .ascii "%f\012\000" > .text > .align 2 > .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} > bl sqrt > 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} > bl printf > sub r0, fp, #32 > ldmia r0, {r0-r1} > bl sqrt > stfd f0, [sp, #-8]! > ldmfd sp!, {r3, r4} > ldr r0, .L4+16 > mov r1, r3 > mov r2, r4 > bl printf > ldr r0, .L4+16 > adr r1, .L4+8 > ldmia r1, {r1-r2} > bl printf > mov r3, #0 > mov r0, r3 > sub sp, fp, #16 > ldmfd sp, {r4, fp, sp, pc} > .L5: > .align 2 > .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