Swatantra-66 opened a new pull request, #22162:
URL: https://github.com/apache/nuttx/pull/22162

   ## Summary
   Memory-constrained embedded targets (`DEFAULT_SMALL=y`) rarely format 
integers in octal notation (`%o`). The vsprintf engine in 
`libs/libc/stream/lib_libvsprintf.c` already provides dead-code elimination via 
`CONFIG_LIBC_PRINTF_OCTAL`, printing `'?'` when octal support is disabled. 
However, `CONFIG_LIBC_PRINTF_OCTAL` currently defaults unconditionally to `y`.
   
   Change `CONFIG_LIBC_PRINTF_OCTAL` to default to `LIBC_PRINTF_FULL || 
!DEFAULT_SMALL`. This eliminates octal parsing, alternate form (`%#o`) checks, 
and base-8 conversion logic on small profiles, saving **178 bytes** of Flash 
(`text`) and **32 bytes** of RAM (`bss`) in `lib_libvsprintf.o` (**176 bytes** 
Flash in the linked `nuttx` binary on `sim:nsh`), while preserving full 
conformance when `LIBC_PRINTF_FULL` is selected or on standard targets.
   
   Part of Issue #20414.
   
   ## Impact
   - **Is new feature added?** No (adjusts default of existing Kconfig option 
`CONFIG_LIBC_PRINTF_OCTAL`).
   - **Is existing feature changed?** Yes, `printf("%o")` outputs `'?'` on 
`DEFAULT_SMALL=y` targets unless explicitly enabled or using `LIBC_PRINTF_FULL`.
   - **Impact on user:** None for standard builds or when `LIBC_PRINTF_FULL=y`. 
On `DEFAULT_SMALL=y` targets, saves Flash without manual Kconfig tuning.
   - **Impact on build:** None.
   - **Impact on hardware:** None.
   - **Impact on documentation:** Updated 
`Documentation/os/libs/libc/printf.rst`.
   
   ## Size Difference (sim:nsh)
   
   Configuration: `sim:nsh` (x86_64)
   
   ### `libs/libc/bin/lib_libvsprintf.o`
   
   | Section | `CONFIG_LIBC_PRINTF_OCTAL=y` | `CONFIG_LIBC_PRINTF_OCTAL=n` | 
Difference |
   | :--- | :--- | :--- | :--- |
   | **text** | 12589 | 12411 | **-178 bytes (-1.4%)** |
   | **data** | 560 | 560 | 0 bytes |
   | **bss** | 1840 | 1808 | **-32 bytes** |
   | **Total** | 14989 | 14779 | **-210 bytes (-1.4%)** |
   
   ### Linked Binary (`nuttx`)
   
   | Section | `CONFIG_LIBC_PRINTF_OCTAL=y` | `CONFIG_LIBC_PRINTF_OCTAL=n` | 
Difference |
   | :--- | :--- | :--- | :--- |
   | **text** | 1245740 | 1245564 | **-176 bytes** |
   | **data** | 287336 | 287336 | 0 bytes |
   | **bss** | 207136 | 207104 | **-32 bytes** |
   | **Total** | 1740212 | 1740004 | **-208 bytes** |
   
   ## Testing
   
   ### Build Verification
   - Clean build with `CONFIG_LIBC_PRINTF_OCTAL=y`: Success.
   - Clean build with `CONFIG_LIBC_PRINTF_OCTAL=n`: Success.
   
   ### Runtime Test Log (`sim:nsh`, `CONFIG_LIBC_PRINTF_OCTAL=n`)
   ```text
   nsh> help
   help usage:  help [-v] [<cmd>]
   
       .           dirname     free        mount       set         umount      
       [           date        help        mv          kill        unset       
       ?           df          hexdump     pidof       pkill       uptime      
       alias       dmesg       losetup     poweroff    sleep       watch       
       unalias     echo        ln          quit        usleep      xd          
       basename    env         ls          printf      source      wait        
       break       exec        du          ps          test        
       cat         exit        mkdir       pwd         time        
       cd          expr        mkfatfs     readlink    true        
       cp          false       mkfifo      rm          truncate    
       cmp         fdinfo      mkrd        rmdir       uname       
   
   Builtin Apps:
       dd           gcov         hello        nsh          sh           
       dumpstack    gpio         init         ostest       
   nsh> ps
     TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK        
    STACK COMMAND
       0     0     0   0 FIFO     Kthread   - Ready              
0000000000000000 0069584 Idle_Task
       1     0     0 224 FIFO     Kthread   - Waiting  Semaphore 
0000000000000000 0067456 sim_loop_wq 0x74a702200400 0x74a702200488
       2     0     0 224 FIFO     Kthread   - Waiting  Semaphore 
0000000000000000 0067472 hpwork 0x4017ccc0 0x4017cd48
       4     4     0 100 FIFO     Task      - Waiting  Semaphore 
0000000000000000 0067504 init_main
       7     7     4 100 FIFO     Task      - Running            
0000000000000000 0067504 sh
   nsh> poweroff
   ```
   


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