xref: /openbsd-src/gnu/llvm/compiler-rt/lib/tsan/benchmarks/func_entry_exit.cpp (revision 3cab2bb3f667058bece8e38b12449a63a9d73c4b)
1*3cab2bb3Spatrick // Synthetic benchmark for __tsan_func_entry/exit (spends ~75% there).
2*3cab2bb3Spatrick 
3*3cab2bb3Spatrick void foo(bool x);
4*3cab2bb3Spatrick 
main()5*3cab2bb3Spatrick int main() {
6*3cab2bb3Spatrick   volatile int kRepeat1 = 1 << 30;
7*3cab2bb3Spatrick   const int kRepeat = kRepeat1;
8*3cab2bb3Spatrick   for (int i = 0; i < kRepeat; i++)
9*3cab2bb3Spatrick     foo(false);
10*3cab2bb3Spatrick }
11*3cab2bb3Spatrick 
bar(volatile bool x)12*3cab2bb3Spatrick __attribute__((noinline)) void bar(volatile bool x) {
13*3cab2bb3Spatrick   if (x)
14*3cab2bb3Spatrick     foo(x);
15*3cab2bb3Spatrick }
16*3cab2bb3Spatrick 
foo(bool x)17*3cab2bb3Spatrick __attribute__((noinline)) void foo(bool x) {
18*3cab2bb3Spatrick   if (__builtin_expect(x, false))
19*3cab2bb3Spatrick     bar(x);
20*3cab2bb3Spatrick }
21