This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strange floating point problem


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]