You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.8 KiB

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