floating point constants on arm

Philip Blundell Philip.Blundell@pobox.com
Mon Apr 24 13:14:00 GMT 2000


This code is distilled from the Linux kernel:

int f(int yTL)
{
	const double fixScale=1.0*256*256;
	const int yScale=(int)(fixScale);	

	return yTL * yScale;
}

Floating point doesn't work inside the kernel.  The author's expectation was 
clearly that GCC would perform the arithmetic and cast it to an int at 
compile time, so that only an integer multiply is needed at runtime.  
Unfortunately, an arm-linux targeted compiler built from the current trunk 
code generates the double->int conversion at run time:

        stmfd   sp!, {r4, lr}
        mov     r4, r0
        adr     r0, .L3
        ldmia   r0, {r0-r1}
        bl      __fixdfsi
        mul     r0, r4, r0
        ldmfd   sp!, {r4, pc}
.L4:
        .align  2
.L3:
        .long 0x40f00000, 0x0   @ double 6.55360000000000000000e4

which is not only slower but actually fails in this situation.

p.




More information about the Gcc-bugs mailing list