[libc-commits] [libc] [libc] add shared subsf3 builtin (PR #205677)

via libc-commits libc-commits at lists.llvm.org
Wed Jun 24 14:03:23 PDT 2026


https://github.com/hulxv created https://github.com/llvm/llvm-project/pull/205677

Re-exposes LLVM-libc's `__subsf3` as `shared::subsf3` for reuse by compiler-rt's builtins.

Stacked change - merge these first:
- #200094
- #205669
- #205670
- #205671
- #205672
- #205673
- #205674
- #205675
- #205676


>From 9a0bb04b42e141693e7b5c6fbfe5623f1beb08b0 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 28 May 2026 03:01:10 +0300
Subject: [PATCH 01/12] [libc] introduce shared compiler-rt builtins

---
 libc/include/llvm-libc-macros/float-macros.h |  6 ++++
 libc/shared/builtins.h                       | 16 +++++++++
 libc/shared/builtins/addtf3.h                | 35 ++++++++++++++++++++
 libc/src/__support/CMakeLists.txt            |  1 +
 libc/src/__support/FPUtil/dyadic_float.h     |  3 ++
 libc/src/__support/builtins/CMakeLists.txt   |  9 +++++
 libc/src/__support/builtins/addtf3.h         | 32 ++++++++++++++++++
 libc/test/shared/CMakeLists.txt              | 10 ++++++
 libc/test/shared/shared_builtins_test.cpp    | 29 ++++++++++++++++
 9 files changed, 141 insertions(+)
 create mode 100644 libc/shared/builtins.h
 create mode 100644 libc/shared/builtins/addtf3.h
 create mode 100644 libc/src/__support/builtins/CMakeLists.txt
 create mode 100644 libc/src/__support/builtins/addtf3.h
 create mode 100644 libc/test/shared/shared_builtins_test.cpp

diff --git a/libc/include/llvm-libc-macros/float-macros.h b/libc/include/llvm-libc-macros/float-macros.h
index a25ef60a293d3..38a3a771cca54 100644
--- a/libc/include/llvm-libc-macros/float-macros.h
+++ b/libc/include/llvm-libc-macros/float-macros.h
@@ -9,6 +9,12 @@
 #ifndef LLVM_LIBC_MACROS_FLOAT_MACROS_H
 #define LLVM_LIBC_MACROS_FLOAT_MACROS_H
 
+// __has_builtin is a Clang extension; GCC < 10 doesn't define it, which
+// turns a bare `#if __has_builtin(...)` into a preprocessor syntax error.
+#ifndef __has_builtin
+#define __has_builtin(x) 0
+#endif
+
 #ifndef FLT_RADIX
 #define FLT_RADIX __FLT_RADIX__
 #endif // FLT_RADIX
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
new file mode 100644
index 0000000000000..157b6622cbcff
--- /dev/null
+++ b/libc/shared/builtins.h
@@ -0,0 +1,16 @@
+//===-- Compiler-runtime builtin primitives ---------------------*- 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_SHARED_BUILTINS_H
+#define LLVM_LIBC_SHARED_BUILTINS_H
+
+#include "libc_common.h"
+
+#include "builtins/addtf3.h"
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_H
diff --git a/libc/shared/builtins/addtf3.h b/libc/shared/builtins/addtf3.h
new file mode 100644
index 0000000000000..9c39e6e9a8406
--- /dev/null
+++ b/libc/shared/builtins/addtf3.h
@@ -0,0 +1,35 @@
+//===-- Shared __addtf3 function -------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This header exposes LLVM-libc's __addtf3 implementation as shared::addtf3
+// so that it can be reused by other LLVM projects, such as compiler-rt's
+// builtins library.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/addtf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::addtf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 9d08b4bcf7303..c09ca012c3594 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -472,6 +472,7 @@ add_subdirectory(wchar)
 add_subdirectory(wctype)
 
 add_subdirectory(math)
+add_subdirectory(builtins)
 if(LIBC_COMPILER_HAS_EXT_VECTOR_TYPE)
   add_subdirectory(mathvec)
 endif()
diff --git a/libc/src/__support/FPUtil/dyadic_float.h b/libc/src/__support/FPUtil/dyadic_float.h
index 7e4ea2f1a81be..d99a14f35f38e 100644
--- a/libc/src/__support/FPUtil/dyadic_float.h
+++ b/libc/src/__support/FPUtil/dyadic_float.h
@@ -415,6 +415,9 @@ template <size_t Bits> struct DyadicFloat {
     if constexpr (cpp::is_same_v<T, bfloat16>
 #if defined(LIBC_TYPES_HAS_FLOAT16) && !defined(__LIBC_USE_FLOAT16_CONVERSION)
                   || cpp::is_same_v<T, float16>
+#endif
+#if defined(LIBC_TYPES_HAS_FLOAT128)
+                  || cpp::is_same_v<T, float128>
 #endif
     )
       return generic_as<T, ShouldSignalExceptions>();
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
new file mode 100644
index 0000000000000..c4982887d0a7c
--- /dev/null
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -0,0 +1,9 @@
+add_header_library(
+  addtf3
+  HDRS
+    addtf3.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/addtf3.h b/libc/src/__support/builtins/addtf3.h
new file mode 100644
index 0000000000000..129ad2a81e827
--- /dev/null
+++ b/libc/src/__support/builtins/addtf3.h
@@ -0,0 +1,32 @@
+//===-- Implementation header for __addtf3 ----------------------*- 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_BUILTINS_ADDTF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDTF3_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Mirrors the compiler-rt __addtf3 ABI: a + b at float128 precision.
+LIBC_INLINE float128 addtf3(float128 x, float128 y) {
+  return fputil::generic::add<float128>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDTF3_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 7a5c3a369c2fc..0f8027e2e0057 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -814,6 +814,16 @@ add_fp_unittest(
 )
 endif() # LIBC_TEST_SKIP_SHARED_MATH_TESTS
 
+add_fp_unittest(
+  shared_builtins_test
+  SUITE
+    libc-shared-tests
+  SRCS
+    shared_builtins_test.cpp
+  DEPENDS
+    libc.src.__support.builtins.addtf3
+)
+
 add_fp_unittest(
   shared_str_to_num_test
   SUITE
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
new file mode 100644
index 0000000000000..67d40b349cef3
--- /dev/null
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -0,0 +1,29 @@
+//===-- Unittests for shared builtins -------------------------------------===//
+//
+// 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 "shared/builtins.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcSharedBuiltinsTest, AllFloat) {
+  // TODO: assertions for shared::*sf3 builtins.
+}
+
+TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {
+  // TODO: assertions for shared::*df3 builtins.
+}
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+TEST(LlvmLibcSharedBuiltinsTest, AllFloat128) {
+  namespace shared = LIBC_NAMESPACE::shared;
+
+  EXPECT_FP_EQ(float128(3.0), shared::addtf3(float128(1.0), float128(2.0)));
+}
+
+#endif // LIBC_TYPES_HAS_FLOAT128

>From 8a3828ae0484b9e8df38518fe12df718c9de5c17 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 11 Jun 2026 15:48:50 +0300
Subject: [PATCH 02/12] correct the header

---
 libc/shared/builtins/addtf3.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libc/shared/builtins/addtf3.h b/libc/shared/builtins/addtf3.h
index 9c39e6e9a8406..33534beeb91c7 100644
--- a/libc/shared/builtins/addtf3.h
+++ b/libc/shared/builtins/addtf3.h
@@ -1,15 +1,15 @@
-//===-- Shared __addtf3 function -------------------------------*- 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
 //
 //===----------------------------------------------------------------------===//
-//
-// This header exposes LLVM-libc's __addtf3 implementation as shared::addtf3
-// so that it can be reused by other LLVM projects, such as compiler-rt's
-// builtins library.
-//
+///
+/// \file
+/// This header exposes LLVM-libc's __addtf3 implementation as shared::addtf3
+/// so that it can be reused by compiler-rt's builtins.
+///
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SHARED_BUILTINS_ADDTF3_H

>From 0fea0cd53236c37ad58f9cc54d440ec0ad102823 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Tue, 23 Jun 2026 22:48:07 +0300
Subject: [PATCH 03/12] header

---
 libc/shared/builtins.h               | 8 +++++++-
 libc/src/__support/builtins/addtf3.h | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 157b6622cbcff..338755314d309 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -1,10 +1,16 @@
-//===-- Compiler-runtime builtin primitives ---------------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header aggregates LLVM-libc's shared compiler-rt builtins so that
+/// they can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SHARED_BUILTINS_H
 #define LLVM_LIBC_SHARED_BUILTINS_H
diff --git a/libc/src/__support/builtins/addtf3.h b/libc/src/__support/builtins/addtf3.h
index 129ad2a81e827..f33036f53ec30 100644
--- a/libc/src/__support/builtins/addtf3.h
+++ b/libc/src/__support/builtins/addtf3.h
@@ -1,10 +1,16 @@
-//===-- Implementation header for __addtf3 ----------------------*- 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
 //
 //===----------------------------------------------------------------------===//
+///
+/// \file
+/// This header exposes LLVM-libc's __addtf3 implementation as
+/// builtins::addtf3 so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
 
 #ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDTF3_H
 #define LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDTF3_H

>From 5b0f8cf2c1d877710f242e262750f712e26faf58 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 24 Jun 2026 22:32:52 +0300
Subject: [PATCH 04/12] [libc] add shared subtf3 builtin

---
 libc/shared/builtins.h                     |  1 +
 libc/shared/builtins/subtf3.h              | 35 ++++++++++++++++++++
 libc/src/__support/builtins/CMakeLists.txt | 10 ++++++
 libc/src/__support/builtins/subtf3.h       | 38 ++++++++++++++++++++++
 libc/test/shared/shared_builtins_test.cpp  | 10 ++++++
 5 files changed, 94 insertions(+)
 create mode 100644 libc/shared/builtins/subtf3.h
 create mode 100644 libc/src/__support/builtins/subtf3.h

diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 338755314d309..0bb156131423d 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -18,5 +18,6 @@
 #include "libc_common.h"
 
 #include "builtins/addtf3.h"
+#include "builtins/subtf3.h"
 
 #endif // LLVM_LIBC_SHARED_BUILTINS_H
diff --git a/libc/shared/builtins/subtf3.h b/libc/shared/builtins/subtf3.h
new file mode 100644
index 0000000000000..a7cecef8b0479
--- /dev/null
+++ b/libc/shared/builtins/subtf3.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 __subtf3 implementation as shared::subtf3 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_SUBTF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_SUBTF3_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/subtf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::subtf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_SUBTF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index c4982887d0a7c..d3d1d65babce8 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -7,3 +7,13 @@ add_header_library(
     libc.src.__support.FPUtil.generic.add_sub
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  subtf3
+  HDRS
+    subtf3.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/subtf3.h b/libc/src/__support/builtins/subtf3.h
new file mode 100644
index 0000000000000..bd758cce0f5f6
--- /dev/null
+++ b/libc/src/__support/builtins/subtf3.h
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __subtf3 implementation as builtins::subtf3
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBTF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBTF3_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Subtraction at float128 precision; mirrors compiler-rt's __subtf3.
+LIBC_INLINE float128 subtf3(float128 x, float128 y) {
+  return fputil::generic::sub<float128>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBTF3_H
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 67d40b349cef3..d2d9c71d4f4fd 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -27,3 +27,13 @@ TEST(LlvmLibcSharedBuiltinsTest, AllFloat128) {
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+TEST(LlvmLibcSharedBuiltinsTest, Subtf3) {
+  namespace shared = LIBC_NAMESPACE::shared;
+
+  EXPECT_FP_EQ(float128(2.0), shared::subtf3(float128(5.0), float128(3.0)));
+}
+
+#endif // LIBC_TYPES_HAS_FLOAT128

>From 163bcd1fa1a4700f5f145ac43ce4bcb32c8600e5 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 24 Jun 2026 22:32:53 +0300
Subject: [PATCH 05/12] [libc] add shared multf3 builtin

---
 libc/shared/builtins.h                     |  1 +
 libc/shared/builtins/multf3.h              | 35 ++++++++++++++++++++
 libc/src/__support/builtins/CMakeLists.txt | 10 ++++++
 libc/src/__support/builtins/multf3.h       | 38 ++++++++++++++++++++++
 libc/test/shared/shared_builtins_test.cpp  | 10 ++++++
 5 files changed, 94 insertions(+)
 create mode 100644 libc/shared/builtins/multf3.h
 create mode 100644 libc/src/__support/builtins/multf3.h

diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 0bb156131423d..26fed715ba2ad 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -18,6 +18,7 @@
 #include "libc_common.h"
 
 #include "builtins/addtf3.h"
+#include "builtins/multf3.h"
 #include "builtins/subtf3.h"
 
 #endif // LLVM_LIBC_SHARED_BUILTINS_H
diff --git a/libc/shared/builtins/multf3.h b/libc/shared/builtins/multf3.h
new file mode 100644
index 0000000000000..cfc2964fd6a79
--- /dev/null
+++ b/libc/shared/builtins/multf3.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 __multf3 implementation as shared::multf3 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_MULTF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_MULTF3_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/multf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::multf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_MULTF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index d3d1d65babce8..98274c9a90416 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -17,3 +17,13 @@ add_header_library(
     libc.src.__support.FPUtil.generic.add_sub
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  multf3
+  HDRS
+    multf3.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/multf3.h b/libc/src/__support/builtins/multf3.h
new file mode 100644
index 0000000000000..b6798325ff17d
--- /dev/null
+++ b/libc/src/__support/builtins/multf3.h
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __multf3 implementation as builtins::multf3
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_MULTF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_MULTF3_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Multiplication at float128 precision; mirrors compiler-rt's __multf3.
+LIBC_INLINE float128 multf3(float128 x, float128 y) {
+  return fputil::generic::mul<float128>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_MULTF3_H
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index d2d9c71d4f4fd..d5c0265660a5a 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -37,3 +37,13 @@ TEST(LlvmLibcSharedBuiltinsTest, Subtf3) {
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+TEST(LlvmLibcSharedBuiltinsTest, Multf3) {
+  namespace shared = LIBC_NAMESPACE::shared;
+
+  EXPECT_FP_EQ(float128(6.0), shared::multf3(float128(2.0), float128(3.0)));
+}
+
+#endif // LIBC_TYPES_HAS_FLOAT128

>From 486371ed17d81b615378e5e28b226c02492c3cc8 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 24 Jun 2026 22:32:55 +0300
Subject: [PATCH 06/12] [libc] add shared divtf3 builtin

---
 libc/shared/builtins.h                     |  1 +
 libc/shared/builtins/divtf3.h              | 35 ++++++++++++++++++++
 libc/src/__support/builtins/CMakeLists.txt | 10 ++++++
 libc/src/__support/builtins/divtf3.h       | 38 ++++++++++++++++++++++
 libc/test/shared/shared_builtins_test.cpp  | 10 ++++++
 5 files changed, 94 insertions(+)
 create mode 100644 libc/shared/builtins/divtf3.h
 create mode 100644 libc/src/__support/builtins/divtf3.h

diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 26fed715ba2ad..fc4c5aee9a8e4 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -18,6 +18,7 @@
 #include "libc_common.h"
 
 #include "builtins/addtf3.h"
+#include "builtins/divtf3.h"
 #include "builtins/multf3.h"
 #include "builtins/subtf3.h"
 
diff --git a/libc/shared/builtins/divtf3.h b/libc/shared/builtins/divtf3.h
new file mode 100644
index 0000000000000..ca69e6f5fc0e7
--- /dev/null
+++ b/libc/shared/builtins/divtf3.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 __divtf3 implementation as shared::divtf3 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_DIVTF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_DIVTF3_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/divtf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::divtf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_DIVTF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index 98274c9a90416..1b4f9ddab2a90 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -27,3 +27,13 @@ add_header_library(
     libc.src.__support.FPUtil.generic.mul
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  divtf3
+  HDRS
+    divtf3.h
+  DEPENDS
+    libc.include.llvm-libc-types.float128
+    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/divtf3.h b/libc/src/__support/builtins/divtf3.h
new file mode 100644
index 0000000000000..7f25586cde6c9
--- /dev/null
+++ b/libc/src/__support/builtins/divtf3.h
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __divtf3 implementation as builtins::divtf3
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVTF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVTF3_H
+
+#include "include/llvm-libc-types/float128.h"
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Division at float128 precision; mirrors compiler-rt's __divtf3.
+LIBC_INLINE float128 divtf3(float128 x, float128 y) {
+  return fputil::generic::div<float128>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LIBC_TYPES_HAS_FLOAT128
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVTF3_H
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index d5c0265660a5a..e06e7ae3eb88b 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -47,3 +47,13 @@ TEST(LlvmLibcSharedBuiltinsTest, Multf3) {
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
+
+#ifdef LIBC_TYPES_HAS_FLOAT128
+
+TEST(LlvmLibcSharedBuiltinsTest, Divtf3) {
+  namespace shared = LIBC_NAMESPACE::shared;
+
+  EXPECT_FP_EQ(float128(3.0), shared::divtf3(float128(6.0), float128(2.0)));
+}
+
+#endif // LIBC_TYPES_HAS_FLOAT128

>From 2411ad34ef0b2c72162420145134ccc6a0ff5e99 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 24 Jun 2026 22:32:56 +0300
Subject: [PATCH 07/12] [libc] add shared adddf3 builtin

---
 libc/shared/builtins.h                     |  1 +
 libc/shared/builtins/adddf3.h              | 29 ++++++++++++++++++++
 libc/src/__support/builtins/CMakeLists.txt |  9 ++++++
 libc/src/__support/builtins/adddf3.h       | 32 ++++++++++++++++++++++
 libc/test/shared/shared_builtins_test.cpp  |  6 ++++
 5 files changed, 77 insertions(+)
 create mode 100644 libc/shared/builtins/adddf3.h
 create mode 100644 libc/src/__support/builtins/adddf3.h

diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index fc4c5aee9a8e4..dca0171c02d18 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -17,6 +17,7 @@
 
 #include "libc_common.h"
 
+#include "builtins/adddf3.h"
 #include "builtins/addtf3.h"
 #include "builtins/divtf3.h"
 #include "builtins/multf3.h"
diff --git a/libc/shared/builtins/adddf3.h b/libc/shared/builtins/adddf3.h
new file mode 100644
index 0000000000000..33936cb8b2486
--- /dev/null
+++ b/libc/shared/builtins/adddf3.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 __adddf3 implementation as shared::adddf3 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_ADDDF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_ADDDF3_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/adddf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::adddf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_ADDDF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index 1b4f9ddab2a90..dee5a830b8857 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -37,3 +37,12 @@ add_header_library(
     libc.src.__support.FPUtil.generic.div
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  adddf3
+  HDRS
+    adddf3.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/adddf3.h b/libc/src/__support/builtins/adddf3.h
new file mode 100644
index 0000000000000..9fa60ca8d1c69
--- /dev/null
+++ b/libc/src/__support/builtins/adddf3.h
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __adddf3 implementation as builtins::adddf3
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDDF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDDF3_H
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Addition at double precision; mirrors compiler-rt's __adddf3.
+LIBC_INLINE double adddf3(double x, double y) {
+  return fputil::generic::add<double>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDDF3_H
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index e06e7ae3eb88b..95f7fb5ae4a30 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -57,3 +57,9 @@ TEST(LlvmLibcSharedBuiltinsTest, Divtf3) {
 }
 
 #endif // LIBC_TYPES_HAS_FLOAT128
+
+TEST(LlvmLibcSharedBuiltinsTest, Adddf3) {
+  namespace shared = LIBC_NAMESPACE::shared;
+
+  EXPECT_FP_EQ(double(3.0), shared::adddf3(double(1.0), double(2.0)));
+}

>From ed03f241ae3dc6d0a0edfa27dc0e825eed189eb3 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 24 Jun 2026 22:32:57 +0300
Subject: [PATCH 08/12] [libc] add shared subdf3 builtin

---
 libc/shared/builtins.h                     |  1 +
 libc/shared/builtins/subdf3.h              | 29 ++++++++++++++++++++
 libc/src/__support/builtins/CMakeLists.txt |  9 ++++++
 libc/src/__support/builtins/subdf3.h       | 32 ++++++++++++++++++++++
 libc/test/shared/shared_builtins_test.cpp  |  6 ++++
 5 files changed, 77 insertions(+)
 create mode 100644 libc/shared/builtins/subdf3.h
 create mode 100644 libc/src/__support/builtins/subdf3.h

diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index dca0171c02d18..867bf6df0d306 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -21,6 +21,7 @@
 #include "builtins/addtf3.h"
 #include "builtins/divtf3.h"
 #include "builtins/multf3.h"
+#include "builtins/subdf3.h"
 #include "builtins/subtf3.h"
 
 #endif // LLVM_LIBC_SHARED_BUILTINS_H
diff --git a/libc/shared/builtins/subdf3.h b/libc/shared/builtins/subdf3.h
new file mode 100644
index 0000000000000..8cff7e3bfa28f
--- /dev/null
+++ b/libc/shared/builtins/subdf3.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 __subdf3 implementation as shared::subdf3 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_SUBDF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_SUBDF3_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/subdf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::subdf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_SUBDF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index dee5a830b8857..47dbc6cddbf68 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -46,3 +46,12 @@ add_header_library(
     libc.src.__support.FPUtil.generic.add_sub
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  subdf3
+  HDRS
+    subdf3.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/subdf3.h b/libc/src/__support/builtins/subdf3.h
new file mode 100644
index 0000000000000..5e704aa714af6
--- /dev/null
+++ b/libc/src/__support/builtins/subdf3.h
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __subdf3 implementation as builtins::subdf3
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBDF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBDF3_H
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Subtraction at double precision; mirrors compiler-rt's __subdf3.
+LIBC_INLINE double subdf3(double x, double y) {
+  return fputil::generic::sub<double>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBDF3_H
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 95f7fb5ae4a30..0186223098744 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -63,3 +63,9 @@ TEST(LlvmLibcSharedBuiltinsTest, Adddf3) {
 
   EXPECT_FP_EQ(double(3.0), shared::adddf3(double(1.0), double(2.0)));
 }
+
+TEST(LlvmLibcSharedBuiltinsTest, Subdf3) {
+  namespace shared = LIBC_NAMESPACE::shared;
+
+  EXPECT_FP_EQ(double(2.0), shared::subdf3(double(5.0), double(3.0)));
+}

>From d68643bea0380c21ecba1b8e4ff7ceb147ddd654 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 24 Jun 2026 22:32:58 +0300
Subject: [PATCH 09/12] [libc] add shared muldf3 builtin

---
 libc/shared/builtins.h                     |  1 +
 libc/shared/builtins/muldf3.h              | 29 ++++++++++++++++++++
 libc/src/__support/builtins/CMakeLists.txt |  9 ++++++
 libc/src/__support/builtins/muldf3.h       | 32 ++++++++++++++++++++++
 libc/test/shared/shared_builtins_test.cpp  |  6 ++++
 5 files changed, 77 insertions(+)
 create mode 100644 libc/shared/builtins/muldf3.h
 create mode 100644 libc/src/__support/builtins/muldf3.h

diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 867bf6df0d306..2540be78519d7 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -20,6 +20,7 @@
 #include "builtins/adddf3.h"
 #include "builtins/addtf3.h"
 #include "builtins/divtf3.h"
+#include "builtins/muldf3.h"
 #include "builtins/multf3.h"
 #include "builtins/subdf3.h"
 #include "builtins/subtf3.h"
diff --git a/libc/shared/builtins/muldf3.h b/libc/shared/builtins/muldf3.h
new file mode 100644
index 0000000000000..702c73428e5f4
--- /dev/null
+++ b/libc/shared/builtins/muldf3.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 __muldf3 implementation as shared::muldf3 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_MULDF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_MULDF3_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/muldf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::muldf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_MULDF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index 47dbc6cddbf68..179337c4d6cf0 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -55,3 +55,12 @@ add_header_library(
     libc.src.__support.FPUtil.generic.add_sub
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  muldf3
+  HDRS
+    muldf3.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.mul
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/muldf3.h b/libc/src/__support/builtins/muldf3.h
new file mode 100644
index 0000000000000..b407b96ef90b4
--- /dev/null
+++ b/libc/src/__support/builtins/muldf3.h
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __muldf3 implementation as builtins::muldf3
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_MULDF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_MULDF3_H
+
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Multiplication at double precision; mirrors compiler-rt's __muldf3.
+LIBC_INLINE double muldf3(double x, double y) {
+  return fputil::generic::mul<double>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_MULDF3_H
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 0186223098744..f79382ffa1df4 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -69,3 +69,9 @@ TEST(LlvmLibcSharedBuiltinsTest, Subdf3) {
 
   EXPECT_FP_EQ(double(2.0), shared::subdf3(double(5.0), double(3.0)));
 }
+
+TEST(LlvmLibcSharedBuiltinsTest, Muldf3) {
+  namespace shared = LIBC_NAMESPACE::shared;
+
+  EXPECT_FP_EQ(double(6.0), shared::muldf3(double(2.0), double(3.0)));
+}

>From 9296720fd9b09709919251c0ca7d6b595972b053 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 24 Jun 2026 22:32:59 +0300
Subject: [PATCH 10/12] [libc] add shared divdf3 builtin

---
 libc/shared/builtins.h                     |  1 +
 libc/shared/builtins/divdf3.h              | 29 ++++++++++++++++++++
 libc/src/__support/builtins/CMakeLists.txt |  9 ++++++
 libc/src/__support/builtins/divdf3.h       | 32 ++++++++++++++++++++++
 libc/test/shared/shared_builtins_test.cpp  |  6 ++++
 5 files changed, 77 insertions(+)
 create mode 100644 libc/shared/builtins/divdf3.h
 create mode 100644 libc/src/__support/builtins/divdf3.h

diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 2540be78519d7..94ff3fb32ee69 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -19,6 +19,7 @@
 
 #include "builtins/adddf3.h"
 #include "builtins/addtf3.h"
+#include "builtins/divdf3.h"
 #include "builtins/divtf3.h"
 #include "builtins/muldf3.h"
 #include "builtins/multf3.h"
diff --git a/libc/shared/builtins/divdf3.h b/libc/shared/builtins/divdf3.h
new file mode 100644
index 0000000000000..4cabc847b7a02
--- /dev/null
+++ b/libc/shared/builtins/divdf3.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 __divdf3 implementation as shared::divdf3 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_DIVDF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_DIVDF3_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/divdf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::divdf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_DIVDF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index 179337c4d6cf0..69b9de039d465 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -64,3 +64,12 @@ add_header_library(
     libc.src.__support.FPUtil.generic.mul
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  divdf3
+  HDRS
+    divdf3.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.div
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/divdf3.h b/libc/src/__support/builtins/divdf3.h
new file mode 100644
index 0000000000000..b9af2252be389
--- /dev/null
+++ b/libc/src/__support/builtins/divdf3.h
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __divdf3 implementation as builtins::divdf3
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVDF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVDF3_H
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Division at double precision; mirrors compiler-rt's __divdf3.
+LIBC_INLINE double divdf3(double x, double y) {
+  return fputil::generic::div<double>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVDF3_H
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index f79382ffa1df4..7f06d8084f98c 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -75,3 +75,9 @@ TEST(LlvmLibcSharedBuiltinsTest, Muldf3) {
 
   EXPECT_FP_EQ(double(6.0), shared::muldf3(double(2.0), double(3.0)));
 }
+
+TEST(LlvmLibcSharedBuiltinsTest, Divdf3) {
+  namespace shared = LIBC_NAMESPACE::shared;
+
+  EXPECT_FP_EQ(double(3.0), shared::divdf3(double(6.0), double(2.0)));
+}

>From 5473f0e9588d453d9447dd7f3a347335578ac7a0 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 24 Jun 2026 22:33:01 +0300
Subject: [PATCH 11/12] [libc] add shared addsf3 builtin

---
 libc/shared/builtins.h                     |  1 +
 libc/shared/builtins/addsf3.h              | 29 ++++++++++++++++++++
 libc/src/__support/builtins/CMakeLists.txt |  9 ++++++
 libc/src/__support/builtins/addsf3.h       | 32 ++++++++++++++++++++++
 libc/test/shared/shared_builtins_test.cpp  |  6 ++++
 5 files changed, 77 insertions(+)
 create mode 100644 libc/shared/builtins/addsf3.h
 create mode 100644 libc/src/__support/builtins/addsf3.h

diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 94ff3fb32ee69..a6a8973beda25 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -18,6 +18,7 @@
 #include "libc_common.h"
 
 #include "builtins/adddf3.h"
+#include "builtins/addsf3.h"
 #include "builtins/addtf3.h"
 #include "builtins/divdf3.h"
 #include "builtins/divtf3.h"
diff --git a/libc/shared/builtins/addsf3.h b/libc/shared/builtins/addsf3.h
new file mode 100644
index 0000000000000..58f8797d93705
--- /dev/null
+++ b/libc/shared/builtins/addsf3.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 __addsf3 implementation as shared::addsf3 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_ADDSF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_ADDSF3_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/addsf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::addsf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_ADDSF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index 69b9de039d465..69d714b9fa207 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -73,3 +73,12 @@ add_header_library(
     libc.src.__support.FPUtil.generic.div
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  addsf3
+  HDRS
+    addsf3.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/addsf3.h b/libc/src/__support/builtins/addsf3.h
new file mode 100644
index 0000000000000..5fa55e30dd0c6
--- /dev/null
+++ b/libc/src/__support/builtins/addsf3.h
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __addsf3 implementation as builtins::addsf3
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDSF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDSF3_H
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Addition at float precision; mirrors compiler-rt's __addsf3.
+LIBC_INLINE float addsf3(float x, float y) {
+  return fputil::generic::add<float>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_ADDSF3_H
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 7f06d8084f98c..d1f02764ff5c3 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -81,3 +81,9 @@ TEST(LlvmLibcSharedBuiltinsTest, Divdf3) {
 
   EXPECT_FP_EQ(double(3.0), shared::divdf3(double(6.0), double(2.0)));
 }
+
+TEST(LlvmLibcSharedBuiltinsTest, Addsf3) {
+  namespace shared = LIBC_NAMESPACE::shared;
+
+  EXPECT_FP_EQ(float(3.0), shared::addsf3(float(1.0), float(2.0)));
+}

>From 50b7a13022e4a78ffc6a897b275d7e292b4541ac Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Wed, 24 Jun 2026 22:33:03 +0300
Subject: [PATCH 12/12] [libc] add shared subsf3 builtin

---
 libc/shared/builtins.h                     |  1 +
 libc/shared/builtins/subsf3.h              | 29 ++++++++++++++++++++
 libc/src/__support/builtins/CMakeLists.txt |  9 ++++++
 libc/src/__support/builtins/subsf3.h       | 32 ++++++++++++++++++++++
 libc/test/shared/shared_builtins_test.cpp  |  6 ++++
 5 files changed, 77 insertions(+)
 create mode 100644 libc/shared/builtins/subsf3.h
 create mode 100644 libc/src/__support/builtins/subsf3.h

diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index a6a8973beda25..a0cf05b5e64e6 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -25,6 +25,7 @@
 #include "builtins/muldf3.h"
 #include "builtins/multf3.h"
 #include "builtins/subdf3.h"
+#include "builtins/subsf3.h"
 #include "builtins/subtf3.h"
 
 #endif // LLVM_LIBC_SHARED_BUILTINS_H
diff --git a/libc/shared/builtins/subsf3.h b/libc/shared/builtins/subsf3.h
new file mode 100644
index 0000000000000..3f92aa1c2828c
--- /dev/null
+++ b/libc/shared/builtins/subsf3.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 __subsf3 implementation as shared::subsf3 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_SUBSF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_SUBSF3_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/subsf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::subsf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_SUBSF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index 69d714b9fa207..d68a36a613de7 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -82,3 +82,12 @@ add_header_library(
     libc.src.__support.FPUtil.generic.add_sub
     libc.src.__support.macros.config
 )
+
+add_header_library(
+  subsf3
+  HDRS
+    subsf3.h
+  DEPENDS
+    libc.src.__support.FPUtil.generic.add_sub
+    libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/subsf3.h b/libc/src/__support/builtins/subsf3.h
new file mode 100644
index 0000000000000..e45c8ce43a896
--- /dev/null
+++ b/libc/src/__support/builtins/subsf3.h
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 __subsf3 implementation as builtins::subsf3
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBSF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBSF3_H
+
+#include "src/__support/FPUtil/generic/add_sub.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Subtraction at float precision; mirrors compiler-rt's __subsf3.
+LIBC_INLINE float subsf3(float x, float y) {
+  return fputil::generic::sub<float>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_SUBSF3_H
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index d1f02764ff5c3..97b477508c957 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -87,3 +87,9 @@ TEST(LlvmLibcSharedBuiltinsTest, Addsf3) {
 
   EXPECT_FP_EQ(float(3.0), shared::addsf3(float(1.0), float(2.0)));
 }
+
+TEST(LlvmLibcSharedBuiltinsTest, Subsf3) {
+  namespace shared = LIBC_NAMESPACE::shared;
+
+  EXPECT_FP_EQ(float(2.0), shared::subsf3(float(5.0), float(3.0)));
+}



More information about the libc-commits mailing list