-
Notifications
You must be signed in to change notification settings - Fork 1.5k
libc: Add C23 stdbit.h with optional Kconfig and generic implementation #18347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
michallenc
left a comment
There was a problem hiding this 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.
include/nuttx/lib/stdbit.h
Outdated
|
|
||
| /* 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
ad2e28a to
277c277
Compare
277c277 to
8abb829
Compare
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>
8abb829 to
8e473c0
Compare
|
Seems the merge request now contains completely different commits unrelated to the title and previous changes. |
Fixes: #18311
Summary
Add optional C23
stdbit.hsupport so builds can provide<stdbit.h>when the toolchain does not. Follows the same pattern asstdarg.h/math.h: redirect atinclude/nuttx/lib/stdbit.h, copied toinclude/stdbit.hwhen enabled.ARCH_HAVE_STDBIT_H,ARCH_STDBIT_H(arch-specific),LIBC_STDBIT_GENERIC(generic on any arch).__builtin_clz/__builtin_ctz/__builtin_popcountfor all C23 stdbit macros; archs may providearch/<arch>/include/stdbit.h.libs/libc/stdbit/stdbit_verify.c(compile-time check when stdbit enabled).Documentation/legacy_README.mdandDocumentation/components/libs/libc/index.rst.