1 #include "benchmark/benchmark.h"
7 std::uint64_t double_up(const std::uint64_t x
) __attribute__((const));
9 std::uint64_t double_up(const std::uint64_t x
) { return x
* 2; }
12 // Using DoNotOptimize on types like BitRef seem to cause a lot of problems
13 // with the inline assembly on both GCC and Clang.
19 static BitRef
Make() {
20 static unsigned char arr
[2] = {};
25 BitRef(int i
, unsigned char& b
) : index(i
), byte(b
) {}
28 int main(int, char*[]) {
29 // this test verifies compilation of DoNotOptimize() for some types
32 benchmark::DoNotOptimize(buffer8
);
34 char buffer20
[20] = "";
35 benchmark::DoNotOptimize(buffer20
);
37 char buffer1024
[1024] = "";
38 benchmark::DoNotOptimize(buffer1024
);
39 benchmark::DoNotOptimize(&buffer1024
[0]);
42 benchmark::DoNotOptimize(x
);
43 benchmark::DoNotOptimize(&x
);
44 benchmark::DoNotOptimize(x
+= 42);
46 benchmark::DoNotOptimize(double_up(x
));
48 // These tests are to e
49 benchmark::DoNotOptimize(BitRef::Make());
50 BitRef lval
= BitRef::Make();
51 benchmark::DoNotOptimize(lval
);