213 changes: 0 additions & 213 deletions libc/test/src/__support/FPUtil/fpbits_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,219 +12,6 @@

using LIBC_NAMESPACE::fputil::FPBits;

TEST(LlvmLibcFPBitsTest, FPType_IEEE754_Binary16) {
using LIBC_NAMESPACE::fputil::FPType;
using LIBC_NAMESPACE::fputil::internal::FPRep;
using Rep = FPRep<FPType::IEEE754_Binary16>;
using u16 = uint16_t;

EXPECT_EQ(u16(0b0'00000'0000000000), Rep::zero());
EXPECT_EQ(u16(0b0'01111'0000000000), Rep::one());
EXPECT_EQ(u16(0b0'00000'0000000001), Rep::min_subnormal());
EXPECT_EQ(u16(0b0'00000'1111111111), Rep::max_subnormal());
EXPECT_EQ(u16(0b0'00001'0000000000), Rep::min_normal());
EXPECT_EQ(u16(0b0'11110'1111111111), Rep::max_normal());
EXPECT_EQ(u16(0b0'11111'0000000000), Rep::inf());
EXPECT_EQ(u16(0b0'11111'0100000000), Rep::build_nan());
EXPECT_EQ(u16(0b0'11111'1000000000), Rep::build_quiet_nan());
}

TEST(LlvmLibcFPBitsTest, FPType_IEEE754_Binary32) {
using LIBC_NAMESPACE::fputil::FPType;
using LIBC_NAMESPACE::fputil::internal::FPRep;
using Rep = FPRep<FPType::IEEE754_Binary32>;
using u32 = uint32_t;

EXPECT_EQ(u32(0b0'00000000'00000000000000000000000), Rep::zero());
EXPECT_EQ(u32(0b0'01111111'00000000000000000000000), Rep::one());
EXPECT_EQ(u32(0b0'00000000'00000000000000000000001), Rep::min_subnormal());
EXPECT_EQ(u32(0b0'00000000'11111111111111111111111), Rep::max_subnormal());
EXPECT_EQ(u32(0b0'00000001'00000000000000000000000), Rep::min_normal());
EXPECT_EQ(u32(0b0'11111110'11111111111111111111111), Rep::max_normal());
EXPECT_EQ(u32(0b0'11111111'00000000000000000000000), Rep::inf());
EXPECT_EQ(u32(0b0'11111111'01000000000000000000000), Rep::build_nan());
EXPECT_EQ(u32(0b0'11111111'10000000000000000000000), Rep::build_quiet_nan());
}

TEST(LlvmLibcFPBitsTest, FPType_IEEE754_Binary64) {
using LIBC_NAMESPACE::fputil::FPType;
using LIBC_NAMESPACE::fputil::internal::FPRep;
using Rep = FPRep<FPType::IEEE754_Binary64>;
using u64 = uint64_t;

EXPECT_EQ(
u64(0b0'00000000000'0000000000000000000000000000000000000000000000000000),
Rep::zero());
EXPECT_EQ(
u64(0b0'01111111111'0000000000000000000000000000000000000000000000000000),
Rep::one());
EXPECT_EQ(
u64(0b0'00000000000'0000000000000000000000000000000000000000000000000001),
Rep::min_subnormal());
EXPECT_EQ(
u64(0b0'00000000000'1111111111111111111111111111111111111111111111111111),
Rep::max_subnormal());
EXPECT_EQ(
u64(0b0'00000000001'0000000000000000000000000000000000000000000000000000),
Rep::min_normal());
EXPECT_EQ(
u64(0b0'11111111110'1111111111111111111111111111111111111111111111111111),
Rep::max_normal());
EXPECT_EQ(
u64(0b0'11111111111'0000000000000000000000000000000000000000000000000000),
Rep::inf());
EXPECT_EQ(
u64(0b0'11111111111'0100000000000000000000000000000000000000000000000000),
Rep::build_nan());
EXPECT_EQ(
u64(0b0'11111111111'1000000000000000000000000000000000000000000000000000),
Rep::build_quiet_nan());
}

static constexpr UInt128 u128(uint64_t hi, uint64_t lo) {
#if defined(__SIZEOF_INT128__)
return __uint128_t(hi) << 64 | __uint128_t(lo);
#else
return UInt128({hi, lo});
#endif
}

