xref: /aosp_15_r20/prebuilts/clang-tools/linux-x86/clang-headers/openmp_wrappers/cmath (revision bed243d3d9cd544cfb038bfa7be843dedc6e6bf7)
1*bed243d3SAndroid Build Coastguard Worker/*===-- __clang_openmp_device_functions.h - OpenMP math declares -*- c++ -*-===
2*bed243d3SAndroid Build Coastguard Worker *
3*bed243d3SAndroid Build Coastguard Worker * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*bed243d3SAndroid Build Coastguard Worker * See https://llvm.org/LICENSE.txt for license information.
5*bed243d3SAndroid Build Coastguard Worker * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*bed243d3SAndroid Build Coastguard Worker *
7*bed243d3SAndroid Build Coastguard Worker *===-----------------------------------------------------------------------===
8*bed243d3SAndroid Build Coastguard Worker */
9*bed243d3SAndroid Build Coastguard Worker
10*bed243d3SAndroid Build Coastguard Worker#ifndef __CLANG_OPENMP_CMATH_H__
11*bed243d3SAndroid Build Coastguard Worker#define __CLANG_OPENMP_CMATH_H__
12*bed243d3SAndroid Build Coastguard Worker
13*bed243d3SAndroid Build Coastguard Worker#ifndef _OPENMP
14*bed243d3SAndroid Build Coastguard Worker#error "This file is for OpenMP compilation only."
15*bed243d3SAndroid Build Coastguard Worker#endif
16*bed243d3SAndroid Build Coastguard Worker
17*bed243d3SAndroid Build Coastguard Worker#include_next <cmath>
18*bed243d3SAndroid Build Coastguard Worker
19*bed243d3SAndroid Build Coastguard Worker// Make sure we include our math.h overlay, it probably happend already but we
20*bed243d3SAndroid Build Coastguard Worker// need to be sure.
21*bed243d3SAndroid Build Coastguard Worker#include <math.h>
22*bed243d3SAndroid Build Coastguard Worker
23*bed243d3SAndroid Build Coastguard Worker// We (might) need cstdlib because __clang_cuda_cmath.h below declares `abs`
24*bed243d3SAndroid Build Coastguard Worker// which might live in cstdlib.
25*bed243d3SAndroid Build Coastguard Worker#include <cstdlib>
26*bed243d3SAndroid Build Coastguard Worker
27*bed243d3SAndroid Build Coastguard Worker// We need limits because __clang_cuda_cmath.h below uses `std::numeric_limit`.
28*bed243d3SAndroid Build Coastguard Worker#include <limits>
29*bed243d3SAndroid Build Coastguard Worker
30*bed243d3SAndroid Build Coastguard Worker#pragma omp begin declare variant match(                                       \
31*bed243d3SAndroid Build Coastguard Worker    device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any, allow_templates)})
32*bed243d3SAndroid Build Coastguard Worker
33*bed243d3SAndroid Build Coastguard Worker#define __CUDA__
34*bed243d3SAndroid Build Coastguard Worker#define __OPENMP_NVPTX__
35*bed243d3SAndroid Build Coastguard Worker#include <__clang_cuda_cmath.h>
36*bed243d3SAndroid Build Coastguard Worker#undef __OPENMP_NVPTX__
37*bed243d3SAndroid Build Coastguard Worker#undef __CUDA__
38*bed243d3SAndroid Build Coastguard Worker
39*bed243d3SAndroid Build Coastguard Worker// Overloads not provided by the CUDA wrappers but by the CUDA system headers.
40*bed243d3SAndroid Build Coastguard Worker// Since we do not include the latter we define them ourselves.
41*bed243d3SAndroid Build Coastguard Worker#define __DEVICE__ static constexpr __attribute__((always_inline, nothrow))
42*bed243d3SAndroid Build Coastguard Worker
43*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float acosh(float __x) { return ::acoshf(__x); }
44*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float asinh(float __x) { return ::asinhf(__x); }
45*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float atanh(float __x) { return ::atanhf(__x); }
46*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float cbrt(float __x) { return ::cbrtf(__x); }
47*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float erf(float __x) { return ::erff(__x); }
48*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float erfc(float __x) { return ::erfcf(__x); }
49*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float exp2(float __x) { return ::exp2f(__x); }
50*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float expm1(float __x) { return ::expm1f(__x); }
51*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float fdim(float __x, float __y) { return ::fdimf(__x, __y); }
52*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float hypot(float __x, float __y) { return ::hypotf(__x, __y); }
53*bed243d3SAndroid Build Coastguard Worker__DEVICE__ int ilogb(float __x) { return ::ilogbf(__x); }
54*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float lgamma(float __x) { return ::lgammaf(__x); }
55*bed243d3SAndroid Build Coastguard Worker__DEVICE__ long long int llrint(float __x) { return ::llrintf(__x); }
56*bed243d3SAndroid Build Coastguard Worker__DEVICE__ long long int llround(float __x) { return ::llroundf(__x); }
57*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float log1p(float __x) { return ::log1pf(__x); }
58*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float log2(float __x) { return ::log2f(__x); }
59*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float logb(float __x) { return ::logbf(__x); }
60*bed243d3SAndroid Build Coastguard Worker__DEVICE__ long int lrint(float __x) { return ::lrintf(__x); }
61*bed243d3SAndroid Build Coastguard Worker__DEVICE__ long int lround(float __x) { return ::lroundf(__x); }
62*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float nextafter(float __x, float __y) {
63*bed243d3SAndroid Build Coastguard Worker  return ::nextafterf(__x, __y);
64*bed243d3SAndroid Build Coastguard Worker}
65*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float remainder(float __x, float __y) {
66*bed243d3SAndroid Build Coastguard Worker  return ::remainderf(__x, __y);
67*bed243d3SAndroid Build Coastguard Worker}
68*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float scalbln(float __x, long int __y) {
69*bed243d3SAndroid Build Coastguard Worker  return ::scalblnf(__x, __y);
70*bed243d3SAndroid Build Coastguard Worker}
71*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float scalbn(float __x, int __y) { return ::scalbnf(__x, __y); }
72*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float tgamma(float __x) { return ::tgammaf(__x); }
73*bed243d3SAndroid Build Coastguard Worker
74*bed243d3SAndroid Build Coastguard Worker#undef __DEVICE__
75*bed243d3SAndroid Build Coastguard Worker
76*bed243d3SAndroid Build Coastguard Worker#pragma omp end declare variant
77*bed243d3SAndroid Build Coastguard Worker
78*bed243d3SAndroid Build Coastguard Worker#ifdef __AMDGCN__
79*bed243d3SAndroid Build Coastguard Worker#pragma omp begin declare variant match(device = {arch(amdgcn)})
80*bed243d3SAndroid Build Coastguard Worker
81*bed243d3SAndroid Build Coastguard Worker#pragma push_macro("__constant__")
82*bed243d3SAndroid Build Coastguard Worker#define __constant__ __attribute__((constant))
83*bed243d3SAndroid Build Coastguard Worker#define __OPENMP_AMDGCN__
84*bed243d3SAndroid Build Coastguard Worker
85*bed243d3SAndroid Build Coastguard Worker#include <__clang_hip_cmath.h>
86*bed243d3SAndroid Build Coastguard Worker
87*bed243d3SAndroid Build Coastguard Worker#pragma pop_macro("__constant__")
88*bed243d3SAndroid Build Coastguard Worker#undef __OPENMP_AMDGCN__
89*bed243d3SAndroid Build Coastguard Worker
90*bed243d3SAndroid Build Coastguard Worker// Define overloads otherwise which are absent
91*bed243d3SAndroid Build Coastguard Worker#define __DEVICE__ static constexpr __attribute__((always_inline, nothrow))
92*bed243d3SAndroid Build Coastguard Worker
93*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float acos(float __x) { return ::acosf(__x); }
94*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float acosh(float __x) { return ::acoshf(__x); }
95*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float asin(float __x) { return ::asinf(__x); }
96*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float asinh(float __x) { return ::asinhf(__x); }
97*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float atan(float __x) { return ::atanf(__x); }
98*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float atan2(float __x, float __y) { return ::atan2f(__x, __y); }
99*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float atanh(float __x) { return ::atanhf(__x); }
100*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float cbrt(float __x) { return ::cbrtf(__x); }
101*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float cosh(float __x) { return ::coshf(__x); }
102*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float erf(float __x) { return ::erff(__x); }
103*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float erfc(float __x) { return ::erfcf(__x); }
104*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float exp2(float __x) { return ::exp2f(__x); }
105*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float expm1(float __x) { return ::expm1f(__x); }
106*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float fdim(float __x, float __y) { return ::fdimf(__x, __y); }
107*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float hypot(float __x, float __y) { return ::hypotf(__x, __y); }
108*bed243d3SAndroid Build Coastguard Worker__DEVICE__ int ilogb(float __x) { return ::ilogbf(__x); }
109*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float ldexp(float __arg, int __exp) {
110*bed243d3SAndroid Build Coastguard Worker  return ::ldexpf(__arg, __exp);
111*bed243d3SAndroid Build Coastguard Worker}
112*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float lgamma(float __x) { return ::lgammaf(__x); }
113*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float log1p(float __x) { return ::log1pf(__x); }
114*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float logb(float __x) { return ::logbf(__x); }
115*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float nextafter(float __x, float __y) {
116*bed243d3SAndroid Build Coastguard Worker  return ::nextafterf(__x, __y);
117*bed243d3SAndroid Build Coastguard Worker}
118*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float remainder(float __x, float __y) {
119*bed243d3SAndroid Build Coastguard Worker  return ::remainderf(__x, __y);
120*bed243d3SAndroid Build Coastguard Worker}
121*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float scalbn(float __x, int __y) { return ::scalbnf(__x, __y); }
122*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float sinh(float __x) { return ::sinhf(__x); }
123*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float tan(float __x) { return ::tanf(__x); }
124*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float tanh(float __x) { return ::tanhf(__x); }
125*bed243d3SAndroid Build Coastguard Worker__DEVICE__ float tgamma(float __x) { return ::tgammaf(__x); }
126*bed243d3SAndroid Build Coastguard Worker
127*bed243d3SAndroid Build Coastguard Worker#undef __DEVICE__
128*bed243d3SAndroid Build Coastguard Worker
129*bed243d3SAndroid Build Coastguard Worker#pragma omp end declare variant
130*bed243d3SAndroid Build Coastguard Worker#endif // __AMDGCN__
131*bed243d3SAndroid Build Coastguard Worker
132*bed243d3SAndroid Build Coastguard Worker#endif
133