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 20 typedef unsigned int uint32_t; 21 typedef int int32_t; 22 23 extern uint32_t SC_abs_i32(int32_t v); 24 uint32_t __attribute__((overloadable)) abs(int32_t v) {return SC_abs_i32(v);} 25 26 #define IMPORT_F32_FN_F32(func) \ 27 extern float SC_##func##f(float v); \ 28 float __attribute__((overloadable)) func(float v) {return SC_##func##f(v);} 29 30 #define IMPORT_F32_FN_F32_F32(func) \ 31 extern float SC_##func##f(float t, float v); \ 32 float __attribute__((overloadable)) func(float t, float v) {return SC_##func##f(t, v);} 33 34 IMPORT_F32_FN_F32(acos) 35 IMPORT_F32_FN_F32(acosh) 36 IMPORT_F32_FN_F32(asin) 37 IMPORT_F32_FN_F32(asinh) 38 IMPORT_F32_FN_F32(atan) 39 IMPORT_F32_FN_F32_F32(atan2) 40 IMPORT_F32_FN_F32(atanh) 41 IMPORT_F32_FN_F32(cbrt) 42 IMPORT_F32_FN_F32(ceil) 43 IMPORT_F32_FN_F32_F32(copysign) 44 IMPORT_F32_FN_F32(cos) 45 IMPORT_F32_FN_F32(cosh) 46 IMPORT_F32_FN_F32(erfc) 47 IMPORT_F32_FN_F32(erf) 48 IMPORT_F32_FN_F32(exp) 49 IMPORT_F32_FN_F32(exp2) 50 IMPORT_F32_FN_F32(expm1) 51 IMPORT_F32_FN_F32_F32(fdim) 52 IMPORT_F32_FN_F32(floor) 53 extern float SC_fmaf(float u, float t, float v); 54 float __attribute__((overloadable)) fma(float u, float t, float v) {return SC_fmaf(u, t, v);} 55 IMPORT_F32_FN_F32_F32(fmax) 56 IMPORT_F32_FN_F32_F32(fmin) 57 IMPORT_F32_FN_F32_F32(fmod) 58 extern float SC_frexpf(float v, int* ptr); 59 float __attribute__((overloadable)) frexp(float v, int* ptr) {return SC_frexpf(v, ptr);} 60 IMPORT_F32_FN_F32_F32(hypot) 61 extern int SC_ilogbf(float v); 62 int __attribute__((overloadable)) ilogb(float v) {return SC_ilogbf(v); } 63 extern float SC_ldexpf(float v, int i); 64 float __attribute__((overloadable)) ldexp(float v, int i) {return SC_ldexpf(v, i);} 65 IMPORT_F32_FN_F32(lgamma) 66 extern float SC_lgammaf_r(float v, int* ptr); 67 float __attribute__((overloadable)) lgamma(float v, int* ptr) {return SC_lgammaf_r(v, ptr);} 68 IMPORT_F32_FN_F32(log) 69 IMPORT_F32_FN_F32(log10) 70 IMPORT_F32_FN_F32(log1p) 71 IMPORT_F32_FN_F32(logb) 72 extern float SC_modff(float v, float* ptr); 73 float modf(float v, float* ptr) {return SC_modff(v, ptr);} 74 IMPORT_F32_FN_F32_F32(nextafter) 75 IMPORT_F32_FN_F32_F32(pow) 76 IMPORT_F32_FN_F32_F32(remainder) 77 extern float SC_remquof(float t, float v, int* ptr); 78 float remquo(float t, float v, int* ptr) {return SC_remquof(t, v, ptr);} 79 IMPORT_F32_FN_F32(rint) 80 IMPORT_F32_FN_F32(round) 81 IMPORT_F32_FN_F32(sin) 82 IMPORT_F32_FN_F32(sinh) 83 IMPORT_F32_FN_F32(sqrt) 84 IMPORT_F32_FN_F32(tan) 85 IMPORT_F32_FN_F32(tanh) 86 IMPORT_F32_FN_F32(tgamma) 87 IMPORT_F32_FN_F32(trunc) 88 89 extern float SC_randf2(float min, float max); 90 float __attribute__((overloadable)) rsRand(float min, float max) { 91 return SC_randf2(min, max); 92 } 93 94 #ifdef RS_COMPATIBILITY_LIB 95 96 // !!! DANGER !!! 97 // These functions are potentially missing on older Android versions. 98 // Work around the issue by supplying our own variants. 99 // !!! DANGER !!! 100 101 // The logbl() implementation is taken from the latest bionic/, since 102 // double == long double on Android. 103 extern "C" long double logbl(long double x) { return logb(x); } 104 105 // __aeabi_idiv0 is a missing function in libcompiler_rt.so, so we just 106 // pick the simplest implementation based on the ARM EABI doc. 107 extern "C" int __aeabi_idiv0(int v) { return v; } 108 109 #endif // compatibility lib 110