lib: Fix log2_ceil() for 0xffffffff
Current log2_ceil(x) is defined as log2(x * 2 - 1). When x is larger than (1 << 31), (x * 2 - 1) won't fit in u32, leading to incorrect result. Therefore, correct it as (log2(x - 1) + 1). Also add unit tests for inline functions in lib.h. BUG=none TEST=make tests/lib/lib-test BRANCH=none Change-Id: If868f793b909a6ad7fc48a7affac15e2c714fa2e Signed-off-by: Yu-Ping Wu <yupingso@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/59834 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
tests-y += lib-test
|
||||
tests-y += string-test
|
||||
tests-y += b64_decode-test
|
||||
tests-y += hexstrtobin-test
|
||||
@@ -40,6 +41,8 @@ tests-y += cbfs-lookup-no-mcache-test
|
||||
tests-y += cbfs-lookup-has-mcache-test
|
||||
tests-y += lzma-test
|
||||
|
||||
lib-test-srcs += tests/lib/lib-test.c
|
||||
|
||||
string-test-srcs += tests/lib/string-test.c
|
||||
string-test-srcs += src/lib/string.c
|
||||
|
||||
|
Reference in New Issue
Block a user