Fix GetCpuInfo() routine to correctly check the cpuinfo file to make
sure we don't miss SIMD path if there is one.
Change-Id: I8c8841ba9924ee28ae56be8b3c66c50b5badf796
diff --git a/cpu_ref/rsCpuCore.cpp b/cpu_ref/rsCpuCore.cpp
index 08ed8f5..4367bd4 100644
--- a/cpu_ref/rsCpuCore.cpp
+++ b/cpu_ref/rsCpuCore.cpp
@@ -203,16 +203,19 @@
}
char cpuinfostr[4096];
- if (!fgets(cpuinfostr, sizeof(cpuinfostr), cpuinfo)) {
- cpuinfostr[0] = '\0';
+ // fgets() ends with newline or EOF, need to check the whole
+ // "cpuinfo" file to make sure we can use SIMD or not.
+ while (fgets(cpuinfostr, sizeof(cpuinfostr), cpuinfo)) {
+#if defined(ARCH_ARM_HAVE_VFP) || defined(ARCH_ARM_USE_INTRINSICS)
+ gArchUseSIMD = strstr(cpuinfostr, " neon") || strstr(cpuinfostr, " asimd");
+#elif defined(ARCH_X86_HAVE_SSSE3)
+ gArchUseSIMD = strstr(cpuinfostr, " ssse3");
+#endif
+ if (gArchUseSIMD) {
+ break;
+ }
}
fclose(cpuinfo);
-
-#if defined(ARCH_ARM_HAVE_VFP) || defined(ARCH_ARM_USE_INTRINSICS)
- gArchUseSIMD = strstr(cpuinfostr, " neon") || strstr(cpuinfostr, " asimd");
-#elif defined(ARCH_X86_HAVE_SSSE3)
- gArchUseSIMD = strstr(cpuinfostr, " ssse3");
-#endif
}
bool RsdCpuReferenceImpl::init(uint32_t version_major, uint32_t version_minor,