[llvm-branch-commits] [compiler-rt] [libc] [compiler-rt][builtins] libc-backed quad-float comparison builtins (PR #212653)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Aug 8 15:14:10 PDT 2026
https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/212653
>From d2d22647c9fa3db2435738649a49a0819c70d6f8 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 29 Jul 2026 00:28:43 +0300
Subject: [PATCH 1/6] [libc][builtins] add cmp_helper for compiler-rt
soft-float comparisons
---
libc/src/__support/builtins/CMakeLists.txt | 7 +++
libc/src/__support/builtins/cmp_helper.h | 63 ++++++++++++++++++++++
2 files changed, 70 insertions(+)
create mode 100644 libc/src/__support/builtins/cmp_helper.h
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index a3e6303f09169..aa3afaf190304 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -232,6 +232,13 @@ add_header_library(
truncdfsf2.h
DEPENDS
libc.src.__support.builtins.fpconvert_helper
+ cmp_helper
+ HDRS
+ cmp_helper.h
+ DEPENDS
+ libc.src.__support.FPUtil.comparison_operations
+ libc.src.__support.FPUtil.fp_bits
+ libc.src.__support.macros.attributes
libc.src.__support.macros.config
)
diff --git a/libc/src/__support/builtins/cmp_helper.h b/libc/src/__support/builtins/cmp_helper.h
new file mode 100644
index 0000000000000..6616783cfc3e4
--- /dev/null
+++ b/libc/src/__support/builtins/cmp_helper.h
@@ -0,0 +1,63 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Shared floating-point comparison results for compiler-rt's soft-float
+/// compare builtins. These mirror compiler-rt's GCC-compatible __le<f>2 /
+/// __ge<f>2 / __unord<f>2 (quiet: they raise no FP exceptions), reusing
+/// LLVM-libc's IEEE comparison predicates, so they can be reused by
+/// compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_CMP_HELPER_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_CMP_HELPER_H
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/__support/FPUtil/comparison_operations.h"
+#include "src/__support/macros/attributes.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// GCC soft-float compare, "LE" convention: -1 if a<b, 0 if a==b, 1 if a>b, and
+// 1 when unordered (either operand is NaN). Quiet -- raises no FP exceptions,
+// matching compiler-rt's __le<f>2 (which __eq/__ne/__lt/__cmp alias). NaN is
+// handled up front so the ordering predicates are only reached for non-NaN
+// inputs, where they never signal.
+template <typename T> LIBC_INLINE int cmp_le(T a, T b) {
+ using FPBits = fputil::FPBits<T>;
+ if (FPBits(a).is_nan() || FPBits(b).is_nan())
+ return 1; // LE_UNORDERED
+ if (fputil::equals(a, b))
+ return 0; // LE_EQUAL
+ return fputil::less_than(a, b) ? -1 : 1; // LE_LESS : LE_GREATER
+}
+
+// Same as cmp_le, but unordered yields -1; matches compiler-rt's __ge<f>2
+// (which __gt aliases).
+template <typename T> LIBC_INLINE int cmp_ge(T a, T b) {
+ using FPBits = fputil::FPBits<T>;
+ if (FPBits(a).is_nan() || FPBits(b).is_nan())
+ return -1; // GE_UNORDERED
+ if (fputil::equals(a, b))
+ return 0; // GE_EQUAL
+ return fputil::greater_than(a, b) ? 1 : -1; // GE_GREATER : GE_LESS
+}
+
+// 1 iff either operand is NaN, else 0; matches compiler-rt's __unord<f>2.
+template <typename T> LIBC_INLINE int cmp_unord(T a, T b) {
+ using FPBits = fputil::FPBits<T>;
+ return FPBits(a).is_nan() || FPBits(b).is_nan();
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_CMP_HELPER_H
>From 1725b1ea7195bb8789108fcba0bf9cc2fe6f62da Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 29 Jul 2026 02:14:36 +0300
Subject: [PATCH 2/6] fix format
---
libc/src/__support/builtins/cmp_helper.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libc/src/__support/builtins/cmp_helper.h b/libc/src/__support/builtins/cmp_helper.h
index 6616783cfc3e4..7cbfb70287f59 100644
--- a/libc/src/__support/builtins/cmp_helper.h
+++ b/libc/src/__support/builtins/cmp_helper.h
@@ -36,7 +36,7 @@ template <typename T> LIBC_INLINE int cmp_le(T a, T b) {
if (FPBits(a).is_nan() || FPBits(b).is_nan())
return 1; // LE_UNORDERED
if (fputil::equals(a, b))
- return 0; // LE_EQUAL
+ return 0; // LE_EQUAL
return fputil::less_than(a, b) ? -1 : 1; // LE_LESS : LE_GREATER
}
@@ -47,7 +47,7 @@ template <typename T> LIBC_INLINE int cmp_ge(T a, T b) {
if (FPBits(a).is_nan() || FPBits(b).is_nan())
return -1; // GE_UNORDERED
if (fputil::equals(a, b))
- return 0; // GE_EQUAL
+ return 0; // GE_EQUAL
return fputil::greater_than(a, b) ? 1 : -1; // GE_GREATER : GE_LESS
}
>From 53813ad68dfd9d082bbed0b0998cb05d1df07b62 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 29 Jul 2026 01:24:14 +0300
Subject: [PATCH 3/6] [compiler-rt][builtins] libc-backed single-float
comparison builtins
---
compiler-rt/lib/builtins/CMakeLists.txt | 1 +
compiler-rt/lib/builtins/comparesf2.cpp | 54 ++++++++++++++++++++++
libc/shared/builtins.h | 3 ++
libc/shared/builtins/gesf2.h | 29 ++++++++++++
libc/shared/builtins/lesf2.h | 29 ++++++++++++
libc/shared/builtins/unordsf2.h | 29 ++++++++++++
libc/src/__support/builtins/CMakeLists.txt | 17 +++++++
libc/src/__support/builtins/gesf2.h | 30 ++++++++++++
libc/src/__support/builtins/lesf2.h | 30 ++++++++++++
libc/src/__support/builtins/unordsf2.h | 30 ++++++++++++
libc/test/shared/CMakeLists.txt | 3 ++
libc/test/shared/shared_builtins_test.cpp | 15 ++++++
12 files changed, 270 insertions(+)
create mode 100644 compiler-rt/lib/builtins/comparesf2.cpp
create mode 100644 libc/shared/builtins/gesf2.h
create mode 100644 libc/shared/builtins/lesf2.h
create mode 100644 libc/shared/builtins/unordsf2.h
create mode 100644 libc/src/__support/builtins/gesf2.h
create mode 100644 libc/src/__support/builtins/lesf2.h
create mode 100644 libc/src/__support/builtins/unordsf2.h
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index e7827f2201b43..2dd2935882143 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -288,6 +288,7 @@ if(COMPILER_RT_USE_LIBC_MATH)
use_libc_builtin(GENERIC_SOURCES adddf3)
use_libc_builtin(GENERIC_SOURCES addsf3)
use_libc_builtin(GENERIC_TF_SOURCES addtf3)
+ use_libc_builtin(GENERIC_SOURCES comparesf2)
use_libc_builtin(GENERIC_SOURCES divdf3)
use_libc_builtin(GENERIC_SOURCES divsf3)
use_libc_builtin(GENERIC_TF_SOURCES divtf3)
diff --git a/compiler-rt/lib/builtins/comparesf2.cpp b/compiler-rt/lib/builtins/comparesf2.cpp
new file mode 100644
index 0000000000000..4db28588f4afc
--- /dev/null
+++ b/compiler-rt/lib/builtins/comparesf2.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file implements compiler-rt's float comparison routines
+/// (__lesf2/__gesf2/__unordsf2 and their aliases) on top of LLVM-libc's shared
+/// comparison builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#define SINGLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_compare_impl.inc"
+#include "fp_libc_config.h"
+#include "shared/builtins/gesf2.h"
+#include "shared/builtins/lesf2.h"
+#include "shared/builtins/unordsf2.h"
+
+extern "C" {
+
+COMPILER_RT_ABI CMP_RESULT __lesf2(fp_t a, fp_t b) {
+ return LIBC_NAMESPACE::shared::lesf2(a, b);
+}
+#if defined(__ELF__)
+COMPILER_RT_ALIAS(__lesf2, __cmpsf2)
+#endif
+COMPILER_RT_ALIAS(__lesf2, __eqsf2)
+COMPILER_RT_ALIAS(__lesf2, __ltsf2)
+COMPILER_RT_ALIAS(__lesf2, __nesf2)
+
+COMPILER_RT_ABI CMP_RESULT __gesf2(fp_t a, fp_t b) {
+ return LIBC_NAMESPACE::shared::gesf2(a, b);
+}
+COMPILER_RT_ALIAS(__gesf2, __gtsf2)
+
+COMPILER_RT_ABI CMP_RESULT __unordsf2(fp_t a, fp_t b) {
+ return LIBC_NAMESPACE::shared::unordsf2(a, b);
+}
+
+#if defined(__ARM_EABI__)
+#if defined(COMPILER_RT_ARMHF_TARGET)
+AEABI_RTABI int __aeabi_fcmpun(fp_t a, fp_t b) { return __unordsf2(a, b); }
+#else
+COMPILER_RT_ALIAS(__unordsf2, __aeabi_fcmpun)
+#endif
+#endif
+
+} // extern "C"
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 21c2bed4a0af1..592ba3589dc47 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -51,6 +51,8 @@
#include "builtins/floatunsisf.h"
#include "builtins/floatuntidf.h"
#include "builtins/floatuntisf.h"
+#include "builtins/gesf2.h"
+#include "builtins/lesf2.h"
#include "builtins/muldf3.h"
#include "builtins/mulsf3.h"
#include "builtins/multf3.h"
@@ -63,5 +65,6 @@
#include "builtins/trunctfdf2.h"
#include "builtins/trunctfsf2.h"
#include "builtins/trunctfxf2.h"
+#include "builtins/unordsf2.h"
#endif // LLVM_LIBC_SHARED_BUILTINS_H
diff --git a/libc/shared/builtins/gesf2.h b/libc/shared/builtins/gesf2.h
new file mode 100644
index 0000000000000..81b0d3972d280
--- /dev/null
+++ b/libc/shared/builtins/gesf2.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __gesf2 implementation as shared::gesf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_GESF2_H
+#define LLVM_LIBC_SHARED_BUILTINS_GESF2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/gesf2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::gesf2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_GESF2_H
diff --git a/libc/shared/builtins/lesf2.h b/libc/shared/builtins/lesf2.h
new file mode 100644
index 0000000000000..3fec6d3f0366f
--- /dev/null
+++ b/libc/shared/builtins/lesf2.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __lesf2 implementation as shared::lesf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_LESF2_H
+#define LLVM_LIBC_SHARED_BUILTINS_LESF2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/lesf2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::lesf2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_LESF2_H
diff --git a/libc/shared/builtins/unordsf2.h b/libc/shared/builtins/unordsf2.h
new file mode 100644
index 0000000000000..eb2c4d4c0483e
--- /dev/null
+++ b/libc/shared/builtins/unordsf2.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __unordsf2 implementation as
+/// shared::unordsf2 so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_UNORDSF2_H
+#define LLVM_LIBC_SHARED_BUILTINS_UNORDSF2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/unordsf2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::unordsf2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_UNORDSF2_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index aa3afaf190304..da47cc044613b 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -249,6 +249,11 @@ add_header_library(
DEPENDS
libc.hdr.stdint_proxy
libc.src.__support.builtins.fixint_helper
+ lesf2
+ HDRS
+ lesf2.h
+ DEPENDS
+ libc.src.__support.builtins.cmp_helper
libc.src.__support.macros.config
)
@@ -271,6 +276,11 @@ add_header_library(
DEPENDS
libc.hdr.stdint_proxy
libc.src.__support.builtins.fixint_helper
+ gesf2
+ HDRS
+ gesf2.h
+ DEPENDS
+ libc.src.__support.builtins.cmp_helper
libc.src.__support.macros.config
)
@@ -492,4 +502,11 @@ add_header_library(
libc.src.__support.builtins.floatint_helper
libc.src.__support.macros.config
libc.src.__support.macros.properties.types
+)
+ unordsf2
+ HDRS
+ unordsf2.h
+ DEPENDS
+ libc.src.__support.builtins.cmp_helper
+ libc.src.__support.macros.config
)
diff --git a/libc/src/__support/builtins/gesf2.h b/libc/src/__support/builtins/gesf2.h
new file mode 100644
index 0000000000000..14523acce5be7
--- /dev/null
+++ b/libc/src/__support/builtins/gesf2.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __gesf2 implementation as builtins::gesf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_GESF2_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_GESF2_H
+
+#include "src/__support/builtins/cmp_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Greater-equal comparison of float; mirrors compiler-rt's __gesf2.
+LIBC_INLINE int gesf2(float a, float b) { return cmp_ge(a, b); }
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_GESF2_H
diff --git a/libc/src/__support/builtins/lesf2.h b/libc/src/__support/builtins/lesf2.h
new file mode 100644
index 0000000000000..8358198d90df1
--- /dev/null
+++ b/libc/src/__support/builtins/lesf2.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __lesf2 implementation as builtins::lesf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_LESF2_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_LESF2_H
+
+#include "src/__support/builtins/cmp_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Less-equal comparison of float; mirrors compiler-rt's __lesf2.
+LIBC_INLINE int lesf2(float a, float b) { return cmp_le(a, b); }
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_LESF2_H
diff --git a/libc/src/__support/builtins/unordsf2.h b/libc/src/__support/builtins/unordsf2.h
new file mode 100644
index 0000000000000..23268413863e5
--- /dev/null
+++ b/libc/src/__support/builtins/unordsf2.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __unordsf2 implementation as
+/// builtins::unordsf2 so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_UNORDSF2_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_UNORDSF2_H
+
+#include "src/__support/builtins/cmp_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Unordered comparison of float; mirrors compiler-rt's __unordsf2.
+LIBC_INLINE int unordsf2(float a, float b) { return cmp_unord(a, b); }
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_UNORDSF2_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 49232caf377bc..681f17de5b9ec 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -862,6 +862,8 @@ add_fp_unittest(
libc.src.__support.builtins.floatunsisf
libc.src.__support.builtins.floatuntidf
libc.src.__support.builtins.floatuntisf
+ libc.src.__support.builtins.gesf2
+ libc.src.__support.builtins.lesf2
libc.src.__support.builtins.muldf3
libc.src.__support.builtins.mulsf3
libc.src.__support.builtins.multf3
@@ -875,6 +877,7 @@ add_fp_unittest(
libc.src.__support.builtins.trunctfsf2
libc.src.__support.builtins.trunctfxf2
libc.src.__support.uint128
+ libc.src.__support.builtins.unordsf2
)
add_fp_unittest(
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index eb1c566d6b179..771d16e001328 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -61,3 +61,18 @@ TEST(LlvmLibcSharedBuiltinsTest, TruncateConversion) {
#endif // LIBC_TYPES_LONG_DOUBLE_IS_X86_FLOAT80
#endif // LIBC_TYPES_HAS_FLOAT128
}
+
+TEST(LlvmLibcSharedBuiltinsTest, SingleCompare) {
+ const float aNaN =
+ LIBC_NAMESPACE::fputil::FPBits<float>::quiet_nan().get_val();
+ EXPECT_EQ(-1, shared::gesf2(1.0f, 2.0f));
+ EXPECT_EQ(0, shared::gesf2(1.0f, 1.0f));
+ EXPECT_EQ(1, shared::gesf2(2.0f, 1.0f));
+ EXPECT_EQ(-1, shared::gesf2(aNaN, 1.0f));
+ EXPECT_EQ(-1, shared::lesf2(1.0f, 2.0f));
+ EXPECT_EQ(0, shared::lesf2(1.0f, 1.0f));
+ EXPECT_EQ(1, shared::lesf2(2.0f, 1.0f));
+ EXPECT_EQ(1, shared::lesf2(aNaN, 1.0f));
+ EXPECT_EQ(0, shared::unordsf2(1.0f, 2.0f));
+ EXPECT_EQ(1, shared::unordsf2(aNaN, 1.0f));
+}
>From 4084a4a970d0174775a63f07f6b49e3ff7ffbd9c Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 29 Jul 2026 01:27:13 +0300
Subject: [PATCH 4/6] [compiler-rt][builtins] libc-backed double-float
comparison builtins
---
compiler-rt/lib/builtins/CMakeLists.txt | 1 +
compiler-rt/lib/builtins/comparedf2.cpp | 54 ++++++++++++++++++++++
libc/shared/builtins.h | 3 ++
libc/shared/builtins/gedf2.h | 29 ++++++++++++
libc/shared/builtins/ledf2.h | 29 ++++++++++++
libc/shared/builtins/unorddf2.h | 29 ++++++++++++
libc/src/__support/builtins/CMakeLists.txt | 27 +++++++++++
libc/src/__support/builtins/gedf2.h | 30 ++++++++++++
libc/src/__support/builtins/ledf2.h | 30 ++++++++++++
libc/src/__support/builtins/unorddf2.h | 30 ++++++++++++
libc/test/shared/CMakeLists.txt | 3 ++
libc/test/shared/shared_builtins_test.cpp | 15 ++++++
12 files changed, 280 insertions(+)
create mode 100644 compiler-rt/lib/builtins/comparedf2.cpp
create mode 100644 libc/shared/builtins/gedf2.h
create mode 100644 libc/shared/builtins/ledf2.h
create mode 100644 libc/shared/builtins/unorddf2.h
create mode 100644 libc/src/__support/builtins/gedf2.h
create mode 100644 libc/src/__support/builtins/ledf2.h
create mode 100644 libc/src/__support/builtins/unorddf2.h
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index 2dd2935882143..664eea84adb3c 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -288,6 +288,7 @@ if(COMPILER_RT_USE_LIBC_MATH)
use_libc_builtin(GENERIC_SOURCES adddf3)
use_libc_builtin(GENERIC_SOURCES addsf3)
use_libc_builtin(GENERIC_TF_SOURCES addtf3)
+ use_libc_builtin(GENERIC_SOURCES comparedf2)
use_libc_builtin(GENERIC_SOURCES comparesf2)
use_libc_builtin(GENERIC_SOURCES divdf3)
use_libc_builtin(GENERIC_SOURCES divsf3)
diff --git a/compiler-rt/lib/builtins/comparedf2.cpp b/compiler-rt/lib/builtins/comparedf2.cpp
new file mode 100644
index 0000000000000..d794c2dceeee4
--- /dev/null
+++ b/compiler-rt/lib/builtins/comparedf2.cpp
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file implements compiler-rt's double comparison routines
+/// (__ledf2/__gedf2/__unorddf2 and their aliases) on top of LLVM-libc's shared
+/// comparison builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#define DOUBLE_PRECISION
+#include "fp_lib.h"
+
+#include "fp_compare_impl.inc"
+#include "fp_libc_config.h"
+#include "shared/builtins/gedf2.h"
+#include "shared/builtins/ledf2.h"
+#include "shared/builtins/unorddf2.h"
+
+extern "C" {
+
+COMPILER_RT_ABI CMP_RESULT __ledf2(fp_t a, fp_t b) {
+ return LIBC_NAMESPACE::shared::ledf2(a, b);
+}
+#if defined(__ELF__)
+COMPILER_RT_ALIAS(__ledf2, __cmpdf2)
+#endif
+COMPILER_RT_ALIAS(__ledf2, __eqdf2)
+COMPILER_RT_ALIAS(__ledf2, __ltdf2)
+COMPILER_RT_ALIAS(__ledf2, __nedf2)
+
+COMPILER_RT_ABI CMP_RESULT __gedf2(fp_t a, fp_t b) {
+ return LIBC_NAMESPACE::shared::gedf2(a, b);
+}
+COMPILER_RT_ALIAS(__gedf2, __gtdf2)
+
+COMPILER_RT_ABI CMP_RESULT __unorddf2(fp_t a, fp_t b) {
+ return LIBC_NAMESPACE::shared::unorddf2(a, b);
+}
+
+#if defined(__ARM_EABI__)
+#if defined(COMPILER_RT_ARMHF_TARGET)
+AEABI_RTABI int __aeabi_dcmpun(fp_t a, fp_t b) { return __unorddf2(a, b); }
+#else
+COMPILER_RT_ALIAS(__unorddf2, __aeabi_dcmpun)
+#endif
+#endif
+
+} // extern "C"
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 592ba3589dc47..dc66b94274ed5 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -51,7 +51,9 @@
#include "builtins/floatunsisf.h"
#include "builtins/floatuntidf.h"
#include "builtins/floatuntisf.h"
+#include "builtins/gedf2.h"
#include "builtins/gesf2.h"
+#include "builtins/ledf2.h"
#include "builtins/lesf2.h"
#include "builtins/muldf3.h"
#include "builtins/mulsf3.h"
@@ -65,6 +67,7 @@
#include "builtins/trunctfdf2.h"
#include "builtins/trunctfsf2.h"
#include "builtins/trunctfxf2.h"
+#include "builtins/unorddf2.h"
#include "builtins/unordsf2.h"
#endif // LLVM_LIBC_SHARED_BUILTINS_H
diff --git a/libc/shared/builtins/gedf2.h b/libc/shared/builtins/gedf2.h
new file mode 100644
index 0000000000000..ee8714993d8a2
--- /dev/null
+++ b/libc/shared/builtins/gedf2.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __gedf2 implementation as shared::gedf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_GEDF2_H
+#define LLVM_LIBC_SHARED_BUILTINS_GEDF2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/gedf2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::gedf2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_GEDF2_H
diff --git a/libc/shared/builtins/ledf2.h b/libc/shared/builtins/ledf2.h
new file mode 100644
index 0000000000000..f57f4f2a4d271
--- /dev/null
+++ b/libc/shared/builtins/ledf2.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __ledf2 implementation as shared::ledf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_LEDF2_H
+#define LLVM_LIBC_SHARED_BUILTINS_LEDF2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/ledf2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::ledf2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_LEDF2_H
diff --git a/libc/shared/builtins/unorddf2.h b/libc/shared/builtins/unorddf2.h
new file mode 100644
index 0000000000000..a8db77c51415a
--- /dev/null
+++ b/libc/shared/builtins/unorddf2.h
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __unorddf2 implementation as
+/// shared::unorddf2 so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_UNORDDF2_H
+#define LLVM_LIBC_SHARED_BUILTINS_UNORDDF2_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/unorddf2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::unorddf2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_UNORDDF2_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index da47cc044613b..f35a3f421fa3d 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -510,3 +510,30 @@ add_header_library(
libc.src.__support.builtins.cmp_helper
libc.src.__support.macros.config
)
+
+add_header_library(
+ ledf2
+ HDRS
+ ledf2.h
+ DEPENDS
+ libc.src.__support.builtins.cmp_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ gedf2
+ HDRS
+ gedf2.h
+ DEPENDS
+ libc.src.__support.builtins.cmp_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ unorddf2
+ HDRS
+ unorddf2.h
+ DEPENDS
+ libc.src.__support.builtins.cmp_helper
+ libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/gedf2.h b/libc/src/__support/builtins/gedf2.h
new file mode 100644
index 0000000000000..710d6e0e71860
--- /dev/null
+++ b/libc/src/__support/builtins/gedf2.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __gedf2 implementation as builtins::gedf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_GEDF2_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_GEDF2_H
+
+#include "src/__support/builtins/cmp_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Greater-equal comparison of double; mirrors compiler-rt's __gedf2.
+LIBC_INLINE int gedf2(double a, double b) { return cmp_ge(a, b); }
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_GEDF2_H
diff --git a/libc/src/__support/builtins/ledf2.h b/libc/src/__support/builtins/ledf2.h
new file mode 100644
index 0000000000000..d96b02943384e
--- /dev/null
+++ b/libc/src/__support/builtins/ledf2.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __ledf2 implementation as builtins::ledf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_LEDF2_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_LEDF2_H
+
+#include "src/__support/builtins/cmp_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Less-equal comparison of double; mirrors compiler-rt's __ledf2.
+LIBC_INLINE int ledf2(double a, double b) { return cmp_le(a, b); }
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_LEDF2_H
diff --git a/libc/src/__support/builtins/unorddf2.h b/libc/src/__support/builtins/unorddf2.h
new file mode 100644
index 0000000000000..2d4f5f3f1fcc1
--- /dev/null
+++ b/libc/src/__support/builtins/unorddf2.h
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __unorddf2 implementation as
+/// builtins::unorddf2 so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_UNORDDF2_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_UNORDDF2_H
+
+#include "src/__support/builtins/cmp_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Unordered comparison of double; mirrors compiler-rt's __unorddf2.
+LIBC_INLINE int unorddf2(double a, double b) { return cmp_unord(a, b); }
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_UNORDDF2_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 681f17de5b9ec..7a5b6453ca8ff 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -862,7 +862,9 @@ add_fp_unittest(
libc.src.__support.builtins.floatunsisf
libc.src.__support.builtins.floatuntidf
libc.src.__support.builtins.floatuntisf
+ libc.src.__support.builtins.gedf2
libc.src.__support.builtins.gesf2
+ libc.src.__support.builtins.ledf2
libc.src.__support.builtins.lesf2
libc.src.__support.builtins.muldf3
libc.src.__support.builtins.mulsf3
@@ -877,6 +879,7 @@ add_fp_unittest(
libc.src.__support.builtins.trunctfsf2
libc.src.__support.builtins.trunctfxf2
libc.src.__support.uint128
+ libc.src.__support.builtins.unorddf2
libc.src.__support.builtins.unordsf2
)
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 771d16e001328..57e789b231931 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -76,3 +76,18 @@ TEST(LlvmLibcSharedBuiltinsTest, SingleCompare) {
EXPECT_EQ(0, shared::unordsf2(1.0f, 2.0f));
EXPECT_EQ(1, shared::unordsf2(aNaN, 1.0f));
}
+
+TEST_F(LlvmLibcSharedBuiltinsTest, DoubleCompare) {
+ const double aNaN =
+ LIBC_NAMESPACE::fputil::FPBits<double>::quiet_nan().get_val();
+ EXPECT_EQ(-1, shared::gedf2(1.0, 2.0));
+ EXPECT_EQ(0, shared::gedf2(1.0, 1.0));
+ EXPECT_EQ(1, shared::gedf2(2.0, 1.0));
+ EXPECT_EQ(-1, shared::gedf2(aNaN, 1.0));
+ EXPECT_EQ(-1, shared::ledf2(1.0, 2.0));
+ EXPECT_EQ(0, shared::ledf2(1.0, 1.0));
+ EXPECT_EQ(1, shared::ledf2(2.0, 1.0));
+ EXPECT_EQ(1, shared::ledf2(aNaN, 1.0));
+ EXPECT_EQ(0, shared::unorddf2(1.0, 2.0));
+ EXPECT_EQ(1, shared::unorddf2(aNaN, 1.0));
+}
>From e7b7fd1c7533121a7ef0640580bd7f023f247570 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 29 Jul 2026 01:29:11 +0300
Subject: [PATCH 5/6] [compiler-rt][builtins] libc-backed quad-float comparison
builtins
---
compiler-rt/lib/builtins/CMakeLists.txt | 1 +
compiler-rt/lib/builtins/comparetf2.cpp | 49 ++++++++++++++++++++++
libc/shared/builtins.h | 3 ++
libc/shared/builtins/getf2.h | 35 ++++++++++++++++
libc/shared/builtins/letf2.h | 35 ++++++++++++++++
libc/shared/builtins/unordtf2.h | 35 ++++++++++++++++
libc/src/__support/builtins/CMakeLists.txt | 30 +++++++++++++
libc/src/__support/builtins/getf2.h | 36 ++++++++++++++++
libc/src/__support/builtins/letf2.h | 36 ++++++++++++++++
libc/src/__support/builtins/unordtf2.h | 36 ++++++++++++++++
libc/test/shared/CMakeLists.txt | 3 ++
libc/test/shared/shared_builtins_test.cpp | 22 ++++++++++
12 files changed, 321 insertions(+)
create mode 100644 compiler-rt/lib/builtins/comparetf2.cpp
create mode 100644 libc/shared/builtins/getf2.h
create mode 100644 libc/shared/builtins/letf2.h
create mode 100644 libc/shared/builtins/unordtf2.h
create mode 100644 libc/src/__support/builtins/getf2.h
create mode 100644 libc/src/__support/builtins/letf2.h
create mode 100644 libc/src/__support/builtins/unordtf2.h
diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt
index 664eea84adb3c..a4393e10559b0 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -290,6 +290,7 @@ if(COMPILER_RT_USE_LIBC_MATH)
use_libc_builtin(GENERIC_TF_SOURCES addtf3)
use_libc_builtin(GENERIC_SOURCES comparedf2)
use_libc_builtin(GENERIC_SOURCES comparesf2)
+ use_libc_builtin(GENERIC_TF_SOURCES comparetf2)
use_libc_builtin(GENERIC_SOURCES divdf3)
use_libc_builtin(GENERIC_SOURCES divsf3)
use_libc_builtin(GENERIC_TF_SOURCES divtf3)
diff --git a/compiler-rt/lib/builtins/comparetf2.cpp b/compiler-rt/lib/builtins/comparetf2.cpp
new file mode 100644
index 0000000000000..8abd8f08dab93
--- /dev/null
+++ b/compiler-rt/lib/builtins/comparetf2.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file implements compiler-rt's float128 comparison routines
+/// (__letf2/__getf2/__unordtf2 and their aliases) on top of LLVM-libc's shared
+/// comparison builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#define QUAD_PRECISION
+#include "fp_lib.h"
+
+#if defined(CRT_HAS_TF_MODE)
+#include "fp_compare_impl.inc"
+#include "fp_libc_config.h"
+#include "shared/builtins/getf2.h"
+#include "shared/builtins/letf2.h"
+#include "shared/builtins/unordtf2.h"
+
+extern "C" {
+
+COMPILER_RT_ABI CMP_RESULT __letf2(fp_t a, fp_t b) {
+ return LIBC_NAMESPACE::shared::letf2(a, b);
+}
+#if defined(__ELF__)
+COMPILER_RT_ALIAS(__letf2, __cmptf2)
+#endif
+COMPILER_RT_ALIAS(__letf2, __eqtf2)
+COMPILER_RT_ALIAS(__letf2, __lttf2)
+COMPILER_RT_ALIAS(__letf2, __netf2)
+
+COMPILER_RT_ABI CMP_RESULT __getf2(fp_t a, fp_t b) {
+ return LIBC_NAMESPACE::shared::getf2(a, b);
+}
+COMPILER_RT_ALIAS(__getf2, __gttf2)
+
+COMPILER_RT_ABI CMP_RESULT __unordtf2(fp_t a, fp_t b) {
+ return LIBC_NAMESPACE::shared::unordtf2(a, b);
+}
+
+} // extern "C"
+
+#endif
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index dc66b94274ed5..29380688849e5 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -53,8 +53,10 @@
#include "builtins/floatuntisf.h"
#include "builtins/gedf2.h"
#include "builtins/gesf2.h"
+#include "builtins/getf2.h"
#include "builtins/ledf2.h"
#include "builtins/lesf2.h"
+#include "builtins/letf2.h"
#include "builtins/muldf3.h"
#include "builtins/mulsf3.h"
#include "builtins/multf3.h"
@@ -69,5 +71,6 @@
#include "builtins/trunctfxf2.h"
#include "builtins/unorddf2.h"
#include "builtins/unordsf2.h"
+#include "builtins/unordtf2.h"
#endif // LLVM_LIBC_SHARED_BUILTINS_H
diff --git a/libc/shared/builtins/getf2.h b/libc/shared/builtins/getf2.h
new file mode 100644
index 0000000000000..c91227edf391f
--- /dev/null
+++ b/libc/shared/builtins/getf2.h
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __getf2 implementation as shared::getf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_GETF2_H
+#define LLVM_LIBC_SHARED_BUILTINS_GETF2_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/getf2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::getf2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_GETF2_H
diff --git a/libc/shared/builtins/letf2.h b/libc/shared/builtins/letf2.h
new file mode 100644
index 0000000000000..55251ab0c7a08
--- /dev/null
+++ b/libc/shared/builtins/letf2.h
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __letf2 implementation as shared::letf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_LETF2_H
+#define LLVM_LIBC_SHARED_BUILTINS_LETF2_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/letf2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::letf2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_LETF2_H
diff --git a/libc/shared/builtins/unordtf2.h b/libc/shared/builtins/unordtf2.h
new file mode 100644
index 0000000000000..d2ceeea8944fc
--- /dev/null
+++ b/libc/shared/builtins/unordtf2.h
@@ -0,0 +1,35 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __unordtf2 implementation as
+/// shared::unordtf2 so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_UNORDTF2_H
+#define LLVM_LIBC_SHARED_BUILTINS_UNORDTF2_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/unordtf2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::unordtf2;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_UNORDTF2_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index f35a3f421fa3d..21fa7910b57ea 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -537,3 +537,33 @@ add_header_library(
libc.src.__support.builtins.cmp_helper
libc.src.__support.macros.config
)
+
+add_header_library(
+ letf2
+ HDRS
+ letf2.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.builtins.cmp_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ getf2
+ HDRS
+ getf2.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.builtins.cmp_helper
+ libc.src.__support.macros.config
+)
+
+add_header_library(
+ unordtf2
+ HDRS
+ unordtf2.h
+ DEPENDS
+ libc.include.llvm-libc-types.float128
+ libc.src.__support.builtins.cmp_helper
+ libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/getf2.h b/libc/src/__support/builtins/getf2.h
new file mode 100644
index 0000000000000..d24d210e3426a
--- /dev/null
+++ b/libc/src/__support/builtins/getf2.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __getf2 implementation as builtins::getf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_GETF2_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_GETF2_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/builtins/cmp_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Greater-equal comparison of float128; mirrors compiler-rt's __getf2.
+LIBC_INLINE int getf2(float128 a, float128 b) { return cmp_ge(a, b); }
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_GETF2_H
diff --git a/libc/src/__support/builtins/letf2.h b/libc/src/__support/builtins/letf2.h
new file mode 100644
index 0000000000000..ba901e2ade58a
--- /dev/null
+++ b/libc/src/__support/builtins/letf2.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __letf2 implementation as builtins::letf2 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_LETF2_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_LETF2_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/builtins/cmp_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Less-equal comparison of float128; mirrors compiler-rt's __letf2.
+LIBC_INLINE int letf2(float128 a, float128 b) { return cmp_le(a, b); }
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_LETF2_H
diff --git a/libc/src/__support/builtins/unordtf2.h b/libc/src/__support/builtins/unordtf2.h
new file mode 100644
index 0000000000000..d8e3ebf9644b3
--- /dev/null
+++ b/libc/src/__support/builtins/unordtf2.h
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __unordtf2 implementation as
+/// builtins::unordtf2 so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_UNORDTF2_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_UNORDTF2_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/builtins/cmp_helper.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Unordered comparison of float128; mirrors compiler-rt's __unordtf2.
+LIBC_INLINE int unordtf2(float128 a, float128 b) { return cmp_unord(a, b); }
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_UNORDTF2_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 7a5b6453ca8ff..4aa6a070785d1 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -864,8 +864,10 @@ add_fp_unittest(
libc.src.__support.builtins.floatuntisf
libc.src.__support.builtins.gedf2
libc.src.__support.builtins.gesf2
+ libc.src.__support.builtins.getf2
libc.src.__support.builtins.ledf2
libc.src.__support.builtins.lesf2
+ libc.src.__support.builtins.letf2
libc.src.__support.builtins.muldf3
libc.src.__support.builtins.mulsf3
libc.src.__support.builtins.multf3
@@ -881,6 +883,7 @@ add_fp_unittest(
libc.src.__support.uint128
libc.src.__support.builtins.unorddf2
libc.src.__support.builtins.unordsf2
+ libc.src.__support.builtins.unordtf2
)
add_fp_unittest(
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 57e789b231931..e05b7ac43c882 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -91,3 +91,25 @@ TEST_F(LlvmLibcSharedBuiltinsTest, DoubleCompare) {
EXPECT_EQ(0, shared::unorddf2(1.0, 2.0));
EXPECT_EQ(1, shared::unorddf2(aNaN, 1.0));
}
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+using LlvmLibcSharedBuiltinsQuadTest =
+ LIBC_NAMESPACE::testing::FPTest<float128>;
+
+TEST_F(LlvmLibcSharedBuiltinsQuadTest, Comparison) {
+ const float128 aNaN =
+ LIBC_NAMESPACE::fputil::FPBits<float128>::quiet_nan().get_val();
+ EXPECT_EQ(-1, shared::getf2(float128(1.0), float128(2.0)));
+ EXPECT_EQ(0, shared::getf2(float128(1.0), float128(1.0)));
+ EXPECT_EQ(1, shared::getf2(float128(2.0), float128(1.0)));
+ EXPECT_EQ(-1, shared::getf2(aNaN, float128(1.0)));
+ EXPECT_EQ(-1, shared::letf2(float128(1.0), float128(2.0)));
+ EXPECT_EQ(0, shared::letf2(float128(1.0), float128(1.0)));
+ EXPECT_EQ(1, shared::letf2(float128(2.0), float128(1.0)));
+ EXPECT_EQ(1, shared::letf2(aNaN, float128(1.0)));
+ EXPECT_EQ(0, shared::unordtf2(float128(1.0), float128(2.0)));
+ EXPECT_EQ(1, shared::unordtf2(aNaN, float128(1.0)));
+}
+
+#endif // LIBC_TYPES_HAS_FLOAT128
>From 980f4f6f12ad0f6dbd521abcd5e90b9ab8a13fde Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Sat, 1 Aug 2026 18:55:00 +0300
Subject: [PATCH 6/6] fix conflicts
---
libc/test/shared/shared_builtins_test.cpp | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index e05b7ac43c882..70910f1fc414d 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -77,7 +77,7 @@ TEST(LlvmLibcSharedBuiltinsTest, SingleCompare) {
EXPECT_EQ(1, shared::unordsf2(aNaN, 1.0f));
}
-TEST_F(LlvmLibcSharedBuiltinsTest, DoubleCompare) {
+TEST(LlvmLibcSharedBuiltinsTest, DoubleCompare) {
const double aNaN =
LIBC_NAMESPACE::fputil::FPBits<double>::quiet_nan().get_val();
EXPECT_EQ(-1, shared::gedf2(1.0, 2.0));
@@ -94,10 +94,7 @@ TEST_F(LlvmLibcSharedBuiltinsTest, DoubleCompare) {
#ifdef LIBC_TYPES_HAS_FLOAT128
-using LlvmLibcSharedBuiltinsQuadTest =
- LIBC_NAMESPACE::testing::FPTest<float128>;
-
-TEST_F(LlvmLibcSharedBuiltinsQuadTest, Comparison) {
+TEST(LlvmLibcSharedBuiltinsTest, Comparison) {
const float128 aNaN =
LIBC_NAMESPACE::fputil::FPBits<float128>::quiet_nan().get_val();
EXPECT_EQ(-1, shared::getf2(float128(1.0), float128(2.0)));
More information about the llvm-branch-commits
mailing list