From: Tue Ly Date: Mon, 31 Oct 2022 19:42:00 +0000 (-0400) Subject: [libc][math] Add place-holder implementation for asin to unblock demo examples. X-Git-Tag: upstream/17.0.6~28926 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=97b4cc83e16abec8daa67f5dc82f71791c523f43;p=platform%2Fupstream%2Fllvm.git [libc][math] Add place-holder implementation for asin to unblock demo examples. Add a place-holder implementation for asin to unblock libc demo examples. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D137105 --- diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt index 5b2e609be3e7..440bc2be96fa 100644 --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -206,6 +206,7 @@ set(TARGET_LIBM_ENTRYPOINTS # math.h entrypoints libc.src.math.acosf + libc.src.math.asin libc.src.math.asinf libc.src.math.atanf libc.src.math.atanhf diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt index 56e38f0f13fd..cef4e26b1677 100644 --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -207,6 +207,7 @@ set(TARGET_LIBM_ENTRYPOINTS # math.h entrypoints libc.src.math.acosf + libc.src.math.asin libc.src.math.asinf libc.src.math.atanf libc.src.math.atanhf diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt index 3e6dceb4622e..d50927ec3c4a 100644 --- a/libc/config/windows/entrypoints.txt +++ b/libc/config/windows/entrypoints.txt @@ -107,6 +107,7 @@ set(TARGET_LIBM_ENTRYPOINTS # math.h entrypoints libc.src.math.acosf + libc.src.math.asin libc.src.math.asinf libc.src.math.atanf libc.src.math.atanhf diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td index 337713e48c15..22e233c5faa9 100644 --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -483,6 +483,7 @@ def StdC : StandardSpec<"stdc"> { FunctionSpec<"acosf", RetValSpec, [ArgSpec]>, FunctionSpec<"asinf", RetValSpec, [ArgSpec]>, + FunctionSpec<"asin", RetValSpec, [ArgSpec]>, FunctionSpec<"atanf", RetValSpec, [ArgSpec]>, FunctionSpec<"atanhf", RetValSpec, [ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index e15e4c2a48e9..0c425c7658fd 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -65,7 +65,10 @@ add_entrypoint_object( ) add_math_entrypoint_object(acosf) + +add_math_entrypoint_object(asin) add_math_entrypoint_object(asinf) + add_math_entrypoint_object(atanf) add_math_entrypoint_object(atanhf) diff --git a/libc/src/math/asin.h b/libc/src/math/asin.h new file mode 100644 index 000000000000..d8f3f191a357 --- /dev/null +++ b/libc/src/math/asin.h @@ -0,0 +1,18 @@ +//===-- Implementation header for asin --------------------------*- 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_MATH_ASIN_H +#define LLVM_LIBC_SRC_MATH_ASIN_H + +namespace __llvm_libc { + +double asin(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_ASIN_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 3c6a3f074f7e..50617598de17 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -1325,6 +1325,18 @@ add_entrypoint_object( -O3 ) +add_entrypoint_object( + asin + SRCS + asin.cpp + HDRS + ../asin.h + DEPENDS + .asinf + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( acosf SRCS diff --git a/libc/src/math/generic/asin.cpp b/libc/src/math/generic/asin.cpp new file mode 100644 index 000000000000..a53ae0a21037 --- /dev/null +++ b/libc/src/math/generic/asin.cpp @@ -0,0 +1,22 @@ +//===-- Double-precision asin function ------------------------------------===// +// +// 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 "src/math/asin.h" +#include "src/math/asinf.h" + +#include "src/__support/common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, asin, (double x)) { + // Place-holder implementation for double precision asin function. + // TODO: Implement correctly rounded asin function for double precision. + return static_cast(asinf(static_cast(x))); +} + +} // namespace __llvm_libc diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index 5162b2fe68c6..c285c35397cf 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -1466,6 +1466,19 @@ add_fp_unittest( libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + asin_test + NEED_MPFR + SUITE + libc_math_unittests + SRCS + asin_test.cpp + DEPENDS + libc.include.errno + libc.src.errno.errno + libc.src.math.asin +) + add_fp_unittest( acosf_test NEED_MPFR diff --git a/libc/test/src/math/asin_test.cpp b/libc/test/src/math/asin_test.cpp new file mode 100644 index 000000000000..ade6da014461 --- /dev/null +++ b/libc/test/src/math/asin_test.cpp @@ -0,0 +1,41 @@ +//===-- Unittests for asin ------------------------------------------------===// +// +// 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 "src/math/asin.h" +#include "utils/MPFRWrapper/MPFRUtils.h" +#include "utils/UnitTest/FPMatcher.h" +#include "utils/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +namespace mpfr = __llvm_libc::testing::mpfr; + +DECLARE_SPECIAL_CONSTANTS(double) + +TEST(LlvmLibcAsinTest, SpecialNumbers) { + errno = 0; + + EXPECT_FP_EQ(aNaN, __llvm_libc::asin(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(0.0, __llvm_libc::asin(0.0)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(-0.0, __llvm_libc::asin(-0.0)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(aNaN, __llvm_libc::asin(inf)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ(aNaN, __llvm_libc::asin(neg_inf)); + EXPECT_MATH_ERRNO(EDOM); +}