[libc][math] Add place-holder implementation for asin to unblock demo examples.
authorTue Ly <lntue@google.com>
Mon, 31 Oct 2022 19:42:00 +0000 (15:42 -0400)
committerTue Ly <lntue@google.com>
Mon, 31 Oct 2022 21:22:12 +0000 (17:22 -0400)
Add a place-holder implementation for asin to unblock libc demo
examples.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D137105

libc/config/linux/aarch64/entrypoints.txt
libc/config/linux/x86_64/entrypoints.txt
libc/config/windows/entrypoints.txt
libc/spec/stdc.td
libc/src/math/CMakeLists.txt
libc/src/math/asin.h [new file with mode: 0644]
libc/src/math/generic/CMakeLists.txt
libc/src/math/generic/asin.cpp [new file with mode: 0644]
libc/test/src/math/CMakeLists.txt
libc/test/src/math/asin_test.cpp [new file with mode: 0644]

index 5b2e609be3e74499946f2c6c87744e6977f9dbfe..440bc2be96fa89f5378932d23c0f531c076ed16a 100644 (file)
@@ -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    
index 56e38f0f13fdd520a4d8764d9ceacecb04248df9..cef4e26b167782cc677df8a6dce87c2281dde58a 100644 (file)
@@ -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
index 3e6dceb4622e9b9db0ed22b4d89efb0a524a38c6..d50927ec3c4a1d8e6973630cd1968992f0507b15 100644 (file)
@@ -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
index 337713e48c152ad046df7cbc56348e869ab1a133..22e233c5faa9faf08117b20f995195f2f332258a 100644 (file)
@@ -483,6 +483,7 @@ def StdC : StandardSpec<"stdc"> {
 
           FunctionSpec<"acosf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
           FunctionSpec<"asinf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
+          FunctionSpec<"asin", RetValSpec<DoubleType>, [ArgSpec<DoubleType>]>,
           FunctionSpec<"atanf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
 
           FunctionSpec<"atanhf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
index e15e4c2a48e92345c1826dacc302ef61b376ba2e..0c425c7658fd8c7cf529634f77395fcab3e4da5a 100644 (file)
@@ -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 (file)
index 0000000..d8f3f19
--- /dev/null
@@ -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
index 3c6a3f074f7ee43781590e16a0d6b4b0afce6164..50617598de1729790923482eddb807c5356b8de0 100644 (file)
@@ -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 (file)
index 0000000..a53ae0a
--- /dev/null
@@ -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<double>(asinf(static_cast<float>(x)));
+}
+
+} // namespace __llvm_libc
index 5162b2fe68c65821467e82cfa3db7d391f5737fd..c285c35397cfa57af882af6427d70d4deba333ff 100644 (file)
@@ -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 (file)
index 0000000..ade6da0
--- /dev/null
@@ -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 <math.h>
+
+#include <errno.h>
+#include <stdint.h>
+
+using FPBits = __llvm_libc::fputil::FPBits<double>;
+
+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);
+}