mirror of
https://github.com/Z3Prover/z3
synced 2026-01-19 16:53:18 +00:00
cross-compile do_not_optimize
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
5cf59ea5e4
commit
9a80bd2016
1 changed files with 13 additions and 1 deletions
|
|
@ -46,10 +46,22 @@ double measure_time_ms(Func f, int iterations = 1000000) {
|
|||
}
|
||||
|
||||
// Prevent compiler optimization
|
||||
// Prevent compiler optimization (portable for GCC/Clang and MSVC)
|
||||
#if defined(_MSC_VER)
|
||||
#include <intrin.h>
|
||||
template<typename T>
|
||||
void do_not_optimize(T const& value) {
|
||||
inline void do_not_optimize(T const& value) {
|
||||
// Trick MSVC into thinking value is used
|
||||
volatile const T* volatile ptr = &value;
|
||||
(void)ptr;
|
||||
_ReadWriteBarrier();
|
||||
}
|
||||
#else
|
||||
template<typename T>
|
||||
inline void do_not_optimize(T const& value) {
|
||||
asm volatile("" : : "m"(value) : "memory");
|
||||
}
|
||||
#endif
|
||||
|
||||
void benchmark_construction() {
|
||||
const int iterations = 1000000;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue