• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 #include <cutils/compiler.h>
18 
19 #include "rsContext.h"
20 #include "rsScriptC.h"
21 #include "rsMatrix4x4.h"
22 #include "rsMatrix3x3.h"
23 #include "rsMatrix2x2.h"
24 
25 #include "rsdCore.h"
26 #include "rsdRuntime.h"
27 
28 
29 using namespace android;
30 using namespace android::renderscript;
31 
32 
SC_exp10(float v)33 static float SC_exp10(float v) {
34     return pow(10.f, v);
35 }
36 
SC_fract(float v,int * iptr)37 static float SC_fract(float v, int *iptr) {
38     int i = (int)floor(v);
39     iptr[0] = i;
40     return fmin(v - i, 0x1.fffffep-1f);
41 }
42 
SC_log2(float v)43 static float SC_log2(float v) {
44     return log10(v) / log10(2.f);
45 }
46 
SC_mad(float v1,float v2,float v3)47 static float SC_mad(float v1, float v2, float v3) {
48     return v1 * v2 + v3;
49 }
50 
51 #if 0
52 static float SC_pown(float v, int p) {
53     return powf(v, (float)p);
54 }
55 
56 static float SC_powr(float v, float p) {
57     return powf(v, p);
58 }
59 #endif
60 
SC_rootn(float v,int r)61 float SC_rootn(float v, int r) {
62     return pow(v, 1.f / r);
63 }
64 
SC_rsqrt(float v)65 float SC_rsqrt(float v) {
66     return 1.f / sqrtf(v);
67 }
68 
SC_sincos(float v,float * cosptr)69 float SC_sincos(float v, float *cosptr) {
70     *cosptr = cosf(v);
71     return sinf(v);
72 }
73 
74 //////////////////////////////////////////////////////////////////////////////
75 // Integer
76 //////////////////////////////////////////////////////////////////////////////
77 
78 
SC_abs_i32(int32_t v)79 static uint32_t SC_abs_i32(int32_t v) {return abs(v);}
SC_abs_i16(int16_t v)80 static uint16_t SC_abs_i16(int16_t v) {return (uint16_t)abs(v);}
SC_abs_i8(int8_t v)81 static uint8_t SC_abs_i8(int8_t v) {return (uint8_t)abs(v);}
82 
SC_clz_u32(uint32_t v)83 static uint32_t SC_clz_u32(uint32_t v) {return __builtin_clz(v);}
SC_clz_u16(uint16_t v)84 static uint16_t SC_clz_u16(uint16_t v) {return (uint16_t)__builtin_clz(v);}
SC_clz_u8(uint8_t v)85 static uint8_t SC_clz_u8(uint8_t v) {return (uint8_t)__builtin_clz(v);}
SC_clz_i32(int32_t v)86 static int32_t SC_clz_i32(int32_t v) {return (int32_t)__builtin_clz((uint32_t)v);}
SC_clz_i16(int16_t v)87 static int16_t SC_clz_i16(int16_t v) {return (int16_t)__builtin_clz(v);}
SC_clz_i8(int8_t v)88 static int8_t SC_clz_i8(int8_t v) {return (int8_t)__builtin_clz(v);}
89 
SC_max_u32(uint32_t v,uint32_t v2)90 static uint32_t SC_max_u32(uint32_t v, uint32_t v2) {return rsMax(v, v2);}
SC_max_u16(uint16_t v,uint16_t v2)91 static uint16_t SC_max_u16(uint16_t v, uint16_t v2) {return rsMax(v, v2);}
SC_max_u8(uint8_t v,uint8_t v2)92 static uint8_t SC_max_u8(uint8_t v, uint8_t v2) {return rsMax(v, v2);}
SC_max_i32(int32_t v,int32_t v2)93 static int32_t SC_max_i32(int32_t v, int32_t v2) {return rsMax(v, v2);}
SC_max_i16(int16_t v,int16_t v2)94 static int16_t SC_max_i16(int16_t v, int16_t v2) {return rsMax(v, v2);}
SC_max_i8(int8_t v,int8_t v2)95 static int8_t SC_max_i8(int8_t v, int8_t v2) {return rsMax(v, v2);}
96 
SC_min_u32(uint32_t v,uint32_t v2)97 static uint32_t SC_min_u32(uint32_t v, uint32_t v2) {return rsMin(v, v2);}
SC_min_u16(uint16_t v,uint16_t v2)98 static uint16_t SC_min_u16(uint16_t v, uint16_t v2) {return rsMin(v, v2);}
SC_min_u8(uint8_t v,uint8_t v2)99 static uint8_t SC_min_u8(uint8_t v, uint8_t v2) {return rsMin(v, v2);}
SC_min_i32(int32_t v,int32_t v2)100 static int32_t SC_min_i32(int32_t v, int32_t v2) {return rsMin(v, v2);}
SC_min_i16(int16_t v,int16_t v2)101 static int16_t SC_min_i16(int16_t v, int16_t v2) {return rsMin(v, v2);}
SC_min_i8(int8_t v,int8_t v2)102 static int8_t SC_min_i8(int8_t v, int8_t v2) {return rsMin(v, v2);}
103 
104 //////////////////////////////////////////////////////////////////////////////
105 // Float util
106 //////////////////////////////////////////////////////////////////////////////
107 
SC_clamp_f32(float amount,float low,float high)108 static float SC_clamp_f32(float amount, float low, float high) {
109     return amount < low ? low : (amount > high ? high : amount);
110 }
111 
SC_degrees(float radians)112 static float SC_degrees(float radians) {
113     return radians * (180.f / M_PI);
114 }
115 
SC_max_f32(float v,float v2)116 static float SC_max_f32(float v, float v2) {
117     return rsMax(v, v2);
118 }
119 
SC_min_f32(float v,float v2)120 static float SC_min_f32(float v, float v2) {
121     return rsMin(v, v2);
122 }
123 
SC_mix_f32(float start,float stop,float amount)124 static float SC_mix_f32(float start, float stop, float amount) {
125     //ALOGE("lerpf %f  %f  %f", start, stop, amount);
126     return start + (stop - start) * amount;
127 }
128 
SC_radians(float degrees)129 static float SC_radians(float degrees) {
130     return degrees * (M_PI / 180.f);
131 }
132 
SC_step_f32(float edge,float v)133 static float SC_step_f32(float edge, float v) {
134     if (v < edge) return 0.f;
135     return 1.f;
136 }
137 
SC_sign_f32(float value)138 static float SC_sign_f32(float value) {
139     if (value > 0) return 1.f;
140     if (value < 0) return -1.f;
141     return value;
142 }
143 
SC_MatrixLoadIdentity_4x4(Matrix4x4 * m)144 static void SC_MatrixLoadIdentity_4x4(Matrix4x4 *m) {
145     m->loadIdentity();
146 }
SC_MatrixLoadIdentity_3x3(Matrix3x3 * m)147 static void SC_MatrixLoadIdentity_3x3(Matrix3x3 *m) {
148     m->loadIdentity();
149 }
SC_MatrixLoadIdentity_2x2(Matrix2x2 * m)150 static void SC_MatrixLoadIdentity_2x2(Matrix2x2 *m) {
151     m->loadIdentity();
152 }
153 
SC_MatrixLoad_4x4_f(Matrix4x4 * m,const float * f)154 static void SC_MatrixLoad_4x4_f(Matrix4x4 *m, const float *f) {
155     m->load(f);
156 }
SC_MatrixLoad_3x3_f(Matrix3x3 * m,const float * f)157 static void SC_MatrixLoad_3x3_f(Matrix3x3 *m, const float *f) {
158     m->load(f);
159 }
SC_MatrixLoad_2x2_f(Matrix2x2 * m,const float * f)160 static void SC_MatrixLoad_2x2_f(Matrix2x2 *m, const float *f) {
161     m->load(f);
162 }
163 
SC_MatrixLoad_4x4_4x4(Matrix4x4 * m,const Matrix4x4 * s)164 static void SC_MatrixLoad_4x4_4x4(Matrix4x4 *m, const Matrix4x4 *s) {
165     m->load(s);
166 }
SC_MatrixLoad_4x4_3x3(Matrix4x4 * m,const Matrix3x3 * s)167 static void SC_MatrixLoad_4x4_3x3(Matrix4x4 *m, const Matrix3x3 *s) {
168     m->load(s);
169 }
SC_MatrixLoad_4x4_2x2(Matrix4x4 * m,const Matrix2x2 * s)170 static void SC_MatrixLoad_4x4_2x2(Matrix4x4 *m, const Matrix2x2 *s) {
171     m->load(s);
172 }
SC_MatrixLoad_3x3_3x3(Matrix3x3 * m,const Matrix3x3 * s)173 static void SC_MatrixLoad_3x3_3x3(Matrix3x3 *m, const Matrix3x3 *s) {
174     m->load(s);
175 }
SC_MatrixLoad_2x2_2x2(Matrix2x2 * m,const Matrix2x2 * s)176 static void SC_MatrixLoad_2x2_2x2(Matrix2x2 *m, const Matrix2x2 *s) {
177     m->load(s);
178 }
179 
SC_MatrixLoadRotate(Matrix4x4 * m,float rot,float x,float y,float z)180 static void SC_MatrixLoadRotate(Matrix4x4 *m, float rot, float x, float y, float z) {
181     m->loadRotate(rot, x, y, z);
182 }
SC_MatrixLoadScale(Matrix4x4 * m,float x,float y,float z)183 static void SC_MatrixLoadScale(Matrix4x4 *m, float x, float y, float z) {
184     m->loadScale(x, y, z);
185 }
SC_MatrixLoadTranslate(Matrix4x4 * m,float x,float y,float z)186 static void SC_MatrixLoadTranslate(Matrix4x4 *m, float x, float y, float z) {
187     m->loadTranslate(x, y, z);
188 }
SC_MatrixRotate(Matrix4x4 * m,float rot,float x,float y,float z)189 static void SC_MatrixRotate(Matrix4x4 *m, float rot, float x, float y, float z) {
190     m->rotate(rot, x, y, z);
191 }
SC_MatrixScale(Matrix4x4 * m,float x,float y,float z)192 static void SC_MatrixScale(Matrix4x4 *m, float x, float y, float z) {
193     m->scale(x, y, z);
194 }
SC_MatrixTranslate(Matrix4x4 * m,float x,float y,float z)195 static void SC_MatrixTranslate(Matrix4x4 *m, float x, float y, float z) {
196     m->translate(x, y, z);
197 }
198 
SC_MatrixLoadMultiply_4x4_4x4_4x4(Matrix4x4 * m,const Matrix4x4 * lhs,const Matrix4x4 * rhs)199 static void SC_MatrixLoadMultiply_4x4_4x4_4x4(Matrix4x4 *m, const Matrix4x4 *lhs, const Matrix4x4 *rhs) {
200     m->loadMultiply(lhs, rhs);
201 }
SC_MatrixLoadMultiply_3x3_3x3_3x3(Matrix3x3 * m,const Matrix3x3 * lhs,const Matrix3x3 * rhs)202 static void SC_MatrixLoadMultiply_3x3_3x3_3x3(Matrix3x3 *m, const Matrix3x3 *lhs, const Matrix3x3 *rhs) {
203     m->loadMultiply(lhs, rhs);
204 }
SC_MatrixLoadMultiply_2x2_2x2_2x2(Matrix2x2 * m,const Matrix2x2 * lhs,const Matrix2x2 * rhs)205 static void SC_MatrixLoadMultiply_2x2_2x2_2x2(Matrix2x2 *m, const Matrix2x2 *lhs, const Matrix2x2 *rhs) {
206     m->loadMultiply(lhs, rhs);
207 }
208 
SC_MatrixMultiply_4x4_4x4(Matrix4x4 * m,const Matrix4x4 * rhs)209 static void SC_MatrixMultiply_4x4_4x4(Matrix4x4 *m, const Matrix4x4 *rhs) {
210     m->multiply(rhs);
211 }
SC_MatrixMultiply_3x3_3x3(Matrix3x3 * m,const Matrix3x3 * rhs)212 static void SC_MatrixMultiply_3x3_3x3(Matrix3x3 *m, const Matrix3x3 *rhs) {
213     m->multiply(rhs);
214 }
SC_MatrixMultiply_2x2_2x2(Matrix2x2 * m,const Matrix2x2 * rhs)215 static void SC_MatrixMultiply_2x2_2x2(Matrix2x2 *m, const Matrix2x2 *rhs) {
216     m->multiply(rhs);
217 }
218 
SC_MatrixLoadOrtho(Matrix4x4 * m,float l,float r,float b,float t,float n,float f)219 static void SC_MatrixLoadOrtho(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) {
220     m->loadOrtho(l, r, b, t, n, f);
221 }
SC_MatrixLoadFrustum(Matrix4x4 * m,float l,float r,float b,float t,float n,float f)222 static void SC_MatrixLoadFrustum(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) {
223     m->loadFrustum(l, r, b, t, n, f);
224 }
SC_MatrixLoadPerspective(Matrix4x4 * m,float fovy,float aspect,float near,float far)225 static void SC_MatrixLoadPerspective(Matrix4x4 *m, float fovy, float aspect, float near, float far) {
226     m->loadPerspective(fovy, aspect, near, far);
227 }
228 
SC_MatrixInverse_4x4(Matrix4x4 * m)229 static bool SC_MatrixInverse_4x4(Matrix4x4 *m) {
230     return m->inverse();
231 }
SC_MatrixInverseTranspose_4x4(Matrix4x4 * m)232 static bool SC_MatrixInverseTranspose_4x4(Matrix4x4 *m) {
233     return m->inverseTranspose();
234 }
SC_MatrixTranspose_4x4(Matrix4x4 * m)235 static void SC_MatrixTranspose_4x4(Matrix4x4 *m) {
236     m->transpose();
237 }
SC_MatrixTranspose_3x3(Matrix3x3 * m)238 static void SC_MatrixTranspose_3x3(Matrix3x3 *m) {
239     m->transpose();
240 }
SC_MatrixTranspose_2x2(Matrix2x2 * m)241 static void SC_MatrixTranspose_2x2(Matrix2x2 *m) {
242     m->transpose();
243 }
244 
SC_randf(float max)245 static float SC_randf(float max) {
246     float r = (float)rand();
247     r *= max;
248     r /= RAND_MAX;
249     return r;
250 }
251 
SC_randf2(float min,float max)252 static float SC_randf2(float min, float max) {
253     float r = (float)rand();
254     r /= RAND_MAX;
255     r = r * (max - min) + min;
256     return r;
257 }
258 
SC_randi(int max)259 static int SC_randi(int max) {
260     return (int)SC_randf(max);
261 }
262 
SC_randi2(int min,int max)263 static int SC_randi2(int min, int max) {
264     return (int)SC_randf2(min, max);
265 }
266 
SC_frac(float v)267 static float SC_frac(float v) {
268     int i = (int)floor(v);
269     return fmin(v - i, 0x1.fffffep-1f);
270 }
271 
272 
SC_AtomicCas(volatile int32_t * ptr,int32_t expectedValue,int32_t newValue)273 static int32_t SC_AtomicCas(volatile int32_t *ptr, int32_t expectedValue, int32_t newValue) {
274     int32_t prev;
275 
276     do {
277         int32_t ret = android_atomic_release_cas(expectedValue, newValue, ptr);
278         if (!ret) {
279             // The android cas return 0 if it wrote the value.  This means the
280             // previous value was the expected value and we can return.
281             return expectedValue;
282         }
283         // We didn't write the value and need to load the "previous" value.
284         prev = *ptr;
285 
286         // A race condition exists where the expected value could appear after our cas failed
287         // above.  In this case loop until we have a legit previous value or the
288         // write passes.
289         } while (prev == expectedValue);
290     return prev;
291 }
292 
293 
SC_AtomicInc(volatile int32_t * ptr)294 static int32_t SC_AtomicInc(volatile int32_t *ptr) {
295     return android_atomic_inc(ptr);
296 }
297 
SC_AtomicDec(volatile int32_t * ptr)298 static int32_t SC_AtomicDec(volatile int32_t *ptr) {
299     return android_atomic_dec(ptr);
300 }
301 
SC_AtomicAdd(volatile int32_t * ptr,int32_t value)302 static int32_t SC_AtomicAdd(volatile int32_t *ptr, int32_t value) {
303     return android_atomic_add(value, ptr);
304 }
305 
SC_AtomicSub(volatile int32_t * ptr,int32_t value)306 static int32_t SC_AtomicSub(volatile int32_t *ptr, int32_t value) {
307     int32_t prev, status;
308     do {
309         prev = *ptr;
310         status = android_atomic_release_cas(prev, prev - value, ptr);
311     } while (CC_UNLIKELY(status != 0));
312     return prev;
313 }
314 
SC_AtomicAnd(volatile int32_t * ptr,int32_t value)315 static int32_t SC_AtomicAnd(volatile int32_t *ptr, int32_t value) {
316     return android_atomic_and(value, ptr);
317 }
318 
SC_AtomicOr(volatile int32_t * ptr,int32_t value)319 static int32_t SC_AtomicOr(volatile int32_t *ptr, int32_t value) {
320     return android_atomic_or(value, ptr);
321 }
322 
SC_AtomicXor(volatile int32_t * ptr,int32_t value)323 static int32_t SC_AtomicXor(volatile int32_t *ptr, int32_t value) {
324     int32_t prev, status;
325     do {
326         prev = *ptr;
327         status = android_atomic_release_cas(prev, prev ^ value, ptr);
328     } while (CC_UNLIKELY(status != 0));
329     return prev;
330 }
331 
SC_AtomicUMin(volatile uint32_t * ptr,uint32_t value)332 static uint32_t SC_AtomicUMin(volatile uint32_t *ptr, uint32_t value) {
333     uint32_t prev, status;
334     do {
335         prev = *ptr;
336         uint32_t n = rsMin(value, prev);
337         status = android_atomic_release_cas((int32_t) prev, (int32_t)n, (volatile int32_t*) ptr);
338     } while (CC_UNLIKELY(status != 0));
339     return prev;
340 }
341 
SC_AtomicMin(volatile int32_t * ptr,int32_t value)342 static int32_t SC_AtomicMin(volatile int32_t *ptr, int32_t value) {
343     int32_t prev, status;
344     do {
345         prev = *ptr;
346         int32_t n = rsMin(value, prev);
347         status = android_atomic_release_cas(prev, n, ptr);
348     } while (CC_UNLIKELY(status != 0));
349     return prev;
350 }
351 
SC_AtomicUMax(volatile uint32_t * ptr,uint32_t value)352 static uint32_t SC_AtomicUMax(volatile uint32_t *ptr, uint32_t value) {
353     uint32_t prev, status;
354     do {
355         prev = *ptr;
356         uint32_t n = rsMax(value, prev);
357         status = android_atomic_release_cas((int32_t) prev, (int32_t) n, (volatile int32_t*) ptr);
358     } while (CC_UNLIKELY(status != 0));
359     return prev;
360 }
361 
SC_AtomicMax(volatile int32_t * ptr,int32_t value)362 static int32_t SC_AtomicMax(volatile int32_t *ptr, int32_t value) {
363     int32_t prev, status;
364     do {
365         prev = *ptr;
366         int32_t n = rsMax(value, prev);
367         status = android_atomic_release_cas(prev, n, ptr);
368     } while (CC_UNLIKELY(status != 0));
369     return prev;
370 }
371 
372 
373 
374 //////////////////////////////////////////////////////////////////////////////
375 // Class implementation
376 //////////////////////////////////////////////////////////////////////////////
377 
378 // llvm name mangling ref
379 //  <builtin-type> ::= v  # void
380 //                 ::= b  # bool
381 //                 ::= c  # char
382 //                 ::= a  # signed char
383 //                 ::= h  # unsigned char
384 //                 ::= s  # short
385 //                 ::= t  # unsigned short
386 //                 ::= i  # int
387 //                 ::= j  # unsigned int
388 //                 ::= l  # long
389 //                 ::= m  # unsigned long
390 //                 ::= x  # long long, __int64
391 //                 ::= y  # unsigned long long, __int64
392 //                 ::= f  # float
393 //                 ::= d  # double
394 
395 static RsdSymbolTable gSyms[] = {
396     { "_Z4acosf", (void *)&acosf, true },
397     { "_Z5acoshf", (void *)&acoshf, true },
398     { "_Z4asinf", (void *)&asinf, true },
399     { "_Z5asinhf", (void *)&asinhf, true },
400     { "_Z4atanf", (void *)&atanf, true },
401     { "_Z5atan2ff", (void *)&atan2f, true },
402     { "_Z5atanhf", (void *)&atanhf, true },
403     { "_Z4cbrtf", (void *)&cbrtf, true },
404     { "_Z4ceilf", (void *)&ceilf, true },
405     { "_Z8copysignff", (void *)&copysignf, true },
406     { "_Z3cosf", (void *)&cosf, true },
407     { "_Z4coshf", (void *)&coshf, true },
408     { "_Z4erfcf", (void *)&erfcf, true },
409     { "_Z3erff", (void *)&erff, true },
410     { "_Z3expf", (void *)&expf, true },
411     { "_Z4exp2f", (void *)&exp2f, true },
412     { "_Z5exp10f", (void *)&SC_exp10, true },
413     { "_Z5expm1f", (void *)&expm1f, true },
414     { "_Z4fabsf", (void *)&fabsf, true },
415     { "_Z4fdimff", (void *)&fdimf, true },
416     { "_Z5floorf", (void *)&floorf, true },
417     { "_Z3fmafff", (void *)&fmaf, true },
418     { "_Z4fmaxff", (void *)&fmaxf, true },
419     { "_Z4fminff", (void *)&fminf, true },  // float fmin(float, float)
420     { "_Z4fmodff", (void *)&fmodf, true },
421     { "_Z5fractfPf", (void *)&SC_fract, true },
422     { "_Z5frexpfPi", (void *)&frexpf, true },
423     { "_Z5hypotff", (void *)&hypotf, true },
424     { "_Z5ilogbf", (void *)&ilogbf, true },
425     { "_Z5ldexpfi", (void *)&ldexpf, true },
426     { "_Z6lgammaf", (void *)&lgammaf, true },
427     { "_Z6lgammafPi", (void *)&lgammaf_r, true },
428     { "_Z3logf", (void *)&logf, true },
429     { "_Z4log2f", (void *)&SC_log2, true },
430     { "_Z5log10f", (void *)&log10f, true },
431     { "_Z5log1pf", (void *)&log1pf, true },
432     { "_Z4logbf", (void *)&logbf, true },
433     { "_Z3madfff", (void *)&SC_mad, true },
434     { "_Z4modffPf", (void *)&modff, true },
435     //{ "_Z3nanj", (void *)&SC_nan, true },
436     { "_Z9nextafterff", (void *)&nextafterf, true },
437     { "_Z3powff", (void *)&powf, true },
438     { "_Z9remainderff", (void *)&remainderf, true },
439     { "_Z6remquoffPi", (void *)&remquof, true },
440     { "_Z4rintf", (void *)&rintf, true },
441     { "_Z5rootnfi", (void *)&SC_rootn, true },
442     { "_Z5roundf", (void *)&roundf, true },
443     { "_Z5rsqrtf", (void *)&SC_rsqrt, true },
444     { "_Z3sinf", (void *)&sinf, true },
445     { "_Z6sincosfPf", (void *)&SC_sincos, true },
446     { "_Z4sinhf", (void *)&sinhf, true },
447     { "_Z4sqrtf", (void *)&sqrtf, true },
448     { "_Z3tanf", (void *)&tanf, true },
449     { "_Z4tanhf", (void *)&tanhf, true },
450     { "_Z6tgammaf", (void *)&tgammaf, true },
451     { "_Z5truncf", (void *)&truncf, true },
452 
453     { "_Z3absi", (void *)&SC_abs_i32, true },
454     { "_Z3abss", (void *)&SC_abs_i16, true },
455     { "_Z3absc", (void *)&SC_abs_i8, true },
456     { "_Z3clzj", (void *)&SC_clz_u32, true },
457     { "_Z3clzt", (void *)&SC_clz_u16, true },
458     { "_Z3clzh", (void *)&SC_clz_u8, true },
459     { "_Z3clzi", (void *)&SC_clz_i32, true },
460     { "_Z3clzs", (void *)&SC_clz_i16, true },
461     { "_Z3clzc", (void *)&SC_clz_i8, true },
462     { "_Z3maxjj", (void *)&SC_max_u32, true },
463     { "_Z3maxtt", (void *)&SC_max_u16, true },
464     { "_Z3maxhh", (void *)&SC_max_u8, true },
465     { "_Z3maxii", (void *)&SC_max_i32, true },
466     { "_Z3maxss", (void *)&SC_max_i16, true },
467     { "_Z3maxcc", (void *)&SC_max_i8, true },
468     { "_Z3minjj", (void *)&SC_min_u32, true },
469     { "_Z3mintt", (void *)&SC_min_u16, true },
470     { "_Z3minhh", (void *)&SC_min_u8, true },
471     { "_Z3minii", (void *)&SC_min_i32, true },
472     { "_Z3minss", (void *)&SC_min_i16, true },
473     { "_Z3mincc", (void *)&SC_min_i8, true },
474 
475     { "_Z5clampfff", (void *)&SC_clamp_f32, true },
476     { "_Z7degreesf", (void *)&SC_degrees, true },
477     { "_Z3maxff", (void *)&SC_max_f32, true },
478     { "_Z3minff", (void *)&SC_min_f32, true },
479     { "_Z3mixfff", (void *)&SC_mix_f32, true },
480     { "_Z7radiansf", (void *)&SC_radians, true },
481     { "_Z4stepff", (void *)&SC_step_f32, true },
482     //{ "smoothstep", (void *)&, true },
483     { "_Z4signf", (void *)&SC_sign_f32, true },
484 
485     // matrix
486     { "_Z20rsMatrixLoadIdentityP12rs_matrix4x4", (void *)&SC_MatrixLoadIdentity_4x4, true },
487     { "_Z20rsMatrixLoadIdentityP12rs_matrix3x3", (void *)&SC_MatrixLoadIdentity_3x3, true },
488     { "_Z20rsMatrixLoadIdentityP12rs_matrix2x2", (void *)&SC_MatrixLoadIdentity_2x2, true },
489 
490     { "_Z12rsMatrixLoadP12rs_matrix4x4PKf", (void *)&SC_MatrixLoad_4x4_f, true },
491     { "_Z12rsMatrixLoadP12rs_matrix3x3PKf", (void *)&SC_MatrixLoad_3x3_f, true },
492     { "_Z12rsMatrixLoadP12rs_matrix2x2PKf", (void *)&SC_MatrixLoad_2x2_f, true },
493 
494     { "_Z12rsMatrixLoadP12rs_matrix4x4PKS_", (void *)&SC_MatrixLoad_4x4_4x4, true },
495     { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix3x3", (void *)&SC_MatrixLoad_4x4_3x3, true },
496     { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix2x2", (void *)&SC_MatrixLoad_4x4_2x2, true },
497     { "_Z12rsMatrixLoadP12rs_matrix3x3PKS_", (void *)&SC_MatrixLoad_3x3_3x3, true },
498     { "_Z12rsMatrixLoadP12rs_matrix2x2PKS_", (void *)&SC_MatrixLoad_2x2_2x2, true },
499 
500     { "_Z18rsMatrixLoadRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadRotate, true },
501     { "_Z17rsMatrixLoadScaleP12rs_matrix4x4fff", (void *)&SC_MatrixLoadScale, true },
502     { "_Z21rsMatrixLoadTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixLoadTranslate, true },
503     { "_Z14rsMatrixRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixRotate, true },
504     { "_Z13rsMatrixScaleP12rs_matrix4x4fff", (void *)&SC_MatrixScale, true },
505     { "_Z17rsMatrixTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixTranslate, true },
506 
507     { "_Z20rsMatrixLoadMultiplyP12rs_matrix4x4PKS_S2_", (void *)&SC_MatrixLoadMultiply_4x4_4x4_4x4, true },
508     { "_Z16rsMatrixMultiplyP12rs_matrix4x4PKS_", (void *)&SC_MatrixMultiply_4x4_4x4, true },
509     { "_Z20rsMatrixLoadMultiplyP12rs_matrix3x3PKS_S2_", (void *)&SC_MatrixLoadMultiply_3x3_3x3_3x3, true },
510     { "_Z16rsMatrixMultiplyP12rs_matrix3x3PKS_", (void *)&SC_MatrixMultiply_3x3_3x3, true },
511     { "_Z20rsMatrixLoadMultiplyP12rs_matrix2x2PKS_S2_", (void *)&SC_MatrixLoadMultiply_2x2_2x2_2x2, true },
512     { "_Z16rsMatrixMultiplyP12rs_matrix2x2PKS_", (void *)&SC_MatrixMultiply_2x2_2x2, true },
513 
514     { "_Z17rsMatrixLoadOrthoP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadOrtho, true },
515     { "_Z19rsMatrixLoadFrustumP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadFrustum, true },
516     { "_Z23rsMatrixLoadPerspectiveP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadPerspective, true },
517 
518     { "_Z15rsMatrixInverseP12rs_matrix4x4", (void *)&SC_MatrixInverse_4x4, true },
519     { "_Z24rsMatrixInverseTransposeP12rs_matrix4x4", (void *)&SC_MatrixInverseTranspose_4x4, true },
520     { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_4x4, true },
521     { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_3x3, true },
522     { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_2x2, true },
523 
524     // RS Math
525     { "_Z6rsRandi", (void *)&SC_randi, true },
526     { "_Z6rsRandii", (void *)&SC_randi2, true },
527     { "_Z6rsRandf", (void *)&SC_randf, true },
528     { "_Z6rsRandff", (void *)&SC_randf2, true },
529     { "_Z6rsFracf", (void *)&SC_frac, true },
530 
531     // Atomics
532     { "_Z11rsAtomicIncPVi", (void *)&SC_AtomicInc, true },
533     { "_Z11rsAtomicIncPVj", (void *)&SC_AtomicInc, true },
534     { "_Z11rsAtomicDecPVi", (void *)&SC_AtomicDec, true },
535     { "_Z11rsAtomicDecPVj", (void *)&SC_AtomicDec, true },
536     { "_Z11rsAtomicAddPVii", (void *)&SC_AtomicAdd, true },
537     { "_Z11rsAtomicAddPVjj", (void *)&SC_AtomicAdd, true },
538     { "_Z11rsAtomicSubPVii", (void *)&SC_AtomicSub, true },
539     { "_Z11rsAtomicSubPVjj", (void *)&SC_AtomicSub, true },
540     { "_Z11rsAtomicAndPVii", (void *)&SC_AtomicAnd, true },
541     { "_Z11rsAtomicAndPVjj", (void *)&SC_AtomicAnd, true },
542     { "_Z10rsAtomicOrPVii", (void *)&SC_AtomicOr, true },
543     { "_Z10rsAtomicOrPVjj", (void *)&SC_AtomicOr, true },
544     { "_Z11rsAtomicXorPVii", (void *)&SC_AtomicXor, true },
545     { "_Z11rsAtomicXorPVjj", (void *)&SC_AtomicXor, true },
546     { "_Z11rsAtomicMinPVii", (void *)&SC_AtomicMin, true },
547     { "_Z11rsAtomicMinPVjj", (void *)&SC_AtomicUMin, true },
548     { "_Z11rsAtomicMaxPVii", (void *)&SC_AtomicMax, true },
549     { "_Z11rsAtomicMaxPVjj", (void *)&SC_AtomicUMax, true },
550     { "_Z11rsAtomicCasPViii", (void *)&SC_AtomicCas, true },
551     { "_Z11rsAtomicCasPVjjj", (void *)&SC_AtomicCas, true },
552 
553     { NULL, NULL, false }
554 };
555 
rsdLookupSymbolMath(const char * sym)556 const RsdSymbolTable * rsdLookupSymbolMath(const char *sym) {
557     const RsdSymbolTable *syms = gSyms;
558 
559     while (syms->mPtr) {
560         if (!strcmp(syms->mName, sym)) {
561             return syms;
562         }
563         syms++;
564     }
565     return NULL;
566 }
567 
568