Hi,
On 2024-07-30 21:59:44 -0500, Nathan Bossart wrote:
> On Tue, Jul 30, 2024 at 07:39:18PM -0700, Andres Freund wrote:
> > We can hide most of the dispatch cost in a static inline function that only
> > does the runtime test if size is large enough - the size is a compile time
> > constant most of the time, which optimizes away the dispatch cost most of the
> > time. And even if not, an inlined runtime branch is a *lot* cheaper than an
> > indirect function call.
>
> I ended up doing precisely this for pg_popcount()/pg_popcount_masked(),
> although not quite as sophisticated as what you propose below. I'll look
> into expanding on this strategy in v18.
I think you subsume that under "not quite as sophisticated", but just to make
clear: The most important bits are to
a) do the dispatch in a header, without an indirect function call
b) implement intrinsic using stuff in a header if it's using a size argument
or such, because that allows to compiler to optimize away size checks in
the very common case of such an argument being a compile time constant.
Greetings,
Andres Freund