Skip to content

Commit b28f0d3

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 b28f0d3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

libc/src/__support/FPUtil/FPBits.h

Lines changed: 12 additions & 0 deletions
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
}

libc/src/stdio/printf_core/core_structs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ struct FormatSection {
5656
int precision = -1;
5757

5858
// Needs to be large enough to hold a long double.
59-
fputil::FPBits<long double>::StorageType conv_val_raw;
59+
fputil::internal::FPLayout<fputil::get_fp_type<long double>()>::StorageType
60+
conv_val_raw;
6061
void *conv_val_ptr;
6162

6263
char conv_name;

0 commit comments

Comments
 (0)