summaryrefslogtreecommitdiff
path: root/tests/lib/lib-test.c
diff options
context:
space:
mode:
authorJianjun Wang <jianjun.wang@mediatek.com>2021-11-30 10:51:53 +0800
committerHung-Te Lin <hungte@chromium.org>2021-12-13 02:57:07 +0000
commit8bb59ca2faee83ba50850900c8b4edf9331ae931 (patch)
treefab7bde1be5ff24af106a41c8f47b7d4fac75762 /tests/lib/lib-test.c
parent5588f34a35209f34d9061e6a83856289450d8131 (diff)
lib: Add __fls() (Find Last Set)
Implement __fls() as an alias for log2(), and remove the duplicate definitions in commonlib/storage/sdhci.c. Signed-off-by: Jianjun Wang <jianjun.wang@mediatek.com> Change-Id: Ib458abfec7e03b2979569a8440a6e69b0285ac32 Reviewed-on: https://review.coreboot.org/c/coreboot/+/59738 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Diffstat (limited to 'tests/lib/lib-test.c')
-rw-r--r--tests/lib/lib-test.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/lib/lib-test.c b/tests/lib/lib-test.c
index adaa2f9500..826c6c563a 100644
--- a/tests/lib/lib-test.c
+++ b/tests/lib/lib-test.c
@@ -37,6 +37,15 @@ void test_ffs(void **state)
assert_int_equal(__ffs(0xffffffff), 0);
}
+void test_fls(void **state)
+{
+ assert_int_equal(__fls(0x0), -1);
+ assert_int_equal(__fls(0x1), 0);
+ assert_int_equal(__fls(0x5), 2);
+ assert_int_equal(__fls(0x80000000), 31);
+ assert_int_equal(__fls(0xffffffff), 31);
+}
+
void test_log2_ceil(void **state)
{
assert_int_equal(log2_ceil(0x0), -1);
@@ -53,6 +62,7 @@ int main(void)
cmocka_unit_test(test_clz),
cmocka_unit_test(test_log2),
cmocka_unit_test(test_ffs),
+ cmocka_unit_test(test_fls),
cmocka_unit_test(test_log2_ceil),
};