[libc-commits] [libc] 97b4cc8 - [libc][math] Add place-holder implementation for asin to unblock demo examples.

Tue Ly via libc-commits libc-commits at lists.llvm.org
Mon Oct 31 14:22:31 PDT 2022


Author: Tue Ly
Date: 2022-10-31T17:22:12-04:00
New Revision: 97b4cc83e16abec8daa67f5dc82f71791c523f43

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

LOG: [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

Added: 
    libc/src/math/asin.h
    libc/src/math/generic/asin.cpp
    libc/test/src/math/asin_test.cpp

Modified: 
    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/generic/CMakeLists.txt
    libc/test/src/math/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt
index 5b2e609be3e74..440bc2be96fa8 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 56e38f0f13fdd..cef4e26b16778 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 3e6dceb4622e9..d50927ec3c4a1 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 337713e48c152..22e233c5faa9f 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -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>]>,

diff  --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index e15e4c2a48e92..0c425c7658fd8 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 0000000000000..d8f3f191a3578
--- /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 3c6a3f074f7ee..50617598de172 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 0000000000000..a53ae0a210376
--- /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<double>(asinf(static_cast<float>(x)));
+}
+
+} // namespace __llvm_libc

diff  --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 5162b2fe68c65..c285c35397cfa 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 0000000000000..ade6da014461c
--- /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 <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);
+}


        


More information about the libc-commits mailing list