blob: 6a8f7b64c868edc216fd093716fcf04ee6d45bab [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
Stephen Hines43cfc0c2013-08-15 10:02:11 -070017#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
Glenn Kasten72f4f4c2011-12-15 09:51:17 -080018#include <cutils/compiler.h>
Tim Murray0b575de2013-03-15 15:56:43 -070019#endif
Glenn Kasten72f4f4c2011-12-15 09:51:17 -080020
Jason Sams87fe59a2011-04-20 15:09:01 -070021#include "rsContext.h"
22#include "rsScriptC.h"
23#include "rsMatrix4x4.h"
24#include "rsMatrix3x3.h"
25#include "rsMatrix2x2.h"
26
Jason Sams709a0972012-11-15 18:18:04 -080027#include "rsCpuCore.h"
28#include "rsCpuScript.h"
Jason Sams87fe59a2011-04-20 15:09:01 -070029
Chih-Hung Hsieh462de212016-11-16 11:33:57 -080030using android::renderscript::Matrix2x2;
31using android::renderscript::Matrix3x3;
32using android::renderscript::Matrix4x4;
Jason Sams87fe59a2011-04-20 15:09:01 -070033
Tim Murrayd6f1f462013-03-25 16:36:59 -070034#define EXPORT_F32_FN_F32(func) \
35 float __attribute__((overloadable)) SC_##func(float v) { \
36 return func(v); \
37 }
38
39#define EXPORT_F32_FN_F32_F32(func) \
40 float __attribute__((overloadable)) SC_##func(float t, float v) { \
41 return func(t, v); \
42 }
Jason Sams87fe59a2011-04-20 15:09:01 -070043
Jason Sams87fe59a2011-04-20 15:09:01 -070044//////////////////////////////////////////////////////////////////////////////
45// Float util
46//////////////////////////////////////////////////////////////////////////////
47
Tim Murrayd6f1f462013-03-25 16:36:59 -070048// Handle missing Gingerbread functions like tgammaf.
49float SC_tgammaf(float x) {
Stephen Hines11418c82013-08-14 16:46:21 -070050#ifdef RS_COMPATIBILITY_LIB
Dan Albertb4fc3952016-08-11 11:50:12 -070051 return __builtin_tgamma(x);
Stephen Hines11418c82013-08-14 16:46:21 -070052#else
53 return tgammaf(x);
54#endif
Tim Murrayd6f1f462013-03-25 16:36:59 -070055}
56
57uint32_t SC_abs_i32(int32_t v) {return abs(v);}
Jason Sams87fe59a2011-04-20 15:09:01 -070058
59static void SC_MatrixLoadRotate(Matrix4x4 *m, float rot, float x, float y, float z) {
60 m->loadRotate(rot, x, y, z);
61}
62static void SC_MatrixLoadScale(Matrix4x4 *m, float x, float y, float z) {
63 m->loadScale(x, y, z);
64}
65static void SC_MatrixLoadTranslate(Matrix4x4 *m, float x, float y, float z) {
66 m->loadTranslate(x, y, z);
67}
68static void SC_MatrixRotate(Matrix4x4 *m, float rot, float x, float y, float z) {
69 m->rotate(rot, x, y, z);
70}
71static void SC_MatrixScale(Matrix4x4 *m, float x, float y, float z) {
72 m->scale(x, y, z);
73}
74static void SC_MatrixTranslate(Matrix4x4 *m, float x, float y, float z) {
75 m->translate(x, y, z);
76}
77
Jason Sams87fe59a2011-04-20 15:09:01 -070078static void SC_MatrixLoadOrtho(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) {
79 m->loadOrtho(l, r, b, t, n, f);
80}
81static void SC_MatrixLoadFrustum(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) {
82 m->loadFrustum(l, r, b, t, n, f);
83}
84static void SC_MatrixLoadPerspective(Matrix4x4 *m, float fovy, float aspect, float near, float far) {
85 m->loadPerspective(fovy, aspect, near, far);
86}
87
88static bool SC_MatrixInverse_4x4(Matrix4x4 *m) {
89 return m->inverse();
90}
91static bool SC_MatrixInverseTranspose_4x4(Matrix4x4 *m) {
92 return m->inverseTranspose();
93}
94static void SC_MatrixTranspose_4x4(Matrix4x4 *m) {
95 m->transpose();
96}
97static void SC_MatrixTranspose_3x3(Matrix3x3 *m) {
98 m->transpose();
99}
100static void SC_MatrixTranspose_2x2(Matrix2x2 *m) {
101 m->transpose();
102}
103
Stephen Hinesb93cb422013-03-27 17:32:31 -0700104float SC_randf2(float min, float max) {
Jason Sams87fe59a2011-04-20 15:09:01 -0700105 float r = (float)rand();
Jason Samsb8fa7562011-04-22 14:19:42 -0700106 r /= RAND_MAX;
Jason Sams87fe59a2011-04-20 15:09:01 -0700107 r = r * (max - min) + min;
Jason Samsb8fa7562011-04-22 14:19:42 -0700108 return r;
Jason Sams87fe59a2011-04-20 15:09:01 -0700109}
110
Tim Murrayd6f1f462013-03-25 16:36:59 -0700111EXPORT_F32_FN_F32(acosf)
112EXPORT_F32_FN_F32(acoshf)
113EXPORT_F32_FN_F32(asinf)
114EXPORT_F32_FN_F32(asinhf)
115EXPORT_F32_FN_F32(atanf)
116EXPORT_F32_FN_F32_F32(atan2f)
117EXPORT_F32_FN_F32(atanhf)
118EXPORT_F32_FN_F32(cbrtf)
119EXPORT_F32_FN_F32(ceilf)
120EXPORT_F32_FN_F32_F32(copysignf)
121EXPORT_F32_FN_F32(cosf)
122EXPORT_F32_FN_F32(coshf)
123EXPORT_F32_FN_F32(erfcf)
124EXPORT_F32_FN_F32(erff)
125EXPORT_F32_FN_F32(expf)
126EXPORT_F32_FN_F32(exp2f)
127EXPORT_F32_FN_F32(expm1f)
128EXPORT_F32_FN_F32_F32(fdimf)
129EXPORT_F32_FN_F32(floorf)
130float SC_fmaf(float u, float t, float v) {return fmaf(u, t, v);}
131EXPORT_F32_FN_F32_F32(fmaxf)
132EXPORT_F32_FN_F32_F32(fminf)
133EXPORT_F32_FN_F32_F32(fmodf)
134float SC_frexpf(float v, int* ptr) {return frexpf(v, ptr);}
135EXPORT_F32_FN_F32_F32(hypotf)
Pirama Arumuga Nainar6fdd0602015-01-13 11:21:13 -0800136int SC_ilogbf(float v) {return ilogbf(v); }
Tim Murrayd6f1f462013-03-25 16:36:59 -0700137float SC_ldexpf(float v, int i) {return ldexpf(v, i);}
138EXPORT_F32_FN_F32(lgammaf)
139float SC_lgammaf_r(float v, int* ptr) {return lgammaf_r(v, ptr);}
140EXPORT_F32_FN_F32(logf)
141EXPORT_F32_FN_F32(log10f)
142EXPORT_F32_FN_F32(log1pf)
143EXPORT_F32_FN_F32(logbf)
144float SC_modff(float v, float* ptr) {return modff(v, ptr);}
145EXPORT_F32_FN_F32_F32(nextafterf)
146EXPORT_F32_FN_F32_F32(powf)
147EXPORT_F32_FN_F32_F32(remainderf)
148float SC_remquof(float t, float v, int* ptr) {return remquof(t, v, ptr);}
149EXPORT_F32_FN_F32(rintf)
150EXPORT_F32_FN_F32(roundf)
151EXPORT_F32_FN_F32(sinf)
152EXPORT_F32_FN_F32(sinhf)
153EXPORT_F32_FN_F32(sqrtf)
154EXPORT_F32_FN_F32(tanf)
155EXPORT_F32_FN_F32(tanhf)
156EXPORT_F32_FN_F32(truncf)
Stephen Hinescadee382013-12-12 13:21:00 -0800157void __attribute__((overloadable)) rsMatrixLoadRotate(rs_matrix4x4 *m,
158 float rot, float x, float y, float z) {
159 SC_MatrixLoadRotate((Matrix4x4 *) m, rot, x, y, z);
160}
161void __attribute__((overloadable)) rsMatrixLoadScale(rs_matrix4x4 *m,
162 float x, float y, float z) {
163 SC_MatrixLoadScale((Matrix4x4 *) m, x, y, z);
164}
165void __attribute__((overloadable)) rsMatrixLoadTranslate(rs_matrix4x4 *m,
166 float x, float y, float z) {
167 SC_MatrixLoadTranslate((Matrix4x4 *) m, x, y, z);
168}
169void __attribute__((overloadable)) rsMatrixRotate(rs_matrix4x4 *m, float rot,
170 float x, float y, float z) {
171 SC_MatrixRotate((Matrix4x4 *) m, rot, x, y, z);
172}
173void __attribute__((overloadable)) rsMatrixScale(rs_matrix4x4 *m, float x,
174 float y, float z) {
175 SC_MatrixScale((Matrix4x4 *) m, x, y, z);
176}
177void __attribute__((overloadable)) rsMatrixTranslate(rs_matrix4x4 *m, float x,
178 float y, float z) {
179 SC_MatrixTranslate((Matrix4x4 *) m, x, y, z);
180}
181void __attribute__((overloadable)) rsMatrixLoadOrtho(rs_matrix4x4 *m, float l,
182 float r, float b, float t, float n, float f) {
183 SC_MatrixLoadOrtho((Matrix4x4 *) m, l, r, b, t, n, f);
184}
185void __attribute__((overloadable)) rsMatrixLoadFrustum(rs_matrix4x4 *m,
186 float l, float r, float b, float t, float n, float f) {
187 SC_MatrixLoadFrustum((Matrix4x4 *) m, l, r, b, t, n, f);
188}
189void __attribute__((overloadable)) rsMatrixLoadPerspective(rs_matrix4x4 *m,
190 float fovy, float aspect, float near, float far) {
191 SC_MatrixLoadPerspective((Matrix4x4 *) m, fovy, aspect, near, far);
192}
193bool __attribute__((overloadable)) rsMatrixInverse(rs_matrix4x4 *m) {
194 return SC_MatrixInverse_4x4((Matrix4x4 *) m);
195}
196bool __attribute__((overloadable)) rsMatrixInverseTranspose(rs_matrix4x4 *m) {
197 return SC_MatrixInverseTranspose_4x4((Matrix4x4 *) m);
198}
199void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix4x4 *m) {
200 SC_MatrixTranspose_4x4((Matrix4x4 *) m);
201}
202void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix3x3 *m) {
203 SC_MatrixTranspose_3x3((Matrix3x3 *) m);
204}
205void __attribute__((overloadable)) rsMatrixTranspose(rs_matrix2x2 *m) {
206 SC_MatrixTranspose_2x2((Matrix2x2 *) m);
207}
Jason Sams87fe59a2011-04-20 15:09:01 -0700208
Jason Sams87fe59a2011-04-20 15:09:01 -0700209