Merge "Move renderscript over to __clear_cache (compiler-rt)."
diff --git a/Android.mk b/Android.mk
index 12d5804..d2caac6 100644
--- a/Android.mk
+++ b/Android.mk
@@ -13,7 +13,7 @@
 include $(CLEAR_VARS)
 LOCAL_CLANG := true
 LOCAL_MODULE := libRSDriver
-LOCAL_MODULE_TARGET_ARCH_WARN := arm mips x86 x86_64
+LOCAL_MODULE_TARGET_ARCH_WARN := arm mips x86 x86_64 arm64
 
 LOCAL_SRC_FILES:= \
 	driver/rsdAllocation.cpp \
@@ -38,13 +38,18 @@
 
 LOCAL_SHARED_LIBRARIES += libRS libRSCpuRef
 LOCAL_SHARED_LIBRARIES += liblog libcutils libutils libEGL libGLESv1_CM libGLESv2
-LOCAL_SHARED_LIBRARIES += libbcc libbcinfo libLLVM libui libgui libsync
+LOCAL_SHARED_LIBRARIES += libui libgui libsync
+
+# FIXME for 64-bit
+LOCAL_SHARED_LIBRARIES_32 += libbcc libbcinfo libLLVM
 
 LOCAL_C_INCLUDES += frameworks/compile/libbcc/include
 LOCAL_C_INCLUDES += frameworks/rs/cpu_ref/linkloader/include
 
 LOCAL_CFLAGS += $(rs_base_CFLAGS)
 
+LOCAL_CFLAGS_64 += -DFAKE_ARM64_BUILD=1
+
 LOCAL_LDLIBS := -lpthread -ldl
 LOCAL_MODULE_TAGS := optional
 
@@ -74,7 +79,7 @@
 include $(CLEAR_VARS)
 LOCAL_CLANG := true
 LOCAL_MODULE := libRS
-LOCAL_MODULE_TARGET_ARCH_WARN := arm mips x86 x86_64
+LOCAL_MODULE_TARGET_ARCH_WARN := arm mips x86 x86_64 arm64
 
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
 generated_sources:= $(local-generated-sources-dir)
@@ -152,15 +157,22 @@
 	rsThreadIO.cpp \
 	rsType.cpp
 
-LOCAL_SHARED_LIBRARIES += liblog libcutils libutils libEGL libGLESv1_CM libGLESv2 libbcc
-LOCAL_SHARED_LIBRARIES += libui libbcinfo libLLVM libgui libsync libdl
+LOCAL_SHARED_LIBRARIES += liblog libcutils libutils libEGL libGLESv1_CM libGLESv2
+LOCAL_SHARED_LIBRARIES += libgui libsync libdl libui
 LOCAL_SHARED_LIBRARIES += libft2 libpng libz
 
+# FIXME for 64-bit
+LOCAL_SHARED_LIBRARIES_32 += libbcc libbcinfo libLLVM
+
+
 LOCAL_C_INCLUDES += external/freetype/include
 LOCAL_C_INCLUDES += frameworks/compile/libbcc/include
 
 LOCAL_CFLAGS += $(rs_base_CFLAGS)
 
+# FIXME for 64-bit
+LOCAL_CFLAGS_64 += -DFAKE_ARM64_BUILD=1
+
 LOCAL_LDLIBS := -lpthread -ldl
 LOCAL_MODULE_TAGS := optional
 
@@ -249,7 +261,6 @@
 
 include $(BUILD_HOST_STATIC_LIBRARY)
 
-
 LLVM_ROOT_PATH := external/llvm
 
 #=============================================================================
@@ -271,6 +282,7 @@
 
 include $(CLEAR_VARS)
 
+
 LOCAL_MODULE := librsloader
 
 LOCAL_MODULE_TAGS := optional
@@ -289,7 +301,6 @@
 include $(LLVM_ROOT_PATH)/llvm-device-build.mk
 include $(BUILD_STATIC_LIBRARY)
 
-
 #=============================================================================
 # android librsloader for libbcc (Host)
 #-----------------------------------------------------------------------------
@@ -320,3 +331,4 @@
 include $(BUILD_HOST_STATIC_LIBRARY)
 
 include $(call all-makefiles-under,$(LOCAL_PATH))
