[libc-commits] [libc] [libc][stdbit] implement stdc_first_trailing_one (C23) (PR #81768)
via libc-commits
libc-commits at lists.llvm.org
Wed Feb 14 09:35:16 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Nick Desaulniers (nickdesaulniers)
<details>
<summary>Changes</summary>
---
Patch is 41.40 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/81768.diff
39 Files Affected:
- (modified) libc/config/linux/x86_64/entrypoints.txt (+10)
- (modified) libc/docs/stdbit.rst (+12-12)
- (modified) libc/include/llvm-libc-macros/stdbit-macros.h (+44)
- (modified) libc/spec/stdc.td (+9-2)
- (modified) libc/src/__support/CPP/bit.h (+12)
- (modified) libc/src/stdbit/CMakeLists.txt (+2)
- (added) libc/src/stdbit/stdc_first_trailing_one_uc.cpp (+21)
- (added) libc/src/stdbit/stdc_first_trailing_one_uc.h (+18)
- (added) libc/src/stdbit/stdc_first_trailing_one_ui.cpp (+20)
- (added) libc/src/stdbit/stdc_first_trailing_one_ui.h (+18)
- (added) libc/src/stdbit/stdc_first_trailing_one_ul.cpp (+21)
- (added) libc/src/stdbit/stdc_first_trailing_one_ul.h (+18)
- (added) libc/src/stdbit/stdc_first_trailing_one_ull.cpp (+21)
- (added) libc/src/stdbit/stdc_first_trailing_one_ull.h (+18)
- (added) libc/src/stdbit/stdc_first_trailing_one_us.cpp (+21)
- (added) libc/src/stdbit/stdc_first_trailing_one_us.h (+18)
- (added) libc/src/stdbit/stdc_first_trailing_zero_uc.cpp (+21)
- (added) libc/src/stdbit/stdc_first_trailing_zero_uc.h (+18)
- (added) libc/src/stdbit/stdc_first_trailing_zero_ui.cpp (+20)
- (added) libc/src/stdbit/stdc_first_trailing_zero_ui.h (+18)
- (added) libc/src/stdbit/stdc_first_trailing_zero_ul.cpp (+21)
- (added) libc/src/stdbit/stdc_first_trailing_zero_ul.h (+18)
- (added) libc/src/stdbit/stdc_first_trailing_zero_ull.cpp (+21)
- (added) libc/src/stdbit/stdc_first_trailing_zero_ull.h (+18)
- (added) libc/src/stdbit/stdc_first_trailing_zero_us.cpp (+21)
- (added) libc/src/stdbit/stdc_first_trailing_zero_us.h (+18)
- (modified) libc/test/include/stdbit_test.cpp (+30)
- (modified) libc/test/src/__support/CPP/bit_test.cpp (+12)
- (modified) libc/test/src/stdbit/CMakeLists.txt (+2)
- (added) libc/test/src/stdbit/stdc_first_trailing_one_uc_test.cpp (+20)
- (added) libc/test/src/stdbit/stdc_first_trailing_one_ui_test.cpp (+20)
- (added) libc/test/src/stdbit/stdc_first_trailing_one_ul_test.cpp (+20)
- (added) libc/test/src/stdbit/stdc_first_trailing_one_ull_test.cpp (+20)
- (added) libc/test/src/stdbit/stdc_first_trailing_one_us_test.cpp (+20)
- (added) libc/test/src/stdbit/stdc_first_trailing_zero_uc_test.cpp (+20)
- (added) libc/test/src/stdbit/stdc_first_trailing_zero_ui_test.cpp (+20)
- (added) libc/test/src/stdbit/stdc_first_trailing_zero_ul_test.cpp (+20)
- (added) libc/test/src/stdbit/stdc_first_trailing_zero_ull_test.cpp (+21)
- (added) libc/test/src/stdbit/stdc_first_trailing_zero_us_test.cpp (+20)
``````````diff
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index fc30bcf56665c7..57b4a1e0f93d4f 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -122,6 +122,16 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdbit.stdc_first_leading_one_ui
libc.src.stdbit.stdc_first_leading_one_ul
libc.src.stdbit.stdc_first_leading_one_ull
+ libc.src.stdbit.stdc_first_trailing_zero_uc
+ libc.src.stdbit.stdc_first_trailing_zero_us
+ libc.src.stdbit.stdc_first_trailing_zero_ui
+ libc.src.stdbit.stdc_first_trailing_zero_ul
+ libc.src.stdbit.stdc_first_trailing_zero_ull
+ libc.src.stdbit.stdc_first_trailing_one_uc
+ libc.src.stdbit.stdc_first_trailing_one_us
+ libc.src.stdbit.stdc_first_trailing_one_ui
+ libc.src.stdbit.stdc_first_trailing_one_ul
+ libc.src.stdbit.stdc_first_trailing_one_ull
# stdlib.h entrypoints
libc.src.stdlib.abs
diff --git a/libc/docs/stdbit.rst b/libc/docs/stdbit.rst
index 5ff36dcb0f5929..3bd83ff70c8924 100644
--- a/libc/docs/stdbit.rst
+++ b/libc/docs/stdbit.rst
@@ -61,16 +61,16 @@ stdc_first_leading_one_us |check|
stdc_first_leading_one_ui |check|
stdc_first_leading_one_ul |check|
stdc_first_leading_one_ull |check|
-stdc_first_trailing_zero_uc
-stdc_first_trailing_zero_us
-stdc_first_trailing_zero_ui
-stdc_first_trailing_zero_ul
-stdc_first_trailing_zero_ull
-stdc_first_trailing_one_uc
-stdc_first_trailing_one_us
-stdc_first_trailing_one_ui
-stdc_first_trailing_one_ul
-stdc_first_trailing_one_ull
+stdc_first_trailing_zero_uc |check|
+stdc_first_trailing_zero_us |check|
+stdc_first_trailing_zero_ui |check|
+stdc_first_trailing_zero_ul |check|
+stdc_first_trailing_zero_ull |check|
+stdc_first_trailing_one_uc |check|
+stdc_first_trailing_one_us |check|
+stdc_first_trailing_one_ui |check|
+stdc_first_trailing_one_ul |check|
+stdc_first_trailing_one_ull |check|
stdc_count_zeros_uc
stdc_count_zeros_us
stdc_count_zeros_ui
@@ -120,8 +120,8 @@ stdc_trailing_zeros |check|
stdc_trailing_ones |check|
stdc_first_leading_zero |check|
stdc_first_leading_one |check|
-stdc_first_trailing_zero
-stdc_first_trailing_one
+stdc_first_trailing_zero |check|
+stdc_first_trailing_one |check|
stdc_count_zeros
stdc_count_ones
stdc_has_single_bit
diff --git a/libc/include/llvm-libc-macros/stdbit-macros.h b/libc/include/llvm-libc-macros/stdbit-macros.h
index 87c590e61e3999..0c97da96ebba29 100644
--- a/libc/include/llvm-libc-macros/stdbit-macros.h
+++ b/libc/include/llvm-libc-macros/stdbit-macros.h
@@ -101,6 +101,36 @@ inline unsigned stdc_first_leading_one(unsigned long x) {
inline unsigned stdc_first_leading_one(unsigned long long x) {
return stdc_first_leading_one_ull(x);
}
+inline unsigned stdc_first_trailing_zero(unsigned char x) {
+ return stdc_first_trailing_zero_uc(x);
+}
+inline unsigned stdc_first_trailing_zero(unsigned short x) {
+ return stdc_first_trailing_zero_us(x);
+}
+inline unsigned stdc_first_trailing_zero(unsigned x) {
+ return stdc_first_trailing_zero_ui(x);
+}
+inline unsigned stdc_first_trailing_zero(unsigned long x) {
+ return stdc_first_trailing_zero_ul(x);
+}
+inline unsigned stdc_first_trailing_zero(unsigned long long x) {
+ return stdc_first_trailing_zero_ull(x);
+}
+inline unsigned stdc_first_trailing_one(unsigned char x) {
+ return stdc_first_trailing_one_uc(x);
+}
+inline unsigned stdc_first_trailing_one(unsigned short x) {
+ return stdc_first_trailing_one_us(x);
+}
+inline unsigned stdc_first_trailing_one(unsigned x) {
+ return stdc_first_trailing_one_ui(x);
+}
+inline unsigned stdc_first_trailing_one(unsigned long x) {
+ return stdc_first_trailing_one_ul(x);
+}
+inline unsigned stdc_first_trailing_one(unsigned long long x) {
+ return stdc_first_trailing_one_ull(x);
+}
#else
#define stdc_leading_zeros(x) \
_Generic((x), \
@@ -144,6 +174,20 @@ inline unsigned stdc_first_leading_one(unsigned long long x) {
unsigned: stdc_first_leading_one_ui, \
unsigned long: stdc_first_leading_one_ul, \
unsigned long long: stdc_first_leading_one_ull)(x)
+#define stdc_first_trailing_zero(x) \
+ _Generic((x), \
+ unsigned char: stdc_first_trailing_zero_uc, \
+ unsigned short: stdc_first_trailing_zero_us, \
+ unsigned: stdc_first_trailing_zero_ui, \
+ unsigned long: stdc_first_trailing_zero_ul, \
+ unsigned long long: stdc_first_trailing_zero_ull)(x)
+#define stdc_first_trailing_one(x) \
+ _Generic((x), \
+ unsigned char: stdc_first_trailing_one_uc, \
+ unsigned short: stdc_first_trailing_one_us, \
+ unsigned: stdc_first_trailing_one_ui, \
+ unsigned long: stdc_first_trailing_one_ul, \
+ unsigned long long: stdc_first_trailing_one_ull)(x)
#endif // __cplusplus
#endif // __LLVM_LIBC_MACROS_STDBIT_MACROS_H
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 5e87831b907fb5..9ed94638f522ca 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -782,7 +782,9 @@ def StdC : StandardSpec<"stdc"> {
Macro<"stdc_trailing_zeros">,
Macro<"stdc_trailing_ones">,
Macro<"stdc_first_leading_zero">,
- Macro<"stdc_first_leading_one">
+ Macro<"stdc_first_leading_one">,
+ Macro<"stdc_first_trailing_zero">,
+ Macro<"stdc_first_trailing_one">
], // Macros
[], // Types
[], // Enumerations
@@ -816,7 +818,12 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"stdc_first_leading_one_us", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedShortType>]>,
FunctionSpec<"stdc_first_leading_one_ui", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedIntType>]>,
FunctionSpec<"stdc_first_leading_one_ul", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongType>]>,
- FunctionSpec<"stdc_first_leading_one_ull", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongLongType>]>
+ FunctionSpec<"stdc_first_leading_one_ull", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongLongType>]>,
+ FunctionSpec<"stdc_first_trailing_one_uc", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedCharType>]>,
+ FunctionSpec<"stdc_first_trailing_one_us", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedShortType>]>,
+ FunctionSpec<"stdc_first_trailing_one_ui", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedIntType>]>,
+ FunctionSpec<"stdc_first_trailing_one_ul", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongType>]>,
+ FunctionSpec<"stdc_first_trailing_one_ull", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongLongType>]>
] // Functions
>;
diff --git a/libc/src/__support/CPP/bit.h b/libc/src/__support/CPP/bit.h
index 23e305ab86219e..f5e50262371f26 100644
--- a/libc/src/__support/CPP/bit.h
+++ b/libc/src/__support/CPP/bit.h
@@ -236,6 +236,18 @@ template <typename T, typename = cpp::enable_if_t<cpp::is_unsigned_v<T>>>
return first_leading_zero(static_cast<T>(~value));
}
+template <typename T, typename = cpp::enable_if_t<cpp::is_unsigned_v<T>>>
+[[nodiscard]] LIBC_INLINE constexpr int first_trailing_zero(T value) {
+ return value == cpp::numeric_limits<T>::max()
+ ? 0
+ : countr_zero(static_cast<T>(~value)) + 1;
+}
+
+template <typename T, typename = cpp::enable_if_t<cpp::is_unsigned_v<T>>>
+[[nodiscard]] LIBC_INLINE constexpr int first_trailing_one(T value) {
+ return value == cpp::numeric_limits<T>::max() ? 0 : countr_zero(value) + 1;
+}
+
} // namespace LIBC_NAMESPACE::cpp
#endif // LLVM_LIBC_SRC___SUPPORT_CPP_BIT_H
diff --git a/libc/src/stdbit/CMakeLists.txt b/libc/src/stdbit/CMakeLists.txt
index 6ee93861b8db40..14cc26e206e0d3 100644
--- a/libc/src/stdbit/CMakeLists.txt
+++ b/libc/src/stdbit/CMakeLists.txt
@@ -5,6 +5,8 @@ set(prefixes
trailing_ones
first_leading_zero
first_leading_one
+ first_trailing_zero
+ first_trailing_one
)
set(suffixes c s i l ll)
foreach(prefix IN LISTS prefixes)
diff --git a/libc/src/stdbit/stdc_first_trailing_one_uc.cpp b/libc/src/stdbit/stdc_first_trailing_one_uc.cpp
new file mode 100644
index 00000000000000..6ed35966be61a0
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_one_uc.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of stdc_first_trailing_one_uc ----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdbit/stdc_first_trailing_one_uc.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned, stdc_first_trailing_one_uc,
+ (unsigned char value)) {
+ return static_cast<unsigned>(cpp::first_trailing_one(value));
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_first_trailing_one_uc.h b/libc/src/stdbit/stdc_first_trailing_one_uc.h
new file mode 100644
index 00000000000000..d733ce850de0fb
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_one_uc.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_first_trailing_one_uc ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_UC_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_UC_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned stdc_first_trailing_one_uc(unsigned char value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_UC_H
diff --git a/libc/src/stdbit/stdc_first_trailing_one_ui.cpp b/libc/src/stdbit/stdc_first_trailing_one_ui.cpp
new file mode 100644
index 00000000000000..a89083bd49507a
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_one_ui.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of stdc_first_trailing_one_ui ----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdbit/stdc_first_trailing_one_ui.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned, stdc_first_trailing_one_ui, (unsigned value)) {
+ return static_cast<unsigned>(cpp::first_trailing_one(value));
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_first_trailing_one_ui.h b/libc/src/stdbit/stdc_first_trailing_one_ui.h
new file mode 100644
index 00000000000000..6a6a5046709aec
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_one_ui.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_first_trailing_one_ui ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_UI_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_UI_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned stdc_first_trailing_one_ui(unsigned value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_UI_H
diff --git a/libc/src/stdbit/stdc_first_trailing_one_ul.cpp b/libc/src/stdbit/stdc_first_trailing_one_ul.cpp
new file mode 100644
index 00000000000000..f30078d0f5ffaa
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_one_ul.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of stdc_first_trailing_one_ul ----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdbit/stdc_first_trailing_one_ul.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned, stdc_first_trailing_one_ul,
+ (unsigned long value)) {
+ return static_cast<unsigned>(cpp::first_trailing_one(value));
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_first_trailing_one_ul.h b/libc/src/stdbit/stdc_first_trailing_one_ul.h
new file mode 100644
index 00000000000000..09b6a9bbbe34a1
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_one_ul.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_first_trailing_one_ul ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_UL_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_UL_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned stdc_first_trailing_one_ul(unsigned long value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_UL_H
diff --git a/libc/src/stdbit/stdc_first_trailing_one_ull.cpp b/libc/src/stdbit/stdc_first_trailing_one_ull.cpp
new file mode 100644
index 00000000000000..2e526a890cda9c
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_one_ull.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of stdc_first_trailing_one_ull ---------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdbit/stdc_first_trailing_one_ull.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned, stdc_first_trailing_one_ull,
+ (unsigned long long value)) {
+ return static_cast<unsigned>(cpp::first_trailing_one(value));
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_first_trailing_one_ull.h b/libc/src/stdbit/stdc_first_trailing_one_ull.h
new file mode 100644
index 00000000000000..3e12a1d7456691
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_one_ull.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_first_trailing_one_ull --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_ULL_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_ULL_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned stdc_first_trailing_one_ull(unsigned long long value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_ULL_H
diff --git a/libc/src/stdbit/stdc_first_trailing_one_us.cpp b/libc/src/stdbit/stdc_first_trailing_one_us.cpp
new file mode 100644
index 00000000000000..e4c88e0d7906b9
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_one_us.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of stdc_first_trailing_one_us ----------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdbit/stdc_first_trailing_one_us.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned, stdc_first_trailing_one_us,
+ (unsigned short value)) {
+ return static_cast<unsigned>(cpp::first_trailing_one(value));
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_first_trailing_one_us.h b/libc/src/stdbit/stdc_first_trailing_one_us.h
new file mode 100644
index 00000000000000..f380898fc68cde
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_one_us.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_first_trailing_one_us ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_US_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_US_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned stdc_first_trailing_one_us(unsigned short value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ONE_US_H
diff --git a/libc/src/stdbit/stdc_first_trailing_zero_uc.cpp b/libc/src/stdbit/stdc_first_trailing_zero_uc.cpp
new file mode 100644
index 00000000000000..5825d5d441c591
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_zero_uc.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of stdc_first_trailing_zero_uc ---------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/stdbit/stdc_first_trailing_zero_uc.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned, stdc_first_trailing_zero_uc,
+ (unsigned char value)) {
+ return static_cast<unsigned>(cpp::first_trailing_zero(value));
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_first_trailing_zero_uc.h b/libc/src/stdbit/stdc_first_trailing_zero_uc.h
new file mode 100644
index 00000000000000..242472ae34f2e6
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_zero_uc.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_first_trailing_zero_uc ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ZERO_UC_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ZERO_UC_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned stdc_first_trailing_zero_uc(unsigned char value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_FIRST_TRAILING_ZERO_UC_H
diff --git a/libc/src/stdbit/stdc_first_trailing_zero_ui.cpp b/libc/src/stdbit/stdc_first_trailing_zero_ui.cpp
new file mode 100644
index 00000000000000..3b51b5fa22c324
--- /dev/null
+++ b/libc/src/stdbit/stdc_first_trailing_zero_ui.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of stdc_first_trailing_zero_ui ---------------------===//
+//
+// Part of the LL...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/81768
More information about the libc-commits
mailing list