[libc-commits] [libc] [libc][stdbit][c23] adds implementation of `stdc_bit_ceil` functions (PR #84657)

via libc-commits libc-commits at lists.llvm.org
Sat Mar 9 15:26:56 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Michael Flanders (Flandini)

<details>
<summary>Changes</summary>

Closes #<!-- -->84652.

Based on #<!-- -->84233.

---

Patch is 23.32 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/84657.diff


23 Files Affected:

- (modified) libc/config/linux/x86_64/entrypoints.txt (+5) 
- (modified) libc/docs/stdbit.rst (+6-6) 
- (modified) libc/include/llvm-libc-macros/stdbit-macros.h (+22) 
- (modified) libc/spec/stdc.td (+8-2) 
- (modified) libc/src/__support/CPP/bit.h (+1-1) 
- (modified) libc/src/stdbit/CMakeLists.txt (+1) 
- (added) libc/src/stdbit/stdc_bit_ceil_uc.cpp (+20) 
- (added) libc/src/stdbit/stdc_bit_ceil_uc.h (+18) 
- (added) libc/src/stdbit/stdc_bit_ceil_ui.cpp (+20) 
- (added) libc/src/stdbit/stdc_bit_ceil_ui.h (+18) 
- (added) libc/src/stdbit/stdc_bit_ceil_ul.cpp (+20) 
- (added) libc/src/stdbit/stdc_bit_ceil_ul.h (+18) 
- (added) libc/src/stdbit/stdc_bit_ceil_ull.cpp (+21) 
- (added) libc/src/stdbit/stdc_bit_ceil_ull.h (+18) 
- (added) libc/src/stdbit/stdc_bit_ceil_us.cpp (+20) 
- (added) libc/src/stdbit/stdc_bit_ceil_us.h (+18) 
- (modified) libc/test/include/stdbit_test.cpp (+17) 
- (modified) libc/test/src/stdbit/CMakeLists.txt (+1) 
- (added) libc/test/src/stdbit/stdc_bit_ceil_uc_test.cpp (+34) 
- (added) libc/test/src/stdbit/stdc_bit_ceil_ui_test.cpp (+33) 
- (added) libc/test/src/stdbit/stdc_bit_ceil_ul_test.cpp (+33) 
- (added) libc/test/src/stdbit/stdc_bit_ceil_ull_test.cpp (+33) 
- (added) libc/test/src/stdbit/stdc_bit_ceil_us_test.cpp (+34) 


``````````diff
diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt
index 0880c372b37390..41b051ec914bfb 100644
--- a/libc/config/linux/x86_64/entrypoints.txt
+++ b/libc/config/linux/x86_64/entrypoints.txt
@@ -158,6 +158,11 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.stdbit.stdc_bit_floor_ui
     libc.src.stdbit.stdc_bit_floor_ul
     libc.src.stdbit.stdc_bit_floor_ull
+    libc.src.stdbit.stdc_bit_ceil_uc
+    libc.src.stdbit.stdc_bit_ceil_us
+    libc.src.stdbit.stdc_bit_ceil_ui
+    libc.src.stdbit.stdc_bit_ceil_ul
+    libc.src.stdbit.stdc_bit_ceil_ull
 
     # stdlib.h entrypoints
     libc.src.stdlib.abs
diff --git a/libc/docs/stdbit.rst b/libc/docs/stdbit.rst
index 3ec46cf8d8ffa4..9b4974cf1479b1 100644
--- a/libc/docs/stdbit.rst
+++ b/libc/docs/stdbit.rst
@@ -96,11 +96,11 @@ stdc_bit_floor_us            |check|
 stdc_bit_floor_ui            |check|
 stdc_bit_floor_ul            |check|
 stdc_bit_floor_ull           |check|
-stdc_bit_ceil_uc
-stdc_bit_ceil_us
-stdc_bit_ceil_ui
-stdc_bit_ceil_ul
-stdc_bit_ceil_ull
+stdc_bit_ceil_uc             |check|
+stdc_bit_ceil_us             |check|
+stdc_bit_ceil_ui             |check|
+stdc_bit_ceil_ul             |check|
+stdc_bit_ceil_ull            |check|
 ============================ =========
 
 
@@ -127,7 +127,7 @@ stdc_count_ones            |check|
 stdc_has_single_bit        |check|
 stdc_bit_width             |check|
 stdc_bit_floor             |check|
-stdc_bit_ceil
+stdc_bit_ceil              |check|
 =========================  =========
 
 Standards
diff --git a/libc/include/llvm-libc-macros/stdbit-macros.h b/libc/include/llvm-libc-macros/stdbit-macros.h
index 5b51068f866b71..50ce272860290f 100644
--- a/libc/include/llvm-libc-macros/stdbit-macros.h
+++ b/libc/include/llvm-libc-macros/stdbit-macros.h
@@ -194,6 +194,21 @@ inline unsigned long stdc_bit_floor(unsigned long x) {
 inline unsigned long long stdc_bit_floor(unsigned long long x) {
   return stdc_bit_floor_ull(x);
 }
+inline unsigned char stdc_bit_ceil(unsigned char x) {
+  return stdc_bit_ceil_uc(x);
+}
+inline unsigned short stdc_bit_ceil(unsigned short x) {
+  return stdc_bit_ceil_us(x);
+}
+inline unsigned stdc_bit_ceil(unsigned x) {
+  return stdc_bit_ceil_ui(x);
+}
+inline unsigned long stdc_bit_ceil(unsigned long x) {
+  return stdc_bit_ceil_ul(x);
+}
+inline unsigned long long stdc_bit_ceil(unsigned long long x) {
+  return stdc_bit_ceil_ull(x);
+}
 #else
 #define stdc_leading_zeros(x)                                                  \
   _Generic((x),                                                                \
@@ -286,6 +301,13 @@ inline unsigned long long stdc_bit_floor(unsigned long long x) {
       unsigned: stdc_bit_floor_ui,                                             \
       unsigned long: stdc_bit_floor_ul,                                        \
       unsigned long long: stdc_bit_floor_ull)(x)
+#define stdc_bit_ceil(x)
+  _Generic((x),                                                                \
+      unsigned char: stdc_bit_ceil_ui,                                         \
+      unsigned short: stdc_bit_ceil_us,                                        \
+      unsigned: stdc_bit_ceil_ui,                                              \
+      unsigned long: stdc_bit_ceil_ul,                                         \
+      unsigned long long: stdc_bit_ceil_ull)(x)
 #endif // __cplusplus
 
 #endif // __LLVM_LIBC_MACROS_STDBIT_MACROS_H
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index cc845a93a3330b..b15857dfa8acf8 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -815,7 +815,8 @@ def StdC : StandardSpec<"stdc"> {
         Macro<"stdc_count_ones">,
         Macro<"stdc_has_single_bit">,
         Macro<"std_bit_width">,
-        Macro<"std_bit_floor">
+        Macro<"std_bit_floor">,
+        Macro<"std_bit_ceil">
       ], // Macros
       [], // Types
       [], // Enumerations
@@ -879,7 +880,12 @@ def StdC : StandardSpec<"stdc"> {
           FunctionSpec<"stdc_bit_floor_us", RetValSpec<UnsignedShortType>, [ArgSpec<UnsignedShortType>]>,
           FunctionSpec<"stdc_bit_floor_ui", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedIntType>]>,
           FunctionSpec<"stdc_bit_floor_ul", RetValSpec<UnsignedLongType>, [ArgSpec<UnsignedLongType>]>,
-          FunctionSpec<"stdc_bit_floor_ull", RetValSpec<UnsignedLongLongType>, [ArgSpec<UnsignedLongLongType>]>
+          FunctionSpec<"stdc_bit_floor_ull", RetValSpec<UnsignedLongLongType>, [ArgSpec<UnsignedLongLongType>]>,
+          FunctionSpec<"stdc_bit_ceil_uc", RetValSpec<UnsignedCharType>, [ArgSpec<UnsignedCharType>]>,
+          FunctionSpec<"stdc_bit_ceil_us", RetValSpec<UnsignedShortType>, [ArgSpec<UnsignedShortType>]>,
+          FunctionSpec<"stdc_bit_ceil_ui", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedIntType>]>,
+          FunctionSpec<"stdc_bit_ceil_ul", RetValSpec<UnsignedLongType>, [ArgSpec<UnsignedLongType>]>,
+          FunctionSpec<"stdc_bit_ceil_ull", RetValSpec<UnsignedLongLongType>, [ArgSpec<UnsignedLongLongType>]>
       ] // Functions
   >;
 
diff --git a/libc/src/__support/CPP/bit.h b/libc/src/__support/CPP/bit.h
index 9c74a346949f0c..4464703e4b064e 100644
--- a/libc/src/__support/CPP/bit.h
+++ b/libc/src/__support/CPP/bit.h
@@ -193,7 +193,7 @@ template <typename T>
 bit_ceil(T value) {
   if (value < 2)
     return 1;
-  return T(1) << cpp::bit_width<T>(value - 1u);
+  return static_cast<T>(T(1) << cpp::bit_width<T>(value - 1u));
 }
 
 // Rotate algorithms make use of "Safe, Efficient, and Portable Rotate in C/C++"
diff --git a/libc/src/stdbit/CMakeLists.txt b/libc/src/stdbit/CMakeLists.txt
index 7ab4fee4454a15..2aef2029f2df0b 100644
--- a/libc/src/stdbit/CMakeLists.txt
+++ b/libc/src/stdbit/CMakeLists.txt
@@ -12,6 +12,7 @@ set(prefixes
   has_single_bit
   bit_width
   bit_floor
+  bit_ceil
 )
 set(suffixes c s i l ll)
 foreach(prefix IN LISTS prefixes)
diff --git a/libc/src/stdbit/stdc_bit_ceil_uc.cpp b/libc/src/stdbit/stdc_bit_ceil_uc.cpp
new file mode 100644
index 00000000000000..675ae4a0edb021
--- /dev/null
+++ b/libc/src/stdbit/stdc_bit_ceil_uc.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of stdc_bit_ceil_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_bit_ceil_uc.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned char, stdc_bit_ceil_uc, (unsigned char value)) {
+  return cpp::bit_ceil(value);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_bit_ceil_uc.h b/libc/src/stdbit/stdc_bit_ceil_uc.h
new file mode 100644
index 00000000000000..204261e4108121
--- /dev/null
+++ b/libc/src/stdbit/stdc_bit_ceil_uc.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_bit_ceil_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_BIT_CEIL_UC_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_BIT_CEIL_UC_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned char stdc_bit_ceil_uc(unsigned char value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_BIT_CEIL_UC_H
diff --git a/libc/src/stdbit/stdc_bit_ceil_ui.cpp b/libc/src/stdbit/stdc_bit_ceil_ui.cpp
new file mode 100644
index 00000000000000..a8ac9726179bc7
--- /dev/null
+++ b/libc/src/stdbit/stdc_bit_ceil_ui.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of stdc_bit_ceil_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_bit_ceil_ui.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned, stdc_bit_ceil_ui, (unsigned value)) {
+  return cpp::bit_ceil(value);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_bit_ceil_ui.h b/libc/src/stdbit/stdc_bit_ceil_ui.h
new file mode 100644
index 00000000000000..db66c336e36624
--- /dev/null
+++ b/libc/src/stdbit/stdc_bit_ceil_ui.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_bit_ceil_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_BIT_CEIL_UI_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_BIT_CEIL_UI_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned stdc_bit_ceil_ui(unsigned value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_BIT_CEIL_UI_H
diff --git a/libc/src/stdbit/stdc_bit_ceil_ul.cpp b/libc/src/stdbit/stdc_bit_ceil_ul.cpp
new file mode 100644
index 00000000000000..18a9c38b5b4cf6
--- /dev/null
+++ b/libc/src/stdbit/stdc_bit_ceil_ul.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of stdc_bit_ceil_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_bit_ceil_ul.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned long, stdc_bit_ceil_ul, (unsigned long value)) {
+  return cpp::bit_ceil(value);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_bit_ceil_ul.h b/libc/src/stdbit/stdc_bit_ceil_ul.h
new file mode 100644
index 00000000000000..f8393a42fcbfc1
--- /dev/null
+++ b/libc/src/stdbit/stdc_bit_ceil_ul.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_bit_ceil_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_BIT_CEIL_UL_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_BIT_CEIL_UL_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned long stdc_bit_ceil_ul(unsigned long value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_BIT_CEIL_UL_H
diff --git a/libc/src/stdbit/stdc_bit_ceil_ull.cpp b/libc/src/stdbit/stdc_bit_ceil_ull.cpp
new file mode 100644
index 00000000000000..8d97ba05c72ff1
--- /dev/null
+++ b/libc/src/stdbit/stdc_bit_ceil_ull.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of stdc_bit_ceil_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_bit_ceil_ull.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned long long, stdc_bit_ceil_ull,
+		   (unsigned long long value)) {
+  return cpp::bit_ceil(value);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_bit_ceil_ull.h b/libc/src/stdbit/stdc_bit_ceil_ull.h
new file mode 100644
index 00000000000000..e65f537efb172f
--- /dev/null
+++ b/libc/src/stdbit/stdc_bit_ceil_ull.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_bit_ceil_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_BIT_CEIL_ULL_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_BIT_CEIL_ULL_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned long long stdc_bit_ceil_ull(unsigned long long value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_BIT_CEIL_ULL_H
diff --git a/libc/src/stdbit/stdc_bit_ceil_us.cpp b/libc/src/stdbit/stdc_bit_ceil_us.cpp
new file mode 100644
index 00000000000000..f86a216bb840e9
--- /dev/null
+++ b/libc/src/stdbit/stdc_bit_ceil_us.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of stdc_bit_ceil_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_bit_ceil_us.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned short, stdc_bit_ceil_us, (unsigned short value)) {
+  return cpp::bit_ceil(value);
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_bit_ceil_us.h b/libc/src/stdbit/stdc_bit_ceil_us.h
new file mode 100644
index 00000000000000..16a14e51b74334
--- /dev/null
+++ b/libc/src/stdbit/stdc_bit_ceil_us.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_bit_ceil_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_BIT_CEIL_US_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_BIT_CEIL_US_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned short stdc_bit_ceil_us(unsigned short value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_BIT_CEIL_US_H
diff --git a/libc/test/include/stdbit_test.cpp b/libc/test/include/stdbit_test.cpp
index 20820d52fbdede..6c12665c4454d0 100644
--- a/libc/test/include/stdbit_test.cpp
+++ b/libc/test/include/stdbit_test.cpp
@@ -98,6 +98,13 @@ unsigned long stdc_bit_floor_ul(unsigned long) noexcept { return 0x5DU; }
 unsigned long long stdc_bit_floor_ull(unsigned long long) noexcept {
   return 0x5EU;
 }
+unsigned char stdc_bit_ceil_uc(unsigned char) noexcept { return 0x6AU; }
+unsigned short stdc_bit_ceil_us(unsigned short) noexcept { return 0x6BU; }
+unsigned stdc_bit_ceil_ui(unsigned) noexcept { return 0x6CU; }
+unsigned long stdc_bit_ceil_ul(unsigned long) noexcept { return 0x6DU; }
+unsigned long long stdc_bit_ceil_ull(unsigned long long) noexcept {
+  return 0x6EU;
+}
 }
 
 #include "include/llvm-libc-macros/stdbit-macros.h"
@@ -207,3 +214,13 @@ TEST(LlvmLibcStdbitTest, TypeGenericMacroBitFloor) {
   EXPECT_EQ(stdc_bit_floor(0UL), 0x5DUL);
   EXPECT_EQ(stdc_bit_floor(0ULL), 0x5EULL);
 }
+
+TEST(LlvmLibcStdbitTest, TypeGenericMacroBitCeil) {
+  EXPECT_EQ(stdc_bit_ceil(static_cast<unsigned char>(0U)),
+            static_cast<unsigned char>(0x6AU));
+  EXPECT_EQ(stdc_bit_ceil(static_cast<unsigned short>(0U)),
+            static_cast<unsigned short>(0x6BU));
+  EXPECT_EQ(stdc_bit_ceil(0U), 0x6CU);
+  EXPECT_EQ(stdc_bit_ceil(0UL), 0x6DUL);
+  EXPECT_EQ(stdc_bit_ceil(0ULL), 0x6EULL);
+}
diff --git a/libc/test/src/stdbit/CMakeLists.txt b/libc/test/src/stdbit/CMakeLists.txt
index 3aed56c0e92380..c3f8059d2d9b2a 100644
--- a/libc/test/src/stdbit/CMakeLists.txt
+++ b/libc/test/src/stdbit/CMakeLists.txt
@@ -14,6 +14,7 @@ set(prefixes
   has_single_bit
   bit_width
   bit_floor
+  bit_ceil
 )
 set(suffixes c s i l ll)
 foreach(prefix IN LISTS prefixes)
diff --git a/libc/test/src/stdbit/stdc_bit_ceil_uc_test.cpp b/libc/test/src/stdbit/stdc_bit_ceil_uc_test.cpp
new file mode 100644
index 00000000000000..a6c62e0a5dd44e
--- /dev/null
+++ b/libc/test/src/stdbit/stdc_bit_ceil_uc_test.cpp
@@ -0,0 +1,34 @@
+//===-- Unittests for stdc_bit_ceil_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/__support/CPP/limits.h"
+#include "src/stdbit/stdc_bit_ceil_uc.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcStdcBitceilUcTest, Zero) {
+  EXPECT_EQ(LIBC_NAMESPACE::stdc_bit_ceil_uc(0U),
+            static_cast<unsigned char>(1));
+}
+
+TEST(LlvmLibcStdcBitceilUcTest, Ones) {
+  for (unsigned i = 0U; i != UCHAR_WIDTH; ++i)
+    EXPECT_EQ(LIBC_NAMESPACE::stdc_bit_ceil_uc(1U << i),
+              static_cast<unsigned char>(1U << i));
+}
+
+TEST(LlvmLibcStdcBitceilUcTest, OneLessThanPowsTwo) {
+  for (unsigned i = 2U; i != UCHAR_WIDTH; ++i)
+    EXPECT_EQ(LIBC_NAMESPACE::stdc_bit_ceil_uc((1U << i) - 1),
+              static_cast<unsigned char>(1U << i));
+}
+
+TEST(LlvmLibcStdcBitceilUcTest, OneMoreThanPowsTwo) {
+  for (unsigned i = 2U; i != UCHAR_WIDTH; ++i)
+    EXPECT_EQ(LIBC_NAMESPACE::stdc_bit_ceil_uc((1U << i) + 1),
+              static_cast<unsigned char>(1U << (i + 1)));
+}
diff --git a/libc/test/src/stdbit/stdc_bit_ceil_ui_test.cpp b/libc/test/src/stdbit/stdc_bit_ceil_ui_test.cpp
new file mode 100644
index 00000000000000..82015a342aa9a0
--- /dev/null
+++ b/libc/test/src/stdbit/stdc_bit_ceil_ui_test.cpp
@@ -0,0 +1,33 @@
+//===-- Unittests for stdc_bit_ceil_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/__support/CPP/limits.h"
+#include "src/stdbit/stdc_bit_ceil_ui.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcStdcBitceilUiTest, Zero) {
+  EXPECT_EQ(LIBC_NAMESPACE::stdc_bit_ceil_ui(0U), 1U);
+}
+
+TEST(LlvmLibcStdcBitceilUiTest, Ones) {
+  for (unsigned i = 0U; i != UINT_WIDTH; ++i)
+    EXPECT_EQ(LIBC_NAMESPACE::stdc_bit_ceil_ui(1U << i),
+              1U << i);
+}
+
+TEST(LlvmLibcStdcBitceilUiTest, OneLessThanPowsTwo) {
+  for (unsigned i = 2U; i != UINT_WIDTH; ++i)
+    EXPECT_EQ(LIBC_NAMESPACE::stdc_bit_ceil_ui((1U << i) - 1),
+              1U << i);
+}
+
+TEST(LlvmLibcStdcBitceilUiTest, OneMoreThanPowsTwo) {
+  for (unsigned i = 2U; i != UINT_WIDTH; ++i)
+    EXPECT_EQ(LIBC_NAMESPACE::stdc_bit_ceil_ui((1U << i) + 1),
+              1U << (i + 1));
+}
diff --git a/libc/test/src/stdbit/stdc_bit_ceil_ul_test.cpp b/libc/test/src/stdbit/stdc_bit_ceil_ul_test.cpp
new file mode 100644
index 00000000000000..aa70596946e245
--- /dev/null
+++ b/libc/test/src/stdbit/stdc_bit_ceil_ul_test.cpp
@@ -0,0 +1,33 @@
+//===-- Unittests for stdc_bit_ceil_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/__support/CPP/limits.h"
+#include "src/stdbit/stdc_bit_ceil_ul.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcStdcBitceilUlTest, Zero) {
+  EXPECT_EQ(LIBC_NAMESPACE::stdc_bit_ceil_ul(0UL), 1UL);
+}
+
+TEST(LlvmLibcStdcBitceilUlTest, Ones) {
+  for (unsigned i = 0U; i != ULONG_WIDTH; ++i)
+    EXPECT_EQ(LIBC_NAMESPACE::stdc_bit_ceil_ul(1UL << i),
+              1UL << i);
+}
+
+TEST(...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/84657


More information about the libc-commits mailing list