libs/log2ceil: Move implementation of log2ceil to a common place

Move log2ceil from riscv_pmp to libc. Also, implement log2floor for
completeness.

These are the run-time alternative to the compile-time macros.
This commit is contained in:
Ville Juven
2023-12-13 13:28:05 +02:00
committed by Xiang Xiao
parent 90d73153fb
commit e03599d9ae
6 changed files with 151 additions and 26 deletions
+32
View File
@@ -249,6 +249,38 @@ void umul64(FAR const struct uint64_s *factor1,
FAR const struct uint64_s *factor2,
FAR struct uint64_s *product);
/****************************************************************************
* Name: log2ceil
*
* Description:
* Calculate the up-rounded power-of-two for input.
*
* Input Parameters:
* x - Argument to calculate the power-of-two from.
*
* Returned Value:
* Power-of-two for argument, rounded up.
*
****************************************************************************/
uintptr_t log2ceil(uintptr_t x);
/****************************************************************************
* Name: log2floor
*
* Description:
* Calculate the down-rounded (truncated) power-of-two for input.
*
* Input Parameters:
* x - Argument to calculate the power-of-two from.
*
* Returned Value:
* Power-of-two for argument, rounded (truncated) down.
*
****************************************************************************/
uintptr_t log2floor(uintptr_t x);
#undef EXTERN
#ifdef __cplusplus
}