blob: e2c5c8648d03556692033e520bcb982f00669d6a [file] [log] [blame]
Kirill Bobyrev0addd172018-08-28 09:42:41 +00001#include <benchmark/benchmark.h>
2
3#ifdef __clang__
4#pragma clang diagnostic ignored "-Wreturn-type"
5#endif
6
7extern "C" {
8 extern int ExternInt;
9 benchmark::State& GetState();
10 void Fn();
11}
12
13using benchmark::State;
14
15// CHECK-LABEL: test_for_auto_loop:
16extern "C" int test_for_auto_loop() {
17 State& S = GetState();
18 int x = 42;
19 // CHECK: [[CALL:call(q)*]] _ZN9benchmark5State16StartKeepRunningEv
20 // CHECK-NEXT: testq %rbx, %rbx
21 // CHECK-NEXT: je [[LOOP_END:.*]]
22
23 for (auto _ : S) {
24 // CHECK: .L[[LOOP_HEAD:[a-zA-Z0-9_]+]]:
25 // CHECK-GNU-NEXT: subq $1, %rbx
26 // CHECK-CLANG-NEXT: {{(addq \$1,|incq)}} %rax
27 // CHECK-NEXT: jne .L[[LOOP_HEAD]]
28 benchmark::DoNotOptimize(x);
29 }
30 // CHECK: [[LOOP_END]]:
31 // CHECK: [[CALL]] _ZN9benchmark5State17FinishKeepRunningEv
32
33 // CHECK: movl $101, %eax
34 // CHECK: ret
35 return 101;
36}
37
38// CHECK-LABEL: test_while_loop:
39extern "C" int test_while_loop() {
40 State& S = GetState();
41 int x = 42;
42
43 // CHECK: j{{(e|mp)}} .L[[LOOP_HEADER:[a-zA-Z0-9_]+]]
44 // CHECK-NEXT: .L[[LOOP_BODY:[a-zA-Z0-9_]+]]:
45 while (S.KeepRunning()) {
46 // CHECK-GNU-NEXT: subq $1, %[[IREG:[a-z]+]]
47 // CHECK-CLANG-NEXT: {{(addq \$-1,|decq)}} %[[IREG:[a-z]+]]
48 // CHECK: movq %[[IREG]], [[DEST:.*]]
49 benchmark::DoNotOptimize(x);
50 }
51 // CHECK-DAG: movq [[DEST]], %[[IREG]]
52 // CHECK-DAG: testq %[[IREG]], %[[IREG]]
53 // CHECK-DAG: jne .L[[LOOP_BODY]]
54 // CHECK-DAG: .L[[LOOP_HEADER]]:
55
56 // CHECK: cmpb $0
57 // CHECK-NEXT: jne .L[[LOOP_END:[a-zA-Z0-9_]+]]
58 // CHECK: [[CALL:call(q)*]] _ZN9benchmark5State16StartKeepRunningEv
59
60 // CHECK: .L[[LOOP_END]]:
61 // CHECK: [[CALL]] _ZN9benchmark5State17FinishKeepRunningEv
62
63 // CHECK: movl $101, %eax
64 // CHECK: ret
65 return 101;
66}