Path: blob/master/tools/android-sdk/renderscript/clang-include/__clang_cuda_cmath.h
496 views
/*===---- __clang_cuda_cmath.h - Device-side CUDA cmath support ------------===1*2* Permission is hereby granted, free of charge, to any person obtaining a copy3* of this software and associated documentation files (the "Software"), to deal4* in the Software without restriction, including without limitation the rights5* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell6* copies of the Software, and to permit persons to whom the Software is7* furnished to do so, subject to the following conditions:8*9* The above copyright notice and this permission notice shall be included in10* all copies or substantial portions of the Software.11*12* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR13* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,14* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE15* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER16* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,17* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN18* THE SOFTWARE.19*20*===-----------------------------------------------------------------------===21*/22#ifndef __CLANG_CUDA_CMATH_H__23#define __CLANG_CUDA_CMATH_H__24#ifndef __CUDA__25#error "This file is for CUDA compilation only."26#endif2728// CUDA lets us use various std math functions on the device side. This file29// works in concert with __clang_cuda_math_forward_declares.h to make this work.30//31// Specifically, the forward-declares header declares __device__ overloads for32// these functions in the global namespace, then pulls them into namespace std33// with 'using' statements. Then this file implements those functions, after34// the implementations have been pulled in.35//36// It's important that we declare the functions in the global namespace and pull37// them into namespace std with using statements, as opposed to simply declaring38// these functions in namespace std, because our device functions need to39// overload the standard library functions, which may be declared in the global40// namespace or in std, depending on the degree of conformance of the stdlib41// implementation. Declaring in the global namespace and pulling into namespace42// std covers all of the known knowns.4344#define __DEVICE__ static __device__ __inline__ __attribute__((always_inline))4546__DEVICE__ long long abs(long long __n) { return ::llabs(__n); }47__DEVICE__ long abs(long __n) { return ::labs(__n); }48__DEVICE__ float abs(float __x) { return ::fabsf(__x); }49__DEVICE__ double abs(double __x) { return ::fabs(__x); }50__DEVICE__ float acos(float __x) { return ::acosf(__x); }51__DEVICE__ float asin(float __x) { return ::asinf(__x); }52__DEVICE__ float atan(float __x) { return ::atanf(__x); }53__DEVICE__ float atan2(float __x, float __y) { return ::atan2f(__x, __y); }54__DEVICE__ float ceil(float __x) { return ::ceilf(__x); }55__DEVICE__ float cos(float __x) { return ::cosf(__x); }56__DEVICE__ float cosh(float __x) { return ::coshf(__x); }57__DEVICE__ float exp(float __x) { return ::expf(__x); }58__DEVICE__ float fabs(float __x) { return ::fabsf(__x); }59__DEVICE__ float floor(float __x) { return ::floorf(__x); }60__DEVICE__ float fmod(float __x, float __y) { return ::fmodf(__x, __y); }61__DEVICE__ int fpclassify(float __x) {62return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL,63FP_ZERO, __x);64}65__DEVICE__ int fpclassify(double __x) {66return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL,67FP_ZERO, __x);68}69__DEVICE__ float frexp(float __arg, int *__exp) {70return ::frexpf(__arg, __exp);71}72__DEVICE__ bool isinf(float __x) { return ::__isinff(__x); }73__DEVICE__ bool isinf(double __x) { return ::__isinf(__x); }74__DEVICE__ bool isfinite(float __x) { return ::__finitef(__x); }75__DEVICE__ bool isfinite(double __x) { return ::__finite(__x); }76__DEVICE__ bool isgreater(float __x, float __y) {77return __builtin_isgreater(__x, __y);78}79__DEVICE__ bool isgreater(double __x, double __y) {80return __builtin_isgreater(__x, __y);81}82__DEVICE__ bool isgreaterequal(float __x, float __y) {83return __builtin_isgreaterequal(__x, __y);84}85__DEVICE__ bool isgreaterequal(double __x, double __y) {86return __builtin_isgreaterequal(__x, __y);87}88__DEVICE__ bool isless(float __x, float __y) {89return __builtin_isless(__x, __y);90}91__DEVICE__ bool isless(double __x, double __y) {92return __builtin_isless(__x, __y);93}94__DEVICE__ bool islessequal(float __x, float __y) {95return __builtin_islessequal(__x, __y);96}97__DEVICE__ bool islessequal(double __x, double __y) {98return __builtin_islessequal(__x, __y);99}100__DEVICE__ bool islessgreater(float __x, float __y) {101return __builtin_islessgreater(__x, __y);102}103__DEVICE__ bool islessgreater(double __x, double __y) {104return __builtin_islessgreater(__x, __y);105}106__DEVICE__ bool isnan(float __x) { return ::__isnanf(__x); }107__DEVICE__ bool isnan(double __x) { return ::__isnan(__x); }108__DEVICE__ bool isnormal(float __x) { return __builtin_isnormal(__x); }109__DEVICE__ bool isnormal(double __x) { return __builtin_isnormal(__x); }110__DEVICE__ bool isunordered(float __x, float __y) {111return __builtin_isunordered(__x, __y);112}113__DEVICE__ bool isunordered(double __x, double __y) {114return __builtin_isunordered(__x, __y);115}116__DEVICE__ float ldexp(float __arg, int __exp) {117return ::ldexpf(__arg, __exp);118}119__DEVICE__ float log(float __x) { return ::logf(__x); }120__DEVICE__ float log10(float __x) { return ::log10f(__x); }121__DEVICE__ float modf(float __x, float *__iptr) { return ::modff(__x, __iptr); }122__DEVICE__ float nexttoward(float __from, float __to) {123return __builtin_nexttowardf(__from, __to);124}125__DEVICE__ double nexttoward(double __from, double __to) {126return __builtin_nexttoward(__from, __to);127}128__DEVICE__ float pow(float __base, float __exp) {129return ::powf(__base, __exp);130}131__DEVICE__ float pow(float __base, int __iexp) {132return ::powif(__base, __iexp);133}134__DEVICE__ double pow(double __base, int __iexp) {135return ::powi(__base, __iexp);136}137__DEVICE__ bool signbit(float __x) { return ::__signbitf(__x); }138__DEVICE__ bool signbit(double __x) { return ::__signbit(__x); }139__DEVICE__ float sin(float __x) { return ::sinf(__x); }140__DEVICE__ float sinh(float __x) { return ::sinhf(__x); }141__DEVICE__ float sqrt(float __x) { return ::sqrtf(__x); }142__DEVICE__ float tan(float __x) { return ::tanf(__x); }143__DEVICE__ float tanh(float __x) { return ::tanhf(__x); }144145#undef __DEVICE__146147#endif148149150