On Mon, 18 Feb 2008 17:22:52 +0100, Tim Frink wrote:
> I've a question about the influence of compiler optimizations that
> reorder functions on the system performance.
>
> Assume a modern processor with all state-of-the art features like
> prefetching, branch prediction and a superscalar pipeline. Further
> assume that all caches are disabled. Will the program runtime change
> when just the order of functions is changed (without any other code
> transformation)?
Aren't "with branch prediction" and "caches are disabled" somewhat
mutually exclusive statements?
As I understand it, the processor does branch prediction based on
past experience (which is cached using some hash generated
from the instruction address), or lacking experience, heuristics.
If such cache exists, then function reordering might help in cases
where multiple functions have jumps in identically ha****ng addresses
with identical probabilities. I find that to be unlikely.
> I'm of the opinion that a reordering of function should have little
> influence on the program execution, maybe due to some prefetch effects
> but thes should be marginal. Of course, with caches this situation
> would look different.
Function reordering might help also in situations where the processor
sup****ts jumps that are differently encoded depending on the jump length
(such as the bra/brl opcodes on 65c816, or similar on x86). If a tailcall
occurs to a function that is located within a short distance, it might
be faster with than a tailcall with a larger distance, because the opcodes
differ.
In any case, I think the effects of cache (and/or demand loading) are
greatly more significant than those which I listed, regarding the function
ordering.
--
Joel Yliluoma - http://iki.fi/bisqwit/


|