diff --git a/libc/shared/builtins.h b/libc/shared/builtins.h index 7415f7eec4473..ced054cb02582 100644 --- a/libc/shared/builtins.h +++ b/libc/shared/builtins.h @@ -21,6 +21,7 @@ #include "builtins/addsf3.h" #include "builtins/addtf3.h" #include "builtins/divdf3.h" +#include "builtins/divsf3.h" #include "builtins/divtf3.h" #include "builtins/muldf3.h" #include "builtins/mulsf3.h" diff --git a/libc/shared/builtins/divsf3.h b/libc/shared/builtins/divsf3.h new file mode 100644 index 0000000000000..edb6aec227760 --- /dev/null +++ b/libc/shared/builtins/divsf3.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 __divsf3 implementation as shared::divsf3 so +/// that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SHARED_BUILTINS_DIVSF3_H +#define LLVM_LIBC_SHARED_BUILTINS_DIVSF3_H + +#include "shared/libc_common.h" +#include "src/__support/builtins/divsf3.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using builtins::divsf3; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SHARED_BUILTINS_DIVSF3_H diff --git a/libc/src/__support/builtins/CMakeLists.txt b/libc/src/__support/builtins/CMakeLists.txt index a97265e5028d8..f5b5ffe3e07b4 100644 --- a/libc/src/__support/builtins/CMakeLists.txt +++ b/libc/src/__support/builtins/CMakeLists.txt @@ -100,3 +100,12 @@ add_header_library( libc.src.__support.FPUtil.generic.mul libc.src.__support.macros.config ) + +add_header_library( + divsf3 + HDRS + divsf3.h + DEPENDS + libc.src.__support.FPUtil.generic.div + libc.src.__support.macros.config +) diff --git a/libc/src/__support/builtins/divsf3.h b/libc/src/__support/builtins/divsf3.h new file mode 100644 index 0000000000000..681b705f9e666 --- /dev/null +++ b/libc/src/__support/builtins/divsf3.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 __divsf3 implementation as builtins::divsf3 +/// so that it can be reused by compiler-rt's builtins. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVSF3_H +#define LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVSF3_H + +#include "src/__support/FPUtil/generic/div.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace builtins { + +// Division at float precision; mirrors compiler-rt's __divsf3. +LIBC_INLINE float divsf3(float x, float y) { + return fputil::generic::div(x, y); +} + +} // namespace builtins +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_BUILTINS_DIVSF3_H diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt index 0489bd2efaf79..6efe8365b1557 100644 --- a/libc/test/shared/CMakeLists.txt +++ b/libc/test/shared/CMakeLists.txt @@ -831,6 +831,7 @@ add_fp_unittest( libc.src.__support.builtins.addsf3 libc.src.__support.builtins.addtf3 libc.src.__support.builtins.divdf3 + libc.src.__support.builtins.divsf3 libc.src.__support.builtins.divtf3 libc.src.__support.builtins.muldf3 libc.src.__support.builtins.mulsf3 diff --git a/libc/test/shared/shared_builtins_test.cpp b/libc/test/shared/shared_builtins_test.cpp index 3e455f27b42c8..dac84345eade1 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(3.0f, LIBC_NAMESPACE::shared::divsf3(6.0f, 2.0f)); EXPECT_FP_EQ(6.0f, LIBC_NAMESPACE::shared::mulsf3(2.0f, 3.0f)); EXPECT_FP_EQ(2.0f, LIBC_NAMESPACE::shared::subsf3(5.0f, 3.0f)); }