Skip to content

Commit

Permalink
[libc][NFC] Rename LIBC_LONG_DOUBLE_IS_ macros (#83399)
Browse files Browse the repository at this point in the history
Umbrella bug #83182
  • Loading branch information
gchatelet authored Mar 4, 2024
1 parent ded5de1 commit f7d4236
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 92 deletions.
4 changes: 2 additions & 2 deletions libc/src/__support/FPUtil/ManipulationFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ LIBC_INLINE T nextafter(T from, U to) {
} // namespace fputil
} // namespace LIBC_NAMESPACE

#ifdef LIBC_LONG_DOUBLE_IS_X86_FLOAT80
#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
#include "x86_64/NextAfterLongDouble.h"
#endif // LIBC_LONG_DOUBLE_IS_X86_FLOAT80
#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80

#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_MANIPULATIONFUNCTIONS_H
4 changes: 2 additions & 2 deletions libc/src/__support/FPUtil/NormalFloat.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ template <typename T> struct NormalFloat {
}
};

#ifdef LIBC_LONG_DOUBLE_IS_X86_FLOAT80
#ifdef LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
template <>
LIBC_INLINE void
NormalFloat<long double>::init_from_bits(FPBits<long double> bits) {
Expand Down Expand Up @@ -261,7 +261,7 @@ template <> LIBC_INLINE NormalFloat<long double>::operator long double() const {
result.set_implicit_bit(1);
return result.get_val();
}
#endif // LIBC_LONG_DOUBLE_IS_X86_FLOAT80
#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80

} // namespace fputil
} // namespace LIBC_NAMESPACE
Expand Down
8 changes: 4 additions & 4 deletions libc/src/__support/FPUtil/generic/sqrt.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ template <typename T> struct SpecialLongDouble {
static constexpr bool VALUE = false;
};

#if defined(LIBC_LONG_DOUBLE_IS_X86_FLOAT80)
#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80)
template <> struct SpecialLongDouble<long double> {
static constexpr bool VALUE = true;
};
#endif // LIBC_LONG_DOUBLE_IS_X86_FLOAT80
#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80

template <typename T>
LIBC_INLINE void normalize(int &exponent,
Expand All @@ -43,12 +43,12 @@ LIBC_INLINE void normalize(int &exponent,
mantissa <<= shift;
}

#ifdef LIBC_LONG_DOUBLE_IS_FLOAT64
#ifdef LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
template <>
LIBC_INLINE void normalize<long double>(int &exponent, uint64_t &mantissa) {
normalize<double>(exponent, mantissa);
}
#elif !defined(LIBC_LONG_DOUBLE_IS_X86_FLOAT80)
#elif !defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80)
template <>
LIBC_INLINE void normalize<long double>(int &exponent, UInt128 &mantissa) {
const uint64_t hi_bits = static_cast<uint64_t>(mantissa >> 64);
Expand Down
4 changes: 2 additions & 2 deletions libc/src/__support/FPUtil/generic/sqrt_80_bit_long_double.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ LIBC_INLINE long double sqrt(long double x);

// Correctly rounded SQRT for all rounding modes.
// Shift-and-add algorithm.
#if defined(LIBC_LONG_DOUBLE_IS_X86_FLOAT80)
#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80)
LIBC_INLINE long double sqrt(long double x) {
using LDBits = FPBits<long double>;
using StorageType = typename LDBits::StorageType;
Expand Down Expand Up @@ -130,7 +130,7 @@ LIBC_INLINE long double sqrt(long double x) {
return out.get_val();
}
}
#endif // LIBC_LONG_DOUBLE_IS_X86_FLOAT80
#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80

} // namespace x86
} // namespace fputil
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 LIBC_LONG_DOUBLE_IS_FLOAT64
#ifdef LIBC_TYPES_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 @@ -615,7 +615,7 @@ class FloatToString {
}
};

#if !defined(LIBC_LONG_DOUBLE_IS_FLOAT64) && \
#if !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64) && \
!defined(LIBC_COPT_FLOAT_TO_STR_NO_SPECIALIZE_LD)
// --------------------------- LONG DOUBLE FUNCTIONS ---------------------------

Expand Down Expand Up @@ -837,7 +837,7 @@ template <> class FloatToString<long double> {
}
};

#endif // !LIBC_LONG_DOUBLE_IS_FLOAT64 &&
#endif // !LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64 &&
// !LIBC_COPT_FLOAT_TO_STR_NO_SPECIALIZE_LD

} // namespace LIBC_NAMESPACE
Expand Down
8 changes: 4 additions & 4 deletions libc/src/__support/macros/properties/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

// 'long double' properties.
#if (LDBL_MANT_DIG == 53)
#define LIBC_LONG_DOUBLE_IS_FLOAT64
#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
#elif (LDBL_MANT_DIG == 64)
#define LIBC_LONG_DOUBLE_IS_X86_FLOAT80
#define LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
#elif (LDBL_MANT_DIG == 113)
#define LIBC_LONG_DOUBLE_IS_FLOAT128
#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
#endif

// float16 support.
Expand Down Expand Up @@ -53,7 +53,7 @@ using float16 = _Float16;
// float128 support.
#if defined(LIBC_COMPILER_HAS_C23_FLOAT128) || \
defined(LIBC_COMPILER_HAS_FLOAT128_EXTENSION) || \
defined(LIBC_LONG_DOUBLE_IS_FLOAT128)
defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128)
#define LIBC_TYPES_HAS_FLOAT128
#endif