TEST(LlvmLibcFPBitsTest, FPType_X86_Binary80) {
using LIBC_NAMESPACE::fputil::FPType;
using LIBC_NAMESPACE::fputil::internal::FPRep;
using Rep = FPRep<FPType::X86_Binary80>;

EXPECT_EQ(
u128(0b0'000000000000000,
0b0000000000000000000000000000000000000000000000000000000000000000),
Rep::zero());
EXPECT_EQ(
u128(0b0'011111111111111,
0b1000000000000000000000000000000000000000000000000000000000000000),
Rep::one());
EXPECT_EQ(
u128(0b0'000000000000000,
0b0000000000000000000000000000000000000000000000000000000000000001),
Rep::min_subnormal());
EXPECT_EQ(
u128(0b0'000000000000000,
0b0111111111111111111111111111111111111111111111111111111111111111),
Rep::max_subnormal());
EXPECT_EQ(
u128(0b0'000000000000001,
0b1000000000000000000000000000000000000000000000000000000000000000),
Rep::min_normal());
EXPECT_EQ(
u128(0b0'111111111111110,
0b1111111111111111111111111111111111111111111111111111111111111111),
Rep::max_normal());
EXPECT_EQ(
u128(0b0'111111111111111,
0b1000000000000000000000000000000000000000000000000000000000000000),
Rep::inf());
EXPECT_EQ(
u128(0b0'111111111111111,
0b1010000000000000000000000000000000000000000000000000000000000000),
Rep::build_nan());
EXPECT_EQ(
u128(0b0'111111111111111,
0b1100000000000000000000000000000000000000000000000000000000000000),
Rep::build_quiet_nan());
}

TEST(LlvmLibcFPBitsTest, FPType_X86_Binary80_IsNan) {
using LIBC_NAMESPACE::fputil::FPType;
using LIBC_NAMESPACE::fputil::internal::FPRep;
using Rep = FPRep<FPType::X86_Binary80>;

const auto is_nan = [](uint64_t hi, uint64_t lo) {
Rep rep;
rep.set_uintval(u128(hi, lo));
return rep.is_nan();
};

EXPECT_TRUE(is_nan(
0b0'111111111111111, // NAN : Pseudo-Infinity
0b0000000000000000000000000000000000000000000000000000000000000000));
EXPECT_TRUE(is_nan(
0b0'111111111111111, // NAN : Pseudo Not a Number
0b0000000000000000000000000000000000000000000000000000000000000001));
EXPECT_TRUE(is_nan(
0b0'111111111111111, // NAN : Pseudo Not a Number
0b0100000000000000000000000000000000000000000000000000000000000000));
EXPECT_TRUE(is_nan(
0b0'111111111111111, // NAN : Signalling Not a Number
0b1000000000000000000000000000000000000000000000000000000000000001));
EXPECT_TRUE(is_nan(
0b0'111111111111111, // NAN : Floating-point Indefinite
0b1100000000000000000000000000000000000000000000000000000000000000));
EXPECT_TRUE(is_nan(
0b0'111111111111111, // NAN : Quiet Not a Number
0b1100000000000000000000000000000000000000000000000000000000000001));
EXPECT_TRUE(is_nan(
0b0'111111111111110, // NAN : Unnormal
0b0000000000000000000000000000000000000000000000000000000000000000));

EXPECT_FALSE(is_nan(
0b0'000000000000000, // Zero
0b0000000000000000000000000000000000000000000000000000000000000000));
EXPECT_FALSE(is_nan(
0b0'000000000000000, // Subnormal
0b0000000000000000000000000000000000000000000000000000000000000001));
EXPECT_FALSE(is_nan(
0b0'000000000000000, // Pseudo Denormal
0b1000000000000000000000000000000000000000000000000000000000000001));
EXPECT_FALSE(is_nan(
0b0'111111111111111, // Infinity
0b1000000000000000000000000000000000000000000000000000000000000000));
EXPECT_FALSE(is_nan(
0b0'111111111111110, // Normalized
0b1000000000000000000000000000000000000000000000000000000000000000));
}

