[libc-commits] [libc] d769cd8 - [reland][libc][NFC] Use STL case for bit

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Fri Aug 19 14:26:40 PDT 2022


Author: Guillaume Chatelet
Date: 2022-08-19T21:26:26Z
New Revision: d769cd8cdc11bb2439bf8d0cb3f079c9e8912fa8

URL: https://github.com/llvm/llvm-project/commit/d769cd8cdc11bb2439bf8d0cb3f079c9e8912fa8
DIFF: https://github.com/llvm/llvm-project/commit/d769cd8cdc11bb2439bf8d0cb3f079c9e8912fa8.diff

LOG: [reland][libc][NFC] Use STL case for bit

Added: 
    libc/src/__support/CPP/bit.h

Modified: 
    libc/src/__support/CPP/CMakeLists.txt
    libc/src/__support/FPUtil/FPBits.h
    libc/src/__support/FPUtil/Hypot.h
    libc/src/__support/FPUtil/ManipulationFunctions.h
    libc/src/__support/FPUtil/generic/FMA.h
    libc/src/__support/FPUtil/generic/sqrt.h
    libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
    libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
    libc/src/math/generic/math_utils.h
    libc/src/stdio/printf_core/parser.cpp
    libc/src/string/memory_utils/elements_x86.h
    libc/test/src/math/NextAfterTest.h
    libc/test/src/math/SqrtTest.h
    libc/test/src/stdio/printf_core/parser_test.cpp
    libc/test/src/string/memory_utils/backend_test.cpp
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    libc/src/__support/CPP/Bit.h


