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

via libc-commits libc-commits at lists.llvm.org
Fri Jun 26 13:02:33 PDT 2026


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

>From f98eb8e9bfe33e99898c62fe5969ef0a662d9a76 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:20 +0300
Subject: [PATCH 1/8] [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/CMakeLists.txt            |  1 +
 libc/test/shared/shared_builtins_test.cpp  |  2 ++
 6 files changed, 87 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/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 98f787c7453f6..614b2a87809e5 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -827,6 +827,7 @@ add_fp_unittest(
     shared_builtins_test.cpp
   DEPENDS
     libc.src.__support.builtins.addtf3
+    libc.src.__support.builtins.multf3
     libc.src.__support.builtins.subtf3
 )
 
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index bf84d2c0866a4..52130e75c4c31 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -23,6 +23,8 @@ TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {
 TEST(LlvmLibcSharedBuiltinsTest, AllFloat128) {
   EXPECT_FP_EQ(float128(3.0),
                LIBC_NAMESPACE::shared::addtf3(float128(1.0), float128(2.0)));
+  EXPECT_FP_EQ(float128(6.0),
+               LIBC_NAMESPACE::shared::multf3(float128(2.0), float128(3.0)));
   EXPECT_FP_EQ(float128(2.0),
                LIBC_NAMESPACE::shared::subtf3(float128(5.0), float128(3.0)));
 }

>From 06e51039c585efb8fcba8d69de25680d8dbfd669 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:21 +0300
Subject: [PATCH 2/8] [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/CMakeLists.txt            |  1 +
 libc/test/shared/shared_builtins_test.cpp  |  2 ++
 6 files changed, 87 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/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 614b2a87809e5..8449d18dd6e10 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -827,6 +827,7 @@ add_fp_unittest(
     shared_builtins_test.cpp
   DEPENDS
     libc.src.__support.builtins.addtf3
+    libc.src.__support.builtins.divtf3
     libc.src.__support.builtins.multf3
     libc.src.__support.builtins.subtf3
 )
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 52130e75c4c31..b8350829f4f71 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -23,6 +23,8 @@ TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {
 TEST(LlvmLibcSharedBuiltinsTest, AllFloat128) {
   EXPECT_FP_EQ(float128(3.0),
                LIBC_NAMESPACE::shared::addtf3(float128(1.0), float128(2.0)));
+  EXPECT_FP_EQ(float128(3.0),
+               LIBC_NAMESPACE::shared::divtf3(float128(6.0), float128(2.0)));
   EXPECT_FP_EQ(float128(6.0),
                LIBC_NAMESPACE::shared::multf3(float128(2.0), float128(3.0)));
   EXPECT_FP_EQ(float128(2.0),

>From 252f1c29f6fc6e647895b3a083e0c66dd6a44c54 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:22 +0300
Subject: [PATCH 3/8] [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/CMakeLists.txt            |  1 +
 libc/test/shared/shared_builtins_test.cpp  |  2 +-
 6 files changed, 73 insertions(+), 1 deletion(-)
 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/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 8449d18dd6e10..3b6bb6c2cf507 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -826,6 +826,7 @@ add_fp_unittest(
   SRCS
     shared_builtins_test.cpp
   DEPENDS
+    libc.src.__support.builtins.adddf3
     libc.src.__support.builtins.addtf3
     libc.src.__support.builtins.divtf3
     libc.src.__support.builtins.multf3
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index b8350829f4f71..4960c7abe6b04 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -15,7 +15,7 @@ TEST(LlvmLibcSharedBuiltinsTest, AllFloat) {
 }
 
 TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {
-  // TODO: assertions for shared::*df3 builtins.
+  EXPECT_FP_EQ(3.0, LIBC_NAMESPACE::shared::adddf3(1.0, 2.0));
 }
 
 #ifdef LIBC_TYPES_HAS_FLOAT128

>From 5f43ed0d79d23909775664bb5a92d928e33c5adf Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:23 +0300
Subject: [PATCH 4/8] [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/CMakeLists.txt            |  1 +
 libc/test/shared/shared_builtins_test.cpp  |  1 +
 6 files changed, 73 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/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 3b6bb6c2cf507..f8904c08a6966 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -830,6 +830,7 @@ add_fp_unittest(
     libc.src.__support.builtins.addtf3
     libc.src.__support.builtins.divtf3
     libc.src.__support.builtins.multf3
+    libc.src.__support.builtins.subdf3
     libc.src.__support.builtins.subtf3
 )
 
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 4960c7abe6b04..1de81ce129c20 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -16,6 +16,7 @@ TEST(LlvmLibcSharedBuiltinsTest, AllFloat) {
 
 TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {
   EXPECT_FP_EQ(3.0, LIBC_NAMESPACE::shared::adddf3(1.0, 2.0));
+  EXPECT_FP_EQ(2.0, LIBC_NAMESPACE::shared::subdf3(5.0, 3.0));
 }
 
 #ifdef LIBC_TYPES_HAS_FLOAT128

>From 7680e8084208e3ace377fbfc1466ef97910b8a67 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:24 +0300
Subject: [PATCH 5/8] [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/CMakeLists.txt            |  1 +
 libc/test/shared/shared_builtins_test.cpp  |  1 +
 6 files changed, 73 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/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index f8904c08a6966..e02fb11017611 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -829,6 +829,7 @@ add_fp_unittest(
     libc.src.__support.builtins.adddf3
     libc.src.__support.builtins.addtf3
     libc.src.__support.builtins.divtf3
+    libc.src.__support.builtins.muldf3
     libc.src.__support.builtins.multf3
     libc.src.__support.builtins.subdf3
     libc.src.__support.builtins.subtf3
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 1de81ce129c20..be89aea684e8e 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -16,6 +16,7 @@ TEST(LlvmLibcSharedBuiltinsTest, AllFloat) {
 
 TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {
   EXPECT_FP_EQ(3.0, LIBC_NAMESPACE::shared::adddf3(1.0, 2.0));
+  EXPECT_FP_EQ(6.0, LIBC_NAMESPACE::shared::muldf3(2.0, 3.0));
   EXPECT_FP_EQ(2.0, LIBC_NAMESPACE::shared::subdf3(5.0, 3.0));
 }
 

>From b10324355b7a8dcdb1f47bec0acd1341345c157a Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:26 +0300
Subject: [PATCH 6/8] [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/CMakeLists.txt            |  1 +
 libc/test/shared/shared_builtins_test.cpp  |  1 +
 6 files changed, 73 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/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index e02fb11017611..78cc73071055f 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -828,6 +828,7 @@ add_fp_unittest(
   DEPENDS
     libc.src.__support.builtins.adddf3
     libc.src.__support.builtins.addtf3
+    libc.src.__support.builtins.divdf3
     libc.src.__support.builtins.divtf3
     libc.src.__support.builtins.muldf3
     libc.src.__support.builtins.multf3
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index be89aea684e8e..e7e06452da8bc 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -16,6 +16,7 @@ TEST(LlvmLibcSharedBuiltinsTest, AllFloat) {
 
 TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {
   EXPECT_FP_EQ(3.0, LIBC_NAMESPACE::shared::adddf3(1.0, 2.0));
+  EXPECT_FP_EQ(3.0, LIBC_NAMESPACE::shared::divdf3(6.0, 2.0));
   EXPECT_FP_EQ(6.0, LIBC_NAMESPACE::shared::muldf3(2.0, 3.0));
   EXPECT_FP_EQ(2.0, LIBC_NAMESPACE::shared::subdf3(5.0, 3.0));
 }

>From 564397ac22d79894a26e3ad6b2b27324034dd0f9 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:27 +0300
Subject: [PATCH 7/8] [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/CMakeLists.txt            |  1 +
 libc/test/shared/shared_builtins_test.cpp  |  2 +-
 6 files changed, 73 insertions(+), 1 deletion(-)
 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/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 78cc73071055f..db68233d95c48 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -827,6 +827,7 @@ add_fp_unittest(
     shared_builtins_test.cpp
   DEPENDS
     libc.src.__support.builtins.adddf3
+    libc.src.__support.builtins.addsf3
     libc.src.__support.builtins.addtf3
     libc.src.__support.builtins.divdf3
     libc.src.__support.builtins.divtf3
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index e7e06452da8bc..20e79498b4cfb 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -11,7 +11,7 @@
 #include "test/UnitTest/Test.h"
 
 TEST(LlvmLibcSharedBuiltinsTest, AllFloat) {
-  // TODO: assertions for shared::*sf3 builtins.
+  EXPECT_FP_EQ(3.0f, LIBC_NAMESPACE::shared::addsf3(1.0f, 2.0f));
 }
 
 TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {

>From c9602937038380584b1e8ffb1519885eb26c942a Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:28 +0300
Subject: [PATCH 8/8] [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/CMakeLists.txt            |  1 +
 libc/test/shared/shared_builtins_test.cpp  |  1 +
 6 files changed, 73 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/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index db68233d95c48..008c0d7005905 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -834,6 +834,7 @@ add_fp_unittest(
     libc.src.__support.builtins.muldf3
     libc.src.__support.builtins.multf3
     libc.src.__support.builtins.subdf3
+    libc.src.__support.builtins.subsf3
     libc.src.__support.builtins.subtf3
 )
 
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 20e79498b4cfb..dc72824626416 100644
--- a/libc/test/shared/shared_builtins_test.cpp
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -12,6 +12,7 @@
 
 TEST(LlvmLibcSharedBuiltinsTest, AllFloat) {
   EXPECT_FP_EQ(3.0f, LIBC_NAMESPACE::shared::addsf3(1.0f, 2.0f));
+  EXPECT_FP_EQ(2.0f, LIBC_NAMESPACE::shared::subsf3(5.0f, 3.0f));
 }
 
 TEST(LlvmLibcSharedBuiltinsTest, AllDouble) {



More information about the libc-commits mailing list