-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[reland][libc][NFC] Remove __support/bit.h and use __support/CPP/bit.h instead (#73939) #74446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gchatelet
merged 1 commit into
llvm:main
from
gchatelet:reland_b14094885077fb10ae688a4cae85f7cfee795fb3
Dec 5, 2023
Merged
[reland][libc][NFC] Remove __support/bit.h and use __support/CPP/bit.h instead (#73939) #74446
gchatelet
merged 1 commit into
llvm:main
from
gchatelet:reland_b14094885077fb10ae688a4cae85f7cfee795fb3
Dec 5, 2023
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-libc Author: Guillaume Chatelet (gchatelet) ChangesPatch is 47.55 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/74446.diff 32 Files Affected:
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index d6dbad661cb73..502bf72ae9906 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -135,13 +135,13 @@ add_header_library(
.str_to_num_result
.uint128
libc.src.__support.common
+ libc.src.__support.CPP.bit
libc.src.__support.CPP.limits
libc.src.__support.CPP.optional
libc.src.__support.FPUtil.dyadic_float
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.rounding_mode
- libc.src.__support.bit
libc.src.errno.errno
)
@@ -188,10 +188,10 @@ add_header_library(
HDRS
integer_utils.h
DEPENDS
- .bit
.math_extras
.number_pair
libc.src.__support.common
+ libc.src.__support.CPP.bit
libc.src.__support.CPP.type_traits
)
@@ -200,11 +200,11 @@ add_header_library(
HDRS
UInt.h
DEPENDS
- .bit
.integer_utils
.math_extras
.number_pair
libc.src.__support.CPP.array
+ libc.src.__support.CPP.bit
libc.src.__support.CPP.type_traits
libc.src.__support.macros.optimization
)
@@ -231,8 +231,9 @@ add_header_library(
HDRS
hash.h
DEPENDS
- .bit
.uint128
+ libc.src.__support.CPP.bit
+ libc.src.__support.CPP.limits
libc.src.__support.macros.attributes
)
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index 58a182eaa797b..3d6d712fc2058 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -41,7 +41,6 @@ add_header_library(
libc.src.__support.common
libc.src.__support.CPP.bit
libc.src.__support.CPP.type_traits
- libc.src.__support.bit
)
add_header_library(
@@ -146,7 +145,6 @@ add_header_library(
libc.src.__support.common
libc.src.__support.CPP.bit
libc.src.__support.CPP.type_traits
- libc.src.__support.bit
libc.src.__support.uint128
)
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index f5b73440de215..ca98aa7126249 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -11,7 +11,6 @@
#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/type_traits.h"
-#include "src/__support/bit.h"
#include "src/__support/common.h"
#include "src/__support/macros/attributes.h" // LIBC_INLINE
@@ -222,7 +221,7 @@ template <typename T> struct FPBits {
LIBC_INLINE static constexpr FPBits<T> make_value(UIntType number, int ep) {
FPBits<T> result;
// offset: +1 for sign, but -1 for implicit first bit
- int lz = unsafe_clz(number) - FloatProp::EXPONENT_WIDTH;
+ int lz = cpp::countl_zero(number) - FloatProp::EXPONENT_WIDTH;
number <<= lz;
ep -= lz;
diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h
index db2a62fbdf2a1..8a6eb4b920acd 100644
--- a/libc/src/__support/FPUtil/Hypot.h
+++ b/libc/src/__support/FPUtil/Hypot.h
@@ -16,7 +16,6 @@
#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/UInt128.h"
-#include "src/__support/bit.h"
#include "src/__support/common.h"
namespace LIBC_NAMESPACE {
@@ -28,7 +27,7 @@ template <typename T>
LIBC_INLINE T find_leading_one(T mant, int &shift_length) {
shift_length = 0;
if (mant > 0) {
- shift_length = (sizeof(mant) * 8) - 1 - unsafe_clz(mant);
+ shift_length = (sizeof(mant) * 8) - 1 - cpp::countl_zero(mant);
}
return T(1) << shift_length;
}
@@ -37,9 +36,13 @@ LIBC_INLINE T find_leading_one(T mant, int &shift_length) {
template <typename T> struct DoubleLength;
-template <> struct DoubleLength<uint16_t> { using Type = uint32_t; };
+template <> struct DoubleLength<uint16_t> {
+ using Type = uint32_t;
+};
-template <> struct DoubleLength<uint32_t> { using Type = uint64_t; };
+template <> struct DoubleLength<uint32_t> {
+ using Type = uint64_t;
+};
template <> struct DoubleLength<uint64_t> {
using Type = UInt128;
diff --git a/libc/src/__support/FPUtil/generic/CMakeLists.txt b/libc/src/__support/FPUtil/generic/CMakeLists.txt
index c799d502b47d6..b17f325210473 100644
--- a/libc/src/__support/FPUtil/generic/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/generic/CMakeLists.txt
@@ -11,7 +11,6 @@ add_header_library(
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.rounding_mode
- libc.src.__support.bit
libc.src.__support.uint128
)
@@ -21,13 +20,13 @@ add_header_library(
FMA.h
DEPENDS
libc.src.__support.common
+ libc.src.__support.CPP.bit
libc.src.__support.CPP.type_traits
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.float_properties
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.rounding_mode
libc.src.__support.macros.optimization
- libc.src.__support.bit
libc.src.__support.uint128
)
@@ -37,12 +36,12 @@ add_header_library(
FMod.h
DEPENDS
libc.src.__support.common
+ libc.src.__support.CPP.bit
libc.src.__support.CPP.type_traits
libc.src.__support.FPUtil.fenv_impl
libc.src.__support.FPUtil.float_properties
libc.src.__support.FPUtil.fp_bits
libc.src.__support.FPUtil.rounding_mode
libc.src.__support.macros.optimization
- libc.src.__support.bit
libc.src.math.generic.math_utils
)
diff --git a/libc/src/__support/FPUtil/generic/FMA.h b/libc/src/__support/FPUtil/generic/FMA.h
index 5a856d1447330..4a825f2f4942c 100644
--- a/libc/src/__support/FPUtil/generic/FMA.h
+++ b/libc/src/__support/FPUtil/generic/FMA.h
@@ -9,13 +9,13 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_GENERIC_FMA_H
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_GENERIC_FMA_H
+#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/FloatProperties.h"
#include "src/__support/FPUtil/rounding_mode.h"
#include "src/__support/UInt128.h"
-#include "src/__support/bit.h"
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
@@ -209,9 +209,9 @@ template <> LIBC_INLINE double fma<double>(double x, double y, double z) {
// Normalize the result.
if (prod_mant != 0) {
uint64_t prod_hi = static_cast<uint64_t>(prod_mant >> 64);
- int lead_zeros = prod_hi
- ? unsafe_clz(prod_hi)
- : 64 + unsafe_clz(static_cast<uint64_t>(prod_mant));
+ int lead_zeros =
+ prod_hi ? cpp::countl_zero(prod_hi)
+ : 64 + cpp::countl_zero(static_cast<uint64_t>(prod_mant));
// Move the leading 1 to the most significant bit.
prod_mant <<= lead_zeros;
// The lower 64 bits are always sticky bits after moving the leading 1 to
diff --git a/libc/src/__support/FPUtil/generic/FMod.h b/libc/src/__support/FPUtil/generic/FMod.h
index 6f934cd4a87bd..0e71b039d5c06 100644
--- a/libc/src/__support/FPUtil/generic/FMod.h
+++ b/libc/src/__support/FPUtil/generic/FMod.h
@@ -9,11 +9,11 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_GENERIC_FMOD_H
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_GENERIC_FMOD_H
+#include "src/__support/CPP/bit.h"
#include "src/__support/CPP/limits.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
-#include "src/__support/bit.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/math/generic/math_utils.h"
@@ -229,7 +229,7 @@ class FMod {
if (LIBC_LIKELY(sx.uintval() <= sy.uintval())) {
if (sx.uintval() < sy.uintval())
- return sx; // |x|<|y| return x
+ return sx; // |x|<|y| return x
return FPB(FPB::zero()); // |x|=|y| return 0.0
}
@@ -264,11 +264,11 @@ class FMod {
e_y--;
} else {
m_y = sy.get_mantissa();
- lead_zeros_m_y = unsafe_clz(m_y);
+ lead_zeros_m_y = cpp::countl_zero(m_y);
}
// Assume hy != 0
- int tail_zeros_m_y = unsafe_ctz(m_y);
+ int tail_zeros_m_y = cpp::countr_zero(m_y);
int sides_zeroes_count = lead_zeros_m_y + tail_zeros_m_y;
// n > 0 by conditions above
int exp_diff = e_x - e_y;
diff --git a/libc/src/__support/FPUtil/generic/sqrt.h b/libc/src/__support/FPUtil/generic/sqrt.h
index b93fa7a35f826..6ae2171bacf7b 100644
--- a/libc/src/__support/FPUtil/generic/sqrt.h
+++ b/libc/src/__support/FPUtil/generic/sqrt.h
@@ -10,13 +10,12 @@
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_GENERIC_SQRT_H
#include "sqrt_80_bit_long_double.h"
-#include "src/__support/CPP/bit.h"
+#include "src/__support/CPP/bit.h" // countl_zero
#include "src/__support/CPP/type_traits.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/rounding_mode.h"
#include "src/__support/UInt128.h"
-#include "src/__support/bit.h"
#include "src/__support/common.h"
namespace LIBC_NAMESPACE {
@@ -37,7 +36,7 @@ template <> struct SpecialLongDouble<long double> {
template <typename T>
LIBC_INLINE void normalize(int &exponent,
typename FPBits<T>::UIntType &mantissa) {
- const int shift = unsafe_clz(mantissa) -
+ const int shift = cpp::countl_zero(mantissa) -
(8 * sizeof(mantissa) - 1 - MantissaWidth<T>::VALUE);
exponent -= shift;
mantissa <<= shift;
@@ -52,9 +51,9 @@ LIBC_INLINE void normalize<long double>(int &exponent, uint64_t &mantissa) {
template <>
LIBC_INLINE void normalize<long double>(int &exponent, UInt128 &mantissa) {
const uint64_t hi_bits = static_cast<uint64_t>(mantissa >> 64);
- const int shift = hi_bits
- ? (unsafe_clz(hi_bits) - 15)
- : (unsafe_clz(static_cast<uint64_t>(mantissa)) + 49);
+ const int shift =
+ hi_bits ? (cpp::countl_zero(hi_bits) - 15)
+ : (cpp::countl_zero(static_cast<uint64_t>(mantissa)) + 49);
exponent -= shift;
mantissa <<= shift;
}
@@ -137,7 +136,7 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<T>, T> sqrt(T x) {
// We compute one more iteration in order to round correctly.
bool lsb = static_cast<bool>(y & 1); // Least significant bit
- bool rb = false; // Round bit
+ bool rb = false; // Round bit
r <<= 2;
UIntType tmp = (y << 2) + 1;
if (r >= tmp) {
diff --git a/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
index a3bf7e3cabad3..0e7907e82943a 100644
--- a/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
+++ b/libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
@@ -9,11 +9,11 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_GENERIC_SQRT_80_BIT_LONG_DOUBLE_H
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_GENERIC_SQRT_80_BIT_LONG_DOUBLE_H
+#include "src/__support/CPP/bit.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/FPUtil/FPBits.h"
#include "src/__support/FPUtil/rounding_mode.h"
#include "src/__support/UInt128.h"
-#include "src/__support/bit.h"
#include "src/__support/common.h"
namespace LIBC_NAMESPACE {
@@ -22,7 +22,7 @@ namespace x86 {
LIBC_INLINE void normalize(int &exponent, UInt128 &mantissa) {
const unsigned int shift = static_cast<unsigned int>(
- unsafe_clz(static_cast<uint64_t>(mantissa)) -
+ cpp::countl_zero(static_cast<uint64_t>(mantissa)) -
(8 * sizeof(uint64_t) - 1 - MantissaWidth<long double>::VALUE));
exponent -= shift;
mantissa <<= shift;
@@ -101,7 +101,7 @@ LIBC_INLINE long double sqrt(long double x) {
// We compute one more iteration in order to round correctly.
bool lsb = static_cast<bool>(y & 1); // Least significant bit
- bool rb = false; // Round bit
+ bool rb = false; // Round bit
r <<= 2;
UIntType tmp = (y << 2) + 1;
if (r >= tmp) {
diff --git a/libc/src/__support/HashTable/CMakeLists.txt b/libc/src/__support/HashTable/CMakeLists.txt
index e9b4aa31290a1..920ba194badd9 100644
--- a/libc/src/__support/HashTable/CMakeLists.txt
+++ b/libc/src/__support/HashTable/CMakeLists.txt
@@ -6,7 +6,7 @@ add_header_library(
PREFER_GENERIC
DEPENDS
libc.src.__support.common
- libc.src.__support.bit
+ libc.src.__support.CPP.bit
libc.src.__support.macros.properties.cpu_features
)
@@ -25,17 +25,17 @@ add_header_library(
table.h
DEPENDS
.bitmask
- libc.src.__support.memory_size
- libc.src.__support.bit
- libc.src.__support.CPP.type_traits
+ libc.include.llvm-libc-types.ENTRY
+ libc.src.__support.CPP.bit
libc.src.__support.CPP.new
+ libc.src.__support.CPP.type_traits
+ libc.src.__support.hash
libc.src.__support.macros.attributes
libc.src.__support.macros.optimization
- libc.src.__support.hash
+ libc.src.__support.memory_size
libc.src.string.memset
libc.src.string.strcmp
libc.src.string.strlen
- libc.include.llvm-libc-types.ENTRY
)
add_header_library(
diff --git a/libc/src/__support/HashTable/bitmask.h b/libc/src/__support/HashTable/bitmask.h
index 38c9860020594..c775b09f2236f 100644
--- a/libc/src/__support/HashTable/bitmask.h
+++ b/libc/src/__support/HashTable/bitmask.h
@@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_HASHTABLE_BITMASK_H
#define LLVM_LIBC_SRC___SUPPORT_HASHTABLE_BITMASK_H
-#include "src/__support/bit.h"
+#include "src/__support/CPP/bit.h"
#include "src/__support/macros/properties/cpu_features.h"
#include <stddef.h> // size_t
#include <stdint.h> // uint8_t, uint64_t
@@ -45,7 +45,7 @@ template <typename T, T WORD_MASK, size_t WORD_STRIDE> struct BitMaskAdaptor {
// Count trailing zeros with respect to stride. (Assume the bitmask is none
// zero.)
LIBC_INLINE constexpr size_t lowest_set_bit_nonzero() const {
- return unsafe_ctz<T>(word) / WORD_STRIDE;
+ return cpp::countr_zero<T>(word) / WORD_STRIDE;
}
};
diff --git a/libc/src/__support/HashTable/table.h b/libc/src/__support/HashTable/table.h
index ec0ec78869ad5..305fe59792d5a 100644
--- a/libc/src/__support/HashTable/table.h
+++ b/libc/src/__support/HashTable/table.h
@@ -10,10 +10,10 @@
#define LLVM_LIBC_SRC___SUPPORT_HASHTABLE_table_H
#include "include/llvm-libc-types/ENTRY.h"
+#include "src/__support/CPP/bit.h" // bit_ceil
#include "src/__support/CPP/new.h"
#include "src/__support/CPP/type_traits.h"
#include "src/__support/HashTable/bitmask.h"
-#include "src/__support/bit.h"
#include "src/__support/hash.h"
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/optimization.h"
@@ -70,7 +70,7 @@ LIBC_INLINE size_t capacity_to_entries(size_t cap) {
if (cap < sizeof(Group))
cap = sizeof(Group);
// overflow is always checked in allocate()
- return next_power_of_two(cap * 8 / 7);
+ return cpp::bit_ceil(cap * 8 / 7);
}
// The heap memory layout for N buckets HashTable is as follows:
@@ -98,7 +98,8 @@ struct HashTable {
LIBC_INLINE size_t offset_from_entries() const {
size_t entries_size = num_of_entries() * sizeof(ENTRY);
- return entries_size + offset_to(entries_size, table_alignment());
+ return entries_size +
+ SafeMemSize::offset_to(entries_size, table_alignment());
}
LIBC_INLINE constexpr static size_t table_alignment() {
diff --git a/libc/src/__support/UInt.h b/libc/src/__support/UInt.h
index 248324c326dfb..3bec2e3a47130 100644
--- a/libc/src/__support/UInt.h
+++ b/libc/src/__support/UInt.h
@@ -10,10 +10,10 @@
#define LLVM_LIBC_SRC___SUPPORT_UINT_H
#include "src/__support/CPP/array.h"
+#include "src/__support/CPP/bit.h" // countl_zero
#include "src/__support/CPP/limits.h"
#include "src/__support/CPP/optional.h"
#include "src/__support/CPP/type_traits.h"
-#include "src/__support/bit.h" // unsafe_clz
#include "src/__support/integer_utils.h"
#include "src/__support/macros/attributes.h" // LIBC_INLINE
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
@@ -557,7 +557,7 @@ template <size_t Bits, bool Signed> struct BigInt {
if (val[i - 1] == 0) {
leading_zeroes += sizeof(uint64_t) * 8;
} else {
- leading_zeroes += unsafe_clz(val[i - 1]);
+ leading_zeroes += countl_zero(val[i - 1]);
break;
}
}
diff --git a/libc/src/__support/bit.h b/libc/src/__support/bit.h
deleted file mode 100644
index ba7fc31de1227..0000000000000
--- a/libc/src/__support/bit.h
+++ /dev/null
@@ -1,117 +0,0 @@
-//===-- Mimics llvm/ADT/Bit.h -----------------------------------*- C++ -*-===//
-// Provides useful bit functions.
-//
-// 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___SUPPORT_BIT_H
-#define LLVM_LIBC_SRC___SUPPORT_BIT_H
-
-#include "src/__support/CPP/type_traits.h" // make_unsigned
-#include "src/__support/macros/attributes.h" // LIBC_INLINE
-
-namespace LIBC_NAMESPACE {
-
-// The following overloads are matched based on what is accepted by
-// __builtin_clz/ctz* rather than using the exactly-sized aliases from stdint.h.
-// This way, we can avoid making any assumptions about integer sizes and let the
-// compiler match for us.
-namespace __internal {
-
-template <typename T> LIBC_INLINE int constexpr correct_zero(T val, int bits) {
- if (val == T(0))
- return sizeof(T(0)) * 8;
- else
- return bits;
-}
-
-template <typename T> LIBC_INLINE constexpr int clz(T val);
-template <> LIBC_INLINE int clz<unsigned char>(unsigned char val) {
- return __builtin_clz(static_cast<unsigned int>(val)) -
- 8 * static_cast<int>(sizeof(unsigned int) - sizeof(unsigned char));
-}
-template <> LIBC_INLINE int clz<unsigned short>(unsigned short val) {
- return __builtin_clz(static_cast<unsigned int>(val)) -
- 8 * static_cast<int>(sizeof(unsigned int) - sizeof(unsigned short));
-}
-template <> LIBC_INLINE int clz<unsigned int>(unsigned int val) {
- return __builtin_clz(val);
-}
-template <>
-LIBC_INLINE constexpr int clz<unsigned long int>(unsigned long int val) {
- return __builtin_clzl(val);
-}
-template <>
-LIBC_INLINE constexpr int
-clz<unsigned long long int>(unsigned long long int val) {
- return __builtin_clzll(val);
-}
-
-template <typename T> LIBC_INLINE constexpr int ctz(T val);
-template <> LIBC_INLINE int ctz<unsigned char>(unsigned char val) {
- return __builtin_ctz(static_cast<unsigned int>(val));
-}
-template <> LIBC_INLINE int ctz<unsigned short>(unsigned short val) {
- return __builtin_ctz(static_cast<unsigned int>(val));
-}
-template <> LIBC_INLINE int ctz<unsigned int>(unsigned int val) {
- return __builtin_ctz(val);
-}
-template <>
-LIBC_INLINE constexpr int ctz<unsigned long int>(unsigned long int val) {
- return __builtin_ctzl(val);
-}
-template <>
-LIBC_INLINE constexpr int
-ctz<unsigned long long int>(unsigned long long int val) {
- return __builtin_ctzll(val);
-}
-} // namespace __internal
-
-template <typename T> LIBC_INLINE constexpr int safe_ctz(T val) {
- return __internal::correct_zero(val, __internal::ctz(val));
-}
-
-template <typename T> LIBC_INLINE constexpr int unsafe_ctz(T val) {
- return __internal::ctz(val);
-}
-
-template <typename T> LIBC_INLINE constexpr int safe_clz(T val) {
- return __internal::correct_zero(val, __internal::clz(val));
-}
-
-template <typename T> LIBC_INLINE constexpr int unsafe_clz(T val) {
- return __internal::clz(val);
-}
-
-template <typename T> LIBC_INLINE constexpr T next_power_of_two(T val) {
- if (val == 0)
- return 1;
- T idx = safe_clz(val - 1);
- return static_cast<T>(1) << ((8ull * sizeof(T)) - idx);
-}
-
-template <typename T> LIBC_INLINE constexpr bool is_power_of_two(T val) {
- return val != 0 && (val & (val - 1)) == 0;
-}
-
-template <typename T> LIBC_INLINE constexpr T offset_to(T val, T align) {
- return (-val) & (align - 1);
-}
-
-template <typename T> LIBC_INLINE constexpr T rotate_left(T val, T amount) {
- // Implementation taken from "Safe, Efficient, and Portable Rotate in C/C++"
- // https://blog.regehr.org/archives/1063
- // Using the safe version as t...
[truncated]
|
This was referenced Dec 5, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Same as #73939 but also fix
libc/src/string/memory_utils/op_aarch64.h
that was still usingdeferred_static_assert
.