42 changes: 21 additions & 21 deletions libc/test/src/math/NextAfterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -52,90 +52,90 @@ 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);

x = -x;
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);

Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions libc/test/src/math/SqrtTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions libc/test/src/stdio/printf_core/parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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]);
Expand All @@ -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]);
Expand Down
23 changes: 13 additions & 10 deletions libc/test/src/string/memory_utils/backend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
}
};

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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));
}
};

Expand Down
2 changes: 1 addition & 1 deletion utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)

Expand Down