HomeFreeBSD

log2: move log2 functions from linuxkpi to libkern

Description

log2: move log2 functions from linuxkpi to libkern

Linux has a header file that defines an ilog2 function and some simple
functions/macros that use it: roundup_pow_of_two, is_power_of_2,
rounddown_pow_of_two, and order_base_2. This change moves three of
those simple functions (all but is_power_of_2) from linuxkpi to
libkern. It also deletes a few implementations of these functions
that have previously been copied into code for various device drivers,
so that they can use the libkern version. The is_power_of_2 macro was
not moved because powerof2 in param.h provides almost the same service
already (except that they disagree about whether 0 is a power of two).

Since the linux definitions of these functions were copied into
FreeBSD 11 years ago, linux has improved them, and this change
provides those improvements. In particular, a giant table of log
values for evaluating ilog2 for constant values is no longer
necessary.

Reviewed by: alc, markj (previous version)
Differential Revision: https://reviews.freebsd.org/D45536

Details

Provenance
dougmAuthored on Jun 24 2024, 7:00 AM
Reviewer
alc
Differential Revision
D45536: log2: move log2 related functions from kpi to libkern
Parents
rGa94ed493b507: dev/mana: replace power2 function
Branches
Unknown
Tags
Unknown