Log2 all through the kernel?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux