line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
// Copyright Catch2 Authors |
3
|
|
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. |
4
|
|
|
|
|
|
|
// (See accompanying file LICENSE_1_0.txt or copy at |
5
|
|
|
|
|
|
|
// https://www.boost.org/LICENSE_1_0.txt) |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
// SPDX-License-Identifier: BSL-1.0 |
8
|
|
|
|
|
|
|
// Adapted from donated nonius code. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#ifndef CATCH_OPTIMIZER_HPP_INCLUDED |
11
|
|
|
|
|
|
|
#define CATCH_OPTIMIZER_HPP_INCLUDED |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#if defined(_MSC_VER) |
14
|
|
|
|
|
|
|
# include // atomic_thread_fence |
15
|
|
|
|
|
|
|
#endif |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#include |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#include |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
namespace Catch { |
22
|
|
|
|
|
|
|
namespace Benchmark { |
23
|
|
|
|
|
|
|
#if defined(__GNUC__) || defined(__clang__) |
24
|
|
|
|
|
|
|
template |
25
|
0
|
|
|
|
|
|
inline void keep_memory(T* p) { |
26
|
0
|
|
|
|
|
|
asm volatile("" : : "g"(p) : "memory"); |
27
|
0
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
|
inline void keep_memory() { |
29
|
0
|
|
|
|
|
|
asm volatile("" : : : "memory"); |
30
|
0
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
namespace Detail { |
33
|
0
|
|
|
|
|
|
inline void optimizer_barrier() { keep_memory(); } |
34
|
|
|
|
|
|
|
} // namespace Detail |
35
|
|
|
|
|
|
|
#elif defined(_MSC_VER) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#pragma optimize("", off) |
38
|
|
|
|
|
|
|
template |
39
|
|
|
|
|
|
|
inline void keep_memory(T* p) { |
40
|
|
|
|
|
|
|
// thanks @milleniumbug |
41
|
|
|
|
|
|
|
*reinterpret_cast(p) = *reinterpret_cast(p); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
// TODO equivalent keep_memory() |
44
|
|
|
|
|
|
|
#pragma optimize("", on) |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
namespace Detail { |
47
|
|
|
|
|
|
|
inline void optimizer_barrier() { |
48
|
|
|
|
|
|
|
std::atomic_thread_fence(std::memory_order_seq_cst); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} // namespace Detail |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#endif |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
template |
55
|
0
|
|
|
|
|
|
inline void deoptimize_value(T&& x) { |
56
|
0
|
|
|
|
|
|
keep_memory(&x); |
57
|
0
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
template |
60
|
0
|
|
|
|
|
|
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t::value> { |
61
|
0
|
0
|
|
|
|
|
deoptimize_value(CATCH_FORWARD(fn) (CATCH_FORWARD(args)...)); |
|
|
0
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
template |
65
|
0
|
|
|
|
|
|
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t::value> { |
66
|
0
|
|
|
|
|
|
CATCH_FORWARD(fn) (CATCH_FORWARD(args)...); |
67
|
0
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} // namespace Benchmark |
69
|
|
|
|
|
|
|
} // namespace Catch |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#endif // CATCH_OPTIMIZER_HPP_INCLUDED |