rsCpuRuntimeMathFuncs.cpp revision b93cb42b4b8511d244ec8df4559fdc5c0b2de1bf
1/* 2 * Copyright (C) 2011-2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17// exports unavailable mathlib functions to compat lib 18 19#ifdef RS_COMPATIBILITY_LIB 20 21typedef unsigned int uint32_t; 22typedef int int32_t; 23 24extern uint32_t SC_abs_i32(int32_t v); 25uint32_t __attribute__((overloadable)) abs(int32_t v) {return SC_abs_i32(v);} 26 27#define IMPORT_F32_FN_F32(func) \ 28 extern float SC_##func##f(float v); \ 29 float __attribute__((overloadable)) func(float v) {return SC_##func##f(v);} 30 31#define IMPORT_F32_FN_F32_F32(func) \ 32 extern float SC_##func##f(float t, float v); \ 33 float __attribute__((overloadable)) func(float t, float v) {return SC_##func##f(t, v);} 34 35IMPORT_F32_FN_F32(acos) 36IMPORT_F32_FN_F32(acosh) 37IMPORT_F32_FN_F32(asin) 38IMPORT_F32_FN_F32(asinh) 39IMPORT_F32_FN_F32(atan) 40IMPORT_F32_FN_F32_F32(atan2) 41IMPORT_F32_FN_F32(atanh) 42IMPORT_F32_FN_F32(cbrt) 43IMPORT_F32_FN_F32(ceil) 44IMPORT_F32_FN_F32_F32(copysign) 45IMPORT_F32_FN_F32(cos) 46IMPORT_F32_FN_F32(cosh) 47IMPORT_F32_FN_F32(erfc) 48IMPORT_F32_FN_F32(erf) 49IMPORT_F32_FN_F32(exp) 50IMPORT_F32_FN_F32(exp2) 51IMPORT_F32_FN_F32(expm1) 52IMPORT_F32_FN_F32_F32(fdim) 53IMPORT_F32_FN_F32(floor) 54extern float SC_fmaf(float u, float t, float v); 55float __attribute__((overloadable)) fma(float u, float t, float v) {return SC_fmaf(u, t, v);} 56IMPORT_F32_FN_F32_F32(fmax) 57IMPORT_F32_FN_F32_F32(fmin) 58IMPORT_F32_FN_F32_F32(fmod) 59extern float SC_frexpf(float v, int* ptr); 60float __attribute__((overloadable)) frexp(float v, int* ptr) {return SC_frexpf(v, ptr);} 61IMPORT_F32_FN_F32_F32(hypot) 62IMPORT_F32_FN_F32(ilogb) 63extern float SC_ldexpf(float v, int i); 64float __attribute__((overloadable)) ldexp(float v, int i) {return SC_ldexpf(v, i);} 65IMPORT_F32_FN_F32(lgamma) 66extern float SC_lgammaf_r(float v, int* ptr); 67float __attribute__((overloadable)) lgamma(float v, int* ptr) {return SC_lgammaf_r(v, ptr);} 68IMPORT_F32_FN_F32(log) 69IMPORT_F32_FN_F32(log10) 70IMPORT_F32_FN_F32(log1p) 71IMPORT_F32_FN_F32(logb) 72extern float SC_modff(float v, float* ptr); 73float modf(float v, float* ptr) {return SC_modff(v, ptr);} 74IMPORT_F32_FN_F32_F32(nextafter) 75IMPORT_F32_FN_F32_F32(pow) 76IMPORT_F32_FN_F32_F32(remainder) 77extern float SC_remquof(float t, float v, int* ptr); 78float remquo(float t, float v, int* ptr) {return SC_remquof(t, v, ptr);} 79IMPORT_F32_FN_F32(rint) 80IMPORT_F32_FN_F32(round) 81IMPORT_F32_FN_F32(sin) 82IMPORT_F32_FN_F32(sinh) 83IMPORT_F32_FN_F32(sqrt) 84IMPORT_F32_FN_F32(tan) 85IMPORT_F32_FN_F32(tanh) 86IMPORT_F32_FN_F32(tgamma) 87IMPORT_F32_FN_F32(trunc) 88 89extern float SC_randf2(float min, float max); 90float __attribute__((overloadable)) rsRand(float min, float max) { 91 return SC_randf2(min, max); 92} 93 94 95// !!! DANGER !!! 96// These functions are potentially missing on older Android versions. 97// Work around the issue by supplying our own variants. 98// !!! DANGER !!! 99 100// The logbl() implementation is taken from the latest bionic/, since 101// double == long double on Android. 102extern "C" long double logbl(long double x) { return logb(x); } 103 104// __aeabi_idiv0 is a missing function in libcompiler_rt.so, so we just 105// pick the simplest implementation based on the ARM EABI doc. 106extern "C" int __aeabi_idiv0(int v) { return v; } 107 108#endif // compatibility lib 109