################################################################################
diff  --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt
index cdd6787d2622b..0364bc0df246c 100644
--- a/libc/src/__support/CPP/CMakeLists.txt
+++ b/libc/src/__support/CPP/CMakeLists.txt
@@ -29,7 +29,7 @@ add_header_library(
 add_header_library(
   bit
   HDRS
-    Bit.h
+    bit.h
 )
 
 add_header_library(

diff  --git a/libc/src/__support/CPP/Bit.h b/libc/src/__support/CPP/bit.h
similarity index 96%
rename from libc/src/__support/CPP/Bit.h
rename to libc/src/__support/CPP/bit.h
index 517762788757d..0ff946ca3cc76 100644
--- a/libc/src/__support/CPP/Bit.h
+++ b/libc/src/__support/CPP/bit.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SUPPORT_CPP_BIT_H
 #define LLVM_LIBC_SUPPORT_CPP_BIT_H
 
-namespace __llvm_libc {
+namespace __llvm_libc::cpp {
 
 #if defined __has_builtin
 #if __has_builtin(__builtin_bit_cast)
@@ -43,6 +43,6 @@ template <class To, class From> constexpr To bit_cast(const From &from) {
 #endif // defined(LLVM_LIBC_HAS_BUILTIN_BIT_CAST)
 }
 
-} // namespace __llvm_libc
+} // namespace __llvm_libc::cpp
 
 #endif // LLVM_LIBC_SUPPORT_CPP_BIT_H

diff  --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index c8a9546a73a87..4b2c5132abdf6 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -11,7 +11,7 @@
 
 #include "PlatformDefs.h"
 
-#include "src/__support/CPP/Bit.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/FPUtil/builtin_wrappers.h"
 #include "src/__support/common.h"
@@ -104,8 +104,7 @@ template <typename T> struct FPBits {
   // We don't want accidental type promotions/conversions, so we require exact
   // type match.
   template <typename XType, cpp::enable_if_t<cpp::is_same_v<T, XType>, int> = 0>
-  constexpr explicit FPBits(XType x)
-      : bits(__llvm_libc::bit_cast<UIntType>(x)) {}
+  constexpr explicit FPBits(XType x) : bits(cpp::bit_cast<UIntType>(x)) {}
 
   template <typename XType,
             cpp::enable_if_t<cpp::is_same_v<XType, UIntType>, int> = 0>
@@ -113,9 +112,9 @@ template <typename T> struct FPBits {
 
   FPBits() : bits(0) {}
 
-  T get_val() const { return __llvm_libc::bit_cast<T>(bits); }
+  T get_val() const { return cpp::bit_cast<T>(bits); }
 
-  void set_val(T value) { bits = __llvm_libc::bit_cast<UIntType>(value); }
+  void set_val(T value) { bits = cpp::bit_cast<UIntType>(value); }
 
   explicit operator T() const { return get_val(); }
 

diff  --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h
index 11cedea3d4e50..3e72e85250fb9 100644
--- a/libc/src/__support/FPUtil/Hypot.h
+++ b/libc/src/__support/FPUtil/Hypot.h
@@ -13,8 +13,8 @@
 #include "FEnvImpl.h"
 #include "FPBits.h"
 #include "builtin_wrappers.h"
-#include "src/__support/CPP/Bit.h"
 #include "src/__support/CPP/UInt128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/CPP/type_traits.h"
 
 namespace __llvm_libc {
@@ -248,7 +248,7 @@ static inline T hypot(T x, T y) {
   }
 
   y_new |= static_cast<UIntType>(out_exp) << MantissaWidth<T>::VALUE;
-  return __llvm_libc::bit_cast<T>(y_new);
+  return cpp::bit_cast<T>(y_new);
 }
 
 } // namespace fputil

diff  --git a/libc/src/__support/FPUtil/ManipulationFunctions.h b/libc/src/__support/FPUtil/ManipulationFunctions.h
index 21bce00f2874b..60c0e4887cd8d 100644
--- a/libc/src/__support/FPUtil/ManipulationFunctions.h
+++ b/libc/src/__support/FPUtil/ManipulationFunctions.h
@@ -14,7 +14,7 @@
 #include "NormalFloat.h"
 #include "PlatformDefs.h"
 
-#include "src/__support/CPP/Bit.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/CPP/type_traits.h"
 
 #include <limits.h>
@@ -165,7 +165,7 @@ static inline T nextafter(T from, T to) {
     int_val = (to_bits.uintval() & sign_mask) + UIntType(1);
   }
 
-  return __llvm_libc::bit_cast<T>(int_val);
+  return cpp::bit_cast<T>(int_val);
   // TODO: Raise floating point exceptions as required by the standard.
 }
 

diff  --git a/libc/src/__support/FPUtil/generic/FMA.h b/libc/src/__support/FPUtil/generic/FMA.h
index 2eb729ee6acca..6aeaff399b040 100644
--- a/libc/src/__support/FPUtil/generic/FMA.h
+++ b/libc/src/__support/FPUtil/generic/FMA.h
@@ -9,7 +9,6 @@
 #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/UInt128.h"
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
@@ -259,7 +258,8 @@ template <> inline double fma<double>(double x, double y, double z) {
         (round_mode == FE_UPWARD && prod_sign) ||
         (round_mode == FE_DOWNWARD && !prod_sign)) {
       result = FPBits::MAX_NORMAL;
-      return prod_sign ? -bit_cast<double>(result) : bit_cast<double>(result);
+      return prod_sign ? -cpp::bit_cast<double>(result)
+                       : cpp::bit_cast<double>(result);
     }
     return prod_sign ? static_cast<double>(FPBits::neg_inf())
                      : static_cast<double>(FPBits::inf());
@@ -282,7 +282,7 @@ template <> inline double fma<double>(double x, double y, double z) {
       ++result;
   }
 
-  return bit_cast<double>(result);
+  return cpp::bit_cast<double>(result);
 }
 
 } // namespace generic

diff  --git a/libc/src/__support/FPUtil/generic/sqrt.h b/libc/src/__support/FPUtil/generic/sqrt.h
index 8763ac7a624e4..842df24e3b093 100644
--- a/libc/src/__support/FPUtil/generic/sqrt.h
+++ b/libc/src/__support/FPUtil/generic/sqrt.h
@@ -10,8 +10,8 @@
 #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/UInt128.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"
@@ -161,7 +161,7 @@ static inline cpp::enable_if_t<cpp::is_floating_point_v<T>, T> sqrt(T x) {
         break;
       }
 
-      return __llvm_libc::bit_cast<T>(y);
+      return cpp::bit_cast<T>(y);
     }
   }
 }

diff  --git a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
index edae1534be7e4..30a4c1309f2f1 100644
--- a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
+++ b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h
@@ -9,8 +9,8 @@
 #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H
 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H
 
