Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | #include "acc/acc.h" |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 22 | #include "utils/Timers.h" |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 23 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 24 | #include <time.h> |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 25 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 26 | using namespace android; |
| 27 | using namespace android::renderscript; |
| 28 | |
| 29 | #define GET_TLS() Context::ScriptTLSStruct * tls = \ |
| 30 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
| 31 | Context * rsc = tls->mContext; \ |
| 32 | ScriptC * sc = (ScriptC *) tls->mScript |
| 33 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 34 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 35 | ////////////////////////////////////////////////////////////////////////////// |
| 36 | // Math routines |
| 37 | ////////////////////////////////////////////////////////////////////////////// |
| 38 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 39 | static float SC_sinf_fast(float x) |
| 40 | { |
| 41 | const float A = 1.0f / (2.0f * M_PI); |
| 42 | const float B = -16.0f; |
| 43 | const float C = 8.0f; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 44 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 45 | // scale angle for easy argument reduction |
| 46 | x *= A; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 47 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 48 | if (fabsf(x) >= 0.5f) { |
| 49 | // argument reduction |
| 50 | x = x - ceilf(x + 0.5f) + 1.0f; |
| 51 | } |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 52 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 53 | const float y = B * x * fabsf(x) + C * x; |
| 54 | return 0.2215f * (y * fabsf(y) - y) + y; |
| 55 | } |
| 56 | |
| 57 | static float SC_cosf_fast(float x) |
| 58 | { |
| 59 | x += float(M_PI / 2); |
| 60 | |
| 61 | const float A = 1.0f / (2.0f * M_PI); |
| 62 | const float B = -16.0f; |
| 63 | const float C = 8.0f; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 64 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 65 | // scale angle for easy argument reduction |
| 66 | x *= A; |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 67 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 68 | if (fabsf(x) >= 0.5f) { |
| 69 | // argument reduction |
| 70 | x = x - ceilf(x + 0.5f) + 1.0f; |
| 71 | } |
Jason Sams | ea84a7c | 2009-09-04 14:42:41 -0700 | [diff] [blame] | 72 | |
Romain Guy | cac80a6 | 2009-08-18 11:39:17 -0700 | [diff] [blame] | 73 | const float y = B * x * fabsf(x) + C * x; |
| 74 | return 0.2215f * (y * fabsf(y) - y) + y; |
| 75 | } |
| 76 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 77 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 78 | static float SC_randf(float max) |
| 79 | { |
| 80 | float r = (float)rand(); |
| 81 | return r / RAND_MAX * max; |
| 82 | } |
| 83 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 84 | static float SC_randf2(float min, float max) |
| 85 | { |
| 86 | float r = (float)rand(); |
| 87 | return r / RAND_MAX * (max - min) + min; |
| 88 | } |
| 89 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 90 | static int SC_randi(int max) |
| 91 | { |
| 92 | return (int)SC_randf(max); |
| 93 | } |
| 94 | |
| 95 | static int SC_randi2(int min, int max) |
| 96 | { |
| 97 | return (int)SC_randf2(min, max); |
| 98 | } |
| 99 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 100 | static float SC_frac(float v) |
| 101 | { |
| 102 | int i = (int)floor(v); |
| 103 | return fmin(v - i, 0x1.fffffep-1f); |
| 104 | } |
| 105 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 106 | ////////////////////////////////////////////////////////////////////////////// |
| 107 | // Time routines |
| 108 | ////////////////////////////////////////////////////////////////////////////// |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 109 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 110 | static int32_t SC_second() |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 111 | { |
| 112 | GET_TLS(); |
| 113 | |
| 114 | time_t rawtime; |
| 115 | time(&rawtime); |
| 116 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 117 | struct tm *timeinfo; |
| 118 | timeinfo = localtime(&rawtime); |
| 119 | return timeinfo->tm_sec; |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 122 | static int32_t SC_minute() |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 123 | { |
| 124 | GET_TLS(); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 125 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 126 | time_t rawtime; |
| 127 | time(&rawtime); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 128 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 129 | struct tm *timeinfo; |
| 130 | timeinfo = localtime(&rawtime); |
| 131 | return timeinfo->tm_min; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 132 | } |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 133 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 134 | static int32_t SC_hour() |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 135 | { |
| 136 | GET_TLS(); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 137 | |
Romain Guy | 584a375 | 2009-07-30 18:45:01 -0700 | [diff] [blame] | 138 | time_t rawtime; |
| 139 | time(&rawtime); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 140 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 141 | struct tm *timeinfo; |
| 142 | timeinfo = localtime(&rawtime); |
| 143 | return timeinfo->tm_hour; |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 146 | static int32_t SC_day() |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 147 | { |
| 148 | GET_TLS(); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 149 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 150 | time_t rawtime; |
| 151 | time(&rawtime); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 152 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 153 | struct tm *timeinfo; |
| 154 | timeinfo = localtime(&rawtime); |
| 155 | return timeinfo->tm_mday; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 156 | } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 157 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 158 | static int32_t SC_month() |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 159 | { |
| 160 | GET_TLS(); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 161 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 162 | time_t rawtime; |
| 163 | time(&rawtime); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 164 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 165 | struct tm *timeinfo; |
| 166 | timeinfo = localtime(&rawtime); |
| 167 | return timeinfo->tm_mon; |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 168 | } |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 169 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 170 | static int32_t SC_year() |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 171 | { |
| 172 | GET_TLS(); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 173 | |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 174 | time_t rawtime; |
| 175 | time(&rawtime); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 176 | |
Romain Guy | baed727 | 2009-11-11 15:36:06 -0800 | [diff] [blame] | 177 | struct tm *timeinfo; |
| 178 | timeinfo = localtime(&rawtime); |
| 179 | return timeinfo->tm_year; |
Romain Guy | 8839ca5 | 2009-07-31 11:20:59 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 182 | static int64_t SC_uptimeMillis2() |
| 183 | { |
| 184 | return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 185 | } |
| 186 | |
| 187 | static int64_t SC_startTimeMillis2() |
| 188 | { |
| 189 | GET_TLS(); |
| 190 | return sc->mEnviroment.mStartTimeMillis; |
| 191 | } |
| 192 | |
| 193 | static int64_t SC_elapsedTimeMillis2() |
| 194 | { |
| 195 | GET_TLS(); |
| 196 | return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)) |
| 197 | - sc->mEnviroment.mStartTimeMillis; |
| 198 | } |
| 199 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 200 | static int32_t SC_uptimeMillis() |
| 201 | { |
| 202 | return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 203 | } |
| 204 | |
| 205 | static int32_t SC_startTimeMillis() |
| 206 | { |
| 207 | GET_TLS(); |
| 208 | return sc->mEnviroment.mStartTimeMillis; |
| 209 | } |
| 210 | |
| 211 | static int32_t SC_elapsedTimeMillis() |
| 212 | { |
| 213 | GET_TLS(); |
| 214 | return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)) |
| 215 | - sc->mEnviroment.mStartTimeMillis; |
| 216 | } |
| 217 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 218 | ////////////////////////////////////////////////////////////////////////////// |
| 219 | // Matrix routines |
| 220 | ////////////////////////////////////////////////////////////////////////////// |
| 221 | |
| 222 | |
| 223 | static void SC_matrixLoadIdentity(rsc_Matrix *mat) |
| 224 | { |
| 225 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 226 | m->loadIdentity(); |
| 227 | } |
| 228 | |
| 229 | static void SC_matrixLoadFloat(rsc_Matrix *mat, const float *f) |
| 230 | { |
| 231 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 232 | m->load(f); |
| 233 | } |
| 234 | |
| 235 | static void SC_matrixLoadMat(rsc_Matrix *mat, const rsc_Matrix *newmat) |
| 236 | { |
| 237 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 238 | m->load(reinterpret_cast<const Matrix *>(newmat)); |
| 239 | } |
| 240 | |
| 241 | static void SC_matrixLoadRotate(rsc_Matrix *mat, float rot, float x, float y, float z) |
| 242 | { |
| 243 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 244 | m->loadRotate(rot, x, y, z); |
| 245 | } |
| 246 | |
| 247 | static void SC_matrixLoadScale(rsc_Matrix *mat, float x, float y, float z) |
| 248 | { |
| 249 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 250 | m->loadScale(x, y, z); |
| 251 | } |
| 252 | |
| 253 | static void SC_matrixLoadTranslate(rsc_Matrix *mat, float x, float y, float z) |
| 254 | { |
| 255 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 256 | m->loadTranslate(x, y, z); |
| 257 | } |
| 258 | |
| 259 | static void SC_matrixLoadMultiply(rsc_Matrix *mat, const rsc_Matrix *lhs, const rsc_Matrix *rhs) |
| 260 | { |
| 261 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 262 | m->loadMultiply(reinterpret_cast<const Matrix *>(lhs), |
| 263 | reinterpret_cast<const Matrix *>(rhs)); |
| 264 | } |
| 265 | |
| 266 | static void SC_matrixMultiply(rsc_Matrix *mat, const rsc_Matrix *rhs) |
| 267 | { |
| 268 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 269 | m->multiply(reinterpret_cast<const Matrix *>(rhs)); |
| 270 | } |
| 271 | |
| 272 | static void SC_matrixRotate(rsc_Matrix *mat, float rot, float x, float y, float z) |
| 273 | { |
| 274 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 275 | m->rotate(rot, x, y, z); |
| 276 | } |
| 277 | |
| 278 | static void SC_matrixScale(rsc_Matrix *mat, float x, float y, float z) |
| 279 | { |
| 280 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 281 | m->scale(x, y, z); |
| 282 | } |
| 283 | |
| 284 | static void SC_matrixTranslate(rsc_Matrix *mat, float x, float y, float z) |
| 285 | { |
| 286 | Matrix *m = reinterpret_cast<Matrix *>(mat); |
| 287 | m->translate(x, y, z); |
| 288 | } |
| 289 | |
| 290 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 291 | ////////////////////////////////////////////////////////////////////////////// |
| 292 | // |
| 293 | ////////////////////////////////////////////////////////////////////////////// |
| 294 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 295 | static uint32_t SC_allocGetDimX(RsAllocation va) |
| 296 | { |
| 297 | GET_TLS(); |
| 298 | const Allocation *a = static_cast<const Allocation *>(va); |
| 299 | //LOGE("SC_allocGetDimX a=%p", a); |
| 300 | //LOGE(" type=%p", a->getType()); |
| 301 | return a->getType()->getDimX(); |
| 302 | } |
| 303 | |
| 304 | static uint32_t SC_allocGetDimY(RsAllocation va) |
| 305 | { |
| 306 | GET_TLS(); |
| 307 | const Allocation *a = static_cast<const Allocation *>(va); |
| 308 | return a->getType()->getDimY(); |
| 309 | } |
| 310 | |
| 311 | static uint32_t SC_allocGetDimZ(RsAllocation va) |
| 312 | { |
| 313 | GET_TLS(); |
| 314 | const Allocation *a = static_cast<const Allocation *>(va); |
| 315 | return a->getType()->getDimZ(); |
| 316 | } |
| 317 | |
| 318 | static uint32_t SC_allocGetDimLOD(RsAllocation va) |
| 319 | { |
| 320 | GET_TLS(); |
| 321 | const Allocation *a = static_cast<const Allocation *>(va); |
| 322 | return a->getType()->getDimLOD(); |
| 323 | } |
| 324 | |
| 325 | static uint32_t SC_allocGetDimFaces(RsAllocation va) |
| 326 | { |
| 327 | GET_TLS(); |
| 328 | const Allocation *a = static_cast<const Allocation *>(va); |
| 329 | return a->getType()->getDimFaces(); |
| 330 | } |
| 331 | |
| 332 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 333 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 334 | static void SC_debugF(const char *s, float f) { |
| 335 | LOGE("%s %f, 0x%08x", s, f, *((int *) (&f))); |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 336 | } |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 337 | static void SC_debugFv2(const char *s, rsvF_2 fv) { |
| 338 | float *f = (float *)&fv; |
| 339 | LOGE("%s {%f, %f}", s, f[0], f[1]); |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 340 | } |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 341 | static void SC_debugFv3(const char *s, rsvF_4 fv) { |
| 342 | float *f = (float *)&fv; |
| 343 | LOGE("%s {%f, %f, %f}", s, f[0], f[1], f[2]); |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 344 | } |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 345 | static void SC_debugFv4(const char *s, rsvF_4 fv) { |
| 346 | float *f = (float *)&fv; |
| 347 | LOGE("%s {%f, %f, %f, %f}", s, f[0], f[1], f[2], f[3]); |
| 348 | } |
| 349 | static void SC_debugI32(const char *s, int32_t i) { |
| 350 | LOGE("%s %i 0x%x", s, i, i); |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 353 | static uint32_t SC_toClient(void *data, int cmdID, int len, int waitForSpace) |
| 354 | { |
| 355 | GET_TLS(); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 356 | //LOGE("SC_toClient %i %i %i", cmdID, len, waitForSpace); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 357 | return rsc->sendMessageToClient(data, cmdID, len, waitForSpace != 0); |
| 358 | } |
| 359 | |
Jason Sams | bd2197f | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 360 | static void SC_scriptCall(int scriptID) |
| 361 | { |
| 362 | GET_TLS(); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 363 | rsc->runScript((Script *)scriptID); |
Jason Sams | bd2197f | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 366 | int SC_divsi3(int a, int b) |
| 367 | { |
| 368 | return a / b; |
| 369 | } |
Jason Sams | bd2197f | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 370 | |
Jason Sams | 1de0b87 | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 371 | int SC_getAllocation(const void *ptr) |
| 372 | { |
| 373 | GET_TLS(); |
| 374 | const Allocation *alloc = sc->ptrToAllocation(ptr); |
| 375 | return (int)alloc; |
| 376 | } |
| 377 | |
| 378 | |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 379 | void SC_ForEachii(RsScript vs, RsAllocation vin) |
| 380 | { |
| 381 | GET_TLS(); |
| 382 | Script *s = static_cast<Script *>(vs); |
| 383 | Allocation *ain = static_cast<Allocation *>(vin); |
| 384 | s->runForEach(rsc, ain, NULL); |
| 385 | } |
| 386 | |
| 387 | void SC_ForEachiii(RsScript vs, RsAllocation vin, RsAllocation vout) |
| 388 | { |
| 389 | GET_TLS(); |
| 390 | Script *s = static_cast<Script *>(vs); |
| 391 | Allocation *ain = static_cast<Allocation *>(vin); |
| 392 | Allocation *aout = static_cast<Allocation *>(vout); |
| 393 | s->runForEach(rsc, ain, aout); |
| 394 | } |
| 395 | |
| 396 | void SC_ForEachiiii(RsScript vs, RsAllocation vin, int xStart, int xEnd) |
| 397 | { |
| 398 | GET_TLS(); |
| 399 | Script *s = static_cast<Script *>(vs); |
| 400 | Allocation *ain = static_cast<Allocation *>(vin); |
| 401 | s->runForEach(rsc, ain, NULL, xStart, xEnd); |
| 402 | } |
| 403 | |
| 404 | void SC_ForEachiiiii(RsScript vs, RsAllocation vin, RsAllocation vout, int xStart, int xEnd) |
| 405 | { |
| 406 | GET_TLS(); |
| 407 | Script *s = static_cast<Script *>(vs); |
| 408 | Allocation *ain = static_cast<Allocation *>(vin); |
| 409 | Allocation *aout = static_cast<Allocation *>(vout); |
| 410 | s->runForEach(rsc, ain, aout, xStart, xEnd); |
| 411 | } |
| 412 | |
| 413 | void SC_ForEachiiiiii(RsScript vs, RsAllocation vin, int xStart, int yStart, int xEnd, int yEnd) |
| 414 | { |
| 415 | GET_TLS(); |
| 416 | Script *s = static_cast<Script *>(vs); |
| 417 | Allocation *ain = static_cast<Allocation *>(vin); |
| 418 | s->runForEach(rsc, ain, NULL, xStart, yStart, xEnd, yEnd); |
| 419 | } |
| 420 | |
| 421 | void SC_ForEachiiiiiii(RsScript vs, RsAllocation vin, RsAllocation vout, int xStart, int yStart, int xEnd, int yEnd) |
| 422 | { |
| 423 | GET_TLS(); |
| 424 | Script *s = static_cast<Script *>(vs); |
| 425 | Allocation *ain = static_cast<Allocation *>(vin); |
| 426 | Allocation *aout = static_cast<Allocation *>(vout); |
| 427 | s->runForEach(rsc, ain, aout, xStart, yStart, xEnd, yEnd); |
| 428 | } |
| 429 | |
| 430 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 431 | ////////////////////////////////////////////////////////////////////////////// |
| 432 | // Class implementation |
| 433 | ////////////////////////////////////////////////////////////////////////////// |
| 434 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 435 | // llvm name mangling ref |
| 436 | // <builtin-type> ::= v # void |
| 437 | // ::= b # bool |
| 438 | // ::= c # char |
| 439 | // ::= a # signed char |
| 440 | // ::= h # unsigned char |
| 441 | // ::= s # short |
| 442 | // ::= t # unsigned short |
| 443 | // ::= i # int |
| 444 | // ::= j # unsigned int |
| 445 | // ::= l # long |
| 446 | // ::= m # unsigned long |
| 447 | // ::= x # long long, __int64 |
| 448 | // ::= y # unsigned long long, __int64 |
| 449 | // ::= f # float |
| 450 | // ::= d # double |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 451 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 452 | static ScriptCState::SymbolTable_t gSyms[] = { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 453 | { "__divsi3", (void *)&SC_divsi3 }, |
| 454 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 455 | // allocation |
| 456 | { "rsAllocationGetDimX", (void *)&SC_allocGetDimX }, |
| 457 | { "rsAllocationGetDimY", (void *)&SC_allocGetDimY }, |
| 458 | { "rsAllocationGetDimZ", (void *)&SC_allocGetDimZ }, |
| 459 | { "rsAllocationGetDimLOD", (void *)&SC_allocGetDimLOD }, |
| 460 | { "rsAllocationGetDimFaces", (void *)&SC_allocGetDimFaces }, |
| 461 | { "rsGetAllocation", (void *)&SC_getAllocation }, |
| 462 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 463 | // Debug |
| 464 | { "_Z7rsDebugPKcf", (void *)&SC_debugF }, |
| 465 | { "_Z7rsDebugPKcDv2_f", (void *)&SC_debugFv2 }, |
| 466 | { "_Z7rsDebugPKcDv3_f", (void *)&SC_debugFv3 }, |
| 467 | { "_Z7rsDebugPKcDv4_f", (void *)&SC_debugFv4 }, |
| 468 | { "_Z7rsDebugPKci", (void *)&SC_debugI32 }, |
| 469 | //extern void __attribute__((overloadable))rsDebug(const char *, const void *); |
| 470 | |
| 471 | |
| 472 | // RS Math |
| 473 | { "_Z6rsRandi", (void *)&SC_randi }, |
| 474 | { "_Z6rsRandii", (void *)&SC_randi2 }, |
| 475 | { "_Z6rsRandf", (void *)&SC_randf }, |
| 476 | { "_Z6rsRandff", (void *)&SC_randf2 }, |
| 477 | { "_Z6rsFracf", (void *)&SC_frac }, |
| 478 | |
| 479 | // time |
| 480 | { "rsSecond", (void *)&SC_second }, |
| 481 | { "rsMinute", (void *)&SC_minute }, |
| 482 | { "rsHour", (void *)&SC_hour }, |
| 483 | { "rsDay", (void *)&SC_day }, |
| 484 | { "rsMonth", (void *)&SC_month }, |
| 485 | { "rsYear", (void *)&SC_year }, |
| 486 | { "rsUptimeMillis", (void*)&SC_uptimeMillis2 }, |
| 487 | { "rsStartTimeMillis", (void*)&SC_startTimeMillis2 }, |
| 488 | { "rsElapsedTimeMillis", (void*)&SC_elapsedTimeMillis2 }, |
| 489 | |
| 490 | { "rsSendToClient", (void *)&SC_toClient }, |
| 491 | |
| 492 | // matrix |
| 493 | { "rsMatrixLoadIdentity", (void *)&SC_matrixLoadIdentity }, |
| 494 | { "rsMatrixLoadFloat", (void *)&SC_matrixLoadFloat }, |
| 495 | { "rsMatrixLoadMat", (void *)&SC_matrixLoadMat }, |
| 496 | { "rsMatrixLoadRotate", (void *)&SC_matrixLoadRotate }, |
| 497 | { "rsMatrixLoadScale", (void *)&SC_matrixLoadScale }, |
| 498 | { "rsMatrixLoadTranslate", (void *)&SC_matrixLoadTranslate }, |
| 499 | { "rsMatrixLoadMultiply", (void *)&SC_matrixLoadMultiply }, |
| 500 | { "rsMatrixMultiply", (void *)&SC_matrixMultiply }, |
| 501 | { "rsMatrixRotate", (void *)&SC_matrixRotate }, |
| 502 | { "rsMatrixScale", (void *)&SC_matrixScale }, |
| 503 | { "rsMatrixTranslate", (void *)&SC_matrixTranslate }, |
| 504 | |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 505 | { "_Z9rsForEachii", (void *)&SC_ForEachii }, |
| 506 | { "_Z9rsForEachiii", (void *)&SC_ForEachiii }, |
| 507 | { "_Z9rsForEachiiii", (void *)&SC_ForEachiiii }, |
| 508 | { "_Z9rsForEachiiiii", (void *)&SC_ForEachiiiii }, |
| 509 | { "_Z9rsForEachiiiiii", (void *)&SC_ForEachiiiiii }, |
| 510 | { "_Z9rsForEachiiiiiii", (void *)&SC_ForEachiiiiiii }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 511 | |
| 512 | //////////////////////////////////////////////////////////////////// |
| 513 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 514 | //{ "sinf_fast", (void *)&SC_sinf_fast }, |
| 515 | //{ "cosf_fast", (void *)&SC_cosf_fast }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 516 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 517 | { "scriptCall", (void *)&SC_scriptCall }, |
Jason Sams | 1de0b87 | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 518 | |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 519 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 520 | { NULL, NULL } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 521 | }; |
| 522 | |
| 523 | const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) |
| 524 | { |
| 525 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 526 | |
| 527 | while (syms->mPtr) { |
| 528 | if (!strcmp(syms->mName, sym)) { |
| 529 | return syms; |
| 530 | } |
| 531 | syms++; |
| 532 | } |
| 533 | return NULL; |
| 534 | } |
| 535 | |