Skip to content

Commit

Permalink
[libc][NFC] rename LONG_DOUBLE_IS_DOUBLE into LIBC_LONG_DOUBLE_IS_FLO…
Browse files Browse the repository at this point in the history
…AT64 (#73948)
  • Loading branch information
gchatelet committed Dec 1, 2023
1 parent 85184b4 commit 808b7d2
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 38 deletions.
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/generic/sqrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ LIBC_INLINE void normalize(int &exponent,
mantissa <<= shift;
}

#ifdef LONG_DOUBLE_IS_DOUBLE
#ifdef LIBC_LONG_DOUBLE_IS_FLOAT64
template <>
LIBC_INLINE void normalize<long double>(int &exponent, uint64_t &mantissa) {
normalize<double>(exponent, mantissa);
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/FPUtil/x86_64/sqrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ template <> LIBC_INLINE double sqrt<double>(double x) {
return result;
}

#ifdef LONG_DOUBLE_IS_DOUBLE
#ifdef LIBC_LONG_DOUBLE_IS_FLOAT64
template <> LIBC_INLINE long double sqrt<long double>(long double x) {
long double result;
__asm__ __volatile__("sqrtsd %x1, %x0" : "=x"(result) : "x"(x));
Expand Down
4 changes: 2 additions & 2 deletions libc/src/__support/float_to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ class FloatToString {
}
};

#ifndef LONG_DOUBLE_IS_DOUBLE
#ifndef LIBC_LONG_DOUBLE_IS_FLOAT64
// --------------------------- LONG DOUBLE FUNCTIONS ---------------------------

template <>
Expand Down Expand Up @@ -754,7 +754,7 @@ FloatToString<long double>::get_negative_block(int block_index) {
}
}

#endif // LONG_DOUBLE_IS_DOUBLE
#endif // LIBC_LONG_DOUBLE_IS_FLOAT64

} // namespace LIBC_NAMESPACE

Expand Down
8 changes: 3 additions & 5 deletions libc/src/__support/macros/properties/float.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
#include <float.h> // LDBL_MANT_DIG

// 'long double' properties.
#if (LDBL_MANT_DIG == DBL_MANT_DIG)
// TODO: Replace with LIBC_LONG_DOUBLE_IS_DOUBLE
#define LONG_DOUBLE_IS_DOUBLE
#endif
#if (LDBL_MANT_DIG == 64)
#if (LDBL_MANT_DIG == 53)
#define LIBC_LONG_DOUBLE_IS_FLOAT64
#elif (LDBL_MANT_DIG == 64)
// TODO: Replace with LIBC_LONG_DOUBLE_IS_X86_BIN80
#define SPECIAL_X86_LONG_DOUBLE
#elif (LDBL_MANT_DIG == 113)
Expand Down
4 changes: 2 additions & 2 deletions libc/src/__support/str_to_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ eisel_lemire(ExpandedFloat<T> init_num,
return output;
}

