blob: ecae306e8a7542d554125dd1519fa66726a2983e [file] [log] [blame]
Jason Samse45ac6e2009-07-20 14:31:06 -07001/*
2 * Copyright (C) 2009 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 "rsContext.h"
18#include "rsScriptC.h"
19#include "rsMatrix.h"
20
Joe Onorato9c4e4ca2009-08-09 11:39:02 -070021#include "utils/Timers.h"
Jason Samse45ac6e2009-07-20 14:31:06 -070022
Romain Guy98e10fd2009-07-30 18:45:01 -070023#include <time.h>
Romain Guy98e10fd2009-07-30 18:45:01 -070024
Jason Samse45ac6e2009-07-20 14:31:06 -070025using namespace android;
26using namespace android::renderscript;
27
28#define GET_TLS() Context::ScriptTLSStruct * tls = \
29 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
30 Context * rsc = tls->mContext; \
31 ScriptC * sc = (ScriptC *) tls->mScript
32
Jason Samsbe36bf32010-05-11 14:03:58 -070033
Jason Samse45ac6e2009-07-20 14:31:06 -070034//////////////////////////////////////////////////////////////////////////////
35// Math routines
36//////////////////////////////////////////////////////////////////////////////
37
Romain Guy2275d632009-08-18 11:39:17 -070038static float SC_sinf_fast(float x)
39{
40 const float A = 1.0f / (2.0f * M_PI);
41 const float B = -16.0f;
42 const float C = 8.0f;
Jason Samsa57c0a72009-09-04 14:42:41 -070043
Romain Guy2275d632009-08-18 11:39:17 -070044 // scale angle for easy argument reduction
45 x *= A;
Jason Samsa57c0a72009-09-04 14:42:41 -070046
Romain Guy2275d632009-08-18 11:39:17 -070047 if (fabsf(x) >= 0.5f) {
48 // argument reduction
49 x = x - ceilf(x + 0.5f) + 1.0f;
50 }
Jason Samsa57c0a72009-09-04 14:42:41 -070051
Romain Guy2275d632009-08-18 11:39:17 -070052 const float y = B * x * fabsf(x) + C * x;
53 return 0.2215f * (y * fabsf(y) - y) + y;
54}
55
56static float SC_cosf_fast(float x)
57{
58 x += float(M_PI / 2);
59
60 const float A = 1.0f / (2.0f * M_PI);
61 const float B = -16.0f;
62 const float C = 8.0f;
Jason Samsa57c0a72009-09-04 14:42:41 -070063
Romain Guy2275d632009-08-18 11:39:17 -070064 // scale angle for easy argument reduction
65 x *= A;
Jason Samsa57c0a72009-09-04 14:42:41 -070066
Romain Guy2275d632009-08-18 11:39:17 -070067 if (fabsf(x) >= 0.5f) {
68 // argument reduction
69 x = x - ceilf(x + 0.5f) + 1.0f;
70 }
Jason Samsa57c0a72009-09-04 14:42:41 -070071
Romain Guy2275d632009-08-18 11:39:17 -070072 const float y = B * x * fabsf(x) + C * x;
73 return 0.2215f * (y * fabsf(y) - y) + y;
74}
75
Jason Sams22fa3712010-05-19 17:22:57 -070076
Jason Samse45ac6e2009-07-20 14:31:06 -070077static float SC_randf(float max)
78{
79 float r = (float)rand();
80 return r / RAND_MAX * max;
81}
82
Romain Guy39dbc802009-07-31 11:20:59 -070083static float SC_randf2(float min, float max)
84{
85 float r = (float)rand();
86 return r / RAND_MAX * (max - min) + min;
87}
88
Jason Sams22fa3712010-05-19 17:22:57 -070089static int SC_randi(int max)
90{
91 return (int)SC_randf(max);
92}
93
94static int SC_randi2(int min, int max)
95{
96 return (int)SC_randf2(min, max);
97}
98
Jason Samsbe36bf32010-05-11 14:03:58 -070099static float SC_frac(float v)
100{
101 int i = (int)floor(v);
102 return fmin(v - i, 0x1.fffffep-1f);
103}
104
Romain Guy98e10fd2009-07-30 18:45:01 -0700105//////////////////////////////////////////////////////////////////////////////
106// Time routines
107//////////////////////////////////////////////////////////////////////////////
Jason Samse45ac6e2009-07-20 14:31:06 -0700108
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700109static int32_t SC_second()
Romain Guy98e10fd2009-07-30 18:45:01 -0700110{
111 GET_TLS();
112
113 time_t rawtime;
114 time(&rawtime);
115
Romain Guy519cdc92009-11-11 15:36:06 -0800116 struct tm *timeinfo;
117 timeinfo = localtime(&rawtime);
118 return timeinfo->tm_sec;
Romain Guy98e10fd2009-07-30 18:45:01 -0700119}
120
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700121static int32_t SC_minute()
Romain Guy98e10fd2009-07-30 18:45:01 -0700122{
123 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700124
Romain Guy98e10fd2009-07-30 18:45:01 -0700125 time_t rawtime;
126 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700127
Romain Guy519cdc92009-11-11 15:36:06 -0800128 struct tm *timeinfo;
129 timeinfo = localtime(&rawtime);
130 return timeinfo->tm_min;
Jason Samse5ffb872009-08-09 17:01:55 -0700131}
Romain Guy98e10fd2009-07-30 18:45:01 -0700132
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700133static int32_t SC_hour()
Romain Guy98e10fd2009-07-30 18:45:01 -0700134{
135 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700136
Romain Guy98e10fd2009-07-30 18:45:01 -0700137 time_t rawtime;
138 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700139
Romain Guy519cdc92009-11-11 15:36:06 -0800140 struct tm *timeinfo;
141 timeinfo = localtime(&rawtime);
142 return timeinfo->tm_hour;
Romain Guy39dbc802009-07-31 11:20:59 -0700143}
144
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700145static int32_t SC_day()
Romain Guy39dbc802009-07-31 11:20:59 -0700146{
147 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700148
Romain Guy39dbc802009-07-31 11:20:59 -0700149 time_t rawtime;
150 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700151
Romain Guy519cdc92009-11-11 15:36:06 -0800152 struct tm *timeinfo;
153 timeinfo = localtime(&rawtime);
154 return timeinfo->tm_mday;
Jason Samse5ffb872009-08-09 17:01:55 -0700155}
Jason Samse45ac6e2009-07-20 14:31:06 -0700156
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700157static int32_t SC_month()
Romain Guy39dbc802009-07-31 11:20:59 -0700158{
159 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700160
Romain Guy39dbc802009-07-31 11:20:59 -0700161 time_t rawtime;
162 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700163
Romain Guy519cdc92009-11-11 15:36:06 -0800164 struct tm *timeinfo;
165 timeinfo = localtime(&rawtime);
166 return timeinfo->tm_mon;
Jason Samse5ffb872009-08-09 17:01:55 -0700167}
Romain Guy39dbc802009-07-31 11:20:59 -0700168
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700169static int32_t SC_year()
Romain Guy39dbc802009-07-31 11:20:59 -0700170{
171 GET_TLS();
Jason Samse5ffb872009-08-09 17:01:55 -0700172
Romain Guy39dbc802009-07-31 11:20:59 -0700173 time_t rawtime;
174 time(&rawtime);
Jason Samse5ffb872009-08-09 17:01:55 -0700175
Romain Guy519cdc92009-11-11 15:36:06 -0800176 struct tm *timeinfo;
177 timeinfo = localtime(&rawtime);
178 return timeinfo->tm_year;
Romain Guy39dbc802009-07-31 11:20:59 -0700179}
180
Jason Samsef5867a2010-07-28 11:17:53 -0700181static int64_t SC_uptimeMillis()
Jason Sams22fa3712010-05-19 17:22:57 -0700182{
183 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
184}
185
Jason Sams73495472010-07-29 17:31:14 -0700186static int64_t SC_uptimeNanos()
Jason Sams22fa3712010-05-19 17:22:57 -0700187{
Jason Sams73495472010-07-29 17:31:14 -0700188 return systemTime(SYSTEM_TIME_MONOTONIC);
Jason Sams22fa3712010-05-19 17:22:57 -0700189}
190
Jason Samsef5867a2010-07-28 11:17:53 -0700191static float SC_getDt()
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700192{
193 GET_TLS();
Jason Samsef5867a2010-07-28 11:17:53 -0700194 int64_t l = sc->mEnviroment.mLastDtTime;
195 sc->mEnviroment.mLastDtTime = systemTime(SYSTEM_TIME_MONOTONIC);
196 return ((float)(sc->mEnviroment.mLastDtTime - l)) / 1.0e9;
Jason Samse45ac6e2009-07-20 14:31:06 -0700197}
198
199
Jason Samse45ac6e2009-07-20 14:31:06 -0700200//////////////////////////////////////////////////////////////////////////////
201//
202//////////////////////////////////////////////////////////////////////////////
203
Jason Samsbe36bf32010-05-11 14:03:58 -0700204static uint32_t SC_allocGetDimX(RsAllocation va)
205{
Jason Samsbe36bf32010-05-11 14:03:58 -0700206 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700207 CHECK_OBJ(a);
208 //LOGE("SC_allocGetDimX a=%p type=%p", a, a->getType());
Jason Samsbe36bf32010-05-11 14:03:58 -0700209 return a->getType()->getDimX();
210}
211
212static uint32_t SC_allocGetDimY(RsAllocation va)
213{
Jason Samsbe36bf32010-05-11 14:03:58 -0700214 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700215 CHECK_OBJ(a);
Jason Samsbe36bf32010-05-11 14:03:58 -0700216 return a->getType()->getDimY();
217}
218
219static uint32_t SC_allocGetDimZ(RsAllocation va)
220{
Jason Samsbe36bf32010-05-11 14:03:58 -0700221 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700222 CHECK_OBJ(a);
Jason Samsbe36bf32010-05-11 14:03:58 -0700223 return a->getType()->getDimZ();
224}
225
226static uint32_t SC_allocGetDimLOD(RsAllocation va)
227{
Jason Samsbe36bf32010-05-11 14:03:58 -0700228 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700229 CHECK_OBJ(a);
Jason Samsbe36bf32010-05-11 14:03:58 -0700230 return a->getType()->getDimLOD();
231}
232
233static uint32_t SC_allocGetDimFaces(RsAllocation va)
234{
Jason Samsbe36bf32010-05-11 14:03:58 -0700235 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700236 CHECK_OBJ(a);
Jason Samsbe36bf32010-05-11 14:03:58 -0700237 return a->getType()->getDimFaces();
238}
239
Jason Samsc0936852010-08-16 12:41:48 -0700240static const void * SC_getElementAtX(RsAllocation va, uint32_t x)
Jason Sams7bf29dd2010-07-19 15:38:19 -0700241{
242 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700243 CHECK_OBJ(a);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700244 const Type *t = a->getType();
Jason Sams605048a2010-09-30 18:15:52 -0700245 CHECK_OBJ(t);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700246 const uint8_t *p = (const uint8_t *)a->getPtr();
247 return &p[t->getElementSizeBytes() * x];
248}
249
Jason Samsc0936852010-08-16 12:41:48 -0700250static const void * SC_getElementAtXY(RsAllocation va, uint32_t x, uint32_t y)
Jason Sams7bf29dd2010-07-19 15:38:19 -0700251{
252 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700253 CHECK_OBJ(a);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700254 const Type *t = a->getType();
Jason Sams605048a2010-09-30 18:15:52 -0700255 CHECK_OBJ(t);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700256 const uint8_t *p = (const uint8_t *)a->getPtr();
257 return &p[t->getElementSizeBytes() * (x + y*t->getDimX())];
258}
259
Jason Samsc0936852010-08-16 12:41:48 -0700260static const void * SC_getElementAtXYZ(RsAllocation va, uint32_t x, uint32_t y, uint32_t z)
Jason Sams7bf29dd2010-07-19 15:38:19 -0700261{
262 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700263 CHECK_OBJ(a);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700264 const Type *t = a->getType();
Jason Sams605048a2010-09-30 18:15:52 -0700265 CHECK_OBJ(t);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700266 const uint8_t *p = (const uint8_t *)a->getPtr();
267 return &p[t->getElementSizeBytes() * (x + y*t->getDimX())];
268}
Jason Samsbe36bf32010-05-11 14:03:58 -0700269
Jason Samsc0936852010-08-16 12:41:48 -0700270static void SC_setObject(void **vdst, void * vsrc) {
Jason Samsf24d7d02010-09-17 13:17:17 -0700271 //LOGE("SC_setObject %p,%p %p", vdst, *vdst, vsrc);
272 if (vsrc) {
Jason Sams605048a2010-09-30 18:15:52 -0700273 CHECK_OBJ(vsrc);
Jason Samsf24d7d02010-09-17 13:17:17 -0700274 static_cast<ObjectBase *>(vsrc)->incSysRef();
275 }
276 if (vdst[0]) {
Jason Sams605048a2010-09-30 18:15:52 -0700277 CHECK_OBJ(vdst[0]);
Jason Samsf24d7d02010-09-17 13:17:17 -0700278 static_cast<ObjectBase *>(vdst[0])->decSysRef();
279 }
Jason Samsc0936852010-08-16 12:41:48 -0700280 *vdst = vsrc;
Jason Samsf24d7d02010-09-17 13:17:17 -0700281 //LOGE("SC_setObject *");
Jason Samsc0936852010-08-16 12:41:48 -0700282}
283static void SC_clearObject(void **vdst) {
Jason Samsf24d7d02010-09-17 13:17:17 -0700284 //LOGE("SC_clearObject %p,%p", vdst, *vdst);
285 if (vdst[0]) {
Jason Sams605048a2010-09-30 18:15:52 -0700286 CHECK_OBJ(vdst[0]);
Jason Samsf24d7d02010-09-17 13:17:17 -0700287 static_cast<ObjectBase *>(vdst[0])->decSysRef();
288 }
Jason Samsc0936852010-08-16 12:41:48 -0700289 *vdst = NULL;
Jason Samsf24d7d02010-09-17 13:17:17 -0700290 //LOGE("SC_clearObject *");
Jason Samsc0936852010-08-16 12:41:48 -0700291}
292static bool SC_isObject(RsAllocation vsrc) {
293 return vsrc != NULL;
294}
295
296
Jason Samse45ac6e2009-07-20 14:31:06 -0700297
Jason Sams22fa3712010-05-19 17:22:57 -0700298static void SC_debugF(const char *s, float f) {
299 LOGE("%s %f, 0x%08x", s, f, *((int *) (&f)));
Jason Samsc9d43db2009-07-28 12:02:16 -0700300}
Jason Sams7dce6bc2010-08-06 16:22:50 -0700301static void SC_debugFv2(const char *s, float f1, float f2) {
302 LOGE("%s {%f, %f}", s, f1, f2);
Romain Guy370ed152009-08-20 17:08:33 -0700303}
Jason Sams7dce6bc2010-08-06 16:22:50 -0700304static void SC_debugFv3(const char *s, float f1, float f2, float f3) {
305 LOGE("%s {%f, %f, %f}", s, f1, f2, f3);
Jason Samsc9d43db2009-07-28 12:02:16 -0700306}
Jason Sams7dce6bc2010-08-06 16:22:50 -0700307static void SC_debugFv4(const char *s, float f1, float f2, float f3, float f4) {
308 LOGE("%s {%f, %f, %f, %f}", s, f1, f2, f3, f4);
Jason Sams22fa3712010-05-19 17:22:57 -0700309}
Stephen Hinesdf097192010-10-15 12:47:49 -0700310static void SC_debugD(const char *s, double d) {
311 LOGE("%s %f, 0x%08llx", s, d, *((long long *) (&d)));
312}
Jason Sams7dce6bc2010-08-06 16:22:50 -0700313static void SC_debugFM4v4(const char *s, const float *f) {
314 LOGE("%s {%f, %f, %f, %f", s, f[0], f[4], f[8], f[12]);
315 LOGE("%s %f, %f, %f, %f", s, f[1], f[5], f[9], f[13]);
316 LOGE("%s %f, %f, %f, %f", s, f[2], f[6], f[10], f[14]);
317 LOGE("%s %f, %f, %f, %f}", s, f[3], f[7], f[11], f[15]);
318}
319static void SC_debugFM3v3(const char *s, const float *f) {
320 LOGE("%s {%f, %f, %f", s, f[0], f[3], f[6]);
321 LOGE("%s %f, %f, %f", s, f[1], f[4], f[7]);
322 LOGE("%s %f, %f, %f}",s, f[2], f[5], f[8]);
323}
324static void SC_debugFM2v2(const char *s, const float *f) {
325 LOGE("%s {%f, %f", s, f[0], f[2]);
326 LOGE("%s %f, %f}",s, f[1], f[3]);
327}
328
Jason Sams22fa3712010-05-19 17:22:57 -0700329static void SC_debugI32(const char *s, int32_t i) {
330 LOGE("%s %i 0x%x", s, i, i);
Romain Guy370ed152009-08-20 17:08:33 -0700331}
Jason Samsef5867a2010-07-28 11:17:53 -0700332static void SC_debugU32(const char *s, uint32_t i) {
Stephen Hinesdf097192010-10-15 12:47:49 -0700333 LOGE("%s %u 0x%x", s, i, i);
334}
335static void SC_debugLL64(const char *s, long long ll) {
336 LOGE("%s %lld 0x%llx", s, ll, ll);
337}
338static void SC_debugULL64(const char *s, unsigned long long ll) {
339 LOGE("%s %llu 0x%llx", s, ll, ll);
Jason Samsef5867a2010-07-28 11:17:53 -0700340}
Romain Guy370ed152009-08-20 17:08:33 -0700341
Jason Sams7bf29dd2010-07-19 15:38:19 -0700342static void SC_debugP(const char *s, const void *p) {
343 LOGE("%s %p", s, p);
344}
345
Jason Samsef5867a2010-07-28 11:17:53 -0700346static uint32_t SC_toClient2(int cmdID, void *data, int len)
Jason Sams8c401ef2009-10-06 13:58:47 -0700347{
348 GET_TLS();
Jason Samsef5867a2010-07-28 11:17:53 -0700349 //LOGE("SC_toClient %i %i %i", cmdID, len);
350 return rsc->sendMessageToClient(data, cmdID, len, false);
Jason Sams8c401ef2009-10-06 13:58:47 -0700351}
352
Jason Samsef5867a2010-07-28 11:17:53 -0700353static uint32_t SC_toClient(int cmdID)
Jason Sams3a27c952009-10-07 18:14:01 -0700354{
355 GET_TLS();
Jason Samsef5867a2010-07-28 11:17:53 -0700356 //LOGE("SC_toClient %i", cmdID);
357 return rsc->sendMessageToClient(NULL, cmdID, 0, false);
358}
359
360static uint32_t SC_toClientBlocking2(int cmdID, void *data, int len)
361{
362 GET_TLS();
363 //LOGE("SC_toClientBlocking %i %i", cmdID, len);
364 return rsc->sendMessageToClient(data, cmdID, len, true);
365}
366
367static uint32_t SC_toClientBlocking(int cmdID)
368{
369 GET_TLS();
370 //LOGE("SC_toClientBlocking %i", cmdID);
371 return rsc->sendMessageToClient(NULL, cmdID, 0, true);
Jason Sams3a27c952009-10-07 18:14:01 -0700372}
373
Jason Samsbe36bf32010-05-11 14:03:58 -0700374int SC_divsi3(int a, int b)
375{
376 return a / b;
377}
Jason Sams3a27c952009-10-07 18:14:01 -0700378
Jason Samsce92d4b2010-05-17 14:55:34 -0700379int SC_getAllocation(const void *ptr)
380{
381 GET_TLS();
382 const Allocation *alloc = sc->ptrToAllocation(ptr);
383 return (int)alloc;
384}
385
Alex Sakhartchouk1e5168d2010-09-01 16:34:48 -0700386void SC_allocationMarkDirty(RsAllocation a)
387{
388 Allocation *alloc = static_cast<Allocation *>(a);
389 alloc->sendDirty();
390}
Jason Samsce92d4b2010-05-17 14:55:34 -0700391
Jason Samsace3e012010-07-15 17:11:13 -0700392void SC_ForEach(RsScript vs,
393 RsAllocation vin,
394 RsAllocation vout,
395 const void *usr)
Jason Samsc61346b2010-05-28 18:23:22 -0700396{
397 GET_TLS();
Jason Samsace3e012010-07-15 17:11:13 -0700398 const Allocation *ain = static_cast<const Allocation *>(vin);
Jason Samsc61346b2010-05-28 18:23:22 -0700399 Allocation *aout = static_cast<Allocation *>(vout);
Jason Samsace3e012010-07-15 17:11:13 -0700400 Script *s = static_cast<Script *>(vs);
401 s->runForEach(rsc, ain, aout, usr);
Jason Samsc61346b2010-05-28 18:23:22 -0700402}
403
Jason Samsace3e012010-07-15 17:11:13 -0700404void SC_ForEach2(RsScript vs,
405 RsAllocation vin,
406 RsAllocation vout,
407 const void *usr,
408 const RsScriptCall *call)
Jason Samsc61346b2010-05-28 18:23:22 -0700409{
410 GET_TLS();
Jason Samsace3e012010-07-15 17:11:13 -0700411 const Allocation *ain = static_cast<const Allocation *>(vin);
Jason Samsc61346b2010-05-28 18:23:22 -0700412 Allocation *aout = static_cast<Allocation *>(vout);
Jason Samsc61346b2010-05-28 18:23:22 -0700413 Script *s = static_cast<Script *>(vs);
Jason Samsace3e012010-07-15 17:11:13 -0700414 s->runForEach(rsc, ain, aout, usr, call);
Jason Samsc61346b2010-05-28 18:23:22 -0700415}
416
Jason Samse45ac6e2009-07-20 14:31:06 -0700417//////////////////////////////////////////////////////////////////////////////
418// Class implementation
419//////////////////////////////////////////////////////////////////////////////
420
Jason Samsbe36bf32010-05-11 14:03:58 -0700421// llvm name mangling ref
422// <builtin-type> ::= v # void
423// ::= b # bool
424// ::= c # char
425// ::= a # signed char
426// ::= h # unsigned char
427// ::= s # short
428// ::= t # unsigned short
429// ::= i # int
430// ::= j # unsigned int
431// ::= l # long
432// ::= m # unsigned long
433// ::= x # long long, __int64
434// ::= y # unsigned long long, __int64
435// ::= f # float
436// ::= d # double
Jason Samse45ac6e2009-07-20 14:31:06 -0700437
Jason Samsaeb094b2010-05-18 13:35:45 -0700438static ScriptCState::SymbolTable_t gSyms[] = {
Jason Sams6bfc1b92010-11-01 14:26:30 -0700439 { "__divsi3", (void *)&SC_divsi3, true },
Jason Samsbe36bf32010-05-11 14:03:58 -0700440
Jason Sams22fa3712010-05-19 17:22:57 -0700441 // allocation
Jason Sams6bfc1b92010-11-01 14:26:30 -0700442 { "_Z19rsAllocationGetDimX13rs_allocation", (void *)&SC_allocGetDimX, true },
443 { "_Z19rsAllocationGetDimY13rs_allocation", (void *)&SC_allocGetDimY, true },
444 { "_Z19rsAllocationGetDimZ13rs_allocation", (void *)&SC_allocGetDimZ, true },
445 { "_Z21rsAllocationGetDimLOD13rs_allocation", (void *)&SC_allocGetDimLOD, true },
446 { "_Z23rsAllocationGetDimFaces13rs_allocation", (void *)&SC_allocGetDimFaces, true },
447 { "_Z15rsGetAllocationPKv", (void *)&SC_getAllocation, true },
Jason Sams22fa3712010-05-19 17:22:57 -0700448
Jason Sams6bfc1b92010-11-01 14:26:30 -0700449 { "_Z14rsGetElementAt13rs_allocationj", (void *)&SC_getElementAtX, true },
450 { "_Z14rsGetElementAt13rs_allocationjj", (void *)&SC_getElementAtXY, true },
451 { "_Z14rsGetElementAt13rs_allocationjjj", (void *)&SC_getElementAtXYZ, true },
Jason Sams7bf29dd2010-07-19 15:38:19 -0700452
Jason Sams6bfc1b92010-11-01 14:26:30 -0700453 { "_Z11rsSetObjectP10rs_elementS_", (void *)&SC_setObject, true },
454 { "_Z13rsClearObjectP10rs_element", (void *)&SC_clearObject, true },
455 { "_Z10rsIsObject10rs_element", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700456
Jason Sams6bfc1b92010-11-01 14:26:30 -0700457 { "_Z11rsSetObjectP7rs_typeS_", (void *)&SC_setObject, true },
458 { "_Z13rsClearObjectP7rs_type", (void *)&SC_clearObject, true },
459 { "_Z10rsIsObject7rs_type", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700460
Jason Sams6bfc1b92010-11-01 14:26:30 -0700461 { "_Z11rsSetObjectP13rs_allocationS_", (void *)&SC_setObject, true },
462 { "_Z13rsClearObjectP13rs_allocation", (void *)&SC_clearObject, true },
463 { "_Z10rsIsObject13rs_allocation", (void *)&SC_isObject, true },
Jason Samsc0936852010-08-16 12:41:48 -0700464
Jason Sams6bfc1b92010-11-01 14:26:30 -0700465 { "_Z11rsSetObjectP10rs_samplerS_", (void *)&SC_setObject, true },
466 { "_Z13rsClearObjectP10rs_sampler", (void *)&SC_clearObject, true },
467 { "_Z10rsIsObject10rs_sampler", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700468
Jason Sams6bfc1b92010-11-01 14:26:30 -0700469 { "_Z11rsSetObjectP9rs_scriptS_", (void *)&SC_setObject, true },
470 { "_Z13rsClearObjectP9rs_script", (void *)&SC_clearObject, true },
471 { "_Z10rsIsObject9rs_script", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700472
Jason Sams6bfc1b92010-11-01 14:26:30 -0700473 { "_Z11rsSetObjectP7rs_meshS_", (void *)&SC_setObject, true },
474 { "_Z13rsClearObjectP7rs_mesh", (void *)&SC_clearObject, true },
475 { "_Z10rsIsObject7rs_mesh", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700476
Jason Sams6bfc1b92010-11-01 14:26:30 -0700477 { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&SC_setObject, true },
478 { "_Z13rsClearObjectP19rs_program_fragment", (void *)&SC_clearObject, true },
479 { "_Z10rsIsObject19rs_program_fragment", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700480
Jason Sams6bfc1b92010-11-01 14:26:30 -0700481 { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&SC_setObject, true },
482 { "_Z13rsClearObjectP17rs_program_vertex", (void *)&SC_clearObject, true },
483 { "_Z10rsIsObject17rs_program_vertex", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700484
Jason Sams6bfc1b92010-11-01 14:26:30 -0700485 { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&SC_setObject, true },
486 { "_Z13rsClearObjectP17rs_program_raster", (void *)&SC_clearObject, true },
487 { "_Z10rsIsObject17rs_program_raster", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700488
Jason Sams6bfc1b92010-11-01 14:26:30 -0700489 { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&SC_setObject, true },
490 { "_Z13rsClearObjectP16rs_program_store", (void *)&SC_clearObject, true },
491 { "_Z10rsIsObject16rs_program_store", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700492
Jason Sams6bfc1b92010-11-01 14:26:30 -0700493 { "_Z11rsSetObjectP7rs_fontS_", (void *)&SC_setObject, true },
494 { "_Z13rsClearObjectP7rs_font", (void *)&SC_clearObject, true },
495 { "_Z10rsIsObject7rs_font", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700496
497
Jason Sams6bfc1b92010-11-01 14:26:30 -0700498 { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_allocationMarkDirty, true },
Alex Sakhartchouk1e5168d2010-09-01 16:34:48 -0700499
Jason Samsc0936852010-08-16 12:41:48 -0700500
Jason Sams22fa3712010-05-19 17:22:57 -0700501 // Debug
Jason Sams6bfc1b92010-11-01 14:26:30 -0700502 { "_Z7rsDebugPKcf", (void *)&SC_debugF, true },
503 { "_Z7rsDebugPKcff", (void *)&SC_debugFv2, true },
504 { "_Z7rsDebugPKcfff", (void *)&SC_debugFv3, true },
505 { "_Z7rsDebugPKcffff", (void *)&SC_debugFv4, true },
506 { "_Z7rsDebugPKcd", (void *)&SC_debugD, true },
507 { "_Z7rsDebugPKcPK12rs_matrix4x4", (void *)&SC_debugFM4v4, true },
508 { "_Z7rsDebugPKcPK12rs_matrix3x3", (void *)&SC_debugFM3v3, true },
509 { "_Z7rsDebugPKcPK12rs_matrix2x2", (void *)&SC_debugFM2v2, true },
510 { "_Z7rsDebugPKci", (void *)&SC_debugI32, true },
511 { "_Z7rsDebugPKcj", (void *)&SC_debugU32, true },
Stephen Hinesdf097192010-10-15 12:47:49 -0700512 // Both "long" and "unsigned long" need to be redirected to their
513 // 64-bit counterparts, since we have hacked Slang to use 64-bit
514 // for "long" on Arm (to be similar to Java).
Jason Sams6bfc1b92010-11-01 14:26:30 -0700515 { "_Z7rsDebugPKcl", (void *)&SC_debugLL64, true },
516 { "_Z7rsDebugPKcm", (void *)&SC_debugULL64, true },
517 { "_Z7rsDebugPKcx", (void *)&SC_debugLL64, true },
518 { "_Z7rsDebugPKcy", (void *)&SC_debugULL64, true },
519 { "_Z7rsDebugPKcPKv", (void *)&SC_debugP, true },
Jason Sams22fa3712010-05-19 17:22:57 -0700520
521 // RS Math
Jason Sams6bfc1b92010-11-01 14:26:30 -0700522 { "_Z6rsRandi", (void *)&SC_randi, true },
523 { "_Z6rsRandii", (void *)&SC_randi2, true },
524 { "_Z6rsRandf", (void *)&SC_randf, true },
525 { "_Z6rsRandff", (void *)&SC_randf2, true },
526 { "_Z6rsFracf", (void *)&SC_frac, true },
Jason Sams22fa3712010-05-19 17:22:57 -0700527
528 // time
Jason Sams6bfc1b92010-11-01 14:26:30 -0700529 { "_Z8rsSecondv", (void *)&SC_second, true },
530 { "_Z8rsMinutev", (void *)&SC_minute, true },
531 { "_Z6rsHourv", (void *)&SC_hour, true },
532 { "_Z5rsDayv", (void *)&SC_day, true },
533 { "_Z7rsMonthv", (void *)&SC_month, true },
534 { "_Z6rsYearv", (void *)&SC_year, true },
535 { "_Z14rsUptimeMillisv", (void*)&SC_uptimeMillis, true },
536 { "_Z13rsUptimeNanosv", (void*)&SC_uptimeNanos, true },
537 { "_Z7rsGetDtv", (void*)&SC_getDt, false },
Jason Sams22fa3712010-05-19 17:22:57 -0700538
Jason Sams6bfc1b92010-11-01 14:26:30 -0700539 { "_Z14rsSendToClienti", (void *)&SC_toClient, false },
540 { "_Z14rsSendToClientiPKvj", (void *)&SC_toClient2, false },
541 { "_Z22rsSendToClientBlockingi", (void *)&SC_toClientBlocking, false },
542 { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_toClientBlocking2, false },
Jason Sams22fa3712010-05-19 17:22:57 -0700543
Jason Sams6bfc1b92010-11-01 14:26:30 -0700544 { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach, false },
545 //{ "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach2, true },
Jason Sams22fa3712010-05-19 17:22:57 -0700546
547////////////////////////////////////////////////////////////////////
548
Jason Sams6bfc1b92010-11-01 14:26:30 -0700549 //{ "sinf_fast", (void *)&SC_sinf_fast, true },
550 //{ "cosf_fast", (void *)&SC_cosf_fast, true },
Jason Samse45ac6e2009-07-20 14:31:06 -0700551
Jason Sams6bfc1b92010-11-01 14:26:30 -0700552 { NULL, NULL, false }
Jason Samse45ac6e2009-07-20 14:31:06 -0700553};
554
555const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym)
556{
557 ScriptCState::SymbolTable_t *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