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(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)); }