[libc-commits] [libc] [libc] Stub handling for the PPC double double type (PR #136614)

via libc-commits libc-commits at lists.llvm.org
Mon Apr 21 14:13:08 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Joseph Huber (jhuber6)

<details>
<summary>Changes</summary>

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: https://github.com/llvm/llvm-project/issues/136596


---
Full diff: https://github.com/llvm/llvm-project/pull/136614.diff


2 Files Affected:

- (modified) libc/src/__support/FPUtil/FPBits.h (+12) 
- (modified) libc/src/stdio/printf_core/core_structs.h (+2-1) 


``````````diff
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index bee8d0a8dc47d..608459d53d432 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -38,6 +38,7 @@ enum class FPType {
   IEEE754_Binary64,
   IEEE754_Binary128,
   X86_Binary80,
+  PPC_DoubleDouble,
 };
 
 // The classes hierarchy is as follows:
@@ -138,6 +139,15 @@ template <> struct FPLayout<FPType::X86_Binary80> {
   LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN - 1;
 };
 
+// TODO: This needs an FPRepSem interface as well.
+template <> struct FPLayout<FPType::PPC_DoubleDouble> {
+  using StorageType = UInt128;
+  LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
+  LIBC_INLINE_VAR static constexpr int EXP_LEN = 11;
+  LIBC_INLINE_VAR static constexpr int SIG_LEN = 106;
+  LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN - 1;
+};
+
 // FPStorage derives useful constants from the FPLayout above.
 template <FPType fp_type> struct FPStorage : public FPLayout<fp_type> {
   using UP = FPLayout<fp_type>;
@@ -790,6 +800,8 @@ template <typename T> LIBC_INLINE static constexpr FPType get_fp_type() {
       return FPType::IEEE754_Binary64;
     else if constexpr (__LDBL_MANT_DIG__ == 64)
       return FPType::X86_Binary80;
+    else if constexpr (__LDBL_MANT_DIG__ == 106)
+      return FPType::PPC_DoubleDouble;
     else if constexpr (__LDBL_MANT_DIG__ == 113)
       return FPType::IEEE754_Binary128;
   }
diff --git a/libc/src/stdio/printf_core/core_structs.h b/libc/src/stdio/printf_core/core_structs.h
index 4c3b81ff018ab..a0e9a3d0d2c10 100644
--- a/libc/src/stdio/printf_core/core_structs.h
+++ b/libc/src/stdio/printf_core/core_structs.h
@@ -56,7 +56,8 @@ struct FormatSection {
   int precision = -1;
 
   // Needs to be large enough to hold a long double.
-  fputil::FPBits<long double>::StorageType conv_val_raw;
+  fputil::internal::FPLayout<fputil::get_fp_type<long double>()>::StorageType
+      conv_val_raw;
   void *conv_val_ptr;
 
   char conv_name;

``````````

</details>


https://github.com/llvm/llvm-project/pull/136614


More information about the libc-commits mailing list