Merge "Enable 64bit RS compat lib to build."
diff --git a/Android.mk b/Android.mk
index cb3ef33..d9af8cc 100644
--- a/Android.mk
+++ b/Android.mk
@@ -83,6 +83,7 @@
     rsg_generator.c
 
 LOCAL_CXX_STL := none
+LOCAL_ADDRESS_SANITIZER := false
 
 include $(BUILD_HOST_EXECUTABLE)
 
diff --git a/api/generate.sh b/api/generate.sh
index 55bb208..0514661 100755
--- a/api/generate.sh
+++ b/api/generate.sh
@@ -16,7 +16,7 @@
 #
 
 set -e
-g++ gen_runtime.cpp -Wall -o gen_runtime
+g++ gen_runtime.cpp -std=c++11 -Wall -o gen_runtime
 ./gen_runtime -v 21 rs_core_math.spec
 mv Test*.java ../../../cts/tests/tests/renderscript/src/android/renderscript/cts/
 mv Test*.rs ../../../cts/tests/tests/renderscript/src/android/renderscript/cts/
diff --git a/cpu_ref/Android.mk b/cpu_ref/Android.mk
index a91e373..5de964f 100644
--- a/cpu_ref/Android.mk
+++ b/cpu_ref/Android.mk
@@ -43,6 +43,10 @@
 
 LOCAL_CFLAGS_arm64 += -DARCH_ARM_USE_INTRINSICS -DARCH_ARM64_USE_INTRINSICS -DARCH_ARM64_HAVE_NEON
 
+ifeq ($(RS_DISABLE_A53_WORKAROUND),true)
+LOCAL_CFLAGS_arm64 += -DDISABLE_A53_WORKAROUND
+endif
+
 LOCAL_SRC_FILES_arm64 += \
     rsCpuIntrinsics_advsimd_3DLUT.S \
     rsCpuIntrinsics_advsimd_Convolve.S \
diff --git a/cpu_ref/rsCpuIntrinsics_neon_ColorMatrix.S b/cpu_ref/rsCpuIntrinsics_neon_ColorMatrix.S
index de996fa..ecb8c13 100644
--- a/cpu_ref/rsCpuIntrinsics_neon_ColorMatrix.S
+++ b/cpu_ref/rsCpuIntrinsics_neon_ColorMatrix.S
@@ -14,8 +14,6 @@
  * limitations under the License.
  */
 
-#include <machine/cpu-features.h>
-
 #define SNIP_START(x) \
     .globl x; x:
 
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index f4abe67..fe51eec 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -258,6 +258,11 @@
     args->push_back("-mtriple");
     args->push_back(DEFAULT_TARGET_TRIPLE_STRING);
 
+    // Enable workaround for A53 codegen by default.
+#if defined(__aarch64__) && !defined(DISABLE_A53_WORKAROUND)
+    args->push_back("-aarch64-fix-cortex-a53-835769");
+#endif
+
     // Execute the bcc compiler.
     if (useRSDebugContext) {
         args->push_back("-rs-debug-ctx");
diff --git a/driver/rsdRuntimeStubs.cpp b/driver/rsdRuntimeStubs.cpp
index 15f810a..c90ab84 100644
--- a/driver/rsdRuntimeStubs.cpp
+++ b/driver/rsdRuntimeStubs.cpp
@@ -616,6 +616,7 @@
 }
 #endif
 
+// These functions are only supported in 32-bit.
 #ifndef __LP64__
 static void SC_ForEach_SAAUL(android::renderscript::rs_script target,
                              android::renderscript::rs_allocation in,
@@ -626,18 +627,6 @@
     rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p,
                usr, usrLen, nullptr);
 }
-#else
-static void SC_ForEach_SAAUL(android::renderscript::rs_script *target,
-                             android::renderscript::rs_allocation *in,
-                             android::renderscript::rs_allocation *out,
-                             const void *usr,
-                             uint32_t usrLen) {
-    Context *rsc = RsdCpuReference::getTlsContext();
-    rsrForEach(rsc, (Script*)target->p, (Allocation*)in->p, (Allocation*)out->p, usr, usrLen, NULL);
-}
-#endif
-
-#ifndef __LP64__
 static void SC_ForEach_SAAULS(android::renderscript::rs_script target,
                               android::renderscript::rs_allocation in,
                               android::renderscript::rs_allocation out,
@@ -647,16 +636,6 @@
     Context *rsc = RsdCpuReference::getTlsContext();
     rsrForEach(rsc, (Script*)target.p, (Allocation*)in.p, (Allocation*)out.p, usr, usrLen, call);
 }
