Feature Request: nontrivial functions and vtable optimizations
Jb
jb at nowhere.com
Wed Aug 13 03:03:38 PDT 2008
"Craig Black" <cblack at ara.com> wrote in message
news:g7s7o1$dpt$1 at digitalmars.com...
>
>
> You are right. Function pointer invokation tends to slow down processing
> because it doesn't cooperate well with pipelining and branch prediction.
> I don't understand why this is so hard for some programmers to accept.
Thats not true these days. I know cause I've profiled it on multiple cpus,
correctly predicted Indirect jumps (through a pointer) cost no more than a
normal call/ret pair. They get a slot in the BTB just like conditional
jumps, and IIRC they are predicted to go to the same place they did last
time.
(on x86 anyway).
Virtual methods are in such high use that Intel and Amd have put a lot of
effort into optimizing them.
Replacing the function pointer with a conditional branch wont make it
faster.
> See Microsoft Visual C++ profile guided optimizations (PGO) "Virtual Call
> Speculation". Using PGO, the most commonly called virtual functions are
> optimized so that they do not require a function pointer invokation.
The speedup you get from this is the inlining of the function, *not* the
getting rid of the function pointer lookup. It still requires a lookup in
the class info and a conditional branch to check that the "inlined function"
is the correct match for the speculated object.
That will still cost a whole pipline of cycles if wrongly predicted.
More information about the Digitalmars-d
mailing list