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 | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 182 | static int64_t SC_uptimeMillis() |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 183 | { |
| 184 | return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 185 | } |
| 186 | |
Jason Sams | f0690c4 | 2010-07-29 17:31:14 -0700 | [diff] [blame] | 187 | static int64_t SC_uptimeNanos() |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 188 | { |
Jason Sams | f0690c4 | 2010-07-29 17:31:14 -0700 | [diff] [blame] | 189 | return systemTime(SYSTEM_TIME_MONOTONIC); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 192 | static float SC_getDt() |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 193 | { |
| 194 | GET_TLS(); |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 195 | int64_t l = sc->mEnviroment.mLastDtTime; |
| 196 | sc->mEnviroment.mLastDtTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 197 | return ((float)(sc->mEnviroment.mLastDtTime - l)) / 1.0e9; |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 201 | ////////////////////////////////////////////////////////////////////////////// |
| 202 | // |
| 203 | ////////////////////////////////////////////////////////////////////////////// |
| 204 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 205 | static uint32_t SC_allocGetDimX(RsAllocation va) |
| 206 | { |
| 207 | GET_TLS(); |
| 208 | const Allocation *a = static_cast<const Allocation *>(va); |
| 209 | //LOGE("SC_allocGetDimX a=%p", a); |
| 210 | //LOGE(" type=%p", a->getType()); |
| 211 | return a->getType()->getDimX(); |
| 212 | } |
| 213 | |
| 214 | static uint32_t SC_allocGetDimY(RsAllocation va) |
| 215 | { |
| 216 | GET_TLS(); |
| 217 | const Allocation *a = static_cast<const Allocation *>(va); |
| 218 | return a->getType()->getDimY(); |
| 219 | } |
| 220 | |
| 221 | static uint32_t SC_allocGetDimZ(RsAllocation va) |
| 222 | { |
| 223 | GET_TLS(); |
| 224 | const Allocation *a = static_cast<const Allocation *>(va); |
| 225 | return a->getType()->getDimZ(); |
| 226 | } |
| 227 | |
| 228 | static uint32_t SC_allocGetDimLOD(RsAllocation va) |
| 229 | { |
| 230 | GET_TLS(); |
| 231 | const Allocation *a = static_cast<const Allocation *>(va); |
| 232 | return a->getType()->getDimLOD(); |
| 233 | } |
| 234 | |
| 235 | static uint32_t SC_allocGetDimFaces(RsAllocation va) |
| 236 | { |
| 237 | GET_TLS(); |
| 238 | const Allocation *a = static_cast<const Allocation *>(va); |
| 239 | return a->getType()->getDimFaces(); |
| 240 | } |
| 241 | |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 242 | const void * SC_getElementAtX(RsAllocation va, uint32_t x) |
| 243 | { |
| 244 | const Allocation *a = static_cast<const Allocation *>(va); |
| 245 | const Type *t = a->getType(); |
| 246 | const uint8_t *p = (const uint8_t *)a->getPtr(); |
| 247 | return &p[t->getElementSizeBytes() * x]; |
| 248 | } |
| 249 | |
| 250 | const void * SC_getElementAtXY(RsAllocation va, uint32_t x, uint32_t y) |
| 251 | { |
| 252 | const Allocation *a = static_cast<const Allocation *>(va); |
| 253 | const Type *t = a->getType(); |
| 254 | const uint8_t *p = (const uint8_t *)a->getPtr(); |
| 255 | return &p[t->getElementSizeBytes() * (x + y*t->getDimX())]; |
| 256 | } |
| 257 | |
| 258 | const void * SC_getElementAtXYZ(RsAllocation va, uint32_t x, uint32_t y, uint32_t z) |
| 259 | { |
| 260 | const Allocation *a = static_cast<const Allocation *>(va); |
| 261 | const Type *t = a->getType(); |
| 262 | const uint8_t *p = (const uint8_t *)a->getPtr(); |
| 263 | return &p[t->getElementSizeBytes() * (x + y*t->getDimX())]; |
| 264 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 265 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 266 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 267 | static void SC_debugF(const char *s, float f) { |
| 268 | LOGE("%s %f, 0x%08x", s, f, *((int *) (&f))); |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 269 | } |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 270 | static void SC_debugFv2(const char *s, rsvF_2 fv) { |
| 271 | float *f = (float *)&fv; |
| 272 | LOGE("%s {%f, %f}", s, f[0], f[1]); |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 273 | } |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 274 | static void SC_debugFv3(const char *s, rsvF_4 fv) { |
| 275 | float *f = (float *)&fv; |
| 276 | LOGE("%s {%f, %f, %f}", s, f[0], f[1], f[2]); |
Jason Sams | b0ec1b4 | 2009-07-28 12:02:16 -0700 | [diff] [blame] | 277 | } |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 278 | static void SC_debugFv4(const char *s, rsvF_4 fv) { |
| 279 | float *f = (float *)&fv; |
| 280 | LOGE("%s {%f, %f, %f, %f}", s, f[0], f[1], f[2], f[3]); |
| 281 | } |
| 282 | static void SC_debugI32(const char *s, int32_t i) { |
| 283 | LOGE("%s %i 0x%x", s, i, i); |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 284 | } |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 285 | static void SC_debugU32(const char *s, uint32_t i) { |
| 286 | LOGE("%s %i 0x%x", s, i, i); |
| 287 | } |
Romain Guy | d22fff7 | 2009-08-20 17:08:33 -0700 | [diff] [blame] | 288 | |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 289 | static void SC_debugP(const char *s, const void *p) { |
| 290 | LOGE("%s %p", s, p); |
| 291 | } |
| 292 | |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 293 | static uint32_t SC_toClient2(int cmdID, void *data, int len) |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 294 | { |
| 295 | GET_TLS(); |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 296 | //LOGE("SC_toClient %i %i %i", cmdID, len); |
| 297 | return rsc->sendMessageToClient(data, cmdID, len, false); |
Jason Sams | 516c319 | 2009-10-06 13:58:47 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 300 | static uint32_t SC_toClient(int cmdID) |
Jason Sams | bd2197f | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 301 | { |
| 302 | GET_TLS(); |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 303 | //LOGE("SC_toClient %i", cmdID); |
| 304 | return rsc->sendMessageToClient(NULL, cmdID, 0, false); |
| 305 | } |
| 306 | |
| 307 | static uint32_t SC_toClientBlocking2(int cmdID, void *data, int len) |
| 308 | { |
| 309 | GET_TLS(); |
| 310 | //LOGE("SC_toClientBlocking %i %i", cmdID, len); |
| 311 | return rsc->sendMessageToClient(data, cmdID, len, true); |
| 312 | } |
| 313 | |
| 314 | static uint32_t SC_toClientBlocking(int cmdID) |
| 315 | { |
| 316 | GET_TLS(); |
| 317 | //LOGE("SC_toClientBlocking %i", cmdID); |
| 318 | return rsc->sendMessageToClient(NULL, cmdID, 0, true); |
Jason Sams | bd2197f | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 321 | int SC_divsi3(int a, int b) |
| 322 | { |
| 323 | return a / b; |
| 324 | } |
Jason Sams | bd2197f | 2009-10-07 18:14:01 -0700 | [diff] [blame] | 325 | |
Jason Sams | 1de0b87 | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 326 | int SC_getAllocation(const void *ptr) |
| 327 | { |
| 328 | GET_TLS(); |
| 329 | const Allocation *alloc = sc->ptrToAllocation(ptr); |
| 330 | return (int)alloc; |
| 331 | } |
| 332 | |
| 333 | |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 334 | void SC_ForEach(RsScript vs, |
| 335 | RsAllocation vin, |
| 336 | RsAllocation vout, |
| 337 | const void *usr) |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 338 | { |
| 339 | GET_TLS(); |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 340 | const Allocation *ain = static_cast<const Allocation *>(vin); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 341 | Allocation *aout = static_cast<Allocation *>(vout); |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 342 | Script *s = static_cast<Script *>(vs); |
| 343 | s->runForEach(rsc, ain, aout, usr); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 346 | void SC_ForEach2(RsScript vs, |
| 347 | RsAllocation vin, |
| 348 | RsAllocation vout, |
| 349 | const void *usr, |
| 350 | const RsScriptCall *call) |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 351 | { |
| 352 | GET_TLS(); |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 353 | const Allocation *ain = static_cast<const Allocation *>(vin); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 354 | Allocation *aout = static_cast<Allocation *>(vout); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 355 | Script *s = static_cast<Script *>(vs); |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 356 | s->runForEach(rsc, ain, aout, usr, call); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 359 | ////////////////////////////////////////////////////////////////////////////// |
| 360 | // Class implementation |
| 361 | ////////////////////////////////////////////////////////////////////////////// |
| 362 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 363 | // llvm name mangling ref |
| 364 | // <builtin-type> ::= v # void |
| 365 | // ::= b # bool |
| 366 | // ::= c # char |
| 367 | // ::= a # signed char |
| 368 | // ::= h # unsigned char |
| 369 | // ::= s # short |
| 370 | // ::= t # unsigned short |
| 371 | // ::= i # int |
| 372 | // ::= j # unsigned int |
| 373 | // ::= l # long |
| 374 | // ::= m # unsigned long |
| 375 | // ::= x # long long, __int64 |
| 376 | // ::= y # unsigned long long, __int64 |
| 377 | // ::= f # float |
| 378 | // ::= d # double |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 379 | |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 380 | static ScriptCState::SymbolTable_t gSyms[] = { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 381 | { "__divsi3", (void *)&SC_divsi3 }, |
| 382 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 383 | // allocation |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 384 | { "_Z19rsAllocationGetDimX13rs_allocation", (void *)&SC_allocGetDimX }, |
| 385 | { "_Z19rsAllocationGetDimY13rs_allocation", (void *)&SC_allocGetDimY }, |
| 386 | { "_Z19rsAllocationGetDimZ13rs_allocation", (void *)&SC_allocGetDimZ }, |
| 387 | { "_Z21rsAllocationGetDimLOD13rs_allocation", (void *)&SC_allocGetDimLOD }, |
| 388 | { "_Z23rsAllocationGetDimFaces13rs_allocation", (void *)&SC_allocGetDimFaces }, |
| 389 | { "_Z15rsGetAllocationPKv", (void *)&SC_getAllocation }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 390 | |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 391 | { "_Z14rsGetElementAt13rs_allocationj", (void *)&SC_getElementAtX }, |
| 392 | { "_Z14rsGetElementAt13rs_allocationjj", (void *)&SC_getElementAtXY }, |
| 393 | { "_Z14rsGetElementAt13rs_allocationjjj", (void *)&SC_getElementAtXYZ }, |
| 394 | |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 395 | // Debug |
| 396 | { "_Z7rsDebugPKcf", (void *)&SC_debugF }, |
| 397 | { "_Z7rsDebugPKcDv2_f", (void *)&SC_debugFv2 }, |
| 398 | { "_Z7rsDebugPKcDv3_f", (void *)&SC_debugFv3 }, |
| 399 | { "_Z7rsDebugPKcDv4_f", (void *)&SC_debugFv4 }, |
| 400 | { "_Z7rsDebugPKci", (void *)&SC_debugI32 }, |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 401 | { "_Z7rsDebugPKcj", (void *)&SC_debugU32 }, |
Jason Sams | 8e6c17f | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 402 | { "_Z7rsDebugPKcPKv", (void *)&SC_debugP }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 403 | |
| 404 | // RS Math |
| 405 | { "_Z6rsRandi", (void *)&SC_randi }, |
| 406 | { "_Z6rsRandii", (void *)&SC_randi2 }, |
| 407 | { "_Z6rsRandf", (void *)&SC_randf }, |
| 408 | { "_Z6rsRandff", (void *)&SC_randf2 }, |
| 409 | { "_Z6rsFracf", (void *)&SC_frac }, |
| 410 | |
| 411 | // time |
Jason Sams | f0690c4 | 2010-07-29 17:31:14 -0700 | [diff] [blame] | 412 | { "_Z8rsSecondv", (void *)&SC_second }, |
| 413 | { "_Z8rsMinutev", (void *)&SC_minute }, |
| 414 | { "_Z6rsHourv", (void *)&SC_hour }, |
| 415 | { "_Z5rsDayv", (void *)&SC_day }, |
| 416 | { "_Z7rsMonthv", (void *)&SC_month }, |
| 417 | { "_Z6rsYearv", (void *)&SC_year }, |
| 418 | { "_Z14rsUptimeMillisv", (void*)&SC_uptimeMillis }, |
| 419 | { "_Z13rsUptimeNanosv", (void*)&SC_uptimeNanos }, |
| 420 | { "_Z7rsGetDtv", (void*)&SC_getDt }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 421 | |
Jason Sams | 1796651 | 2010-07-28 11:17:53 -0700 | [diff] [blame] | 422 | { "_Z14rsSendToClienti", (void *)&SC_toClient }, |
| 423 | { "_Z14rsSendToClientiPKvj", (void *)&SC_toClient2 }, |
| 424 | { "_Z22rsSendToClientBlockingi", (void *)&SC_toClientBlocking }, |
| 425 | { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_toClientBlocking2 }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 426 | |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 427 | { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach }, |
| 428 | //{ "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach2 }, |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 429 | |
| 430 | //////////////////////////////////////////////////////////////////// |
| 431 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 432 | //{ "sinf_fast", (void *)&SC_sinf_fast }, |
| 433 | //{ "cosf_fast", (void *)&SC_cosf_fast }, |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 434 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 435 | { NULL, NULL } |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 436 | }; |
| 437 | |
| 438 | const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) |
| 439 | { |
| 440 | ScriptCState::SymbolTable_t *syms = gSyms; |
| 441 | |
| 442 | while (syms->mPtr) { |
| 443 | if (!strcmp(syms->mName, sym)) { |
| 444 | return syms; |
| 445 | } |
| 446 | syms++; |
| 447 | } |
| 448 | return NULL; |
| 449 | } |
| 450 | |