[libc-commits] [libc] f9f4331 - [libc] add shared muldf3 builtin (#205674)

via libc-commits libc-commits at lists.llvm.org
Tue Jun 30 17:18:45 PDT 2026


Author: hulxv
Date: 2026-07-01T00:18:40Z
New Revision: f9f4331c2883fc441c5f146ef674e693acf2fc9b

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

LOG: [libc] add shared muldf3 builtin (#205674)

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

Added: 
    libc/shared/builtins/muldf3.h
    libc/src/__support/builtins/muldf3.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 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));
 }
 


        


More information about the libc-commits mailing list