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!
Inlining large function & mem. alignment
Inlining large function & mem. alignment
____
Dario
Dario
Re: Inlining large function & mem. alignment
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
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
-
- Member
- Posts: 255
- Joined: Tue Jun 15, 2010 9:27 am
- Location: Flyover State, United States
- Contact:
Re: Inlining large function & mem. alignment
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.
2. What linuxfood said.
Re: Inlining large function & mem. alignment
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.
Every good solution is obvious once you've found it.