3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-01-18 16:28:56 +00:00

cross-compile do_not_optimize

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2026-01-11 17:40:30 -08:00
parent 5cf59ea5e4
commit 9a80bd2016

View file

@ -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;