[libc-commits] [libc] [libc] add shared divtf3 builtin (PR #205671)
via libc-commits
libc-commits at lists.llvm.org
Fri Jun 26 13:02:08 PDT 2026
https://github.com/hulxv updated https://github.com/llvm/llvm-project/pull/205671
>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/2] [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/2] [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),
More information about the libc-commits
mailing list