Fix-Point opened a new pull request, #22351:
URL: https://github.com/apache/nuttx/pull/22351

   ## Summary
   
   This series repairs the code-size behavior of `invdiv_init_param()` and 
keeps `LOG2_CEIL()` a constant expression on every compiler.
   
   The `invdiv_init_param()` macro expands `LOG2_CEIL(d)` at each call site. 
With a runtime divisor that expansion turns into several bit operations 
(`log2ceil()` through `flsx()`/`flsl()`), which increases code size 
significantly wherever invariant division is set up for runtime values. This 
series hoists the computation to the caller:
   
   - `LOG2_CEIL()` is now unconditionally the `FLS()`-based form. The previous 
`CONFIG_HAVE_BUILTIN_CLZ` branch routed through `log2ceil()`, which is not an 
integer constant expression on TASKING (TASKING maps `__builtin_clz()` to the 
`__clz()` intrinsic). That broke `static_assert()`s and array bounds such as 
`MM_MIN_SHIFT` in `mm/mm_heap/mm.h`. The pure bit-wise form makes `LOG2_CEIL()` 
a constant expression everywhere.
   - `invdiv_init_param32()` and `invdiv_init_param64()` now take the 
precomputed `l = log2ceil(d)` as an argument instead of computing it inside. 
`invdiv_init_param()` passes the lightweight runtime form `log2ceil(d)`, and a 
new `invdiv_init_param_const()` passes the constant-expression form 
`LOG2_CEIL(d)` for compile-time divisors. `div64_const32()` uses the const form.
   
   ## Impact
   
   Only `include/nuttx/lib/math32.h` is touched; there is no caller-facing API 
change. The two existing `invdiv_init_param()` call sites 
(`arch/tricore/src/common/tricore_perf.c` and `include/nuttx/timers/oneshot.h`) 
are unaffected. Runtime invdiv setups get smaller code, and the 
constant-expression property is preserved where it must be.
   
   ## Testing
   
   Builds, both with zero warnings:
   
   ```
   rv-virt:nsh   (rv32): BUILD_OK warnings=0 image=4122536
   rv-virt:smp64 (rv64): BUILD_OK warnings=0 image=3663024
   ```
   
   ostest under QEMU, full runs, both exit with status 0:
   
   - rv32 (`qemu-system-riscv32 -M virt -cpu rv32`), tail of the log:
   
   ```
   arena     1fc1d40  1fc1d40
   ordblks         2        4
   mxordblk  1fbc778  1fba3e8
   uordblks     55b0     56b8
   fordblks  1fbc790  1fbc688
   user_main: Exiting
   ostest_main: Exiting with status 0
   ```
   
   - rv64 (`qemu-system-riscv64 -M virt -cpu rv64 -smp 8`), tail of the log:
   
   ```
   arena     1fc9700  1fc9700
   ordblks         1        7
   mxordblk  1fc3570  1fa1890
   uordblks     6190     c120
   fordblks  1fc3570  1fbd5e0
   user_main: Exiting
   ostest_main: Exiting with status 0
   ```
   
   Full logs are available at 
`/disk0/gitcode/pick-invdiv-verify/ostest-rv32.log` (1028 lines) and 
`ostest-rv64.log` (1390 lines). Strict failure count on both runs: 0.


-- 
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]

Reply via email to