#if !defined(LONG_DOUBLE_IS_DOUBLE)
#if !defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
template <>
LIBC_INLINE cpp::optional<ExpandedFloat<long double>>
eisel_lemire<long double>(ExpandedFloat<long double> init_num,
Expand Down Expand Up @@ -516,7 +516,7 @@ template <> class ClingerConsts<double> {
static constexpr double MAX_EXACT_INT = 9007199254740991.0;
};

#if defined(LONG_DOUBLE_IS_DOUBLE)
#if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
template <> class ClingerConsts<long double> {
public:
static constexpr long double POWERS_OF_TEN_ARRAY[] = {
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/__support/FPUtil/fpbits_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ TEST(LlvmLibcFPBitsTest, X86LongDoubleType) {
}
#else
TEST(LlvmLibcFPBitsTest, LongDoubleType) {
#if defined(LONG_DOUBLE_IS_DOUBLE)
#if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
return; // The tests for the "double" type cover for this case.
#else
using LongDoubleBits = FPBits<long double>;
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/__support/str_to_float_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ TEST(LlvmLibcStrToFloatTest, SimpleDecimalConversionExtraTypes) {
EXPECT_EQ(double_result.error, 0);
}

#if defined(LONG_DOUBLE_IS_DOUBLE)
#if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
TEST_F(LlvmLibcStrToFloatTest, EiselLemireFloat64AsLongDouble) {
eisel_lemire_test<long double>(123, 0, 0x1EC00000000000, 1029);
}
Expand Down
44 changes: 22 additions & 22 deletions libc/test/src/stdio/sprintf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 0.1L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xc.ccccccccccccccdp-7");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x1.999999999999ap-4");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.999999999999999999999999999ap-4");
Expand All @@ -653,7 +653,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 1.0e1000L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xf.38db1f9dd3dac05p+3318");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "inf");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.e71b63f3ba7b580af1a52d2a7379p+3321");
Expand All @@ -662,7 +662,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 1.0e-1000L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0x8.68a9188a89e1467p-3325");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x0p+0");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.0d152311513c28ce202627c06ec2p-3322");
Expand Down Expand Up @@ -768,7 +768,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%.1La", 0.1L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xc.dp-7");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x1.ap-4");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.ap-4");
Expand All @@ -777,7 +777,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatHexExpConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%.1La", 0xf.fffffffffffffffp16380L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0x1.0p+16384");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "inf");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x2.0p+16383");
Expand Down Expand Up @@ -1024,14 +1024,14 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {

// Some float128 systems (specifically the ones used for aarch64 buildbots)
// don't respect signs for long double NaNs.
#if defined(SPECIAL_X86_LONG_DOUBLE) || defined(LONG_DOUBLE_IS_DOUBLE)
#if defined(SPECIAL_X86_LONG_DOUBLE) || defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
written = LIBC_NAMESPACE::sprintf(buff, "%LF", -ld_nan);
ASSERT_STREQ_LEN(written, buff, "-NAN");
#endif

// Length Modifier Tests.

// TODO(michaelrj): Add tests for LONG_DOUBLE_IS_DOUBLE and 128 bit long
// TODO(michaelrj): Add tests for LIBC_LONG_DOUBLE_IS_FLOAT64 and 128 bit long
// double systems.
// TODO(michaelrj): Fix the tests to only depend on the digits the long double
// is accurate for.
Expand Down Expand Up @@ -1333,7 +1333,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 0.1L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xc.ccccccccccccccdp-7");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x1.999999999999ap-4");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.999999999999999999999999999ap-4");
Expand All @@ -1342,7 +1342,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 1.0e1000L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xf.38db1f9dd3dac05p+3318");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "inf");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.e71b63f3ba7b580af1a52d2a7379p+3321");
Expand All @@ -1351,7 +1351,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 1.0e-1000L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0x8.68a9188a89e1467p-3325");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x0p+0");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.0d152311513c28ce202627c06ec2p-3322");
Expand Down Expand Up @@ -1550,7 +1550,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%.1La", 0.1L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xc.dp-7");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x1.ap-4");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.ap-4");
Expand All @@ -1559,7 +1559,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatDecimalConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%.1La",
0xf.fffffffffffffffp16380L); #if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0x1.0p+16384");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "inf");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x2.0p+16383");
Expand Down Expand Up @@ -1977,7 +1977,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 0.1L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xc.ccccccccccccccdp-7");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x1.999999999999ap-4");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.999999999999999999999999999ap-4");
Expand All @@ -1986,7 +1986,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 1.0e1000L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xf.38db1f9dd3dac05p+3318");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "inf");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.e71b63f3ba7b580af1a52d2a7379p+3321");
Expand All @@ -1995,7 +1995,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 1.0e-1000L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0x8.68a9188a89e1467p-3325");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x0p+0");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.0d152311513c28ce202627c06ec2p-3322");
Expand Down Expand Up @@ -2173,7 +2173,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%.1La", 0.1L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xc.dp-7");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x1.ap-4");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.ap-4");
Expand All @@ -2182,7 +2182,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatExponentConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%.1La",
0xf.fffffffffffffffp16380L); #if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0x1.0p+16384");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "inf");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x2.0p+16383");
Expand Down Expand Up @@ -2616,7 +2616,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 0.1L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xc.ccccccccccccccdp-7");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x1.999999999999ap-4");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.999999999999999999999999999ap-4");
Expand All @@ -2625,7 +2625,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 1.0e1000L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xf.38db1f9dd3dac05p+3318");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "inf");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.e71b63f3ba7b580af1a52d2a7379p+3321");
Expand All @@ -2634,7 +2634,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%La", 1.0e-1000L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0x8.68a9188a89e1467p-3325");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x0p+0");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.0d152311513c28ce202627c06ec2p-3322");
Expand Down Expand Up @@ -2822,7 +2822,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%.1La", 0.1L);
#if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0xc.dp-7");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "0x1.ap-4");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x1.ap-4");
Expand All @@ -2831,7 +2831,7 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoConv) {
written = LIBC_NAMESPACE::sprintf(buff, "%.1La",
0xf.fffffffffffffffp16380L); #if defined(SPECIAL_X86_LONG_DOUBLE)
ASSERT_STREQ_LEN(written, buff, "0x1.0p+16384");
#elif defined(LONG_DOUBLE_IS_DOUBLE)
#elif defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
ASSERT_STREQ_LEN(written, buff, "inf");
#else // 128 bit long double
ASSERT_STREQ_LEN(written, buff, "0x2.0p+16383");
Expand Down
2 changes: 1 addition & 1 deletion libc/test/src/stdio/sscanf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ TEST(LlvmLibcSScanfTest, FloatConvLengthModifier) {
EXPECT_EQ(ret_val, 1);
// 1e600 may be larger than the maximum long double (if long double is double).
// In that case both of these should be evaluated as inf.
#ifdef LONG_DOUBLE_IS_DOUBLE
#ifdef LIBC_LONG_DOUBLE_IS_FLOAT64
EXPECT_FP_EQ(ld_result, d_inf);
#else
EXPECT_FP_EQ(ld_result, 1.0e600L);
Expand Down
4 changes: 2 additions & 2 deletions libc/test/src/stdlib/strtold_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <limits.h>
#include <stddef.h>

#if defined(LONG_DOUBLE_IS_DOUBLE)
#if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
#define SELECT_CONST(val, _, __) val
#elif defined(SPECIAL_X86_LONG_DOUBLE)
#define SELECT_CONST(_, val, __) val
Expand All @@ -26,7 +26,7 @@

class LlvmLibcStrToLDTest : public LIBC_NAMESPACE::testing::Test {
public:
#if defined(LONG_DOUBLE_IS_DOUBLE)
#if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
void run_test(const char *inputString, const ptrdiff_t expectedStrLen,
const uint64_t expectedRawData, const int expectedErrno = 0)
#else
Expand Down

0 comments on commit 808b7d2

Please sign in to comment.