Skip to content

Commit

Permalink
prevent statement reordering
Browse files Browse the repository at this point in the history
  • Loading branch information
baruxu committed Jun 5, 2024
1 parent 0cbd13a commit 9085daa
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <iostream>
#include <random>
#include <chrono>
#include <functional>

using fp = float;

Expand Down Expand Up @@ -83,18 +84,25 @@ FIXED_64_FORCEINLINE void PreventOptimizedAway(fixed val)
EXPR1;\
}

#pragma optimize("",off) // prevent statement reordering
template<class T>
void run_test(T& a, T& b, std::function<void(T&, T&)>&& f)
{
f(a,b);
}
#pragma optimize("",on)


#define RUN_TEST(EXPR1, EXPR2, COUNT, Min, Max) \
{\
Operand operand(Min, Max);\
{\
auto& a = operand.a,& b = operand.b;\
Counter c(totals[0]);\
TEST_LOOP(EXPR1, EXPR2, COUNT)\
run_test<fp>(operand.a, operand.b, [COUNT](auto& a, auto& b){ TEST_LOOP(EXPR1, EXPR2, COUNT) });\
}\
{\
auto& a = operand.fa, &b = operand.fb;\
Counter c(totals[1]);\
TEST_LOOP(EXPR1, EXPR2, COUNT)\
run_test<fixed>(operand.fa, operand.fb, [COUNT](auto& a, auto& b){ TEST_LOOP(EXPR1, EXPR2, COUNT) });\
}\
prevent_optimized_float += operand.a, prevent_optimized_fixed += operand.fa;\
}
Expand Down

0 comments on commit 9085daa

Please sign in to comment.