From: Jacob Lifshay Date: Fri, 22 Jul 2022 09:00:10 +0000 (-0700) Subject: change cmp_xchg to work better X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fa03cfa58fc7ee1e5a16910245f80828b528da63;p=benchmarks.git change cmp_xchg to work better --- diff --git a/src/common/c11_atomics/c11_atomics_benchmarks.cpp b/src/common/c11_atomics/c11_atomics_benchmarks.cpp index 13dc5af..01f831c 100644 --- a/src/common/c11_atomics/c11_atomics_benchmarks.cpp +++ b/src/common/c11_atomics/c11_atomics_benchmarks.cpp @@ -65,7 +65,7 @@ static void push_atomic_bench(std::vector &benches, Config config, index &= index_mask; std::atomic *atomic = &(*buf)[index]; input ^= static_cast(iteration); - return fn(input, atomic); + return fn(input, atomic, iteration ^ thread_num); }, T{}, name_parts...); } @@ -76,37 +76,37 @@ static void rmw_benchmarks(std::vector &benches, Config config, { push_atomic_bench( benches, config, buf, - [](T input, std::atomic *atomic) { + [](T input, std::atomic *atomic, std::uint64_t) { return std::atomic_exchange_explicit(atomic, input, order); }, "atomic_exchange_", int_type_name, "_", memory_order_name); push_atomic_bench( benches, config, buf, - [](T input, std::atomic *atomic) { + [](T input, std::atomic *atomic, std::uint64_t) { return std::atomic_fetch_add_explicit(atomic, input, order); }, "atomic_fetch_add_", int_type_name, "_", memory_order_name); push_atomic_bench( benches, config, buf, - [](T input, std::atomic *atomic) { + [](T input, std::atomic *atomic, std::uint64_t) { return std::atomic_fetch_sub_explicit(atomic, input, order); }, "atomic_fetch_sub_", int_type_name, "_", memory_order_name); push_atomic_bench( benches, config, buf, - [](T input, std::atomic *atomic) { + [](T input, std::atomic *atomic, std::uint64_t) { return std::atomic_fetch_and_explicit(atomic, input, order); }, "atomic_fetch_and_", int_type_name, "_", memory_order_name); push_atomic_bench( benches, config, buf, - [](T input, std::atomic *atomic) { + [](T input, std::atomic *atomic, std::uint64_t) { return std::atomic_fetch_or_explicit(atomic, input, order); }, "atomic_fetch_or_", int_type_name, "_", memory_order_name); push_atomic_bench( benches, config, buf, - [](T input, std::atomic *atomic) { + [](T input, std::atomic *atomic, std::uint64_t) { return std::atomic_fetch_xor_explicit(atomic, input, order); }, "atomic_fetch_xor_", int_type_name, "_", memory_order_name); @@ -118,7 +118,7 @@ static void load_benchmarks(std::vector &benches, Config config, { push_atomic_bench( benches, config, buf, - [](T, std::atomic *atomic) { + [](T, std::atomic *atomic, std::uint64_t) { return std::atomic_load_explicit(atomic, order); }, "atomic_load_", int_type_name, "_", memory_order_name); @@ -130,7 +130,7 @@ static void store_benchmarks(std::vector &benches, Config config, { push_atomic_bench( benches, config, buf, - [](T input, std::atomic *atomic) { + [](T input, std::atomic *atomic, std::uint64_t) { return std::atomic_store_explicit(atomic, input, order); }, "atomic_store_", int_type_name, "_", memory_order_name); @@ -142,8 +142,8 @@ static void cmp_xchg_benchmarks(std::vector &benches, Config config, { push_atomic_bench( benches, config, buf, - [](T input, std::atomic *atomic) { - T expected = input >> 1; + [](T input, std::atomic *atomic, std::uint64_t state) { + T expected = state; bool succeeded = std::atomic_compare_exchange_weak_explicit( atomic, &expected, input, succ, fail); return std::pair(expected, succeeded); @@ -152,8 +152,8 @@ static void cmp_xchg_benchmarks(std::vector &benches, Config config, memory_order_name, "_", memory_order_name); push_atomic_bench( benches, config, buf, - [](T input, std::atomic *atomic) { - T expected = input >> 1; + [](T input, std::atomic *atomic, std::uint64_t state) { + T expected = state; bool succeeded = std::atomic_compare_exchange_strong_explicit( atomic, &expected, input, succ, fail); return std::pair(expected, succeeded); @@ -220,4 +220,4 @@ std::vector c11_atomics_benchmarks(Config config) benchmarks(benches, config); benchmarks(benches, config); return benches; -} \ No newline at end of file +}