1 #include <benchmark/benchmark.h>
4 #pragma clang diagnostic ignored "-Wreturn-type"
9 benchmark::State
& GetState();
13 using benchmark::State
;
15 // CHECK-LABEL: test_for_auto_loop:
16 extern "C" int test_for_auto_loop() {
17 State
& S
= GetState();
19 // CHECK: [[CALL:call(q)*]] _ZN9benchmark5State16StartKeepRunningEv
20 // CHECK-NEXT: testq %rbx, %rbx
21 // CHECK-NEXT: je [[LOOP_END:.*]]
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
);
30 // CHECK: [[LOOP_END]]:
31 // CHECK: [[CALL]] _ZN9benchmark5State17FinishKeepRunningEv
33 // CHECK: movl $101, %eax
38 // CHECK-LABEL: test_while_loop:
39 extern "C" int test_while_loop() {
40 State
& S
= GetState();
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
);
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]]:
57 // CHECK-NEXT: jne .L[[LOOP_END:[a-zA-Z0-9_]+]]
58 // CHECK: [[CALL:call(q)*]] _ZN9benchmark5State16StartKeepRunningEv
60 // CHECK: .L[[LOOP_END]]:
61 // CHECK: [[CALL]] _ZN9benchmark5State17FinishKeepRunningEv
63 // CHECK: movl $101, %eax