rsdRuntimeStubs.cpp revision 0ca7cbaea8d5cf18f25d1148be75fbb6e2d86c62
1/*
2 * Copyright (C) 2011-2012 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 "rsMatrix4x4.h"
20#include "rsMatrix3x3.h"
21#include "rsMatrix2x2.h"
22#include "rsRuntime.h"
23
24#include "rsdCore.h"
25#include "rsdBcc.h"
26
27#include "rsdAllocation.h"
28#include "rsdShaderCache.h"
29#include "rsdVertexArray.h"
30
31#include <time.h>
32
33using namespace android;
34using namespace android::renderscript;
35
36typedef float float2 __attribute__((ext_vector_type(2)));
37typedef float float3 __attribute__((ext_vector_type(3)));
38typedef float float4 __attribute__((ext_vector_type(4)));
39typedef double double2 __attribute__((ext_vector_type(2)));
40typedef double double3 __attribute__((ext_vector_type(3)));
41typedef double double4 __attribute__((ext_vector_type(4)));
42typedef char char2 __attribute__((ext_vector_type(2)));
43typedef char char3 __attribute__((ext_vector_type(3)));
44typedef char char4 __attribute__((ext_vector_type(4)));
45typedef unsigned char uchar2 __attribute__((ext_vector_type(2)));
46typedef unsigned char uchar3 __attribute__((ext_vector_type(3)));
47typedef unsigned char uchar4 __attribute__((ext_vector_type(4)));
48typedef int16_t short2 __attribute__((ext_vector_type(2)));
49typedef int16_t short3 __attribute__((ext_vector_type(3)));
50typedef int16_t short4 __attribute__((ext_vector_type(4)));
51typedef uint16_t ushort2 __attribute__((ext_vector_type(2)));
52typedef uint16_t ushort3 __attribute__((ext_vector_type(3)));
53typedef uint16_t ushort4 __attribute__((ext_vector_type(4)));
54typedef int32_t int2 __attribute__((ext_vector_type(2)));
55typedef int32_t int3 __attribute__((ext_vector_type(3)));
56typedef int32_t int4 __attribute__((ext_vector_type(4)));
57typedef uint32_t uint2 __attribute__((ext_vector_type(2)));
58typedef uint32_t uint3 __attribute__((ext_vector_type(3)));
59typedef uint32_t uint4 __attribute__((ext_vector_type(4)));
60typedef int64_t long2 __attribute__((ext_vector_type(2)));
61typedef int64_t long3 __attribute__((ext_vector_type(3)));
62typedef int64_t long4 __attribute__((ext_vector_type(4)));
63typedef uint64_t ulong2 __attribute__((ext_vector_type(2)));
64typedef uint64_t ulong3 __attribute__((ext_vector_type(3)));
65typedef uint64_t ulong4 __attribute__((ext_vector_type(4)));
66
67typedef uint8_t uchar;
68typedef uint16_t ushort;
69typedef uint32_t uint;
70#ifndef RS_SERVER
71typedef uint64_t ulong;
72#endif
73
74#ifndef __LP64__
75#define OPAQUETYPE(t) \
76    typedef struct { const int* const p; } __attribute__((packed, aligned(4))) t;
77#else
78#define OPAQUETYPE(t) \
79    typedef struct { const void* p; const void* r; const void* v1; const void* v2; } t;
80#endif
81
82OPAQUETYPE(rs_element)
83OPAQUETYPE(rs_type)
84OPAQUETYPE(rs_allocation)
85OPAQUETYPE(rs_sampler)
86OPAQUETYPE(rs_script)
87OPAQUETYPE(rs_script_call)
88
89OPAQUETYPE(rs_program_fragment);
90OPAQUETYPE(rs_program_store);
91OPAQUETYPE(rs_program_vertex);
92OPAQUETYPE(rs_program_raster);
93
94OPAQUETYPE(rs_mesh);
95OPAQUETYPE(rs_font);
96OPAQUETYPE(rs_path);
97
98#undef OPAQUETYPE
99
100typedef enum {
101    // Empty to avoid conflicting definitions with RsAllocationCubemapFace
102} rs_allocation_cubemap_face;
103
104typedef struct {
105    int tm_sec;     ///< seconds
106    int tm_min;     ///< minutes
107    int tm_hour;    ///< hours
108    int tm_mday;    ///< day of the month
109    int tm_mon;     ///< month
110    int tm_year;    ///< year
111    int tm_wday;    ///< day of the week
112    int tm_yday;    ///< day of the year
113    int tm_isdst;   ///< daylight savings time
114} rs_tm;
115
116#ifndef __LP64__
117typedef android::renderscript::rs_script RS_TY_SCRIPT;
118typedef android::renderscript::rs_allocation RS_TY_ALLOC;
119
120static inline Script* rsGetObjPtr(RS_TY_SCRIPT s) {
121    return const_cast<Script*>(s.p);
122}
123static inline Allocation* rsGetObjPtr(RS_TY_ALLOC a) {
124    return const_cast<Allocation*>(a.p);
125}
126static inline RS_TY_SCRIPT rsTyCast(::rs_script s) {
127    RS_TY_SCRIPT cast;
128    cast.p = (const Script*)s.p;
129    return cast;
130}
131static inline RS_TY_ALLOC rsTyCast(::rs_allocation a) {
132    RS_TY_ALLOC cast;
133    cast.p = (const Allocation*)a.p;
134    return cast;
135}
136#define RS_CAST(a)  rsTyCast(a)
137
138#else
139
140typedef android::renderscript::rs_script* RS_TY_SCRIPT;
141typedef android::renderscript::rs_allocation* RS_TY_ALLOC;
142
143static inline Script* rsGetObjPtr(RS_TY_SCRIPT s) {
144    return const_cast<Script*>(s->p);
145}
146static inline Allocation* rsGetObjPtr(RS_TY_ALLOC a) {
147    return const_cast<Allocation*>(a->p);
148}
149static inline RS_TY_SCRIPT rsTyCast(::rs_script *s) {
150    return reinterpret_cast<RS_TY_SCRIPT>(s);
151}
152static inline RS_TY_ALLOC rsTyCast(::rs_allocation *a) {
153    return reinterpret_cast<RS_TY_ALLOC>(a);
154}
155#define RS_CAST(a)  rsTyCast(&(a))
156
157#endif
158
159// Some RS functions are not threadsafe but can be called from an invoke
160// function.  Instead of summarily marking scripts that call these functions as
161// not-threadable we detect calls to them in the driver and sends a fatal error
162// message.
163static bool failIfInKernel(Context *rsc, const char *funcName) {
164    RsdHal *dc = (RsdHal *)rsc->mHal.drv;
165    RsdCpuReference *impl = (RsdCpuReference *) dc->mCpuRef;
166
167    if (impl->getInForEach()) {
168        char buf[256];
169        sprintf(buf, "Error: Call to unsupported function %s "
170                         "in kernel", funcName);
171        rsc->setError(RS_ERROR_FATAL_DRIVER, buf);
172        return true;
173    }
174    return false;
175}
176
177//////////////////////////////////////////////////////////////////////////////
178// Allocation
179//////////////////////////////////////////////////////////////////////////////
180
181
182static void SC_AllocationSyncAll2(RS_TY_ALLOC a, RsAllocationUsageType source) {
183    Context *rsc = RsdCpuReference::getTlsContext();
184    rsrAllocationSyncAll(rsc, rsGetObjPtr(a), source);
185}
186
187static void SC_AllocationSyncAll(RS_TY_ALLOC a) {
188    Context *rsc = RsdCpuReference::getTlsContext();
189    rsrAllocationSyncAll(rsc, rsGetObjPtr(a), RS_ALLOCATION_USAGE_SCRIPT);
190}
191
192#ifndef RS_COMPATIBILITY_LIB
193
194static void SC_AllocationCopy1DRange(RS_TY_ALLOC dstAlloc,
195                                     uint32_t dstOff,
196                                     uint32_t dstMip,
197                                     uint32_t count,
198                                     RS_TY_ALLOC srcAlloc,
199                                     uint32_t srcOff, uint32_t srcMip) {
200    Context *rsc = RsdCpuReference::getTlsContext();
201    if (failIfInKernel(rsc, "rsAllocationCopy1DRange"))
202        return;
203
204    rsrAllocationCopy1DRange(rsc, rsGetObjPtr(dstAlloc), dstOff, dstMip, count,
205                             rsGetObjPtr(srcAlloc), srcOff, srcMip);
206}
207
208static void SC_AllocationCopy2DRange(RS_TY_ALLOC dstAlloc,
209                                     uint32_t dstXoff, uint32_t dstYoff,
210                                     uint32_t dstMip, uint32_t dstFace,
211                                     uint32_t width, uint32_t height,
212                                     RS_TY_ALLOC srcAlloc,
213                                     uint32_t srcXoff, uint32_t srcYoff,
214                                     uint32_t srcMip, uint32_t srcFace) {
215    Context *rsc = RsdCpuReference::getTlsContext();
216    if (failIfInKernel(rsc, "rsAllocationCopy2DRange"))
217        return;
218
219    rsrAllocationCopy2DRange(rsc, rsGetObjPtr(dstAlloc),
220                             dstXoff, dstYoff, dstMip, dstFace,
221                             width, height, rsGetObjPtr(srcAlloc),
222                             srcXoff, srcYoff, srcMip, srcFace);
223}
224
225static void SC_AllocationIoSend(RS_TY_ALLOC alloc) {
226    Context *rsc = RsdCpuReference::getTlsContext();
227    if (failIfInKernel(rsc, "rsAllocationIoSend"))
228        return;
229
230    rsrAllocationIoSend(rsc, rsGetObjPtr(alloc));
231}
232
233
234static void SC_AllocationIoReceive(RS_TY_ALLOC alloc) {
235    Context *rsc = RsdCpuReference::getTlsContext();
236    if (failIfInKernel(rsc, "rsAllocationIoReceive"))
237        return;
238
239    rsrAllocationIoReceive(rsc, rsGetObjPtr(alloc));
240}
241
242#else
243
244static void SC_AllocationCopy1DRange(RS_TY_ALLOC dstAlloc,
245                                     uint32_t dstOff,
246                                     uint32_t dstMip,
247                                     uint32_t count,
248                                     RS_TY_ALLOC srcAlloc,
249                                     uint32_t srcOff, uint32_t srcMip) {
250    Context *rsc = RsdCpuReference::getTlsContext();
251    if (failIfInKernel(rsc, "rsAllocationCopy1DRange"))
252        return;
253
254    rsrAllocationCopy1DRange(rsc, rsGetObjPtr(dstAlloc), dstOff, dstMip, count,
255                             rsGetObjPtr(srcAlloc), srcOff, srcMip);
256}
257
258static void SC_AllocationCopy2DRange(RS_TY_ALLOC dstAlloc,
259                                     uint32_t dstXoff, uint32_t dstYoff,
260                                     uint32_t dstMip, uint32_t dstFace,
261                                     uint32_t width, uint32_t height,
262                                     RS_TY_ALLOC srcAlloc,
263                                     uint32_t srcXoff, uint32_t srcYoff,
264                                     uint32_t srcMip, uint32_t srcFace) {
265    Context *rsc = RsdCpuReference::getTlsContext();
266    if (failIfInKernel(rsc, "rsAllocationCopy2DRange"))
267        return;
268
269    rsrAllocationCopy2DRange(rsc, rsGetObjPtr(dstAlloc),
270                             dstXoff, dstYoff, dstMip, dstFace,
271                             width, height,
272                             rsGetObjPtr(srcAlloc),
273                             srcXoff, srcYoff, srcMip, srcFace);
274}
275
276static void SC_AllocationIoSend(RS_TY_ALLOC alloc) {
277    Context *rsc = RsdCpuReference::getTlsContext();
278    if (failIfInKernel(rsc, "rsAllocationIoSend"))
279        return;
280
281    rsrAllocationIoSend(rsc, rsGetObjPtr(alloc));
282}
283
284
285static void SC_AllocationIoReceive(RS_TY_ALLOC alloc) {
286    Context *rsc = RsdCpuReference::getTlsContext();
287    if (failIfInKernel(rsc, "rsAllocationIoReceive"))
288        return;
289
290    rsrAllocationIoReceive(rsc, rsGetObjPtr(alloc));
291}
292
293#endif
294
295#ifndef RS_COMPATIBILITY_LIB
296
297//////////////////////////////////////////////////////////////////////////////
298// Context
299//////////////////////////////////////////////////////////////////////////////
300
301static void SC_BindTexture(ProgramFragment *pf, uint32_t slot, Allocation *a) {
302    Context *rsc = RsdCpuReference::getTlsContext();
303    rsrBindTexture(rsc, pf, slot, a);
304}
305
306static void SC_BindVertexConstant(ProgramVertex *pv, uint32_t slot, Allocation *a) {
307    Context *rsc = RsdCpuReference::getTlsContext();
308    rsrBindConstant(rsc, pv, slot, a);
309}
310
311static void SC_BindFragmentConstant(ProgramFragment *pf, uint32_t slot, Allocation *a) {
312    Context *rsc = RsdCpuReference::getTlsContext();
313    rsrBindConstant(rsc, pf, slot, a);
314}
315
316static void SC_BindSampler(ProgramFragment *pf, uint32_t slot, Sampler *s) {
317    Context *rsc = RsdCpuReference::getTlsContext();
318    rsrBindSampler(rsc, pf, slot, s);
319}
320
321static void SC_BindProgramStore(ProgramStore *ps) {
322    Context *rsc = RsdCpuReference::getTlsContext();
323    rsrBindProgramStore(rsc, ps);
324}
325
326static void SC_BindProgramFragment(ProgramFragment *pf) {
327    Context *rsc = RsdCpuReference::getTlsContext();
328    rsrBindProgramFragment(rsc, pf);
329}
330
331static void SC_BindProgramVertex(ProgramVertex *pv) {
332    Context *rsc = RsdCpuReference::getTlsContext();
333    rsrBindProgramVertex(rsc, pv);
334}
335
336static void SC_BindProgramRaster(ProgramRaster *pr) {
337    Context *rsc = RsdCpuReference::getTlsContext();
338    rsrBindProgramRaster(rsc, pr);
339}
340
341static void SC_BindFrameBufferObjectColorTarget(Allocation *a, uint32_t slot) {
342    Context *rsc = RsdCpuReference::getTlsContext();
343    rsrBindFrameBufferObjectColorTarget(rsc, a, slot);
344}
345
346static void SC_BindFrameBufferObjectDepthTarget(Allocation *a) {
347    Context *rsc = RsdCpuReference::getTlsContext();
348    rsrBindFrameBufferObjectDepthTarget(rsc, a);
349}
350
351static void SC_ClearFrameBufferObjectColorTarget(uint32_t slot) {
352    Context *rsc = RsdCpuReference::getTlsContext();
353    rsrClearFrameBufferObjectColorTarget(rsc, slot);
354}
355
356static void SC_ClearFrameBufferObjectDepthTarget(Context *, Script *) {
357    Context *rsc = RsdCpuReference::getTlsContext();
358    rsrClearFrameBufferObjectDepthTarget(rsc);
359}
360
361static void SC_ClearFrameBufferObjectTargets(Context *, Script *) {
362    Context *rsc = RsdCpuReference::getTlsContext();
363    rsrClearFrameBufferObjectTargets(rsc);
364}
365
366
367//////////////////////////////////////////////////////////////////////////////
368// VP
369//////////////////////////////////////////////////////////////////////////////
370
371static void SC_VpLoadProjectionMatrix(const rsc_Matrix *m) {
372    Context *rsc = RsdCpuReference::getTlsContext();
373    rsrVpLoadProjectionMatrix(rsc, m);
374}
375
376static void SC_VpLoadModelMatrix(const rsc_Matrix *m) {
377    Context *rsc = RsdCpuReference::getTlsContext();
378    rsrVpLoadModelMatrix(rsc, m);
379}
380
381static void SC_VpLoadTextureMatrix(const rsc_Matrix *m) {
382    Context *rsc = RsdCpuReference::getTlsContext();
383    rsrVpLoadTextureMatrix(rsc, m);
384}
385
386static void SC_PfConstantColor(ProgramFragment *pf, float r, float g, float b, float a) {
387    Context *rsc = RsdCpuReference::getTlsContext();
388    rsrPfConstantColor(rsc, pf, r, g, b, a);
389}
390
391static void SC_VpGetProjectionMatrix(rsc_Matrix *m) {
392    Context *rsc = RsdCpuReference::getTlsContext();
393    rsrVpGetProjectionMatrix(rsc, m);
394}
395
396
397//////////////////////////////////////////////////////////////////////////////
398// Drawing
399//////////////////////////////////////////////////////////////////////////////
400
401static void SC_DrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1,
402                                 float x2, float y2, float z2, float u2, float v2,
403                                 float x3, float y3, float z3, float u3, float v3,
404                                 float x4, float y4, float z4, float u4, float v4) {
405    Context *rsc = RsdCpuReference::getTlsContext();
406
407    if (!rsc->setupCheck()) {
408        return;
409    }
410
411    RsdHal *dc = (RsdHal *)rsc->mHal.drv;
412    if (!dc->gl.shaderCache->setup(rsc)) {
413        return;
414    }
415
416    //ALOGE("Quad");
417    //ALOGE("%4.2f, %4.2f, %4.2f", x1, y1, z1);
418    //ALOGE("%4.2f, %4.2f, %4.2f", x2, y2, z2);
419    //ALOGE("%4.2f, %4.2f, %4.2f", x3, y3, z3);
420    //ALOGE("%4.2f, %4.2f, %4.2f", x4, y4, z4);
421
422    float vtx[] = {x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4};
423    const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
424
425    RsdVertexArray::Attrib attribs[2];
426    attribs[0].set(GL_FLOAT, 3, 12, false, (size_t)vtx, "ATTRIB_position");
427    attribs[1].set(GL_FLOAT, 2, 8, false, (size_t)tex, "ATTRIB_texture0");
428
429    RsdVertexArray va(attribs, 2);
430    va.setup(rsc);
431
432    RSD_CALL_GL(glDrawArrays, GL_TRIANGLE_FAN, 0, 4);
433}
434
435static void SC_DrawQuad(float x1, float y1, float z1,
436                        float x2, float y2, float z2,
437                        float x3, float y3, float z3,
438                        float x4, float y4, float z4) {
439    SC_DrawQuadTexCoords(x1, y1, z1, 0, 1,
440                         x2, y2, z2, 1, 1,
441                         x3, y3, z3, 1, 0,
442                         x4, y4, z4, 0, 0);
443}
444
445static void SC_DrawSpriteScreenspace(float x, float y, float z, float w, float h) {
446    Context *rsc = RsdCpuReference::getTlsContext();
447
448    ObjectBaseRef<const ProgramVertex> tmp(rsc->getProgramVertex());
449    rsc->setProgramVertex(rsc->getDefaultProgramVertex());
450    //rsc->setupCheck();
451
452    //GLint crop[4] = {0, h, w, -h};
453
454    float sh = rsc->getHeight();
455
456    SC_DrawQuad(x,   sh - y,     z,
457                x+w, sh - y,     z,
458                x+w, sh - (y+h), z,
459                x,   sh - (y+h), z);
460    rsc->setProgramVertex((ProgramVertex *)tmp.get());
461}
462
463static void SC_DrawRect(float x1, float y1, float x2, float y2, float z) {
464    SC_DrawQuad(x1, y2, z, x2, y2, z, x2, y1, z, x1, y1, z);
465}
466
467static void SC_DrawMesh(Mesh *m) {
468    Context *rsc = RsdCpuReference::getTlsContext();
469    rsrDrawMesh(rsc, m);
470}
471
472static void SC_DrawMeshPrimitive(Mesh *m, uint32_t primIndex) {
473    Context *rsc = RsdCpuReference::getTlsContext();
474    rsrDrawMeshPrimitive(rsc, m, primIndex);
475}
476
477static void SC_DrawMeshPrimitiveRange(Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len) {
478    Context *rsc = RsdCpuReference::getTlsContext();
479    rsrDrawMeshPrimitiveRange(rsc, m, primIndex, start, len);
480}
481
482static void SC_MeshComputeBoundingBox(Mesh *m,
483                               float *minX, float *minY, float *minZ,
484                               float *maxX, float *maxY, float *maxZ) {
485    Context *rsc = RsdCpuReference::getTlsContext();
486    rsrMeshComputeBoundingBox(rsc, m, minX, minY, minZ, maxX, maxY, maxZ);
487}
488
489
490
491//////////////////////////////////////////////////////////////////////////////
492//
493//////////////////////////////////////////////////////////////////////////////
494
495
496static void SC_Color(float r, float g, float b, float a) {
497    Context *rsc = RsdCpuReference::getTlsContext();
498    rsrColor(rsc, r, g, b, a);
499}
500
501static void SC_Finish() {
502    Context *rsc = RsdCpuReference::getTlsContext();
503    rsdGLFinish(rsc);
504}
505
506static void SC_ClearColor(float r, float g, float b, float a) {
507    Context *rsc = RsdCpuReference::getTlsContext();
508    rsrPrepareClear(rsc);
509    rsdGLClearColor(rsc, r, g, b, a);
510}
511
512static void SC_ClearDepth(float v) {
513    Context *rsc = RsdCpuReference::getTlsContext();
514    rsrPrepareClear(rsc);
515    rsdGLClearDepth(rsc, v);
516}
517
518static uint32_t SC_GetWidth() {
519    Context *rsc = RsdCpuReference::getTlsContext();
520    return rsrGetWidth(rsc);
521}
522
523static uint32_t SC_GetHeight() {
524    Context *rsc = RsdCpuReference::getTlsContext();
525    return rsrGetHeight(rsc);
526}
527
528static void SC_DrawTextAlloc(Allocation *a, int x, int y) {
529    Context *rsc = RsdCpuReference::getTlsContext();
530    rsrDrawTextAlloc(rsc, a, x, y);
531}
532
533static void SC_DrawText(const char *text, int x, int y) {
534    Context *rsc = RsdCpuReference::getTlsContext();
535    rsrDrawText(rsc, text, x, y);
536}
537
538static void SC_MeasureTextAlloc(Allocation *a,
539                         int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) {
540    Context *rsc = RsdCpuReference::getTlsContext();
541    rsrMeasureTextAlloc(rsc, a, left, right, top, bottom);
542}
543
544static void SC_MeasureText(const char *text,
545                    int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) {
546    Context *rsc = RsdCpuReference::getTlsContext();
547    rsrMeasureText(rsc, text, left, right, top, bottom);
548}
549
550static void SC_BindFont(Font *f) {
551    Context *rsc = RsdCpuReference::getTlsContext();
552    rsrBindFont(rsc, f);
553}
554
555static void SC_FontColor(float r, float g, float b, float a) {
556    Context *rsc = RsdCpuReference::getTlsContext();
557    rsrFontColor(rsc, r, g, b, a);
558}
559#endif
560
561
562//////////////////////////////////////////////////////////////////////////////
563//
564//////////////////////////////////////////////////////////////////////////////
565
566static void SC_ClearObject(rs_object_base *dst) {
567    Context *rsc = RsdCpuReference::getTlsContext();
568    rsrClearObject(rsc, dst);
569}
570
571static void SC_SetObject(rs_object_base *dst, rs_object_base  src) {
572    //    ALOGE("SC_SetObject: dst = %p, src = %p", dst, src.p);
573    //    ALOGE("SC_SetObject: dst[0] = %p", dst[0]);
574    Context *rsc = RsdCpuReference::getTlsContext();
575    rsrSetObject(rsc, dst, (ObjectBase*)src.p);
576}
577
578static bool SC_IsObject(rs_object_base o) {
579    Context *rsc = RsdCpuReference::getTlsContext();
580    return rsrIsObject(rsc, o);
581}
582
583#ifdef __LP64__
584static void SC_SetObject_ByRef(rs_object_base *dst, rs_object_base *src) {
585    //    ALOGE("SC_SetObject_ByRef: dst = %p, src = %p", dst, src->p);
586    Context *rsc = RsdCpuReference::getTlsContext();
587    rsrSetObject(rsc, dst, (ObjectBase*)src->p);
588}
589
590static bool SC_IsObject_ByRef(rs_object_base *o) {
591    Context *rsc = RsdCpuReference::getTlsContext();
592    return rsrIsObject(rsc, *o);
593}
594#endif
595
596
597#ifndef RS_COMPATIBILITY_LIB
598#ifndef __LP64__
599
600// i386 has different struct return passing to ARM; emulate with void*
601#ifdef __i386__
602static const void* SC_GetAllocation(const void *ptr) {
603    Context *rsc = RsdCpuReference::getTlsContext();
604    const Script *sc = RsdCpuReference::getTlsScript();
605    Allocation* alloc = rsdScriptGetAllocationForPointer(rsc, sc, ptr);
606    android::renderscript::rs_allocation obj = {0};
607    alloc->callUpdateCacheObject(rsc, &obj);
608    return (void*)obj.p;
609}
610#else
611// ARMv7/MIPS
612static const android::renderscript::rs_allocation SC_GetAllocation(const void *ptr) {
613    Context *rsc = RsdCpuReference::getTlsContext();
614    const Script *sc = RsdCpuReference::getTlsScript();
615    Allocation* alloc = rsdScriptGetAllocationForPointer(rsc, sc, ptr);
616    android::renderscript::rs_allocation obj = {0};
617    alloc->callUpdateCacheObject(rsc, &obj);
618    return obj;
619}
620#endif
621#else
622// AArch64/x86_64/MIPS64
623static const android::renderscript::rs_allocation SC_GetAllocation(const void *ptr) {
624    Context *rsc = RsdCpuReference::getTlsContext();
625    const Script *sc = RsdCpuReference::getTlsScript();
626    Allocation* alloc = rsdScriptGetAllocationForPointer(rsc, sc, ptr);
627    android::renderscript::rs_allocation obj = {0, 0, 0, 0};
628    alloc->callUpdateCacheObject(rsc, &obj);
629    return obj;
630}
631#endif
632#endif
633
634
635static void SC_ForEach_SAA(RS_TY_SCRIPT target, RS_TY_ALLOC in, RS_TY_ALLOC out) {
636    Context *rsc = RsdCpuReference::getTlsContext();
637    rsrForEach(rsc, rsGetObjPtr(target), rsGetObjPtr(in), rsGetObjPtr(out), nullptr, 0, nullptr);
638}
639
640static void SC_ForEach_SAAU(RS_TY_SCRIPT target, RS_TY_ALLOC in,
641                            RS_TY_ALLOC out, const void *usr) {
642    Context *rsc = RsdCpuReference::getTlsContext();
643    rsrForEach(rsc, rsGetObjPtr(target), rsGetObjPtr(in), rsGetObjPtr(out), usr, 0, nullptr);
644}
645
646static void SC_ForEach_SAAUS(RS_TY_SCRIPT target, RS_TY_ALLOC in,
647                             RS_TY_ALLOC out, const void *usr, const RsScriptCall *call) {
648    Context *rsc = RsdCpuReference::getTlsContext();
649    rsrForEach(rsc, rsGetObjPtr(target), rsGetObjPtr(in), rsGetObjPtr(out), usr, 0, call);
650}
651
652// These functions are only supported in 32-bit.
653#ifndef __LP64__
654static void SC_ForEach_SAAUL(RS_TY_SCRIPT target, RS_TY_ALLOC in,
655                             RS_TY_ALLOC out, const void *usr, uint32_t usrLen) {
656    Context *rsc = RsdCpuReference::getTlsContext();
657    rsrForEach(rsc, rsGetObjPtr(target), rsGetObjPtr(in), rsGetObjPtr(out), usr, usrLen, nullptr);
658}
659
660static void SC_ForEach_SAAULS(RS_TY_SCRIPT target, RS_TY_ALLOC in, RS_TY_ALLOC out,
661                              const void *usr, uint32_t usrLen, const RsScriptCall *call) {
662    Context *rsc = RsdCpuReference::getTlsContext();
663    rsrForEach(rsc, rsGetObjPtr(target), rsGetObjPtr(in), rsGetObjPtr(out), usr, usrLen, call);
664}
665#endif
666
667
668//////////////////////////////////////////////////////////////////////////////
669// Time routines
670//////////////////////////////////////////////////////////////////////////////
671
672static float SC_GetDt() {
673    Context *rsc = RsdCpuReference::getTlsContext();
674    const Script *sc = RsdCpuReference::getTlsScript();
675    return rsrGetDt(rsc, sc);
676}
677
678// #if !defined(RS_COMPATIBILITY_LIB) && defined(__LP64__)
679#ifdef __LP64__
680time_t SC_Time(time_t *timer) {
681    Context *rsc = RsdCpuReference::getTlsContext();
682    return rsrTime(rsc, timer);
683}
684#else
685static int SC_Time(int *timer) {
686    Context *rsc = RsdCpuReference::getTlsContext();
687    return rsrTime(rsc, (long*)timer);
688}
689#endif
690
691tm* SC_LocalTime(tm *local, time_t *timer) {
692    Context *rsc = RsdCpuReference::getTlsContext();
693    return rsrLocalTime(rsc, local, timer);
694}
695
696int64_t SC_UptimeMillis() {
697    Context *rsc = RsdCpuReference::getTlsContext();
698    return rsrUptimeMillis(rsc);
699}
700
701int64_t SC_UptimeNanos() {
702    Context *rsc = RsdCpuReference::getTlsContext();
703    return rsrUptimeNanos(rsc);
704}
705
706//////////////////////////////////////////////////////////////////////////////
707// Message routines
708//////////////////////////////////////////////////////////////////////////////
709
710static uint32_t SC_ToClient2(int cmdID, const void *data, uint32_t len) {
711    Context *rsc = RsdCpuReference::getTlsContext();
712    return rsrToClient(rsc, cmdID, data, len);
713}
714
715static uint32_t SC_ToClient(int cmdID) {
716    Context *rsc = RsdCpuReference::getTlsContext();
717    return rsrToClient(rsc, cmdID, (const void *)nullptr, 0);
718}
719
720static uint32_t SC_ToClientBlocking2(int cmdID, const void *data, uint32_t len) {
721    Context *rsc = RsdCpuReference::getTlsContext();
722    return rsrToClientBlocking(rsc, cmdID, data, len);
723}
724
725static uint32_t SC_ToClientBlocking(int cmdID) {
726    Context *rsc = RsdCpuReference::getTlsContext();
727    return rsrToClientBlocking(rsc, cmdID, (const void *)nullptr, 0);
728}
729
730
731static void * ElementAt1D(Allocation *a, RsDataType dt, uint32_t vecSize, uint32_t x) {
732    Context *rsc = RsdCpuReference::getTlsContext();
733    const Type *t = a->getType();
734    const Element *e = t->getElement();
735
736    char buf[256];
737    if (x >= t->getLODDimX(0)) {
738        sprintf(buf, "Out range ElementAt X %i of %i", x, t->getLODDimX(0));
739        rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
740        return nullptr;
741    }
742
743    if (vecSize > 0) {
744        if (vecSize != e->getVectorSize()) {
745            sprintf(buf, "Vector size mismatch for ElementAt %i of %i", vecSize, e->getVectorSize());
746            rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
747            return nullptr;
748        }
749
750        if (dt != e->getType()) {
751            sprintf(buf, "Data type mismatch for ElementAt %i of %i", dt, e->getType());
752            rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
753            return nullptr;
754        }
755    }
756
757    uint8_t *p = (uint8_t *)a->mHal.drvState.lod[0].mallocPtr;
758    const uint32_t eSize = e->getSizeBytes();
759    return &p[(eSize * x)];
760}
761
762static void * ElementAt2D(Allocation *a, RsDataType dt, uint32_t vecSize, uint32_t x, uint32_t y) {
763    Context *rsc = RsdCpuReference::getTlsContext();
764    const Type *t = a->getType();
765    const Element *e = t->getElement();
766
767    char buf[256];
768    if (x >= t->getLODDimX(0)) {
769        sprintf(buf, "Out range ElementAt X %i of %i", x, t->getLODDimX(0));
770        rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
771        return nullptr;
772    }
773
774    if (y >= t->getLODDimY(0)) {
775        sprintf(buf, "Out range ElementAt Y %i of %i", y, t->getLODDimY(0));
776        rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
777        return nullptr;
778    }
779
780    if (vecSize > 0) {
781        if (vecSize != e->getVectorSize()) {
782            sprintf(buf, "Vector size mismatch for ElementAt %i of %i", vecSize, e->getVectorSize());
783            rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
784            return nullptr;
785        }
786
787        if (dt != e->getType()) {
788            sprintf(buf, "Data type mismatch for ElementAt %i of %i", dt, e->getType());
789            rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
790            return nullptr;
791        }
792    }
793
794    uint8_t *p = (uint8_t *)a->mHal.drvState.lod[0].mallocPtr;
795    const uint32_t eSize = e->getSizeBytes();
796    const uint32_t stride = a->mHal.drvState.lod[0].stride;
797    return &p[(eSize * x) + (y * stride)];
798}
799
800static void * ElementAt3D(Allocation *a, RsDataType dt, uint32_t vecSize, uint32_t x, uint32_t y, uint32_t z) {
801    Context *rsc = RsdCpuReference::getTlsContext();
802    const Type *t = a->getType();
803    const Element *e = t->getElement();
804
805    char buf[256];
806    if (x >= t->getLODDimX(0)) {
807        sprintf(buf, "Out range ElementAt X %i of %i", x, t->getLODDimX(0));
808        rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
809        return nullptr;
810    }
811
812    if (y >= t->getLODDimY(0)) {
813        sprintf(buf, "Out range ElementAt Y %i of %i", y, t->getLODDimY(0));
814        rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
815        return nullptr;
816    }
817
818    if (z >= t->getLODDimZ(0)) {
819        sprintf(buf, "Out range ElementAt Z %i of %i", z, t->getLODDimZ(0));
820        rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
821        return nullptr;
822    }
823
824    if (vecSize > 0) {
825        if (vecSize != e->getVectorSize()) {
826            sprintf(buf, "Vector size mismatch for ElementAt %i of %i", vecSize, e->getVectorSize());
827            rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
828            return nullptr;
829        }
830
831        if (dt != e->getType()) {
832            sprintf(buf, "Data type mismatch for ElementAt %i of %i", dt, e->getType());
833            rsc->setError(RS_ERROR_FATAL_DEBUG, buf);
834            return nullptr;
835        }
836    }
837
838    uint8_t *p = (uint8_t *)a->mHal.drvState.lod[0].mallocPtr;
839    const uint32_t eSize = e->getSizeBytes();
840    const uint32_t stride = a->mHal.drvState.lod[0].stride;
841    return &p[(eSize * x) + (y * stride)];
842}
843
844static const void * SC_GetElementAt1D(RS_TY_ALLOC a, uint32_t x) {
845    return ElementAt1D(rsGetObjPtr(a), RS_TYPE_UNSIGNED_8, 0, x);
846}
847static const void * SC_GetElementAt2D(RS_TY_ALLOC a, uint32_t x, uint32_t y) {
848    return ElementAt2D(rsGetObjPtr(a), RS_TYPE_UNSIGNED_8, 0, x, y);
849}
850static const void * SC_GetElementAt3D(RS_TY_ALLOC a, uint32_t x, uint32_t y, uint32_t z) {
851    return ElementAt3D(rsGetObjPtr(a), RS_TYPE_UNSIGNED_8, 0, x, y, z);
852}
853
854static void SC_SetElementAt1D(RS_TY_ALLOC a, const void *ptr, uint32_t x) {
855    const Type *t = rsGetObjPtr(a)->getType();
856    const Element *e = t->getElement();
857    void *tmp = ElementAt1D(rsGetObjPtr(a), RS_TYPE_UNSIGNED_8, 0, x);
858    if (tmp != nullptr) {
859        memcpy(tmp, ptr, e->getSizeBytes());
860    }
861}
862static void SC_SetElementAt2D(RS_TY_ALLOC a, const void *ptr, uint32_t x, uint32_t y) {
863    const Type *t = rsGetObjPtr(a)->getType();
864    const Element *e = t->getElement();
865    void *tmp = ElementAt2D(rsGetObjPtr(a), RS_TYPE_UNSIGNED_8, 0, x, y);
866    if (tmp != nullptr) {
867        memcpy(tmp, ptr, e->getSizeBytes());
868    }
869}
870static void SC_SetElementAt3D(RS_TY_ALLOC a, const void *ptr, uint32_t x, uint32_t y, uint32_t z) {
871    const Type *t = rsGetObjPtr(a)->getType();
872    const Element *e = t->getElement();
873    void *tmp = ElementAt3D(rsGetObjPtr(a), RS_TYPE_UNSIGNED_8, 0, x, y, z);
874    if (tmp != nullptr) {
875        memcpy(tmp, ptr, e->getSizeBytes());
876    }
877}
878
879const void *rsGetElementAt(::rs_allocation a, uint32_t x) {
880    return SC_GetElementAt1D(RS_CAST(a), x);
881}
882
883const void *rsGetElementAt(::rs_allocation a, uint32_t x, uint32_t y) {
884    return SC_GetElementAt2D(RS_CAST(a), x, y);
885}
886
887const void *rsGetElementAt(::rs_allocation a, uint32_t x, uint32_t y, uint32_t z) {
888    return SC_GetElementAt3D(RS_CAST(a), x, y, z);
889}
890
891void rsSetElementAt(::rs_allocation a, const void *ptr, uint32_t x) {
892    SC_SetElementAt1D(RS_CAST(a), ptr, x);
893}
894
895void rsSetElementAt(::rs_allocation a, const void *ptr, uint32_t x, uint32_t y) {
896    SC_SetElementAt2D(RS_CAST(a), ptr, x, y);
897}
898
899void rsSetElementAt(::rs_allocation a, const void *ptr, uint32_t x, uint32_t y, uint32_t z) {
900    SC_SetElementAt3D(RS_CAST(a), ptr, x, y, z);
901}
902
903
904#define ELEMENT_AT(T, DT, VS)                                           \
905    static void SC_SetElementAt1_##T(RS_TY_ALLOC a, const T *val, uint32_t x) { \
906        void *r = ElementAt1D(rsGetObjPtr(a), DT, VS, x);               \
907        if (r != nullptr) ((T *)r)[0] = *val;                           \
908        else ALOGE("Error from %s", __PRETTY_FUNCTION__);               \
909    }                                                                   \
910    static void SC_SetElementAt2_##T(RS_TY_ALLOC a, const T * val, uint32_t x, uint32_t y) { \
911        void *r = ElementAt2D(rsGetObjPtr(a), DT, VS, x, y);            \
912        if (r != nullptr) ((T *)r)[0] = *val;                           \
913        else ALOGE("Error from %s", __PRETTY_FUNCTION__);               \
914    }                                                                   \
915    static void SC_SetElementAt3_##T(RS_TY_ALLOC a, const T * val, uint32_t x, uint32_t y, uint32_t z) { \
916        void *r = ElementAt3D(rsGetObjPtr(a), DT, VS, x, y, z);         \
917        if (r != nullptr) ((T *)r)[0] = *val;                           \
918        else ALOGE("Error from %s", __PRETTY_FUNCTION__);               \
919    }                                                                   \
920    static void SC_GetElementAt1_##T(RS_TY_ALLOC a, T *val, uint32_t x) { \
921        void *r = ElementAt1D(rsGetObjPtr(a), DT, VS, x);               \
922        if (r != nullptr) *val = ((T *)r)[0];                           \
923        else ALOGE("Error from %s", __PRETTY_FUNCTION__);               \
924    }                                                                   \
925    static void SC_GetElementAt2_##T(RS_TY_ALLOC a, T *val, uint32_t x, uint32_t y) { \
926        void *r = ElementAt2D(rsGetObjPtr(a), DT, VS, x, y);            \
927        if (r != nullptr) *val = ((T *)r)[0];                           \
928        else ALOGE("Error from %s", __PRETTY_FUNCTION__);               \
929    }                                                                   \
930    static void SC_GetElementAt3_##T(RS_TY_ALLOC a, T *val, uint32_t x, uint32_t y, uint32_t z) { \
931        void *r = ElementAt3D(rsGetObjPtr(a), DT, VS, x, y, z);         \
932        if (r != nullptr) *val = ((T *)r)[0];                           \
933        else ALOGE("Error from %s", __PRETTY_FUNCTION__);               \
934    }                                                                   \
935    void rsSetElementAt_##T(::rs_allocation a, const T *val, uint32_t x) { \
936        SC_SetElementAt1_##T(RS_CAST(a), val, x);                       \
937    }                                                                   \
938    void rsSetElementAt_##T(::rs_allocation a, const T *val, uint32_t x, uint32_t y) { \
939        SC_SetElementAt2_##T(RS_CAST(a), val, x, y);                    \
940    }                                                                   \
941    void rsSetElementAt_##T(::rs_allocation a, const T *val, uint32_t x, uint32_t y, uint32_t z) { \
942        SC_SetElementAt3_##T(RS_CAST(a), val, x, y, z);                 \
943    }                                                                   \
944    void rsGetElementAt_##T(::rs_allocation a, T *val, uint32_t x) {    \
945        SC_GetElementAt1_##T(RS_CAST(a), val, x);                       \
946    }                                                                   \
947    void rsGetElementAt_##T(::rs_allocation a, T *val, uint32_t x, uint32_t y) { \
948        SC_GetElementAt2_##T(RS_CAST(a), val, x, y);                    \
949    }                                                                   \
950    void rsGetElementAt_##T(::rs_allocation a, T *val, uint32_t x, uint32_t y, uint32_t z) { \
951        SC_GetElementAt3_##T(RS_CAST(a), val, x, y, z);                 \
952    }                                                                   \
953
954ELEMENT_AT(char, RS_TYPE_SIGNED_8, 1)
955ELEMENT_AT(char2, RS_TYPE_SIGNED_8, 2)
956ELEMENT_AT(char3, RS_TYPE_SIGNED_8, 3)
957ELEMENT_AT(char4, RS_TYPE_SIGNED_8, 4)
958ELEMENT_AT(uchar, RS_TYPE_UNSIGNED_8, 1)
959ELEMENT_AT(uchar2, RS_TYPE_UNSIGNED_8, 2)
960ELEMENT_AT(uchar3, RS_TYPE_UNSIGNED_8, 3)
961ELEMENT_AT(uchar4, RS_TYPE_UNSIGNED_8, 4)
962ELEMENT_AT(short, RS_TYPE_SIGNED_16, 1)
963ELEMENT_AT(short2, RS_TYPE_SIGNED_16, 2)
964ELEMENT_AT(short3, RS_TYPE_SIGNED_16, 3)
965ELEMENT_AT(short4, RS_TYPE_SIGNED_16, 4)
966ELEMENT_AT(ushort, RS_TYPE_UNSIGNED_16, 1)
967ELEMENT_AT(ushort2, RS_TYPE_UNSIGNED_16, 2)
968ELEMENT_AT(ushort3, RS_TYPE_UNSIGNED_16, 3)
969ELEMENT_AT(ushort4, RS_TYPE_UNSIGNED_16, 4)
970ELEMENT_AT(int, RS_TYPE_SIGNED_32, 1)
971ELEMENT_AT(int2, RS_TYPE_SIGNED_32, 2)
972ELEMENT_AT(int3, RS_TYPE_SIGNED_32, 3)
973ELEMENT_AT(int4, RS_TYPE_SIGNED_32, 4)
974ELEMENT_AT(uint, RS_TYPE_UNSIGNED_32, 1)
975ELEMENT_AT(uint2, RS_TYPE_UNSIGNED_32, 2)
976ELEMENT_AT(uint3, RS_TYPE_UNSIGNED_32, 3)
977ELEMENT_AT(uint4, RS_TYPE_UNSIGNED_32, 4)
978ELEMENT_AT(long, RS_TYPE_SIGNED_64, 1)
979ELEMENT_AT(long2, RS_TYPE_SIGNED_64, 2)
980ELEMENT_AT(long3, RS_TYPE_SIGNED_64, 3)
981ELEMENT_AT(long4, RS_TYPE_SIGNED_64, 4)
982ELEMENT_AT(ulong, RS_TYPE_UNSIGNED_64, 1)
983ELEMENT_AT(ulong2, RS_TYPE_UNSIGNED_64, 2)
984ELEMENT_AT(ulong3, RS_TYPE_UNSIGNED_64, 3)
985ELEMENT_AT(ulong4, RS_TYPE_UNSIGNED_64, 4)
986ELEMENT_AT(float, RS_TYPE_FLOAT_32, 1)
987ELEMENT_AT(float2, RS_TYPE_FLOAT_32, 2)
988ELEMENT_AT(float3, RS_TYPE_FLOAT_32, 3)
989ELEMENT_AT(float4, RS_TYPE_FLOAT_32, 4)
990ELEMENT_AT(double, RS_TYPE_FLOAT_64, 1)
991ELEMENT_AT(double2, RS_TYPE_FLOAT_64, 2)
992ELEMENT_AT(double3, RS_TYPE_FLOAT_64, 3)
993ELEMENT_AT(double4, RS_TYPE_FLOAT_64, 4)
994
995#undef ELEMENT_AT
996
997#ifndef __LP64__
998/*
999 * We miss some symbols for rs{Get,Set}Element_long,ulong variants because 64
1000 * bit integer values are 'long' in RS-land but might be 'long long' in the
1001 * driver.  Define native_long* and native_ulong* types to be vectors of
1002 * 'long' as seen by the driver and define overloaded versions of
1003 * rsSetElementAt_* and rsGetElementAt_*.  This should get us the correct
1004 * mangled names in the driver.
1005 */
1006
1007typedef long native_long2 __attribute__((ext_vector_type(2)));
1008typedef long native_long3 __attribute__((ext_vector_type(3)));
1009typedef long native_long4 __attribute__((ext_vector_type(4)));
1010typedef unsigned long native_ulong2 __attribute__((ext_vector_type(2)));
1011typedef unsigned long native_ulong3 __attribute__((ext_vector_type(3)));
1012typedef unsigned long native_ulong4 __attribute__((ext_vector_type(4)));
1013
1014#define ELEMENT_AT_OVERLOADS(T, U) \
1015    void rsSetElementAt_##T(::rs_allocation a, const U *val, uint32_t x) { \
1016        SC_SetElementAt1_##T(RS_CAST(a), (T *) val, x); \
1017    } \
1018    void rsSetElementAt_##T(::rs_allocation a, const U *val, uint32_t x, uint32_t y) { \
1019        SC_SetElementAt2_##T(RS_CAST(a), (T *) val, x, y); \
1020    } \
1021    void rsSetElementAt_##T(::rs_allocation a, const U *val, uint32_t x, uint32_t y, uint32_t z) { \
1022        SC_SetElementAt3_##T(RS_CAST(a), (T *) val, x, y, z); \
1023    } \
1024    void rsGetElementAt_##T(::rs_allocation a, U *val, uint32_t x) { \
1025        SC_GetElementAt1_##T(RS_CAST(a), (T *) val, x); \
1026    } \
1027    void rsGetElementAt_##T(::rs_allocation a, U *val, uint32_t x, uint32_t y) { \
1028        SC_GetElementAt2_##T(RS_CAST(a), (T *) val, x, y); \
1029    } \
1030    void rsGetElementAt_##T(::rs_allocation a, U *val, uint32_t x, uint32_t y, uint32_t z) { \
1031        SC_GetElementAt3_##T(RS_CAST(a), (T *) val, x, y, z); \
1032    } \
1033
1034ELEMENT_AT_OVERLOADS(long2, native_long2)
1035ELEMENT_AT_OVERLOADS(long3, native_long3)
1036ELEMENT_AT_OVERLOADS(long4, native_long4)
1037ELEMENT_AT_OVERLOADS(ulong, unsigned long)
1038ELEMENT_AT_OVERLOADS(ulong2, native_ulong2)
1039ELEMENT_AT_OVERLOADS(ulong3, native_ulong3)
1040ELEMENT_AT_OVERLOADS(ulong4, native_ulong4)
1041
1042// We also need variants of rs{Get,Set}ElementAt_long that take 'long long *' as
1043// we might have this overloaded variant in old APKs.
1044ELEMENT_AT_OVERLOADS(long, long long)
1045
1046#undef ELEMENT_AT_OVERLOADS
1047#endif
1048
1049
1050//////////////////////////////////////////////////////////////////////////////
1051// Stub implementation
1052//////////////////////////////////////////////////////////////////////////////
1053
1054// llvm name mangling ref
1055//  <builtin-type> ::= v  # void
1056//                 ::= b  # bool
1057//                 ::= c  # char
1058//                 ::= a  # signed char
1059//                 ::= h  # unsigned char
1060//                 ::= s  # short
1061//                 ::= t  # unsigned short
1062//                 ::= i  # int
1063//                 ::= j  # unsigned int
1064//                 ::= l  # long
1065//                 ::= m  # unsigned long
1066//                 ::= x  # long long, __int64
1067//                 ::= y  # unsigned long long, __int64
1068//                 ::= f  # float
1069//                 ::= d  # double
1070
1071static RsdCpuReference::CpuSymbol gSyms[] = {
1072    // Debug runtime
1073    { "_Z14rsGetElementAt13rs_allocationj", (void *)&SC_GetElementAt1D, true },
1074    { "_Z14rsGetElementAt13rs_allocationjj", (void *)&SC_GetElementAt2D, true },
1075    { "_Z14rsGetElementAt13rs_allocationjjj", (void *)&SC_GetElementAt3D, true },
1076    { "_Z14rsSetElementAt13rs_allocationPKvj", (void *)&SC_SetElementAt1D, true },
1077    { "_Z14rsSetElementAt13rs_allocationPKvjj", (void *)&SC_SetElementAt2D, true },
1078    { "_Z14rsSetElementAt13rs_allocationPKvjjj", (void *)&SC_SetElementAt3D, true },
1079
1080
1081    { "_Z20rsGetElementAt_uchar13rs_allocationPhj", (void *)&SC_GetElementAt1_uchar, true },
1082    { "_Z21rsGetElementAt_uchar213rs_allocationPDv2_hj", (void *)&SC_GetElementAt1_uchar2, true },
1083    { "_Z21rsGetElementAt_uchar313rs_allocationPDv3_hj", (void *)&SC_GetElementAt1_uchar3, true },
1084    { "_Z21rsGetElementAt_uchar413rs_allocationPDv4_hj", (void *)&SC_GetElementAt1_uchar4, true },
1085    { "_Z20rsGetElementAt_uchar13rs_allocationPhjj", (void *)&SC_GetElementAt2_uchar, true },
1086    { "_Z21rsGetElementAt_uchar213rs_allocationPDv2_hjj", (void *)&SC_GetElementAt2_uchar2, true },
1087    { "_Z21rsGetElementAt_uchar313rs_allocationPDv3_hjj", (void *)&SC_GetElementAt2_uchar3, true },
1088    { "_Z21rsGetElementAt_uchar413rs_allocationPDv4_hjj", (void *)&SC_GetElementAt2_uchar4, true },
1089    { "_Z20rsGetElementAt_uchar13rs_allocationPhjjj", (void *)&SC_GetElementAt3_uchar, true },
1090    { "_Z21rsGetElementAt_uchar213rs_allocationPDv2_hjjj", (void *)&SC_GetElementAt3_uchar2, true },
1091    { "_Z21rsGetElementAt_uchar313rs_allocationPDv3_hjjj", (void *)&SC_GetElementAt3_uchar3, true },
1092    { "_Z21rsGetElementAt_uchar413rs_allocationPDv4_hjjj", (void *)&SC_GetElementAt3_uchar4, true },
1093
1094    { "_Z19rsGetElementAt_char13rs_allocationPcj", (void *)&SC_GetElementAt1_char, true },
1095    { "_Z20rsGetElementAt_char213rs_allocationPDv2_cj", (void *)&SC_GetElementAt1_char2, true },
1096    { "_Z20rsGetElementAt_char313rs_allocationPDv3_cj", (void *)&SC_GetElementAt1_char3, true },
1097    { "_Z20rsGetElementAt_char413rs_allocationPDv4_cj", (void *)&SC_GetElementAt1_char4, true },
1098    { "_Z19rsGetElementAt_char13rs_allocationPcjj", (void *)&SC_GetElementAt2_char, true },
1099    { "_Z20rsGetElementAt_char213rs_allocationPDv2_cjj", (void *)&SC_GetElementAt2_char2, true },
1100    { "_Z20rsGetElementAt_char313rs_allocationPDv3_cjj", (void *)&SC_GetElementAt2_char3, true },
1101    { "_Z20rsGetElementAt_char413rs_allocationPDv4_cjj", (void *)&SC_GetElementAt2_char4, true },
1102    { "_Z19rsGetElementAt_char13rs_allocationPcjjj", (void *)&SC_GetElementAt3_char, true },
1103    { "_Z20rsGetElementAt_char213rs_allocationPDv2_cjjj", (void *)&SC_GetElementAt3_char2, true },
1104    { "_Z20rsGetElementAt_char313rs_allocationPDv3_cjjj", (void *)&SC_GetElementAt3_char3, true },
1105    { "_Z20rsGetElementAt_char413rs_allocationPDv4_cjjj", (void *)&SC_GetElementAt3_char4, true },
1106
1107    { "_Z21rsGetElementAt_ushort13rs_allocationPtj", (void *)&SC_GetElementAt1_ushort, true },
1108    { "_Z22rsGetElementAt_ushort213rs_allocationPDv2_tj", (void *)&SC_GetElementAt1_ushort2, true },
1109    { "_Z22rsGetElementAt_ushort313rs_allocationPDv3_tj", (void *)&SC_GetElementAt1_ushort3, true },
1110    { "_Z22rsGetElementAt_ushort413rs_allocationPDv4_tj", (void *)&SC_GetElementAt1_ushort4, true },
1111    { "_Z21rsGetElementAt_ushort13rs_allocationPtjj", (void *)&SC_GetElementAt2_ushort, true },
1112    { "_Z22rsGetElementAt_ushort213rs_allocationPDv2_tjj", (void *)&SC_GetElementAt2_ushort2, true },
1113    { "_Z22rsGetElementAt_ushort313rs_allocationPDv3_tjj", (void *)&SC_GetElementAt2_ushort3, true },
1114    { "_Z22rsGetElementAt_ushort413rs_allocationPDv4_tjj", (void *)&SC_GetElementAt2_ushort4, true },
1115    { "_Z21rsGetElementAt_ushort13rs_allocationPtjjj", (void *)&SC_GetElementAt3_ushort, true },
1116    { "_Z22rsGetElementAt_ushort213rs_allocationPDv2_tjjj", (void *)&SC_GetElementAt3_ushort2, true },
1117    { "_Z22rsGetElementAt_ushort313rs_allocationPDv3_tjjj", (void *)&SC_GetElementAt3_ushort3, true },
1118    { "_Z22rsGetElementAt_ushort413rs_allocationPDv4_tjjj", (void *)&SC_GetElementAt3_ushort4, true },
1119
1120    { "_Z20rsGetElementAt_short13rs_allocationPsj", (void *)&SC_GetElementAt1_short, true },
1121    { "_Z21rsGetElementAt_short213rs_allocationPDv2_sj", (void *)&SC_GetElementAt1_short2, true },
1122    { "_Z21rsGetElementAt_short313rs_allocationPDv3_sj", (void *)&SC_GetElementAt1_short3, true },
1123    { "_Z21rsGetElementAt_short413rs_allocationPDv4_sj", (void *)&SC_GetElementAt1_short4, true },
1124    { "_Z20rsGetElementAt_short13rs_allocationPsjj", (void *)&SC_GetElementAt2_short, true },
1125    { "_Z21rsGetElementAt_short213rs_allocationPDv2_sjj", (void *)&SC_GetElementAt2_short2, true },
1126    { "_Z21rsGetElementAt_short313rs_allocationPDv3_sjj", (void *)&SC_GetElementAt2_short3, true },
1127    { "_Z21rsGetElementAt_short413rs_allocationPDv4_sjj", (void *)&SC_GetElementAt2_short4, true },
1128    { "_Z20rsGetElementAt_short13rs_allocationPsjjj", (void *)&SC_GetElementAt3_short, true },
1129    { "_Z21rsGetElementAt_short213rs_allocationPDv2_sjjj", (void *)&SC_GetElementAt3_short2, true },
1130    { "_Z21rsGetElementAt_short313rs_allocationPDv3_sjjj", (void *)&SC_GetElementAt3_short3, true },
1131    { "_Z21rsGetElementAt_short413rs_allocationPDv4_sjjj", (void *)&SC_GetElementAt3_short4, true },
1132
1133    { "_Z19rsGetElementAt_uint13rs_allocationPjj", (void *)&SC_GetElementAt1_uint, true },
1134    { "_Z20rsGetElementAt_uint213rs_allocationPDv2_jj", (void *)&SC_GetElementAt1_uint2, true },
1135    { "_Z20rsGetElementAt_uint313rs_allocationPDv3_jj", (void *)&SC_GetElementAt1_uint3, true },
1136    { "_Z20rsGetElementAt_uint413rs_allocationPDv4_jj", (void *)&SC_GetElementAt1_uint4, true },
1137    { "_Z19rsGetElementAt_uint13rs_allocationPjjj", (void *)&SC_GetElementAt2_uint, true },
1138    { "_Z20rsGetElementAt_uint213rs_allocationPDv2_jjj", (void *)&SC_GetElementAt2_uint2, true },
1139    { "_Z20rsGetElementAt_uint313rs_allocationPDv3_jjj", (void *)&SC_GetElementAt2_uint3, true },
1140    { "_Z20rsGetElementAt_uint413rs_allocationPDv4_jjj", (void *)&SC_GetElementAt2_uint4, true },
1141    { "_Z19rsGetElementAt_uint13rs_allocationPjjjj", (void *)&SC_GetElementAt3_uint, true },
1142    { "_Z20rsGetElementAt_uint213rs_allocationPDv2_jjjj", (void *)&SC_GetElementAt3_uint2, true },
1143    { "_Z20rsGetElementAt_uint313rs_allocationPDv3_jjjj", (void *)&SC_GetElementAt3_uint3, true },
1144    { "_Z20rsGetElementAt_uint413rs_allocationPDv4_jjjj", (void *)&SC_GetElementAt3_uint4, true },
1145
1146    { "_Z18rsGetElementAt_int13rs_allocationPij", (void *)&SC_GetElementAt1_int, true },
1147    { "_Z19rsGetElementAt_int213rs_allocationPDv2_ij", (void *)&SC_GetElementAt1_int2, true },
1148    { "_Z19rsGetElementAt_int313rs_allocationPDv3_ij", (void *)&SC_GetElementAt1_int3, true },
1149    { "_Z19rsGetElementAt_int413rs_allocationPDv4_ij", (void *)&SC_GetElementAt1_int4, true },
1150    { "_Z18rsGetElementAt_int13rs_allocationPijj", (void *)&SC_GetElementAt2_int, true },
1151    { "_Z19rsGetElementAt_int213rs_allocationPDv2_ijj", (void *)&SC_GetElementAt2_int2, true },
1152    { "_Z19rsGetElementAt_int313rs_allocationPDv3_ijj", (void *)&SC_GetElementAt2_int3, true },
1153    { "_Z19rsGetElementAt_int413rs_allocationPDv4_ijj", (void *)&SC_GetElementAt2_int4, true },
1154    { "_Z18rsGetElementAt_int13rs_allocationPijjj", (void *)&SC_GetElementAt3_int, true },
1155    { "_Z19rsGetElementAt_int213rs_allocationPDv2_ijjj", (void *)&SC_GetElementAt3_int2, true },
1156    { "_Z19rsGetElementAt_int313rs_allocationPDv3_ijjj", (void *)&SC_GetElementAt3_int3, true },
1157    { "_Z19rsGetElementAt_int413rs_allocationPDv4_ijjj", (void *)&SC_GetElementAt3_int4, true },
1158
1159    { "_Z20rsGetElementAt_ulong13rs_allocationPmj", (void *)&SC_GetElementAt1_ulong, true },
1160    { "_Z21rsGetElementAt_ulong213rs_allocationPDv2_mj", (void *)&SC_GetElementAt1_ulong2, true },
1161    { "_Z21rsGetElementAt_ulong313rs_allocationPDv3_mj", (void *)&SC_GetElementAt1_ulong3, true },
1162    { "_Z21rsGetElementAt_ulong413rs_allocationPDv4_mj", (void *)&SC_GetElementAt1_ulong4, true },
1163    { "_Z20rsGetElementAt_ulong13rs_allocationPmjj", (void *)&SC_GetElementAt2_ulong, true },
1164    { "_Z21rsGetElementAt_ulong213rs_allocationPDv2_mjj", (void *)&SC_GetElementAt2_ulong2, true },
1165    { "_Z21rsGetElementAt_ulong313rs_allocationPDv3_mjj", (void *)&SC_GetElementAt2_ulong3, true },
1166    { "_Z21rsGetElementAt_ulong413rs_allocationPDv4_mjj", (void *)&SC_GetElementAt2_ulong4, true },
1167    { "_Z20rsGetElementAt_ulong13rs_allocationPmjjj", (void *)&SC_GetElementAt3_ulong, true },
1168    { "_Z21rsGetElementAt_ulong213rs_allocationPDv2_mjjj", (void *)&SC_GetElementAt3_ulong2, true },
1169    { "_Z21rsGetElementAt_ulong313rs_allocationPDv3_mjjj", (void *)&SC_GetElementAt3_ulong3, true },
1170    { "_Z21rsGetElementAt_ulong413rs_allocationPDv4_mjjj", (void *)&SC_GetElementAt3_ulong4, true },
1171
1172    { "_Z19rsGetElementAt_long13rs_allocationPlj", (void *)&SC_GetElementAt1_long, true },
1173    { "_Z20rsGetElementAt_long213rs_allocationPDv2_lj", (void *)&SC_GetElementAt1_long2, true },
1174    { "_Z20rsGetElementAt_long313rs_allocationPDv3_lj", (void *)&SC_GetElementAt1_long3, true },
1175    { "_Z20rsGetElementAt_long413rs_allocationPDv4_lj", (void *)&SC_GetElementAt1_long4, true },
1176    { "_Z19rsGetElementAt_long13rs_allocationPljj", (void *)&SC_GetElementAt2_long, true },
1177    { "_Z20rsGetElementAt_long213rs_allocationPDv2_ljj", (void *)&SC_GetElementAt2_long2, true },
1178    { "_Z20rsGetElementAt_long313rs_allocationPDv3_ljj", (void *)&SC_GetElementAt2_long3, true },
1179    { "_Z20rsGetElementAt_long413rs_allocationPDv4_ljj", (void *)&SC_GetElementAt2_long4, true },
1180    { "_Z19rsGetElementAt_long13rs_allocationPljjj", (void *)&SC_GetElementAt3_long, true },
1181    { "_Z20rsGetElementAt_long213rs_allocationPDv2_ljjj", (void *)&SC_GetElementAt3_long2, true },
1182    { "_Z20rsGetElementAt_long313rs_allocationPDv3_ljjj", (void *)&SC_GetElementAt3_long3, true },
1183    { "_Z20rsGetElementAt_long413rs_allocationPDv4_ljjj", (void *)&SC_GetElementAt3_long4, true },
1184
1185    { "_Z20rsGetElementAt_float13rs_allocationPfj", (void *)&SC_GetElementAt1_float, true },
1186    { "_Z21rsGetElementAt_float213rs_allocationPDv2_fj", (void *)&SC_GetElementAt1_float2, true },
1187    { "_Z21rsGetElementAt_float313rs_allocationPDv3_fj", (void *)&SC_GetElementAt1_float3, true },
1188    { "_Z21rsGetElementAt_float413rs_allocationPDv4_fj", (void *)&SC_GetElementAt1_float4, true },
1189    { "_Z20rsGetElementAt_float13rs_allocationPfjj", (void *)&SC_GetElementAt2_float, true },
1190    { "_Z21rsGetElementAt_float213rs_allocationPDv2_fjj", (void *)&SC_GetElementAt2_float2, true },
1191    { "_Z21rsGetElementAt_float313rs_allocationPDv3_fjj", (void *)&SC_GetElementAt2_float3, true },
1192    { "_Z21rsGetElementAt_float413rs_allocationPDv4_fjj", (void *)&SC_GetElementAt2_float4, true },
1193    { "_Z20rsGetElementAt_float13rs_allocationPfjjj", (void *)&SC_GetElementAt3_float, true },
1194    { "_Z21rsGetElementAt_float213rs_allocationPDv2_fjjj", (void *)&SC_GetElementAt3_float2, true },
1195    { "_Z21rsGetElementAt_float313rs_allocationPDv3_fjjj", (void *)&SC_GetElementAt3_float3, true },
1196    { "_Z21rsGetElementAt_float413rs_allocationPDv4_fjjj", (void *)&SC_GetElementAt3_float4, true },
1197
1198    { "_Z21rsGetElementAt_double13rs_allocationPdj", (void *)&SC_GetElementAt1_double, true },
1199    { "_Z22rsGetElementAt_double213rs_allocationPDv2_dj", (void *)&SC_GetElementAt1_double2, true },
1200    { "_Z22rsGetElementAt_double313rs_allocationPDv3_dj", (void *)&SC_GetElementAt1_double3, true },
1201    { "_Z22rsGetElementAt_double413rs_allocationPDv4_dj", (void *)&SC_GetElementAt1_double4, true },
1202    { "_Z21rsGetElementAt_double13rs_allocationPdjj", (void *)&SC_GetElementAt2_double, true },
1203    { "_Z22rsGetElementAt_double213rs_allocationPDv2_djj", (void *)&SC_GetElementAt2_double2, true },
1204    { "_Z22rsGetElementAt_double313rs_allocationPDv3_djj", (void *)&SC_GetElementAt2_double3, true },
1205    { "_Z22rsGetElementAt_double413rs_allocationPDv4_djj", (void *)&SC_GetElementAt2_double4, true },
1206    { "_Z21rsGetElementAt_double13rs_allocationPdjjj", (void *)&SC_GetElementAt3_double, true },
1207    { "_Z22rsGetElementAt_double213rs_allocationPDv2_djjj", (void *)&SC_GetElementAt3_double2, true },
1208    { "_Z22rsGetElementAt_double313rs_allocationPDv3_djjj", (void *)&SC_GetElementAt3_double3, true },
1209    { "_Z22rsGetElementAt_double413rs_allocationPDv4_djjj", (void *)&SC_GetElementAt3_double4, true },
1210
1211
1212
1213    { "_Z20rsSetElementAt_uchar13rs_allocationPKhj", (void *)&SC_SetElementAt1_uchar, true },
1214    { "_Z21rsSetElementAt_uchar213rs_allocationPKDv2_hj", (void *)&SC_SetElementAt1_uchar2, true },
1215    { "_Z21rsSetElementAt_uchar313rs_allocationPKDv3_hj", (void *)&SC_SetElementAt1_uchar3, true },
1216    { "_Z21rsSetElementAt_uchar413rs_allocationPKDv4_hj", (void *)&SC_SetElementAt1_uchar4, true },
1217    { "_Z20rsSetElementAt_uchar13rs_allocationPKhjj", (void *)&SC_SetElementAt2_uchar, true },
1218    { "_Z21rsSetElementAt_uchar213rs_allocationPKDv2_hjj", (void *)&SC_SetElementAt2_uchar2, true },
1219    { "_Z21rsSetElementAt_uchar313rs_allocationPKDv3_hjj", (void *)&SC_SetElementAt2_uchar3, true },
1220    { "_Z21rsSetElementAt_uchar413rs_allocationPKDv4_hjj", (void *)&SC_SetElementAt2_uchar4, true },
1221    { "_Z20rsSetElementAt_uchar13rs_allocationPKhjjj", (void *)&SC_SetElementAt3_uchar, true },
1222    { "_Z21rsSetElementAt_uchar213rs_allocationPKDv2_hjjj", (void *)&SC_SetElementAt3_uchar2, true },
1223    { "_Z21rsSetElementAt_uchar313rs_allocationPKDv3_hjjj", (void *)&SC_SetElementAt3_uchar3, true },
1224    { "_Z21rsSetElementAt_uchar413rs_allocationPKDv4_hjjj", (void *)&SC_SetElementAt3_uchar4, true },
1225
1226    { "_Z19rsSetElementAt_char13rs_allocationPKcj", (void *)&SC_SetElementAt1_char, true },
1227    { "_Z20rsSetElementAt_char213rs_allocationPKDv2_cj", (void *)&SC_SetElementAt1_char2, true },
1228    { "_Z20rsSetElementAt_char313rs_allocationPKDv3_cj", (void *)&SC_SetElementAt1_char3, true },
1229    { "_Z20rsSetElementAt_char413rs_allocationPKDv4_cj", (void *)&SC_SetElementAt1_char4, true },
1230    { "_Z19rsSetElementAt_char13rs_allocationPKcjj", (void *)&SC_SetElementAt2_char, true },
1231    { "_Z20rsSetElementAt_char213rs_allocationPKDv2_cjj", (void *)&SC_SetElementAt2_char2, true },
1232    { "_Z20rsSetElementAt_char313rs_allocationPKDv3_cjj", (void *)&SC_SetElementAt2_char3, true },
1233    { "_Z20rsSetElementAt_char413rs_allocationPKDv4_cjj", (void *)&SC_SetElementAt2_char4, true },
1234    { "_Z19rsSetElementAt_char13rs_allocationPKcjjj", (void *)&SC_SetElementAt3_char, true },
1235    { "_Z20rsSetElementAt_char213rs_allocationPKDv2_cjjj", (void *)&SC_SetElementAt3_char2, true },
1236    { "_Z20rsSetElementAt_char313rs_allocationPKDv3_cjjj", (void *)&SC_SetElementAt3_char3, true },
1237    { "_Z20rsSetElementAt_char413rs_allocationPKDv4_cjjj", (void *)&SC_SetElementAt3_char4, true },
1238
1239    { "_Z21rsSetElementAt_ushort13rs_allocationPKtj", (void *)&SC_SetElementAt1_ushort, true },
1240    { "_Z22rsSetElementAt_ushort213rs_allocationPKDv2_tj", (void *)&SC_SetElementAt1_ushort2, true },
1241    { "_Z22rsSetElementAt_ushort313rs_allocationPKDv3_tj", (void *)&SC_SetElementAt1_ushort3, true },
1242    { "_Z22rsSetElementAt_ushort413rs_allocationPKDv4_tj", (void *)&SC_SetElementAt1_ushort4, true },
1243    { "_Z21rsSetElementAt_ushort13rs_allocationPKtjj", (void *)&SC_SetElementAt2_ushort, true },
1244    { "_Z22rsSetElementAt_ushort213rs_allocationPKDv2_tjj", (void *)&SC_SetElementAt2_ushort2, true },
1245    { "_Z22rsSetElementAt_ushort313rs_allocationPKDv3_tjj", (void *)&SC_SetElementAt2_ushort3, true },
1246    { "_Z22rsSetElementAt_ushort413rs_allocationPKDv4_tjj", (void *)&SC_SetElementAt2_ushort4, true },
1247    { "_Z21rsSetElementAt_ushort13rs_allocationPKtjjj", (void *)&SC_SetElementAt3_ushort, true },
1248    { "_Z22rsSetElementAt_ushort213rs_allocationPKDv2_tjjj", (void *)&SC_SetElementAt3_ushort2, true },
1249    { "_Z22rsSetElementAt_ushort313rs_allocationPKDv3_tjjj", (void *)&SC_SetElementAt3_ushort3, true },
1250    { "_Z22rsSetElementAt_ushort413rs_allocationPKDv4_tjjj", (void *)&SC_SetElementAt3_ushort4, true },
1251
1252    { "_Z20rsSetElementAt_short13rs_allocationPKsj", (void *)&SC_SetElementAt1_short, true },
1253    { "_Z21rsSetElementAt_short213rs_allocationPKDv2_sj", (void *)&SC_SetElementAt1_short2, true },
1254    { "_Z21rsSetElementAt_short313rs_allocationPKDv3_sj", (void *)&SC_SetElementAt1_short3, true },
1255    { "_Z21rsSetElementAt_short413rs_allocationPKDv4_sj", (void *)&SC_SetElementAt1_short4, true },
1256    { "_Z20rsSetElementAt_short13rs_allocationPKsjj", (void *)&SC_SetElementAt2_short, true },
1257    { "_Z21rsSetElementAt_short213rs_allocationPKDv2_sjj", (void *)&SC_SetElementAt2_short2, true },
1258    { "_Z21rsSetElementAt_short313rs_allocationPKDv3_sjj", (void *)&SC_SetElementAt2_short3, true },
1259    { "_Z21rsSetElementAt_short413rs_allocationPKDv4_sjj", (void *)&SC_SetElementAt2_short4, true },
1260    { "_Z20rsSetElementAt_short13rs_allocationPKsjjj", (void *)&SC_SetElementAt3_short, true },
1261    { "_Z21rsSetElementAt_short213rs_allocationPKDv2_sjjj", (void *)&SC_SetElementAt3_short2, true },
1262    { "_Z21rsSetElementAt_short313rs_allocationPKDv3_sjjj", (void *)&SC_SetElementAt3_short3, true },
1263    { "_Z21rsSetElementAt_short413rs_allocationPKDv4_sjjj", (void *)&SC_SetElementAt3_short4, true },
1264
1265    { "_Z19rsSetElementAt_uint13rs_allocationPKjj", (void *)&SC_SetElementAt1_uint, true },
1266    { "_Z20rsSetElementAt_uint213rs_allocationPKDv2_jj", (void *)&SC_SetElementAt1_uint2, true },
1267    { "_Z20rsSetElementAt_uint313rs_allocationPKDv3_jj", (void *)&SC_SetElementAt1_uint3, true },
1268    { "_Z20rsSetElementAt_uint413rs_allocationPKDv4_jj", (void *)&SC_SetElementAt1_uint4, true },
1269    { "_Z19rsSetElementAt_uint13rs_allocationPKjjj", (void *)&SC_SetElementAt2_uint, true },
1270    { "_Z20rsSetElementAt_uint213rs_allocationPKDv2_jjj", (void *)&SC_SetElementAt2_uint2, true },
1271    { "_Z20rsSetElementAt_uint313rs_allocationPKDv3_jjj", (void *)&SC_SetElementAt2_uint3, true },
1272    { "_Z20rsSetElementAt_uint413rs_allocationPKDv4_jjj", (void *)&SC_SetElementAt2_uint4, true },
1273    { "_Z19rsSetElementAt_uint13rs_allocationPKjjjj", (void *)&SC_SetElementAt3_uint, true },
1274    { "_Z20rsSetElementAt_uint213rs_allocationPKDv2_jjjj", (void *)&SC_SetElementAt3_uint2, true },
1275    { "_Z20rsSetElementAt_uint313rs_allocationPKDv3_jjjj", (void *)&SC_SetElementAt3_uint3, true },
1276    { "_Z20rsSetElementAt_uint413rs_allocationPKDv4_jjjj", (void *)&SC_SetElementAt3_uint4, true },
1277
1278    { "_Z18rsSetElementAt_int13rs_allocationPKij", (void *)&SC_SetElementAt1_int, true },
1279    { "_Z19rsSetElementAt_int213rs_allocationPKDv2_ij", (void *)&SC_SetElementAt1_int2, true },
1280    { "_Z19rsSetElementAt_int313rs_allocationPKDv3_ij", (void *)&SC_SetElementAt1_int3, true },
1281    { "_Z19rsSetElementAt_int413rs_allocationPKDv4_ij", (void *)&SC_SetElementAt1_int4, true },
1282    { "_Z18rsSetElementAt_int13rs_allocationPKijj", (void *)&SC_SetElementAt2_int, true },
1283    { "_Z19rsSetElementAt_int213rs_allocationPKDv2_ijj", (void *)&SC_SetElementAt2_int2, true },
1284    { "_Z19rsSetElementAt_int313rs_allocationPKDv3_ijj", (void *)&SC_SetElementAt2_int3, true },
1285    { "_Z19rsSetElementAt_int413rs_allocationPKDv4_ijj", (void *)&SC_SetElementAt2_int4, true },
1286    { "_Z18rsSetElementAt_int13rs_allocationPKijjj", (void *)&SC_SetElementAt3_int, true },
1287    { "_Z19rsSetElementAt_int213rs_allocationPKDv2_ijjj", (void *)&SC_SetElementAt3_int2, true },
1288    { "_Z19rsSetElementAt_int313rs_allocationPKDv3_ijjj", (void *)&SC_SetElementAt3_int3, true },
1289    { "_Z19rsSetElementAt_int413rs_allocationPKDv4_ijjj", (void *)&SC_SetElementAt3_int4, true },
1290
1291    { "_Z20rsSetElementAt_ulong13rs_allocationPKmj", (void *)&SC_SetElementAt1_ulong, true },
1292    { "_Z21rsSetElementAt_ulong213rs_allocationPKDv2_mj", (void *)&SC_SetElementAt1_ulong2, true },
1293    { "_Z21rsSetElementAt_ulong313rs_allocationPKDv3_mj", (void *)&SC_SetElementAt1_ulong3, true },
1294    { "_Z21rsSetElementAt_ulong413rs_allocationPKDv4_mj", (void *)&SC_SetElementAt1_ulong4, true },
1295    { "_Z20rsSetElementAt_ulong13rs_allocationPKmjj", (void *)&SC_SetElementAt2_ulong, true },
1296    { "_Z21rsSetElementAt_ulong213rs_allocationPKDv2_mjj", (void *)&SC_SetElementAt2_ulong2, true },
1297    { "_Z21rsSetElementAt_ulong313rs_allocationPKDv3_mjj", (void *)&SC_SetElementAt2_ulong3, true },
1298    { "_Z21rsSetElementAt_ulong413rs_allocationPKDv4_mjj", (void *)&SC_SetElementAt2_ulong4, true },
1299    { "_Z20rsSetElementAt_ulong13rs_allocationPKmjjj", (void *)&SC_SetElementAt3_ulong, true },
1300    { "_Z21rsSetElementAt_ulong213rs_allocationPKDv2_mjjj", (void *)&SC_SetElementAt3_ulong2, true },
1301    { "_Z21rsSetElementAt_ulong313rs_allocationPKDv3_mjjj", (void *)&SC_SetElementAt3_ulong3, true },
1302    { "_Z21rsSetElementAt_ulong413rs_allocationPKDv4_mjjj", (void *)&SC_SetElementAt3_ulong4, true },
1303
1304    // Pre-21 compatibility path
1305    { "_Z20rsSetElementAt_ulong13rs_allocationPKyj", (void *)&SC_SetElementAt1_ulong, true },
1306    { "_Z21rsSetElementAt_ulong213rs_allocationPKDv2_yj", (void *)&SC_SetElementAt1_ulong2, true },
1307    { "_Z21rsSetElementAt_ulong313rs_allocationPKDv3_yj", (void *)&SC_SetElementAt1_ulong3, true },
1308    { "_Z21rsSetElementAt_ulong413rs_allocationPKDv4_yj", (void *)&SC_SetElementAt1_ulong4, true },
1309    { "_Z20rsSetElementAt_ulong13rs_allocationPKyjj", (void *)&SC_SetElementAt2_ulong, true },
1310    { "_Z21rsSetElementAt_ulong213rs_allocationPKDv2_yjj", (void *)&SC_SetElementAt2_ulong2, true },
1311    { "_Z21rsSetElementAt_ulong313rs_allocationPKDv3_yjj", (void *)&SC_SetElementAt2_ulong3, true },
1312    { "_Z21rsSetElementAt_ulong413rs_allocationPKDv4_yjj", (void *)&SC_SetElementAt2_ulong4, true },
1313    { "_Z20rsSetElementAt_ulong13rs_allocationPKyjjj", (void *)&SC_SetElementAt3_ulong, true },
1314    { "_Z21rsSetElementAt_ulong213rs_allocationPKDv2_yjjj", (void *)&SC_SetElementAt3_ulong2, true },
1315    { "_Z21rsSetElementAt_ulong313rs_allocationPKDv3_yjjj", (void *)&SC_SetElementAt3_ulong3, true },
1316    { "_Z21rsSetElementAt_ulong413rs_allocationPKDv4_yjjj", (void *)&SC_SetElementAt3_ulong4, true },
1317
1318    { "_Z19rsSetElementAt_long13rs_allocationPKlj", (void *)&SC_SetElementAt1_long, true },
1319    { "_Z20rsSetElementAt_long213rs_allocationPKDv2_lj", (void *)&SC_SetElementAt1_long2, true },
1320    { "_Z20rsSetElementAt_long313rs_allocationPKDv3_lj", (void *)&SC_SetElementAt1_long3, true },
1321    { "_Z20rsSetElementAt_long413rs_allocationPKDv4_lj", (void *)&SC_SetElementAt1_long4, true },
1322    { "_Z19rsSetElementAt_long13rs_allocationPKljj", (void *)&SC_SetElementAt2_long, true },
1323    { "_Z20rsSetElementAt_long213rs_allocationPKDv2_ljj", (void *)&SC_SetElementAt2_long2, true },
1324    { "_Z20rsSetElementAt_long313rs_allocationPKDv3_ljj", (void *)&SC_SetElementAt2_long3, true },
1325    { "_Z20rsSetElementAt_long413rs_allocationPKDv4_ljj", (void *)&SC_SetElementAt2_long4, true },
1326    { "_Z19rsSetElementAt_long13rs_allocationPKljjj", (void *)&SC_SetElementAt3_long, true },
1327    { "_Z20rsSetElementAt_long213rs_allocationPKDv2_ljjj", (void *)&SC_SetElementAt3_long2, true },
1328    { "_Z20rsSetElementAt_long313rs_allocationPKDv3_ljjj", (void *)&SC_SetElementAt3_long3, true },
1329    { "_Z20rsSetElementAt_long413rs_allocationPKDv4_ljjj", (void *)&SC_SetElementAt3_long4, true },
1330
1331    // Pre-21 compatibility path
1332    { "_Z19rsSetElementAt_long13rs_allocationPKxj", (void *)&SC_SetElementAt1_long, true },
1333    { "_Z20rsSetElementAt_long213rs_allocationPKDv2_xj", (void *)&SC_SetElementAt1_long2, true },
1334    { "_Z20rsSetElementAt_long313rs_allocationPKDv3_xj", (void *)&SC_SetElementAt1_long3, true },
1335    { "_Z20rsSetElementAt_long413rs_allocationPKDv4_xj", (void *)&SC_SetElementAt1_long4, true },
1336    { "_Z19rsSetElementAt_long13rs_allocationPKxjj", (void *)&SC_SetElementAt2_long, true },
1337    { "_Z20rsSetElementAt_long213rs_allocationPKDv2_xjj", (void *)&SC_SetElementAt2_long2, true },
1338    { "_Z20rsSetElementAt_long313rs_allocationPKDv3_xjj", (void *)&SC_SetElementAt2_long3, true },
1339    { "_Z20rsSetElementAt_long413rs_allocationPKDv4_xjj", (void *)&SC_SetElementAt2_long4, true },
1340    { "_Z19rsSetElementAt_long13rs_allocationPKxjjj", (void *)&SC_SetElementAt3_long, true },
1341    { "_Z20rsSetElementAt_long213rs_allocationPKDv2_xjjj", (void *)&SC_SetElementAt3_long2, true },
1342    { "_Z20rsSetElementAt_long313rs_allocationPKDv3_xjjj", (void *)&SC_SetElementAt3_long3, true },
1343    { "_Z20rsSetElementAt_long413rs_allocationPKDv4_xjjj", (void *)&SC_SetElementAt3_long4, true },
1344
1345    { "_Z20rsSetElementAt_float13rs_allocationPKfj", (void *)&SC_SetElementAt1_float, true },
1346    { "_Z21rsSetElementAt_float213rs_allocationPKDv2_fj", (void *)&SC_SetElementAt1_float2, true },
1347    { "_Z21rsSetElementAt_float313rs_allocationPKDv3_fj", (void *)&SC_SetElementAt1_float3, true },
1348    { "_Z21rsSetElementAt_float413rs_allocationPKDv4_fj", (void *)&SC_SetElementAt1_float4, true },
1349    { "_Z20rsSetElementAt_float13rs_allocationPKfjj", (void *)&SC_SetElementAt2_float, true },
1350    { "_Z21rsSetElementAt_float213rs_allocationPKDv2_fjj", (void *)&SC_SetElementAt2_float2, true },
1351    { "_Z21rsSetElementAt_float313rs_allocationPKDv3_fjj", (void *)&SC_SetElementAt2_float3, true },
1352    { "_Z21rsSetElementAt_float413rs_allocationPKDv4_fjj", (void *)&SC_SetElementAt2_float4, true },
1353    { "_Z20rsSetElementAt_float13rs_allocationPKfjjj", (void *)&SC_SetElementAt3_float, true },
1354    { "_Z21rsSetElementAt_float213rs_allocationPKDv2_fjjj", (void *)&SC_SetElementAt3_float2, true },
1355    { "_Z21rsSetElementAt_float313rs_allocationPKDv3_fjjj", (void *)&SC_SetElementAt3_float3, true },
1356    { "_Z21rsSetElementAt_float413rs_allocationPKDv4_fjjj", (void *)&SC_SetElementAt3_float4, true },
1357
1358    { "_Z21rsSetElementAt_double13rs_allocationPKdj", (void *)&SC_SetElementAt1_double, true },
1359    { "_Z22rsSetElementAt_double213rs_allocationPKDv2_dj", (void *)&SC_SetElementAt1_double2, true },
1360    { "_Z22rsSetElementAt_double313rs_allocationPKDv3_dj", (void *)&SC_SetElementAt1_double3, true },
1361    { "_Z22rsSetElementAt_double413rs_allocationPKDv4_dj", (void *)&SC_SetElementAt1_double4, true },
1362    { "_Z21rsSetElementAt_double13rs_allocationPKdjj", (void *)&SC_SetElementAt2_double, true },
1363    { "_Z22rsSetElementAt_double213rs_allocationPKDv2_djj", (void *)&SC_SetElementAt2_double2, true },
1364    { "_Z22rsSetElementAt_double313rs_allocationPKDv3_djj", (void *)&SC_SetElementAt2_double3, true },
1365    { "_Z22rsSetElementAt_double413rs_allocationPKDv4_djj", (void *)&SC_SetElementAt2_double4, true },
1366    { "_Z21rsSetElementAt_double13rs_allocationPKdjjj", (void *)&SC_SetElementAt3_double, true },
1367    { "_Z22rsSetElementAt_double213rs_allocationPKDv2_djjj", (void *)&SC_SetElementAt3_double2, true },
1368    { "_Z22rsSetElementAt_double313rs_allocationPKDv3_djjj", (void *)&SC_SetElementAt3_double3, true },
1369    { "_Z22rsSetElementAt_double413rs_allocationPKDv4_djjj", (void *)&SC_SetElementAt3_double4, true },
1370
1371
1372    // Refcounting
1373#ifndef __LP64__
1374    { "_Z11rsSetObjectP10rs_elementS_", (void *)&SC_SetObject, true },
1375    { "_Z10rsIsObject10rs_element", (void *)&SC_IsObject, true },
1376
1377    { "_Z11rsSetObjectP7rs_typeS_", (void *)&SC_SetObject, true },
1378    { "_Z10rsIsObject7rs_type", (void *)&SC_IsObject, true },
1379
1380    { "_Z11rsSetObjectP13rs_allocationS_", (void *)&SC_SetObject, true },
1381    { "_Z10rsIsObject13rs_allocation", (void *)&SC_IsObject, true },
1382
1383    { "_Z11rsSetObjectP10rs_samplerS_", (void *)&SC_SetObject, true },
1384    { "_Z10rsIsObject10rs_sampler", (void *)&SC_IsObject, true },
1385
1386    { "_Z11rsSetObjectP9rs_scriptS_", (void *)&SC_SetObject, true },
1387    { "_Z10rsIsObject9rs_script", (void *)&SC_IsObject, true },
1388#else
1389    { "_Z11rsSetObjectP10rs_elementS_", (void *)&SC_SetObject_ByRef, true },
1390    { "_Z10rsIsObject10rs_element", (void *)&SC_IsObject_ByRef, true },
1391
1392    { "_Z11rsSetObjectP7rs_typeS_", (void *)&SC_SetObject_ByRef, true },
1393    { "_Z10rsIsObject7rs_type", (void *)&SC_IsObject_ByRef, true },
1394
1395    { "_Z11rsSetObjectP13rs_allocationS_", (void *)&SC_SetObject_ByRef, true },
1396    { "_Z10rsIsObject13rs_allocation", (void *)&SC_IsObject_ByRef, true },
1397
1398    { "_Z11rsSetObjectP10rs_samplerS_", (void *)&SC_SetObject_ByRef, true },
1399    { "_Z10rsIsObject10rs_sampler", (void *)&SC_IsObject_ByRef, true },
1400
1401    { "_Z11rsSetObjectP9rs_scriptS_", (void *)&SC_SetObject_ByRef, true },
1402    { "_Z10rsIsObject9rs_script", (void *)&SC_IsObject_ByRef, true },
1403#endif
1404    { "_Z13rsClearObjectP10rs_element", (void *)&SC_ClearObject, true },
1405    { "_Z13rsClearObjectP7rs_type", (void *)&SC_ClearObject, true },
1406    { "_Z13rsClearObjectP13rs_allocation", (void *)&SC_ClearObject, true },
1407    { "_Z13rsClearObjectP10rs_sampler", (void *)&SC_ClearObject, true },
1408    { "_Z13rsClearObjectP9rs_script", (void *)&SC_ClearObject, true },
1409
1410    { "_Z11rsSetObjectP7rs_pathS_", (void *)&SC_SetObject, true },
1411    { "_Z13rsClearObjectP7rs_path", (void *)&SC_ClearObject, true },
1412    { "_Z10rsIsObject7rs_path", (void *)&SC_IsObject, true },
1413
1414    { "_Z11rsSetObjectP7rs_meshS_", (void *)&SC_SetObject, true },
1415    { "_Z13rsClearObjectP7rs_mesh", (void *)&SC_ClearObject, true },
1416    { "_Z10rsIsObject7rs_mesh", (void *)&SC_IsObject, true },
1417
1418    { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&SC_SetObject, true },
1419    { "_Z13rsClearObjectP19rs_program_fragment", (void *)&SC_ClearObject, true },
1420    { "_Z10rsIsObject19rs_program_fragment", (void *)&SC_IsObject, true },
1421
1422    { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&SC_SetObject, true },
1423    { "_Z13rsClearObjectP17rs_program_vertex", (void *)&SC_ClearObject, true },
1424    { "_Z10rsIsObject17rs_program_vertex", (void *)&SC_IsObject, true },
1425
1426    { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&SC_SetObject, true },
1427    { "_Z13rsClearObjectP17rs_program_raster", (void *)&SC_ClearObject, true },
1428    { "_Z10rsIsObject17rs_program_raster", (void *)&SC_IsObject, true },
1429
1430    { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&SC_SetObject, true },
1431    { "_Z13rsClearObjectP16rs_program_store", (void *)&SC_ClearObject, true },
1432    { "_Z10rsIsObject16rs_program_store", (void *)&SC_IsObject, true },
1433
1434    { "_Z11rsSetObjectP7rs_fontS_", (void *)&SC_SetObject, true },
1435    { "_Z13rsClearObjectP7rs_font", (void *)&SC_ClearObject, true },
1436    { "_Z10rsIsObject7rs_font", (void *)&SC_IsObject, true },
1437
1438    // Allocation ops
1439    { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_AllocationSyncAll, true },
1440    { "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_AllocationSyncAll, false },
1441    { "_Z20rsgAllocationSyncAll13rs_allocationj", (void *)&SC_AllocationSyncAll2, false },
1442    { "_Z20rsgAllocationSyncAll13rs_allocation24rs_allocation_usage_type", (void *)&SC_AllocationSyncAll2, false },
1443#ifndef RS_COMPATIBILITY_LIB
1444    { "_Z15rsGetAllocationPKv", (void *)&SC_GetAllocation, true },
1445    { "_Z18rsAllocationIoSend13rs_allocation", (void *)&SC_AllocationIoSend, false },
1446    { "_Z21rsAllocationIoReceive13rs_allocation", (void *)&SC_AllocationIoReceive, false },
1447#endif
1448    { "_Z23rsAllocationCopy1DRange13rs_allocationjjjS_jj", (void *)&SC_AllocationCopy1DRange, false },
1449    { "_Z23rsAllocationCopy2DRange13rs_allocationjjj26rs_allocation_cubemap_facejjS_jjjS0_", (void *)&SC_AllocationCopy2DRange, false },
1450
1451    // Messaging
1452
1453    { "_Z14rsSendToClienti", (void *)&SC_ToClient, false },
1454    { "_Z14rsSendToClientiPKvj", (void *)&SC_ToClient2, false },
1455    { "_Z22rsSendToClientBlockingi", (void *)&SC_ToClientBlocking, false },
1456    { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_ToClientBlocking2, false },
1457#ifndef RS_COMPATIBILITY_LIB
1458    { "_Z22rsgBindProgramFragment19rs_program_fragment", (void *)&SC_BindProgramFragment, false },
1459    { "_Z19rsgBindProgramStore16rs_program_store", (void *)&SC_BindProgramStore, false },
1460    { "_Z20rsgBindProgramVertex17rs_program_vertex", (void *)&SC_BindProgramVertex, false },
1461    { "_Z20rsgBindProgramRaster17rs_program_raster", (void *)&SC_BindProgramRaster, false },
1462    { "_Z14rsgBindSampler19rs_program_fragmentj10rs_sampler", (void *)&SC_BindSampler, false },
1463    { "_Z14rsgBindTexture19rs_program_fragmentj13rs_allocation", (void *)&SC_BindTexture, false },
1464    { "_Z15rsgBindConstant19rs_program_fragmentj13rs_allocation", (void *)&SC_BindFragmentConstant, false },
1465    { "_Z15rsgBindConstant17rs_program_vertexj13rs_allocation", (void *)&SC_BindVertexConstant, false },
1466
1467    { "_Z36rsgProgramVertexLoadProjectionMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadProjectionMatrix, false },
1468    { "_Z31rsgProgramVertexLoadModelMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadModelMatrix, false },
1469    { "_Z33rsgProgramVertexLoadTextureMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadTextureMatrix, false },
1470
1471    { "_Z35rsgProgramVertexGetProjectionMatrixP12rs_matrix4x4", (void *)&SC_VpGetProjectionMatrix, false },
1472
1473    { "_Z31rsgProgramFragmentConstantColor19rs_program_fragmentffff", (void *)&SC_PfConstantColor, false },
1474
1475    { "_Z11rsgGetWidthv", (void *)&SC_GetWidth, false },
1476    { "_Z12rsgGetHeightv", (void *)&SC_GetHeight, false },
1477
1478
1479    { "_Z11rsgDrawRectfffff", (void *)&SC_DrawRect, false },
1480    { "_Z11rsgDrawQuadffffffffffff", (void *)&SC_DrawQuad, false },
1481    { "_Z20rsgDrawQuadTexCoordsffffffffffffffffffff", (void *)&SC_DrawQuadTexCoords, false },
1482    { "_Z24rsgDrawSpriteScreenspacefffff", (void *)&SC_DrawSpriteScreenspace, false },
1483
1484    { "_Z11rsgDrawMesh7rs_mesh", (void *)&SC_DrawMesh, false },
1485    { "_Z11rsgDrawMesh7rs_meshj", (void *)&SC_DrawMeshPrimitive, false },
1486    { "_Z11rsgDrawMesh7rs_meshjjj", (void *)&SC_DrawMeshPrimitiveRange, false },
1487    { "_Z25rsgMeshComputeBoundingBox7rs_meshPfS0_S0_S0_S0_S0_", (void *)&SC_MeshComputeBoundingBox, false },
1488
1489    { "_Z13rsgClearColorffff", (void *)&SC_ClearColor, false },
1490    { "_Z13rsgClearDepthf", (void *)&SC_ClearDepth, false },
1491
1492    { "_Z11rsgDrawTextPKcii", (void *)&SC_DrawText, false },
1493    { "_Z11rsgDrawText13rs_allocationii", (void *)&SC_DrawTextAlloc, false },
1494    { "_Z14rsgMeasureTextPKcPiS1_S1_S1_", (void *)&SC_MeasureText, false },
1495    { "_Z14rsgMeasureText13rs_allocationPiS0_S0_S0_", (void *)&SC_MeasureTextAlloc, false },
1496
1497    { "_Z11rsgBindFont7rs_font", (void *)&SC_BindFont, false },
1498    { "_Z12rsgFontColorffff", (void *)&SC_FontColor, false },
1499
1500    { "_Z18rsgBindColorTarget13rs_allocationj", (void *)&SC_BindFrameBufferObjectColorTarget, false },
1501    { "_Z18rsgBindDepthTarget13rs_allocation", (void *)&SC_BindFrameBufferObjectDepthTarget, false },
1502    { "_Z19rsgClearColorTargetj", (void *)&SC_ClearFrameBufferObjectColorTarget, false },
1503    { "_Z19rsgClearDepthTargetv", (void *)&SC_ClearFrameBufferObjectDepthTarget, false },
1504    { "_Z24rsgClearAllRenderTargetsv", (void *)&SC_ClearFrameBufferObjectTargets, false },
1505
1506
1507    { "_Z9rsForEach9rs_script13rs_allocationS0_", (void *)&SC_ForEach_SAA, true },
1508    { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach_SAAU, true },
1509    { "_Z9rsForEach9rs_script13rs_allocationS0_PKvPK14rs_script_call", (void *)&SC_ForEach_SAAUS, true },
1510
1511    //rsForEach with usrdata is not supported in 64-bit
1512#ifndef __LP64__
1513    { "_Z9rsForEach9rs_script13rs_allocationS0_PKvj", (void *)&SC_ForEach_SAAUL, true },
1514    { "_Z9rsForEach9rs_script13rs_allocationS0_PKvjPK14rs_script_call", (void *)&SC_ForEach_SAAULS, true },
1515#endif
1516#endif // RS_COMPATIBILITY_LIB
1517
1518#ifndef __LP64__
1519    // time
1520    { "_Z6rsTimePi", (void *)&SC_Time, true },
1521    { "_Z11rsLocaltimeP5rs_tmPKi", (void *)&SC_LocalTime, true },
1522#else
1523    // time
1524    { "_Z6rsTimePl", (void *)&SC_Time, true },
1525    { "_Z11rsLocaltimeP5rs_tmPKl", (void *)&SC_LocalTime, true },
1526#endif
1527    { "_Z14rsUptimeMillisv", (void*)&SC_UptimeMillis, true },
1528    { "_Z13rsUptimeNanosv", (void*)&SC_UptimeNanos, true },
1529    { "_Z7rsGetDtv", (void*)&SC_GetDt, false },
1530
1531    // misc
1532#ifndef RS_COMPATIBILITY_LIB
1533    { "_Z5colorffff", (void *)&SC_Color, false },
1534    { "_Z9rsgFinishv", (void *)&SC_Finish, false },
1535#endif
1536
1537    { nullptr, nullptr, false }
1538};
1539
1540#ifndef RS_COMPATIBILITY_LIB
1541
1542typedef struct { unsigned int val; } rs_allocation_usage_type;
1543
1544void rsAllocationMarkDirty(::rs_allocation a) {
1545    return SC_AllocationSyncAll(RS_CAST(a));
1546}
1547
1548void rsgAllocationSyncAll(::rs_allocation a) {
1549    return SC_AllocationSyncAll(RS_CAST(a));
1550}
1551
1552void rsgAllocationSyncAll(::rs_allocation a,
1553                          unsigned int usage) {
1554    return SC_AllocationSyncAll2(RS_CAST(a), (RsAllocationUsageType) usage);
1555}
1556void rsgAllocationSyncAll(::rs_allocation a,
1557                          rs_allocation_usage_type source) {
1558    return SC_AllocationSyncAll2(RS_CAST(a), (RsAllocationUsageType) source.val);
1559}
1560
1561void rsgBindProgramFragment(::rs_program_fragment pf) {
1562    return SC_BindProgramFragment((ProgramFragment *) pf.p);
1563}
1564
1565void rsgBindProgramStore(::rs_program_store ps) {
1566    return SC_BindProgramStore((ProgramStore *) ps.p);
1567}
1568
1569void rsgBindProgramVertex(::rs_program_vertex pv) {
1570    return SC_BindProgramVertex((ProgramVertex *) pv.p);
1571}
1572
1573void rsgBindProgramRaster(::rs_program_raster pr) {
1574    return SC_BindProgramRaster((ProgramRaster *) pr.p);
1575}
1576
1577void rsgBindSampler(::rs_program_fragment pf,
1578                    uint32_t slot,
1579                    ::rs_sampler s) {
1580    return SC_BindSampler((ProgramFragment *) pf.p, slot, (Sampler *) s.p);
1581}
1582
1583void rsgBindTexture(::rs_program_fragment pf,
1584                    uint32_t slot,
1585                    ::rs_allocation a) {
1586    return SC_BindTexture((ProgramFragment *) pf.p,
1587                          slot,
1588                          (Allocation *) a.p);
1589}
1590
1591void rsgBindConstant(::rs_program_fragment pf,
1592                     uint32_t slot,
1593                     ::rs_allocation a) {
1594    return SC_BindFragmentConstant((ProgramFragment *) pf.p,
1595                                   slot,
1596                                   (Allocation *) a.p);
1597}
1598
1599void rsgBindConstant(::rs_program_vertex pv,
1600                     uint32_t slot,
1601                     ::rs_allocation a) {
1602    return SC_BindVertexConstant((ProgramVertex *) pv.p,
1603                                 slot,
1604                                 (Allocation *) a.p);
1605}
1606
1607void rsgProgramVertexLoadProjectionMatrix(const rs_matrix4x4 *m) {
1608    return SC_VpLoadProjectionMatrix((const rsc_Matrix *) m);
1609}
1610
1611void rsgProgramVertexLoadModelMatrix(const rs_matrix4x4 *m) {
1612    return SC_VpLoadModelMatrix((const rsc_Matrix *) m);
1613}
1614
1615void rsgProgramVertexLoadTextureMatrix(const rs_matrix4x4 *m) {
1616    return SC_VpLoadTextureMatrix((const rsc_Matrix *) m);
1617}
1618
1619void rsgProgramVertexGetProjectionMatrix(rs_matrix4x4 *m) {
1620    return SC_VpGetProjectionMatrix((rsc_Matrix *) m);
1621}
1622
1623void rsgProgramFragmentConstantColor(::rs_program_fragment pf,
1624                                     float r, float g,
1625                                     float b, float a) {
1626
1627    return SC_PfConstantColor((ProgramFragment *) pf.p, r, g, b, a);
1628}
1629
1630uint32_t rsgGetWidth(void) {
1631    return SC_GetWidth();
1632}
1633
1634uint32_t rsgGetHeight(void) {
1635    return SC_GetHeight();
1636}
1637
1638void rsgDrawRect(float x1, float y1, float x2, float y2, float z) {
1639    return SC_DrawRect(x1, y1, x2, y2, z);
1640}
1641
1642void rsgDrawQuad(float x1, float y1, float z1,
1643                 float x2, float y2, float z2,
1644                 float x3, float y3, float z3,
1645                 float x4, float y4, float z4) {
1646
1647    SC_DrawQuad(x1, y1, z1,
1648                x2, y2, z2,
1649                x3, y3, z3,
1650                x4, y4, z4);
1651}
1652
1653void rsgDrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1,
1654                          float x2, float y2, float z2, float u2, float v2,
1655                          float x3, float y3, float z3, float u3, float v3,
1656                          float x4, float y4, float z4, float u4, float v4) {
1657
1658    return rsgDrawQuadTexCoords(x1, y1, z1, u1, v1,
1659                                x2, y2, z2, u2, v2,
1660                                x3, y3, z3, u3, v3,
1661                                x4, y4, z4, u4, v4);
1662}
1663
1664void rsgDrawSpriteScreenspace(float x, float y, float z, float w, float h) {
1665    return SC_DrawSpriteScreenspace(x, y, z, w, h);
1666}
1667
1668void rsgDrawMesh(::rs_mesh ism) {
1669    return SC_DrawMesh((Mesh *) ism.p);
1670}
1671
1672void rsgDrawMesh(::rs_mesh ism, uint primitiveIndex) {
1673    return SC_DrawMeshPrimitive((Mesh *) ism.p, primitiveIndex);
1674}
1675
1676void rsgDrawMesh(::rs_mesh ism, uint primitiveIndex, uint start, uint len) {
1677    return SC_DrawMeshPrimitiveRange((Mesh *) ism.p, primitiveIndex, start, len);
1678}
1679
1680void  rsgMeshComputeBoundingBox(::rs_mesh mesh,
1681                                float *minX, float *minY, float *minZ,
1682                                float *maxX, float *maxY, float *maxZ) {
1683
1684    return SC_MeshComputeBoundingBox((Mesh *) mesh.p,
1685                                minX, minY, minZ,
1686                                maxX, maxY, maxZ);
1687}
1688
1689void rsgClearColor(float r, float g, float b, float a) {
1690    return SC_ClearColor(r, g, b, a);
1691}
1692
1693void rsgClearDepth(float value) {
1694    return SC_ClearDepth(value);
1695}
1696
1697void rsgDrawText(const char *text, int x, int y) {
1698    return SC_DrawText(text, x, y);
1699}
1700
1701void rsgDrawText(::rs_allocation a, int x, int y) {
1702    return SC_DrawTextAlloc((Allocation *) a.p, x, y);
1703}
1704
1705void rsgMeasureText(const char *text, int *left, int *right,
1706                    int *top, int *bottom) {
1707    return SC_MeasureText(text, left, right, top, bottom);
1708}
1709
1710void rsgMeasureText(::rs_allocation a, int *left, int *right,
1711                    int *top, int *bottom) {
1712    return SC_MeasureTextAlloc((Allocation *) a.p, left, right, top, bottom);
1713}
1714
1715void rsgBindFont(::rs_font font) {
1716    return SC_BindFont((Font *) font.p);
1717}
1718
1719void rsgFontColor(float r, float g, float b, float a) {
1720    return SC_FontColor(r, g, b, a);
1721}
1722
1723void rsgBindColorTarget(::rs_allocation a, uint slot) {
1724    return SC_BindFrameBufferObjectColorTarget((Allocation *) a.p, slot);
1725}
1726
1727void rsgBindDepthTarget(::rs_allocation a) {
1728    return SC_BindFrameBufferObjectDepthTarget((Allocation *) a.p);
1729}
1730
1731void rsgClearColorTarget(uint slot) {
1732    return SC_ClearFrameBufferObjectColorTarget(slot);
1733}
1734
1735void rsgClearDepthTarget(void) {
1736    return SC_ClearFrameBufferObjectDepthTarget(nullptr, nullptr);
1737}
1738
1739void rsgClearAllRenderTargets(void) {
1740    return SC_ClearFrameBufferObjectTargets(nullptr, nullptr);
1741}
1742
1743void color(float r, float g, float b, float a) {
1744    return SC_Color(r, g, b, a);
1745}
1746
1747void rsgFinish(void) {
1748    return SC_Finish();
1749}
1750
1751#endif
1752
1753//////////////////////////////////////////////////////////////////////////////
1754// Compatibility Library entry points
1755//////////////////////////////////////////////////////////////////////////////
1756
1757#ifndef __LP64__
1758#define IS_CLEAR_SET_OBJ(t, u, v) \
1759    bool rsIsObject(t src) { \
1760        return src.p != nullptr; \
1761    } \
1762    void __attribute__((overloadable)) rsClearObject(t *dst) { \
1763        return SC_ClearObject(reinterpret_cast<rs_object_base *>(dst)); \
1764    } \
1765    void __attribute__((overloadable)) rsSetObject(t *dst, t src) { \
1766        android::renderscript::rs_object_base cast; \
1767        cast.p = (ObjectBase *) src.p; \
1768        return SC_SetObject(reinterpret_cast<rs_object_base *>(dst), cast);\
1769    }
1770#else
1771#define IS_CLEAR_SET_OBJ(t, u, v) \
1772    extern "C" { bool u(t* src) { \
1773        return src->p != nullptr; \
1774    } }\
1775    void __attribute__((overloadable)) rsClearObject(t *dst) { \
1776        return SC_ClearObject(reinterpret_cast<rs_object_base *>(dst)); \
1777    } \
1778    extern "C" {\
1779      void v (t *dst, t *src) { \
1780        return SC_SetObject_ByRef(reinterpret_cast<rs_object_base *>(dst),\
1781                                  reinterpret_cast<rs_object_base *>(src));\
1782    } }
1783#endif
1784
1785IS_CLEAR_SET_OBJ(::rs_element, _Z10rsIsObject10rs_element, _Z11rsSetObjectP10rs_elementS_)
1786IS_CLEAR_SET_OBJ(::rs_type, _Z10rsIsObject7rs_type, _Z11rsSetObjectP7rs_typeS_)
1787IS_CLEAR_SET_OBJ(::rs_allocation, _Z10rsIsObject13rs_allocation, _Z11rsSetObjectP13rs_allocationS_)
1788IS_CLEAR_SET_OBJ(::rs_sampler, _Z10rsIsObject10rs_sampler, _Z11rsSetObjectP10rs_samplerS_)
1789IS_CLEAR_SET_OBJ(::rs_script, _Z10rsIsObject9rs_script, _Z11rsSetObjectP9rs_scriptS_)
1790
1791IS_CLEAR_SET_OBJ(::rs_path, _Z10rsIsObject7rs_path, _Z11rsSetObjectP7rs_pathS_)
1792IS_CLEAR_SET_OBJ(::rs_mesh, _Z10rsIsObject7rs_mesh, _Z11rsSetObjectP7rs_meshS_)
1793IS_CLEAR_SET_OBJ(::rs_program_fragment, _Z10rsIsObject19rs_program_fragment, _Z11rsSetObjectP19rs_program_fragmentS_)
1794IS_CLEAR_SET_OBJ(::rs_program_vertex, _Z10rsIsObject17rs_program_vertex, _Z11rsSetObjectP17rs_program_vertexS_)
1795IS_CLEAR_SET_OBJ(::rs_program_raster, _Z10rsIsObject17rs_program_raster, _Z11rsSetObjectP17rs_program_rasterS_)
1796IS_CLEAR_SET_OBJ(::rs_program_store, _Z10rsIsObject16rs_program_store, _Z11rsSetObjectP16rs_program_storeS_)
1797IS_CLEAR_SET_OBJ(::rs_font, _Z10rsIsObject7rs_font, _Z11rsSetObjectP7rs_fontS_)
1798
1799
1800#undef IS_CLEAR_SET_OBJ
1801
1802#ifdef RS_COMPATIBILITY_LIB
1803static const Allocation * SC_GetAllocation(const void *ptr) {
1804    Context *rsc = RsdCpuReference::getTlsContext();
1805    const Script *sc = RsdCpuReference::getTlsScript();
1806    return rsdScriptGetAllocationForPointer(rsc, sc, ptr);
1807}
1808
1809const Allocation * rsGetAllocation(const void *ptr) {
1810    return SC_GetAllocation(ptr);
1811}
1812
1813#else
1814const android::renderscript::rs_allocation rsGetAllocation(const void *ptr) {
1815#ifdef __i386__
1816    android::renderscript::rs_allocation obj;
1817    obj.p = (Allocation *) SC_GetAllocation(ptr);
1818    return obj;
1819#else
1820    return SC_GetAllocation(ptr);
1821#endif
1822}
1823#endif
1824
1825
1826void __attribute__((overloadable)) rsAllocationIoSend(::rs_allocation a) {
1827    SC_AllocationIoSend(RS_CAST(a));
1828}
1829
1830void __attribute__((overloadable)) rsAllocationIoReceive(::rs_allocation a) {
1831    SC_AllocationIoReceive(RS_CAST(a));
1832}
1833
1834
1835void __attribute__((overloadable)) rsAllocationCopy1DRange(
1836        ::rs_allocation dstAlloc,
1837        uint32_t dstOff, uint32_t dstMip, uint32_t count,
1838        ::rs_allocation srcAlloc,
1839        uint32_t srcOff, uint32_t srcMip) {
1840    SC_AllocationCopy1DRange(RS_CAST(dstAlloc), dstOff, dstMip, count,
1841                             RS_CAST(srcAlloc), srcOff, srcMip);
1842}
1843
1844void __attribute__((overloadable)) rsAllocationCopy2DRange(
1845        ::rs_allocation dstAlloc,
1846        uint32_t dstXoff, uint32_t dstYoff,
1847        uint32_t dstMip, rs_allocation_cubemap_face dstFace,
1848        uint32_t width, uint32_t height,
1849        ::rs_allocation srcAlloc,
1850        uint32_t srcXoff, uint32_t srcYoff,
1851        uint32_t srcMip, rs_allocation_cubemap_face srcFace) {
1852    SC_AllocationCopy2DRange(RS_CAST(dstAlloc), dstXoff, dstYoff,
1853                             dstMip, dstFace, width, height,
1854                             RS_CAST(srcAlloc), srcXoff, srcYoff,
1855                             srcMip, srcFace);
1856}
1857
1858void __attribute__((overloadable)) rsForEach(::rs_script script,
1859                                             ::rs_allocation in,
1860                                             ::rs_allocation out,
1861                                             const void *usr,
1862                                             const rs_script_call *call) {
1863    return SC_ForEach_SAAUS(RS_CAST(script), RS_CAST(in), RS_CAST(out), usr, (RsScriptCall*)call);
1864}
1865
1866void __attribute__((overloadable)) rsForEach(::rs_script script,
1867                                             ::rs_allocation in,
1868                                             ::rs_allocation out,
1869                                             const void *usr) {
1870    return SC_ForEach_SAAU(RS_CAST(script), RS_CAST(in), RS_CAST(out), usr);
1871}
1872
1873void __attribute__((overloadable)) rsForEach(::rs_script script,
1874                                             ::rs_allocation in,
1875                                             ::rs_allocation out) {
1876    return SC_ForEach_SAA(RS_CAST(script), RS_CAST(in), RS_CAST(out));
1877}
1878
1879#ifndef __LP64__
1880void __attribute__((overloadable)) rsForEach(::rs_script script,
1881                                             ::rs_allocation in,
1882                                             ::rs_allocation out,
1883                                             const void *usr,
1884                                             uint32_t usrLen) {
1885    return SC_ForEach_SAAUL(RS_CAST(script), RS_CAST(in), RS_CAST(out), usr, usrLen);
1886}
1887
1888void __attribute__((overloadable)) rsForEach(::rs_script script,
1889                                             ::rs_allocation in,
1890                                             ::rs_allocation out,
1891                                             const void *usr,
1892                                             uint32_t usrLen,
1893                                             const rs_script_call *call) {
1894    return SC_ForEach_SAAULS(RS_CAST(script), RS_CAST(in), RS_CAST(out), usr, usrLen, (RsScriptCall*)call);
1895}
1896#endif
1897
1898// #if defined(RS_COMPATIBILITY_LIB) || !defined(__LP64__)
1899#ifndef __LP64__
1900int rsTime(int *timer) {
1901    return SC_Time(timer);
1902}
1903
1904rs_tm* rsLocaltime(rs_tm* local, const int *timer) {
1905    return (rs_tm*)(SC_LocalTime((tm*)local, (time_t *)timer));
1906}
1907#else
1908time_t rsTime(time_t * timer) {
1909    return SC_Time(timer);
1910}
1911
1912rs_tm* rsLocaltime(rs_tm* local, const time_t *timer) {
1913    return (rs_tm*)(SC_LocalTime((tm*)local, (time_t *)timer));
1914}
1915#endif // RS_COMPATIBILITY_LIB
1916
1917int64_t rsUptimeMillis() {
1918    Context *rsc = RsdCpuReference::getTlsContext();
1919    return rsrUptimeMillis(rsc);
1920}
1921
1922int64_t rsUptimeNanos() {
1923    return SC_UptimeNanos();
1924}
1925
1926float rsGetDt() {
1927    return SC_GetDt();
1928}
1929
1930uint32_t rsSendToClient(int cmdID) {
1931    return SC_ToClient(cmdID);
1932}
1933
1934uint32_t rsSendToClient(int cmdID, const void *data, uint32_t len) {
1935    return SC_ToClient2(cmdID, data, len);
1936}
1937
1938uint32_t rsSendToClientBlocking(int cmdID) {
1939    return SC_ToClientBlocking(cmdID);
1940}
1941
1942uint32_t rsSendToClientBlocking(int cmdID, const void *data, uint32_t len) {
1943    return SC_ToClientBlocking2(cmdID, data, len);
1944}
1945
1946static void SC_debugF(const char *s, float f) {
1947    ALOGD("%s %f, 0x%08x", s, f, *((int *) (&f)));
1948}
1949static void SC_debugFv2(const char *s, float f1, float f2) {
1950    ALOGD("%s {%f, %f}", s, f1, f2);
1951}
1952static void SC_debugFv3(const char *s, float f1, float f2, float f3) {
1953    ALOGD("%s {%f, %f, %f}", s, f1, f2, f3);
1954}
1955static void SC_debugFv4(const char *s, float f1, float f2, float f3, float f4) {
1956    ALOGD("%s {%f, %f, %f, %f}", s, f1, f2, f3, f4);
1957}
1958static void SC_debugF2(const char *s, float2 f) {
1959    ALOGD("%s {%f, %f}", s, f.x, f.y);
1960}
1961static void SC_debugF3(const char *s, float3 f) {
1962    ALOGD("%s {%f, %f, %f}", s, f.x, f.y, f.z);
1963}
1964static void SC_debugF4(const char *s, float4 f) {
1965    ALOGD("%s {%f, %f, %f, %f}", s, f.x, f.y, f.z, f.w);
1966}
1967static void SC_debugD(const char *s, double d) {
1968    ALOGD("%s %f, 0x%08llx", s, d, *((long long *) (&d)));
1969}
1970static void SC_debugFM4v4(const char *s, const float *f) {
1971    ALOGD("%s {%f, %f, %f, %f", s, f[0], f[4], f[8], f[12]);
1972    ALOGD("%s  %f, %f, %f, %f", s, f[1], f[5], f[9], f[13]);
1973    ALOGD("%s  %f, %f, %f, %f", s, f[2], f[6], f[10], f[14]);
1974    ALOGD("%s  %f, %f, %f, %f}", s, f[3], f[7], f[11], f[15]);
1975}
1976static void SC_debugFM3v3(const char *s, const float *f) {
1977    ALOGD("%s {%f, %f, %f", s, f[0], f[3], f[6]);
1978    ALOGD("%s  %f, %f, %f", s, f[1], f[4], f[7]);
1979    ALOGD("%s  %f, %f, %f}",s, f[2], f[5], f[8]);
1980}
1981static void SC_debugFM2v2(const char *s, const float *f) {
1982    ALOGD("%s {%f, %f", s, f[0], f[2]);
1983    ALOGD("%s  %f, %f}",s, f[1], f[3]);
1984}
1985static void SC_debugI8(const char *s, char c) {
1986    ALOGD("%s %hhd  0x%hhx", s, c, (unsigned char)c);
1987}
1988static void SC_debugC2(const char *s, char2 c) {
1989    ALOGD("%s {%hhd, %hhd}  0x%hhx 0x%hhx", s, c.x, c.y, (unsigned char)c.x, (unsigned char)c.y);
1990}
1991static void SC_debugC3(const char *s, char3 c) {
1992    ALOGD("%s {%hhd, %hhd, %hhd}  0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, (unsigned char)c.x, (unsigned char)c.y, (unsigned char)c.z);
1993}
1994static void SC_debugC4(const char *s, char4 c) {
1995    ALOGD("%s {%hhd, %hhd, %hhd, %hhd}  0x%hhx 0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, c.w, (unsigned char)c.x, (unsigned char)c.y, (unsigned char)c.z, (unsigned char)c.w);
1996}
1997static void SC_debugU8(const char *s, unsigned char c) {
1998    ALOGD("%s %hhu  0x%hhx", s, c, c);
1999}
2000static void SC_debugUC2(const char *s, uchar2 c) {
2001    ALOGD("%s {%hhu, %hhu}  0x%hhx 0x%hhx", s, c.x, c.y, c.x, c.y);
2002}
2003static void SC_debugUC3(const char *s, uchar3 c) {
2004    ALOGD("%s {%hhu, %hhu, %hhu}  0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, c.x, c.y, c.z);
2005}
2006static void SC_debugUC4(const char *s, uchar4 c) {
2007    ALOGD("%s {%hhu, %hhu, %hhu, %hhu}  0x%hhx 0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, c.w, c.x, c.y, c.z, c.w);
2008}
2009static void SC_debugI16(const char *s, short c) {
2010    ALOGD("%s %hd  0x%hx", s, c, c);
2011}
2012static void SC_debugS2(const char *s, short2 c) {
2013    ALOGD("%s {%hd, %hd}  0x%hx 0x%hx", s, c.x, c.y, c.x, c.y);
2014}
2015static void SC_debugS3(const char *s, short3 c) {
2016    ALOGD("%s {%hd, %hd, %hd}  0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.x, c.y, c.z);
2017}
2018static void SC_debugS4(const char *s, short4 c) {
2019    ALOGD("%s {%hd, %hd, %hd, %hd}  0x%hx 0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.w, c.x, c.y, c.z, c.w);
2020}
2021static void SC_debugU16(const char *s, unsigned short c) {
2022    ALOGD("%s %hu  0x%hx", s, c, c);
2023}
2024static void SC_debugUS2(const char *s, ushort2 c) {
2025    ALOGD("%s {%hu, %hu}  0x%hx 0x%hx", s, c.x, c.y, c.x, c.y);
2026}
2027static void SC_debugUS3(const char *s, ushort3 c) {
2028    ALOGD("%s {%hu, %hu, %hu}  0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.x, c.y, c.z);
2029}
2030static void SC_debugUS4(const char *s, ushort4 c) {
2031    ALOGD("%s {%hu, %hu, %hu, %hu}  0x%hx 0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.w, c.x, c.y, c.z, c.w);
2032}
2033static void SC_debugI32(const char *s, int32_t i) {
2034    ALOGD("%s %d  0x%x", s, i, i);
2035}
2036static void SC_debugI2(const char *s, int2 i) {
2037    ALOGD("%s {%d, %d}  0x%x 0x%x", s, i.x, i.y, i.x, i.y);
2038}
2039static void SC_debugI3(const char *s, int3 i) {
2040    ALOGD("%s {%d, %d, %d}  0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.x, i.y, i.z);
2041}
2042static void SC_debugI4(const char *s, int4 i) {
2043    ALOGD("%s {%d, %d, %d, %d}  0x%x 0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.w, i.x, i.y, i.z, i.w);
2044}
2045static void SC_debugU32(const char *s, uint32_t i) {
2046    ALOGD("%s %u  0x%x", s, i, i);
2047}
2048static void SC_debugUI2(const char *s, uint2 i) {
2049    ALOGD("%s {%u, %u}  0x%x 0x%x", s, i.x, i.y, i.x, i.y);
2050}
2051static void SC_debugUI3(const char *s, uint3 i) {
2052    ALOGD("%s {%u, %u, %u}  0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.x, i.y, i.z);
2053}
2054static void SC_debugUI4(const char *s, uint4 i) {
2055    ALOGD("%s {%u, %u, %u, %u}  0x%x 0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.w, i.x, i.y, i.z, i.w);
2056}
2057
2058template <typename T>
2059static inline long long LL(const T &x) {
2060    return static_cast<long long>(x);
2061}
2062
2063template <typename T>
2064static inline unsigned long long LLu(const T &x) {
2065    return static_cast<unsigned long long>(x);
2066}
2067
2068static void SC_debugLL64(const char *s, long long ll) {
2069    ALOGD("%s %lld  0x%llx", s, LL(ll), LL(ll));
2070}
2071
2072static void SC_debugL2(const char *s, long2 ll) {
2073    ALOGD("%s {%lld, %lld}  0x%llx 0x%llx", s, LL(ll.x), LL(ll.y), LL(ll.x), LL(ll.y));
2074}
2075static void SC_debugL3(const char *s, long3 ll) {
2076    ALOGD("%s {%lld, %lld, %lld}  0x%llx 0x%llx 0x%llx", s, LL(ll.x), LL(ll.y), LL(ll.z), LL(ll.x), LL(ll.y), LL(ll.z));
2077}
2078static void SC_debugL4(const char *s, long4 ll) {
2079    ALOGD("%s {%lld, %lld, %lld, %lld}  0x%llx 0x%llx 0x%llx 0x%llx", s, LL(ll.x), LL(ll.y), LL(ll.z), LL(ll.w), LL(ll.x), LL(ll.y), LL(ll.z), LL(ll.w));
2080}
2081static void SC_debugULL64(const char *s, unsigned long long ll) {
2082    ALOGD("%s %llu  0x%llx", s, ll, ll);
2083}
2084static void SC_debugUL2(const char *s, ulong2 ll) {
2085    ALOGD("%s {%llu, %llu}  0x%llx 0x%llx", s, LLu(ll.x), LLu(ll.y), LLu(ll.x), LLu(ll.y));
2086}
2087static void SC_debugUL3(const char *s, ulong3 ll) {
2088    ALOGD("%s {%llu, %llu, %llu}  0x%llx 0x%llx 0x%llx", s, LLu(ll.x), LLu(ll.y), LLu(ll.z), LLu(ll.x), LLu(ll.y), LLu(ll.z));
2089}
2090static void SC_debugUL4(const char *s, ulong4 ll) {
2091    ALOGD("%s {%llu, %llu, %llu, %llu}  0x%llx 0x%llx 0x%llx 0x%llx", s, LLu(ll.x), LLu(ll.y), LLu(ll.z), LLu(ll.w), LLu(ll.x), LLu(ll.y), LLu(ll.z), LLu(ll.w));
2092}
2093
2094static void SC_debugP(const char *s, const void *p) {
2095    ALOGD("%s %p", s, p);
2096}
2097
2098// TODO: allocation ops, messaging, time
2099
2100void rsDebug(const char *s, float f) {
2101    SC_debugF(s, f);
2102}
2103
2104void rsDebug(const char *s, float f1, float f2) {
2105    SC_debugFv2(s, f1, f2);
2106}
2107
2108void rsDebug(const char *s, float f1, float f2, float f3) {
2109    SC_debugFv3(s, f1, f2, f3);
2110}
2111
2112void rsDebug(const char *s, float f1, float f2, float f3, float f4) {
2113    SC_debugFv4(s, f1, f2, f3, f4);
2114}
2115
2116void rsDebug(const char *s, const float2 *f) {
2117    SC_debugF2(s, *f);
2118}
2119
2120void rsDebug(const char *s, const float3 *f) {
2121    SC_debugF3(s, *f);
2122}
2123
2124void rsDebug(const char *s, const float4 *f) {
2125    SC_debugF4(s, *f);
2126}
2127
2128void rsDebug(const char *s, double d) {
2129    SC_debugD(s, d);
2130}
2131
2132void rsDebug(const char *s, const rs_matrix4x4 *m) {
2133    SC_debugFM4v4(s, (float *) m);
2134}
2135
2136void rsDebug(const char *s, const rs_matrix3x3 *m) {
2137    SC_debugFM3v3(s, (float *) m);
2138}
2139
2140void rsDebug(const char *s, const rs_matrix2x2 *m) {
2141    SC_debugFM2v2(s, (float *) m);
2142}
2143
2144void rsDebug(const char *s, char c) {
2145    SC_debugI8(s, c);
2146}
2147
2148void rsDebug(const char *s, const char2 *c) {
2149    SC_debugC2(s, *c);
2150}
2151
2152void rsDebug(const char *s, const char3 *c) {
2153    SC_debugC3(s, *c);
2154}
2155
2156void rsDebug(const char *s, const char4 *c) {
2157    SC_debugC4(s, *c);
2158}
2159
2160void rsDebug(const char *s, unsigned char c) {
2161    SC_debugU8(s, c);
2162}
2163
2164void rsDebug(const char *s, const uchar2 *c) {
2165    SC_debugUC2(s, *c);
2166}
2167
2168void rsDebug(const char *s, const uchar3 *c) {
2169    SC_debugUC3(s, *c);
2170}
2171
2172void rsDebug(const char *s, const uchar4 *c) {
2173    SC_debugUC4(s, *c);
2174}
2175
2176void rsDebug(const char *s, short c) {
2177    SC_debugI16(s, c);
2178}
2179
2180void rsDebug(const char *s, const short2 *c) {
2181    SC_debugS2(s, *c);
2182}
2183
2184void rsDebug(const char *s, const short3 *c) {
2185    SC_debugS3(s, *c);
2186}
2187
2188void rsDebug(const char *s, const short4 *c) {
2189    SC_debugS4(s, *c);
2190}
2191
2192void rsDebug(const char *s, unsigned short c) {
2193    SC_debugU16(s, c);
2194}
2195
2196void rsDebug(const char *s, const ushort2 *c) {
2197    SC_debugUS2(s, *c);
2198}
2199
2200void rsDebug(const char *s, const ushort3 *c) {
2201    SC_debugUS3(s, *c);
2202}
2203
2204void rsDebug(const char *s, const ushort4 *c) {
2205    SC_debugUS4(s, *c);
2206}
2207
2208void rsDebug(const char *s, int c) {
2209    SC_debugI32(s, c);
2210}
2211
2212void rsDebug(const char *s, const int2 *c) {
2213    SC_debugI2(s, *c);
2214}
2215
2216void rsDebug(const char *s, const int3 *c) {
2217    SC_debugI3(s, *c);
2218}
2219
2220void rsDebug(const char *s, const int4 *c) {
2221    SC_debugI4(s, *c);
2222}
2223
2224void rsDebug(const char *s, unsigned int c) {
2225    SC_debugU32(s, c);
2226}
2227
2228void rsDebug(const char *s, const uint2 *c) {
2229    SC_debugUI2(s, *c);
2230}
2231
2232void rsDebug(const char *s, const uint3 *c) {
2233    SC_debugUI3(s, *c);
2234}
2235
2236void rsDebug(const char *s, const uint4 *c) {
2237    SC_debugUI4(s, *c);
2238}
2239
2240void rsDebug(const char *s, long c) {
2241    SC_debugLL64(s, c);
2242}
2243
2244void rsDebug(const char *s, long long c) {
2245    SC_debugLL64(s, c);
2246}
2247
2248void rsDebug(const char *s, const long2 *c) {
2249    SC_debugL2(s, *c);
2250}
2251
2252void rsDebug(const char *s, const long3 *c) {
2253    SC_debugL3(s, *c);
2254}
2255
2256void rsDebug(const char *s, const long4 *c) {
2257    SC_debugL4(s, *c);
2258}
2259
2260void rsDebug(const char *s, unsigned long c) {
2261    SC_debugULL64(s, c);
2262}
2263
2264void rsDebug(const char *s, unsigned long long c) {
2265    SC_debugULL64(s, c);
2266}
2267
2268void rsDebug(const char *s, const ulong2 *c) {
2269    SC_debugUL2(s, *c);
2270}
2271
2272void rsDebug(const char *s, const ulong3 *c) {
2273    SC_debugUL3(s, *c);
2274}
2275
2276void rsDebug(const char *s, const ulong4 *c) {
2277    SC_debugUL4(s, *c);
2278}
2279
2280// FIXME: We need to export these function signatures for the compatibility
2281// library. The C++ name mangling that LLVM uses for ext_vector_type requires
2282// different versions for "long" vs. "long long". Note that the called
2283// functions are still using the appropriate 64-bit sizes.
2284
2285#ifndef __LP64__
2286typedef long l2 __attribute__((ext_vector_type(2)));
2287typedef long l3 __attribute__((ext_vector_type(3)));
2288typedef long l4 __attribute__((ext_vector_type(4)));
2289typedef unsigned long ul2 __attribute__((ext_vector_type(2)));
2290typedef unsigned long ul3 __attribute__((ext_vector_type(3)));
2291typedef unsigned long ul4 __attribute__((ext_vector_type(4)));
2292
2293void rsDebug(const char *s, const l2 *c) {
2294    SC_debugL2(s, *(const long2 *)c);
2295}
2296
2297void rsDebug(const char *s, const l3 *c) {
2298    SC_debugL3(s, *(const long3 *)c);
2299}
2300
2301void rsDebug(const char *s, const l4 *c) {
2302    SC_debugL4(s, *(const long4 *)c);
2303}
2304
2305void rsDebug(const char *s, const ul2 *c) {
2306    SC_debugUL2(s, *(const ulong2 *)c);
2307}
2308
2309void rsDebug(const char *s, const ul3 *c) {
2310    SC_debugUL3(s, *(const ulong3 *)c);
2311}
2312
2313void rsDebug(const char *s, const ul4 *c) {
2314    SC_debugUL4(s, *(const ulong4 *)c);
2315}
2316#endif
2317
2318void rsDebug(const char *s, const long2 c) {
2319    SC_debugL2(s, c);
2320}
2321
2322void rsDebug(const char *s, const long3 c) {
2323    SC_debugL3(s, c);
2324}
2325
2326void rsDebug(const char *s, const long4 c) {
2327    SC_debugL4(s, c);
2328}
2329
2330void rsDebug(const char *s, const ulong2 c) {
2331    SC_debugUL2(s, c);
2332}
2333
2334void rsDebug(const char *s, const ulong3 c) {
2335    SC_debugUL3(s, c);
2336}
2337
2338void rsDebug(const char *s, const ulong4 c) {
2339    SC_debugUL4(s, c);
2340}
2341
2342
2343void rsDebug(const char *s, const void *p) {
2344    SC_debugP(s, p);
2345}
2346
2347extern const RsdCpuReference::CpuSymbol * rsdLookupRuntimeStub(Context * pContext, char const* name) {
2348    ScriptC *s = (ScriptC *)pContext;
2349    const RsdCpuReference::CpuSymbol *syms = gSyms;
2350    const RsdCpuReference::CpuSymbol *sym = nullptr;
2351
2352    if (!sym) {
2353        while (syms->fnPtr) {
2354            if (!strcmp(syms->name, name)) {
2355                return syms;
2356            }
2357            syms++;
2358        }
2359    }
2360
2361    return nullptr;
2362}
2363