+
diff --git a/api/gen_runtime.cpp b/api/gen_runtime.cpp
index 589556f..68e7a4d 100644
--- a/api/gen_runtime.cpp
+++ b/api/gen_runtime.cpp
@@ -1468,27 +1468,29 @@
                                                            const Type& generatedType) const {
     file << "createRandomFloatAllocation"
          << "(mRS, Element.DataType." << dataType << ", " << vectorSize << ", " << seed << ", ";
-    file << scientific << std::setprecision(10);
+    double minValue = 0.0;
+    double maxValue = 0.0;
     switch (compatibleType.kind) {
         case FLOATING_POINT: {
             // We're generating floating point values.  We just have to worry about the
             // exponent.  Subtract 1 for the sign.
             int bits = min(compatibleType.significantBits, generatedType.significantBits) - 1;
-            double maxValue = ldexp(0.95, (1 << bits) - 1);
-            file << -maxValue << ", " << maxValue;
+            maxValue = ldexp(0.95, (1 << bits) - 1);
+            minValue = -maxValue;
             break;
         }
         case UNSIGNED_INTEGER:
-            file << "0, " << ldexp(1, compatibleType.significantBits);
+            minValue = 0.0;
+            maxValue = ldexp(1, compatibleType.significantBits) - 1.0;
             break;
-        case SIGNED_INTEGER: {
-            double max = ldexp(1, compatibleType.significantBits);
-            file << -max << ", " << (max - 1);
+        case SIGNED_INTEGER:
+            minValue = -ldexp(1, compatibleType.significantBits);
+            maxValue = ldexp(1, compatibleType.significantBits) - 1;
             break;
-        }
     }
+    file << scientific << std::setprecision(10);
+    file << minValue << ", " << maxValue << ")";
     file.unsetf(ios_base::floatfield);
-    file << ")";
 }
 
 void Permutation::writeJavaRandomCompatibleIntegerAllocation(ofstream& file, const string& dataType,
diff --git a/cpp/Allocation.cpp b/cpp/Allocation.cpp
index de0f229..91ccbd1 100644
--- a/cpp/Allocation.cpp
+++ b/cpp/Allocation.cpp
@@ -198,7 +198,7 @@
         return;
     }
     if((off + count) > mCurrentCount) {
-        ALOGE("Overflow, Available count %zu, got %zu at offset %zu.", mCurrentCount, count, off);
+        ALOGE("Overflow, Available count %u, got %zu at offset %u.", mCurrentCount, count, off);
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Invalid copy specified");
         return;
     }
@@ -213,7 +213,7 @@
         return;
     }
     if((off + count) > mCurrentCount) {
-        ALOGE("Overflow, Available count %zu, got %zu at offset %zu.", mCurrentCount, count, off);
+        ALOGE("Overflow, Available count %u, got %zu at offset %u.", mCurrentCount, count, off);
         mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Invalid copy specified");
         return;
     }
diff --git a/cpu_ref/Android.mk b/cpu_ref/Android.mk
index c4e0ebf..9517594 100644
--- a/cpu_ref/Android.mk
+++ b/cpu_ref/Android.mk
@@ -13,7 +13,7 @@
 include $(CLEAR_VARS)
 LOCAL_CLANG := true
 LOCAL_MODULE := libRSCpuRef
-LOCAL_MODULE_TARGET_ARCH := arm mips x86 x86_64
+LOCAL_MODULE_TARGET_ARCH := arm mips x86 x86_64 arm64
 
 LOCAL_SRC_FILES:= \
 	rsCpuCore.cpp \
@@ -34,11 +34,11 @@
 	rsCpuIntrinsicYuvToRGB.cpp \
 	convolve/convolve.c
 
-LOCAL_CFLAGS_arm64 += -DARCH_ARM_HAVE_NEON
-LOCAL_SRC_FILES_arm64 += \
-    rsCpuIntrinsics_advsimd_Blend.S \
-    rsCpuIntrinsics_advsimd_Blur.S \
-    rsCpuIntrinsics_advsimd_YuvToRGB.S
+LOCAL_CFLAGS_arm64 += -DARCH_ARM_HAVE_NEON -DFAKE_ARM64_BUILD
+#LOCAL_SRC_FILES_arm64 += \
+#    rsCpuIntrinsics_advsimd_Blend.S \
+#    rsCpuIntrinsics_advsimd_Blur.S \
+#    rsCpuIntrinsics_advsimd_YuvToRGB.S
 
 ifeq ($(ARCH_ARM_HAVE_NEON),true)
     LOCAL_CFLAGS_arm += -DARCH_ARM_HAVE_NEON
@@ -61,7 +61,10 @@
 endif
 
 LOCAL_SHARED_LIBRARIES += libRS libcutils libutils liblog libsync
-LOCAL_SHARED_LIBRARIES += libbcc libbcinfo
+
+# these are not supported in 64-bit yet
+LOCAL_SHARED_LIBRARIES_32 += libbcc libbcinfo
+
 
 LOCAL_C_INCLUDES += frameworks/compile/libbcc/include
 LOCAL_C_INCLUDES += frameworks/rs
