Page 1 of 1
Inlining large function & mem. alignment
Posted: Wed Dec 29, 2010 1:45 pm
by Dario
Hi,
I have two questions:
1. If large function gets called only once (initialization code) should I force inlining(always_inline)?
2. When to force cache line alignments? For now, I have only GDT and IDT aligned on cache line bounderis.
Thank you!
Re: Inlining large function & mem. alignment
Posted: Wed Dec 29, 2010 3:46 pm
by linuxfood
Hi,
1. Why is it a function if it's only called once? What are you architectural reasons and other considerations for making it a function? Why do you believe it should be inlined? Why is it a problem for you if isnt?
Those are questions that I might ask myself and see if I have answers to them.
Generally, I tend to first trust the compiler and then only after I've verified I need specific behavior do I attempt to coerce certain behavior out of it.
2. After you've measured, identified a bottleneck, determined that cache alignment may help, and then verified that hypothesis.
Some APIs also require certain byte alignments. SSE comes to mind here.
-B
Re: Inlining large function & mem. alignment
Posted: Sun Jan 02, 2011 7:47 am
by Tosi
1. There is absolutely no reason to inline a function if it only gets called once, or even if it only gets called a few times. Especially initialization functions, which aren't usually called hundreds of times per second. Inlining is for small functions that get called a lot in loops. As an example, I'm writing an NES emulator. The function to read a .NES image is not inlined, since it only needs to be called once. However, most of the functions used in the CPU are inlined, because they get called almost every opcode.
2. What linuxfood said.
Re: Inlining large function & mem. alignment
Posted: Sun Jan 02, 2011 11:24 am
by Solar
Seconding Tosi here. There are good reasons to bundle semantically related code in a function. But if it isn't called often, don't bother about inlining it - inlining is a tiny optimization for inner-loop calls of tiny functions.
Re: Inlining large function & mem. alignment
Posted: Sun Jan 02, 2011 3:08 pm
by Dario
Thank you guys!