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

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Mon Apr 21 15:08:47 PDT 2025


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

>From fef5fab173754ec16fe4dd659c3a7626eb9c3c49 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Mon, 21 Apr 2025 16:10:00 -0500
Subject: [PATCH] [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: https://github.com/llvm/llvm-project/issues/136596
---
 libc/src/__support/FPUtil/FPBits.h | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index bee8d0a8dc47d..09f50c9d06a66 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;
   }
@@ -818,7 +830,8 @@ struct FPBits final : public internal::FPRepImpl<get_fp_type<T>(), FPBits<T>> {
   static_assert(cpp::is_floating_point_v<T>,
                 "FPBits instantiated with invalid type.");
   using UP = internal::FPRepImpl<get_fp_type<T>(), FPBits<T>>;
-  using StorageType = typename UP::StorageType;
+  using StorageType =
+      typename internal::FPLayout<get_fp_type<T>()>::StorageType;
 
   // Constructors.
   LIBC_INLINE constexpr FPBits() = default;



More information about the libc-commits mailing list