arjav1528 commented on code in PR #18347:
URL: https://github.com/apache/nuttx/pull/18347#discussion_r2774078922


##########
include/nuttx/lib/stdbit.h:
##########
@@ -0,0 +1,225 @@
+/****************************************************************************
+ * include/nuttx/lib/stdbit.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_LIB_STDBIT_H
+#define __INCLUDE_NUTTX_LIB_STDBIT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+#include <stdint.h>
+
+#ifdef CONFIG_ARCH_STDBIT_H
+#  include <arch/stdbit.h>
+#else
+
+/****************************************************************************
+ * Generic C23 stdbit implementation (CONFIG_LIBC_STDBIT_GENERIC).
+ * Requires __builtin_clz, __builtin_ctz, __builtin_popcount (and ll
+ * variants). If the toolchain does not provide them, enable the
+ * corresponding CONFIG_HAVE_BUILTIN_* in nuttx/compiler.h or do not
+ * use LIBC_STDBIT_GENERIC.
+ ****************************************************************************/
+
+#  if !defined(CONFIG_HAVE_BUILTIN_CLZ) || \
+      !defined(CONFIG_HAVE_BUILTIN_CTZ) || \
+      !defined(CONFIG_HAVE_BUILTIN_POPCOUNT)
+#    error "Generic stdbit requires CONFIG_HAVE_BUILTIN_CLZ, CTZ, POPCOUNT"
+#  endif
+
+#  if defined(CONFIG_HAVE_LONG_LONG) && \
+      !defined(CONFIG_HAVE_BUILTIN_POPCOUNTLL)
+#    error "Generic stdbit 64-bit requires CONFIG_HAVE_BUILTIN_POPCOUNTLL"
+#  endif
+
+/****************************************************************************
+ * C23 endianness macros
+ ****************************************************************************/
+
+#  ifdef CONFIG_ENDIAN_BIG
+#    define __STDC_ENDIAN_NATIVE__  __STDC_ENDIAN_BIG__
+#    define __STDC_ENDIAN_LITTLE__  1234
+#    define __STDC_ENDIAN_BIG__     4321
+#  else
+#    define __STDC_ENDIAN_NATIVE__  __STDC_ENDIAN_LITTLE__
+#    define __STDC_ENDIAN_LITTLE__  1234
+#    define __STDC_ENDIAN_BIG__     4321
+#  endif
+
+/****************************************************************************
+ * Leading / trailing zeros (C23: zero input returns bit width)
+ ****************************************************************************/
+
+#  define stdc_leading_zeros_uc(x) \
+    ((unsigned char)(x) == 0 ? 8 : \
+     (unsigned char)__builtin_clz((unsigned)(x) << 24))
+#  define stdc_leading_zeros_us(x) \
+    ((unsigned short)(x) == 0 ? 16 : \
+     (unsigned short)__builtin_clz((unsigned)(x) << 16))
+#  define stdc_leading_zeros_ui(x) \
+    ((x) == 0 ? 32 : (unsigned)__builtin_clz(x))
+#  define stdc_leading_zeros_ul(x) \
+    ((x) == 0 ? (unsigned long)(8*sizeof(unsigned long)) : \
+     (unsigned long)__builtin_clzl(x))
+#  define stdc_leading_zeros_ull(x) \
+    ((x) == 0 ? (unsigned long long)(8*sizeof(unsigned long long)) : \
+     (unsigned long long)__builtin_clzll(x))

Review Comment:
   Me too!, I have commited the change, kindly review the PR 



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