This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Inline functiion in GCC
- From: jeroen dobbelaere <jeroen dot dobbelaere at acunia dot com>
- To: venkatu at samsung dot com
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 06 Aug 2004 13:39:21 +0200
- Subject: RE: Inline functiion in GCC
- Organization: ACUNIA
Hi Venkatachala Upadhya,
Your inline problem would probably work better if you would add optimization when compiling.
(-O2 for example).
I've changed your example into the following :
The assembly function was changed in such way, that gcc can reorder
instructions at will.
#include <stdio.h>
#include <stdlib.h>
__inline__ static int add(int x, int y)
{
__asm__
(
"qadd %0, %1, %2 \n;"
: "=r" (x)
: "0" (x << 16), "r" (y << 16)
) ;
return (x >> 16);
}
int main (void)
{
int x=10, y=20, z=30;
int sum1, sum2, sum3;
sum1 = add (x, y);
sum2 = add (y, z);
sum3 = add (sum1, sum2);
printf("sum1 = %d sum2 = %d sum3 = %d\n", sum1, sum2, sum3);
}
The resulting code with '-O2' is :
(my arm-linux-gcc compiler has an 'xscale' target (armv5) as default)
> arm-linux-gcc -O2 -finline-functions -Winline -I. test.c -c -o test.o
> arm-linux-objdump -d test.o
test.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <main>:
0: e3a00705 mov r0, #1310720 ; 0x140000
4: e1a02000 mov r2, r0
8: e3a0381e mov r3, #1966080 ; 0x1e0000
c: e3a0180a mov r1, #655360 ; 0xa0000
10: e1032052 qadd r2, r2, r3
14: e1001051 qadd r1, r1, r0
18: e1a01841 mov r1, r1, asr #16
1c: e1a02842 mov r2, r2, asr #16
20: e1a00802 mov r0, r2, lsl #16
24: e1a03801 mov r3, r1, lsl #16
28: e1003053 qadd r3, r3, r0
2c: e59f0004 ldr r0, [pc, #4] ; 38 <main+0x38>
30: e1a03843 mov r3, r3, asr #16
34: eafffffe b 0 <main>
38: 00000000 andeq r0, r0, r0
Greetings,
--
Jeroen Dobbelaere
Embedded Software Engineer
Acunia International
http://www.acunia.com