[libc-commits] [libc] [libc] Add definition for `atan2l` on 64-bit long double platforms (PR #104489)
via libc-commits
libc-commits at lists.llvm.org
Thu Aug 15 12:43:50 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Joseph Huber (jhuber6)
<details>
<summary>Changes</summary>
Summary:
This just adds `atan2l` for platforms that can implement it as an alias
to `atan2`.
---
Full diff: https://github.com/llvm/llvm-project/pull/104489.diff
7 Files Affected:
- (modified) libc/config/gpu/entrypoints.txt (+1)
- (modified) libc/newhdrgen/yaml/math.yaml (+14)
- (modified) libc/spec/stdc.td (+1)
- (modified) libc/src/math/CMakeLists.txt (+1)
- (added) libc/src/math/atan2l.h (+20)
- (modified) libc/src/math/generic/CMakeLists.txt (+11)
- (added) libc/src/math/generic/atan2l.cpp (+27)
``````````diff
diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt
index b2644d2ebf386c..9ead5aa92d5a92 100644
--- a/libc/config/gpu/entrypoints.txt
+++ b/libc/config/gpu/entrypoints.txt
@@ -248,6 +248,7 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.atan
libc.src.math.atan2
libc.src.math.atan2f
+ libc.src.math.atan2l
libc.src.math.atanf
libc.src.math.atanh
libc.src.math.atanhf
diff --git a/libc/newhdrgen/yaml/math.yaml b/libc/newhdrgen/yaml/math.yaml
index f8b105514271c7..04b6a073deace0 100644
--- a/libc/newhdrgen/yaml/math.yaml
+++ b/libc/newhdrgen/yaml/math.yaml
@@ -37,6 +37,13 @@ functions:
return_type: float
arguments:
- type: float
+ - name: atan2
+ standards:
+ - stdc
+ return_type: double
+ arguments:
+ - type: double
+ - type: double
- name: atan2f
standards:
- stdc
@@ -44,6 +51,13 @@ functions:
arguments:
- type: float
- type: float
+ - name: atan2l
+ standards:
+ - stdc
+ return_type: long double
+ arguments:
+ - type: long double
+ - type: long double
- name: atanf
standards:
- stdc
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 8497acbfd62f0d..118dcce829be23 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -715,6 +715,7 @@ def StdC : StandardSpec<"stdc"> {
FunctionSpec<"atan2", RetValSpec<DoubleType>, [ArgSpec<DoubleType>, ArgSpec<DoubleType>]>,
FunctionSpec<"atan2f", RetValSpec<FloatType>, [ArgSpec<FloatType>, ArgSpec<FloatType>]>,
+ FunctionSpec<"atan2l", RetValSpec<LongDoubleType>, [ArgSpec<LongDoubleType>, ArgSpec<LongDoubleType>]>,
FunctionSpec<"acoshf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
FunctionSpec<"asinhf", RetValSpec<FloatType>, [ArgSpec<FloatType>]>,
diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt
index 132511a536366c..3cba34fc249322 100644
--- a/libc/src/math/CMakeLists.txt
+++ b/libc/src/math/CMakeLists.txt
@@ -55,6 +55,7 @@ add_math_entrypoint_object(atanf)
add_math_entrypoint_object(atan2)
add_math_entrypoint_object(atan2f)
+add_math_entrypoint_object(atan2l)
add_math_entrypoint_object(atanh)
add_math_entrypoint_object(atanhf)
diff --git a/libc/src/math/atan2l.h b/libc/src/math/atan2l.h
new file mode 100644
index 00000000000000..134d570d72e1f5
--- /dev/null
+++ b/libc/src/math/atan2l.h
@@ -0,0 +1,20 @@
+//===-- Implementation header for atan2l ------------------------*- 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_ATAN2L_H
+#define LLVM_LIBC_SRC_MATH_ATAN2L_H
+
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+long double atan2l(long double x, long double y);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_MATH_ATAN2L_H
diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt
index 745bd65e1d75b5..251afe5d320a2d 100644
--- a/libc/src/math/generic/CMakeLists.txt
+++ b/libc/src/math/generic/CMakeLists.txt
@@ -4230,6 +4230,17 @@ add_entrypoint_object(
libc.src.__support.macros.optimization
)
+add_entrypoint_object(
+ atan2l
+ SRCS
+ atan2l.cpp
+ HDRS
+ ../atan2l.h
+ COMPILE_OPTIONS
+ -O3
+ DEPENDS
+ .atan2
+)
add_entrypoint_object(
scalbln
diff --git a/libc/src/math/generic/atan2l.cpp b/libc/src/math/generic/atan2l.cpp
new file mode 100644
index 00000000000000..f213db11c95c65
--- /dev/null
+++ b/libc/src/math/generic/atan2l.cpp
@@ -0,0 +1,27 @@
+//===-- Extended-precision atan2 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/atan2l.h"
+
+#include "src/__support/common.h"
+#include "src/__support/macros/properties/types.h"
+#include "src/math/atan2.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+// TODO: Implement this for extended precision.
+LLVM_LIBC_FUNCTION(long double, atan2l, (long double y, long double x)) {
+#if defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT64)
+ return static_cast<long double>(
+ atan2(static_cast<double>(y), static_cast<double>(x)));
+#else
+#error "Extended precision is not yet supported"
+#endif
+}
+
+} // namespace LIBC_NAMESPACE_DECL
``````````
</details>
https://github.com/llvm/llvm-project/pull/104489
More information about the libc-commits
mailing list