summaryrefslogtreecommitdiff
path: root/libc/src/stdbit
diff options
context:
space:
mode:
authorNick Desaulniers <nickdesaulniers@users.noreply.github.com>2024-02-01 10:14:22 -0800
committerGitHub <noreply@github.com>2024-02-01 10:14:22 -0800
commit6a3fde6d600cccd2ffbede6dd54519036cc4089c (patch)
tree304ae778c6e8f6cede6ff2947b6d689e5829aab6 /libc/src/stdbit
parentecb5a1b0e236a98f59863793b4cfef1f13ea225c (diff)
[libc] implement stdc_leading_ones (C23) (#80082)
Diffstat (limited to 'libc/src/stdbit')
-rw-r--r--libc/src/stdbit/CMakeLists.txt50
-rw-r--r--libc/src/stdbit/stdc_leading_ones_uc.cpp20
-rw-r--r--libc/src/stdbit/stdc_leading_ones_uc.h18
-rw-r--r--libc/src/stdbit/stdc_leading_ones_ui.cpp20
-rw-r--r--libc/src/stdbit/stdc_leading_ones_ui.h18
-rw-r--r--libc/src/stdbit/stdc_leading_ones_ul.cpp20
-rw-r--r--libc/src/stdbit/stdc_leading_ones_ul.h18
-rw-r--r--libc/src/stdbit/stdc_leading_ones_ull.cpp21
-rw-r--r--libc/src/stdbit/stdc_leading_ones_ull.h18
-rw-r--r--libc/src/stdbit/stdc_leading_ones_us.cpp21
-rw-r--r--libc/src/stdbit/stdc_leading_ones_us.h18
11 files changed, 242 insertions, 0 deletions
diff --git a/libc/src/stdbit/CMakeLists.txt b/libc/src/stdbit/CMakeLists.txt
index d72bf8bc42de..d7daff44dfda 100644
--- a/libc/src/stdbit/CMakeLists.txt
+++ b/libc/src/stdbit/CMakeLists.txt
@@ -47,3 +47,53 @@ add_entrypoint_object(
DEPENDS
libc.src.__support.CPP.bit
)
+
+add_entrypoint_object(
+ stdc_leading_ones_uc
+ SRCS
+ stdc_leading_ones_uc.cpp
+ HDRS
+ stdc_leading_ones_uc.h
+ DEPENDS
+ libc.src.__support.CPP.bit
+)
+
+add_entrypoint_object(
+ stdc_leading_ones_us
+ SRCS
+ stdc_leading_ones_us.cpp
+ HDRS
+ stdc_leading_ones_us.h
+ DEPENDS
+ libc.src.__support.CPP.bit
+)
+
+add_entrypoint_object(
+ stdc_leading_ones_ui
+ SRCS
+ stdc_leading_ones_ui.cpp
+ HDRS
+ stdc_leading_ones_ui.h
+ DEPENDS
+ libc.src.__support.CPP.bit
+)
+
+add_entrypoint_object(
+ stdc_leading_ones_ul
+ SRCS
+ stdc_leading_ones_ul.cpp
+ HDRS
+ stdc_leading_ones_ul.h
+ DEPENDS
+ libc.src.__support.CPP.bit
+)
+
+add_entrypoint_object(
+ stdc_leading_ones_ull
+ SRCS
+ stdc_leading_ones_ull.cpp
+ HDRS
+ stdc_leading_ones_ull.h
+ DEPENDS
+ libc.src.__support.CPP.bit
+)
diff --git a/libc/src/stdbit/stdc_leading_ones_uc.cpp b/libc/src/stdbit/stdc_leading_ones_uc.cpp
new file mode 100644
index 000000000000..beae134eeb91
--- /dev/null
+++ b/libc/src/stdbit/stdc_leading_ones_uc.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of stdc_leading_ones_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_leading_ones_uc.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned char, stdc_leading_ones_uc, (unsigned char value)) {
+ return static_cast<unsigned char>(cpp::countl_one(value));
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_ones_uc.h b/libc/src/stdbit/stdc_leading_ones_uc.h
new file mode 100644
index 000000000000..8303f3f7bd26
--- /dev/null
+++ b/libc/src/stdbit/stdc_leading_ones_uc.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_leading_ones_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_LEADING_ONES_UC_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_LEADING_ONES_UC_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned char stdc_leading_ones_uc(unsigned char value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_LEADING_ONES_UC_H
diff --git a/libc/src/stdbit/stdc_leading_ones_ui.cpp b/libc/src/stdbit/stdc_leading_ones_ui.cpp
new file mode 100644
index 000000000000..2a73c2ccfa49
--- /dev/null
+++ b/libc/src/stdbit/stdc_leading_ones_ui.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of stdc_leading_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/stdbit/stdc_leading_ones_ui.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned, stdc_leading_ones_ui, (unsigned value)) {
+ return static_cast<unsigned>(cpp::countl_one(value));
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_ones_ui.h b/libc/src/stdbit/stdc_leading_ones_ui.h
new file mode 100644
index 000000000000..c381eb50e973
--- /dev/null
+++ b/libc/src/stdbit/stdc_leading_ones_ui.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_leading_ones_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_LEADING_ONES_UI_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_LEADING_ONES_UI_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned stdc_leading_ones_ui(unsigned value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_LEADING_ONES_UI_H
diff --git a/libc/src/stdbit/stdc_leading_ones_ul.cpp b/libc/src/stdbit/stdc_leading_ones_ul.cpp
new file mode 100644
index 000000000000..ccfd9b9594e0
--- /dev/null
+++ b/libc/src/stdbit/stdc_leading_ones_ul.cpp
@@ -0,0 +1,20 @@
+//===-- Implementation of stdc_leading_ones_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_leading_ones_ul.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned long, stdc_leading_ones_ul, (unsigned long value)) {
+ return static_cast<unsigned long>(cpp::countl_one(value));
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_ones_ul.h b/libc/src/stdbit/stdc_leading_ones_ul.h
new file mode 100644
index 000000000000..7643bd1ba81d
--- /dev/null
+++ b/libc/src/stdbit/stdc_leading_ones_ul.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_leading_ones_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_LEADING_ONES_UL_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_LEADING_ONES_UL_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned long stdc_leading_ones_ul(unsigned long value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_LEADING_ONES_UL_H
diff --git a/libc/src/stdbit/stdc_leading_ones_ull.cpp b/libc/src/stdbit/stdc_leading_ones_ull.cpp
new file mode 100644
index 000000000000..8cb1ff08c7b0
--- /dev/null
+++ b/libc/src/stdbit/stdc_leading_ones_ull.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of stdc_leading_ones_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_leading_ones_ull.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned long long, stdc_leading_ones_ull,
+ (unsigned long long value)) {
+ return static_cast<unsigned long long>(cpp::countl_one(value));
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_ones_ull.h b/libc/src/stdbit/stdc_leading_ones_ull.h
new file mode 100644
index 000000000000..8ae814510967
--- /dev/null
+++ b/libc/src/stdbit/stdc_leading_ones_ull.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_leading_ones_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_LEADING_ONES_ULL_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_LEADING_ONES_ULL_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned long long stdc_leading_ones_ull(unsigned long long value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_LEADING_ONES_ULL_H
diff --git a/libc/src/stdbit/stdc_leading_ones_us.cpp b/libc/src/stdbit/stdc_leading_ones_us.cpp
new file mode 100644
index 000000000000..4b58cf5cee43
--- /dev/null
+++ b/libc/src/stdbit/stdc_leading_ones_us.cpp
@@ -0,0 +1,21 @@
+//===-- Implementation of stdc_leading_ones_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_leading_ones_us.h"
+
+#include "src/__support/CPP/bit.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+LLVM_LIBC_FUNCTION(unsigned short, stdc_leading_ones_us,
+ (unsigned short value)) {
+ return static_cast<unsigned short>(cpp::countl_one(value));
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_ones_us.h b/libc/src/stdbit/stdc_leading_ones_us.h
new file mode 100644
index 000000000000..583a479f79a8
--- /dev/null
+++ b/libc/src/stdbit/stdc_leading_ones_us.h
@@ -0,0 +1,18 @@
+//===-- Implementation header for stdc_leading_ones_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_LEADING_ONES_US_H
+#define LLVM_LIBC_SRC_STDBIT_STDC_LEADING_ONES_US_H
+
+namespace LIBC_NAMESPACE {
+
+unsigned short stdc_leading_ones_us(unsigned short value);
+
+} // namespace LIBC_NAMESPACE
+
+#endif // LLVM_LIBC_SRC_STDBIT_STDC_LEADING_ONES_US_H