Neon detection for RS SDK compat lib.

Change-Id: I3887158c7ec97ba116c28dc7b1d0c789b81fae60
diff --git a/cpu_ref/rsCpuCore.cpp b/cpu_ref/rsCpuCore.cpp
index a4cf0ad..79b908c 100644
--- a/cpu_ref/rsCpuCore.cpp
+++ b/cpu_ref/rsCpuCore.cpp
@@ -28,6 +28,10 @@
 #include <string.h>
 #include <unistd.h>
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
 #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
 #include <cutils/properties.h>
 #include "utils/StopWatch.h"
@@ -53,6 +57,8 @@
 static uint32_t gThreadTLSKeyCount = 0;
 static pthread_mutex_t gInitMutex = PTHREAD_MUTEX_INITIALIZER;
 
+bool android::renderscript::gArchUseSIMD = false;
+
 RsdCpuReference::~RsdCpuReference() {
 }
 
@@ -193,6 +199,38 @@
     pthread_mutex_unlock(&gInitMutex);
 }
 
+#if defined(ARCH_ARM_HAVE_VFP)
+static int
+read_file(const char*  pathname, char*  buffer, size_t  buffsize)
+{
+    int  fd, len;
+
+    fd = open(pathname, O_RDONLY);
+    if (fd < 0)
+        return -1;
+
+    do {
+        len = read(fd, buffer, buffsize);
+    } while (len < 0 && errno == EINTR);
+
+    close(fd);
+
+    return len;
+}
+
+static void GetCpuInfo() {
+    char cpuinfo[4096];
+    int  cpuinfo_len;
+
+    cpuinfo_len = read_file("/proc/cpuinfo", cpuinfo, sizeof cpuinfo);
+    if (cpuinfo_len < 0)  /* should not happen */ {
+        return;
+    }
+
+    gArchUseSIMD = !!strstr(cpuinfo, " neon");
+}
+#endif // ARCH_ARM_HAVE_VFP
+
 bool RsdCpuReferenceImpl::init(uint32_t version_major, uint32_t version_minor,
                                sym_lookup_t lfn, script_lookup_t slfn) {
 
@@ -218,6 +256,10 @@
         ALOGE("pthread_setspecific %i", status);
     }
 
+#if defined(ARCH_ARM_HAVE_VFP)
+    GetCpuInfo();
+#endif
+
     int cpu = sysconf(_SC_NPROCESSORS_ONLN);
     if(mRSC->props.mDebugMaxThreads) {
         cpu = mRSC->props.mDebugMaxThreads;