Skip to content

Conversation

@Donny9
Copy link
Contributor

@Donny9 Donny9 commented Dec 31, 2025

Summary

nshlib/ls_handler: eliminate floating-point operations for human-readable sizes

Replace floating-point arithmetic with fixed-point integer math to avoid linking soft-float library (~2-3KB Flash) when displaying human-readable file sizes (ls -lh command).

Changes:

  • Use integer division and modulo to calculate size components
  • Calculate decimal part: (remainder * 10) / unit for one decimal place
  • Refactor duplicated code: consolidate GB/MB/KB logic into single path
  • Remove CONFIG_HAVE_FLOAT dependency

This eliminates calls to __aeabi_f2d, __aeabi_fmul, __aeabi_i2f and other ARM EABI floating-point helpers, reducing Flash footprint for systems compiled with -mfloat-abi=soft.

Impact

save flash size

Testing

nsh ls

…able sizes

Replace floating-point arithmetic with fixed-point integer math to avoid
linking soft-float library (~2-3KB Flash) when displaying human-readable
file sizes (ls -lh command).

Changes:
- Use integer division and modulo to calculate size components
- Calculate decimal part: (remainder * 10) / unit for one decimal place
- Refactor duplicated code: consolidate GB/MB/KB logic into single path
- Remove CONFIG_HAVE_FLOAT dependency

This eliminates calls to __aeabi_f2d, __aeabi_fmul, __aeabi_i2f and other
ARM EABI floating-point helpers, reducing Flash footprint for systems
compiled with -mfloat-abi=soft.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
@linguini1
Copy link
Contributor

Looks good! Can you add the output of the ls command to your testing section?

@acassis acassis merged commit c90b64e into apache:master Dec 31, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants