imneme / pcg-c-basic

PCG — Minimal C Implementation
Apache License 2.0
401 stars 51 forks source link

Can't inline #14

Open travisdowns opened 5 years ago

travisdowns commented 5 years ago

Since PCG is oriented towards speed, I thought I'd mention that as far as performance goes, not being able to inline the core functions like pcg32_random_r has a significant impact on speed. I'm getting around this by simply doing #include "pcg-basic.c" - yes, including the implementation file!

A usual solution is to declare the key functions static inline in the header file, then you don't have to mess around with "out of line" versions.

The more fully featured C library is able to be inlined.

lemire commented 5 years ago

Can't LTO solve this? -flto? Gold linker, etc.

travisdowns commented 5 years ago

I don't think gold linker has anything to do with it (?), but yes LTO solves it.

LTO is still a bit like PGO - some people know about it, few people use it. If you are writing a high performance library you don't want to rely on people using it.

In a way LTO is harder to turn on than PGO even, because the old TU-at-a-time model hides certain types of bugs that are revealed when you enable LTO, because the compiler can now see that what you've been doing is UB after all, etc. On Mon, Mar 4, 2019, 10:10 AM Daniel Lemire notifications@github.com wrote:

Can't LTO solve this? -flto? Gold linker, etc.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/imneme/pcg-c-basic/issues/14#issuecomment-469247404, or mute the thread https://github.com/notifications/unsubscribe-auth/ACSswffZpNsyL45gj_hu3X3G5UMQkrH9ks5vTRs7gaJpZM4bbfKc .