4 ms·
> either via function pointers or a switch/if? > but would a modern CPU not be able to predict the path taken by a brach that tests the CPU features. That's t
by jcalvinowens 3y ago
> either via function pointers or a switch/if?
> but would a modern CPU not be able to predict the path taken by a brach that tests the CPU features.
That's true, but the CPU has finite branch predictor state, and now you've wasted some of it. Indirect calls hurt too, especially in you need retpolines.
This is a great read: https://www.agner.org/optimize/microarchitecture.pdf https://www.agner.org/optimize/microarchitecture.pdf
The Linux kernel has interfaces for doing the same thing, more explicitly than ifunc:
https://docs.kernel.org/next/staging/static-keys.html https://docs.kernel.org/next/staging/static-keys.html
https://lwn.net/Articles/815908/ https://lwn.net/Articles/815908/