Skip to content

[libc] introduce shared compiler-rt builtins#200094

Merged
hulxv merged 3 commits into
llvm:mainfrom
hulxv:libc/feat/builtins/addtf3
Jun 26, 2026
Merged

[libc] introduce shared compiler-rt builtins#200094
hulxv merged 3 commits into
llvm:mainfrom
hulxv:libc/feat/builtins/addtf3

Conversation

@hulxv

@hulxv hulxv commented May 28, 2026

Copy link
Copy Markdown
Member

Introduce shared compiler-rt builtins to libc and addtf3 builtin

Split from #197950

Part of #197824

@hulxv
hulxv requested a review from a team as a code owner May 28, 2026 01:07
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-libc

Author: hulxv (hulxv)

Changes

Introduce shared compiler-rt builtins to libc and addtf3 builtin

Split from #197950

Part of #197824


Full diff: https://github.com/llvm/llvm-project/pull/200094.diff

8 Files Affected:

  • (added) libc/shared/builtins.h (+16)
  • (added) libc/shared/builtins/addtf3.h (+35)
  • (modified) libc/src/__support/CMakeLists.txt (+1)
  • (modified) libc/src/__support/FPUtil/dyadic_float.h (+3)
  • (added) libc/src/__support/builtins/CMakeLists.txt (+9)
  • (added) libc/src/__support/builtins/addtf3.h (+32)
  • (modified) libc/test/shared/CMakeLists.txt (+10)
  • (added) libc/test/shared/shared_builtins_test.cpp (+21)
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 ada489046ef9e..0246bcd8f01b6 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -470,6 +470,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 8ce041247716b..04e7c0c34859b 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 84a8d4bf79b3d..0a4d7e2e30723 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -801,6 +801,16 @@ add_fp_unittest(
     libc.src.__support.math.totalordermagl
 )
 
+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..1cc0025487680
--- /dev/null
+++ b/libc/test/shared/shared_builtins_test.cpp
@@ -0,0 +1,21 @@
+//===-- 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"
+
+#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

@hulxv
hulxv force-pushed the libc/feat/builtins/addtf3 branch from 067ecc3 to 640f094 Compare May 29, 2026 18:41
@github-actions

github-actions Bot commented May 29, 2026

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 124803 tests passed
  • 2944 tests skipped

✅ The build succeeded and all tests passed.

@hulxv
hulxv force-pushed the libc/feat/builtins/addtf3 branch 3 times, most recently from 5a17df0 to 92b1480 Compare May 29, 2026 22:56
@hulxv
hulxv force-pushed the libc/feat/builtins/addtf3 branch from 92b1480 to 9a0bb04 Compare May 30, 2026 15:42

@kaladron kaladron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm having trouble telling what I'm looking at. Could you please flesh out the commit message a bit? This says it's introducing compiler-rt builtins - but it doesn't link in compiler-rt?

libc/src/__support/builtins/addtf3.h returns something from fputil into a bulitins namespace, but this doesn't appear builtin?

I need more of a roadmap than I've got here, sorry!

Comment thread libc/shared/builtins/addtf3.h Outdated
Comment thread libc/test/shared/shared_builtins_test.cpp
Comment thread libc/include/llvm-libc-macros/float-macros.h
@hulxv

hulxv commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

I'm having trouble telling what I'm looking at. Could you please flesh out the commit message a bit? This says it's introducing compiler-rt builtins - but it doesn't link in compiler-rt?

libc/src/__support/builtins/addtf3.h returns something from fputil into a bulitins namespace, but this doesn't appear builtin?

I need more of a roadmap than I've got here, sorry!

It's split from the main pr about the integration with compiler-rt. Take a look here #197950. We decided to split the main Pr into 3 different PRs to make it cleaner

@kaladron kaladron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes left, thanks!

Comment thread libc/shared/builtins.h Outdated
Comment thread libc/include/llvm-libc-macros/float-macros.h
@hulxv
hulxv requested a review from kaladron June 23, 2026 19:48
@hulxv

hulxv commented Jun 23, 2026

Copy link
Copy Markdown
Member Author

Minor changes left, thanks!

done. thanks!

@kaladron kaladron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes and this commit!

@hulxv
hulxv merged commit c1be719 into llvm:main Jun 26, 2026
40 of 41 checks passed
hulxv added a commit that referenced this pull request Jun 26, 2026
Re-exposes LLVM-libc's `__subtf3` as `shared::subtf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- #200094


Part of #197824

---------

Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
hulxv added a commit that referenced this pull request Jun 26, 2026
Re-exposes LLVM-libc's `__multf3` as `shared::multf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- #200094
- #205669

Part of #197824

---------

Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
hulxv added a commit that referenced this pull request Jun 26, 2026
Re-exposes LLVM-libc's `__divtf3` as `shared::divtf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- #200094
- #205669
- #205670

Part of #197824
hulxv added a commit that referenced this pull request Jun 26, 2026
Re-exposes LLVM-libc's `__adddf3` as `shared::adddf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- #200094
- #205669
- #205670
- #205671

Part of #197824
hulxv added a commit that referenced this pull request Jun 28, 2026
Re-exposes LLVM-libc's `__subdf3` as `shared::subdf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- #200094
- #205669
- #205670
- #205671
- #205672

Part of #197824
LouisLu060211 pushed a commit to LouisLu060211/llvm-project that referenced this pull request Jun 30, 2026
Introduce shared compiler-rt builtins to libc and addtf3 builtin

