mu578 commented on code in PR #10724:
URL: https://github.com/apache/nuttx/pull/10724#discussion_r1331980388
##########
arch/risc-v/src/common/riscv_pmp.c:
##########
@@ -100,32 +101,6 @@ typedef struct pmp_entry_s pmp_entry_t;
* Private Functions
****************************************************************************/
-/****************************************************************************
- * Name: log2ceil
- *
- * Description:
- * Calculate the up-rounded power-of-two for input.
- *
- * Input Parameters:
- * size - The size of the PMP region.
- *
- * Returned Value:
- * Power-of-two for argument, rounded up.
- *
- ****************************************************************************/
-
-static uintptr_t log2ceil(uintptr_t size)
-{
- uintptr_t pot = 0;
-
- for (size = size - 1; size > 1; size >>= 1)
- {
- pot++;
- }
-
- return pot;
-}
-
Review Comment:
In `mu0` you have a bit_floor and bit_ceil implementation matching c++
definition. `__mu0_bit_floor_u8__` is performed on `unsigned long long`.
Meanwhile size of `uintptr_t` must be pounded defined i.e arch32 vs arch64.
https://github.com/mu578/mu0
https://en.cppreference.com/w/cpp/numeric/bit_floor
https://en.cppreference.com/w/cpp/numeric/bit_ceil
https://en.cppreference.com/w/cpp/numeric/bit_width
https://en.cppreference.com/w/cpp/numeric/countl_zero
example:
```c
__mu0_static_inline__
const ___mu0_uint8_t___ __mu0_bit_floor_u8__(const ___mu0_uint8_t___ __x)
{
# if MU0_HAVE_C99 || MU0_HAVE_CPP11
const ___mu0_uint8_t___ one = 1ULL;
const ___mu0_uint8_t___ zero = 0ULL;
# else
const ___mu0_uint8_t___ one = 1UL;
const ___mu0_uint8_t___ zero = 0UL;
# endif
return __x != zero ? (one << (__mu0_bit_width_u8__(__x) - one)) : zero;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]