Home | History | Annotate | Download | only in cpu_ref
      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 
     21 typedef unsigned int uint32_t;
     22 typedef int int32_t;
     23 
     24 extern uint32_t SC_abs_i32(int32_t v);
     25 uint32_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 
     35 IMPORT_F32_FN_F32(acos)
     36 IMPORT_F32_FN_F32(acosh)
     37 IMPORT_F32_FN_F32(asin)
     38 IMPORT_F32_FN_F32(asinh)
     39 IMPORT_F32_FN_F32(atan)
     40 IMPORT_F32_FN_F32_F32(atan2)
     41 IMPORT_F32_FN_F32(atanh)
     42 IMPORT_F32_FN_F32(cbrt)
     43 IMPORT_F32_FN_F32(ceil)
     44 IMPORT_F32_FN_F32_F32(copysign)
     45 IMPORT_F32_FN_F32(cos)
     46 IMPORT_F32_FN_F32(cosh)
     47 IMPORT_F32_FN_F32(erfc)
     48 IMPORT_F32_FN_F32(erf)
     49 IMPORT_F32_FN_F32(exp)
     50 IMPORT_F32_FN_F32(exp2)
     51 IMPORT_F32_FN_F32(expm1)
     52 IMPORT_F32_FN_F32_F32(fdim)
     53 IMPORT_F32_FN_F32(floor)
     54 extern float SC_fmaf(float u, float t, float v);
     55 float __attribute__((overloadable)) fma(float u, float t, float v) {return SC_fmaf(u, t, v);}
     56 IMPORT_F32_FN_F32_F32(fmax)
     57 IMPORT_F32_FN_F32_F32(fmin)
     58 IMPORT_F32_FN_F32_F32(fmod)
     59 extern float SC_frexpf(float v, int* ptr);
     60 float __attribute__((overloadable)) frexp(float v, int* ptr) {return SC_frexpf(v, ptr);}
     61 IMPORT_F32_FN_F32_F32(hypot)
     62 IMPORT_F32_FN_F32(ilogb)
     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 
     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.
    102 extern "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.
    106 extern "C" int __aeabi_idiv0(int v) { return v; }
    107 
    108 #endif // compatibility lib
    109