Make RS compile on ARM64.

bug 13280327

Change-Id: I79080c448ca17d0cba8df075737c22b24ce9a085
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/rsCpuIntrinsicColorMatrix.cpp b/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
index 0f49dc8..06bc222 100644
--- a/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
+++ b/cpu_ref/rsCpuIntrinsicColorMatrix.cpp
@@ -277,7 +277,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;      \
@@ -407,7 +407,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;