Skip to content

Conversation

@arjav1528
Copy link

@arjav1528 arjav1528 commented Feb 3, 2026

Fixes: #18311

Summary

Add optional C23 stdbit.h support so builds can provide <stdbit.h> when the toolchain does not. Follows the same pattern as stdarg.h / math.h: redirect at include/nuttx/lib/stdbit.h, copied to include/stdbit.h when enabled.

  • Kconfig: ARCH_HAVE_STDBIT_H, ARCH_STDBIT_H (arch-specific), LIBC_STDBIT_GENERIC (generic on any arch).
  • Header: Generic implementation using __builtin_clz/__builtin_ctz/__builtin_popcount for all C23 stdbit macros; archs may provide arch/<arch>/include/stdbit.h.
  • Build: Unix.mk, Win.mk, CMake copy the header when either option is set.
  • Libc: Optional libs/libc/stdbit/stdbit_verify.c (compile-time check when stdbit enabled).
  • Docs: Documentation/legacy_README.md and Documentation/components/libs/libc/index.rst.

@github-actions github-actions bot added Area: Documentation Improvements or additions to documentation Area: Tooling Area: Build system Area: OS Components OS Components issues Size: M The size of the change in this PR is medium labels Feb 3, 2026
@linguini1 linguini1 requested a review from michallenc February 3, 2026 17:47
Copy link
Contributor

@michallenc michallenc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was fast, nice work! Please squash the commits ideally into two - one implementing stdbit and other updating the documentation. Also fix long lines in stdbit.h causing CI to fail.

We definitely need proper tests before merging this. These should go to app repository. I can write some, but won't get to it until next week probably.


/* Leading zeros: result is width when x == 0 (C23). */

#define stdc_leading_zeros_uc(x) ((x) ? (unsigned int)(__builtin_clz((unsigned int)(x)) - (_STDBIT_WIDTH_UI - _STDBIT_WIDTH_UC)) : _STDBIT_WIDTH_UC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NuttX still supports builds with older GNUC where __builtin_clz and others might not be defined (look at nuttx/compiler.h). We get CONFIG_HAVE_BUILTIN_CTZ and other defines that tell us if the builtin is available.

We probably don't have to support older GNUC right away, but I think at least some compilation time error could be raised here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I have applied the changes, could you please review the changes

Kconfig Outdated
ARCH_HAVE_STDBIT_H. Otherwise a generic C23 implementation is
used.

config LIBC_STDBIT_GENERIC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this belongs here. I suppose it's ok to make stdbit.h not mandatory, but maybe it could be done similarly to libm and put the configuration option to libs/libc/stdbit/ directory?

tools/Unix.mk Outdated
# CONFIG_LIBC_STDBIT_GENERIC is defined, copy stdbit.h to include/ for C23
# bit utilities.

ifeq ($(CONFIG_ARCH_STDBIT_H),y)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do something like

ifeq ($(firstword $(filter y,$(CONFIG_ARCH_STDBIT_H) $(CONFIG_LIBC_STDBIT_GENERIC))),y)

to get logical OR and avoid unnecessary code duplication.

@arjav1528 arjav1528 force-pushed the dev-issue-18311 branch 2 times, most recently from ad2e28a to 277c277 Compare February 4, 2026 12:43
@arjav1528 arjav1528 requested a review from michallenc February 4, 2026 12:44
txy-21 and others added 2 commits February 4, 2026 22:15
Include nuttx/kmalloc.h in arm64_arch_timer.c to fix missing header
dependency. This ensures proper memory allocation functions are
available for the architecture timer implementation.

Signed-off-by: hongfengchen <hongfengchen@xiaomi.com>
Add DEBUGASSERT in nxsem_wait_slow() to catch illegal mutex
recursion attempts. This helps identify bugs where a task tries
to lock a mutex it already holds, which is not allowed.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
@github-actions github-actions bot added Arch: arm64 Issues related to ARM64 (64-bit) architecture Size: XS The size of the change in this PR is very small and removed Area: Documentation Improvements or additions to documentation Area: Tooling Area: Build system labels Feb 4, 2026
@michallenc
Copy link
Contributor

Seems the merge request now contains completely different commits unrelated to the title and previous changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm64 Issues related to ARM64 (64-bit) architecture Area: OS Components OS Components issues Size: M The size of the change in this PR is medium Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Missing stdbit.h header

4 participants