[libc-commits] [libc] [libc][stdbit] implement stdc_first_trailing_zero (C23) (PR #81526)
via libc-commits
libc-commits at lists.llvm.org
Mon Feb 12 12:30:08 PST 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff d2d6b368a17547a847baf2c9767ad8c1686e58d1 be816525a7bb42297c625a58fb55af5e90aa1425 -- libc/src/stdbit/stdc_first_leading_one_uc.cpp libc/src/stdbit/stdc_first_leading_one_uc.h libc/src/stdbit/stdc_first_leading_one_ui.cpp libc/src/stdbit/stdc_first_leading_one_ui.h libc/src/stdbit/stdc_first_leading_one_ul.cpp libc/src/stdbit/stdc_first_leading_one_ul.h libc/src/stdbit/stdc_first_leading_one_ull.cpp libc/src/stdbit/stdc_first_leading_one_ull.h libc/src/stdbit/stdc_first_leading_one_us.cpp libc/src/stdbit/stdc_first_leading_one_us.h libc/src/stdbit/stdc_first_trailing_zero_uc.cpp libc/src/stdbit/stdc_first_trailing_zero_uc.h libc/src/stdbit/stdc_first_trailing_zero_ui.cpp libc/src/stdbit/stdc_first_trailing_zero_ui.h libc/src/stdbit/stdc_first_trailing_zero_ul.cpp libc/src/stdbit/stdc_first_trailing_zero_ul.h libc/src/stdbit/stdc_first_trailing_zero_ull.cpp libc/src/stdbit/stdc_first_trailing_zero_ull.h libc/src/stdbit/stdc_first_trailing_zero_us.cpp libc/src/stdbit/stdc_first_trailing_zero_us.h libc/test/src/stdbit/stdc_first_leading_one_uc_test.cpp libc/test/src/stdbit/stdc_first_leading_one_ui_test.cpp libc/test/src/stdbit/stdc_first_leading_one_ul_test.cpp libc/test/src/stdbit/stdc_first_leading_one_ull_test.cpp libc/test/src/stdbit/stdc_first_leading_one_us_test.cpp libc/test/src/stdbit/stdc_first_trailing_zero_uc_test.cpp libc/test/src/stdbit/stdc_first_trailing_zero_ui_test.cpp libc/test/src/stdbit/stdc_first_trailing_zero_ul_test.cpp libc/test/src/stdbit/stdc_first_trailing_zero_ull_test.cpp libc/test/src/stdbit/stdc_first_trailing_zero_us_test.cpp libc/include/llvm-libc-macros/stdbit-macros.h libc/src/__support/CPP/bit.h libc/test/include/stdbit_test.cpp libc/test/src/__support/CPP/bit_test.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libc/include/llvm-libc-macros/stdbit-macros.h b/libc/include/llvm-libc-macros/stdbit-macros.h
index 19b800f342..0ec8aef10d 100644
--- a/libc/include/llvm-libc-macros/stdbit-macros.h
+++ b/libc/include/llvm-libc-macros/stdbit-macros.h
@@ -159,12 +159,12 @@ inline unsigned stdc_first_trailing_zero(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) \
+#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 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)
#endif // __cplusplus
diff --git a/libc/src/__support/CPP/bit.h b/libc/src/__support/CPP/bit.h
index 596b1fb530..8cacc35d8c 100644
--- a/libc/src/__support/CPP/bit.h
+++ b/libc/src/__support/CPP/bit.h
@@ -300,9 +300,9 @@ SPECIALIZE_FLO(first_leading_one, unsigned long long, __builtin_clzll)
#define SPECIALIZE_FTZ(NAME, TYPE, BUILTIN) \
template <> [[nodiscard]] LIBC_INLINE constexpr int NAME<TYPE>(TYPE value) { \
static_assert(cpp::is_unsigned_v<TYPE>); \
- return value == cpp::numeric_limits<TYPE>::max() \
+ return value == cpp::numeric_limits<TYPE>::max() \
? 0 \
- : BUILTIN(static_cast<TYPE>(~value)) + 1; \
+ : BUILTIN(static_cast<TYPE>(~value)) + 1; \
}
template <typename T, typename = cpp::enable_if_t<cpp::is_unsigned_v<T>>>
diff --git a/libc/src/stdbit/stdc_first_trailing_zero_ull.cpp b/libc/src/stdbit/stdc_first_trailing_zero_ull.cpp
index e17df2b40d..bcd5df42c1 100644
--- a/libc/src/stdbit/stdc_first_trailing_zero_ull.cpp
+++ b/libc/src/stdbit/stdc_first_trailing_zero_ull.cpp
@@ -1,4 +1,5 @@
-//===-- Implementation of stdc_first_trailing_zero_ull ---------------------===//
+//===-- Implementation of stdc_first_trailing_zero_ull
+//---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/src/stdbit/stdc_first_trailing_zero_ull.h b/libc/src/stdbit/stdc_first_trailing_zero_ull.h
index 03a0f40026..ad72778064 100644
--- a/libc/src/stdbit/stdc_first_trailing_zero_ull.h
+++ b/libc/src/stdbit/stdc_first_trailing_zero_ull.h
@@ -1,4 +1,5 @@
-//===-- Implementation header for stdc_first_trailing_zero_ull ---*- C++ -*-===//
+//===-- Implementation header for stdc_first_trailing_zero_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.
diff --git a/libc/test/src/stdbit/stdc_first_trailing_zero_uc_test.cpp b/libc/test/src/stdbit/stdc_first_trailing_zero_uc_test.cpp
index 8b0168c76f..1a3a464520 100644
--- a/libc/test/src/stdbit/stdc_first_trailing_zero_uc_test.cpp
+++ b/libc/test/src/stdbit/stdc_first_trailing_zero_uc_test.cpp
@@ -1,4 +1,5 @@
-//===-- Unittests for stdc_first_trailing_zero_uc --------------------------===//
+//===-- Unittests for 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.
diff --git a/libc/test/src/stdbit/stdc_first_trailing_zero_ui_test.cpp b/libc/test/src/stdbit/stdc_first_trailing_zero_ui_test.cpp
index c259d5aee9..da873608ba 100644
--- a/libc/test/src/stdbit/stdc_first_trailing_zero_ui_test.cpp
+++ b/libc/test/src/stdbit/stdc_first_trailing_zero_ui_test.cpp
@@ -1,4 +1,5 @@
-//===-- Unittests for stdc_first_trailing_zero_ui --------------------------===//
+//===-- Unittests for stdc_first_trailing_zero_ui
+//--------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdbit/stdc_first_trailing_zero_ul_test.cpp b/libc/test/src/stdbit/stdc_first_trailing_zero_ul_test.cpp
index 61881a7c21..b97d305c3f 100644
--- a/libc/test/src/stdbit/stdc_first_trailing_zero_ul_test.cpp
+++ b/libc/test/src/stdbit/stdc_first_trailing_zero_ul_test.cpp
@@ -1,4 +1,5 @@
-//===-- Unittests for stdc_first_trailing_zero_ul --------------------------===//
+//===-- Unittests for stdc_first_trailing_zero_ul
+//--------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/stdbit/stdc_first_trailing_zero_ull_test.cpp b/libc/test/src/stdbit/stdc_first_trailing_zero_ull_test.cpp
index 96e7209c0e..6f89711f80 100644
--- a/libc/test/src/stdbit/stdc_first_trailing_zero_ull_test.cpp
+++ b/libc/test/src/stdbit/stdc_first_trailing_zero_ull_test.cpp
@@ -1,4 +1,5 @@
-//===-- Unittests for stdc_first_trailing_zero_ull --------------------------===//
+//===-- Unittests for stdc_first_trailing_zero_ull
+//--------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -16,5 +17,6 @@ TEST(LlvmLibcStdcFirstTrailingZeroUllTest, ALL) {
TEST(LlvmLibcStdcFirstTrailingZeroUllTest, ZeroHot) {
for (unsigned i = 0U; i != ULLONG_WIDTH; ++i)
- EXPECT_EQ(LIBC_NAMESPACE::stdc_first_trailing_zero_ull(~(1ULL << i)), i + 1);
+ EXPECT_EQ(LIBC_NAMESPACE::stdc_first_trailing_zero_ull(~(1ULL << i)),
+ i + 1);
}
diff --git a/libc/test/src/stdbit/stdc_first_trailing_zero_us_test.cpp b/libc/test/src/stdbit/stdc_first_trailing_zero_us_test.cpp
index 792dd502be..4b55af7bd7 100644
--- a/libc/test/src/stdbit/stdc_first_trailing_zero_us_test.cpp
+++ b/libc/test/src/stdbit/stdc_first_trailing_zero_us_test.cpp
@@ -1,4 +1,5 @@
-//===-- Unittests for stdc_first_trailing_zero_us --------------------------===//
+//===-- Unittests for stdc_first_trailing_zero_us
+//--------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
``````````
</details>
https://github.com/llvm/llvm-project/pull/81526
More information about the libc-commits
mailing list