Add DoNotOptimize and use it in tests.
Bug: http://b/148307629
Test: treehugger
Change-Id: I3b1726ae55116f6553ea38fe163abdde179c21f0
diff --git a/tests/utils.h b/tests/utils.h
index acd8bc6..94ff050 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -290,3 +290,13 @@
size_t start_count_ = CountOpenFds();
};
+
+// From <benchmark/benchmark.h>.
+template <class Tp>
+static inline void DoNotOptimize(Tp const& value) {
+ asm volatile("" : : "r,m"(value) : "memory");
+}
+template <class Tp>
+static inline void DoNotOptimize(Tp& value) {
+ asm volatile("" : "+r,m"(value) : : "memory");
+}