Inlining large function & mem. alignment

Programming, for all ages and all languages.
Post Reply
Dario
Member
Member
Posts: 117
Joined: Sun Aug 31, 2008 12:39 pm

Inlining large function & mem. alignment

Post 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!
____
Dario
User avatar
linuxfood
Member
Member
Posts: 38
Joined: Wed Dec 31, 2008 12:22 am

Re: Inlining large function & mem. alignment

Post 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
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: Inlining large function & mem. alignment

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Inlining large function & mem. alignment

Post 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.
Every good solution is obvious once you've found it.
Dario
Member
Member
Posts: 117
Joined: Sun Aug 31, 2008 12:39 pm

Re: Inlining large function & mem. alignment

Post by Dario »

Thank you guys!
____
Dario
Post Reply