Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Documentation/components/libs/libc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ functions. So we have::
sched - sched.h
search - search.h
semaphore - semaphore.h
stdbit - stdbit.h (optional C23)
stdio - stdio.h
stdlib - stdlib.h
string - string.h (and legacy strings.h and non-standard nuttx/b2c.h)
Expand Down Expand Up @@ -155,5 +156,6 @@ Implementation Details
:caption: Contents:

search.rst
stdbit.rst
stream.rst
zoneinfo.rst
30 changes: 30 additions & 0 deletions Documentation/components/libs/libc/stdbit.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
========
stdbit.h
========

The optional C23 ``stdbit.h`` header provides bit manipulation macros
(endianness, leading/trailing zeros and ones, count, single-bit test,
bit width, bit floor, bit ceil). NuttX provides this header only when
explicitly enabled via Kconfig.

Configuration
=============

- **CONFIG_ARCH_HAVE_STDBIT_H** (bool, selected by arch)
Architecture indicates it provides ``arch/<arch>/include/stdbit.h``.

- **CONFIG_ARCH_STDBIT_H** (bool "stdbit.h", depends on ARCH_HAVE_STDBIT_H)
Use the redirecting header. The build copies
``include/nuttx/lib/stdbit.h`` to ``include/stdbit.h``; that header
then includes ``<arch/stdbit.h>`` when this option is set.

- **CONFIG_LIBC_STDBIT_GENERIC** (bool "stdbit.h (generic C23)")
Use the generic C23 implementation. The same redirecting file
``include/nuttx/lib/stdbit.h`` is copied to ``include/stdbit.h``,
and the generic implementation is used (no arch header). Requires
compiler builtins (e.g. ``__builtin_clz``, ``__builtin_ctz``,
``__builtin_popcount``); see ``CONFIG_HAVE_BUILTIN_*`` in
``nuttx/compiler.h``.

Either **CONFIG_ARCH_STDBIT_H** or **CONFIG_LIBC_STDBIT_GENERIC** may be
enabled so that ``#include <stdbit.h>`` is available.
25 changes: 25 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,31 @@ config ARCH_STDARG_H
ARCH_STDARG_H=y and providing. If ARCH_STDARG_H, is not defined, then
the stdarg.h header file will stay out-of-the-way in include/nuttx/.

config ARCH_HAVE_STDBIT_H
bool
default n
---help---
Selected by architecture specific logic if the architecture
provides a stdbit.h header file.

config ARCH_STDBIT_H
bool "stdbit.h"
depends on ARCH_HAVE_STDBIT_H
default n
---help---
Redirecting stdbit.h lives at include/nuttx/lib/stdbit.h. When
this is set, the build copies it to include/stdbit.h and it
includes arch/stdbit.h if the architecture provides one.

config LIBC_STDBIT_GENERIC
bool "stdbit.h (generic C23)"
default n
---help---
Use generic C23 stdbit implementation. When set, copy
include/nuttx/lib/stdbit.h to include/stdbit.h. No arch
header is used; builtins (e.g. __builtin_clz) must be
available (see CONFIG_HAVE_BUILTIN_* in compiler.h).

config ARCH_HAVE_SETJMP
bool
default n
Expand Down
16 changes: 15 additions & 1 deletion cmake/nuttx_generate_headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ else()
file(REMOVE ${CMAKE_BINARY_DIR}/include/setjmp.h)
endif()

# Target used to copy include/nuttx/lib/stdbit.h. If CONFIG_ARCH_STDBIT_H or
# CONFIG_LIBC_STDBIT_GENERIC is set, copy stdbit.h to include/ for C23 bit
# utilities.

if(CONFIG_ARCH_STDBIT_H OR CONFIG_LIBC_STDBIT_GENERIC)
nuttx_create_symlink(${NUTTX_DIR}/include/nuttx/lib/stdbit.h
${CMAKE_BINARY_DIR}/include/stdbit.h)
else()
file(REMOVE ${CMAKE_BINARY_DIR}/include/stdbit.h)
endif()

# Add final context target that ties together all of the above The context
# target is invoked on each target build to assure that NuttX is properly
# configured. The basic configuration steps include creation of the the
Expand All @@ -151,7 +162,10 @@ add_custom_target(
$<$<BOOL:${CONFIG_ARCH_STDARG_H}>:${CMAKE_BINARY_DIR}/include/stdarg.h>
$<$<BOOL:${NEED_MATH_H}>:${CMAKE_BINARY_DIR}/include/math.h>
$<$<BOOL:${CONFIG_ARCH_FLOAT_H}>:${CMAKE_BINARY_DIR}/include/float.h>
$<$<BOOL:${CONFIG_ARCH_SETJMP_H}>:${CMAKE_BINARY_DIR}/include/setjmp.h>)
$<$<BOOL:${CONFIG_ARCH_SETJMP_H}>:${CMAKE_BINARY_DIR}/include/setjmp.h>
$<$<BOOL:${CONFIG_ARCH_STDBIT_H}>:${CMAKE_BINARY_DIR}/include/stdbit.h>
$<$<BOOL:${CONFIG_LIBC_STDBIT_GENERIC}>:${CMAKE_BINARY_DIR}/include/stdbit.h>
)

# apps_context is a PHONY target used as an intermediate process to control the
# time order of context preparation actions of app building
Expand Down
Loading
Loading