[libc-commits] [libc] F128 test (PR #200808)
via libc-commits
libc-commits at lists.llvm.org
Mon Jun 1 07:12:11 PDT 2026
https://github.com/Sukumarsawant updated https://github.com/llvm/llvm-project/pull/200808
>From 64006cdced3e2d77dc19001cd0de8594ba1b12d1 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 29 May 2026 13:45:09 +0530
Subject: [PATCH 1/7] test1
---
libc/src/__support/FPUtil/float128.h | 127 +++++++++++++++++++++++++++
1 file changed, 127 insertions(+)
create mode 100644 libc/src/__support/FPUtil/float128.h
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
new file mode 100644
index 0000000000000..d6b8bb3eebc77
--- /dev/null
+++ b/libc/src/__support/FPUtil/float128.h
@@ -0,0 +1,127 @@
+//===-- Definition of float128 data type -----------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
+#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
+
+#include "hdr/stdint_proxy.h"
+#include "src/__support/CPP/bit.h"
+#include "src/__support/CPP/type_traits.h"
+#include "src/__support/FPUtil/cast.h"
+#include "src/__support/FPUtil/comparison_operations.h"
+#include "src/__support/FPUtil/dyadic_float.h"
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h"
+#include "src/__support/UInt128.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace fputil {
+
+struct Float128 {
+ UInt128 bits;
+
+ LIBC_INLINE Float128() = default;
+
+ template <typename T>
+ LIBC_INLINE constexpr explicit Float128(T value)
+ : bits(static_cast<UInt128>(0U)) {
+ if constexpr (cpp::is_floating_point_v<T>) {
+ bits = fputil::cast<Float128>(value).bits;
+ } else if constexpr (cpp::is_integral_v<T>) {
+ Sign sign = Sign::POS;
+
+ if constexpr (cpp::is_signed_v<T>) {
+ if (value < 0) {
+ sign = Sign::NEG;
+ value = -value;
+ }
+ }
+
+ fputil::DyadicFloat<cpp::numeric_limits<cpp::make_unsigned_t<T>>::digits>
+ xd(sign, 0, value);
+ bits = xd.template as<Float128, /*ShouldSignalExceptions=*/true>().bits;
+
+ } else if constexpr (cpp::is_convertible_v<T, Float128>) {
+ bits = value.operator Float128().bits;
+ } else {
+ bits = fputil::cast<Float128>(static_cast<float>(value)).bits;
+ }
+ }
+
+ template <cpp::enable_if_t<fputil::get_fp_type<float>() ==
+ fputil::FPType::IEEE754_Binary32,
+ int> = 0>
+ LIBC_INLINE constexpr operator float() const {
+ UInt128 x_bits = static_cast<UInt128>(bits) << 16U;
+ return cpp::bit_cast<float>(x_bits);
+ }
+
+ template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
+ LIBC_INLINE constexpr explicit operator T() const {
+ return static_cast<T>(static_cast<float>(*this));
+ }
+
+ LIBC_INLINE constexpr bool operator==(BFloat16 other) const {
+ return fputil::equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator!=(BFloat16 other) const {
+ return !fputil::equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator<(BFloat16 other) const {
+ return fputil::less_than(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator<=(BFloat16 other) const {
+ return fputil::less_than_or_equals(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator>(BFloat16 other) const {
+ return fputil::greater_than(*this, other);
+ }
+
+ LIBC_INLINE constexpr bool operator>=(BFloat16 other) const {
+ return fputil::greater_than_or_equals(*this, other);
+ }
+
+ LIBC_INLINE LIBC_BIT_CAST_CONSTEXPR BFloat16 operator-() const {
+ fputil::FPBits<bfloat16> result(*this);
+ result.set_sign(result.is_pos() ? Sign::NEG : Sign::POS);
+ return result.get_val();
+ }
+
+ LIBC_INLINE constexpr BFloat16 operator+(BFloat16 other) const {
+ return fputil::generic::add<BFloat16>(*this, other);
+ }
+
+ LIBC_INLINE constexpr BFloat16 operator-(BFloat16 other) const {
+ return fputil::generic::sub<BFloat16>(*this, other);
+ }
+
+ LIBC_INLINE constexpr BFloat16 operator*(BFloat16 other) const {
+ return fputil::generic::mul<bfloat16>(*this, other);
+ }
+
+ LIBC_INLINE constexpr BFloat16 operator/(BFloat16 other) const {
+ return fputil::generic::div<bfloat16>(*this, other);
+ }
+
+ LIBC_INLINE constexpr BFloat16 &operator*=(const BFloat16 &other) {
+ *this = *this * other;
+ return *this;
+ }
+}; // struct BFloat16
+
+} // namespace fputil
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_BFLOAT16_H
>From 3a29e944662e516c406ffc39f88c8921c8324d62 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Fri, 29 May 2026 18:56:02 +0530
Subject: [PATCH 2/7] Test skeleton
---
libc/src/__support/FPUtil/CMakeLists.txt | 10 ++
libc/src/__support/FPUtil/float128.h | 122 ++++-------------------
2 files changed, 30 insertions(+), 102 deletions(-)
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index d45dd82560788..4d2c6e9078ec3 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -294,4 +294,14 @@ add_header_library(
libc.src.__support.macros.properties.types
)
+add_header_library(
+ float128
+ HDRS
+ float128.h
+ DEPENDS
+ .fp_bits
+ libc.src.__support.CPP.bit
+ libc.src.__support.CPP.type_traits
+)
+
add_subdirectory(generic)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index d6b8bb3eebc77..5945837bed5c2 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -1,4 +1,4 @@
-//===-- Definition of float128 data type -----------------------*- C++ -*-===//
+//===-- Utilities for Float128 data type -----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,119 +9,37 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
-#include "hdr/stdint_proxy.h"
+#include "FPBits.h"
+#include "hdr/fenv_macros.h"
#include "src/__support/CPP/bit.h"
-#include "src/__support/CPP/type_traits.h"
-#include "src/__support/FPUtil/cast.h"
-#include "src/__support/FPUtil/comparison_operations.h"
-#include "src/__support/FPUtil/dyadic_float.h"
-#include "src/__support/FPUtil/generic/add_sub.h"
-#include "src/__support/FPUtil/generic/div.h"
-#include "src/__support/FPUtil/generic/mul.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/macros/properties/types.h"
-#include "src/__support/UInt128.h"
+#include "src/__support/uint128.h"
namespace LIBC_NAMESPACE_DECL {
namespace fputil {
struct Float128 {
UInt128 bits;
-
- LIBC_INLINE Float128() = default;
-
- template <typename T>
- LIBC_INLINE constexpr explicit Float128(T value)
- : bits(static_cast<UInt128>(0U)) {
- if constexpr (cpp::is_floating_point_v<T>) {
- bits = fputil::cast<Float128>(value).bits;
- } else if constexpr (cpp::is_integral_v<T>) {
- Sign sign = Sign::POS;
-
- if constexpr (cpp::is_signed_v<T>) {
- if (value < 0) {
- sign = Sign::NEG;
- value = -value;
- }
- }
-
- fputil::DyadicFloat<cpp::numeric_limits<cpp::make_unsigned_t<T>>::digits>
- xd(sign, 0, value);
- bits = xd.template as<Float128, /*ShouldSignalExceptions=*/true>().bits;
-
- } else if constexpr (cpp::is_convertible_v<T, Float128>) {
- bits = value.operator Float128().bits;
- } else {
- bits = fputil::cast<Float128>(static_cast<float>(value)).bits;
- }
- }
-
- template <cpp::enable_if_t<fputil::get_fp_type<float>() ==
- fputil::FPType::IEEE754_Binary32,
+ // Testing
+ constexpr Float128() = default;
+ /* TODO: precision
+ TODO: explicit so it does not convert without warn
+ VERIFY : template <cpp::enable_if_t<fputil::get_fp_type<Double>() ==
+ fputil::FPType::IEEE754_Binary64,
int> = 0>
- LIBC_INLINE constexpr operator float() const {
- UInt128 x_bits = static_cast<UInt128>(bits) << 16U;
- return cpp::bit_cast<float>(x_bits);
- }
-
- template <typename T, cpp::enable_if_t<cpp::is_integral_v<T>, int> = 0>
- LIBC_INLINE constexpr explicit operator T() const {
- return static_cast<T>(static_cast<float>(*this));
- }
-
- LIBC_INLINE constexpr bool operator==(BFloat16 other) const {
- return fputil::equals(*this, other);
- }
-
- LIBC_INLINE constexpr bool operator!=(BFloat16 other) const {
- return !fputil::equals(*this, other);
- }
-
- LIBC_INLINE constexpr bool operator<(BFloat16 other) const {
- return fputil::less_than(*this, other);
- }
-
- LIBC_INLINE constexpr bool operator<=(BFloat16 other) const {
- return fputil::less_than_or_equals(*this, other);
- }
-
- LIBC_INLINE constexpr bool operator>(BFloat16 other) const {
- return fputil::greater_than(*this, other);
- }
-
- LIBC_INLINE constexpr bool operator>=(BFloat16 other) const {
- return fputil::greater_than_or_equals(*this, other);
- }
-
- LIBC_INLINE LIBC_BIT_CAST_CONSTEXPR BFloat16 operator-() const {
- fputil::FPBits<bfloat16> result(*this);
- result.set_sign(result.is_pos() ? Sign::NEG : Sign::POS);
- return result.get_val();
- }
-
- LIBC_INLINE constexpr BFloat16 operator+(BFloat16 other) const {
- return fputil::generic::add<BFloat16>(*this, other);
- }
-
- LIBC_INLINE constexpr BFloat16 operator-(BFloat16 other) const {
- return fputil::generic::sub<BFloat16>(*this, other);
- }
-
- LIBC_INLINE constexpr BFloat16 operator*(BFloat16 other) const {
- return fputil::generic::mul<bfloat16>(*this, other);
- }
-
- LIBC_INLINE constexpr BFloat16 operator/(BFloat16 other) const {
- return fputil::generic::div<bfloat16>(*this, other);
+ */
+ constexpr Float128(double x) {
+ FPBits<double> x_bits(x);
+ uint64_t val = x_bits.uintval();
+ bits = static_cast<UInt128>(val) << 64;
}
- LIBC_INLINE constexpr BFloat16 &operator*=(const BFloat16 &other) {
- *this = *this * other;
- return *this;
+ constexpr operator double() const {
+ uint64_t val = static_cast<uint64_t>(bits >> 64U);
+ return cpp::bit_cast<double>(val);
}
-}; // struct BFloat16
+};
} // namespace fputil
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_BFLOAT16_H
+#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
>From b38ae04d5c025707e0259a226672d38418402780 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 1 Jun 2026 17:23:38 +0530
Subject: [PATCH 3/7] test: FPType
---
.../CPP/type_traits/is_floating_point.h | 100 ++++++------
libc/src/__support/FPUtil/FPBits.h | 13 +-
libc/src/__support/FPUtil/float128.h | 2 +-
libc/src/__support/macros/properties/types.h | 151 ++++++++++--------
4 files changed, 144 insertions(+), 122 deletions(-)
diff --git a/libc/src/__support/CPP/type_traits/is_floating_point.h b/libc/src/__support/CPP/type_traits/is_floating_point.h
index 9dc77ad7ee0ea..8bd0ee1e0ac1f 100644
--- a/libc/src/__support/CPP/type_traits/is_floating_point.h
+++ b/libc/src/__support/CPP/type_traits/is_floating_point.h
@@ -1,49 +1,51 @@
-//===-- is_floating_point type_traits ---------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
-#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
-
-#include "src/__support/CPP/type_traits/is_same.h"
-#include "src/__support/CPP/type_traits/remove_cv.h"
-#include "src/__support/macros/attributes.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128
-
-namespace LIBC_NAMESPACE_DECL {
-namespace cpp {
-
-// is_floating_point
-template <typename T> struct is_floating_point {
-private:
- template <typename Head, typename... Args>
- LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() {
- return (... || is_same_v<remove_cv_t<Head>, Args>);
- }
-
-public:
- LIBC_INLINE_VAR static constexpr bool value =
- __is_unqualified_any_of<T, float, double, long double
-#ifdef LIBC_TYPES_HAS_FLOAT16
- ,
- float16
-#endif
-#ifdef LIBC_TYPES_HAS_FLOAT128
- ,
- float128
-#endif
- ,
- bfloat16>();
-};
-template <typename T>
-LIBC_INLINE_VAR constexpr bool is_floating_point_v =
- is_floating_point<T>::value;
-
-} // namespace cpp
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
+//===-- is_floating_point type_traits ---------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
+#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
+
+#include "src/__support/CPP/type_traits/is_same.h"
+#include "src/__support/CPP/type_traits/remove_cv.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128
+
+namespace LIBC_NAMESPACE_DECL {
+namespace cpp {
+
+// is_floating_point
+template <typename T> struct is_floating_point {
+private:
+ template <typename Head, typename... Args>
+ LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() {
+ return (... || is_same_v<remove_cv_t<Head>, Args>);
+ }
+
+public:
+ LIBC_INLINE_VAR static constexpr bool value =
+ __is_unqualified_any_of<T, float, double, long double
+#ifdef LIBC_TYPES_HAS_FLOAT16
+ ,
+ float16
+#endif
+#ifdef LIBC_TYPES_HAS_FLOAT128
+ ,
+ float128
+#endif
+ ,
+ bfloat16>();
+ ,
+ Float128>();
+};
+template <typename T>
+LIBC_INLINE_VAR constexpr bool is_floating_point_v =
+ is_floating_point<T>::value;
+
+} // namespace cpp
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index c52699e17e225..5b7461a44cff5 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -37,7 +37,8 @@ enum class FPType {
IEEE754_Binary64,
IEEE754_Binary128,
X86_Binary80,
- BFloat16
+ BFloat16,
+ Float128
};
// The classes hierarchy is as follows:
@@ -146,6 +147,14 @@ template <> struct FPLayout<FPType::BFloat16> {
LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN;
};
+template <> struct FPLayout<FPType::Float128> {
+ using StorageType = UInt128;
+ LIBC_INLINE_VAR static constexpr int SIGN_LEN = 1;
+ LIBC_INLINE_VAR static constexpr int EXP_LEN = 15;
+ LIBC_INLINE_VAR static constexpr int SIG_LEN = 112;
+ LIBC_INLINE_VAR static constexpr int FRACTION_LEN = SIG_LEN;
+};
+
// FPStorage derives useful constants from the FPLayout above.
template <FPType fp_type> struct FPStorage : public FPLayout<fp_type> {
using UP = FPLayout<fp_type>;
@@ -813,6 +822,8 @@ template <typename T> LIBC_INLINE static constexpr FPType get_fp_type() {
#endif
else if constexpr (cpp::is_same_v<UnqualT, bfloat16>)
return FPType::BFloat16;
+ else if constexpr (cpp::is_same_v<UnqualT, Float128>)
+ return FPType::Float128;
else
static_assert(cpp::always_false<UnqualT>, "Unsupported type");
}
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index 5945837bed5c2..d3c43888cb855 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -30,7 +30,7 @@ struct Float128 {
constexpr Float128(double x) {
FPBits<double> x_bits(x);
uint64_t val = x_bits.uintval();
- bits = static_cast<UInt128>(val) << 64;
+ bits = fputil::cast<UInt128>(val) << 64;
}
constexpr operator double() const {
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index 3259c8a6a1d12..9a9422bed2fe9 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -1,71 +1,80 @@
-//===-- Types support -------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-// Types detection and support.
-
-#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
-#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
-
-#include "hdr/float_macros.h" // LDBL_MANT_DIG
-#include "hdr/stdint_proxy.h" // UINT64_MAX, __SIZEOF_INT128__
-#include "include/llvm-libc-macros/float16-macros.h" // LIBC_TYPES_HAS_FLOAT16
-#include "include/llvm-libc-types/float128.h" // float128
-#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
-#include "src/__support/macros/properties/architectures.h"
-#include "src/__support/macros/properties/compiler.h"
-#include "src/__support/macros/properties/cpu_features.h"
-#include "src/__support/macros/properties/os.h"
-
-// 'long double' properties.
-#if (LDBL_MANT_DIG == 53)
-#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
-#elif (LDBL_MANT_DIG == 64)
-#define LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
-#elif (LDBL_MANT_DIG == 113)
-#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
-#elif (LDBL_MANT_DIG == 106)
-#define LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
-#endif
-
-#if defined(LIBC_TYPES_HAS_FLOAT128) && \
- !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128)
-#define LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
-#endif
-
-// int64 / uint64 support
-#if defined(UINT64_MAX)
-#define LIBC_TYPES_HAS_INT64
-#endif // UINT64_MAX
-
-// int128 / uint128 support
-#if defined(__SIZEOF_INT128__) && !defined(LIBC_TARGET_OS_IS_WINDOWS)
-#define LIBC_TYPES_HAS_INT128
-#endif // defined(__SIZEOF_INT128__)
-
-// -- float16 support ---------------------------------------------------------
-// LIBC_TYPES_HAS_FLOAT16 is provided by
-// "include/llvm-libc-macros/float16-macros.h"
-#ifdef LIBC_TYPES_HAS_FLOAT16
-// Type alias for internal use.
-using float16 = _Float16;
-#endif // LIBC_TYPES_HAS_FLOAT16
-
-// -- float128 support --------------------------------------------------------
-// LIBC_TYPES_HAS_FLOAT128 and 'float128' type are provided by
-// "include/llvm-libc-types/float128.h"
-
-// -- bfloat16 support ---------------------------------------------------------
-
-namespace LIBC_NAMESPACE_DECL {
-namespace fputil {
-struct BFloat16;
-}
-} // namespace LIBC_NAMESPACE_DECL
-
-using bfloat16 = LIBC_NAMESPACE::fputil::BFloat16;
-
-#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
+//===-- Types support -------------------------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+// Types detection and support.
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
+#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
+
+#include "hdr/float_macros.h" // LDBL_MANT_DIG
+#include "hdr/stdint_proxy.h" // UINT64_MAX, __SIZEOF_INT128__
+#include "include/llvm-libc-macros/float16-macros.h" // LIBC_TYPES_HAS_FLOAT16
+#include "include/llvm-libc-types/float128.h" // float128
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+#include "src/__support/macros/properties/architectures.h"
+#include "src/__support/macros/properties/compiler.h"
+#include "src/__support/macros/properties/cpu_features.h"
+#include "src/__support/macros/properties/os.h"
+
+// 'long double' properties.
+#if (LDBL_MANT_DIG == 53)
+#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
+#elif (LDBL_MANT_DIG == 64)
+#define LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
+#elif (LDBL_MANT_DIG == 113)
+#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
+#elif (LDBL_MANT_DIG == 106)
+#define LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
+#endif
+
+#if defined(LIBC_TYPES_HAS_FLOAT128) && \
+ !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128)
+#define LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+#endif
+
+// int64 / uint64 support
+#if defined(UINT64_MAX)
+#define LIBC_TYPES_HAS_INT64
+#endif // UINT64_MAX
+
+// int128 / uint128 support
+#if defined(__SIZEOF_INT128__) && !defined(LIBC_TARGET_OS_IS_WINDOWS)
+#define LIBC_TYPES_HAS_INT128
+#endif // defined(__SIZEOF_INT128__)
+
+// -- float16 support ---------------------------------------------------------
+// LIBC_TYPES_HAS_FLOAT16 is provided by
+// "include/llvm-libc-macros/float16-macros.h"
+#ifdef LIBC_TYPES_HAS_FLOAT16
+// Type alias for internal use.
+using float16 = _Float16;
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+// -- float128 support --------------------------------------------------------
+// LIBC_TYPES_HAS_FLOAT128 and 'float128' type are provided by
+// "include/llvm-libc-types/float128.h"
+
+// -- Emulated float128 support ------------------------------------------------
+namespace LIBC_NAMESPACE_DECL {
+namespace fputil {
+struct Float128;
+}
+} // namespace LIBC_NAMESPACE_DECL
+
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+
+// -- bfloat16 support ---------------------------------------------------------
+
+namespace LIBC_NAMESPACE_DECL {
+namespace fputil {
+struct BFloat16;
+}
+} // namespace LIBC_NAMESPACE_DECL
+
+using bfloat16 = LIBC_NAMESPACE::fputil::BFloat16;
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
>From f84e0e124794392add70ce8f2b37e82e6f67a50a Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 1 Jun 2026 17:24:53 +0530
Subject: [PATCH 4/7] CRLF->LF
---
.../CPP/type_traits/is_floating_point.h | 102 +++++------
libc/src/__support/macros/properties/types.h | 160 +++++++++---------
2 files changed, 131 insertions(+), 131 deletions(-)
diff --git a/libc/src/__support/CPP/type_traits/is_floating_point.h b/libc/src/__support/CPP/type_traits/is_floating_point.h
index 8bd0ee1e0ac1f..9ddd6509f100e 100644
--- a/libc/src/__support/CPP/type_traits/is_floating_point.h
+++ b/libc/src/__support/CPP/type_traits/is_floating_point.h
@@ -1,51 +1,51 @@
-//===-- is_floating_point type_traits ---------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
-#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
-
-#include "src/__support/CPP/type_traits/is_same.h"
-#include "src/__support/CPP/type_traits/remove_cv.h"
-#include "src/__support/macros/attributes.h"
-#include "src/__support/macros/config.h"
-#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128
-
-namespace LIBC_NAMESPACE_DECL {
-namespace cpp {
-
-// is_floating_point
-template <typename T> struct is_floating_point {
-private:
- template <typename Head, typename... Args>
- LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() {
- return (... || is_same_v<remove_cv_t<Head>, Args>);
- }
-
-public:
- LIBC_INLINE_VAR static constexpr bool value =
- __is_unqualified_any_of<T, float, double, long double
-#ifdef LIBC_TYPES_HAS_FLOAT16
- ,
- float16
-#endif
-#ifdef LIBC_TYPES_HAS_FLOAT128
- ,
- float128
-#endif
- ,
- bfloat16>();
- ,
- Float128>();
-};
-template <typename T>
-LIBC_INLINE_VAR constexpr bool is_floating_point_v =
- is_floating_point<T>::value;
-
-} // namespace cpp
-} // namespace LIBC_NAMESPACE_DECL
-
-#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
+//===-- is_floating_point type_traits ---------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
+#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
+
+#include "src/__support/CPP/type_traits/is_same.h"
+#include "src/__support/CPP/type_traits/remove_cv.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128
+
+namespace LIBC_NAMESPACE_DECL {
+namespace cpp {
+
+// is_floating_point
+template <typename T> struct is_floating_point {
+private:
+ template <typename Head, typename... Args>
+ LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() {
+ return (... || is_same_v<remove_cv_t<Head>, Args>);
+ }
+
+public:
+ LIBC_INLINE_VAR static constexpr bool value =
+ __is_unqualified_any_of<T, float, double, long double
+#ifdef LIBC_TYPES_HAS_FLOAT16
+ ,
+ float16
+#endif
+#ifdef LIBC_TYPES_HAS_FLOAT128
+ ,
+ float128
+#endif
+ ,
+ bfloat16>();
+ ,
+ Float128>();
+};
+template <typename T>
+LIBC_INLINE_VAR constexpr bool is_floating_point_v =
+ is_floating_point<T>::value;
+
+} // namespace cpp
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index 9a9422bed2fe9..3c981173d8c44 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -1,80 +1,80 @@
-//===-- Types support -------------------------------------------*- C++ -*-===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-// Types detection and support.
-
-#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
-#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
-
-#include "hdr/float_macros.h" // LDBL_MANT_DIG
-#include "hdr/stdint_proxy.h" // UINT64_MAX, __SIZEOF_INT128__
-#include "include/llvm-libc-macros/float16-macros.h" // LIBC_TYPES_HAS_FLOAT16
-#include "include/llvm-libc-types/float128.h" // float128
-#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
-#include "src/__support/macros/properties/architectures.h"
-#include "src/__support/macros/properties/compiler.h"
-#include "src/__support/macros/properties/cpu_features.h"
-#include "src/__support/macros/properties/os.h"
-
-// 'long double' properties.
-#if (LDBL_MANT_DIG == 53)
-#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
-#elif (LDBL_MANT_DIG == 64)
-#define LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
-#elif (LDBL_MANT_DIG == 113)
-#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
-#elif (LDBL_MANT_DIG == 106)
-#define LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
-#endif
-
-#if defined(LIBC_TYPES_HAS_FLOAT128) && \
- !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128)
-#define LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
-#endif
-
-// int64 / uint64 support
-#if defined(UINT64_MAX)
-#define LIBC_TYPES_HAS_INT64
-#endif // UINT64_MAX
-
-// int128 / uint128 support
-#if defined(__SIZEOF_INT128__) && !defined(LIBC_TARGET_OS_IS_WINDOWS)
-#define LIBC_TYPES_HAS_INT128
-#endif // defined(__SIZEOF_INT128__)
-
-// -- float16 support ---------------------------------------------------------
-// LIBC_TYPES_HAS_FLOAT16 is provided by
-// "include/llvm-libc-macros/float16-macros.h"
-#ifdef LIBC_TYPES_HAS_FLOAT16
-// Type alias for internal use.
-using float16 = _Float16;
-#endif // LIBC_TYPES_HAS_FLOAT16
-
-// -- float128 support --------------------------------------------------------
-// LIBC_TYPES_HAS_FLOAT128 and 'float128' type are provided by
-// "include/llvm-libc-types/float128.h"
-
-// -- Emulated float128 support ------------------------------------------------
-namespace LIBC_NAMESPACE_DECL {
-namespace fputil {
-struct Float128;
-}
-} // namespace LIBC_NAMESPACE_DECL
-
-using float128 = LIBC_NAMESPACE::fputil::Float128;
-
-// -- bfloat16 support ---------------------------------------------------------
-
-namespace LIBC_NAMESPACE_DECL {
-namespace fputil {
-struct BFloat16;
-}
-} // namespace LIBC_NAMESPACE_DECL
-
-using bfloat16 = LIBC_NAMESPACE::fputil::BFloat16;
-
-#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
+//===-- Types support -------------------------------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+// Types detection and support.
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
+#define LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
+
+#include "hdr/float_macros.h" // LDBL_MANT_DIG
+#include "hdr/stdint_proxy.h" // UINT64_MAX, __SIZEOF_INT128__
+#include "include/llvm-libc-macros/float16-macros.h" // LIBC_TYPES_HAS_FLOAT16
+#include "include/llvm-libc-types/float128.h" // float128
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+#include "src/__support/macros/properties/architectures.h"
+#include "src/__support/macros/properties/compiler.h"
+#include "src/__support/macros/properties/cpu_features.h"
+#include "src/__support/macros/properties/os.h"
+
+// 'long double' properties.
+#if (LDBL_MANT_DIG == 53)
+#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64
+#elif (LDBL_MANT_DIG == 64)
+#define LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
+#elif (LDBL_MANT_DIG == 113)
+#define LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128
+#elif (LDBL_MANT_DIG == 106)
+#define LIBC_TYPES_LONG_DOUBLE_IS_DOUBLE_DOUBLE
+#endif
+
+#if defined(LIBC_TYPES_HAS_FLOAT128) && \
+ !defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128)
+#define LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
+#endif
+
+// int64 / uint64 support
+#if defined(UINT64_MAX)
+#define LIBC_TYPES_HAS_INT64
+#endif // UINT64_MAX
+
+// int128 / uint128 support
+#if defined(__SIZEOF_INT128__) && !defined(LIBC_TARGET_OS_IS_WINDOWS)
+#define LIBC_TYPES_HAS_INT128
+#endif // defined(__SIZEOF_INT128__)
+
+// -- float16 support ---------------------------------------------------------
+// LIBC_TYPES_HAS_FLOAT16 is provided by
+// "include/llvm-libc-macros/float16-macros.h"
+#ifdef LIBC_TYPES_HAS_FLOAT16
+// Type alias for internal use.
+using float16 = _Float16;
+#endif // LIBC_TYPES_HAS_FLOAT16
+
+// -- float128 support --------------------------------------------------------
+// LIBC_TYPES_HAS_FLOAT128 and 'float128' type are provided by
+// "include/llvm-libc-types/float128.h"
+
+// -- Emulated float128 support ------------------------------------------------
+namespace LIBC_NAMESPACE_DECL {
+namespace fputil {
+struct Float128;
+}
+} // namespace LIBC_NAMESPACE_DECL
+
+using float128 = LIBC_NAMESPACE::fputil::Float128;
+
+// -- bfloat16 support ---------------------------------------------------------
+
+namespace LIBC_NAMESPACE_DECL {
+namespace fputil {
+struct BFloat16;
+}
+} // namespace LIBC_NAMESPACE_DECL
+
+using bfloat16 = LIBC_NAMESPACE::fputil::BFloat16;
+
+#endif // LLVM_LIBC_SRC___SUPPORT_MACROS_PROPERTIES_TYPES_H
>From 7a7c36a49acd33dcf15b59667b204a85269ef05e Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 1 Jun 2026 18:31:11 +0530
Subject: [PATCH 5/7] test: 1/6 -> small + test on CI
---
.../CPP/type_traits/is_floating_point.h | 6 ++-
libc/src/__support/FPUtil/CMakeLists.txt | 5 ++-
libc/src/__support/FPUtil/float128.h | 39 ++++++++++---------
libc/test/src/math/smoke/CMakeLists.txt | 10 +++++
libc/test/src/math/smoke/float128_test.cpp | 38 ++++++++++++++++++
5 files changed, 75 insertions(+), 23 deletions(-)
create mode 100644 libc/test/src/math/smoke/float128_test.cpp
diff --git a/libc/src/__support/CPP/type_traits/is_floating_point.h b/libc/src/__support/CPP/type_traits/is_floating_point.h
index 9ddd6509f100e..3efcd9dbdbb55 100644
--- a/libc/src/__support/CPP/type_traits/is_floating_point.h
+++ b/libc/src/__support/CPP/type_traits/is_floating_point.h
@@ -13,6 +13,7 @@
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128
+#include "src/__support/FPUtil/float128.h"
namespace LIBC_NAMESPACE_DECL {
namespace cpp {
@@ -37,9 +38,10 @@ template <typename T> struct is_floating_point {
float128
#endif
,
- bfloat16>();
+ bfloat16
,
- Float128>();
+ fputil::Float128>();
+
};
template <typename T>
LIBC_INLINE_VAR constexpr bool is_floating_point_v =
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index 4d2c6e9078ec3..20e1c01bb8ca1 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -299,9 +299,10 @@ add_header_library(
HDRS
float128.h
DEPENDS
- .fp_bits
libc.src.__support.CPP.bit
- libc.src.__support.CPP.type_traits
+ libc.src.__support.macros.attributes
+ libc.src.__support.macros.config
+ libc.src.__support.uint128
)
add_subdirectory(generic)
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index d3c43888cb855..c14665ece42fc 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -1,4 +1,4 @@
-//===-- Utilities for Float128 data type -----------------------*- C++ -*-===//
+//===-- Definition for Float128 data type ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,33 +9,34 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
-#include "FPBits.h"
-#include "hdr/fenv_macros.h"
-#include "src/__support/CPP/bit.h"
+#include "src/__support/CPP/bit.h" // cpp::bit_cast
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
#include "src/__support/uint128.h"
+#include <stdint.h>
namespace LIBC_NAMESPACE_DECL {
namespace fputil {
struct Float128 {
UInt128 bits;
- // Testing
- constexpr Float128() = default;
- /* TODO: precision
- TODO: explicit so it does not convert without warn
- VERIFY : template <cpp::enable_if_t<fputil::get_fp_type<Double>() ==
- fputil::FPType::IEEE754_Binary64,
- int> = 0>
- */
- constexpr Float128(double x) {
- FPBits<double> x_bits(x);
- uint64_t val = x_bits.uintval();
- bits = fputil::cast<UInt128>(val) << 64;
+
+ LIBC_INLINE Float128() = default;
+
+ LIBC_INLINE constexpr explicit Float128(double x) {
+ uint64_t d = cpp::bit_cast<uint64_t>(x);
+ bits = static_cast<UInt128>(d) << 64U;
}
- constexpr operator double() const {
- uint64_t val = static_cast<uint64_t>(bits >> 64U);
- return cpp::bit_cast<double>(val);
+ LIBC_INLINE constexpr explicit operator double() const {
+ return cpp::bit_cast<double>(static_cast<uint64_t>(bits >> 64U));
+ }
+
+ LIBC_INLINE constexpr bool operator==(Float128 other) const {
+ return bits == other.bits;
+ }
+ LIBC_INLINE constexpr bool operator!=(Float128 other) const {
+ return bits != other.bits;
}
};
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index bb462afb71b91..bc911ea8a798f 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -1,6 +1,16 @@
add_custom_target(libc-math-smoke-tests)
add_dependencies(libc-math-unittests libc-math-smoke-tests)
+add_libc_unittest(
+ float128_test
+ SUITE
+ libc-math-smoke-tests
+ SRCS
+ float128_test.cpp
+ DEPENDS
+ libc.src.__support.FPUtil.float128
+)
+
add_fp_unittest(
cosf_test
SUITE
diff --git a/libc/test/src/math/smoke/float128_test.cpp b/libc/test/src/math/smoke/float128_test.cpp
new file mode 100644
index 0000000000000..2697819e972b9
--- /dev/null
+++ b/libc/test/src/math/smoke/float128_test.cpp
@@ -0,0 +1,38 @@
+//===-- Unittests for Float128 emulated type ------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/FPUtil/float128.h"
+#include "src/__support/uint128.h"
+#include "test/UnitTest/Test.h"
+
+using LIBC_NAMESPACE::fputil::Float128;
+
+TEST(LlvmLibcFloat128Test, DefaultConstructor) {
+ Float128 x;
+ (void)x; // TEST 1>
+}
+
+TEST(LlvmLibcFloat128Test, doubleToFloat128) {
+ // Double -> Float128 -> double should give back the same value
+ constexpr double vals[] = {0.0, 1.0, -1.0, 2.0, 0.5, 3.14};
+ for (double v : vals) {
+ Float128 x(v);
+ ASSERT_EQ(static_cast<double>(x), v);
+ }
+}
+
+TEST(LlvmLibcFloat128Test, ZeroBits) {
+ Float128 x(0.0);
+ ASSERT_EQ(x.bits, static_cast<LIBC_NAMESPACE::UInt128>(0));
+}
+
+TEST(LlvmLibcFloat128Test, Equality) {
+ Float128 a(1.0), b(1.0), c(2.0);
+ ASSERT_TRUE(a == b);
+ ASSERT_TRUE(a != c);
+}
>From bd7e2868cbcc3efcceb4365a7341c19eb0655575 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 1 Jun 2026 19:37:19 +0530
Subject: [PATCH 6/7] circ dependency
---
.../CPP/type_traits/is_floating_point.h | 5 ++--
libc/src/__support/FPUtil/float128.h | 14 ++++-----
libc/src/__support/macros/properties/types.h | 5 ++--
libc/test/src/math/smoke/float128_test.cpp | 29 +++++--------------
4 files changed, 19 insertions(+), 34 deletions(-)
diff --git a/libc/src/__support/CPP/type_traits/is_floating_point.h b/libc/src/__support/CPP/type_traits/is_floating_point.h
index 3efcd9dbdbb55..a035115b94e17 100644
--- a/libc/src/__support/CPP/type_traits/is_floating_point.h
+++ b/libc/src/__support/CPP/type_traits/is_floating_point.h
@@ -12,8 +12,7 @@
#include "src/__support/CPP/type_traits/remove_cv.h"
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
-#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128
-#include "src/__support/FPUtil/float128.h"
+#include "src/__support/macros/properties/types.h" // LIBC_TYPES_HAS_FLOAT128, fputil::Float128 forward-decl
namespace LIBC_NAMESPACE_DECL {
namespace cpp {
@@ -40,7 +39,7 @@ template <typename T> struct is_floating_point {
,
bfloat16
,
- fputil::Float128>();
+ fputil::EFloat128>();
};
template <typename T>
diff --git a/libc/src/__support/FPUtil/float128.h b/libc/src/__support/FPUtil/float128.h
index c14665ece42fc..f95fb133fd92e 100644
--- a/libc/src/__support/FPUtil/float128.h
+++ b/libc/src/__support/FPUtil/float128.h
@@ -1,4 +1,4 @@
-//===-- Definition for Float128 data type ----------------------*- C++ -*-===//
+//===-- Definition for EFloat128 data type ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,7 +9,7 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FLOAT128_H
-#include "src/__support/CPP/bit.h" // cpp::bit_cast
+#include "src/__support/CPP/bit.h" // cpp::bit_cast
#include "src/__support/macros/attributes.h"
#include "src/__support/macros/config.h"
#include "src/__support/uint128.h"
@@ -18,12 +18,12 @@
namespace LIBC_NAMESPACE_DECL {
namespace fputil {
-struct Float128 {
+struct EFloat128 {
UInt128 bits;
- LIBC_INLINE Float128() = default;
+ LIBC_INLINE EFloat128() = default;
- LIBC_INLINE constexpr explicit Float128(double x) {
+ LIBC_INLINE constexpr explicit EFloat128(double x) {
uint64_t d = cpp::bit_cast<uint64_t>(x);
bits = static_cast<UInt128>(d) << 64U;
}
@@ -32,10 +32,10 @@ struct Float128 {
return cpp::bit_cast<double>(static_cast<uint64_t>(bits >> 64U));
}
- LIBC_INLINE constexpr bool operator==(Float128 other) const {
+ LIBC_INLINE constexpr bool operator==(EFloat128 other) const {
return bits == other.bits;
}
- LIBC_INLINE constexpr bool operator!=(Float128 other) const {
+ LIBC_INLINE constexpr bool operator!=(EFloat128 other) const {
return bits != other.bits;
}
};
diff --git a/libc/src/__support/macros/properties/types.h b/libc/src/__support/macros/properties/types.h
index 3c981173d8c44..c7c09c07f95e4 100644
--- a/libc/src/__support/macros/properties/types.h
+++ b/libc/src/__support/macros/properties/types.h
@@ -59,14 +59,13 @@ using float16 = _Float16;
// "include/llvm-libc-types/float128.h"
// -- Emulated float128 support ------------------------------------------------
+// EFloat128 is always available regardless of native __float128 support.
namespace LIBC_NAMESPACE_DECL {
namespace fputil {
-struct Float128;
+struct EFloat128;
}
} // namespace LIBC_NAMESPACE_DECL
-using float128 = LIBC_NAMESPACE::fputil::Float128;
-
// -- bfloat16 support ---------------------------------------------------------
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/test/src/math/smoke/float128_test.cpp b/libc/test/src/math/smoke/float128_test.cpp
index 2697819e972b9..b1b8fde9907bb 100644
--- a/libc/test/src/math/smoke/float128_test.cpp
+++ b/libc/test/src/math/smoke/float128_test.cpp
@@ -1,4 +1,4 @@
-//===-- Unittests for Float128 emulated type ------------------------------===//
+//===-- Unittests for EFloat128 emulated type -----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,29 +10,16 @@
#include "src/__support/uint128.h"
#include "test/UnitTest/Test.h"
-using LIBC_NAMESPACE::fputil::Float128;
+using LIBC_NAMESPACE::fputil::EFloat128;
-TEST(LlvmLibcFloat128Test, DefaultConstructor) {
- Float128 x;
- (void)x; // TEST 1>
+TEST(LlvmLibcEFloat128Test, DefaultConstructor) {
+ EFloat128 x;
+ (void)x;
}
-TEST(LlvmLibcFloat128Test, doubleToFloat128) {
- // Double -> Float128 -> double should give back the same value
- constexpr double vals[] = {0.0, 1.0, -1.0, 2.0, 0.5, 3.14};
- for (double v : vals) {
- Float128 x(v);
- ASSERT_EQ(static_cast<double>(x), v);
- }
-}
-
-TEST(LlvmLibcFloat128Test, ZeroBits) {
- Float128 x(0.0);
- ASSERT_EQ(x.bits, static_cast<LIBC_NAMESPACE::UInt128>(0));
-}
-
-TEST(LlvmLibcFloat128Test, Equality) {
- Float128 a(1.0), b(1.0), c(2.0);
+TEST(LlvmLibcEFloat128Test, Equality) {
+ EFloat128 a(1.0), b(1.0), c(2.0);
ASSERT_TRUE(a == b);
ASSERT_TRUE(a != c);
+ ASSERT_TRUE(b != c);
}
>From ff30eafb00f3d2a9d569f2cfb2cdf9dc6287a18b Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Mon, 1 Jun 2026 19:41:41 +0530
Subject: [PATCH 7/7] nit
---
libc/src/__support/FPUtil/FPBits.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h
index 5b7461a44cff5..ed27e04d6ac7d 100644
--- a/libc/src/__support/FPUtil/FPBits.h
+++ b/libc/src/__support/FPUtil/FPBits.h
@@ -822,7 +822,7 @@ template <typename T> LIBC_INLINE static constexpr FPType get_fp_type() {
#endif
else if constexpr (cpp::is_same_v<UnqualT, bfloat16>)
return FPType::BFloat16;
- else if constexpr (cpp::is_same_v<UnqualT, Float128>)
+ else if constexpr (cpp::is_same_v<UnqualT, EFloat128>)
return FPType::Float128;
else
static_assert(cpp::always_false<UnqualT>, "Unsupported type");
More information about the libc-commits
mailing list