diff --git a/cpu_ref/rsCpuCore.cpp b/cpu_ref/rsCpuCore.cpp
index 7dfb3e2..a86a826 100644
--- a/cpu_ref/rsCpuCore.cpp
+++ b/cpu_ref/rsCpuCore.cpp
@@ -330,6 +330,9 @@
         pthread_join(mWorkers.mThreadId[ct], &res);
     }
     rsAssert(__sync_fetch_and_or(&mWorkers.mRunningCount, 0) == 0);
+    free(mWorkers.mThreadId);
+    free(mWorkers.mNativeThreadId);
+    delete[] mWorkers.mLaunchSignals;
 
     // Global structure cleanup.
     lockMutex();
diff --git a/cpu_ref/rsCpuIntrinsicColorMatrix.cpp b/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
index e381e8e..87db9ba 100644
--- a/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
+++ b/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
@@ -278,7 +278,7 @@
     return key;
 }
 
-#if defined(ARCH_ARM_HAVE_NEON)
+#if defined(ARCH_ARM_HAVE_NEON) && !defined(FAKE_ARM64_BUILD)
 
 #define DEF_SYM(x)                                  \
     extern "C" uint32_t _N_ColorMatrix_##x;      \
@@ -408,7 +408,7 @@
 
 
 bool RsdCpuScriptIntrinsicColorMatrix::build(Key_t key) {
-#if defined(ARCH_ARM_HAVE_NEON)
+#if defined(ARCH_ARM_HAVE_NEON) && !defined(FAKE_ARM64_BUILD)
     mBufSize = 4096;
     //StopWatch build_time("rs cm: build time");
     mBuf = (uint8_t *)mmap(0, mBufSize, PROT_READ | PROT_WRITE,
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index 2b69d85..2cf9b83 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -4,7 +4,7 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- *
+< *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
@@ -17,6 +17,7 @@
 #include "rsCpuCore.h"
 #include "rsCpuScript.h"
 
+#ifndef FAKE_ARM64_BUILD
 #ifdef RS_COMPATIBILITY_LIB
     #include <set>
     #include <string>
@@ -38,8 +39,10 @@
     #include <sys/wait.h>
     #include <unistd.h>
 #endif
+#endif
 
 namespace {
+#ifndef FAKE_ARM64_BUILD
 #ifdef RS_COMPATIBILITY_LIB
 
 // Create a len length string containing random characters from [A-Za-z0-9].
@@ -278,12 +281,12 @@
 #endif  // EXTERNAL_BCC_COMPILER
 
 #endif  // !defined(RS_COMPATIBILITY_LIB)
+#endif
 }  // namespace
 
 namespace android {
 namespace renderscript {
 
-
 #ifdef RS_COMPATIBILITY_LIB
 #define MAXLINE 500
 #define MAKE_STR_HELPER(S) #S
@@ -327,6 +330,7 @@
     mCtx = ctx;
     mScript = s;
 
+#ifndef FAKE_ARM64_BUILD
 #ifdef RS_COMPATIBILITY_LIB
     mScriptSO = NULL;
     mInvokeFunctions = NULL;
@@ -340,6 +344,7 @@
     mExecutable = NULL;
 #endif
 
+
     mRoot = NULL;
     mRootExpand = NULL;
     mInit = NULL;
@@ -349,6 +354,7 @@
     mBoundAllocs = NULL;
     mIntrinsicData = NULL;
     mIsThreadable = true;
+#endif
 }
 
 
@@ -359,7 +365,7 @@
     //ALOGE("rsdScriptInit %p %p", rsc, script);
 
     mCtx->lockMutex();
-
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
     bcc::RSExecutable *exec = NULL;
 
@@ -418,7 +424,7 @@
 
 #if defined(__i386__)
     // x86 devices will use an optimized library.
-    core_lib = bcc::RSInfo::LibCLCoreX86Path;
+     core_lib = bcc::RSInfo::LibCLCoreX86Path;
 #endif
 
     RSSelectRTCallback selectRTCallback = mCtx->getSelectRTCallback();
@@ -680,7 +686,7 @@
         goto error;
     }
 #endif
-
+#endif // FAKE_ARM64_BUILD
     mCtx->unlockMutex();
     return true;
 
@@ -702,6 +708,7 @@
 }
 
 void RsdCpuScriptImpl::populateScript(Script *script) {
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
     const bcc::RSInfo *info = &mExecutable->getInfo();
 
@@ -735,6 +742,7 @@
         script->mHal.info.root = mRoot;
     }
 #endif
+#endif
 }
 
 
