mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 17:33:08 +08:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user