tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Functions locality and instruction fetch


I remember some years ago I was playing with Sun Studio compilers on
Solaris. I don't remember the exact commands/options, but there was a
way to run your code under a special profiler, which would output
locality information about various functions into a file. Then you could
use this file as input to a compiler, which would generate executable
code, where frequently called functions were placed closer to each
other. In theory this would improve performance due to locality of

I don't think GCC has anything of that kind, so I thought maybe the
order in which you write functions in source files has similar effects.

For example, say I have a library with 10 functions, f1 - f10. I can
predict that when the library is used, functions will be called in this
order f1 to f10.

The question that was bugging me is this: if in the source file I write
functions in linear order:


will GCC generate their binary code in the same linear order,
clustering them together in memory addresses?

I ran 'nm' on binary files and it seems the above holds true, at least
for GCC, but I would be wrong...

Home | Main Index | Thread Index | Old Index