Split from llvm#197950

Part of llvm#197824
LouisLu060211 pushed a commit to LouisLu060211/llvm-project that referenced this pull request Jun 30, 2026
Re-exposes LLVM-libc's `__subtf3` as `shared::subtf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- llvm#200094


Part of llvm#197824

---------

Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
LouisLu060211 pushed a commit to LouisLu060211/llvm-project that referenced this pull request Jun 30, 2026
Re-exposes LLVM-libc's `__multf3` as `shared::multf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- llvm#200094
- llvm#205669

Part of llvm#197824

---------

Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
LouisLu060211 pushed a commit to LouisLu060211/llvm-project that referenced this pull request Jun 30, 2026
Re-exposes LLVM-libc's `__divtf3` as `shared::divtf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- llvm#200094
- llvm#205669
- llvm#205670

Part of llvm#197824
LouisLu060211 pushed a commit to LouisLu060211/llvm-project that referenced this pull request Jun 30, 2026
Re-exposes LLVM-libc's `__adddf3` as `shared::adddf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- llvm#200094
- llvm#205669
- llvm#205670
- llvm#205671

Part of llvm#197824
LouisLu060211 pushed a commit to LouisLu060211/llvm-project that referenced this pull request Jun 30, 2026
Re-exposes LLVM-libc's `__subdf3` as `shared::subdf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- llvm#200094
- llvm#205669
- llvm#205670
- llvm#205671
- llvm#205672

Part of llvm#197824
hulxv added a commit that referenced this pull request Jul 1, 2026
Re-exposes LLVM-libc's `__muldf3` as `shared::muldf3` for reuse by
compiler-rt's builtins.

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

Part of #197824
maarcosrmz pushed a commit to maarcosrmz/llvm-project that referenced this pull request Jul 1, 2026
Introduce shared compiler-rt builtins to libc and addtf3 builtin

Split from llvm#197950

Part of llvm#197824
maarcosrmz pushed a commit to maarcosrmz/llvm-project that referenced this pull request Jul 1, 2026
Re-exposes LLVM-libc's `__subtf3` as `shared::subtf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- llvm#200094


Part of llvm#197824

---------

Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
maarcosrmz pushed a commit to maarcosrmz/llvm-project that referenced this pull request Jul 1, 2026
Re-exposes LLVM-libc's `__multf3` as `shared::multf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- llvm#200094
- llvm#205669

Part of llvm#197824

---------

Co-authored-by: Muhammad Bassiouni <60100307+bassiounix@users.noreply.github.com>
maarcosrmz pushed a commit to maarcosrmz/llvm-project that referenced this pull request Jul 1, 2026
Re-exposes LLVM-libc's `__divtf3` as `shared::divtf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- llvm#200094
- llvm#205669
- llvm#205670

Part of llvm#197824
maarcosrmz pushed a commit to maarcosrmz/llvm-project that referenced this pull request Jul 1, 2026
Re-exposes LLVM-libc's `__adddf3` as `shared::adddf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- llvm#200094
- llvm#205669
- llvm#205670
- llvm#205671

Part of llvm#197824
maarcosrmz pushed a commit to maarcosrmz/llvm-project that referenced this pull request Jul 1, 2026
Re-exposes LLVM-libc's `__subdf3` as `shared::subdf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- llvm#200094
- llvm#205669
- llvm#205670
- llvm#205671
- llvm#205672

Part of llvm#197824
maarcosrmz pushed a commit to maarcosrmz/llvm-project that referenced this pull request Jul 1, 2026
Re-exposes LLVM-libc's `__muldf3` as `shared::muldf3` for reuse by
compiler-rt's builtins.

Stacked change - merge these first:
- llvm#200094
- llvm#205669
- llvm#205670
- llvm#205671
- llvm#205672
- llvm#205673

Part of llvm#197824
hulxv added a commit that referenced this pull request Jul 1, 2026
Re-exposes LLVM-libc's `__divdf3` as `shared::divdf3` for reuse by
compiler-rt's builtins.

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

Part of #197824
hulxv added a commit that referenced this pull request Jul 1, 2026
Re-exposes LLVM-libc's `__addsf3` as `shared::addsf3` for reuse by
compiler-rt's builtins.

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

Part of #197824
hulxv added a commit that referenced this pull request Jul 7, 2026
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

Part of #197824
hulxv added a commit that referenced this pull request Jul 7, 2026
Re-exposes LLVM-libc's `__mulsf3` as `shared::mulsf3` for reuse by
compiler-rt's builtins.

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

Part of #197824
aobolensk pushed a commit to aobolensk/llvm-project that referenced this pull request Jul 8, 2026
Re-exposes LLVM-libc's `__mulsf3` as `shared::mulsf3` for reuse by
compiler-rt's builtins.

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

Part of llvm#197824
hulxv added a commit that referenced this pull request Jul 9, 2026
Re-exposes LLVM-libc's `__divsf3` as `shared::divsf3` for reuse by
compiler-rt's builtins.

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

Part of #197824
gandhi56 pushed a commit that referenced this pull request Jul 9, 2026
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

Part of #197824
gandhi56 pushed a commit that referenced this pull request Jul 9, 2026
Re-exposes LLVM-libc's `__mulsf3` as `shared::mulsf3` for reuse by
compiler-rt's builtins.

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

Part of #197824
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants