[libc-commits] [libc] [libc] add shared divsf3 builtin (PR #205679)
via libc-commits
libc-commits at lists.llvm.org
Sat Jun 27 17:21:39 PDT 2026
https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/205679
>From f33671a4a3882c088d978fd27f393d11c073beca Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:23 +0300
Subject: [PATCH 1/7] [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 120524bed5ead..a60b5bc537cc3 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -831,6 +831,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 ee486a5b8557a55939e9885ba9a22d6b4022d28f Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:24 +0300
Subject: [PATCH 2/7] [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 a60b5bc537cc3..3d4255f8539c7 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -830,6 +830,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 91de7820effe63e04442a516575261ad86db0c92 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:26 +0300
Subject: [PATCH 3/7] [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 3d4255f8539c7..7986d5f00ee5b 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -829,6 +829,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 332c6905ce117de57a66e2f8d3b320c7545609e5 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:27 +0300
Subject: [PATCH 4/7] [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 7986d5f00ee5b..aeb573474d6ef 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -828,6 +828,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 dc6a7e204702c4f41d0e7457bc67df49946d903a Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:28 +0300
Subject: [PATCH 5/7] [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 aeb573474d6ef..5156e7e5b32d0 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -835,6 +835,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) {
>From 5c9384dd980a43015691e1ecb58cb18c11e722d9 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:29 +0300
Subject: [PATCH 6/7] [libc] add shared mulsf3 builtin
---
libc/shared/builtins.h | 1 +
libc/shared/builtins/mulsf3.h | 29 ++++++++++++++++++++
libc/src/__support/builtins/CMakeLists.txt | 9 ++++++
libc/src/__support/builtins/mulsf3.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/mulsf3.h
create mode 100644 libc/src/__support/builtins/mulsf3.h
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index a0cf05b5e64e6..7415f7eec4473 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -23,6 +23,7 @@
#include "builtins/divdf3.h"
#include "builtins/divtf3.h"
#include "builtins/muldf3.h"
+#include "builtins/mulsf3.h"
#include "builtins/multf3.h"
#include "builtins/subdf3.h"
#include "builtins/subsf3.h"
diff --git a/libc/shared/builtins/mulsf3.h b/libc/shared/builtins/mulsf3.h
new file mode 100644
index 0000000000000..b0b24b1b2e620
--- /dev/null
+++ b/libc/shared/builtins/mulsf3.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 __mulsf3 implementation as shared::mulsf3 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_MULSF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_MULSF3_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/mulsf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::mulsf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_MULSF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index d68a36a613de7..a97265e5028d8 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -91,3 +91,12 @@ add_header_library(
libc.src.__support.FPUtil.generic.add_sub
libc.src.__support.macros.config
)
+
+add_header_library(
+ mulsf3
+ HDRS
+ mulsf3.h
+ DEPENDS
+ libc.src.__support.FPUtil.generic.mul
+ libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/mulsf3.h b/libc/src/__support/builtins/mulsf3.h
new file mode 100644
index 0000000000000..d1fef264d945a
--- /dev/null
+++ b/libc/src/__support/builtins/mulsf3.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 __mulsf3 implementation as builtins::mulsf3
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_MULSF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_MULSF3_H
+
+#include "src/__support/FPUtil/generic/mul.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Multiplication at float precision; mirrors compiler-rt's __mulsf3.
+LIBC_INLINE float mulsf3(float x, float y) {
+ return fputil::generic::mul<float>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_MULSF3_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 5156e7e5b32d0..0489bd2efaf79 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -833,6 +833,7 @@ add_fp_unittest(
libc.src.__support.builtins.divdf3
libc.src.__support.builtins.divtf3
libc.src.__support.builtins.muldf3
+ libc.src.__support.builtins.mulsf3
libc.src.__support.builtins.multf3
libc.src.__support.builtins.subdf3
libc.src.__support.builtins.subsf3
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index dc72824626416..3e455f27b42c8 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(6.0f, LIBC_NAMESPACE::shared::mulsf3(2.0f, 3.0f));
EXPECT_FP_EQ(2.0f, LIBC_NAMESPACE::shared::subsf3(5.0f, 3.0f));
}
>From a3d41b684f7b5513789d9f7f013eef8aff83eb62 Mon Sep 17 00:00:00 2001
From: hulxv <hulxxv at gmail.com>
Date: Thu, 25 Jun 2026 19:08:30 +0300
Subject: [PATCH 7/7] [libc] add shared divsf3 builtin
---
libc/shared/builtins.h | 1 +
libc/shared/builtins/divsf3.h | 29 ++++++++++++++++++++
libc/src/__support/builtins/CMakeLists.txt | 9 ++++++
libc/src/__support/builtins/divsf3.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/divsf3.h
create mode 100644 libc/src/__support/builtins/divsf3.h
diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h
index 7415f7eec4473..ced054cb02582 100644
--- a/libc/shared/builtins.h
+++ b/libc/shared/builtins.h
@@ -21,6 +21,7 @@
#include "builtins/addsf3.h"
#include "builtins/addtf3.h"
#include "builtins/divdf3.h"
+#include "builtins/divsf3.h"
#include "builtins/divtf3.h"
#include "builtins/muldf3.h"
#include "builtins/mulsf3.h"
diff --git a/libc/shared/builtins/divsf3.h b/libc/shared/builtins/divsf3.h
new file mode 100644
index 0000000000000..edb6aec227760
--- /dev/null
+++ b/libc/shared/builtins/divsf3.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 __divsf3 implementation as shared::divsf3 so
+/// that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SHARED_BUILTINS_DIVSF3_H
+#define LLVM_LIBC_SHARED_BUILTINS_DIVSF3_H
+
+#include "shared/libc_common.h"
+#include "src/__support/builtins/divsf3.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace shared {
+
+using builtins::divsf3;
+
+} // namespace shared
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SHARED_BUILTINS_DIVSF3_H
diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt
index a97265e5028d8..f5b5ffe3e07b4 100644
--- a/libc/src/__support/builtins/CMakeLists.txt
+++ b/libc/src/__support/builtins/CMakeLists.txt
@@ -100,3 +100,12 @@ add_header_library(
libc.src.__support.FPUtil.generic.mul
libc.src.__support.macros.config
)
+
+add_header_library(
+ divsf3
+ HDRS
+ divsf3.h
+ DEPENDS
+ libc.src.__support.FPUtil.generic.div
+ libc.src.__support.macros.config
+)
diff --git a/libc/src/__support/builtins/divsf3.h b/libc/src/__support/builtins/divsf3.h
new file mode 100644
index 0000000000000..681b705f9e666
--- /dev/null
+++ b/libc/src/__support/builtins/divsf3.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 __divsf3 implementation as builtins::divsf3
+/// so that it can be reused by compiler-rt's builtins.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVSF3_H
+#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVSF3_H
+
+#include "src/__support/FPUtil/generic/div.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace builtins {
+
+// Division at float precision; mirrors compiler-rt's __divsf3.
+LIBC_INLINE float divsf3(float x, float y) {
+ return fputil::generic::div<float>(x, y);
+}
+
+} // namespace builtins
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVSF3_H
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index 0489bd2efaf79..6efe8365b1557 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -831,6 +831,7 @@ add_fp_unittest(
libc.src.__support.builtins.addsf3
libc.src.__support.builtins.addtf3
libc.src.__support.builtins.divdf3
+ libc.src.__support.builtins.divsf3
libc.src.__support.builtins.divtf3
libc.src.__support.builtins.muldf3
libc.src.__support.builtins.mulsf3
diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp
index 3e455f27b42c8..dac84345eade1 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(3.0f, LIBC_NAMESPACE::shared::divsf3(6.0f, 2.0f));
EXPECT_FP_EQ(6.0f, LIBC_NAMESPACE::shared::mulsf3(2.0f, 3.0f));
EXPECT_FP_EQ(2.0f, LIBC_NAMESPACE::shared::subsf3(5.0f, 3.0f));
}
More information about the libc-commits
mailing list