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: Force inline without -O2


Hi Ian,

Thanks for the quick response. It worked. You saved me.

thanks and regards,
Isuru

--- On Tue, 12/22/09, Ian Lance Taylor <iant@google.com> wrote:

> From: Ian Lance Taylor <iant@google.com>
> Subject: Re: Force inline without -O2
> To: "isuru herath" <isuru81@yahoo.com>
> Cc: gcc-help@gcc.gnu.org
> Date: Tuesday, December 22, 2009, 9:55 AM
> isuru herath <isuru81@yahoo.com>
> writes:
> 
> > I am writing a C code with inline method.
> >
> > static inline unsigned int READ()
> > {
> >     unsigned long data;
> >     asm volatile ("movl %%eax, %0" : "=g" (data) :  );
> >     return (unsigned int) data;
> > }
> >
> > I dont want to this appear as a method call in the executable. I want 
> > to make in inlined to the code. I tried different methods.
> >
> > 1. I compiled with -finline-functions. Still it apears as a method call  
> > in the assembly generated.
> >
> > 2. Used the attribute __attribute__((always_inline));. Still it appears 
> > as a method call. 
> >
> > But when I compiled with -O2 it doesnot make it a method call. But for 
> > my current work I cannot have optimizations enabled. Therefore I am 
> > looking  for a way to inline this function in the assembly generated. I 
> > am not sure I can achieve this behavior with macros since I need to 
> > return data from  it.
> 
> The compiler generally does not inline functions if you are not
> optimizing.
> 
> If you must have this be inline even when not optimizing, I think you
> will need to use a macro.
> 
> #define READ() \
>   ({ \
>       unsigned long data; \
>       asm volatile ("movl %%eax, %0", : "=g" (data)); \
>       data; \
>    })
> 
> Ian
> 


      


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