Inline functiion in GCC

Nathan Sidwell nathan@codesourcery.com
Fri Aug 6 11:51:00 GMT 2004


Venkatachala Upadhya wrote:

> __inline__ static int add(int, int) __attribute__ ((always_inline));
> 
> __inline__ static int add(int x, int y)
> {
>    int xs, ys;
>    __asm__  __volatile__
>    (
>         "mov     %3, %0, lsl #16 \n;"
>         "mov     %4, %2, lsl #16 \n;"
>         "qadd    %3, %3, %4 \n;"
>         "mov     %0, %3, asr #16 \n;"
>         : "=r" (x)
>         : "0" (x), "r" (y), "r" (xs), "r" (ys)
>    ) ;
this doesn't look at all right.
* You're writing to input registers (%3, & %4).
* the insert does not appear to have any volatile side effects.
* the only compiler unknown instruction in there is possibly qadd (I'm
not sure what that does and I don't have an ARM manual infront of me).

I suspect you'd get better results by writing this as
	int xs = x << 16;
	int ys = y << 16;
	int tmp;
	__asm__ ("qadd %0, %1, %2" : "=r" (tmp) : "r" (xs), "r" (ys));
	x = tmp >> 16;

you should probably turn the optimizer on, too.

nathan
-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk




More information about the Gcc mailing list