On Friday, 1 December 2017 at 11:07:32 UTC, Walter Bright wrote:
On 11/30/2017 8:34 PM, Nicholas Wilson wrote:
What I meant in terms of icache pollution is with the 'cold'
is instead of generating:
if(!cond)
_d_assert(__FILE__, __LINE__,message);
//rest of code
it should actually generate,
if (!cond)
goto failed;
//rest of code
failed:
_d_assert(__FILE__, __LINE__,message);//call is cold &
out of line. no icache pollution
I'm not sure that it does that given the triviality of the
example, but it looks like it doesn't.
You're right, it would be better to generate code that way. But
it currently does not (I should fix that).
Great!
It's not completely correct that icache isn't polluted.
True.
Functions that are tightly coupled can be located adjacent for
better cache performance, and the various asserts would push
them apart.
Does DMD optimise for locality?
I would hope co-located functions are either larger than cache
lines by a reasonable amount or, if they are small enough,
inlined so that the asserts can be aggregated. It is also
possible (though I can't comment on how easy it would be to
implement) if you are trying to optimise for co-location to have
the asserts be completely out of line so that you have
function1
function2
function3
call asserts of function1
call asserts of function2
call asserts of function3
such that the calls to the asserts never appear in the icache at
all apart from overlap of e.g. function1's asserts after the end
of function3, or one of the the asserts fail.
Also, the conditional jumps may need to be the longer variety
due to the longer distance, rather than the 2 byte one.
Then it becomes a tradeoff, one that I'm glad the compiler is
doing for me.