Skip to content

Commit

Permalink
libc/picolibc: Support 'minimal' printf mode
Browse files Browse the repository at this point in the history
Picolibc's 'minimal' printf mode reduces functionality and size even more
than the 'integer' mode. Use this where memory is at a premium and where
the application knows that it does not require exact printf semantics.

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard committed Sep 21, 2023
1 parent 30bc872 commit bbf1279
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/libc/picolibc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ if(NOT CONFIG_PICOLIBC_USE_MODULE)
if(CONFIG_PICOLIBC_IO_FLOAT)
zephyr_compile_definitions(PICOLIBC_DOUBLE_PRINTF_SCANF)
zephyr_link_libraries(-DPICOLIBC_DOUBLE_PRINTF_SCANF)
elseif(CONFIG_PICOLIBC_IO_MINIMAL)
zephyr_compile_definitions(PICOLIBC_MINIMAL_PRINTF_SCANF)
zephyr_link_libraries(-DPICOLIBC_MINIMAL_PRINTF_SCANF)
else()
zephyr_compile_definitions(PICOLIBC_INTEGER_PRINTF_SCANF)
zephyr_link_libraries(-DPICOLIBC_INTEGER_PRINTF_SCANF)
Expand Down
44 changes: 39 additions & 5 deletions lib/libc/picolibc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,38 @@ config PICOLIBC_HEAP_SIZE
config PICOLIBC_IO_LONG_LONG
bool "support for long long in integer-only printf/scanf"
help
Includes support for long long in integer-only printf/scanf. long long
types are always supported in the floating-point versions.
Includes support for long long in minimal printf/scanf. long
long types are always supported in the integer and
floating-point versions.

choice PICOLIBC_IO_LEVEL
prompt "Picolibc printf/scanf level"
default PICOLIBC_IO_MINIMAL if CBPRINTF_NANO
default PICOLIBC_IO_INTEGER
help
Selects the level of printf and scanf support

config PICOLIBC_IO_FLOAT
bool "support for floating point values in printf/scanf"
bool "full support for integer/floating point values in printf/scanf"
help
Include full floating point and integer support in printf/scanf
functions.

config PICOLIBC_IO_INTEGER
bool "full support for integer values in printf/scanf"
depends on !CBPRINTF_FP_SUPPORT
help
Include full integer, but no floating point support in
printf/scanf.

config PICOLIBC_IO_MINIMAL
bool "limited support for integer values in printf/scanf"
depends on !CBPRINTF_FP_SUPPORT
help
Include floating point support in printf/scanf functions.
Include limited integer and no floating point suppor tin
printf/scanf.

endchoice

if PICOLIBC_USE_MODULE

Expand Down Expand Up @@ -94,14 +119,15 @@ config PICOLIBC_ASSERT_VERBOSE
config PICOLIBC_IO_C99_FORMATS
bool "support C99 format additions in printf/scanf"
default y
depends on !PICOLIBC_IO_MINIMAL
help
Includes support for hex floats (in floating-point version) and j, z,
t size modifiers.

config PICOLIBC_IO_POS_ARGS
bool "Support POSIX positional args (e.g. %$1d) in printf/scanf"
default y
depends on !PICOLIBC_IO_FLOAT
depends on PICOLIBC_IO_INTEGER
help
Includes support for positional args (e.g. $1) in integer-only printf
and scanf. Positional args are always supported in the floating-point
Expand All @@ -115,6 +141,14 @@ config PICOLIBC_IO_FLOAT_EXACT
This ensures that printf values with enough digits can be
fed to scanf and generate exactly the same binary value.

config PICOLIBC_IO_SMALL_ULTOA
bool "avoid soft division in printf"
default y if PICOLIBC_IO_MINIMAL || PICOLIBC_IO_INTEGER && PICOLIBC_IO_LONG_LONG
help
Replaces division and modulus by 10 with shifts and adds when
doing binary to decimal conversion in printf for targets with
no hardware divider.

config PICOLIBC_LOCALE_INFO
bool "support locales in libc functions"
help
Expand Down
1 change: 0 additions & 1 deletion lib/os/Kconfig.cbprintf
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ config CBPRINTF_FP_SUPPORT
bool "Floating point formatting in cbprintf"
default y if FPU
depends on CBPRINTF_COMPLETE
select PICOLIBC_IO_FLOAT if PICOLIBC
help
Build the cbprintf utility function with support for floating
point format specifiers. Selecting this increases stack size
Expand Down

0 comments on commit bbf1279

Please sign in to comment.