-#else
-static void SC_ForEach_SAAULS(android::renderscript::rs_script *target,
-                              android::renderscript::rs_allocation *in,
-                              android::renderscript::rs_allocation *out,
-                              const void *usr,
-                              uint32_t usrLen,
-                              const RsScriptCall *call) {
-    Context *rsc = RsdCpuReference::getTlsContext();
-    rsrForEach(rsc, (Script*)target->p, (Allocation*)in->p, (Allocation*)out->p, usr, usrLen, call);
-}
 #endif
 #endif
 
@@ -1408,8 +1387,12 @@
     { "_Z9rsForEach9rs_script13rs_allocationS0_", (void *)&SC_ForEach_SAA, true },
     { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach_SAAU, true },
     { "_Z9rsForEach9rs_script13rs_allocationS0_PKvPK14rs_script_call", (void *)&SC_ForEach_SAAUS, true },
+
+    //rsForEach with usrdata is not supported in 64-bit
+#ifndef __LP64__
     { "_Z9rsForEach9rs_script13rs_allocationS0_PKvj", (void *)&SC_ForEach_SAAUL, true },
     { "_Z9rsForEach9rs_script13rs_allocationS0_PKvjPK14rs_script_call", (void *)&SC_ForEach_SAAULS, true },
+#endif
 #endif // RS_COMPATIBILITY_LIB
 
 #ifndef __LP64__
diff --git a/java/tests/RsTest_11/Android.mk b/java/tests/RsTest_11/Android.mk
index 52d326b..13c8065 100644
--- a/java/tests/RsTest_11/Android.mk
+++ b/java/tests/RsTest_11/Android.mk
@@ -14,8 +14,6 @@
 # limitations under the License.
 #
 
-ifneq ($(TARGET_SIMULATOR),true)
-
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 
@@ -27,5 +25,3 @@
 LOCAL_SDK_VERSION := 11
 
 include $(BUILD_PACKAGE)
-
-endif
diff --git a/rsScriptC_Lib.cpp b/rsScriptC_Lib.cpp
index 4bb0b1c..628190d 100644
--- a/rsScriptC_Lib.cpp
+++ b/rsScriptC_Lib.cpp
@@ -94,12 +94,7 @@
     // have to apply locking for proper behavior in RenderScript.
     pthread_mutex_lock(&rsc->gLibMutex);
     tm *tmp = localtime(timer);
-#ifndef RS_COMPATIBILITY_LIB
-    memcpy(local, tmp, sizeof(*tmp));
-#else
-    // WORKAROUND to struct rs_tm != struct tm
     memcpy(local, tmp, sizeof(int)*9);
-#endif
     pthread_mutex_unlock(&rsc->gLibMutex);
     return local;
 }
diff --git a/scriptc/rs_core.rsh b/scriptc/rs_core.rsh
index 3489e44..2052a2e 100644
--- a/scriptc/rs_core.rsh
+++ b/scriptc/rs_core.rsh
@@ -150,6 +150,8 @@
               rs_allocation output, const void * usrData);
 #else
 
+
+#if (RS_VERSION < 21)
 /**
  * Make a script to script call to launch work. One of the input or output is
  * required to be a valid object. The input and output must be of the same
@@ -160,7 +162,7 @@
  * @param input The allocation to source data from
  * @param output the allocation to write date into
  * @param usrData The user definied params to pass to the root script.  May be
- *                NULL.
+ *                NULL. Not supported in API 21 or higher.
  * @param usrDataLen The size of the userData structure.  This will be used to
  *                   perform a shallow copy of the data if necessary.
  * @param sc Extra control infomation used to select a sub-region of the
@@ -177,6 +179,8 @@
 extern void __attribute__((overloadable))
     rsForEach(rs_script script, rs_allocation input, rs_allocation output,
               const void * usrData, size_t usrDataLen);
+#endif
+
 /**
  * \overload
  */
diff --git a/update_rs_prebuilts.sh b/update_rs_prebuilts.sh
index 362a0c0..2526384 100755
--- a/update_rs_prebuilts.sh
+++ b/update_rs_prebuilts.sh
@@ -167,7 +167,7 @@
 done
 
 for a in $TOOLS_LIB; do
-  cp $ANDROID_HOST_OUT/lib/$a tools/$SHORT_OSNAME/
+  cp $HOST_LIB64_DIR/$a tools/$SHORT_OSNAME/
   strip tools/$SHORT_OSNAME/$a
 done