https://github.com/AntonRydahl updated https://github.com/llvm/llvm-project/pull/66034
>From 7a357059d3ca78afcb02e33a6afce225029a3836 Mon Sep 17 00:00:00 2001 From: antonrydahl <rydahl2...@gmail.com> Date: Mon, 11 Sep 2023 17:06:41 -0700 Subject: [PATCH 1/3] [libc][libm][GPU] Add missing vendor entrypoints to the GPU version of `libm` There are a number of entry-points in `libm` for which no target-agnostic implementations exist and the built-ins do not lower correctly on either AMDGPU or NVPTX targets. This patch adds the vendor entry-points as a temporary solution. --- libc/config/gpu/entrypoints.txt | 37 ++++- libc/src/math/CMakeLists.txt | 15 ++ libc/src/math/acos.h | 18 +++ libc/src/math/acosh.h | 18 +++ libc/src/math/asin.h | 18 +++ libc/src/math/asinh.h | 18 +++ libc/src/math/atan.h | 18 +++ libc/src/math/atan2.h | 18 +++ libc/src/math/atan2f.h | 18 +++ libc/src/math/atanh.h | 18 +++ libc/src/math/erf.h | 18 +++ libc/src/math/expm1.h | 18 +++ libc/src/math/gpu/vendor/CMakeLists.txt | 143 ++++++++++++++++++ libc/src/math/gpu/vendor/acos.cpp | 18 +++ libc/src/math/gpu/vendor/acosh.cpp | 18 +++ libc/src/math/gpu/vendor/amdgpu/amdgpu.h | 25 +++ .../src/math/gpu/vendor/amdgpu/declarations.h | 34 ++++- libc/src/math/gpu/vendor/asin.cpp | 18 +++ libc/src/math/gpu/vendor/asinh.cpp | 18 +++ libc/src/math/gpu/vendor/atan.cpp | 18 +++ libc/src/math/gpu/vendor/atan2.cpp | 20 +++ libc/src/math/gpu/vendor/atan2f.cpp | 21 +++ libc/src/math/gpu/vendor/atanh.cpp | 18 +++ libc/src/math/gpu/vendor/erf.cpp | 18 +++ libc/src/math/gpu/vendor/erff.cpp | 18 +++ libc/src/math/gpu/vendor/exp.cpp | 18 +++ libc/src/math/gpu/vendor/exp10.cpp | 18 +++ libc/src/math/gpu/vendor/exp2.cpp | 18 +++ libc/src/math/gpu/vendor/expm1.cpp | 18 +++ libc/src/math/gpu/vendor/log.cpp | 18 +++ libc/src/math/gpu/vendor/log10.cpp | 18 +++ libc/src/math/gpu/vendor/log10f.cpp | 19 +++ libc/src/math/gpu/vendor/log1p.cpp | 18 +++ libc/src/math/gpu/vendor/log1pf.cpp | 18 +++ libc/src/math/gpu/vendor/log2.cpp | 18 +++ libc/src/math/gpu/vendor/log2f.cpp | 18 +++ libc/src/math/gpu/vendor/logb.cpp | 18 +++ libc/src/math/gpu/vendor/logbf.cpp | 19 +++ libc/src/math/gpu/vendor/logf.cpp | 18 +++ libc/src/math/gpu/vendor/lrint.cpp | 18 +++ libc/src/math/gpu/vendor/lrintf.cpp | 18 +++ libc/src/math/gpu/vendor/lround.cpp | 18 +++ libc/src/math/gpu/vendor/lroundf.cpp | 20 +++ libc/src/math/gpu/vendor/nvptx/declarations.h | 25 +++ libc/src/math/gpu/vendor/nvptx/nvptx.h | 25 +++ libc/src/math/gpu/vendor/tgamma.cpp | 18 +++ libc/src/math/gpu/vendor/tgammaf.cpp | 18 +++ libc/src/math/sincos.h | 18 +++ libc/src/math/tgamma.h | 18 +++ libc/src/math/tgammaf.h | 18 +++ 50 files changed, 1081 insertions(+), 6 deletions(-) create mode 100644 libc/src/math/acos.h create mode 100644 libc/src/math/acosh.h create mode 100644 libc/src/math/asin.h create mode 100644 libc/src/math/asinh.h create mode 100644 libc/src/math/atan.h create mode 100644 libc/src/math/atan2.h create mode 100644 libc/src/math/atan2f.h create mode 100644 libc/src/math/atanh.h create mode 100644 libc/src/math/erf.h create mode 100644 libc/src/math/expm1.h create mode 100644 libc/src/math/gpu/vendor/acos.cpp create mode 100644 libc/src/math/gpu/vendor/acosh.cpp create mode 100644 libc/src/math/gpu/vendor/asin.cpp create mode 100644 libc/src/math/gpu/vendor/asinh.cpp create mode 100644 libc/src/math/gpu/vendor/atan.cpp create mode 100644 libc/src/math/gpu/vendor/atan2.cpp create mode 100644 libc/src/math/gpu/vendor/atan2f.cpp create mode 100644 libc/src/math/gpu/vendor/atanh.cpp create mode 100644 libc/src/math/gpu/vendor/erf.cpp create mode 100644 libc/src/math/gpu/vendor/erff.cpp create mode 100644 libc/src/math/gpu/vendor/exp.cpp create mode 100644 libc/src/math/gpu/vendor/exp10.cpp create mode 100644 libc/src/math/gpu/vendor/exp2.cpp create mode 100644 libc/src/math/gpu/vendor/expm1.cpp create mode 100644 libc/src/math/gpu/vendor/log.cpp create mode 100644 libc/src/math/gpu/vendor/log10.cpp create mode 100644 libc/src/math/gpu/vendor/log10f.cpp create mode 100644 libc/src/math/gpu/vendor/log1p.cpp create mode 100644 libc/src/math/gpu/vendor/log1pf.cpp create mode 100644 libc/src/math/gpu/vendor/log2.cpp create mode 100644 libc/src/math/gpu/vendor/log2f.cpp create mode 100644 libc/src/math/gpu/vendor/logb.cpp create mode 100644 libc/src/math/gpu/vendor/logbf.cpp create mode 100644 libc/src/math/gpu/vendor/logf.cpp create mode 100644 libc/src/math/gpu/vendor/lrint.cpp create mode 100644 libc/src/math/gpu/vendor/lrintf.cpp create mode 100644 libc/src/math/gpu/vendor/lround.cpp create mode 100644 libc/src/math/gpu/vendor/lroundf.cpp create mode 100644 libc/src/math/gpu/vendor/tgamma.cpp create mode 100644 libc/src/math/gpu/vendor/tgammaf.cpp create mode 100644 libc/src/math/sincos.h create mode 100644 libc/src/math/tgamma.h create mode 100644 libc/src/math/tgammaf.h diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt index 0e314c60870c6ae..730f76cbd6fbb9c 100644 --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -113,11 +113,19 @@ set(TARGET_LIBC_ENTRYPOINTS set(TARGET_LIBM_ENTRYPOINTS # math.h entrypoints + libc.src.math.acos libc.src.math.acosf + libc.src.math.acosh libc.src.math.acoshf + libc.src.math.asin libc.src.math.asinf + libc.src.math.asinh libc.src.math.asinhf + libc.src.math.atan libc.src.math.atanf + libc.src.math.atan2 + libc.src.math.atan2f + libc.src.math.atanh libc.src.math.atanhf libc.src.math.ceil libc.src.math.ceilf @@ -127,9 +135,15 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.cosf libc.src.math.cosh libc.src.math.coshf + libc.src.math.erf + libc.src.math.erff + libc.src.math.exp10 libc.src.math.exp10f + libc.src.math.exp2 libc.src.math.exp2f + libc.src.math.exp libc.src.math.expf + libc.src.math.expm1 libc.src.math.expm1f libc.src.math.fabs libc.src.math.fabsf @@ -157,15 +171,26 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.llrintf libc.src.math.llround libc.src.math.llroundf - libc.src.math.pow - libc.src.math.powf - libc.src.math.sin + libc.src.math.log10 + libc.src.math.log10f + libc.src.math.log1p + libc.src.math.log1pf + libc.src.math.log2 + libc.src.math.log2f + libc.src.math.log + libc.src.math.logf + libc.src.math.lrint + libc.src.math.lrintf + libc.src.math.lround + libc.src.math.lroundf libc.src.math.modf libc.src.math.modff libc.src.math.nearbyint libc.src.math.nearbyintf libc.src.math.nextafter libc.src.math.nextafterf + libc.src.math.pow + libc.src.math.powf libc.src.math.remainder libc.src.math.remainderf libc.src.math.remquo @@ -176,6 +201,10 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.roundf libc.src.math.scalbn libc.src.math.scalbnf + libc.src.math.sin + libc.src.math.sinf + libc.src.math.sincos + libc.src.math.sincosf libc.src.math.sinh libc.src.math.sinhf libc.src.math.sqrt @@ -184,6 +213,8 @@ set(TARGET_LIBM_ENTRYPOINTS libc.src.math.tanf libc.src.math.tanh libc.src.math.tanhf + libc.src.math.tgamma + libc.src.math.tgammaf libc.src.math.trunc libc.src.math.truncf ) diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt index 8b2021cac8239fe..f1f72714981a9e5 100644 --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -54,14 +54,23 @@ function(add_math_entrypoint_object name) ) endfunction() +add_math_entrypoint_object(acos) add_math_entrypoint_object(acosf) +add_math_entrypoint_object(acosh) add_math_entrypoint_object(acoshf) +add_math_entrypoint_object(asin) add_math_entrypoint_object(asinf) +add_math_entrypoint_object(asinh) add_math_entrypoint_object(asinhf) +add_math_entrypoint_object(atan) add_math_entrypoint_object(atanf) +add_math_entrypoint_object(atan2) +add_math_entrypoint_object(atan2f) + +add_math_entrypoint_object(atanh) add_math_entrypoint_object(atanhf) add_math_entrypoint_object(ceil) @@ -77,6 +86,7 @@ add_math_entrypoint_object(cosf) add_math_entrypoint_object(cosh) add_math_entrypoint_object(coshf) +add_math_entrypoint_object(erf) add_math_entrypoint_object(erff) add_math_entrypoint_object(exp) @@ -88,6 +98,7 @@ add_math_entrypoint_object(exp2f) add_math_entrypoint_object(exp10) add_math_entrypoint_object(exp10f) +add_math_entrypoint_object(expm1) add_math_entrypoint_object(expm1f) add_math_entrypoint_object(fabs) @@ -198,6 +209,7 @@ add_math_entrypoint_object(scalbn) add_math_entrypoint_object(scalbnf) add_math_entrypoint_object(scalbnl) +add_math_entrypoint_object(sincos) add_math_entrypoint_object(sincosf) add_math_entrypoint_object(sin) @@ -216,6 +228,9 @@ add_math_entrypoint_object(tanf) add_math_entrypoint_object(tanh) add_math_entrypoint_object(tanhf) +add_math_entrypoint_object(tgamma) +add_math_entrypoint_object(tgammaf) + add_math_entrypoint_object(trunc) add_math_entrypoint_object(truncf) add_math_entrypoint_object(truncl) diff --git a/libc/src/math/acos.h b/libc/src/math/acos.h new file mode 100644 index 000000000000000..53b299f1da8902e --- /dev/null +++ b/libc/src/math/acos.h @@ -0,0 +1,18 @@ +//===-- Implementation header for acos --------------------------*- 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_ACOS_H +#define LLVM_LIBC_SRC_MATH_ACOS_H + +namespace __llvm_libc { + +double acos(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_ACOS_H diff --git a/libc/src/math/acosh.h b/libc/src/math/acosh.h new file mode 100644 index 000000000000000..851c619fdb9f799 --- /dev/null +++ b/libc/src/math/acosh.h @@ -0,0 +1,18 @@ +//===-- Implementation header for acosh -------------------------*- 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_ACOSH_H +#define LLVM_LIBC_SRC_MATH_ACOSH_H + +namespace __llvm_libc { + +double acosh(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_ACOSH_H diff --git a/libc/src/math/asin.h b/libc/src/math/asin.h new file mode 100644 index 000000000000000..d8f3f191a357856 --- /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/asinh.h b/libc/src/math/asinh.h new file mode 100644 index 000000000000000..098880f26ecc80c --- /dev/null +++ b/libc/src/math/asinh.h @@ -0,0 +1,18 @@ +//===-- Implementation header for asinh -------------------------*- 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_ASINH_H +#define LLVM_LIBC_SRC_MATH_ASINH_H + +namespace __llvm_libc { + +double asinh(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_ASINH_H diff --git a/libc/src/math/atan.h b/libc/src/math/atan.h new file mode 100644 index 000000000000000..73d67e526d7d5a5 --- /dev/null +++ b/libc/src/math/atan.h @@ -0,0 +1,18 @@ +//===-- Implementation header for atan --------------------------*- 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_ATAN_H +#define LLVM_LIBC_SRC_MATH_ATAN_H + +namespace __llvm_libc { + +double atan(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_ATAN_H diff --git a/libc/src/math/atan2.h b/libc/src/math/atan2.h new file mode 100644 index 000000000000000..cac5b7ddfbb62c1 --- /dev/null +++ b/libc/src/math/atan2.h @@ -0,0 +1,18 @@ +//===-- Implementation header for atan2 -------------------------*- 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_ATAN2_H +#define LLVM_LIBC_SRC_MATH_ATAN2_H + +namespace __llvm_libc { + +double atan2(double x, double y); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_ATAN2_H diff --git a/libc/src/math/atan2f.h b/libc/src/math/atan2f.h new file mode 100644 index 000000000000000..d3e81a2b8d5f2d4 --- /dev/null +++ b/libc/src/math/atan2f.h @@ -0,0 +1,18 @@ +//===-- Implementation header for atan2f ------------------------*- 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_ATAN2F_H +#define LLVM_LIBC_SRC_MATH_ATAN2F_H + +namespace __llvm_libc { + +float atan2f(float x, float y); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_ATAN2F_H diff --git a/libc/src/math/atanh.h b/libc/src/math/atanh.h new file mode 100644 index 000000000000000..de854451e7a281f --- /dev/null +++ b/libc/src/math/atanh.h @@ -0,0 +1,18 @@ +//===-- Implementation header for atanh -------------------------*- 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_ATANH_H +#define LLVM_LIBC_SRC_MATH_ATANH_H + +namespace __llvm_libc { + +double atanh(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_ATANH_H diff --git a/libc/src/math/erf.h b/libc/src/math/erf.h new file mode 100644 index 000000000000000..86a146182b4f729 --- /dev/null +++ b/libc/src/math/erf.h @@ -0,0 +1,18 @@ +//===-- Implementation header for erf ---------------------------*- 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_ERF_H +#define LLVM_LIBC_SRC_MATH_ERF_H + +namespace __llvm_libc { + +double erf(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_ERF_H diff --git a/libc/src/math/expm1.h b/libc/src/math/expm1.h new file mode 100644 index 000000000000000..7ae354e459feb1f --- /dev/null +++ b/libc/src/math/expm1.h @@ -0,0 +1,18 @@ +//===-- Implementation header for expm1 -------------------------*- 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_EXPM1_H +#define LLVM_LIBC_SRC_MATH_EXPM1_H + +namespace __llvm_libc { + +double expm1(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_EXPM1_H diff --git a/libc/src/math/gpu/vendor/CMakeLists.txt b/libc/src/math/gpu/vendor/CMakeLists.txt index 2ee74a06a02d461..58910ac517bdc97 100644 --- a/libc/src/math/gpu/vendor/CMakeLists.txt +++ b/libc/src/math/gpu/vendor/CMakeLists.txt @@ -29,6 +29,17 @@ endif() # will link in identity metadata from both libraries. This silences the warning. list(APPEND bitcode_link_flags "-Wno-linker-warnings") +add_entrypoint_object( + acos + SRCS + acos.cpp + HDRS + ../../acos.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + add_entrypoint_object( acosf SRCS @@ -40,6 +51,17 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + acosh + SRCS + acosh.cpp + HDRS + ../../acosh.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + add_entrypoint_object( acoshf SRCS @@ -51,6 +73,17 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + asin + SRCS + asin.cpp + HDRS + ../../asin.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + add_entrypoint_object( asinf SRCS @@ -62,6 +95,17 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + asinh + SRCS + asinh.cpp + HDRS + ../../asinh.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + add_entrypoint_object( asinhf SRCS @@ -73,6 +117,17 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + atan + SRCS + atan.cpp + HDRS + ../../atan.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + add_entrypoint_object( atanf SRCS @@ -84,6 +139,39 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + atan2 + SRCS + atan2.cpp + HDRS + ../../atan2.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + +add_entrypoint_object( + atan2f + SRCS + atan2f.cpp + HDRS + ../../atan2f.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + +add_entrypoint_object( + atanh + SRCS + atanh.cpp + HDRS + ../../atanh.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + add_entrypoint_object( atanhf SRCS @@ -139,6 +227,28 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + erf + SRCS + erf.cpp + HDRS + ../../erf.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + +add_entrypoint_object( + erff + SRCS + erff.cpp + HDRS + ../../erff.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + add_entrypoint_object( exp10f SRCS @@ -172,6 +282,17 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + expm1 + SRCS + expm1.cpp + HDRS + ../../expm1.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + add_entrypoint_object( expm1f SRCS @@ -515,6 +636,28 @@ add_entrypoint_object( -O2 ) +add_entrypoint_object( + tgamma + SRCS + tgamma.cpp + HDRS + ../../tgamma.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + +add_entrypoint_object( + tgammaf + SRCS + tgammaf.cpp + HDRS + ../../tgammaf.h + COMPILE_OPTIONS + ${bitcode_link_flags} + -O2 +) + add_entrypoint_object( frexp SRCS diff --git a/libc/src/math/gpu/vendor/acos.cpp b/libc/src/math/gpu/vendor/acos.cpp new file mode 100644 index 000000000000000..7e6d00be3c3e589 --- /dev/null +++ b/libc/src/math/gpu/vendor/acos.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU acos 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/acos.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, acos, (double x)) { return internal::acos(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/acosh.cpp b/libc/src/math/gpu/vendor/acosh.cpp new file mode 100644 index 000000000000000..2ea150dcf78e03a --- /dev/null +++ b/libc/src/math/gpu/vendor/acosh.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU acosh 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/acosh.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, acosh, (double x)) { return internal::acosh(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/amdgpu/amdgpu.h b/libc/src/math/gpu/vendor/amdgpu/amdgpu.h index 7755174e445b222..a763f2e3d0f53f1 100644 --- a/libc/src/math/gpu/vendor/amdgpu/amdgpu.h +++ b/libc/src/math/gpu/vendor/amdgpu/amdgpu.h @@ -16,19 +16,30 @@ namespace __llvm_libc { namespace internal { +LIBC_INLINE double acos(double x) { return __ocml_acos_f64(x); } LIBC_INLINE float acosf(float x) { return __ocml_acos_f32(x); } +LIBC_INLINE double acosh(double x) { return __ocml_acosh_f64(x); } LIBC_INLINE float acoshf(float x) { return __ocml_acosh_f32(x); } +LIBC_INLINE double asin(double x) { return __ocml_asin_f64(x); } LIBC_INLINE float asinf(float x) { return __ocml_asin_f32(x); } +LIBC_INLINE double asinh(double x) { return __ocml_asinh_f64(x); } LIBC_INLINE float asinhf(float x) { return __ocml_asinh_f32(x); } +LIBC_INLINE double atan(double x) { return __ocml_atan_f64(x); } LIBC_INLINE float atanf(float x) { return __ocml_atan_f32(x); } +LIBC_INLINE double atan2(double x, double y) { return __ocml_atan2_f64(x, y); } +LIBC_INLINE float atan2f(float x, float y) { return __ocml_atan2_f32(x, y); } +LIBC_INLINE double atanh(double x) { return __ocml_atanh_f64(x); } LIBC_INLINE float atanhf(float x) { return __ocml_atanh_f32(x); } LIBC_INLINE double cos(double x) { return __ocml_cos_f64(x); } LIBC_INLINE float cosf(float x) { return __ocml_cos_f32(x); } LIBC_INLINE double cosh(double x) { return __ocml_cosh_f64(x); } LIBC_INLINE float coshf(float x) { return __ocml_cosh_f32(x); } +LIBC_INLINE double erf(double x) { return __ocml_erf_f64(x); } +LIBC_INLINE float erff(float x) { return __ocml_erf_f32(x); } LIBC_INLINE float expf(float x) { return __builtin_expf(x); } LIBC_INLINE float exp2f(float x) { return __builtin_exp2f(x); } LIBC_INLINE float exp10f(float x) { return __ocml_exp10_f32(x); } +LIBC_INLINE double expm1(double x) { return __ocml_expm1_f64(x); } LIBC_INLINE float expm1f(float x) { return __ocml_expm1_f32(x); } LIBC_INLINE double fdim(double x, double y) { return __ocml_fdim_f64(x, y); } LIBC_INLINE float fdimf(float x, float y) { return __ocml_fdim_f32(x, y); } @@ -50,6 +61,18 @@ LIBC_INLINE long long llround(double x) { LIBC_INLINE long long llroundf(float x) { return static_cast<long long>(__builtin_roundf(x)); } +LIBC_INLINE double log10(double x) { return __ocml_log10_f64(x); } +LIBC_INLINE float log10f(float x) { return __ocml_log10_f32(x); } +LIBC_INLINE double log1p(double x) { return __ocml_log1p_f64(x); } +LIBC_INLINE float log1pf(float x) { return __ocml_log1p_f32(x); } +LIBC_INLINE double log2(double x) { return __ocml_log2_f64(x); } +LIBC_INLINE float log2f(float x) { return __ocml_log2_f32(x); } +LIBC_INLINE double log(double x) { return __ocml_log_f64(x); } +LIBC_INLINE float logf(float x) { return __ocml_log_f32(x); } +LIBC_INLINE long lrint(double x) { return (long)__ocml_rint_f64(x); } +LIBC_INLINE long lrintf(float x) { return (long)__ocml_rint_f32(x); } +LIBC_INLINE long lround(double x) { return (long)__ocml_round_f64(x); } +LIBC_INLINE long lroundf(float x) { return (long)__ocml_round_f32(x); } LIBC_INLINE double nextafter(double x, double y) { return __ocml_nextafter_f64(x, y); } @@ -96,6 +119,8 @@ LIBC_INLINE float remquof(float x, float y, int *q) { *q = tmp; return r; } +LIBC_INLINE double tgamma(double x) { return __ocml_tgamma_f64(x); } +LIBC_INLINE float tgammaf(float x) { return __ocml_tgamma_f32(x); } } // namespace internal } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/amdgpu/declarations.h b/libc/src/math/gpu/vendor/amdgpu/declarations.h index 7219d5a7dfa6d73..84214edb6624bc8 100644 --- a/libc/src/math/gpu/vendor/amdgpu/declarations.h +++ b/libc/src/math/gpu/vendor/amdgpu/declarations.h @@ -15,35 +15,61 @@ namespace __llvm_libc { extern "C" { float __ocml_acos_f32(float); +double __ocml_acos_f64(double); float __ocml_acosh_f32(float); +double __ocml_acosh_f64(double); float __ocml_asin_f32(float); +double __ocml_asin_f64(double); float __ocml_asinh_f32(float); +double __ocml_asinh_f64(double); float __ocml_atan_f32(float); +double __ocml_atan_f64(double); +float __ocml_atan2_f32(float, float); +double __ocml_atan2_f64(double, double); float __ocml_atanh_f32(float); +double __ocml_atanh_f64(double); float __ocml_cos_f32(float); double __ocml_cos_f64(double); float __ocml_cosh_f32(float); double __ocml_cosh_f64(double); +float __ocml_erf_f32(float); +double __ocml_erf_f64(double); float __ocml_exp_f32(float); +double __ocml_exp_f64(double); float __ocml_exp2_f32(float); +double __ocml_exp2_f64(double); float __ocml_exp10_f32(float); +double __ocml_exp2_f64(double); float __ocml_expm1_f32(float); +double __ocml_expm1_f64(double); float __ocml_fdim_f32(float, float); double __ocml_fdim_f64(double, double); -double __ocml_hypot_f64(double, double); float __ocml_hypot_f32(float, float); +double __ocml_hypot_f64(double, double); int __ocml_ilogb_f64(double); int __ocml_ilogb_f32(float); float __ocml_ldexp_f32(float, int); double __ocml_ldexp_f64(double, int); +float __ocml_log10_f32(float); +double __ocml_log10_f64(double); +float __ocml_log1p_f32(float); +double __ocml_log1p_f64(double); +float __ocml_log2_f32(float); +double __ocml_log2_f64(double); +float __ocml_log_f32(float); +double __ocml_log_f64(double); +long __ocml_lrint_f32(float); +long __ocml_lrint_f64(double); +long __ocml_lround_f32(float); +long __ocml_lround_f64(double); float __ocml_nextafter_f32(float, float); double __ocml_nextafter_f64(double, double); float __ocml_pow_f32(float, float); double __ocml_pow_f64(double, double); -double __ocml_rint_f64(double); float __ocml_rint_f32(float); -double __ocml_round_f64(double); +double __ocml_rint_f64(double); float __ocml_round_f32(float); +double __ocml_round_f64(double); float __ocml_sin_f32(float); double __ocml_sin_f64(double); float __ocml_sincos_f32(float, float *); @@ -56,6 +82,8 @@ float __ocml_tanh_f32(float); double __ocml_tanh_f64(double); float __ocml_remquo_f32(float, float, gpu::Private<int> *); double __ocml_remquo_f64(double, double, gpu::Private<int> *); +double __ocml_tgamma_f64(double); +float __ocml_tgamma_f32(float); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/asin.cpp b/libc/src/math/gpu/vendor/asin.cpp new file mode 100644 index 000000000000000..eaf7253ad1ecaff --- /dev/null +++ b/libc/src/math/gpu/vendor/asin.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU 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/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, asin, (double x)) { return internal::asin(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/asinh.cpp b/libc/src/math/gpu/vendor/asinh.cpp new file mode 100644 index 000000000000000..ddb33ebae3a590a --- /dev/null +++ b/libc/src/math/gpu/vendor/asinh.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU asinh 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/asinh.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, asinh, (double x)) { return internal::asinh(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/atan.cpp b/libc/src/math/gpu/vendor/atan.cpp new file mode 100644 index 000000000000000..88452dc60188a59 --- /dev/null +++ b/libc/src/math/gpu/vendor/atan.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU atan 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/atan.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, atan, (double x)) { return internal::atan(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/atan2.cpp b/libc/src/math/gpu/vendor/atan2.cpp new file mode 100644 index 000000000000000..9f5736f7c30e1f8 --- /dev/null +++ b/libc/src/math/gpu/vendor/atan2.cpp @@ -0,0 +1,20 @@ +//===-- Implementation of the GPU 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/atan2.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, atan2, (double x, double y)) { + return internal::atan2(x, y); +} + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/atan2f.cpp b/libc/src/math/gpu/vendor/atan2f.cpp new file mode 100644 index 000000000000000..897bd5d26527763 --- /dev/null +++ b/libc/src/math/gpu/vendor/atan2f.cpp @@ -0,0 +1,21 @@ +//===-- Implementation of the GPU atan2f 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/atan2f.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(float, atan2f, (float x, float y)) { + return internal::atan2f(x, y); +} + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/atanh.cpp b/libc/src/math/gpu/vendor/atanh.cpp new file mode 100644 index 000000000000000..97246bf195ff77c --- /dev/null +++ b/libc/src/math/gpu/vendor/atanh.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU atanh 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/atanh.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, atanh, (double x)) { return internal::atanh(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/erf.cpp b/libc/src/math/gpu/vendor/erf.cpp new file mode 100644 index 000000000000000..f06ab8121ebd669 --- /dev/null +++ b/libc/src/math/gpu/vendor/erf.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU erf 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/erf.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, erf, (double x)) { return internal::erf(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/erff.cpp b/libc/src/math/gpu/vendor/erff.cpp new file mode 100644 index 000000000000000..78c31383d86acb1 --- /dev/null +++ b/libc/src/math/gpu/vendor/erff.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU erff 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/erff.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(float, erff, (float x)) { return internal::erff(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/exp.cpp b/libc/src/math/gpu/vendor/exp.cpp new file mode 100644 index 000000000000000..dc315d9555b422a --- /dev/null +++ b/libc/src/math/gpu/vendor/exp.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU exp 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/exp.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, exp, (double x)) { return internal::exp(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/exp10.cpp b/libc/src/math/gpu/vendor/exp10.cpp new file mode 100644 index 000000000000000..1bb746bfdcac260 --- /dev/null +++ b/libc/src/math/gpu/vendor/exp10.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU exp10 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/exp10.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, exp10, (double x)) { return internal::exp10(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/exp2.cpp b/libc/src/math/gpu/vendor/exp2.cpp new file mode 100644 index 000000000000000..0dbea3837cbdd0d --- /dev/null +++ b/libc/src/math/gpu/vendor/exp2.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU exp2 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/exp2.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, exp2, (double x)) { return internal::exp2(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/expm1.cpp b/libc/src/math/gpu/vendor/expm1.cpp new file mode 100644 index 000000000000000..528daab22e14cfd --- /dev/null +++ b/libc/src/math/gpu/vendor/expm1.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU expm1 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/expm1.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, expm1, (double x)) { return internal::expm1(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/log.cpp b/libc/src/math/gpu/vendor/log.cpp new file mode 100644 index 000000000000000..fe44d78724a4ca2 --- /dev/null +++ b/libc/src/math/gpu/vendor/log.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU log 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/log.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, log, (double x)) { return internal::log(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/log10.cpp b/libc/src/math/gpu/vendor/log10.cpp new file mode 100644 index 000000000000000..6666dae827646da --- /dev/null +++ b/libc/src/math/gpu/vendor/log10.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU log10 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/log10.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, log10, (double x)) { return internal::log10(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/log10f.cpp b/libc/src/math/gpu/vendor/log10f.cpp new file mode 100644 index 000000000000000..5e938a32895128e --- /dev/null +++ b/libc/src/math/gpu/vendor/log10f.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of the GPU log10f 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/log10f.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(float, log10f, (float x)) { return internal::log10f(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/log1p.cpp b/libc/src/math/gpu/vendor/log1p.cpp new file mode 100644 index 000000000000000..e2781bfbab1ceba --- /dev/null +++ b/libc/src/math/gpu/vendor/log1p.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU log1p 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/log1p.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, log1p, (double x)) { return internal::log1p(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/log1pf.cpp b/libc/src/math/gpu/vendor/log1pf.cpp new file mode 100644 index 000000000000000..3cdde90d94b132f --- /dev/null +++ b/libc/src/math/gpu/vendor/log1pf.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU log1pf 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/log1pf.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(float, log1pf, (float x)) { return internal::log1pf(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/log2.cpp b/libc/src/math/gpu/vendor/log2.cpp new file mode 100644 index 000000000000000..45d2200d269009d --- /dev/null +++ b/libc/src/math/gpu/vendor/log2.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU log2 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/log2.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, log2, (double x)) { return internal::log2(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/log2f.cpp b/libc/src/math/gpu/vendor/log2f.cpp new file mode 100644 index 000000000000000..2378bc1bacb47a5 --- /dev/null +++ b/libc/src/math/gpu/vendor/log2f.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU log2f 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/log2f.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(float, log2f, (float x)) { return internal::log2f(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/logb.cpp b/libc/src/math/gpu/vendor/logb.cpp new file mode 100644 index 000000000000000..d7aa9a1d1517e6a --- /dev/null +++ b/libc/src/math/gpu/vendor/logb.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU logb 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/logb.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, logb, (double x)) { return internal::logb(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/logbf.cpp b/libc/src/math/gpu/vendor/logbf.cpp new file mode 100644 index 000000000000000..021bed06c69032c --- /dev/null +++ b/libc/src/math/gpu/vendor/logbf.cpp @@ -0,0 +1,19 @@ +//===-- Implementation of the GPU logbf 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/logbf.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(float, logbf, (float x)) { return internal::logbf(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/logf.cpp b/libc/src/math/gpu/vendor/logf.cpp new file mode 100644 index 000000000000000..6f0c5d5c144ea96 --- /dev/null +++ b/libc/src/math/gpu/vendor/logf.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU logf 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/logf.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(float, logf, (float x)) { return internal::logf(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/lrint.cpp b/libc/src/math/gpu/vendor/lrint.cpp new file mode 100644 index 000000000000000..15316f02ebf871e --- /dev/null +++ b/libc/src/math/gpu/vendor/lrint.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU lrint 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/lrint.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(long, lrint, (double x)) { return internal::lrint(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/lrintf.cpp b/libc/src/math/gpu/vendor/lrintf.cpp new file mode 100644 index 000000000000000..5cbd212e0c999ca --- /dev/null +++ b/libc/src/math/gpu/vendor/lrintf.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU lrintf 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/lrintf.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(long, lrintf, (float x)) { return internal::lrintf(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/lround.cpp b/libc/src/math/gpu/vendor/lround.cpp new file mode 100644 index 000000000000000..cb268104d94b99d --- /dev/null +++ b/libc/src/math/gpu/vendor/lround.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU lround 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/lround.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(long int, lround, (double x)) { return internal::lround(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/lroundf.cpp b/libc/src/math/gpu/vendor/lroundf.cpp new file mode 100644 index 000000000000000..175c6a2561b27de --- /dev/null +++ b/libc/src/math/gpu/vendor/lroundf.cpp @@ -0,0 +1,20 @@ +//===-- Implementation of the GPU lroundf 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/lroundf.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(long int, lroundf, (float x)) { + return internal::lroundf(x); +} + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/nvptx/declarations.h b/libc/src/math/gpu/vendor/nvptx/declarations.h index 8b6702834a04cf4..b8bb90f3bf585c2 100644 --- a/libc/src/math/gpu/vendor/nvptx/declarations.h +++ b/libc/src/math/gpu/vendor/nvptx/declarations.h @@ -12,19 +12,30 @@ namespace __llvm_libc { extern "C" { +double __nv_acos(double); float __nv_acosf(float); +double __nv_acosh(double); float __nv_acoshf(float); +double __nv_asin(double); float __nv_asinf(float); +double __nv_asinh(double); float __nv_asinhf(float); +double __nv_atan(double); float __nv_atanf(float); +double __nv_atan2(double, double); +float __nv_atan2f(float, float); +double __nv_atanh(double); float __nv_atanhf(float); double __nv_cos(double); float __nv_cosf(float); double __nv_cosh(double); float __nv_coshf(float); +double __nv_erf(double); +float __nv_erff(float); float __nv_expf(float); float __nv_exp2f(float); float __nv_exp10f(float); +double __nv_expm1(double); float __nv_expm1f(float); double __nv_fdim(double, double); float __nv_fdimf(float, float); @@ -38,6 +49,18 @@ long long __nv_llrint(double); long long __nv_llrintf(float); long long __nv_llround(double); long long __nv_llroundf(float); +double __nv_log10(double); +float __nv_log10f(float); +double __nv_log1p(double); +float __nv_log1pf(float); +double __nv_log2(double); +float __nv_log2f(float); +double __nv_log(double); +float __nv_logf(float); +long __nv_lrint(double); +long __nv_lrintf(float); +long __nv_lround(double); +long __nv_lroundf(float); double __nv_nextafter(double, double); float __nv_nextafterf(float, float); double __nv_pow(double, double); @@ -58,6 +81,8 @@ double __nv_scalbn(double, int); float __nv_scalbnf(float, int); double __nv_remquo(double, double, int *); float __nv_remquof(float, float, int *); +double __nv_tgamma(double); +float __nv_tgammaf(float); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/nvptx/nvptx.h b/libc/src/math/gpu/vendor/nvptx/nvptx.h index 6ea1743cf7a6f3e..4a2e8d7ab8debea 100644 --- a/libc/src/math/gpu/vendor/nvptx/nvptx.h +++ b/libc/src/math/gpu/vendor/nvptx/nvptx.h @@ -15,19 +15,30 @@ namespace __llvm_libc { namespace internal { +LIBC_INLINE double acos(double x) { return __nv_acos(x); } LIBC_INLINE float acosf(float x) { return __nv_acosf(x); } +LIBC_INLINE double acosh(double x) { return __nv_acosh(x); } LIBC_INLINE float acoshf(float x) { return __nv_acoshf(x); } +LIBC_INLINE double asin(double x) { return __nv_asin(x); } LIBC_INLINE float asinf(float x) { return __nv_asinf(x); } +LIBC_INLINE double asinh(double x) { return __nv_asinh(x); } LIBC_INLINE float asinhf(float x) { return __nv_asinhf(x); } +LIBC_INLINE double atan2(double x, double y) { return __nv_atan2(x, y); } +LIBC_INLINE float atan2f(float x, float y) { return __nv_atan2f(x, y); } +LIBC_INLINE double atan(double x) { return __nv_atan(x); } LIBC_INLINE float atanf(float x) { return __nv_atanf(x); } +LIBC_INLINE double atanh(double x) { return __nv_atanh(x); } LIBC_INLINE float atanhf(float x) { return __nv_atanhf(x); } LIBC_INLINE double cos(double x) { return __nv_cos(x); } LIBC_INLINE float cosf(float x) { return __nv_cosf(x); } LIBC_INLINE double cosh(double x) { return __nv_cosh(x); } LIBC_INLINE float coshf(float x) { return __nv_coshf(x); } +LIBC_INLINE double erf(double x) { return __nv_erf(x); } +LIBC_INLINE float erff(float x) { return __nv_erff(x); } LIBC_INLINE float expf(float x) { return __nv_expf(x); } LIBC_INLINE float exp2f(float x) { return __nv_exp2f(x); } LIBC_INLINE float exp10f(float x) { return __nv_exp10f(x); } +LIBC_INLINE double expm1(double x) { return __nv_expm1(x); } LIBC_INLINE float expm1f(float x) { return __nv_expm1f(x); } LIBC_INLINE double fdim(double x, double y) { return __nv_fdim(x, y); } LIBC_INLINE float fdimf(float x, float y) { return __nv_fdimf(x, y); } @@ -41,6 +52,18 @@ LIBC_INLINE long long llrint(double x) { return __nv_llrint(x); } LIBC_INLINE long long llrintf(float x) { return __nv_llrintf(x); } LIBC_INLINE long long llround(double x) { return __nv_llround(x); } LIBC_INLINE long long llroundf(float x) { return __nv_llroundf(x); } +LIBC_INLINE double log10(double x) { return __nv_log10(x); } +LIBC_INLINE float log10f(float x) { return __nv_log10f(x); } +LIBC_INLINE double log1p(double x) { return __nv_log1p(x); } +LIBC_INLINE float log1pf(float x) { return __nv_log1pf(x); } +LIBC_INLINE double log2(double x) { return __nv_log2(x); } +LIBC_INLINE float log2f(float x) { return __nv_log2f(x); } +LIBC_INLINE double log(double x) { return __nv_log(x); } +LIBC_INLINE float logf(float x) { return __nv_logf(x); } +LIBC_INLINE long lrint(double x) { return __nv_lrint(x); } +LIBC_INLINE long lrintf(float x) { return __nv_lrintf(x); } +LIBC_INLINE long lround(double x) { return __nv_lround(x); } +LIBC_INLINE long lroundf(float x) { return __nv_lroundf(x); } LIBC_INLINE double nextafter(double x, double y) { return __nv_nextafter(x, y); } @@ -71,6 +94,8 @@ LIBC_INLINE double remquo(double x, double y, int *i) { LIBC_INLINE float remquof(float x, float y, int *i) { return __nv_remquof(x, y, i); } +LIBC_INLINE double tgamma(double x) { return __nv_tgamma(x); } +LIBC_INLINE float tgammaf(float x) { return __nv_tgammaf(x); } } // namespace internal } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/tgamma.cpp b/libc/src/math/gpu/vendor/tgamma.cpp new file mode 100644 index 000000000000000..9895c4bfcf55926 --- /dev/null +++ b/libc/src/math/gpu/vendor/tgamma.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU tgamma 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/tgamma.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, tgamma, (double x)) { return internal::tgamma(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/tgammaf.cpp b/libc/src/math/gpu/vendor/tgammaf.cpp new file mode 100644 index 000000000000000..9e86dacf36083a9 --- /dev/null +++ b/libc/src/math/gpu/vendor/tgammaf.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of the GPU tgammaf 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/tgammaf.h" +#include "src/__support/common.h" + +#include "common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(float, tgammaf, (float x)) { return internal::tgammaf(x); } + +} // namespace __llvm_libc diff --git a/libc/src/math/sincos.h b/libc/src/math/sincos.h new file mode 100644 index 000000000000000..2e3d0673935193f --- /dev/null +++ b/libc/src/math/sincos.h @@ -0,0 +1,18 @@ +//===-- Implementation header for sincos ------------------------*- 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_SINCOS_H +#define LLVM_LIBC_SRC_MATH_SINCOS_H + +namespace __llvm_libc { + +void sincos(double x, double *sinx, double *cosx); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_SINCOS_H diff --git a/libc/src/math/tgamma.h b/libc/src/math/tgamma.h new file mode 100644 index 000000000000000..295070383f3950c --- /dev/null +++ b/libc/src/math/tgamma.h @@ -0,0 +1,18 @@ +//===-- Implementation header for tgamma ------------------------*- 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_TGAMMA_H +#define LLVM_LIBC_SRC_MATH_TGAMMA_H + +namespace __llvm_libc { + +double tgamma(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_TGAMMA_H diff --git a/libc/src/math/tgammaf.h b/libc/src/math/tgammaf.h new file mode 100644 index 000000000000000..c098dae4b7ec6bd --- /dev/null +++ b/libc/src/math/tgammaf.h @@ -0,0 +1,18 @@ +//===-- Implementation header for tgammaf -----------------------*- 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_TGAMMAF_H +#define LLVM_LIBC_SRC_MATH_TGAMMAF_H + +namespace __llvm_libc { + +float tgammaf(float x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_TGAMMAF_H >From 14ce71e71827c310a609bb7ff617d02eb65bc9ea Mon Sep 17 00:00:00 2001 From: antonrydahl <rydahl2...@gmail.com> Date: Thu, 14 Sep 2023 20:59:19 -0700 Subject: [PATCH 2/3] Replacing vendor rint and round functions with corresponding LLVM intrinsics --- libc/src/math/gpu/CMakeLists.txt | 80 +++++++++++++++++++ libc/src/math/gpu/{vendor => }/llrint.cpp | 6 +- libc/src/math/gpu/{vendor => }/llrintf.cpp | 6 +- libc/src/math/gpu/{vendor => }/llround.cpp | 6 +- libc/src/math/gpu/{vendor => }/llroundf.cpp | 6 +- libc/src/math/gpu/{vendor => }/lrint.cpp | 4 +- libc/src/math/gpu/{vendor => }/lrintf.cpp | 4 +- libc/src/math/gpu/{vendor => }/lround.cpp | 4 +- libc/src/math/gpu/{vendor => }/lroundf.cpp | 9 +-- libc/src/math/gpu/vendor/CMakeLists.txt | 45 ----------- libc/src/math/gpu/vendor/amdgpu/amdgpu.h | 16 ---- .../src/math/gpu/vendor/amdgpu/declarations.h | 8 -- libc/src/math/gpu/vendor/nvptx/declarations.h | 8 -- libc/src/math/gpu/vendor/nvptx/nvptx.h | 8 -- 14 files changed, 94 insertions(+), 116 deletions(-) rename libc/src/math/gpu/{vendor => }/llrint.cpp (80%) rename libc/src/math/gpu/{vendor => }/llrintf.cpp (80%) rename libc/src/math/gpu/{vendor => }/llround.cpp (80%) rename libc/src/math/gpu/{vendor => }/llroundf.cpp (80%) rename libc/src/math/gpu/{vendor => }/lrint.cpp (85%) rename libc/src/math/gpu/{vendor => }/lrintf.cpp (85%) rename libc/src/math/gpu/{vendor => }/lround.cpp (82%) rename libc/src/math/gpu/{vendor => }/lroundf.cpp (68%) diff --git a/libc/src/math/gpu/CMakeLists.txt b/libc/src/math/gpu/CMakeLists.txt index cee7b7d9db476f2..fbf7f9da7f501c3 100644 --- a/libc/src/math/gpu/CMakeLists.txt +++ b/libc/src/math/gpu/CMakeLists.txt @@ -183,6 +183,86 @@ add_math_entrypoint_gpu_object( -O2 ) +add_math_entrypoint_gpu_object( + lrint + SRCS + lrint.cpp + HDRS + ../lrint.h + COMPILE_OPTIONS + -O2 +) + +add_math_entrypoint_gpu_object( + lrintf + SRCS + lrintf.cpp + HDRS + ../lrintf.h + COMPILE_OPTIONS + -O2 +) + +add_math_entrypoint_gpu_object( + lround + SRCS + lround.cpp + HDRS + ../lround.h + COMPILE_OPTIONS + -O2 +) + +add_math_entrypoint_gpu_object( + lroundf + SRCS + lroundf.cpp + HDRS + ../lroundf.h + COMPILE_OPTIONS + -O2 +) + +add_math_entrypoint_gpu_object( + llrint + SRCS + llrint.cpp + HDRS + ../llrint.h + COMPILE_OPTIONS + -O2 +) + +add_math_entrypoint_gpu_object( + llrintf + SRCS + llrintf.cpp + HDRS + ../llrintf.h + COMPILE_OPTIONS + -O2 +) + +add_math_entrypoint_gpu_object( + llround + SRCS + llround.cpp + HDRS + ../llround.h + COMPILE_OPTIONS + -O2 +) + +add_math_entrypoint_gpu_object( + llroundf + SRCS + llroundf.cpp + HDRS + ../llroundf.h + COMPILE_OPTIONS + -O2 +) + add_math_entrypoint_gpu_object( modf SRCS diff --git a/libc/src/math/gpu/vendor/llrint.cpp b/libc/src/math/gpu/llrint.cpp similarity index 80% rename from libc/src/math/gpu/vendor/llrint.cpp rename to libc/src/math/gpu/llrint.cpp index 064d2775460edc1..26acdda8a727182 100644 --- a/libc/src/math/gpu/vendor/llrint.cpp +++ b/libc/src/math/gpu/llrint.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the llrint function for GPU ---------------------===// +//===-- Implementation of the GPU llrint function -------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,12 +9,10 @@ #include "src/math/llrint.h" #include "src/__support/common.h" -#include "common.h" - namespace __llvm_libc { LLVM_LIBC_FUNCTION(long long, llrint, (double x)) { - return internal::llrint(x); + return __builtin_llrint(x); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/llrintf.cpp b/libc/src/math/gpu/llrintf.cpp similarity index 80% rename from libc/src/math/gpu/vendor/llrintf.cpp rename to libc/src/math/gpu/llrintf.cpp index d1befb67c9788b0..50516f3940a1b03 100644 --- a/libc/src/math/gpu/vendor/llrintf.cpp +++ b/libc/src/math/gpu/llrintf.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the llrintf function for GPU --------------------===// +//===-- Implementation of the GPU llrintf function ------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,12 +9,10 @@ #include "src/math/llrintf.h" #include "src/__support/common.h" -#include "common.h" - namespace __llvm_libc { LLVM_LIBC_FUNCTION(long long, llrintf, (float x)) { - return internal::llrintf(x); + return __builtin_llrintf(x); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/llround.cpp b/libc/src/math/gpu/llround.cpp similarity index 80% rename from libc/src/math/gpu/vendor/llround.cpp rename to libc/src/math/gpu/llround.cpp index 51b8370759e9805..f41852f52023909 100644 --- a/libc/src/math/gpu/vendor/llround.cpp +++ b/libc/src/math/gpu/llround.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the llround function for GPU --------------------===// +//===-- Implementation of the GPU llround function ------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,12 +9,10 @@ #include "src/math/llround.h" #include "src/__support/common.h" -#include "common.h" - namespace __llvm_libc { LLVM_LIBC_FUNCTION(long long, llround, (double x)) { - return internal::llround(x); + return __builtin_llround(x); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/llroundf.cpp b/libc/src/math/gpu/llroundf.cpp similarity index 80% rename from libc/src/math/gpu/vendor/llroundf.cpp rename to libc/src/math/gpu/llroundf.cpp index 0131d278020029a..86d060e6e57b135 100644 --- a/libc/src/math/gpu/vendor/llroundf.cpp +++ b/libc/src/math/gpu/llroundf.cpp @@ -1,4 +1,4 @@ -//===-- Implementation of the llroundf function for GPU -------------------===// +//===-- Implementation of the GPU llroundf function -----------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,12 +9,10 @@ #include "src/math/llroundf.h" #include "src/__support/common.h" -#include "common.h" - namespace __llvm_libc { LLVM_LIBC_FUNCTION(long long, llroundf, (float x)) { - return internal::llroundf(x); + return __builtin_lroundf(x); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/lrint.cpp b/libc/src/math/gpu/lrint.cpp similarity index 85% rename from libc/src/math/gpu/vendor/lrint.cpp rename to libc/src/math/gpu/lrint.cpp index 15316f02ebf871e..acdade0f2dd4fd3 100644 --- a/libc/src/math/gpu/vendor/lrint.cpp +++ b/libc/src/math/gpu/lrint.cpp @@ -9,10 +9,8 @@ #include "src/math/lrint.h" #include "src/__support/common.h" -#include "common.h" - namespace __llvm_libc { -LLVM_LIBC_FUNCTION(long, lrint, (double x)) { return internal::lrint(x); } +LLVM_LIBC_FUNCTION(long, lrint, (double x)) { return __builtin_lrint(x); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/lrintf.cpp b/libc/src/math/gpu/lrintf.cpp similarity index 85% rename from libc/src/math/gpu/vendor/lrintf.cpp rename to libc/src/math/gpu/lrintf.cpp index 5cbd212e0c999ca..7d8d65644b34f6e 100644 --- a/libc/src/math/gpu/vendor/lrintf.cpp +++ b/libc/src/math/gpu/lrintf.cpp @@ -9,10 +9,8 @@ #include "src/math/lrintf.h" #include "src/__support/common.h" -#include "common.h" - namespace __llvm_libc { -LLVM_LIBC_FUNCTION(long, lrintf, (float x)) { return internal::lrintf(x); } +LLVM_LIBC_FUNCTION(long, lrintf, (float x)) { return __builtin_lrintf(x); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/lround.cpp b/libc/src/math/gpu/lround.cpp similarity index 82% rename from libc/src/math/gpu/vendor/lround.cpp rename to libc/src/math/gpu/lround.cpp index cb268104d94b99d..ced70a495e5a198 100644 --- a/libc/src/math/gpu/vendor/lround.cpp +++ b/libc/src/math/gpu/lround.cpp @@ -9,10 +9,8 @@ #include "src/math/lround.h" #include "src/__support/common.h" -#include "common.h" - namespace __llvm_libc { -LLVM_LIBC_FUNCTION(long int, lround, (double x)) { return internal::lround(x); } +LLVM_LIBC_FUNCTION(long, lround, (double x)) { return __builtin_lround(x); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/lroundf.cpp b/libc/src/math/gpu/lroundf.cpp similarity index 68% rename from libc/src/math/gpu/vendor/lroundf.cpp rename to libc/src/math/gpu/lroundf.cpp index 175c6a2561b27de..ef0d114ce0562ff 100644 --- a/libc/src/math/gpu/vendor/lroundf.cpp +++ b/libc/src/math/gpu/lroundf.cpp @@ -1,4 +1,5 @@ -//===-- Implementation of the GPU lroundf function ------------------------===// +//===-- Implementation of the GPU lroundf function +//-------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,12 +10,8 @@ #include "src/math/lroundf.h" #include "src/__support/common.h" -#include "common.h" - namespace __llvm_libc { -LLVM_LIBC_FUNCTION(long int, lroundf, (float x)) { - return internal::lroundf(x); -} +LLVM_LIBC_FUNCTION(long, lroundf, (float x)) { return __builtin_lroundf(x); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/CMakeLists.txt b/libc/src/math/gpu/vendor/CMakeLists.txt index 58910ac517bdc97..963249bcc245021 100644 --- a/libc/src/math/gpu/vendor/CMakeLists.txt +++ b/libc/src/math/gpu/vendor/CMakeLists.txt @@ -392,28 +392,6 @@ add_entrypoint_object( -O2 ) -add_entrypoint_object( - llrint - SRCS - llrint.cpp - HDRS - ../../llrint.h - COMPILE_OPTIONS - ${bitcode_link_flags} - -O2 -) - -add_entrypoint_object( - llrintf - SRCS - llrintf.cpp - HDRS - ../../llrintf.h - COMPILE_OPTIONS - ${bitcode_link_flags} - -O2 -) - add_entrypoint_object( remquo SRCS @@ -436,29 +414,6 @@ add_entrypoint_object( -O2 ) - -add_entrypoint_object( - llround - SRCS - llround.cpp - HDRS - ../../llround.h - COMPILE_OPTIONS - ${bitcode_link_flags} - -O2 -) - -add_entrypoint_object( - llroundf - SRCS - llroundf.cpp - HDRS - ../../llroundf.h - COMPILE_OPTIONS - ${bitcode_link_flags} - -O2 -) - add_entrypoint_object( scalbn SRCS diff --git a/libc/src/math/gpu/vendor/amdgpu/amdgpu.h b/libc/src/math/gpu/vendor/amdgpu/amdgpu.h index a763f2e3d0f53f1..ba4aced183194a5 100644 --- a/libc/src/math/gpu/vendor/amdgpu/amdgpu.h +++ b/libc/src/math/gpu/vendor/amdgpu/amdgpu.h @@ -49,18 +49,6 @@ LIBC_INLINE int ilogb(double x) { return __ocml_ilogb_f64(x); } LIBC_INLINE int ilogbf(float x) { return __ocml_ilogb_f32(x); } LIBC_INLINE double ldexp(double x, int i) { return __builtin_ldexp(x, i); } LIBC_INLINE float ldexpf(float x, int i) { return __builtin_ldexpf(x, i); } -LIBC_INLINE long long llrint(double x) { - return static_cast<long long>(__builtin_rint(x)); -} -LIBC_INLINE long long llrintf(float x) { - return static_cast<long long>(__builtin_rintf(x)); -} -LIBC_INLINE long long llround(double x) { - return static_cast<long long>(__builtin_round(x)); -} -LIBC_INLINE long long llroundf(float x) { - return static_cast<long long>(__builtin_roundf(x)); -} LIBC_INLINE double log10(double x) { return __ocml_log10_f64(x); } LIBC_INLINE float log10f(float x) { return __ocml_log10_f32(x); } LIBC_INLINE double log1p(double x) { return __ocml_log1p_f64(x); } @@ -69,10 +57,6 @@ LIBC_INLINE double log2(double x) { return __ocml_log2_f64(x); } LIBC_INLINE float log2f(float x) { return __ocml_log2_f32(x); } LIBC_INLINE double log(double x) { return __ocml_log_f64(x); } LIBC_INLINE float logf(float x) { return __ocml_log_f32(x); } -LIBC_INLINE long lrint(double x) { return (long)__ocml_rint_f64(x); } -LIBC_INLINE long lrintf(float x) { return (long)__ocml_rint_f32(x); } -LIBC_INLINE long lround(double x) { return (long)__ocml_round_f64(x); } -LIBC_INLINE long lroundf(float x) { return (long)__ocml_round_f32(x); } LIBC_INLINE double nextafter(double x, double y) { return __ocml_nextafter_f64(x, y); } diff --git a/libc/src/math/gpu/vendor/amdgpu/declarations.h b/libc/src/math/gpu/vendor/amdgpu/declarations.h index 84214edb6624bc8..0c4fc351097931d 100644 --- a/libc/src/math/gpu/vendor/amdgpu/declarations.h +++ b/libc/src/math/gpu/vendor/amdgpu/declarations.h @@ -58,18 +58,10 @@ float __ocml_log2_f32(float); double __ocml_log2_f64(double); float __ocml_log_f32(float); double __ocml_log_f64(double); -long __ocml_lrint_f32(float); -long __ocml_lrint_f64(double); -long __ocml_lround_f32(float); -long __ocml_lround_f64(double); float __ocml_nextafter_f32(float, float); double __ocml_nextafter_f64(double, double); float __ocml_pow_f32(float, float); double __ocml_pow_f64(double, double); -float __ocml_rint_f32(float); -double __ocml_rint_f64(double); -float __ocml_round_f32(float); -double __ocml_round_f64(double); float __ocml_sin_f32(float); double __ocml_sin_f64(double); float __ocml_sincos_f32(float, float *); diff --git a/libc/src/math/gpu/vendor/nvptx/declarations.h b/libc/src/math/gpu/vendor/nvptx/declarations.h index b8bb90f3bf585c2..c388837b346537d 100644 --- a/libc/src/math/gpu/vendor/nvptx/declarations.h +++ b/libc/src/math/gpu/vendor/nvptx/declarations.h @@ -45,10 +45,6 @@ int __nv_ilogb(double); int __nv_ilogbf(float); double __nv_ldexp(double, int); float __nv_ldexpf(float, int); -long long __nv_llrint(double); -long long __nv_llrintf(float); -long long __nv_llround(double); -long long __nv_llroundf(float); double __nv_log10(double); float __nv_log10f(float); double __nv_log1p(double); @@ -57,10 +53,6 @@ double __nv_log2(double); float __nv_log2f(float); double __nv_log(double); float __nv_logf(float); -long __nv_lrint(double); -long __nv_lrintf(float); -long __nv_lround(double); -long __nv_lroundf(float); double __nv_nextafter(double, double); float __nv_nextafterf(float, float); double __nv_pow(double, double); diff --git a/libc/src/math/gpu/vendor/nvptx/nvptx.h b/libc/src/math/gpu/vendor/nvptx/nvptx.h index 4a2e8d7ab8debea..b87a86d56342f0f 100644 --- a/libc/src/math/gpu/vendor/nvptx/nvptx.h +++ b/libc/src/math/gpu/vendor/nvptx/nvptx.h @@ -48,10 +48,6 @@ LIBC_INLINE int ilogb(double x) { return __nv_ilogb(x); } LIBC_INLINE int ilogbf(float x) { return __nv_ilogbf(x); } LIBC_INLINE double ldexp(double x, int i) { return __nv_ldexp(x, i); } LIBC_INLINE float ldexpf(float x, int i) { return __nv_ldexpf(x, i); } -LIBC_INLINE long long llrint(double x) { return __nv_llrint(x); } -LIBC_INLINE long long llrintf(float x) { return __nv_llrintf(x); } -LIBC_INLINE long long llround(double x) { return __nv_llround(x); } -LIBC_INLINE long long llroundf(float x) { return __nv_llroundf(x); } LIBC_INLINE double log10(double x) { return __nv_log10(x); } LIBC_INLINE float log10f(float x) { return __nv_log10f(x); } LIBC_INLINE double log1p(double x) { return __nv_log1p(x); } @@ -60,10 +56,6 @@ LIBC_INLINE double log2(double x) { return __nv_log2(x); } LIBC_INLINE float log2f(float x) { return __nv_log2f(x); } LIBC_INLINE double log(double x) { return __nv_log(x); } LIBC_INLINE float logf(float x) { return __nv_logf(x); } -LIBC_INLINE long lrint(double x) { return __nv_lrint(x); } -LIBC_INLINE long lrintf(float x) { return __nv_lrintf(x); } -LIBC_INLINE long lround(double x) { return __nv_lround(x); } -LIBC_INLINE long lroundf(float x) { return __nv_lroundf(x); } LIBC_INLINE double nextafter(double x, double y) { return __nv_nextafter(x, y); } >From f0c5395d4e5e14e5f855cfb529fe281861826544 Mon Sep 17 00:00:00 2001 From: antonrydahl <rydahl2...@gmail.com> Date: Thu, 14 Sep 2023 21:23:31 -0700 Subject: [PATCH 3/3] Replaced vendor logf, log10f, and log2f with corresponding LLVM intrinsics in GPU libm --- libc/src/math/gpu/CMakeLists.txt | 30 +++++++++++++++++++ libc/src/math/gpu/{vendor => }/log10f.cpp | 7 ++--- libc/src/math/gpu/{vendor => }/log2f.cpp | 4 +-- libc/src/math/gpu/{vendor => }/logf.cpp | 4 +-- libc/src/math/gpu/vendor/amdgpu/amdgpu.h | 3 -- .../src/math/gpu/vendor/amdgpu/declarations.h | 3 -- libc/src/math/gpu/vendor/nvptx/declarations.h | 3 -- libc/src/math/gpu/vendor/nvptx/nvptx.h | 3 -- 8 files changed, 34 insertions(+), 23 deletions(-) rename libc/src/math/gpu/{vendor => }/log10f.cpp (71%) rename libc/src/math/gpu/{vendor => }/log2f.cpp (85%) rename libc/src/math/gpu/{vendor => }/logf.cpp (85%) diff --git a/libc/src/math/gpu/CMakeLists.txt b/libc/src/math/gpu/CMakeLists.txt index fbf7f9da7f501c3..94bc518378d77c1 100644 --- a/libc/src/math/gpu/CMakeLists.txt +++ b/libc/src/math/gpu/CMakeLists.txt @@ -183,6 +183,36 @@ add_math_entrypoint_gpu_object( -O2 ) +add_math_entrypoint_gpu_object( + log10f + SRCS + log10f.cpp + HDRS + ../log10f.h + COMPILE_OPTIONS + -O2 +) + +add_math_entrypoint_gpu_object( + log2f + SRCS + log2f.cpp + HDRS + ../log2f.h + COMPILE_OPTIONS + -O2 +) + +add_math_entrypoint_gpu_object( + logf + SRCS + logf.cpp + HDRS + ../logf.h + COMPILE_OPTIONS + -O2 +) + add_math_entrypoint_gpu_object( lrint SRCS diff --git a/libc/src/math/gpu/vendor/log10f.cpp b/libc/src/math/gpu/log10f.cpp similarity index 71% rename from libc/src/math/gpu/vendor/log10f.cpp rename to libc/src/math/gpu/log10f.cpp index 5e938a32895128e..2718ed2a9aa5e61 100644 --- a/libc/src/math/gpu/vendor/log10f.cpp +++ b/libc/src/math/gpu/log10f.cpp @@ -1,5 +1,4 @@ -//===-- Implementation of the GPU log10f function -//---------------------------===// +//===-- Implementation of the GPU log10f function -------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -10,10 +9,8 @@ #include "src/math/log10f.h" #include "src/__support/common.h" -#include "common.h" - namespace __llvm_libc { -LLVM_LIBC_FUNCTION(float, log10f, (float x)) { return internal::log10f(x); } +LLVM_LIBC_FUNCTION(float, log10f, (float x)) { return __builtin_log10f(x); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/log2f.cpp b/libc/src/math/gpu/log2f.cpp similarity index 85% rename from libc/src/math/gpu/vendor/log2f.cpp rename to libc/src/math/gpu/log2f.cpp index 2378bc1bacb47a5..563c73ee807589c 100644 --- a/libc/src/math/gpu/vendor/log2f.cpp +++ b/libc/src/math/gpu/log2f.cpp @@ -9,10 +9,8 @@ #include "src/math/log2f.h" #include "src/__support/common.h" -#include "common.h" - namespace __llvm_libc { -LLVM_LIBC_FUNCTION(float, log2f, (float x)) { return internal::log2f(x); } +LLVM_LIBC_FUNCTION(float, log2f, (float x)) { return __builtin_log2f(x); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/logf.cpp b/libc/src/math/gpu/logf.cpp similarity index 85% rename from libc/src/math/gpu/vendor/logf.cpp rename to libc/src/math/gpu/logf.cpp index 6f0c5d5c144ea96..23918a8a1422b6d 100644 --- a/libc/src/math/gpu/vendor/logf.cpp +++ b/libc/src/math/gpu/logf.cpp @@ -9,10 +9,8 @@ #include "src/math/logf.h" #include "src/__support/common.h" -#include "common.h" - namespace __llvm_libc { -LLVM_LIBC_FUNCTION(float, logf, (float x)) { return internal::logf(x); } +LLVM_LIBC_FUNCTION(float, logf, (float x)) { return __builtin_logf(x); } } // namespace __llvm_libc diff --git a/libc/src/math/gpu/vendor/amdgpu/amdgpu.h b/libc/src/math/gpu/vendor/amdgpu/amdgpu.h index ba4aced183194a5..a4ccae17b728a70 100644 --- a/libc/src/math/gpu/vendor/amdgpu/amdgpu.h +++ b/libc/src/math/gpu/vendor/amdgpu/amdgpu.h @@ -50,13 +50,10 @@ LIBC_INLINE int ilogbf(float x) { return __ocml_ilogb_f32(x); } LIBC_INLINE double ldexp(double x, int i) { return __builtin_ldexp(x, i); } LIBC_INLINE float ldexpf(float x, int i) { return __builtin_ldexpf(x, i); } LIBC_INLINE double log10(double x) { return __ocml_log10_f64(x); } -LIBC_INLINE float log10f(float x) { return __ocml_log10_f32(x); } LIBC_INLINE double log1p(double x) { return __ocml_log1p_f64(x); } LIBC_INLINE float log1pf(float x) { return __ocml_log1p_f32(x); } LIBC_INLINE double log2(double x) { return __ocml_log2_f64(x); } -LIBC_INLINE float log2f(float x) { return __ocml_log2_f32(x); } LIBC_INLINE double log(double x) { return __ocml_log_f64(x); } -LIBC_INLINE float logf(float x) { return __ocml_log_f32(x); } LIBC_INLINE double nextafter(double x, double y) { return __ocml_nextafter_f64(x, y); } diff --git a/libc/src/math/gpu/vendor/amdgpu/declarations.h b/libc/src/math/gpu/vendor/amdgpu/declarations.h index 0c4fc351097931d..2e4ad9fe87fd16e 100644 --- a/libc/src/math/gpu/vendor/amdgpu/declarations.h +++ b/libc/src/math/gpu/vendor/amdgpu/declarations.h @@ -50,13 +50,10 @@ int __ocml_ilogb_f64(double); int __ocml_ilogb_f32(float); float __ocml_ldexp_f32(float, int); double __ocml_ldexp_f64(double, int); -float __ocml_log10_f32(float); double __ocml_log10_f64(double); float __ocml_log1p_f32(float); double __ocml_log1p_f64(double); -float __ocml_log2_f32(float); double __ocml_log2_f64(double); -float __ocml_log_f32(float); double __ocml_log_f64(double); float __ocml_nextafter_f32(float, float); double __ocml_nextafter_f64(double, double); diff --git a/libc/src/math/gpu/vendor/nvptx/declarations.h b/libc/src/math/gpu/vendor/nvptx/declarations.h index c388837b346537d..43e42c42c3361f7 100644 --- a/libc/src/math/gpu/vendor/nvptx/declarations.h +++ b/libc/src/math/gpu/vendor/nvptx/declarations.h @@ -46,13 +46,10 @@ int __nv_ilogbf(float); double __nv_ldexp(double, int); float __nv_ldexpf(float, int); double __nv_log10(double); -float __nv_log10f(float); double __nv_log1p(double); float __nv_log1pf(float); double __nv_log2(double); -float __nv_log2f(float); double __nv_log(double); -float __nv_logf(float); double __nv_nextafter(double, double); float __nv_nextafterf(float, float); double __nv_pow(double, double); diff --git a/libc/src/math/gpu/vendor/nvptx/nvptx.h b/libc/src/math/gpu/vendor/nvptx/nvptx.h index b87a86d56342f0f..d685f50a5a33871 100644 --- a/libc/src/math/gpu/vendor/nvptx/nvptx.h +++ b/libc/src/math/gpu/vendor/nvptx/nvptx.h @@ -49,13 +49,10 @@ LIBC_INLINE int ilogbf(float x) { return __nv_ilogbf(x); } LIBC_INLINE double ldexp(double x, int i) { return __nv_ldexp(x, i); } LIBC_INLINE float ldexpf(float x, int i) { return __nv_ldexpf(x, i); } LIBC_INLINE double log10(double x) { return __nv_log10(x); } -LIBC_INLINE float log10f(float x) { return __nv_log10f(x); } LIBC_INLINE double log1p(double x) { return __nv_log1p(x); } LIBC_INLINE float log1pf(float x) { return __nv_log1pf(x); } LIBC_INLINE double log2(double x) { return __nv_log2(x); } -LIBC_INLINE float log2f(float x) { return __nv_log2f(x); } LIBC_INLINE double log(double x) { return __nv_log(x); } -LIBC_INLINE float logf(float x) { return __nv_logf(x); } LIBC_INLINE double nextafter(double x, double y) { return __nv_nextafter(x, y); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits