This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: strange floating point problem
- From: Harald Krammer <Harald dot Krammer at hkr dot at>
- To: Segher Boessenkool <segher at kernel dot crashing dot org>
- Cc: John Love-Jensen <eljay at adobe dot com>, Harald Krammer <harald dot krammer at hkr dot at>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Sun, 25 Feb 2007 18:51:01 +0100
- Subject: Re: strange floating point problem
- References: <C2032AD7.1CBAB%eljay@adobe.com> <be05818dd5aed0a40f79ec7575345e34@kernel.crashing.org>
Hello Segher,
I made some tests and now it is clear for me, when the problem exists.
Main function with flag -O3:
----------------------------
.LC0:
.ascii "Float:%f UINT:%lu\n\000"
.align 2
.LC1:
.ascii "HEX:%x\n\000"
.text
.align 2
.global main
.type main, %function
main:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
mov r1, #39168
add r0, r1, #153
stmfd sp!, {r4, lr}
orr r4, r0, r0, asl #16
mov r3, r4
adr r1, .L4
ldmia r1, {r1-r2}
ldr r0, .L4+8
bl printf
mov r1, r4
ldr r0, .L4+12
bl printf
mov r0, #0
ldmfd sp!, {r4, pc}
.L5:
.align 2
.L4:
.word 1105408819
.word 858993459
.word .LC0
.word .LC1
.size main, .-main
When I compile the code with -O3 the gcc makes an optimization, so that
GetVal will never called and the conversion works as expected.
In a second test I moved GetVal in an own module and in this case the
problem is always present with -O3, because the compiler can't optimize
the function with an external function and the compiler must call GetVal.
Your are right, the problems really seems in the softfloat library....
GetVal:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
str lr, [sp, #-4]!
bl __fixunsdfsi
ldr pc, [sp], #4
.size GetVal, .-GetVal
The compiler call only __fixunsdfsi to convert float into unsigned long.
I will look into this function.
Nice greetings,
Harald
Segher Boessenkool schrieb:
>> What results do you get if your printf format specifiers match the
>> actual
>> data type being passed in...
>>
>> double - %lf
>
> Plain %f means double, too -- all "float" are
> promoted to "double" when passed to a varargs
> function.
>
>> unsigned long - %lu or %lx
>
> Doesn't matter on his platform (ARM); although
> of course it _is_ incorrect to say %x instead
> of %lx, it doesn't change the result.
>
> It looks like there is a bug in the soft float
> library. Harald, look at the generated assembler
> code (compile with -S instead of -c) to find out
> what's going on, to see why -O3 works.
>
>
> Segher
>
--
Harald Krammer
Brucknerstrasse 33
A - 4020 Linz
AUSTRIA
Mobil +43.(0) 664. 130 59 58
Mail: Harald.Krammer (at) hkr.at