CPU dependent code: how to avoid function pointers?

后端 未结 4 1448
逝去的感伤
逝去的感伤 2021-02-10 15:04

I have performance critical code written for multiple CPUs. I detect CPU at run-time and based on that I use appropriate function for the detected CPU. So, now I have to use fun

4条回答
  •  借酒劲吻你
    2021-02-10 15:52

    For the best performance you need to minimize the number of indirect calls (through pointers) per second and allow the compiler to optimize your code better (DLLs hamper this because there must be a clear boundary between a DLL and the main executable and there's no optimization across this boundary).

    I'd suggest doing these:

    1. moving as much of the main executable's code that frequently calls DLL functions into the DLL. That'll minimize the number of indirect calls per second and allow for better optimization at compile time too.
    2. moving almost all your code into separate CPU-specific DLLs and leaving to main() only the job of loading the proper DLL OR making CPU-specific executables w/o DLLs.

提交回复
热议问题