Skip to contentSkip to conversation

Log2 all through the kernel?

KJ Oliver Korpilla 1 participant 1 message Aug 10, 2005 Kernel janitors

lore
Share & tools
lore
#0 lore raw

Hello!

Upon looking for a function/macro for computing the logarithm to the base 2 I found multiple implementations in the kernel source (2.6.10-rc3), but none fitting my requirements:

* generic (will compute logarithm instead of a table lookup)
* portable (unlike e.g. ceil_log2 only in asm-alpha)

It kind of looks like everyone is reinventing the wheel with several implementations under differing names are within the kernel. Sometimes they are hardcoded (results already put in as constant), sometimes a lookup table is used, and several slightly different algorithms with bit shift are used.

Is this desirable? While it may be some reduction for special cases using a table (like in the log2_2048 function I found - it computes only a certain of log2 and multiplies this with 2048), wouldn't a more generic implementation like ceil_log2 and floor_log2 not be desirable for all platforms?

Or have I simply overlooked the right function?

Thanks and with kind regards,
Oliver Korpilla

_______________________________________________
Kernel-janitors mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/kernel-janitors