This is the mail archive of the gcc@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: Performance testing function pointers


On Fri, 2004-06-25 at 19:17, Jim Wilson wrote:
> Using volatile for a function return type doesn't really do anything 
> useful.  It used to in old gcc releases, but that feature was removed 
> ... noinline which you can use to prevent a function from being inlined. 

Oops, thanks.  Now the function is declared as:

    void __attribute__((noinline)) inc_j(volatile int *p)


> You declared the argument as "volatile int* volatile p".  If all you 
> want is to prevent the increment from being deleted, then you only need 
> the first volatile.

OK, fixed.  It didn't appear to change much.


The updated code is in funcptrs-0.2.tar.gz on:

   http://www.rinspin.com/bronson/code/gcc/

I made the above changes and re-ran the tests (I also updated the code
to benchmark calling into static vs. shared libraries, but I'll post the
results in a different message).

With -O3, now function pointers are 10% faster than the direct call,
rather than 20% as before.  But why would calling through a function
pointer be FASTER??  Well, as far as I can tell, the only difference
between the two programs is a single line (the one you'd expect):

  direct:     0x080484c6 <main+118>:  call   0x8048440 <inc_j>
              0x080484cb <main+123>:  dec    %ebx

  indirect:   0x080484c6 <main+118>:  call   *%esi
              0x080484c8 <main+120>:  dec    %ebx

So, apparently, because the indirect call is 3 bytes shorter, it's 10%
faster.  Neat.  If you need to pick up a few percent in your program,
and using function pointers won't increase register spillage, consider
calling a subroutine or two via fuction pointer instead of directly.  :)


My only remaining question is, "why are direct function calls 5% faster
with -O1, but slower at all other optimization levels?"  This seems
strange to me, but I'll have to investigate another time...


Thanks, Jim.  The results are making a lot more sense now.

    - Scott



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