I hope you discover a solution. Since you raised the issue I've tried a
number of flag combinations without apparent success:
<http://gcc.gnu.org/onlinedocs/gcc/Inline.html>
Non-inlining can result in significant performance penalties. In my case
I've discovered that my read_tsc() function is not being inlined across
source files. It's the ultimate example of a function that should be
inlined:
/* Read the TimeStamp Counter */
inline uint64_t read_tsc(void) {
uint64_t r;
__asm__("rdtsc" : "=A" (r));
return r;
...
8048d59: e8 12 05 00 00 call 8049270 <read_tsc>
...
80490e1: e8 8a 01 00 00 call 8049270 <read_tsc>
...
08049270 <read_tsc>:
8049270: 55 push %ebp
8049271: 0f 31 rdtsc
8049273: 89 e5 mov %esp,%ebp
8049275: c9 leave
8049276: c3 ret
As per Lawrence Kirby's suggestion I'll ask gnu.gcc.help about this on
your behalf. The followup has been set to gnu.gcc.help since this is
largely an implementation-specific question.
> I know i could make big macros of my functions, or gather all in the
> same file, but I would like to keep my source clean.
Likewise. I've been building lots of helper functions content in the
knowledge that the function calling overhead can be compiled away.
When I put the read_tsc() function definition in the same source file as
the function calls to read_tsc() the execution time of my test program
drops from 5.872s to 5.654s.
Regards,
Adam
The sorry state of affairs are well explained here:
<http://www.greenend.org.uk/rjk/2003/03/inline.html>
The only simply portable solution described above is to use static inline
and move all inlined functions into the headers. From my perspective this
has the unacceptable side affect of making the address of the "same"
function different from within different source files.
I suggest another portable solution without this side effect is to create
another source file which #includes all the headers and source files of
the program:
#include "file1.h"
#include "file2.h"
#include "file3.h"
...
#include "file1.c"
#include "file2.c"
#include "file3.c"
....
Headers are only included within this file to avoid duplicated definitions.
Hopefully the compiler can cope with all code being included within a
single source file.
Regards,
Adam