-#include "src/__support/CPP/Bit.h"
 #include "src/__support/CPP/UInt128.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/architectures.h"
 
 #if !defined(LLVM_LIBC_ARCH_X86)
@@ -101,7 +101,7 @@ template <> struct FPBits<long double> {
 
   template <typename XType,
             cpp::enable_if_t<cpp::is_same_v<long double, XType>, int> = 0>
-  explicit FPBits(XType x) : bits(__llvm_libc::bit_cast<UIntType>(x)) {
+  explicit FPBits(XType x) : bits(cpp::bit_cast<UIntType>(x)) {
     // bits starts uninitialized, and setting it to a long double only
     // overwrites the first 80 bits. This clears those upper bits.
     bits = bits & ((UIntType(1) << 80) - 1);
@@ -111,7 +111,7 @@ template <> struct FPBits<long double> {
             cpp::enable_if_t<cpp::is_same_v<XType, UIntType>, int> = 0>
   explicit FPBits(XType x) : bits(x) {}
 
-  operator long double() { return __llvm_libc::bit_cast<long double>(bits); }
+  operator long double() { return cpp::bit_cast<long double>(bits); }
 
   UIntType uintval() {
     // We zero the padding bits as they can contain garbage.

diff  --git a/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h b/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
index 9251d838315a1..5ac45f1d8e6cd 100644
--- a/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
+++ b/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h
@@ -15,7 +15,7 @@
 #error "Invalid include"
 #endif
 
-#include "src/__support/CPP/Bit.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/FPUtil/FPBits.h"
 
 #include <stdint.h>
@@ -112,7 +112,7 @@ static inline long double nextafter(long double from, long double to) {
     }
   }
 
-  return __llvm_libc::bit_cast<long double>(int_val);
+  return cpp::bit_cast<long double>(int_val);
   // TODO: Raise floating point exceptions as required by the standard.
 }
 

diff  --git a/libc/src/math/generic/math_utils.h b/libc/src/math/generic/math_utils.h
index d8cf6fd7cb380..61c84dc630cfc 100644
--- a/libc/src/math/generic/math_utils.h
+++ b/libc/src/math/generic/math_utils.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_MATH_MATH_UTILS_H
 #define LLVM_LIBC_SRC_MATH_MATH_UTILS_H
 
-#include "src/__support/CPP/Bit.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/common.h"
 #include <errno.h>
@@ -20,20 +20,16 @@
 namespace __llvm_libc {
 
 static inline uint32_t as_uint32_bits(float x) {
-  return __llvm_libc::bit_cast<uint32_t>(x);
+  return cpp::bit_cast<uint32_t>(x);
 }
 
 static inline uint64_t as_uint64_bits(double x) {
-  return __llvm_libc::bit_cast<uint64_t>(x);
+  return cpp::bit_cast<uint64_t>(x);
 }
 
-static inline float as_float(uint32_t x) {
-  return __llvm_libc::bit_cast<float>(x);
-}
+static inline float as_float(uint32_t x) { return cpp::bit_cast<float>(x); }
 
-static inline double as_double(uint64_t x) {
-  return __llvm_libc::bit_cast<double>(x);
-}
+static inline double as_double(uint64_t x) { return cpp::bit_cast<double>(x); }
 
 static inline uint32_t top12_bits(float x) { return as_uint32_bits(x) >> 20; }
 

diff  --git a/libc/src/stdio/printf_core/parser.cpp b/libc/src/stdio/printf_core/parser.cpp
index ddf3cec6f52fa..d2f0b89b0f1ba 100644
--- a/libc/src/stdio/printf_core/parser.cpp
+++ b/libc/src/stdio/printf_core/parser.cpp
@@ -12,7 +12,7 @@
 
 #include "src/__support/arg_list.h"
 
-#include "src/__support/CPP/Bit.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/ctype_utils.h"
 #include "src/__support/str_to_integer.h"
@@ -132,10 +132,11 @@ FormatSection Parser::get_next_section() {
     case ('G'):
       if (lm != LengthModifier::L)
         section.conv_val_raw =
-            bit_cast<uint64_t>(GET_ARG_VAL_SIMPLEST(double, conv_index));
+            cpp::bit_cast<uint64_t>(GET_ARG_VAL_SIMPLEST(double, conv_index));
       else
-        section.conv_val_raw = bit_cast<fputil::FPBits<long double>::UIntType>(
-            GET_ARG_VAL_SIMPLEST(long double, conv_index));
+        section.conv_val_raw =
+            cpp::bit_cast<fputil::FPBits<long double>::UIntType>(
+                GET_ARG_VAL_SIMPLEST(long double, conv_index));
       break;
 #endif // LLVM_LIBC_PRINTF_DISABLE_FLOAT
 #ifndef LLVM_LIBC_PRINTF_DISABLE_WRITE_INT

diff  --git a/libc/src/string/memory_utils/elements_x86.h b/libc/src/string/memory_utils/elements_x86.h
index f25c66be74cac..7a2a8ccef4e34 100644
--- a/libc/src/string/memory_utils/elements_x86.h
+++ b/libc/src/string/memory_utils/elements_x86.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_ELEMENTS_X86_H
 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_ELEMENTS_X86_H
 
-#include "src/__support/CPP/Bit.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/architectures.h"
 
 #if defined(LLVM_LIBC_ARCH_X86)
@@ -68,18 +68,18 @@ struct M128 {
   static uint16_t mask(T value) {
     // NOLINTNEXTLINE(llvmlibc-callee-namespace)
     return static_cast<uint16_t>(
-        _mm_movemask_epi8(__llvm_libc::bit_cast<__m128i>(value)));
+        _mm_movemask_epi8(cpp::bit_cast<__m128i>(value)));
   }
   static uint16_t not_equal_mask(T a, T b) { return mask(a != b); }
   static T load(const char *ptr) {
     // NOLINTNEXTLINE(llvmlibc-callee-namespace)
-    return __llvm_libc::bit_cast<T>(
+    return cpp::bit_cast<T>(
         _mm_loadu_si128(reinterpret_cast<__m128i_u const *>(ptr)));
   }
   static void store(char *ptr, T value) {
     // NOLINTNEXTLINE(llvmlibc-callee-namespace)
     return _mm_storeu_si128(reinterpret_cast<__m128i_u *>(ptr),
-                            __llvm_libc::bit_cast<__m128i>(value));
+                            cpp::bit_cast<__m128i>(value));
   }
   static T get_splatted_value(const char v) {
     const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v};
@@ -95,18 +95,18 @@ struct M256 {
   using T = char __attribute__((__vector_size__(SIZE)));
   static uint32_t mask(T value) {
     // NOLINTNEXTLINE(llvmlibc-callee-namespace)
-    return _mm256_movemask_epi8(__llvm_libc::bit_cast<__m256i>(value));
+    return _mm256_movemask_epi8(cpp::bit_cast<__m256i>(value));
   }
   static uint32_t not_equal_mask(T a, T b) { return mask(a != b); }
   static T load(const char *ptr) {
     // NOLINTNEXTLINE(llvmlibc-callee-namespace)
-    return __llvm_libc::bit_cast<T>(
+    return cpp::bit_cast<T>(
         _mm256_loadu_si256(reinterpret_cast<__m256i const *>(ptr)));
   }
   static void store(char *ptr, T value) {
     // NOLINTNEXTLINE(llvmlibc-callee-namespace)
     return _mm256_storeu_si256(reinterpret_cast<__m256i *>(ptr),
-                               __llvm_libc::bit_cast<__m256i>(value));
+                               cpp::bit_cast<__m256i>(value));
   }
   static T get_splatted_value(const char v) {
     const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v,
@@ -123,16 +123,16 @@ struct M512 {
   using T = char __attribute__((__vector_size__(SIZE)));
   static uint64_t not_equal_mask(T a, T b) {
     // NOLINTNEXTLINE(llvmlibc-callee-namespace)
-    return _mm512_cmpneq_epi8_mask(__llvm_libc::bit_cast<__m512i>(a),
-                                   __llvm_libc::bit_cast<__m512i>(b));
+    return _mm512_cmpneq_epi8_mask(cpp::bit_cast<__m512i>(a),
+                                   cpp::bit_cast<__m512i>(b));
   }
   static T load(const char *ptr) {
     // NOLINTNEXTLINE(llvmlibc-callee-namespace)
-    return __llvm_libc::bit_cast<T>(_mm512_loadu_epi8(ptr));
+    return cpp::bit_cast<T>(_mm512_loadu_epi8(ptr));
   }
   static void store(char *ptr, T value) {
     // NOLINTNEXTLINE(llvmlibc-callee-namespace)
-    return _mm512_storeu_epi8(ptr, __llvm_libc::bit_cast<__m512i>(value));
+    return _mm512_storeu_epi8(ptr, cpp::bit_cast<__m512i>(value));
   }
   static T get_splatted_value(const char v) {
     const T splatted = {v, v, v, v, v, v, v, v, v, v, v, v, v, v, v, v,

diff  --git a/libc/test/src/math/NextAfterTest.h b/libc/test/src/math/NextAfterTest.h
index 3ec698311909f..fcc2c43a5aacc 100644
--- a/libc/test/src/math/NextAfterTest.h
+++ b/libc/test/src/math/NextAfterTest.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H
 #define LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H
 
-#include "src/__support/CPP/Bit.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/CPP/type_traits.h"
 #include "src/__support/FPUtil/BasicOperations.h"
 #include "src/__support/FPUtil/FPBits.h"
@@ -52,54 +52,54 @@ class NextAfterTestTemplate : public __llvm_libc::testing::Test {
     T x = zero;
     T result = func(x, T(1));
     UIntType expected_bits = 1;
-    T expected = __llvm_libc::bit_cast<T>(expected_bits);
+    T expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     result = func(x, T(-1));
     expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     x = neg_zero;
     result = func(x, 1);
     expected_bits = 1;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     result = func(x, -1);
     expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     // 'from' is max subnormal value.
-    x = __llvm_libc::bit_cast<T>(max_subnormal);
+    x = __llvm_libc::cpp::bit_cast<T>(max_subnormal);
     result = func(x, 1);
-    expected = __llvm_libc::bit_cast<T>(min_normal);
+    expected = __llvm_libc::cpp::bit_cast<T>(min_normal);
     ASSERT_FP_EQ(result, expected);
 
     result = func(x, 0);
     expected_bits = max_subnormal - 1;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     x = -x;
 
     result = func(x, -1);
     expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     result = func(x, 0);
     expected_bits =
         (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal - 1;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     // 'from' is min subnormal value.
-    x = __llvm_libc::bit_cast<T>(min_subnormal);
+    x = __llvm_libc::cpp::bit_cast<T>(min_subnormal);
     result = func(x, 1);
     expected_bits = min_subnormal + 1;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
     ASSERT_FP_EQ(func(x, 0), 0);
 
@@ -107,35 +107,35 @@ class NextAfterTestTemplate : public __llvm_libc::testing::Test {
     result = func(x, -1);
     expected_bits =
         (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_subnormal + 1;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
     ASSERT_FP_EQ(func(x, 0), T(-0.0));
 
     // 'from' is min normal.
-    x = __llvm_libc::bit_cast<T>(min_normal);
+    x = __llvm_libc::cpp::bit_cast<T>(min_normal);
     result = func(x, 0);
     expected_bits = max_subnormal;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     result = func(x, inf);
     expected_bits = min_normal + 1;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     x = -x;
     result = func(x, 0);
     expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     result = func(x, -inf);
     expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal + 1;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
 
     // 'from' is max normal and 'to' is infinity.
-    x = __llvm_libc::bit_cast<T>(max_normal);
+    x = __llvm_libc::cpp::bit_cast<T>(max_normal);
     result = func(x, inf);
     ASSERT_FP_EQ(result, inf);
 
@@ -146,14 +146,14 @@ class NextAfterTestTemplate : public __llvm_libc::testing::Test {
     x = inf;
     result = func(x, 0);
     expected_bits = max_normal;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
     ASSERT_FP_EQ(func(x, inf), inf);
 
     x = neg_inf;
     result = func(x, 0);
     expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_normal;
-    expected = __llvm_libc::bit_cast<T>(expected_bits);
+    expected = __llvm_libc::cpp::bit_cast<T>(expected_bits);
     ASSERT_FP_EQ(result, expected);
     ASSERT_FP_EQ(func(x, neg_inf), neg_inf);
 

diff  --git a/libc/test/src/math/SqrtTest.h b/libc/test/src/math/SqrtTest.h
index 0be4f3bd63e29..08c0adc9bea42 100644
--- a/libc/test/src/math/SqrtTest.h
+++ b/libc/test/src/math/SqrtTest.h
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "src/__support/CPP/Bit.h"
+#include "src/__support/CPP/bit.h"
 #include "utils/MPFRWrapper/MPFRUtils.h"
 #include "utils/UnitTest/FPMatcher.h"
 #include "utils/UnitTest/Test.h"
@@ -48,7 +48,7 @@ template <typename T> class SqrtTest : public __llvm_libc::testing::Test {
     constexpr UIntType COUNT = 1'000'001;
     constexpr UIntType STEP = HIDDEN_BIT / COUNT;
     for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
-      T x = __llvm_libc::bit_cast<T>(v);
+      T x = __llvm_libc::cpp::bit_cast<T>(v);
       test_all_rounding_modes(func, x);
     }
   }
@@ -57,7 +57,7 @@ template <typename T> class SqrtTest : public __llvm_libc::testing::Test {
     constexpr UIntType COUNT = 10'000'001;
     constexpr UIntType STEP = UIntType(-1) / COUNT;
     for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
-      T x = __llvm_libc::bit_cast<T>(v);
+      T x = __llvm_libc::cpp::bit_cast<T>(v);
       if (isnan(x) || (x < 0)) {
         continue;
       }

diff  --git a/libc/test/src/stdio/printf_core/parser_test.cpp b/libc/test/src/stdio/printf_core/parser_test.cpp
index c9cc1c2f3c58b..d2f32b795ffbd 100644
--- a/libc/test/src/stdio/printf_core/parser_test.cpp
+++ b/libc/test/src/stdio/printf_core/parser_test.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "src/__support/CPP/Bit.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/arg_list.h"
 #include "src/stdio/printf_core/parser.h"
 
@@ -248,7 +248,7 @@ TEST(LlvmLibcPrintfParserTest, EvalThreeArgs) {
   expected1.has_conv = true;
   expected1.raw_len = 2;
   expected1.raw_string = str + 2;
-  expected1.conv_val_raw = __llvm_libc::bit_cast<uint64_t>(arg2);
+  expected1.conv_val_raw = __llvm_libc::cpp::bit_cast<uint64_t>(arg2);
   expected1.conv_name = 'f';
 
   ASSERT_FORMAT_EQ(expected1, format_arr[1]);
@@ -300,7 +300,7 @@ TEST(LlvmLibcPrintfParserTest, IndexModeThreeArgsSequential) {
   expected1.has_conv = true;
   expected1.raw_len = 4;
   expected1.raw_string = str + 4;
-  expected1.conv_val_raw = __llvm_libc::bit_cast<uint64_t>(arg2);
+  expected1.conv_val_raw = __llvm_libc::cpp::bit_cast<uint64_t>(arg2);
   expected1.conv_name = 'f';
 
   ASSERT_FORMAT_EQ(expected1, format_arr[1]);
@@ -334,7 +334,7 @@ TEST(LlvmLibcPrintfParserTest, IndexModeThreeArgsReverse) {
   expected1.has_conv = true;
   expected1.raw_len = 4;
   expected1.raw_string = str + 4;
-  expected1.conv_val_raw = __llvm_libc::bit_cast<uint64_t>(arg2);
+  expected1.conv_val_raw = __llvm_libc::cpp::bit_cast<uint64_t>(arg2);
   expected1.conv_name = 'f';
 
   ASSERT_FORMAT_EQ(expected1, format_arr[1]);
@@ -418,7 +418,7 @@ TEST(LlvmLibcPrintfParserTest, IndexModeComplexParsing) {
   expected5.raw_string = str + 22;
   expected5.flags = __llvm_libc::printf_core::FormatFlags::SPACE_PREFIX;
   expected5.min_width = arg4;
-  expected5.conv_val_raw = __llvm_libc::bit_cast<uint64_t>(arg2);
+  expected5.conv_val_raw = __llvm_libc::cpp::bit_cast<uint64_t>(arg2);
   expected5.conv_name = 'f';
 
   EXPECT_FORMAT_EQ(expected5, format_arr[5]);
@@ -434,7 +434,7 @@ TEST(LlvmLibcPrintfParserTest, IndexModeComplexParsing) {
   expected7.raw_string = str + 31;
   expected7.flags = __llvm_libc::printf_core::FormatFlags::SPACE_PREFIX;
   expected7.precision = arg4;
-  expected7.conv_val_raw = __llvm_libc::bit_cast<uint64_t>(arg2);
+  expected7.conv_val_raw = __llvm_libc::cpp::bit_cast<uint64_t>(arg2);
   expected7.conv_name = 'f';
 
   EXPECT_FORMAT_EQ(expected7, format_arr[7]);

diff  --git a/libc/test/src/string/memory_utils/backend_test.cpp b/libc/test/src/string/memory_utils/backend_test.cpp
index 2ce0d1775ad0d..1ae33a663c1c2 100644
--- a/libc/test/src/string/memory_utils/backend_test.cpp
+++ b/libc/test/src/string/memory_utils/backend_test.cpp
@@ -7,8 +7,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/CPP/ArrayRef.h"
-#include "src/__support/CPP/Bit.h"
 #include "src/__support/CPP/array.h"
+#include "src/__support/CPP/bit.h"
 #include "src/__support/architectures.h"
 #include "src/string/memory_utils/backends.h"
 #include "utils/UnitTest/Test.h"
@@ -49,15 +49,17 @@ template <typename Backend, size_t Size> struct Conf {
   static constexpr size_t SIZE = Size;
 
   static BufferT splat(ubyte value) {
-    return bit_cast<BufferT>(Backend::template splat<T>(value));
+    return cpp::bit_cast<BufferT>(Backend::template splat<T>(value));
   }
 
   static uint64_t notEquals(const BufferT &v1, const BufferT &v2) {
-    return Backend::template notEquals<T>(bit_cast<T>(v1), bit_cast<T>(v2));
+    return Backend::template notEquals<T>(cpp::bit_cast<T>(v1),
+                                          cpp::bit_cast<T>(v2));
   }
 
   static int32_t threeWayCmp(const BufferT &v1, const BufferT &v2) {
-    return Backend::template threeWayCmp<T>(bit_cast<T>(v1), bit_cast<T>(v2));
+    return Backend::template threeWayCmp<T>(cpp::bit_cast<T>(v1),
+                                            cpp::bit_cast<T>(v2));
   }
 };
 
@@ -85,9 +87,10 @@ using FunctionTypes = testing::TypeList< //
 
 TYPED_TEST(LlvmLibcMemoryBackend, splat, FunctionTypes) {
   for (auto value : cpp::array<uint8_t, 3>{0u, 1u, 255u}) {
-    alignas(64) const auto stored = ParamType::splat(bit_cast<ubyte>(value));
+    alignas(64) const auto stored =
+        ParamType::splat(cpp::bit_cast<ubyte>(value));
     for (size_t i = 0; i < ParamType::SIZE; ++i)
-      EXPECT_EQ(bit_cast<uint8_t>(stored[i]), value);
+      EXPECT_EQ(cpp::bit_cast<uint8_t>(stored[i]), value);
   }
 }
 
@@ -129,14 +132,14 @@ struct LoadStoreConf {
   static constexpr size_t SIZE = Size;
 
   static BufferT load(const BufferT &ref) {
-    const auto *ptr = bit_cast<const T *>(ref.data());
+    const auto *ptr = cpp::bit_cast<const T *>(ref.data());
     const T value = Backend::template load<T, TS, AS>(ptr);
-    return bit_cast<BufferT>(value);
+    return cpp::bit_cast<BufferT>(value);
   }
 
   static void store(BufferT &ref, const BufferT value) {
-    auto *ptr = bit_cast<T *>(ref.data());
-    Backend::template store<T, TS, AS>(ptr, bit_cast<T>(value));
+    auto *ptr = cpp::bit_cast<T *>(ref.data());
+    Backend::template store<T, TS, AS>(ptr, cpp::bit_cast<T>(value));
   }
 };
 

diff  --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index a413a3c1cd433..26a0db4ca5290 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -53,7 +53,7 @@ cc_library(
 
 cc_library(
     name = "__support_cpp_bit",
-    hdrs = ["src/__support/CPP/Bit.h"],
+    hdrs = ["src/__support/CPP/bit.h"],
     deps = [":libc_root"],
 )
 


        


More information about the libc-commits mailing list