This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit fae6b3291da51093df97d6f405413bf29c8fd3d9
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Fri Nov 13 19:31:33 2026 +0800

    lib/math32: fix stale invdiv and log2 comments
    
    * invdiv_init_param32(): the description named a triple "(multiplier,
      right shift number 1, right shift number 2)" from an older two-shift
      design; the parameters are a multiplier and one shift.
    * The Granlund-Montgomery usage note named APIs that do not exist
      (invdiv_init_param(d, param), invdiv(n, param)); it now points at
      invdiv_init_param32()/invdiv_init_param64() and
      invdiv_u32()/invdiv_u64().
    * Two kernel descriptions said the divisor is "converted to
      invdiv_param_t", a type that does not exist; the real struct names
      are invdiv_param32_t and invdiv_param64_t.
    * log2ceil()/log2floor() claimed to return "the power-of-two for the
      argument"; they return the base-2 logarithm.
    
    Assisted-By: mimo-v2.6-pro
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 include/nuttx/lib/math32.h | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/include/nuttx/lib/math32.h b/include/nuttx/lib/math32.h
index b35bdcfbfd8..7cd6e4d1ecb 100644
--- a/include/nuttx/lib/math32.h
+++ b/include/nuttx/lib/math32.h
@@ -140,13 +140,13 @@ extern "C"
  * Name: log2ceil
  *
  * Description:
- *   Calculate the up-rounded power-of-two for input.
+ *   Calculate the base-2 logarithm of n, rounded up.
  *
  * Input Parameters:
- *   x - Argument to calculate the power-of-two from.
+ *   n - The value to take the logarithm of (n >= 1).
  *
  * Returned Value:
- *   Power-of-two for argument, rounded up.
+ *   ceil(log2(n)).
  *
  ****************************************************************************/
 
@@ -161,13 +161,13 @@ extern "C"
  * Name: log2floor
  *
  * Description:
- *   Calculate the down-rounded (truncated) power-of-two for input.
+ *   Calculate the base-2 logarithm of n, rounded down.
  *
  * Input Parameters:
- *   x - Argument to calculate the power-of-two from.
+ *   n - The value to take the logarithm of (n >= 1).
  *
  * Returned Value:
- *   Power-of-two for argument, rounded (truncated) down.
+ *   floor(log2(n)).
  *
  ****************************************************************************/
 
@@ -397,16 +397,17 @@ static inline_function uint64_t div64_const(uint64_t n, 
uint64_t base)
  *
  * Usage:
  * If you want to do n/d division where d is an invariant integer,
- * initialize the param by `invdiv_init_param(d, param)` first,
- * then do the division by `invdiv(n, param)`.
+ * initialize the parameters with invdiv_init_param32() /
+ * invdiv_init_param64() first, then do the division with
+ * invdiv_u32() / invdiv_u64().
  */
 
 /****************************************************************************
  * Name: invdiv_init_param32
  *
  * Description:
- *   Calculate the triple (multiplier, right shift number 1, right shift
- * number 2) during initialization.
+ *   Calculate the invariant-division parameters (multiplier, shift) for
+ * divisor d during initialization.
  *
  * Input Parameters:
  *   d - The divisor (unsigned integer). d != 0 and d != 1 is required.
@@ -439,7 +440,7 @@ void invdiv_init_param32(uint32_t d, FAR invdiv_param32_t 
*ip)
  * Description:
  *   Return the result of `n / d`
  *   The division is realized by multiplication and right shift,
- *   where d is already converted to invdiv_param_t.
+ *   where d is already converted to invdiv_param32_t.
  *
  * Input Parameters:
  *   n - The dividend (uint32_t).
@@ -596,7 +597,7 @@ void invdiv_init_param64(uint64_t d, FAR invdiv_param64_t 
*ip)
  * Description:
  *   Return the result of `n / d`
  *   The division is realized by multiplication and right shift,
- *   where d is already converted to invdiv_param_t.
+ *   where d is already converted to invdiv_param64_t.
  *
  * Input Parameters:
  *   n - The dividend (uint64_t).

Reply via email to