Skip to content

Commit fef5fab

Browse files
committed
[libc] Stub handling for the PPC double double type
Summary: We use the storage class for `long double` in the printing implementations. We don't fully support the PPC double double type, which that maps to, but we can stub out just the support needed for the print interface to works. This required using the internal interface for storage type, but it should be good enough. Fixes: #136596
1 parent 56bf0e7 commit fef5fab

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

libc/src/__support/FPUtil/FPBits.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum class FPType {
3838
IEEE754_Binary64,
3939
IEEE754_Binary128,
4040
X86_Binary80,
41+
PPC_DoubleDouble,
4142
};
4243

4344
// The classes hierarchy is as follows:
@@ -138,6 +139,15 @@ template <> struct FPLayout<FPType::X86_Binary80> {
138139
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN - 1;
139140
};
140141

142+
// TODO: This needs an FPRepSem interface as well.
143+
template <> struct FPLayout<FPType::PPC_DoubleDouble> {
144+
using StorageType = UInt128;
145+
LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
146+
LIBC_INLINE_VAR static constexpr int EXP_LEN = 11;
147+
LIBC_INLINE_VAR static constexpr int SIG_LEN = 106;
148+
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN - 1;
149+
};
150+
141151
// FPStorage derives useful constants from the FPLayout above.
142152
template <FPType fp_type> struct FPStorage : public FPLayout<fp_type> {
143153
using UP = FPLayout<fp_type>;
@@ -790,6 +800,8 @@ template <typename T> LIBC_INLINE static constexpr FPType get_fp_type() {
790800
return FPType::IEEE754_Binary64;
791801
else if constexpr (__LDBL_MANT_DIG__ == 64)
792802
return FPType::X86_Binary80;
803+
else if constexpr (__LDBL_MANT_DIG__ == 106)
804+
return FPType::PPC_DoubleDouble;
793805
else if constexpr (__LDBL_MANT_DIG__ == 113)
794806
return FPType::IEEE754_Binary128;
795807
}
@@ -818,7 +830,8 @@ struct FPBits final : public internal::FPRepImpl<get_fp_type<T>(), FPBits<T>> {
818830
static_assert(cpp::is_floating_point_v<T>,
819831
"FPBits instantiated with invalid type.");
820832
using UP = internal::FPRepImpl<get_fp_type<T>(), FPBits<T>>;
821-
using StorageType = typename UP::StorageType;
833+
using StorageType =
834+
typename internal::FPLayout<get_fp_type<T>()>::StorageType;
822835

823836
// Constructors.
824837
LIBC_INLINE constexpr FPBits() = default;

0 commit comments

Comments
 (0)