Expand Down
16 changes: 9 additions & 7 deletions libc/src/__support/str_to_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ template <class T> LIBC_INLINE void set_implicit_bit(fputil::FPBits<T> &) {
return;
}

#if defined(LIBC_LONG_DOUBLE_IS_X86_FLOAT80)
#if defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80)
template <>
LIBC_INLINE void
set_implicit_bit<long double>(fputil::FPBits<long double> &result) {
result.set_implicit_bit(result.get_biased_exponent() != 0);
}
#endif
#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80

// This Eisel-Lemire implementation is based on the algorithm described in the
// paper Number Parsing at a Gigabyte per Second, Software: Practice and
Expand Down Expand Up @@ -176,7 +176,7 @@ eisel_lemire(ExpandedFloat<T> init_num,
return output;
}

#if !defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
#if !defined(LIBC_TYPES_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 @@ -297,7 +297,7 @@ eisel_lemire<long double>(ExpandedFloat<long double> init_num,
output.exponent = exp2;
return output;
}
#endif
#endif // !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)

// The nth item in POWERS_OF_TWO represents the greatest power of two less than
// 10^n. This tells us how much we can safely shift without overshooting.
Expand Down Expand Up @@ -460,7 +460,7 @@ template <> class ClingerConsts<double> {
static constexpr double MAX_EXACT_INT = 9007199254740991.0;
};

#if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
#if defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)
template <> class ClingerConsts<long double> {
public:
static constexpr long double POWERS_OF_TEN_ARRAY[] = {
Expand All @@ -473,7 +473,7 @@ template <> class ClingerConsts<long double> {
static constexpr long double MAX_EXACT_INT =
ClingerConsts<double>::MAX_EXACT_INT;
};
#elif defined(LIBC_LONG_DOUBLE_IS_X86_FLOAT80)
#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80)
template <> class ClingerConsts<long double> {
public:
static constexpr long double POWERS_OF_TEN_ARRAY[] = {
Expand All @@ -484,7 +484,7 @@ template <> class ClingerConsts<long double> {
static constexpr int32_t DIGITS_IN_MANTISSA = 21;
static constexpr long double MAX_EXACT_INT = 18446744073709551615.0L;
};
#else
#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128)
template <> class ClingerConsts<long double> {
public:
static constexpr long double POWERS_OF_TEN_ARRAY[] = {
Expand All @@ -498,6 +498,8 @@ template <> class ClingerConsts<long double> {
static constexpr long double MAX_EXACT_INT =
10384593717069655257060992658440191.0L;
};
#else
#error "Unknown long double type"
#endif

// Take an exact mantissa and exponent and attempt to convert it using only
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 @@ -503,7 +503,7 @@ TEST(LlvmLibcFPBitsTest, X86LongDoubleType) {
}
#else
TEST(LlvmLibcFPBitsTest, LongDoubleType) {
#if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
#if defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)
return; // The tests for the "double" type cover for this case.
#else
using LongDoubleBits = FPBits<long double>;
Expand Down
8 changes: 5 additions & 3 deletions libc/test/src/__support/str_to_long_double_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace LIBC_NAMESPACE {
using LlvmLibcStrToLongDblTest = LlvmLibcStrToFloatTest<long double>;
using LIBC_NAMESPACE::operator""_u128;

#if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
#if defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)

TEST_F(LlvmLibcStrToLongDblTest, EiselLemireFloat64AsLongDouble) {
eisel_lemire_test(123, 0, 0x1EC00000000000, 1029);
}

#elif defined(LIBC_LONG_DOUBLE_IS_X86_FLOAT80)
#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80)

TEST_F(LlvmLibcStrToLongDblTest, EiselLemireFloat80Simple) {
eisel_lemire_test(123, 0, 0xf600000000000000, 16389);
Expand Down Expand Up @@ -54,7 +54,7 @@ TEST_F(LlvmLibcStrToLongDblTest, EiselLemireFloat80Fallback) {
ASSERT_FALSE(internal::eisel_lemire<long double>({1, -1000}).has_value());
}

#else // Quad precision long double
#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128)

TEST_F(LlvmLibcStrToLongDblTest, EiselLemireFloat128Simple) {
eisel_lemire_test(123, 0, 0x1ec00'00000000'00000000'00000000_u128, 16389);
Expand All @@ -77,6 +77,8 @@ TEST_F(LlvmLibcStrToLongDblTest, EiselLemireFloat128Fallback) {
.has_value());
}

#else
#error "Unknown long double type"
#endif

} // namespace LIBC_NAMESPACE
8 changes: 5 additions & 3 deletions libc/test/src/math/smoke/nanl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
#include "test/UnitTest/Test.h"
#include <signal.h>

#if defined(LIBC_LONG_DOUBLE_IS_FLOAT64)
#if defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)
#define SELECT_LONG_DOUBLE(val, _, __) val
#elif defined(LIBC_LONG_DOUBLE_IS_X86_FLOAT80)
#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80)
#define SELECT_LONG_DOUBLE(_, val, __) val
#else
#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128)
#define SELECT_LONG_DOUBLE(_, __, val) val
#else
#error "Unknown long double type"
#endif

class LlvmLibcNanlTest : public LIBC_NAMESPACE::testing::Test {
Expand Down
Loading

0 comments on commit f7d4236

Please sign in to comment.