[libc-commits] [libc] [libc] Add software Float128 fallback wrapper (PR #186868)

via libc-commits libc-commits at lists.llvm.org
Mon Mar 16 15:02:10 PDT 2026


https://github.com/Emmaliu2006git updated https://github.com/llvm/llvm-project/pull/186868

>From 820a8008bd05311d38ce5f91a71683b6b277c3f7 Mon Sep 17 00:00:00 2001
From: Emma Liu <yueqil2 at illinois.edu>
Date: Mon, 16 Mar 2026 14:22:17 -0500
Subject: [PATCH 1/2] [libc] Add software Float128 fallback wrapper

Introduce a minimal fputil::Float128 type used as a fallback when no native float128 type is available.
---
 libc/include/llvm-libc-types/float128.h |  3 ++
 libc/src/__support/FPUtil/float128.h    | 37 +++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 libc/src/__support/FPUtil/float128.h

diff --git a/libc/include/llvm-libc-types/float128.h b/libc/include/llvm-libc-types/float128.h
index 82ebb79f1f580..d507be24e9ace 100644
--- a/libc/include/llvm-libc-types/float128.h
+++ b/libc/include/llvm-libc-types/float128.h
@@ -31,6 +31,9 @@ typedef __float128 float128;
 #elif (LDBL_MANT_DIG == 113)
 #define LIBC_TYPES_HAS_FLOAT128
 typedef long double float128;
+#else
+#include "src/__support/FPUtil/float128.h"
+typedef LIBC_NAMESPACE::fputil::Float128 float128;
 #endif
 
 #endif // LLVM_LIBC_TYPES_FLOAT128_H
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
new file mode 100644
index 0000000000000..5cf5685fa0892
--- /dev/null
+++ b/libc/src/__support/FPUtil/float128.h
@@ -0,0 +1,37 @@
+//===-- Float128 software wrapper ----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines a minimal software-backed Float128 wrapper type used when
+// the host compiler does not provide a native 128-bit floating-point type.
+// The wrapper currently only stores the raw 128-bit representation.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_FLOAT128_H
+#define LLVM_LIBC_SRC_SUPPORT_FPUTIL_FLOAT128_H
+
+#include "src/__support/uint128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace fputil {
+
+class Float128 {
+private:
+  UInt128 bits_;
+
+public:
+  constexpr Float128() = default;
+
+  constexpr explicit Float128(UInt128 value) : bits_(value) {}
+
+  constexpr UInt128 get_bits() const { return bits_; }
+};
+} // namespace fputil
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_FLOAT128_H
\ No newline at end of file

>From c625b9cb93a51677debb8a70af3e0bbf69fba8ae Mon Sep 17 00:00:00 2001
From: Emma Liu <yueqil2 at illinois.edu>
Date: Mon, 16 Mar 2026 16:58:20 -0500
Subject: [PATCH 2/2] [libc] Initialize Float128 bits_ to zero

---
 libc/src/__support/FPUtil/float128.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index 5cf5685fa0892..a9ad68080b907 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -22,14 +22,14 @@ namespace fputil {
 
 class Float128 {
 private:
-  UInt128 bits_;
+  UInt128 bits_ = 0;
 
 public:
-  constexpr Float128() = default;
+    constexpr Float128() = default;
 
-  constexpr explicit Float128(UInt128 value) : bits_(value) {}
+    constexpr explicit Float128(UInt128 value) : bits_(value) {}
 
-  constexpr UInt128 get_bits() const { return bits_; }
+    constexpr UInt128 get_bits() const { return bits_; }
 };
 } // namespace fputil
 } // namespace LIBC_NAMESPACE_DECL



More information about the libc-commits mailing list