blob: 29ea658098e908f761d34008f69d251ecc532fc7 [file] [log] [blame]
Jason Sams87fe59a2011-04-20 15:09:01 -07001/*
Jason Sams709a0972012-11-15 18:18:04 -08002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Sams87fe59a2011-04-20 15:09:01 -07003 *
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#include "rsContext.h"
18#include "rsScriptC.h"
19#include "rsMatrix4x4.h"
20#include "rsMatrix3x3.h"
21#include "rsMatrix2x2.h"
22
Jason Sams709a0972012-11-15 18:18:04 -080023#include "rsCpuCore.h"
24#include "rsCpuScript.h"
Jason Sams87fe59a2011-04-20 15:09:01 -070025
Chih-Hung Hsieh462de212016-11-16 11:33:57 -080026using android::renderscript::Matrix2x2;
27using android::renderscript::Matrix3x3;
28using android::renderscript::Matrix4x4;
Jason Sams87fe59a2011-04-20 15:09:01 -070029
Tim Murrayd6f1f462013-03-25 16:36:59 -070030#define EXPORT_F32_FN_F32(func) \
31 float __attribute__((overloadable)) SC_##func(float v) { \
32 return func(v); \
33 }
34
35#define EXPORT_F32_FN_F32_F32(func) \
36 float __attribute__((overloadable)) SC_##func(float t, float v) { \
37 return func(t, v); \
38 }
Jason Sams87fe59a2011-04-20 15:09:01 -070039
Jason Sams87fe59a2011-04-20 15:09:01 -070040//////////////////////////////////////////////////////////////////////////////
41// Float util
42//////////////////////////////////////////////////////////////////////////////
43
Tim Murrayd6f1f462013-03-25 16:36:59 -070044// Handle missing Gingerbread functions like tgammaf.
45float SC_tgammaf(float x) {
Stephen Hines11418c82013-08-14 16:46:21 -070046#ifdef RS_COMPATIBILITY_LIB
Dan Albertb4fc3952016-08-11 11:50:12 -070047 return __builtin_tgamma(x);
Stephen Hines11418c82013-08-14 16:46:21 -070048#else
49 return tgammaf(x);
50#endif
Tim Murrayd6f1f462013-03-25 16:36:59 -070051}
52
53uint32_t SC_abs_i32(int32_t v) {return abs(v);}
Jason Sams87fe59a2011-04-20 15:09:01 -070054
55static void SC_MatrixLoadRotate(Matrix4x4 *m, float rot, float x, float y, float z) {
56 m->loadRotate(rot, x, y, z);
57}
58static void SC_MatrixLoadScale(Matrix4x4 *m, float x, float y, float z) {
59 m->loadScale(x, y, z);
60}
61static void SC_MatrixLoadTranslate(Matrix4x4 *m, float x, float y, float z) {
62 m->loadTranslate(x, y, z);
63}
64static void SC_MatrixRotate(Matrix4x4 *m, float rot, float x, float y, float z) {
65 m->rotate(rot, x, y, z);
66}
67static void SC_MatrixScale(Matrix4x4 *m, float x, float y, float z) {
68 m->scale(x, y, z);
69}
70static void SC_MatrixTranslate(Matrix4x4 *m, float x, float y, float z) {
71 m->translate(x, y, z);
72}
73
Jason Sams87fe59a2011-04-20 15:09:01 -070074static void SC_MatrixLoadOrtho(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) {
75 m->loadOrtho(l, r, b, t, n, f);
76}
77static void SC_MatrixLoadFrustum(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) {
78 m->loadFrustum(l, r, b, t, n, f);
79}
80static void SC_MatrixLoadPerspective(Matrix4x4 *m, float fovy, float aspect, float near, float far) {
81 m->loadPerspective(fovy, aspect, near, far);
82}
83
84static bool SC_MatrixInverse_4x4(Matrix4x4 *m) {
85 return m->inverse();
86}
87static bool SC_MatrixInverseTranspose_4x4(Matrix4x4 *m) {
88 return m->inverseTranspose();
89}
90static void SC_MatrixTranspose_4x4(Matrix4x4 *m) {
91 m->transpose();
92}
93static void SC_MatrixTranspose_3x3(Matrix3x3 *m) {
94 m->transpose();
95}
96static void SC_MatrixTranspose_2x2(Matrix2x2 *m) {
97 m->transpose();
98}
99
Stephen Hinesb93cb422013-03-27 17:32:31 -0700100float SC_randf2(float min, float max) {
Jason Sams87fe59a2011-04-20 15:09:01 -0700101 float r = (float)rand();
Jason Samsb8fa7562011-04-22 14:19:42 -0700102 r /= RAND_MAX;
Jason Sams87fe59a2011-04-20 15:09:01 -0700103 r = r * (max - min) + min;
Jason Samsb8fa7562011-04-22 14:19:42 -0700104 return r;
Jason Sams87fe59a2011-04-20 15:09:01 -0700105}
106
Tim Murrayd6f1f462013-03-25 16:36:59 -0700107EXPORT_F32_FN_F32(acosf)
108EXPORT_F32_FN_F32(acoshf)
109EXPORT_F32_FN_F32(asinf)
110EXPORT_F32_FN_F32(asinhf)
111EXPORT_F32_FN_F32(atanf)
112EXPORT_F32_FN_F32_F32(atan2f)
113EXPORT_F32_FN_F32(atanhf)
114EXPORT_F32_FN_F32(cbrtf)
115EXPORT_F32_FN_F32(ceilf)
116EXPORT_F32_FN_F32_F32(copysignf)
117EXPORT_F32_FN_F32(cosf)
118EXPORT_F32_FN_F32(coshf)
119EXPORT_F32_FN_F32(erfcf)
120EXPORT_F32_FN_F32(erff)
121EXPORT_F32_FN_F32(expf)
122EXPORT_F32_FN_F32(exp2f)
123EXPORT_F32_FN_F32(expm1f)
124EXPORT_F32_FN_F32_F32(fdimf)
125EXPORT_F32_FN_F32(floorf)
126float SC_fmaf(float u, float t, float v) {return fmaf(u, t, v);}
127EXPORT_F32_FN_F32_F32(fmaxf)
128EXPORT_F32_FN_F32_F32(fminf)
129EXPORT_F32_FN_F32_F32(fmodf)
130float SC_frexpf(float v, int* ptr) {return frexpf(v, ptr);}
131EXPORT_F32_FN_F32_F32(hypotf)
Pirama Arumuga Nainar6fdd0602015-01-13 11:21:13 -0800132int SC_ilogbf(float v) {return ilogbf(v); }
Tim Murrayd6f1f462013-03-25 16:36:59 -0700133float SC_ldexpf(float v, int i) {return ldexpf(v, i);}
134EXPORT_F32_FN_F32(lgammaf)
135float SC_lgammaf_r(float v, int* ptr) {return lgammaf_r(v, ptr);}
136EXPORT_F32_FN_F32(logf)
137EXPORT_F32_FN_F32(log10f)
138EXPORT_F32_FN_F32(log1pf)
139EXPORT_F32_FN_F32(logbf)
140float SC_modff(float v, float* ptr) {return modff(v, ptr);}
141EXPORT_F32_FN_F32_F32(nextafterf)
142EXPORT_F32_FN_F32_F32(powf)
143EXPORT_F32_FN_F32_F32(remainderf)
144float SC_remquof(float t, float v, int* ptr) {return remquof(t, v, ptr);}
145EXPORT_F32_FN_F32(rintf)
146EXPORT_F32_FN_F32(roundf)
147EXPORT_F32_FN_F32(sinf)
148EXPORT_F32_FN_F32(sinhf)
149EXPORT_F32_FN_F32(sqrtf)
150EXPORT_F32_FN_F32(tanf)
151EXPORT_F32_FN_F32(tanhf)
152EXPORT_F32_FN_F32(truncf)
Stephen Hinescadee382013-12-12 13:21:00 -0800153void __attribute__((overloadable)) rsMatrixLoadRotate(rs_matrix4x4 *m,
154 float rot, float x, float y, float z) {
155 SC_MatrixLoadRotate((Matrix4x4 *) m, rot, x, y, z);
156}
157void __attribute__((overloadable)) rsMatrixLoadScale(rs_matrix4x4 *m,
158 float x, float y, float z) {
159 SC_MatrixLoadScale((Matrix4x4 *) m, x, y, z);
160}
161void __attribute__((overloadable)) rsMatrixLoadTranslate(rs_matrix4x4 *m,
162 float x, float y, float z) {
163 SC_MatrixLoadTranslate((Matrix4x4 *) m, x, y, z);
164}
165void __attribute__((overloadable)) rsMatrixRotate(rs_matrix4x4 *m, float rot,
166 float x, float y, float z) {
167 SC_MatrixRotate((Matrix4x4 *) m, rot, x, y, z);
168}
169void __attribute__((overloadable)) rsMatrixScale(rs_matrix4x4 *m, float x,
170 float y, float z) {
171 SC_MatrixScale((Matrix4x4 *) m, x, y, z);
172}
173void __attribute__((overloadable)) rsMatrixTranslate(rs_matrix4x4 *m, float x,
174 float y, float z) {
175 SC_MatrixTranslate((Matrix4x4 *) m, x, y, z);
176}
177void __attribute__((overloadable)) rsMatrixLoadOrtho(rs_matrix4x4 *m, float l,
178 float r, float b, float t, float n, float f) {
179 SC_MatrixLoadOrtho((Matrix4x4 *) m, l, r, b, t, n, f);
180}
181void __attribute__((overloadable)) rsMatrixLoadFrustum(rs_matrix4x4 *m,
182 float l, float r, float b, float t, float n, float f) {
183 SC_MatrixLoadFrustum((Matrix4x4 *) m, l, r, b, t, n, f);
184}
185void __attribute__((overloadable)) rsMatrixLoadPerspective(rs_matrix4x4 *m,
186 float fovy, float aspect, float near, float far) {
187 SC_MatrixLoadPerspective((Matrix4x4 *) m, fovy, aspect, near, far);
188}
189bool __attribute__((overloadable)) rsMatrixInverse(rs_matrix4x4 *m) {
190 return SC_MatrixInverse_4x4((Matrix4x4 *) m);
191}
192bool __attribute__((overloadable)) rsMatrixInverseTranspose(rs_matrix4x4 *m) {
193 return SC_MatrixInverseTranspose_4x4((Matrix4x4 *) m);
194}
195void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix4x4 *m) {
196 SC_MatrixTranspose_4x4((Matrix4x4 *) m);
197}
198void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix3x3 *m) {
199 SC_MatrixTranspose_3x3((Matrix3x3 *) m);
200}
201void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix2x2 *m) {
202 SC_MatrixTranspose_2x2((Matrix2x2 *) m);
203}
Jason Sams87fe59a2011-04-20 15:09:01 -0700204
Jason Sams87fe59a2011-04-20 15:09:01 -0700205