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

via libc-commits libc-commits at lists.llvm.org
Mon Jul 6 19:01:10 PDT 2026


Author: hulxv
Date: 2026-07-07T05:01:05+03:00
New Revision: 0ad19f403165d8fc1596fb2fef9c940e941c54df

URL: https://github.com/llvm/llvm-project/commit/0ad19f403165d8fc1596fb2fef9c940e941c54df
DIFF: https://github.com/llvm/llvm-project/commit/0ad19f403165d8fc1596fb2fef9c940e941c54df.diff

LOG: [libc] add shared subsf3 builtin (#205677)

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

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

Part of #197824

Added: 
    libc/shared/builtins/subsf3.h
    libc/src/__support/builtins/subsf3.h

Modified: 
    libc/shared/builtins.h
    libc/src/__support/builtins/CMakeLists.txt
    libc/test/shared/CMakeLists.txt
    libc/test/shared/shared_builtins_test.cpp

Removed: 
    


################################################################################
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) {


        


More information about the libc-commits mailing list