cb66c5d68e
bazel / bazel.ubuntu-latest (push) Failing after 1s
build-and-test-perfcounters / ubuntu-latest.Debug (push) Failing after 0s
build-and-test-perfcounters / ubuntu-latest.Release (push) Failing after 1s
doxygen / Build HTML documentation (push) Failing after 1s
python + Bazel pre-commit checks / pre-commit (push) Failing after 1s
sanitizer / tsan.Debug (push) Failing after 1s
sanitizer / ubsan.Debug (push) Failing after 0s
sanitizer / ubsan.RelWithDebInfo (push) Failing after 1s
build-and-test-min-cmake / ubuntu-latest.min-cmake (push) Failing after 1s
clang-format-lint / check-clang-format (push) Failing after 1s
sanitizer / asan.Debug (push) Failing after 1s
sanitizer / msan.RelWithDebInfo (push) Failing after 1s
clang-tidy / run-clang-tidy (push) Failing after 1s
sanitizer / msan.Debug (push) Failing after 1s
sanitizer / asan.RelWithDebInfo (push) Failing after 0s
sanitizer / tsan.RelWithDebInfo (push) Failing after 0s
test-bindings / Test Rust bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.10 bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.11 bindings on ubuntu-latest (push) Failing after 0s
test-bindings / Test Python 3.12 bindings on ubuntu-latest (push) Failing after 1s
test-bindings / Test Python 3.13 bindings on ubuntu-latest (push) Failing after 0s
build-and-test / macos-latest.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.clang++ (push) Has been cancelled
bazel / bazel.macos-latest (push) Has been cancelled
bazel / bazel.windows-latest (push) Has been cancelled
build-and-test-min-cmake / macos-latest.min-cmake (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.g++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.g++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.g++ (push) Has been cancelled
build-and-test / windows-2025.Debug.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2022.Release.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Release.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Release.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2025.Release.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.UCRT64 (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.g++ (push) Has been cancelled
build-and-test / windows-2022.Debug.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Debug.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Debug.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-latest.Release.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.UCRT64 (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on macos-latest (push) Has been cancelled
build-and-test / windows-latest.Release.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.CLANG64 (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Rust bindings on macos-latest (push) Has been cancelled
test-bindings / Test Rust bindings on windows-latest (push) Has been cancelled
204 lines
5.2 KiB
C++
204 lines
5.2 KiB
C++
#include "benchmark/macros.h"
|
|
#include "benchmark/utils.h"
|
|
|
|
#ifdef __clang__
|
|
#pragma clang diagnostic ignored "-Wreturn-type"
|
|
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
|
#endif
|
|
BENCHMARK_DISABLE_DEPRECATED_WARNING
|
|
|
|
extern "C" {
|
|
|
|
extern int ExternInt;
|
|
extern int ExternInt2;
|
|
extern int ExternInt3;
|
|
extern int BigArray[2049];
|
|
|
|
const int ConstBigArray[2049]{};
|
|
|
|
inline int Add42(int x) { return x + 42; }
|
|
|
|
struct NotTriviallyCopyable {
|
|
NotTriviallyCopyable();
|
|
explicit NotTriviallyCopyable(int x) : value(x) {}
|
|
NotTriviallyCopyable(NotTriviallyCopyable const&);
|
|
int value;
|
|
};
|
|
|
|
struct Large {
|
|
int value;
|
|
int data[2];
|
|
};
|
|
|
|
struct ExtraLarge {
|
|
int arr[2049];
|
|
};
|
|
}
|
|
|
|
extern ExtraLarge ExtraLargeObj;
|
|
const ExtraLarge ConstExtraLargeObj{};
|
|
|
|
// CHECK-LABEL: test_with_rvalue:
|
|
extern "C" void test_with_rvalue() {
|
|
benchmark::DoNotOptimize(Add42(0));
|
|
// CHECK: movl $42, %eax
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_large_rvalue:
|
|
extern "C" void test_with_large_rvalue() {
|
|
benchmark::DoNotOptimize(Large{ExternInt, {ExternInt, ExternInt}});
|
|
// CHECK: ExternInt(%rip)
|
|
// CHECK: movl %eax, -{{[0-9]+}}(%[[REG:[a-z]+]]
|
|
// CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
|
|
// CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_non_trivial_rvalue:
|
|
extern "C" void test_with_non_trivial_rvalue() {
|
|
benchmark::DoNotOptimize(NotTriviallyCopyable(ExternInt));
|
|
// CHECK: mov{{l|q}} ExternInt(%rip)
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_lvalue:
|
|
extern "C" void test_with_lvalue() {
|
|
int x = 101;
|
|
benchmark::DoNotOptimize(x);
|
|
// CHECK-GNU: movl $101, %eax
|
|
// CHECK-CLANG: movl $101, -{{[0-9]+}}(%[[REG:[a-z]+]])
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_large_lvalue:
|
|
extern "C" void test_with_large_lvalue() {
|
|
Large L{ExternInt, {ExternInt, ExternInt}};
|
|
benchmark::DoNotOptimize(L);
|
|
// CHECK: ExternInt(%rip)
|
|
// CHECK: movl %eax, -{{[0-9]+}}(%[[REG:[a-z]+]])
|
|
// CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
|
|
// CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_extra_large_lvalue_with_op:
|
|
extern "C" void test_with_extra_large_lvalue_with_op() {
|
|
ExtraLargeObj.arr[16] = 42;
|
|
benchmark::DoNotOptimize(ExtraLargeObj);
|
|
// CHECK: movl $42, ExtraLargeObj+64(%rip)
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_big_array_with_op
|
|
extern "C" void test_with_big_array_with_op() {
|
|
BigArray[16] = 42;
|
|
benchmark::DoNotOptimize(BigArray);
|
|
// CHECK: movl $42, BigArray+64(%rip)
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_non_trivial_lvalue:
|
|
extern "C" void test_with_non_trivial_lvalue() {
|
|
NotTriviallyCopyable NTC(ExternInt);
|
|
benchmark::DoNotOptimize(NTC);
|
|
// CHECK: ExternInt(%rip)
|
|
// CHECK: movl %eax, -{{[0-9]+}}(%[[REG:[a-z]+]])
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_const_lvalue:
|
|
extern "C" void test_with_const_lvalue() {
|
|
const int x = 123;
|
|
benchmark::DoNotOptimize(x);
|
|
// CHECK: movl $123, %eax
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_large_const_lvalue:
|
|
extern "C" void test_with_large_const_lvalue() {
|
|
const Large L{ExternInt, {ExternInt, ExternInt}};
|
|
benchmark::DoNotOptimize(L);
|
|
// CHECK: ExternInt(%rip)
|
|
// CHECK: movl %eax, -{{[0-9]+}}(%[[REG:[a-z]+]])
|
|
// CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
|
|
// CHECK: movl %eax, -{{[0-9]+}}(%[[REG]])
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_const_extra_large_obj:
|
|
extern "C" void test_with_const_extra_large_obj() {
|
|
benchmark::DoNotOptimize(ConstExtraLargeObj);
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_const_big_array
|
|
extern "C" void test_with_const_big_array() {
|
|
benchmark::DoNotOptimize(ConstBigArray);
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_with_non_trivial_const_lvalue:
|
|
extern "C" void test_with_non_trivial_const_lvalue() {
|
|
const NotTriviallyCopyable Obj(ExternInt);
|
|
benchmark::DoNotOptimize(Obj);
|
|
// CHECK: mov{{q|l}} ExternInt(%rip)
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_div_by_two:
|
|
extern "C" int test_div_by_two(int input) {
|
|
int divisor = 2;
|
|
benchmark::DoNotOptimize(divisor);
|
|
return input / divisor;
|
|
// CHECK: movl $2, [[DEST:.*]]
|
|
// CHECK: idivl [[DEST]]
|
|
// CHECK: ret
|
|
}
|
|
|
|
// CHECK-LABEL: test_inc_integer:
|
|
extern "C" int test_inc_integer() {
|
|
int x = 0;
|
|
for (int i = 0; i < 5; ++i) benchmark::DoNotOptimize(++x);
|
|
// CHECK: movl $1, [[DEST:.*]]
|
|
// CHECK: {{(addl \$1,|incl)}} [[DEST]]
|
|
// CHECK: {{(addl \$1,|incl)}} [[DEST]]
|
|
// CHECK: {{(addl \$1,|incl)}} [[DEST]]
|
|
// CHECK: {{(addl \$1,|incl)}} [[DEST]]
|
|
// CHECK-CLANG: movl [[DEST]], %eax
|
|
// CHECK: ret
|
|
return x;
|
|
}
|
|
|
|
// CHECK-LABEL: test_pointer_rvalue
|
|
extern "C" void test_pointer_rvalue() {
|
|
// CHECK: movl $42, [[DEST:.*]]
|
|
// CHECK: leaq [[DEST]], %rax
|
|
// CHECK-CLANG: movq %rax, -{{[0-9]+}}(%[[REG:[a-z]+]])
|
|
// CHECK: ret
|
|
int x = 42;
|
|
benchmark::DoNotOptimize(&x);
|
|
}
|
|
|
|
// CHECK-LABEL: test_pointer_const_lvalue:
|
|
extern "C" void test_pointer_const_lvalue() {
|
|
// CHECK: movl $42, [[DEST:.*]]
|
|
// CHECK: leaq [[DEST]], %rax
|
|
// CHECK-CLANG: movq %rax, -{{[0-9]+}}(%[[REG:[a-z]+]])
|
|
// CHECK: ret
|
|
int x = 42;
|
|
int* const xp = &x;
|
|
benchmark::DoNotOptimize(xp);
|
|
}
|
|
|
|
// CHECK-LABEL: test_pointer_lvalue:
|
|
extern "C" void test_pointer_lvalue() {
|
|
// CHECK: movl $42, [[DEST:.*]]
|
|
// CHECK: leaq [[DEST]], %rax
|
|
// CHECK-CLANG: movq %rax, -{{[0-9]+}}(%[[REG:[a-z+]+]])
|
|
// CHECK: ret
|
|
int x = 42;
|
|
int* xp = &x;
|
|
benchmark::DoNotOptimize(xp);
|
|
}
|