tech-userlevel archive

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

Re: Functions locality and instruction fetch



On Mon, 28 Jan 2013 08:23:09 +0000
David Laight <david%l8s.co.uk@localhost> wrote:

> On Sun, Jan 27, 2013 at 05:14:24PM +0000, Sad Clouds wrote:
> > 
> > The question that was bugging me is this: if in the source file I
> > write functions in linear order:
> > 
> > f1()
> > f2()
> > f3()
> > ...
> > f10()
> > 
> > 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...
> 
> I've seen object code where that isn't true.
> I've sure some versions of gcc re-order stuff - especially for static
> functions.
> 
> Why do you want functions adjacent?
> - to reduce the number of active TLB ?
> - NUMA systems copying physical pages into local memory
> - avoid some long instruction sequences for long jumps (don't they
> have to be generated anyway - unless they are linker generated
> trampolines)?
> 
> Sun might have had NUMA systems.
> 
>       David
> 
> -- 
> David Laight: david%l8s.co.uk@localhost

Hello, based on what you just described, it sounds like I shouldn't
depend on object code being generated in the same order as in the
source files.

I guess the reason I wanted to put frequently executed functions
together was to improve the locality of reference and reduce iTLB
mises. There is really no particular issue that I'm trying to resolve,
I just thought it might help to achieve better performance, however
small it is.


Home | Main Index | Thread Index | Old Index