summaryrefslogtreecommitdiff
path: root/libc/test/src/stdbit/stdc_count_ones_ui_test.cpp
diff options
context:
space:
mode:
authorNick Desaulniers <nickdesaulniers@users.noreply.github.com>2024-02-26 09:25:24 -0800
committerGitHub <noreply@github.com>2024-02-26 09:25:24 -0800
commitd8406d48a8c94f88613e5613a7e0d6526a520428 (patch)
tree443501f9a301f383dd73be14007d599a66b7b3c8 /libc/test/src/stdbit/stdc_count_ones_ui_test.cpp
parentbe024307075c37f057fd51d4de0e9c2443b51686 (diff)
[libc][stdbit] implement stdc_count_ones (C23) (#82444)
Diffstat (limited to 'libc/test/src/stdbit/stdc_count_ones_ui_test.cpp')
-rw-r--r--libc/test/src/stdbit/stdc_count_ones_ui_test.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/libc/test/src/stdbit/stdc_count_ones_ui_test.cpp b/libc/test/src/stdbit/stdc_count_ones_ui_test.cpp
new file mode 100644
index 000000000000..198e36658421
--- /dev/null
+++ b/libc/test/src/stdbit/stdc_count_ones_ui_test.cpp
@@ -0,0 +1,21 @@
+//===-- Unittests for stdc_count_ones_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_count_ones_ui.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcStdcCountOnesUiTest, Zero) {
+ EXPECT_EQ(LIBC_NAMESPACE::stdc_count_ones_ui(0), 0U);
+}
+
+TEST(LlvmLibcStdcCountOnesUiTest, Ones) {
+ for (unsigned i = 0U; i != UINT_WIDTH; ++i)
+ EXPECT_EQ(LIBC_NAMESPACE::stdc_count_ones_ui(UINT_MAX >> i),
+ UINT_WIDTH - i);
+}