Re: Remove fls(), use pg_bitutils.h facilities instead?

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, David Rowley <dgrowleyml@gmail.com>
Date: 2022-07-20T04:52:54Z
Lists: pgsql-hackers
Thomas Munro <thomas.munro@gmail.com> writes:
> Back in commit 4f658dc8 we gained src/port/fls.c.  As anticipated by
> its commit message, we later finished up with something better in
> src/include/port/pg_bitutils.h.  fls() ("find last set") is an
> off-by-one cousin of pg_leftmost_one_pos32().  I don't know why ffs()
> ("find first set", the rightmost variant) made it into POSIX while
> fls() did not, other than perhaps its more amusing name.  fls() is
> present on *BSD, Macs and maybe more, but not everywhere, hence the
> configure test.  Let's just do it with pg_bitutils.h instead, and drop
> some cruft?  Open to better ideas on whether we need a new function,

I think we could probably just drop fls() entirely.  It doesn't look
to me like any of the existing callers expect a zero argument, so they
could be converted to use pg_leftmost_one_pos32() pretty trivially.
I don't see that fls() is buying us anything that is worth requiring
readers to know yet another nonstandard function.

			regards, tom lane



Commits

  1. Remove fls(), use pg_leftmost_one_pos32() instead.

  2. Extend size_t support in pg_bitutils.h.

  3. Support fls().