coreboot-kgpe-d16/payloads/libpayload/include
Julius Werner 7a8a4ab1d8 lib: Unify log2() and related functions
This patch adds a few bit counting functions that are commonly needed
for certain register calculations. We previously had a log2()
implementation already, but it was awkwardly split between some C code
that's only available in ramstage and an optimized x86-specific
implementation in pre-RAM that prevented other archs from pulling it
into earlier stages.

Using __builtin_clz() as the baseline allows GCC to inline optimized
assembly for most archs (including CLZ on ARM/ARM64 and BSR on x86), and
to perform constant-folding if possible. What was previously named log2f
on pre-RAM x86 is now ffs, since that's the standard name for that
operation and I honestly don't have the slightest idea how it could've
ever ended up being called log2f (which in POSIX is 'binary(2) LOGarithm
with Float result, whereas the Find First Set operation has no direct
correlation to logarithms that I know of). Make ffs result 0-based
instead of the POSIX standard's 1-based since that is consistent with
clz, log2 and the former log2f, and generally closer to what you want
for most applications (a value that can directly be used as a shift to
reach the found bit). Call it __ffs() instead of ffs() to avoid problems
when importing code, since that's what Linux uses for the 0-based
operation.

CQ-DEPEND=CL:273023
BRANCH=None
BUG=None
TEST=Built on Big, Falco, Jerry, Oak and Urara. Compared old and new
log2() and __ffs() results on Falco for a bunch of test values.

Change-Id: I599209b342059e17b3130621edb6b6bbeae26876
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 3701a16ae944ecff9c54fa9a50d28015690fcb2f
Original-Change-Id: I60f7cf893792508188fa04d088401a8bca4b4af6
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/273008
Original-Reviewed-by: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-on: http://review.coreboot.org/10394
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-06-05 13:18:55 +02:00
..
arm/arch Remove address from GPLv2 headers 2015-05-21 20:50:25 +02:00
arm64/arch arm64: Decouple MMU functions from memranges 2015-06-02 11:34:23 +02:00
arpa
mips/arch Remove address from GPLv2 headers 2015-05-21 20:50:25 +02:00
pci libpayload: Add a few more PCI constants 2013-08-26 00:24:53 +02:00
storage libpayload: Change CONFIG_* to CONFIG_LP_* in the kconfig. 2014-08-05 18:44:08 +02:00
sys
udc libpayload: Add zero length packet support to UDC framework 2015-04-18 08:40:28 +02:00
usb libpayload: Add dwc2 usb driver 2015-04-14 10:42:54 +02:00
x86/arch libpayload: x86: correct types used for IO 2015-05-13 15:39:54 +02:00
assert.h
cbfs.h Remove address from GPLv2 headers 2015-05-21 20:50:25 +02:00
cbfs_core.h Remove address from GPLv2 headers 2015-05-21 20:50:25 +02:00
cbfs_ram.h Remove address from GPLv2 headers 2015-05-21 20:50:25 +02:00
coreboot_tables.h libpayload: cros: add serial number from coreboot table 2015-04-22 08:46:37 +02:00
ctype.h
die.h libpayload: Add a new "die" function to fatally signal programming errors. 2014-09-15 17:37:13 +02:00
endian.h libpayload: Expand setbits_le32() and fix readl() const-ness 2015-01-12 05:56:01 +01:00
errno.h
exception.h libpayload: Rework exception hook interface 2015-01-09 07:05:15 +01:00
gdb.h Remove address from GPLv2 headers 2015-05-21 20:50:25 +02:00
getopt.h
inttypes.h
ipchksum.h libpayload: Add a new "die" function to fatally signal programming errors. 2014-09-15 17:37:13 +02:00
kconfig.h libpayload: Change CONFIG_* to CONFIG_LP_* in the kconfig. 2014-08-05 18:44:08 +02:00
keycodes.h
lar.h Remove address from GPLv2 headers 2015-05-21 20:50:25 +02:00
libpayload.h lib: Unify log2() and related functions 2015-06-05 13:18:55 +02:00
limits.h
lzma.h LZMA: Add a version of ulzma which takes the input and output buffer sizes. 2014-08-10 22:29:51 +02:00
malloc.h
multiboot_tables.h
panel.h
pci.h
queue.h libpayload: Add OpenBSD queue implementation 2015-03-19 23:23:36 +01:00
stdarg.h libpayload: Don't sneak in compiler includes 2013-04-18 02:50:28 +02:00
stddef.h ARM: API to Map Physical Address to Wipe Memory above 4GB 2014-12-09 18:39:34 +01:00
stdint.h libpayload: Add more integer limits 2013-06-27 14:48:08 +02:00
stdio.h
stdlib.h libpayload arm64: update mmu translation table granule size, logic and macros 2015-04-27 20:50:00 +02:00
string.h libpayload: UTF-16LE to ASCII conversion 2015-03-20 09:59:48 +01:00
swab.h libpayload: arch/mips: Add basic MIPS architecture support 2015-03-21 11:07:50 +01:00
sysinfo.h libpayload: cros: add serial number from coreboot table 2015-04-22 08:46:37 +02:00
term.h
unistd.h libpayload: Don't sneak in compiler includes 2013-04-18 02:50:28 +02:00
video_console.h