Skip to content

Commit

Permalink
[libc] Add handling for long double=double double (llvm#113235)
Browse files Browse the repository at this point in the history
For Hand-In-Hand we need float to string to support a wider set of
architectures, specifically the ones that libc++ supports. This includes
powerpc, which apparently uses "double double" as its long double type.
Since Hand-In-Hand isn't currently using long double, this just opts
them out.
  • Loading branch information
michaelrj-google authored Oct 22, 2024
1 parent 23b18fa commit 7eb3264
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions libc/src/__support/macros/properties/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#define LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
#elif (LDBL_MANT_DIG == 113)
#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
#elif (LDBL_MANT_DIG == 103)
#define LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
#endif

// int64 / uint64 support
Expand Down
20 changes: 18 additions & 2 deletions libc/src/__support/str_to_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ eisel_lemire(ExpandedFloat<T> init_num,
return output;
}

#if !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)
// TODO: Re-enable eisel-lemire for long double is double double once it's
// properly supported.
#if !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64) && \
!defined(LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE)
template <>
LIBC_INLINE cpp::optional<ExpandedFloat<long double>>
eisel_lemire<long double>(ExpandedFloat<long double> init_num,
Expand Down Expand Up @@ -316,7 +319,8 @@ eisel_lemire<long double>(ExpandedFloat<long double> init_num,
output.exponent = exp2;
return output;
}
#endif // !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)
#endif // !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64) &&
// !defined(LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE)

// 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 @@ -518,6 +522,18 @@ template <> class ClingerConsts<long double> {
static constexpr long double MAX_EXACT_INT =
10384593717069655257060992658440191.0L;
};
#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE)
// TODO: Add proper double double type support here, currently using constants
// for double since it should be safe.
template <> class ClingerConsts<long double> {
public:
static constexpr double POWERS_OF_TEN_ARRAY[] = {
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11,
1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22};
static constexpr int32_t EXACT_POWERS_OF_TEN = 22;
static constexpr int32_t DIGITS_IN_MANTISSA = 15;
static constexpr double MAX_EXACT_INT = 9007199254740991.0;
};
#else
#error "Unknown long double type"
#endif
Expand Down

0 comments on commit 7eb3264

Please sign in to comment.