Brijesh-Thakkar opened a new pull request, #21212:
URL: https://github.com/apache/nuttx/pull/21212
## Summary
`clock_basetime()` computes the initial time as `tv_sec = jdn *
SEC_PER_DAY`, where `jdn` is
promoted to 64-bit. On targets without a native 64-bit multiply this pulls
in libgcc's
`__muldi3`.
`jdn` is the day count from `clock_calendar2utc()` for `CONFIG_START_YEAR`
(>= 1970), so it is
non-negative and well below 2^32 (at most ~49,710 for the allowed year
range). A 32x32->64
multiply is therefore sufficient:
tp->tv_sec = (uint64_t)(uint32_t)jdn * SEC_PER_DAY;
A comment in the code documents why the cast is safe.
This is a small follow-up from the size investigation in #18849: after
#20996, this is the
only remaining 64-bit libgcc call site in the common clock code where a
portable C change
reduces size on AVR. Replacing the remaining 64-bit divisions with portable
C was measured to
be larger than libgcc's routines on AVR, so it is not proposed.
Refs #18849
## Impact
- No functional change; same result for every legal `jdn` (verified, see
Testing).
- No API/ABI change; `time_t` stays `int64_t`.
- Size (master 3122150b1f vs this PR, `size` total in bytes):
| config | master | this PR | delta | notes |
|---|---:|---:|---:|---|
| breadxavr:nsh (AVR, avr-gcc 14.3.0) | 58485 | 58403 | **-82** | `__muldi3`
replaced by smaller `__umulsidi3` |
| stm32vldiscovery:nsh (Cortex-M3) | 40680 | 40684 | +4 | text identical; +4
is `g_version` build-path string in .data |
| nucleo-f072rb:nsh (Cortex-M0, DEBUG_NOOPT) | 86839 | 86851 | +12 (+8 text)
| M0 has no 32x32->64 multiply instruction, so `__aeabi_lmul` is still used |
| nucleo-f072rb:nsh (Cortex-M0, DEBUG_FULLOPT) | ... | ... | ... | ... |
## Testing
- Host test comparing `(uint64_t)(uint32_t)jdn * 86400` against the original
`(int64_t)jdn * 86400` over the full legal range (strided, with edge
values):
1,178,898 checks, 0 mismatches.
- `sim:nsh`: builds, `ostest` exits with status 0, `/proc/uptime` and `date`
behave normally.
Note: sim uses `CONFIG_RTC=y`, so it does not execute `clock_basetime()`;
this is a
no-regression check only, and the arithmetic is covered by the host test
above.
- Built breadxavr:nsh, stm32vldiscovery:nsh, nucleo-f072rb:nsh
(arm-none-eabi-gcc 14.2.1).
- `tools/checkpatch.sh -c -u -m -g HEAD~1..HEAD` clean.
--
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]