C function code length VS processor cache -
as c procedure oriented language, while working c, end sequential code, running top bottom 1 or few c functions.
sometime, code functions of 1000 lines. because think function calls has overhead. while doesn't duplicate code, can duplicate less 5% code in long functions.
so, effects of long functions on processor cache? long functions prevent improve cpu cache usage? cpu caches works caching whole c function? if processor cache doesn't long functions, more efficient have function calls?
readability should, in general, come first, , can pretty much regard "last resort" kind of optimisation not purchase important performance gain.
today's cpus caching instructions data. in general, should optimise layout of info , memory access patterns, way in instructions arranged matters utilisation of instruction cache.
calling non-inlined function in fact unconditional jump, much jmp instruction. jump makes cpu start fetching instructions (possibly far) location in memory. if new location isn't found in instruction cache, cpu stall until corresponding memory brought there. in theory, if code contains no jumps , branches, cpu prefetch instructions aggressively possible.
also, never know how far "too far". jumping few kilobytes forwards or backwards might cache hit, since usual instruction cache today 32 kilobytes.
it's tricky optimisation right, , advise @ info layout , memory access patterns first.
the other concern overhead of passing arguments on stack or in registers. today's cpus less of problem, since whole stack "hot" in info cache, , register renaming can eliminate register-to-register moves no-op.
c function caching
No comments:
Post a Comment