blob: 0a169359186342f7aeed695adfdb319c495bdfb8 [file] [log] [blame]
Tim Murrayd6f1f462013-03-25 16:36:59 -07001/*
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
Tim Murrayd6f1f462013-03-25 16:36:59 -070019
20typedef unsigned int uint32_t;
21typedef int int32_t;
22
23extern uint32_t SC_abs_i32(int32_t v);
24uint32_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
34IMPORT_F32_FN_F32(acos)
35IMPORT_F32_FN_F32(acosh)
36IMPORT_F32_FN_F32(asin)
37IMPORT_F32_FN_F32(asinh)
38IMPORT_F32_FN_F32(atan)
39IMPORT_F32_FN_F32_F32(atan2)
40IMPORT_F32_FN_F32(atanh)
41IMPORT_F32_FN_F32(cbrt)
42IMPORT_F32_FN_F32(ceil)
43IMPORT_F32_FN_F32_F32(copysign)
44IMPORT_F32_FN_F32(cos)
45IMPORT_F32_FN_F32(cosh)
46IMPORT_F32_FN_F32(erfc)
47IMPORT_F32_FN_F32(erf)
48IMPORT_F32_FN_F32(exp)
49IMPORT_F32_FN_F32(exp2)
50IMPORT_F32_FN_F32(expm1)
51IMPORT_F32_FN_F32_F32(fdim)
52IMPORT_F32_FN_F32(floor)
53extern float SC_fmaf(float u, float t, float v);
54float __attribute__((overloadable)) fma(float u, float t, float v) {return SC_fmaf(u, t, v);}
55IMPORT_F32_FN_F32_F32(fmax)
56IMPORT_F32_FN_F32_F32(fmin)
57IMPORT_F32_FN_F32_F32(fmod)
58extern float SC_frexpf(float v, int* ptr);
59float __attribute__((overloadable)) frexp(float v, int* ptr) {return SC_frexpf(v, ptr);}
60IMPORT_F32_FN_F32_F32(hypot)
Pirama Arumuga Nainar6fdd0602015-01-13 11:21:13 -080061extern int SC_ilogbf(float v);
62int __attribute__((overloadable)) ilogb(float v) {return SC_ilogbf(v); }
Tim Murrayd6f1f462013-03-25 16:36:59 -070063extern 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
Stephen Hinesb93cb422013-03-27 17:32:31 -070089extern float SC_randf2(float min, float max);
90float __attribute__((overloadable)) rsRand(float min, float max) {
91 return SC_randf2(min, max);
92}
93
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -080094#ifdef RS_COMPATIBILITY_LIB
Stephen Hinesb93cb422013-03-27 17:32:31 -070095
Tim Murrayd6f1f462013-03-25 16:36:59 -070096// !!! 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.
103extern "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.
107extern "C" int __aeabi_idiv0(int v) { return v; }
108
109#endif // compatibility lib