diff --git a/app/test/test_common.c b/app/test/test_common.c index 2b856f8ba5..12bd1cad90 100644 --- a/app/test/test_common.c +++ b/app/test/test_common.c @@ -216,7 +216,19 @@ test_log2(void) const uint32_t max = 0x10000; const uint32_t step = 1; - for (i = 0; i < max; i = i + step) { + compare = rte_log2_u32(0); + if (compare != 0) { + printf("Wrong rte_log2_u32(0) val %x, expected 0\n", compare); + return TEST_FAILED; + } + + compare = rte_log2_u64(0); + if (compare != 0) { + printf("Wrong rte_log2_u64(0) val %x, expected 0\n", compare); + return TEST_FAILED; + } + + for (i = 1; i < max; i = i + step) { uint64_t i64; /* extend range for 64-bit */ diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index 459d082d14..c352838073 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -538,6 +538,9 @@ rte_bsf32_safe(uint64_t v, uint32_t *pos) /** * Return the rounded-up log2 of a integer. * + * @note Contrary to the logarithm mathematical operation, + * rte_log2_u32(0) == 0 and not -inf. + * * @param v * The input parameter. * @return @@ -632,6 +635,9 @@ rte_fls_u64(uint64_t x) /** * Return the rounded-up log2 of a 64-bit integer. * + * @note Contrary to the logarithm mathematical operation, + * rte_log2_u64(0) == 0 and not -inf. + * * @param v * The input parameter. * @return