Add a property for overriding FP precision.

adb shell setprop debug.rs.precision rs_fp_full
adb shell setprop debug.rs.precision rs_fp_relaxed
adb shell setprop debug.rs.precision rs_fp_imprecise

Change-Id: Ic7dcba631aeab1046ce928fe8b09122747939870
diff --git a/bcinfo/MetadataExtractor.cpp b/bcinfo/MetadataExtractor.cpp
index 6601ede..da79208 100644
--- a/bcinfo/MetadataExtractor.cpp
+++ b/bcinfo/MetadataExtractor.cpp
@@ -20,6 +20,7 @@
 
 #define LOG_TAG "bcinfo"
 #include <cutils/log.h>
+#include <cutils/properties.h>
 
 #include "llvm/ADT/OwningPtr.h"
 #include "llvm/Bitcode/ReaderWriter.h"
@@ -221,6 +222,7 @@
   // Check to see if we have any FP precision-related pragmas.
   std::string Relaxed("rs_fp_relaxed");
   std::string Imprecise("rs_fp_imprecise");
+  std::string Full("rs_fp_full");
   bool RelaxedPragmaSeen = false;
   bool ImprecisePragmaSeen = false;
 
@@ -246,6 +248,26 @@
     mRSFloatPrecision = RS_FP_Relaxed;
   }
 
+  // Provide an override for precsion via adb shell setprop
+  // adb shell setprop debug.rs.precision rs_fp_full
+  // adb shell setprop debug.rs.precision rs_fp_relaxed
+  // adb shell setprop debug.rs.precision rs_fp_imprecise
+  char PrecisionPropBuf[PROPERTY_VALUE_MAX];
+  const std::string PrecisionPropName("debug.rs.precision");
+  property_get("debug.rs.precision", PrecisionPropBuf, "");
+  if (PrecisionPropBuf[0]) {
+    if (!Relaxed.compare(PrecisionPropBuf)) {
+      ALOGE("Switching to RS FP relaxed mode via setprop");
+      mRSFloatPrecision = RS_FP_Relaxed;
+    } else if (!Imprecise.compare(PrecisionPropBuf)) {
+      ALOGE("Switching to RS FP imprecise mode via setprop");
+      mRSFloatPrecision = RS_FP_Imprecise;
+    } else if (!Full.compare(PrecisionPropBuf)) {
+      ALOGE("Switching to RS FP full mode via setprop");
+      mRSFloatPrecision = RS_FP_Full;
+    }
+  }
+
   return;
 }
 
diff --git a/lib/ExecutionEngine/Script.cpp b/lib/ExecutionEngine/Script.cpp
index 11ef0e1..0c3c7a5 100644
--- a/lib/ExecutionEngine/Script.cpp
+++ b/lib/ExecutionEngine/Script.cpp
@@ -48,6 +48,12 @@
   return strcmp(buf, "0") != 0;
 }
 
+bool isSetProp(const char *str) {
+  char buf[PROPERTY_VALUE_MAX];
+  property_get(str, buf, "");
+  return buf[0] != '\0';
+}
+
 } // namespace anonymous
 
 namespace bcc {
@@ -762,6 +768,11 @@
     return false;
   }
 
+  if (isSetProp("debug.rs.precision")) {
+    // If we have a floating point precision override, don't use the cache.
+    return false;
+  }
+
   if (mCacheDir.empty() || mCacheName.empty()) {
     // The application developer has not specified the cachePath, so
     // we don't know where to open the cache file.