How inlined are inlined functions?

Anjul Srivastava anjul.srivastava@sanchez.com
Fri Dec 3 10:14:00 GMT 1999


I agree wholeheartedly.

At my company due to the fact that we harbour several myths about C++, we
use C.

With great pains, I exemplified how C++ could really help us without
compromising on efficiency.

One of my key points was that we could eliminate ugly macros, and use inline
functions. This basically helped me persuade them that C++ could in fact
help us on a practical basis (even if we couldn't go to OO rightaway).

Imagine my embarrassment when I find that inline functions execute SEVERAL
times slower than macros.

I think we should rectify this with high priority. I am certain our
implementation is not what Stroustroup had in mind when he talked about
inlined functions.

Thanks!
Anjul.



-----Original Message-----
From: Jim Blandy [ mailto:jimb@cygnus.com ]
Sent: Friday, December 03, 1999 11:50 AM
To: egcs@sourceware.cygnus.com
Subject: How inlined are inlined functions?



I've noticed that I get worse code when I used inlined functions than
I do when I use a macro.  I understand that argument passing to
inlined functions is not right, and Mark Mitchell is working on this,
but the problem I'm seeing seems to be related to the returned value.

The code generated is correct, so this isn't a bug report, but I'm
curious as to why some of the optimizations GCC usually brings to bear
don't seem to be working here.  If inlined functions are generally not
handled as well as macros, I may be unable to use them.


Here's my code:

#ifdef INLINE

extern inline int
ptr_bit_clear (int *x)
{
  return ! (*x & 1);
}
#endif

#ifdef MACRO

#define ptr_bit_clear(x) (! (*(x) & 1))

#endif

extern int
foo (int *x)
{
  if (ptr_bit_clear (x))
    return bar ();
}


I'm using EGCS 2.91.66, on Red Hat GNU/Linux 6.1, on a Pentium.  The
command is `gcc -c -O2 -save-temps'.  Here is a diff of the two
assembly files:

*** inline2.macro.s     Fri Dec  3 11:30:30 1999
--- inline2.inline.s    Fri Dec  3 11:30:30 1999
***************
*** 9,18 ****
        pushl %ebp
        movl %esp,%ebp
        movl 8(%ebp),%eax
!       testb $1,(%eax)
!       jne .L2
        call bar
! .L2:
        leave
        ret
  .Lfe1:
--- 9,20 ----
        pushl %ebp
        movl %esp,%ebp
        movl 8(%ebp),%eax
!       movl (%eax),%eax
!       xorb $1,%al
!       testb $1,%al
!       je .L3
        call bar
! .L3:
        leave
        ret
  .Lfe1:



More information about the Gcc mailing list