On 2024-12-17 14:56, Bruno Haible via Gnulib discussion list wrote:
Hi Collin,
Is there any reason not to use stdbit.h for ffs, ffsl, ffsll,
count-leading-zeros, count-one-bits, count-trailing-zeros?
Before doing so, how about making sure that stdbit.in.h works
at least as well as the old code w.r.t. inlining (assuming -O1 or higher)?
(Recall that these functions do very little work, therefore an extra
function call cost is significant.) Maybe it already does, but I haven't
verified it; could you verify it with reasonably modern gcc and clang?
Also, I see that MSVC is not well covered by this default in stdbit.in.h:
#else
/* This platform is so old that it lacks typeof, so _Generic is likely
missing or unreliable. The C23 standard seems to allow yielding B
(which is always unsigned long long int), so do that. */
# define _GL_STDBIT_TYPEOF_CAST(a, b) (b)
#endif
Can it be improved?
Although both of these questions are reasonable if we have a lot of
time, I suspect they're not worth the effort of answering. With modern
GCC or Clang I don't think you'll see much performance difference, and
for ancient GCC/Clang as long as it works correctly we should be OK.
Even MSVC should be fine if it's new enough; i.e., I don't think there
will be significant performance differences in real applications.
That being said, I don't have access to MSVC and didn't check its
performance. Also, I looked at GCC performance with -O2 not -O1, as -O2
is the usual build default.