Re:The cost of dynamic vs. static dispatch in C++
by mappu on Thursday December 05, 2013 @03:29PM
(#6856977)
I use push/ret idiom all the time to stdcall off the stack.. did not realise there was a return cache, that's very interesting.
Re:The cost of dynamic vs. static dispatch in C++
by Taniwha on Thursday December 05, 2013 @03:50PM
(#6857121)
depends on the CPU - but it's relatively trivial thing to build (especially because unlike other caches it's a stack) on x86s return nominally is ALWAYS a bad pipe bubble: a pop followed by an indirect jump - the pop gets resolved at the end of its micro-op and the jump wants to be resolved early on so as to start decoding the next instruction
In the end it can't hurt to generate a bad jump prediction off of the return cache, it's no worse than being idle - the effect of messing with the cache though can cause it to always fail so as a result you get no advantage from it
However some of the code we saw (I think it came from a Borland compiler)
an extra memory write/read but always caught in L1 and on the register poor x86 it saves a register right> ... but on most CPUs of the time you're screwed for the branch prediction - CPUs had a return cache, a cheap way to predict the branch target of a return - by doing a return without a call you've popped the return cache leaving it in a bad state - EVERY return in an enclosing method is going to mispredict as well - the code will run, but slowly