1 #include <benchmark/benchmark.h>
4 #pragma clang diagnostic ignored "-Wreturn-type"
10 benchmark::State
& GetState();
15 using benchmark::State
;
17 // CHECK-LABEL: test_for_auto_loop:
18 extern "C" int test_for_auto_loop() {
19 State
& S
= GetState();
21 // CHECK: [[CALL:call(q)*]] _ZN9benchmark5State16StartKeepRunningEv
22 // CHECK-NEXT: testq %rbx, %rbx
23 // CHECK-NEXT: je [[LOOP_END:.*]]
26 // CHECK: .L[[LOOP_HEAD:[a-zA-Z0-9_]+]]:
27 // CHECK-GNU-NEXT: subq $1, %rbx
28 // CHECK-CLANG-NEXT: {{(addq \$1, %rax|incq %rax|addq \$-1, %rbx)}}
29 // CHECK-NEXT: jne .L[[LOOP_HEAD]]
30 benchmark::DoNotOptimize(x
);
32 // CHECK: [[LOOP_END]]:
33 // CHECK: [[CALL]] _ZN9benchmark5State17FinishKeepRunningEv
35 // CHECK: movl $101, %eax
40 // CHECK-LABEL: test_while_loop:
41 extern "C" int test_while_loop() {
42 State
& S
= GetState();
45 // CHECK: j{{(e|mp)}} .L[[LOOP_HEADER:[a-zA-Z0-9_]+]]
46 // CHECK-NEXT: .L[[LOOP_BODY:[a-zA-Z0-9_]+]]:
47 while (S
.KeepRunning()) {
48 // CHECK-GNU-NEXT: subq $1, %[[IREG:[a-z]+]]
49 // CHECK-CLANG-NEXT: {{(addq \$-1,|decq)}} %[[IREG:[a-z]+]]
50 // CHECK: movq %[[IREG]], [[DEST:.*]]
51 benchmark::DoNotOptimize(x
);
53 // CHECK-DAG: movq [[DEST]], %[[IREG]]
54 // CHECK-DAG: testq %[[IREG]], %[[IREG]]
55 // CHECK-DAG: jne .L[[LOOP_BODY]]
56 // CHECK-DAG: .L[[LOOP_HEADER]]:
59 // CHECK-NEXT: jne .L[[LOOP_END:[a-zA-Z0-9_]+]]
60 // CHECK: [[CALL:call(q)*]] _ZN9benchmark5State16StartKeepRunningEv
62 // CHECK: .L[[LOOP_END]]:
63 // CHECK: [[CALL]] _ZN9benchmark5State17FinishKeepRunningEv
65 // CHECK: movl $101, %eax