diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt --- a/libc/src/__support/FPUtil/CMakeLists.txt +++ b/libc/src/__support/FPUtil/CMakeLists.txt @@ -36,9 +36,7 @@ .platform_defs .float_properties libc.src.__support.builtin_wrappers - libc.src.__support.integer_to_string libc.src.__support.CPP.bit - libc.src.__support.CPP.string libc.src.__support.CPP.type_traits libc.src.__support.common ) diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h --- a/libc/src/__support/FPUtil/FPBits.h +++ b/libc/src/__support/FPUtil/FPBits.h @@ -12,11 +12,9 @@ #include "PlatformDefs.h" #include "src/__support/CPP/bit.h" -#include "src/__support/CPP/string.h" #include "src/__support/CPP/type_traits.h" #include "src/__support/builtin_wrappers.h" #include "src/__support/common.h" -#include "src/__support/integer_to_string.h" #include "FloatProperties.h" #include @@ -215,47 +213,6 @@ result.set_mantissa(mantissa); return result; } - - // Converts the bits to a string in the following format: - // "0x = S: N, E: 0xNNNN, M:0xNNN...N" - // 1. N is a hexadecimal digit. - // 2. The hexadecimal number on the LHS is the raw numerical representation - // of the bits. - // 3. The exponent is always 16 bits wide irrespective of the type of the - // floating encoding. - LIBC_INLINE cpp::string str() const { - if (is_nan()) - return "(NaN)"; - if (is_inf()) - return get_sign() ? "(-Infinity)" : "(+Infinity)"; - - auto zerofill = [](char *arr, size_t n) { - for (size_t i = 0; i < n; ++i) - arr[i] = '0'; - }; - - cpp::string s("0x"); - char bitsbuf[IntegerToString::hex_bufsize()]; - zerofill(bitsbuf, sizeof(bitsbuf)); - IntegerToString::hex(bits, bitsbuf, false); - s += cpp::string(bitsbuf, sizeof(bitsbuf)); - - s += " = ("; - s += cpp::string("S: ") + (get_sign() ? "1" : "0"); - - char expbuf[IntegerToString::hex_bufsize()]; - zerofill(expbuf, sizeof(expbuf)); - IntegerToString::hex(get_unbiased_exponent(), expbuf, false); - s += cpp::string(", E: 0x") + cpp::string(expbuf, sizeof(expbuf)); - - char mantbuf[IntegerToString::hex_bufsize()] = {'0'}; - zerofill(mantbuf, sizeof(mantbuf)); - IntegerToString::hex(get_mantissa(), mantbuf, false); - s += cpp::string(", M: 0x") + cpp::string(mantbuf, sizeof(mantbuf)); - - s += ")"; - return s; - } }; } // namespace fputil diff --git a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h --- a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h +++ b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h @@ -10,10 +10,8 @@ #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_LONG_DOUBLE_BITS_H #include "src/__support/CPP/bit.h" -#include "src/__support/CPP/string.h" #include "src/__support/UInt128.h" #include "src/__support/common.h" -#include "src/__support/integer_to_string.h" #include "src/__support/macros/properties/architectures.h" #if !defined(LIBC_TARGET_ARCH_IS_X86) @@ -209,50 +207,6 @@ result.set_mantissa(mantissa); return result; } - - // Converts the bits to a string in the following format: - // "0x = S: N, E: 0xNNNN, I: N, M:0xNNN...N" - // 1. N is a hexadecimal digit. - // 2. "I" denotes the implicit bit. - // 3. The hexadecimal number on the LHS is the raw numerical representation - // of the bits. - // 4. The exponent is always 16 bits wide irrespective of the type of the - // floating encoding. - LIBC_INLINE cpp::string str() const { - if (is_nan()) - return "(NaN)"; - if (is_inf()) - return get_sign() ? "(-Infinity)" : "(+Infinity)"; - - auto zerofill = [](char *arr, size_t n) { - for (size_t i = 0; i < n; ++i) - arr[i] = '0'; - }; - - cpp::string s("0x"); - char bitsbuf[IntegerToString::hex_bufsize()] = {'0'}; - zerofill(bitsbuf, sizeof(bitsbuf)); - IntegerToString::hex(bits, bitsbuf, false); - s += cpp::string(bitsbuf, sizeof(bitsbuf)); - - s += " = ("; - s += cpp::string("S: ") + (get_sign() ? "1" : "0"); - - char expbuf[IntegerToString::hex_bufsize()] = {'0'}; - zerofill(expbuf, sizeof(expbuf)); - IntegerToString::hex(get_unbiased_exponent(), expbuf, false); - s += cpp::string(", E: 0x") + cpp::string(expbuf, sizeof(expbuf)); - - s += cpp::string(", I: ") + (get_implicit_bit() ? "1" : "0"); - - char mantbuf[IntegerToString::hex_bufsize()] = {'0'}; - zerofill(mantbuf, sizeof(mantbuf)); - IntegerToString::hex(get_mantissa(), mantbuf, false); - s += cpp::string(", M: 0x") + cpp::string(mantbuf, sizeof(mantbuf)); - - s += ")"; - return s; - } }; static_assert( diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt --- a/libc/test/UnitTest/CMakeLists.txt +++ b/libc/test/UnitTest/CMakeLists.txt @@ -95,6 +95,8 @@ DEPENDS libc.src.__support.CPP.string libc.src.__support.CPP.type_traits + libc.src.__support.FPUtil.fp_bits + libc.src.__support.integer_to_string ) add_unittest_framework_library( @@ -109,7 +111,6 @@ libc.test.UnitTest.string_utils libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.fenv_impl - libc.test.UnitTest.string_utils ) add_unittest_framework_library( diff --git a/libc/test/UnitTest/ErrnoSetterMatcher.h b/libc/test/UnitTest/ErrnoSetterMatcher.h --- a/libc/test/UnitTest/ErrnoSetterMatcher.h +++ b/libc/test/UnitTest/ErrnoSetterMatcher.h @@ -13,6 +13,7 @@ #include "src/__support/StringUtil/error_to_string.h" #include "src/__support/macros/properties/architectures.h" #include "src/errno/libc_errno.h" +#include "test/UnitTest/StringUtils.h" #include "test/UnitTest/Test.h" namespace __llvm_libc { @@ -46,10 +47,10 @@ if constexpr (cpp::is_floating_point_v) { __llvm_libc::testing::tlog << "Expected return value to be: " - << __llvm_libc::fputil::FPBits(ExpectedReturn).str() << '\n'; + << str(__llvm_libc::fputil::FPBits(ExpectedReturn)) << '\n'; __llvm_libc::testing::tlog << " But got: " - << __llvm_libc::fputil::FPBits(ActualReturn).str() << '\n'; + << str(__llvm_libc::fputil::FPBits(ActualReturn)) << '\n'; } else { __llvm_libc::testing::tlog << "Expected return value to be " << ExpectedReturn << " but got " diff --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h --- a/libc/test/UnitTest/FPMatcher.h +++ b/libc/test/UnitTest/FPMatcher.h @@ -24,7 +24,7 @@ static_assert(cpp::is_floating_point_v, "FPMatcher can only be used with floating point values."); static_assert(Condition == TestCond::EQ || Condition == TestCond::NE, - "Unsupported FPMathcer test condition."); + "Unsupported FPMatcher test condition."); T expected; T actual; @@ -48,8 +48,8 @@ void explainError() override { tlog << "Expected floating point value: " - << fputil::FPBits(expected).str() << '\n'; - tlog << "Actual floating point value: " << fputil::FPBits(actual).str() + << str(fputil::FPBits(expected)) << '\n'; + tlog << "Actual floating point value: " << str(fputil::FPBits(actual)) << '\n'; } }; diff --git a/libc/test/UnitTest/StringUtils.h b/libc/test/UnitTest/StringUtils.h --- a/libc/test/UnitTest/StringUtils.h +++ b/libc/test/UnitTest/StringUtils.h @@ -11,6 +11,8 @@ #include "src/__support/CPP/string.h" #include "src/__support/CPP/type_traits.h" +#include "src/__support/FPUtil/FPBits.h" +#include "src/__support/integer_to_string.h" namespace __llvm_libc { @@ -31,6 +33,54 @@ return "0x" + s; } +// Converts the bits to a string in the following format: +// "0x = S: N, E: 0xNNNN, M:0xNNN...N" +// 1. N is a hexadecimal digit. +// 2. The hexadecimal number on the LHS is the raw numerical representation +// of the bits. +// 3. The exponent is always 16 bits wide irrespective of the type of the +// floating encoding. +template LIBC_INLINE cpp::string str(fputil::FPBits x) { + using UIntType = typename fputil::FPBits::UIntType; + + if (x.is_nan()) + return "(NaN)"; + if (x.is_inf()) + return x.get_sign() ? "(-Infinity)" : "(+Infinity)"; + + auto zerofill = [](char *arr, size_t n) { + for (size_t i = 0; i < n; ++i) + arr[i] = '0'; + }; + + cpp::string s("0x"); + char bitsbuf[IntegerToString::hex_bufsize()]; + zerofill(bitsbuf, sizeof(bitsbuf)); + IntegerToString::hex(x.bits, bitsbuf, false); + s += cpp::string(bitsbuf, sizeof(bitsbuf)); + + s += " = ("; + s += cpp::string("S: ") + (x.get_sign() ? "1" : "0"); + + char expbuf[IntegerToString::hex_bufsize()]; + zerofill(expbuf, sizeof(expbuf)); + IntegerToString::hex(x.get_unbiased_exponent(), expbuf, false); + s += cpp::string(", E: 0x") + cpp::string(expbuf, sizeof(expbuf)); + + if constexpr (cpp::is_same_v && + fputil::FloatProperties::MANTISSA_WIDTH == 63) { + s += cpp::string(", I: ") + (x.get_implicit_bit() ? "1" : "0"); + } + + char mantbuf[IntegerToString::hex_bufsize()] = {'0'}; + zerofill(mantbuf, sizeof(mantbuf)); + IntegerToString::hex(x.get_mantissa(), mantbuf, false); + s += cpp::string(", M: 0x") + cpp::string(mantbuf, sizeof(mantbuf)); + + s += ")"; + return s; +} + } // namespace __llvm_libc #endif // LLVM_LIBC_UTILS_UNITTEST_SIMPLE_STRING_CONV_H diff --git a/libc/test/src/__support/FPUtil/fpbits_test.cpp b/libc/test/src/__support/FPUtil/fpbits_test.cpp --- a/libc/test/src/__support/FPUtil/fpbits_test.cpp +++ b/libc/test/src/__support/FPUtil/fpbits_test.cpp @@ -7,22 +7,25 @@ //===----------------------------------------------------------------------===// #include "src/__support/FPUtil/FPBits.h" +#include "test/UnitTest/StringUtils.h" #include "test/UnitTest/Test.h" using __llvm_libc::fputil::FPBits; TEST(LlvmLibcFPBitsTest, FloatType) { - EXPECT_STREQ(FPBits::inf().str().c_str(), "(+Infinity)"); - EXPECT_STREQ(FPBits::neg_inf().str().c_str(), "(-Infinity)"); - EXPECT_STREQ(FPBits(FPBits::build_nan(1)).str().c_str(), - "(NaN)"); + EXPECT_STREQ(__llvm_libc::str(FPBits::inf()).c_str(), "(+Infinity)"); + EXPECT_STREQ(__llvm_libc::str(FPBits::neg_inf()).c_str(), + "(-Infinity)"); + EXPECT_STREQ( + __llvm_libc::str(FPBits(FPBits::build_nan(1))).c_str(), + "(NaN)"); FPBits zero(0.0f); EXPECT_EQ(zero.get_sign(), false); EXPECT_EQ(zero.get_unbiased_exponent(), static_cast(0)); EXPECT_EQ(zero.get_mantissa(), static_cast(0)); EXPECT_EQ(zero.uintval(), static_cast(0x00000000)); - EXPECT_STREQ(zero.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(zero).c_str(), "0x00000000 = (S: 0, E: 0x0000, M: 0x00000000)"); FPBits negzero(-0.0f); @@ -30,7 +33,7 @@ EXPECT_EQ(negzero.get_unbiased_exponent(), static_cast(0)); EXPECT_EQ(negzero.get_mantissa(), static_cast(0)); EXPECT_EQ(negzero.uintval(), static_cast(0x80000000)); - EXPECT_STREQ(negzero.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(negzero).c_str(), "0x80000000 = (S: 1, E: 0x0000, M: 0x00000000)"); FPBits one(1.0f); @@ -38,7 +41,7 @@ EXPECT_EQ(one.get_unbiased_exponent(), static_cast(0x7F)); EXPECT_EQ(one.get_mantissa(), static_cast(0)); EXPECT_EQ(one.uintval(), static_cast(0x3F800000)); - EXPECT_STREQ(one.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(one).c_str(), "0x3F800000 = (S: 0, E: 0x007F, M: 0x00000000)"); FPBits negone(-1.0f); @@ -46,7 +49,7 @@ EXPECT_EQ(negone.get_unbiased_exponent(), static_cast(0x7F)); EXPECT_EQ(negone.get_mantissa(), static_cast(0)); EXPECT_EQ(negone.uintval(), static_cast(0xBF800000)); - EXPECT_STREQ(negone.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(negone).c_str(), "0xBF800000 = (S: 1, E: 0x007F, M: 0x00000000)"); FPBits num(1.125f); @@ -54,7 +57,7 @@ EXPECT_EQ(num.get_unbiased_exponent(), static_cast(0x7F)); EXPECT_EQ(num.get_mantissa(), static_cast(0x00100000)); EXPECT_EQ(num.uintval(), static_cast(0x3F900000)); - EXPECT_STREQ(num.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(num).c_str(), "0x3F900000 = (S: 0, E: 0x007F, M: 0x00100000)"); FPBits negnum(-1.125f); @@ -62,22 +65,24 @@ EXPECT_EQ(negnum.get_unbiased_exponent(), static_cast(0x7F)); EXPECT_EQ(negnum.get_mantissa(), static_cast(0x00100000)); EXPECT_EQ(negnum.uintval(), static_cast(0xBF900000)); - EXPECT_STREQ(negnum.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(negnum).c_str(), "0xBF900000 = (S: 1, E: 0x007F, M: 0x00100000)"); } TEST(LlvmLibcFPBitsTest, DoubleType) { - EXPECT_STREQ(FPBits::inf().str().c_str(), "(+Infinity)"); - EXPECT_STREQ(FPBits::neg_inf().str().c_str(), "(-Infinity)"); - EXPECT_STREQ(FPBits(FPBits::build_nan(1)).str().c_str(), - "(NaN)"); + EXPECT_STREQ(__llvm_libc::str(FPBits::inf()).c_str(), "(+Infinity)"); + EXPECT_STREQ(__llvm_libc::str(FPBits::neg_inf()).c_str(), + "(-Infinity)"); + EXPECT_STREQ( + __llvm_libc::str(FPBits(FPBits::build_nan(1))).c_str(), + "(NaN)"); FPBits zero(0.0); EXPECT_EQ(zero.get_sign(), false); EXPECT_EQ(zero.get_unbiased_exponent(), static_cast(0x0000)); EXPECT_EQ(zero.get_mantissa(), static_cast(0x0000000000000000)); EXPECT_EQ(zero.uintval(), static_cast(0x0000000000000000)); - EXPECT_STREQ(zero.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(zero).c_str(), "0x0000000000000000 = (S: 0, E: 0x0000, M: 0x0000000000000000)"); FPBits negzero(-0.0); @@ -85,7 +90,7 @@ EXPECT_EQ(negzero.get_unbiased_exponent(), static_cast(0x0000)); EXPECT_EQ(negzero.get_mantissa(), static_cast(0x0000000000000000)); EXPECT_EQ(negzero.uintval(), static_cast(0x8000000000000000)); - EXPECT_STREQ(negzero.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(negzero).c_str(), "0x8000000000000000 = (S: 1, E: 0x0000, M: 0x0000000000000000)"); FPBits one(1.0); @@ -93,7 +98,7 @@ EXPECT_EQ(one.get_unbiased_exponent(), static_cast(0x03FF)); EXPECT_EQ(one.get_mantissa(), static_cast(0x0000000000000000)); EXPECT_EQ(one.uintval(), static_cast(0x3FF0000000000000)); - EXPECT_STREQ(one.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(one).c_str(), "0x3FF0000000000000 = (S: 0, E: 0x03FF, M: 0x0000000000000000)"); FPBits negone(-1.0); @@ -101,7 +106,7 @@ EXPECT_EQ(negone.get_unbiased_exponent(), static_cast(0x03FF)); EXPECT_EQ(negone.get_mantissa(), static_cast(0x0000000000000000)); EXPECT_EQ(negone.uintval(), static_cast(0xBFF0000000000000)); - EXPECT_STREQ(negone.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(negone).c_str(), "0xBFF0000000000000 = (S: 1, E: 0x03FF, M: 0x0000000000000000)"); FPBits num(1.125); @@ -109,7 +114,7 @@ EXPECT_EQ(num.get_unbiased_exponent(), static_cast(0x03FF)); EXPECT_EQ(num.get_mantissa(), static_cast(0x0002000000000000)); EXPECT_EQ(num.uintval(), static_cast(0x3FF2000000000000)); - EXPECT_STREQ(num.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(num).c_str(), "0x3FF2000000000000 = (S: 0, E: 0x03FF, M: 0x0002000000000000)"); FPBits negnum(-1.125); @@ -117,7 +122,7 @@ EXPECT_EQ(negnum.get_unbiased_exponent(), static_cast(0x03FF)); EXPECT_EQ(negnum.get_mantissa(), static_cast(0x0002000000000000)); EXPECT_EQ(negnum.uintval(), static_cast(0xBFF2000000000000)); - EXPECT_STREQ(negnum.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(negnum).c_str(), "0xBFF2000000000000 = (S: 1, E: 0x03FF, M: 0x0002000000000000)"); } @@ -126,10 +131,13 @@ if constexpr (sizeof(long double) == sizeof(double)) return; // The tests for the "double" type cover for this case. - EXPECT_STREQ(FPBits::inf().str().c_str(), "(+Infinity)"); - EXPECT_STREQ(FPBits::neg_inf().str().c_str(), "(-Infinity)"); + EXPECT_STREQ(__llvm_libc::str(FPBits::inf()).c_str(), + "(+Infinity)"); + EXPECT_STREQ(__llvm_libc::str(FPBits::neg_inf()).c_str(), + "(-Infinity)"); EXPECT_STREQ( - FPBits(FPBits::build_nan(1)).str().c_str(), + __llvm_libc::str(FPBits(FPBits::build_nan(1))) + .c_str(), "(NaN)"); FPBits zero(0.0l); @@ -139,7 +147,7 @@ << 64); EXPECT_EQ(zero.uintval(), static_cast(0x0000000000000000) << 64); EXPECT_STREQ( - zero.str().c_str(), + __llvm_libc::str(zero).c_str(), "0x00000000000000000000000000000000 = " "(S: 0, E: 0x0000, I: 0, M: 0x00000000000000000000000000000000)"); @@ -150,7 +158,7 @@ << 64); EXPECT_EQ(negzero.uintval(), static_cast(0x1) << 79); EXPECT_STREQ( - negzero.str().c_str(), + __llvm_libc::str(negzero).c_str(), "0x00000000000080000000000000000000 = " "(S: 1, E: 0x0000, I: 0, M: 0x00000000000000000000000000000000)"); @@ -160,7 +168,7 @@ EXPECT_EQ(one.get_mantissa(), static_cast(0x0000000000000000) << 64); EXPECT_EQ(one.uintval(), static_cast(0x3FFF8) << 60); EXPECT_STREQ( - one.str().c_str(), + __llvm_libc::str(one).c_str(), "0x0000000000003FFF8000000000000000 = " "(S: 0, E: 0x3FFF, I: 1, M: 0x00000000000000000000000000000000)"); @@ -171,7 +179,7 @@ << 64); EXPECT_EQ(negone.uintval(), static_cast(0xBFFF8) << 60); EXPECT_STREQ( - negone.str().c_str(), + __llvm_libc::str(negone).c_str(), "0x000000000000BFFF8000000000000000 = " "(S: 1, E: 0x3FFF, I: 1, M: 0x00000000000000000000000000000000)"); @@ -181,7 +189,7 @@ EXPECT_EQ(num.get_mantissa(), static_cast(0x1) << 60); EXPECT_EQ(num.uintval(), static_cast(0x3FFF9) << 60); EXPECT_STREQ( - num.str().c_str(), + __llvm_libc::str(num).c_str(), "0x0000000000003FFF9000000000000000 = " "(S: 0, E: 0x3FFF, I: 1, M: 0x00000000000000001000000000000000)"); @@ -191,7 +199,7 @@ EXPECT_EQ(negnum.get_mantissa(), static_cast(0x1) << 60); EXPECT_EQ(negnum.uintval(), static_cast(0xBFFF9) << 60); EXPECT_STREQ( - negnum.str().c_str(), + __llvm_libc::str(negnum).c_str(), "0x000000000000BFFF9000000000000000 = " "(S: 1, E: 0x3FFF, I: 1, M: 0x00000000000000001000000000000000)"); } @@ -200,10 +208,13 @@ #if defined(LONG_DOUBLE_IS_DOUBLE) return; // The tests for the "double" type cover for this case. #else - EXPECT_STREQ(FPBits::inf().str().c_str(), "(+Infinity)"); - EXPECT_STREQ(FPBits::neg_inf().str().c_str(), "(-Infinity)"); + EXPECT_STREQ(__llvm_libc::str(FPBits::inf()).c_str(), + "(+Infinity)"); + EXPECT_STREQ(__llvm_libc::str(FPBits::neg_inf()).c_str(), + "(-Infinity)"); EXPECT_STREQ( - FPBits(FPBits::build_nan(1)).str().c_str(), + __llvm_libc::str(FPBits(FPBits::build_nan(1))) + .c_str(), "(NaN)"); FPBits zero(0.0l); @@ -212,7 +223,7 @@ EXPECT_EQ(zero.get_mantissa(), static_cast(0x0000000000000000) << 64); EXPECT_EQ(zero.uintval(), static_cast(0x0000000000000000) << 64); - EXPECT_STREQ(zero.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(zero).c_str(), "0x00000000000000000000000000000000 = " "(S: 0, E: 0x0000, M: 0x00000000000000000000000000000000)"); @@ -222,7 +233,7 @@ EXPECT_EQ(negzero.get_mantissa(), static_cast(0x0000000000000000) << 64); EXPECT_EQ(negzero.uintval(), static_cast(0x1) << 127); - EXPECT_STREQ(negzero.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(negzero).c_str(), "0x80000000000000000000000000000000 = " "(S: 1, E: 0x0000, M: 0x00000000000000000000000000000000)"); @@ -231,7 +242,7 @@ EXPECT_EQ(one.get_unbiased_exponent(), static_cast(0x3FFF)); EXPECT_EQ(one.get_mantissa(), static_cast(0x0000000000000000) << 64); EXPECT_EQ(one.uintval(), static_cast(0x3FFF) << 112); - EXPECT_STREQ(one.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(one).c_str(), "0x3FFF0000000000000000000000000000 = " "(S: 0, E: 0x3FFF, M: 0x00000000000000000000000000000000)"); @@ -241,7 +252,7 @@ EXPECT_EQ(negone.get_mantissa(), static_cast(0x0000000000000000) << 64); EXPECT_EQ(negone.uintval(), static_cast(0xBFFF) << 112); - EXPECT_STREQ(negone.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(negone).c_str(), "0xBFFF0000000000000000000000000000 = " "(S: 1, E: 0x3FFF, M: 0x00000000000000000000000000000000)"); @@ -250,7 +261,7 @@ EXPECT_EQ(num.get_unbiased_exponent(), static_cast(0x3FFF)); EXPECT_EQ(num.get_mantissa(), static_cast(0x2) << 108); EXPECT_EQ(num.uintval(), static_cast(0x3FFF2) << 108); - EXPECT_STREQ(num.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(num).c_str(), "0x3FFF2000000000000000000000000000 = " "(S: 0, E: 0x3FFF, M: 0x00002000000000000000000000000000)"); @@ -259,7 +270,7 @@ EXPECT_EQ(negnum.get_unbiased_exponent(), static_cast(0x3FFF)); EXPECT_EQ(negnum.get_mantissa(), static_cast(0x2) << 108); EXPECT_EQ(negnum.uintval(), static_cast(0xBFFF2) << 108); - EXPECT_STREQ(negnum.str().c_str(), + EXPECT_STREQ(__llvm_libc::str(negnum).c_str(), "0xBFFF2000000000000000000000000000 = " "(S: 1, E: 0x3FFF, M: 0x00002000000000000000000000000000)"); #endif diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp --- a/libc/utils/MPFRWrapper/MPFRUtils.cpp +++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp @@ -694,11 +694,11 @@ MPFRNumber mpfrMatchValue(matchValue); tlog << "Match value not within tolerance value of MPFR result:\n" << " Input decimal: " << mpfrInput.str() << '\n'; - tlog << " Input bits: " << FPBits(input).str() << '\n'; + tlog << " Input bits: " << str(FPBits(input)) << '\n'; tlog << '\n' << " Match decimal: " << mpfrMatchValue.str() << '\n'; - tlog << " Match bits: " << FPBits(matchValue).str() << '\n'; + tlog << " Match bits: " << str(FPBits(matchValue)) << '\n'; tlog << '\n' << " MPFR result: " << mpfr_result.str() << '\n'; - tlog << " MPFR rounded: " << FPBits(mpfr_result.as()).str() << '\n'; + tlog << " MPFR rounded: " << str(FPBits(mpfr_result.as())) << '\n'; tlog << '\n'; tlog << " ULP error: " << mpfr_result.ulp_as_mpfr_number(matchValue).str() << '\n'; @@ -738,12 +738,12 @@ tlog << " Input decimal: " << mpfrInput.str() << "\n\n"; tlog << "Libc floating point value: " << mpfrMatchValue.str() << '\n'; - tlog << " Libc floating point bits: " << FPBits(libc_result.f).str() + tlog << " Libc floating point bits: " << str(FPBits(libc_result.f)) << '\n'; tlog << "\n\n"; tlog << " MPFR result: " << mpfr_result.str() << '\n'; - tlog << " MPFR rounded: " << FPBits(mpfr_result.as()).str() + tlog << " MPFR rounded: " << str(FPBits(mpfr_result.as())) << '\n'; tlog << '\n' << " ULP error: " @@ -776,10 +776,10 @@ << "Libc integral result: " << libc_result.i << '\n' << "Libc floating point result: " << mpfrMatchValue.str() << '\n' << " MPFR result: " << mpfr_result.str() << '\n'; - tlog << "Libc floating point result bits: " << FPBits(libc_result.f).str() + tlog << "Libc floating point result bits: " << str(FPBits(libc_result.f)) << '\n'; tlog << " MPFR rounded bits: " - << FPBits(mpfr_result.as()).str() << '\n'; + << str(FPBits(mpfr_result.as())) << '\n'; tlog << "ULP error: " << mpfr_result.ulp_as_mpfr_number(libc_result.f).str() << '\n'; } @@ -810,15 +810,15 @@ MPFRNumber mpfrMatchValue(libc_result); tlog << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str() << '\n'; - tlog << "First input bits: " << FPBits(input.x).str() << '\n'; - tlog << "Second input bits: " << FPBits(input.y).str() << '\n'; + tlog << "First input bits: " << str(FPBits(input.x)) << '\n'; + tlog << "Second input bits: " << str(FPBits(input.y)) << '\n'; tlog << "Libc result: " << mpfrMatchValue.str() << '\n' << "MPFR result: " << mpfr_result.str() << '\n'; - tlog << "Libc floating point result bits: " << FPBits(libc_result).str() + tlog << "Libc floating point result bits: " << str(FPBits(libc_result)) << '\n'; tlog << " MPFR rounded bits: " - << FPBits(mpfr_result.as()).str() << '\n'; + << str(FPBits(mpfr_result.as())) << '\n'; tlog << "ULP error: " << mpfr_result.ulp_as_mpfr_number(libc_result).str() << '\n'; } @@ -850,16 +850,16 @@ tlog << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str() << " z: " << mpfrZ.str() << '\n'; - tlog << " First input bits: " << FPBits(input.x).str() << '\n'; - tlog << "Second input bits: " << FPBits(input.y).str() << '\n'; - tlog << " Third input bits: " << FPBits(input.z).str() << '\n'; + tlog << " First input bits: " << str(FPBits(input.x)) << '\n'; + tlog << "Second input bits: " << str(FPBits(input.y)) << '\n'; + tlog << " Third input bits: " << str(FPBits(input.z)) << '\n'; tlog << "Libc result: " << mpfrMatchValue.str() << '\n' << "MPFR result: " << mpfr_result.str() << '\n'; - tlog << "Libc floating point result bits: " << FPBits(libc_result).str() + tlog << "Libc floating point result bits: " << str(FPBits(libc_result)) << '\n'; tlog << " MPFR rounded bits: " - << FPBits(mpfr_result.as()).str() << '\n'; + << str(FPBits(mpfr_result.as())) << '\n'; tlog << "ULP error: " << mpfr_result.ulp_as_mpfr_number(libc_result).str() << '\n'; } diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -569,11 +569,9 @@ ":__support_builtin_wrappers", ":__support_common", ":__support_cpp_bit", - ":__support_cpp_string", ":__support_cpp_type_traits", ":__support_fputil_float_properties", ":__support_fputil_platform_defs", - ":__support_integer_to_string", ":__support_uint128", ":libc_root", ], diff --git a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel @@ -37,6 +37,7 @@ ], deps = [ ":test_logger", + ":string_utils", "//libc:__support_c_string", "//libc:__support_cpp_bit", "//libc:__support_cpp_bitset", @@ -119,5 +120,7 @@ deps = [ "//libc:__support_cpp_string", "//libc:__support_cpp_type_traits", + "//libc:__support_fputil_fp_bits", + "//libc:__support_integer_to_string", ], )