@@ -859,6 +867,7 @@
 void RsdCpuScriptImpl::forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls) {
     mtls->script = this;
     mtls->fep.slot = slot;
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
     rsAssert(slot < mExecutable->getExportForeachFuncAddrs().size());
     mtls->kernel = reinterpret_cast<ForEachFunc_t>(
@@ -870,25 +879,34 @@
     rsAssert(mtls->kernel != NULL);
     mtls->sig = mForEachSignatures[slot];
 #endif
+#endif
 }
 
 int RsdCpuScriptImpl::invokeRoot() {
     RsdCpuScriptImpl * oldTLS = mCtx->setTLS(this);
+#ifndef FAKE_ARM64_BUILD
     int ret = mRoot();
+#else
+    int ret = 0;
+#endif
     mCtx->setTLS(oldTLS);
     return ret;
 }
 
 void RsdCpuScriptImpl::invokeInit() {
+#ifndef FAKE_ARM64_BUILD
     if (mInit) {
         mInit();
     }
+#endif
 }
 
 void RsdCpuScriptImpl::invokeFreeChildren() {
+#ifndef FAKE_ARM64_BUILD
     if (mFreeChildren) {
         mFreeChildren();
     }
+#endif
 }
 
 void RsdCpuScriptImpl::invokeFunction(uint32_t slot, const void *params,
@@ -896,12 +914,14 @@
     //ALOGE("invoke %p %p %i %p %i", dc, script, slot, params, paramLength);
 
     RsdCpuScriptImpl * oldTLS = mCtx->setTLS(this);
+#ifndef FAKE_ARM64_BUILD
     reinterpret_cast<void (*)(const void *, uint32_t)>(
 #ifndef RS_COMPATIBILITY_LIB
         mExecutable->getExportFuncAddrs()[slot])(params, paramLength);
 #else
         mInvokeFunctions[slot])(params, paramLength);
 #endif
+#endif
     mCtx->setTLS(oldTLS);
 }
 
@@ -914,12 +934,16 @@
         //return;
     //}
 
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
     int32_t *destPtr = reinterpret_cast<int32_t *>(
                           mExecutable->getExportVarAddrs()[slot]);
 #else
     int32_t *destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
 #endif