TEST(LlvmLibcFPBitsTest, FPType_IEEE754_Binary128) {
using LIBC_NAMESPACE::fputil::FPType;
using LIBC_NAMESPACE::fputil::internal::FPRep;
using Rep = FPRep<FPType::IEEE754_Binary128>;

EXPECT_EQ(
u128(0b0'000000000000000'000000000000000000000000000000000000000000000000,
0b0000000000000000000000000000000000000000000000000000000000000000),
Rep::zero());
EXPECT_EQ(
u128(0b0'011111111111111'000000000000000000000000000000000000000000000000,
0b0000000000000000000000000000000000000000000000000000000000000000),
Rep::one());
EXPECT_EQ(
u128(0b0'000000000000000'000000000000000000000000000000000000000000000000,
0b0000000000000000000000000000000000000000000000000000000000000001),
Rep::min_subnormal());
EXPECT_EQ(
u128(0b0'000000000000000'111111111111111111111111111111111111111111111111,
0b1111111111111111111111111111111111111111111111111111111111111111),
Rep::max_subnormal());
EXPECT_EQ(
u128(0b0'000000000000001'000000000000000000000000000000000000000000000000,
0b0000000000000000000000000000000000000000000000000000000000000000),
Rep::min_normal());
EXPECT_EQ(
u128(0b0'111111111111110'111111111111111111111111111111111111111111111111,
0b1111111111111111111111111111111111111111111111111111111111111111),
Rep::max_normal());
EXPECT_EQ(
u128(0b0'111111111111111'000000000000000000000000000000000000000000000000,
0b0000000000000000000000000000000000000000000000000000000000000000),
Rep::inf());
EXPECT_EQ(
u128(0b0'111111111111111'010000000000000000000000000000000000000000000000,
0b0000000000000000000000000000000000000000000000000000000000000000),
Rep::build_nan());
EXPECT_EQ(
u128(0b0'111111111111111'100000000000000000000000000000000000000000000000,
0b0000000000000000000000000000000000000000000000000000000000000000),
Rep::build_quiet_nan());
}

TEST(LlvmLibcFPBitsTest, FloatType) {
using FloatBits = FPBits<float>;

Expand Down
12 changes: 6 additions & 6 deletions libc/test/utils/FPUtil/x86_long_double_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
// If exponent has the max value and the implicit bit is 0,
// then the number is a NaN for all values of mantissa.
bits.set_mantissa(i);
long double nan = bits.get_val();
long double nan = bits;
ASSERT_NE(static_cast<int>(isnan(nan)), 0);
ASSERT_TRUE(bits.is_nan());
}
Expand All @@ -38,7 +38,7 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
// then the number is a NaN for all non-zero values of mantissa.
// Note the initial value of |i| of 1 to avoid a zero mantissa.
bits.set_mantissa(i);
long double nan = bits.get_val();
long double nan = bits;
ASSERT_NE(static_cast<int>(isnan(nan)), 0);
ASSERT_TRUE(bits.is_nan());
}
Expand All @@ -49,7 +49,7 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
// If exponent is non-zero and also not max, and the implicit bit is 0,
// then the number is a NaN for all values of mantissa.
bits.set_mantissa(i);
long double nan = bits.get_val();
long double nan = bits;
ASSERT_NE(static_cast<int>(isnan(nan)), 0);
ASSERT_TRUE(bits.is_nan());
}
Expand All @@ -60,7 +60,7 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
// If exponent is non-zero and also not max, and the implicit bit is 1,
// then the number is normal value for all values of mantissa.
bits.set_mantissa(i);
long double valid = bits.get_val();
long double valid = bits;
ASSERT_EQ(static_cast<int>(isnan(valid)), 0);
ASSERT_FALSE(bits.is_nan());
}
Expand All @@ -70,7 +70,7 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
for (unsigned int i = 0; i < COUNT; ++i) {
// If exponent is zero, then the number is a valid but denormal value.
bits.set_mantissa(i);
long double valid = bits.get_val();
long double valid = bits;
ASSERT_EQ(static_cast<int>(isnan(valid)), 0);
ASSERT_FALSE(bits.is_nan());
}
Expand All @@ -80,7 +80,7 @@ TEST(LlvmLibcX86LongDoubleTest, is_nan) {
for (unsigned int i = 0; i < COUNT; ++i) {
// If exponent is zero, then the number is a valid but denormal value.
bits.set_mantissa(i);
long double valid = bits.get_val();
long double valid = bits;
ASSERT_EQ(static_cast<int>(isnan(valid)), 0);
ASSERT_FALSE(bits.is_nan());
}
Expand Down
1 change: 1 addition & 0 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ libc_support_library(
libc_support_library(
name = "__support_fputil_fp_bits",
hdrs = ["src/__support/FPUtil/FPBits.h"],
textual_hdrs = ["src/__support/FPUtil/x86_64/LongDoubleBits.h"],
deps = [
":__support_common",
":__support_cpp_bit",
Expand Down

This file was deleted.