Why is not inlining that bad?
Jb
jb at nowhere.com
Mon Oct 8 03:33:26 PDT 2007
"Janice Caron" <caron800 at googlemail.com> wrote in message
news:mailman.390.1191827338.16939.digitalmars-d at puremagic.com...
> Forgive me if this is a dumb question, but in other threads I've seen
> it argued that dereferencing an address from a register offset is not
> something that anyone needs to be worried about, and that array
> accesses are so fast that no one need worry about them, etc.
Because adressing modes cost pretty much the same on modern x86 cpus.
MOV EAX,[EBX+32+ECX*8]
costs the same as
MOV EAX,[$FFEECCDD]
Because its an incredibly common thing to want to do it is optimized to the
best possible case.
> This being the case, why is anyone worried about the overhead of a
> function call? It's just a memory write and a few registers changing,
> surely? It's not a massively expensive operation like a thread switch
> or anything, so why worry?
A call/ret pair, costs 2-4 cycles on average. Pushing poping parameters to
the stack uses up 1 cycle per instruction aswell, best case scenario, and
there is usualy some shuffling of data into different registers.
And if the callee does anything more complicated than a handful of
operations it's likely that it will need to dump stuff off to the stack to
free up more registers.
Plus avoiding all that allows more oportunity for optimization. If inlined
then things dont have to be shuffled round to suit the calling convention,
whether stack based or register based.
So small functions with lots of parameters are the most likely
beneficiaries.
More information about the Digitalmars-d
mailing list