+#else
+    int32_t *destPtr = NULL;
+#endif
     if (!destPtr) {
         //ALOGV("Calling setVar on slot = %i which is null", slot);
         return;
@@ -932,12 +956,16 @@
     //rsAssert(!script->mFieldIsObject[slot]);
     //ALOGE("getGlobalVar %p %p %i %p %i", dc, script, slot, data, dataLength);
 
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
     int32_t *srcPtr = reinterpret_cast<int32_t *>(
                           mExecutable->getExportVarAddrs()[slot]);
 #else
     int32_t *srcPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
 #endif
+#else
+    int32_t *srcPtr = NULL;
+#endif
     if (!srcPtr) {
         //ALOGV("Calling setVar on slot = %i which is null", slot);
         return;
@@ -950,12 +978,16 @@
                                                 const Element *elem,
                                                 const size_t *dims, size_t dimLength) {
 
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
     int32_t *destPtr = reinterpret_cast<int32_t *>(
         mExecutable->getExportVarAddrs()[slot]);
 #else
     int32_t *destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
 #endif
+#else
+    int32_t *destPtr = NULL;
+#endif
     if (!destPtr) {
         //ALOGV("Calling setVar on slot = %i which is null", slot);
         return;
@@ -992,12 +1024,16 @@
     //rsAssert(!script->mFieldIsObject[slot]);
     //ALOGE("setGlobalBind %p %p %i %p", dc, script, slot, data);
 
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
     int32_t *destPtr = reinterpret_cast<int32_t *>(
                           mExecutable->getExportVarAddrs()[slot]);
 #else
     int32_t *destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
 #endif
+#else
+    int32_t *destPtr = NULL;
+#endif
     if (!destPtr) {
         //ALOGV("Calling setVar on slot = %i which is null", slot);
         return;
@@ -1021,12 +1057,18 @@
         //return;
     //}
 
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
     int32_t *destPtr = reinterpret_cast<int32_t *>(
                           mExecutable->getExportVarAddrs()[slot]);
 #else
     int32_t *destPtr = reinterpret_cast<int32_t *>(mFieldAddress[slot]);
 #endif
+#else
+    int32_t *destPtr = NULL;
+#endif
+
+
     if (!destPtr) {
         //ALOGV("Calling setVar on slot = %i which is null", slot);
         return;
@@ -1036,6 +1078,7 @@
 }
 
 RsdCpuScriptImpl::~RsdCpuScriptImpl() {
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
     if (mExecutable) {
         Vector<void *>::const_iterator var_addr_iter =
@@ -1099,6 +1142,7 @@
         dlclose(mScriptSO);
     }
 #endif
+#endif
 }
 
 Allocation * RsdCpuScriptImpl::getAllocationForPointer(const void *ptr) const {
diff --git a/cpu_ref/rsCpuScript.h b/cpu_ref/rsCpuScript.h
index c8a73bb..eeb38bf 100644
--- a/cpu_ref/rsCpuScript.h
+++ b/cpu_ref/rsCpuScript.h
@@ -91,14 +91,19 @@
 
     virtual Allocation * getAllocationForPointer(const void *ptr) const;
 
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
     virtual  void * getRSExecutable() { return mExecutable; }
 #endif
+#else
+    virtual void* getRSExecutable() { return NULL; }
+#endif
 
 protected:
     RsdCpuReferenceImpl *mCtx;
     const Script *mScript;
 
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
     int (*mRoot)();
     int (*mRootExpand)();
@@ -127,6 +132,7 @@
     size_t mExportedVariableCount;
     size_t mExportedFunctionCount;
 #endif
+#endif
 
     Allocation **mBoundAllocs;
     void * mIntrinsicData;
diff --git a/driver/rsdCore.cpp b/driver/rsdCore.cpp
index e38f92a..43c2375 100644
--- a/driver/rsdCore.cpp
+++ b/driver/rsdCore.cpp
@@ -190,6 +190,7 @@
                                           &rsdLookupRuntimeStub, &LookupScript);
     if (!dc->mCpuRef) {
         ALOGE("RsdCpuReference::create for driver hal failed.");
+        rsc->mHal.drv = NULL;
         free(dc);
         return false;
     }
@@ -230,6 +231,7 @@
 void Shutdown(Context *rsc) {
     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
     delete dc->mCpuRef;
+    free(dc);
     rsc->mHal.drv = NULL;
 }
 
diff --git a/driver/rsdGL.cpp b/driver/rsdGL.cpp
index c421ade..ff0c9a6 100644
--- a/driver/rsdGL.cpp
+++ b/driver/rsdGL.cpp
@@ -542,8 +542,9 @@
     const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
 
     RsdVertexArray::Attrib attribs[2];
-    attribs[0].set(GL_FLOAT, 3, 12, false, (uint32_t)vtx, "ATTRIB_position");
-    attribs[1].set(GL_FLOAT, 2, 8, false, (uint32_t)tex, "ATTRIB_texture0");
+
+    attribs[0].set(GL_FLOAT, 3, 12, false, (size_t)vtx, "ATTRIB_position");
+    attribs[1].set(GL_FLOAT, 2, 8, false, (size_t)tex, "ATTRIB_texture0");
 
     RsdVertexArray va(attribs, 2);
     va.setup(rsc);
diff --git a/driver/rsdMeshObj.cpp b/driver/rsdMeshObj.cpp
index e8df21f..66c3b18 100644
--- a/driver/rsdMeshObj.cpp
+++ b/driver/rsdMeshObj.cpp
@@ -126,7 +126,7 @@
 }
 
 void RsdMeshObj::renderPrimitiveRange(const Context *rsc, uint32_t primIndex,
-                                      uint32_t start, uint32_t len) const {
+                                      size_t start, uint32_t len) const {
     if (len < 1 || primIndex >= mRSMesh->mHal.state.primitivesCount || mAttribCount == 0) {
         rsc->setError(RS_ERROR_FATAL_DRIVER, "Invalid mesh or parameters");
         return;
diff --git a/driver/rsdMeshObj.h b/driver/rsdMeshObj.h
index 1370f01..58eb1ae 100644
--- a/driver/rsdMeshObj.h
+++ b/driver/rsdMeshObj.h
@@ -38,7 +38,7 @@
     ~RsdMeshObj();
 
     void renderPrimitiveRange(const android::renderscript::Context *,
-                              uint32_t primIndex, uint32_t start, uint32_t len) const;
+                              uint32_t primIndex, size_t start, uint32_t len) const;
 
     bool init(const android::renderscript::Context *rsc);
 
diff --git a/driver/rsdPath.cpp b/driver/rsdPath.cpp
index 79ec487..ee5e3ad 100644
--- a/driver/rsdPath.cpp
+++ b/driver/rsdPath.cpp
@@ -150,8 +150,8 @@
     }
 
     RsdVertexArray::Attrib attribs[2];
-    attribs[0].set(GL_FLOAT, 2, 8, false, (uint32_t)vtx, "ATTRIB_position");
-    attribs[1].set(GL_FLOAT, 4, 16, false, (uint32_t)color, "ATTRIB_color");
+    attribs[0].set(GL_FLOAT, 2, 8, false, (size_t)vtx, "ATTRIB_position");
+    attribs[1].set(GL_FLOAT, 4, 16, false, (size_t)color, "ATTRIB_color");
     RsdVertexArray va(attribs, 2);
     va.setup(rsc);
 
diff --git a/driver/rsdProgram.cpp b/driver/rsdProgram.cpp
index a96a5f9..132f7be 100644
--- a/driver/rsdProgram.cpp
+++ b/driver/rsdProgram.cpp
@@ -71,7 +71,7 @@
     if(pv->mHal.drv) {
         drv = (RsdShader*)pv->mHal.drv;
         if (rsc->props.mLogShaders) {
-            ALOGV("Destroying vertex shader with ID %u", (uint32_t)pv);
+            ALOGV("Destroying vertex shader with ID %p", (void*)pv);
         }
         if (drv->getStateBasedIDCount()) {
             dc->gl.shaderCache->cleanupVertex(drv);
@@ -105,7 +105,7 @@
     if(pf->mHal.drv) {
         drv = (RsdShader*)pf->mHal.drv;
         if (rsc->props.mLogShaders) {
-            ALOGV("Destroying fragment shader with ID %u", (uint32_t)pf);
+            ALOGV("Destroying fragment shader with ID %p", (void*)pf);
         }
         if (drv->getStateBasedIDCount()) {
             dc->gl.shaderCache->cleanupFragment(drv);
diff --git a/driver/rsdRuntimeStubs.cpp b/driver/rsdRuntimeStubs.cpp
index cb5d008..d1f29f0 100644
--- a/driver/rsdRuntimeStubs.cpp
+++ b/driver/rsdRuntimeStubs.cpp
@@ -284,8 +284,8 @@
     const float tex[] = {u1,v1, u2,v2, u3,v3, u4,v4};
 
     RsdVertexArray::Attrib attribs[2];
-    attribs[0].set(GL_FLOAT, 3, 12, false, (uint32_t)vtx, "ATTRIB_position");
-    attribs[1].set(GL_FLOAT, 2, 8, false, (uint32_t)tex, "ATTRIB_texture0");
+    attribs[0].set(GL_FLOAT, 3, 12, false, (size_t)vtx, "ATTRIB_position");
+    attribs[1].set(GL_FLOAT, 2, 8, false, (size_t)tex, "ATTRIB_texture0");
 
     RsdVertexArray va(attribs, 2);
     va.setup(rsc);
diff --git a/driver/rsdShader.cpp b/driver/rsdShader.cpp
index 816b17c..0b182ff 100644
--- a/driver/rsdShader.cpp
+++ b/driver/rsdShader.cpp
@@ -468,8 +468,8 @@
     uint32_t numTexturesToBind = mRSProgram->mHal.state.texturesCount;
     uint32_t numTexturesAvailable = dc->gl.gl.maxFragmentTextureImageUnits;
     if (numTexturesToBind >= numTexturesAvailable) {
-        ALOGE("Attempting to bind %u textures on shader id %u, but only %u are available",
-             mRSProgram->mHal.state.texturesCount, (uint32_t)this, numTexturesAvailable);
+        ALOGE("Attempting to bind %u textures on shader id %p, but only %u are available",
+             mRSProgram->mHal.state.texturesCount, this, numTexturesAvailable);
         rsc->setError(RS_ERROR_BAD_SHADER, "Cannot bind more textuers than available");
         numTexturesToBind = numTexturesAvailable;
     }
@@ -489,8 +489,8 @@
         if (mCurrentState->mTextureTargets[ct] != GL_TEXTURE_2D &&
             mCurrentState->mTextureTargets[ct] != GL_TEXTURE_CUBE_MAP &&
             mCurrentState->mTextureTargets[ct] != GL_TEXTURE_EXTERNAL_OES) {
-            ALOGE("Attempting to bind unknown texture to shader id %u, texture unit %u",
-                  (uint)this, ct);
+            ALOGE("Attempting to bind unknown texture to shader id %p, texture unit %u",
+                  this, ct);
             rsc->setError(RS_ERROR_BAD_SHADER, "Non-texture allocation bound to a shader");
         }
         RSD_CALL_GL(glBindTexture, mCurrentState->mTextureTargets[ct], drvTex->textureID);
@@ -523,8 +523,8 @@
         Allocation *alloc = mRSProgram->mHal.state.constants[ct];
 
         if (!alloc) {
-            ALOGE("Attempting to set constants on shader id %u, but alloc at slot %u is not set",
-                 (uint32_t)this, ct);
+            ALOGE("Attempting to set constants on shader id %p, but alloc at slot %u is not set",
+                  this, ct);
             rsc->setError(RS_ERROR_BAD_SHADER, "No constant allocation bound");
             continue;
         }
diff --git a/driver/rsdShader.h b/driver/rsdShader.h
index 2680b3e..fba1790 100644
--- a/driver/rsdShader.h
+++ b/driver/rsdShader.h
@@ -39,7 +39,7 @@
 public:
 
     RsdShader(const android::renderscript::Program *p, uint32_t type,
-              const char * shaderText, uint32_t shaderLength,
+              const char * shaderText, size_t shaderLength,
               const char** textureNames, size_t textureNamesCount,
               const size_t *textureNamesLength);
     virtual ~RsdShader();
diff --git a/driver/rsdVertexArray.cpp b/driver/rsdVertexArray.cpp
index 1836e67..4e293f6 100644
--- a/driver/rsdVertexArray.cpp
+++ b/driver/rsdVertexArray.cpp
@@ -52,7 +52,7 @@
 }
 
 void RsdVertexArray::Attrib::set(uint32_t type, uint32_t size, uint32_t stride,
-                              bool normalized, uint32_t offset,
+                              bool normalized, size_t offset,
                               const char *name) {
     clear();
     this->type = type;
@@ -67,16 +67,16 @@
     if (idx == 0) {
         ALOGV("Starting vertex attribute binding");
     }
-    ALOGV("va %i: slot=%i name=%s buf=%i ptr=%p size=%i  type=0x%x  stride=0x%x  norm=%i  offset=0x%x",
-         idx, slot,
-         mAttribs[idx].name.string(),
-         mAttribs[idx].buffer,
-         mAttribs[idx].ptr,
-         mAttribs[idx].size,
-         mAttribs[idx].type,
-         mAttribs[idx].stride,
-         mAttribs[idx].normalized,
-         mAttribs[idx].offset);
+    ALOGV("va %i: slot=%i name=%s buf=%i ptr=%p size=%i  type=0x%x  stride=0x%x  norm=%i  offset=0x%p",
+          idx, slot,
+          mAttribs[idx].name.string(),
+          mAttribs[idx].buffer,
+          mAttribs[idx].ptr,
+          mAttribs[idx].size,
+          mAttribs[idx].type,
+          mAttribs[idx].stride,
+          mAttribs[idx].normalized,
+          (void*)mAttribs[idx].offset);
 }
 
 void RsdVertexArray::setup(const Context *rsc) const {
diff --git a/driver/rsdVertexArray.h b/driver/rsdVertexArray.h
index 9c655df..975121b 100644
--- a/driver/rsdVertexArray.h
+++ b/driver/rsdVertexArray.h
@@ -34,7 +34,7 @@
     public:
         uint32_t buffer;
         const uint8_t * ptr;
-        uint32_t offset;
+        size_t offset;
         uint32_t type;
         uint32_t size;
         uint32_t stride;
@@ -43,7 +43,7 @@
 
         Attrib();
         void clear();
-        void set(uint32_t type, uint32_t size, uint32_t stride, bool normalized, uint32_t offset, const char *name);
+        void set(uint32_t type, uint32_t size, uint32_t stride, bool normalized, size_t offset, const char *name);
     };
 
     RsdVertexArray(const Attrib *attribs, uint32_t numAttribs);
diff --git a/driver/runtime/Android.mk b/driver/runtime/Android.mk
index 2f8dd5d..501e989 100755
--- a/driver/runtime/Android.mk
+++ b/driver/runtime/Android.mk
@@ -64,6 +64,10 @@
 
 # Build the base version of the library
 include $(CLEAR_VARS)
+
+# FIXME for 64-bit
+LOCAL_32_BIT_ONLY := true
+
 LOCAL_MODULE := libclcore.bc
 LOCAL_SRC_FILES := $(clcore_files)
 
@@ -71,6 +75,10 @@
 
 # Build a debug version of the library
 include $(CLEAR_VARS)
+
+# FIXME for 64-bit
+LOCAL_32_BIT_ONLY := true
+
 LOCAL_MODULE := libclcore_debug.bc
 rs_debug_runtime := 1
 LOCAL_SRC_FILES := $(clcore_files)
@@ -80,6 +88,10 @@
 # Build an optimized version of the library for x86 platforms (all have SSE2/3).
 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
 include $(CLEAR_VARS)
+
+# FIXME for 64-bit
+LOCAL_32_BIT_ONLY := true
+
 LOCAL_MODULE := libclcore_x86.bc
 LOCAL_SRC_FILES := $(clcore_x86_files)
 
@@ -89,6 +101,10 @@
 # Build a NEON-enabled version of the library (if possible)
 ifeq ($(ARCH_ARM_HAVE_NEON),true)
   include $(CLEAR_VARS)
+
+  # FIXME for 64-bit
+  LOCAL_32_BIT_ONLY := true
+
   LOCAL_MODULE := libclcore_neon.bc
   LOCAL_SRC_FILES := $(clcore_neon_files)
   LOCAL_CFLAGS += -DARCH_ARM_HAVE_NEON
@@ -101,6 +117,10 @@
 
 # Build the ARM version of the library
 include $(CLEAR_VARS)
+
+# FIXME for 64-bit
+LOCAL_32_BIT_ONLY := true
+
 BCC_RS_TRIPLE := armv7-none-linux-gnueabi
 LOCAL_MODULE := librsrt_arm.bc
 LOCAL_IS_HOST_MODULE := true
@@ -109,6 +129,10 @@
 
 # Build the MIPS version of the library
 include $(CLEAR_VARS)
+
+# FIXME for 64-bit
+LOCAL_32_BIT_ONLY := true
+
 BCC_RS_TRIPLE := mipsel-unknown-linux
 LOCAL_MODULE := librsrt_mips.bc
 LOCAL_IS_HOST_MODULE := true
@@ -117,8 +141,13 @@
 
 # Build the x86 version of the library
 include $(CLEAR_VARS)
+
+# FIXME for 64-bit
+LOCAL_32_BIT_ONLY := true
+
 BCC_RS_TRIPLE := i686-unknown-linux
 LOCAL_MODULE := librsrt_x86.bc
 LOCAL_IS_HOST_MODULE := true
 LOCAL_SRC_FILES := $(clcore_x86_files)
 include $(LOCAL_PATH)/build_bc_lib.mk
+
diff --git a/java/Android.mk b/java/Android.mk
index c8f64ce..fdcbf97 100644
--- a/java/Android.mk
+++ b/java/Android.mk
@@ -1,7 +1,11 @@
 LOCAL_PATH:=$(call my-dir)
 
+ifneq ($(TARGET_ARCH), arm64)
+
 # Only build our tests if we doing a top-level build. Do not build the
 # tests if we are just doing an mm or mmm in frameworks/rs.
 ifeq (,$(ONE_SHOT_MAKEFILE))
 include $(call all-makefiles-under,$(LOCAL_PATH))
 endif
+
+endif
\ No newline at end of file
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index 49c9b57..f84c4b4 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -17,12 +17,14 @@
 #include "rsContext.h"
 #include "rsScriptC.h"
 
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
 #include <bcinfo/BitcodeTranslator.h>
 #include <bcinfo/BitcodeWrapper.h>
 #endif
 #endif
+#endif
 
 #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
 #include "utils/Timers.h"
@@ -40,14 +42,17 @@
     ScriptC * sc = (ScriptC *) tls->mScript
 
 ScriptC::ScriptC(Context *rsc) : Script(rsc) {
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
     BT = NULL;
 #endif
 #endif
+#endif
 }
 
 ScriptC::~ScriptC() {
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
     if (BT) {
@@ -56,12 +61,14 @@
     }
 #endif
 #endif
+#endif
     if (mInitialized) {
         mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this);
         mRSC->mHal.funcs.script.destroy(mRSC, this);
     }
 }
 
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
 bool ScriptC::createCacheDir(const char *cacheDir) {
     String8 cacheDirString, currentDir;
@@ -100,6 +107,7 @@
     return true;
 }
 #endif
+#endif
 
 void ScriptC::setupScript(Context *rsc) {
 #ifndef RS_SERVER
@@ -249,6 +257,7 @@
                           size_t bitcodeLen) {
     ATRACE_CALL();
     //ALOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen);
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
     uint32_t sdkVersion = 0;
@@ -281,8 +290,8 @@
     }
     bitcode = (const uint8_t *) BT->getTranslatedBitcode();
     bitcodeLen = BT->getTranslatedBitcodeSize();
-#endif
 
+#endif
     if (!cacheDir) {
         // MUST BE FIXED BEFORE ANYTHING USING C++ API IS RELEASED
         cacheDir = getenv("EXTERNAL_STORAGE");
@@ -294,6 +303,7 @@
       return false;
     }
 #endif
+#endif
 
     if (!rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0)) {
         return false;
diff --git a/rsScriptC.h b/rsScriptC.h
index c1e3301..fdf678d 100644
--- a/rsScriptC.h
+++ b/rsScriptC.h
@@ -21,11 +21,13 @@
 
 #include "rsEnv.h"
 
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
 #include "bcinfo/BitcodeTranslator.h"
 #endif
 #endif
+#endif
 
 // ---------------------------------------------------------------------------
 namespace android {
@@ -63,6 +65,7 @@
     void setupScript(Context *);
     void setupGLState(Context *);
 private:
+#ifndef FAKE_ARM64_BUILD
 #ifndef RS_COMPATIBILITY_LIB
 #ifndef ANDROID_RS_SERIALIZE
     bcinfo::BitcodeTranslator *BT;
@@ -70,6 +73,7 @@
 
     bool createCacheDir(const char *cacheDir);
 #endif
+#endif
 };
 
 class ScriptCState {