6#ifndef VIR_SIMD_BENCHMARKING_H_
7#define VIR_SIMD_BENCHMARKING_H_
9#if __cpp_concepts >= 201907 and defined __GNUC__
12#define VIR_HAVE_SIMD_BENCHMARKING 1
16#if defined(__x86_64__) or defined(__i686__)
17#define VIR_SIMD_REG "v,x,"
23 VIR_ALWAYS_INLINE
void
26 if constexpr (std::is_floating_point_v<T>)
27 asm volatile(
"" :
"+" VIR_SIMD_REG
"g,m"(x));
28 else if constexpr (stdx::is_simd_v<T> || stdx::is_simd_mask_v<T>)
30#if defined _GLIBCXX_EXPERIMENTAL_SIMD && __cpp_lib_experimental_parallel_simd >= 201803
31 auto& d = stdx::__data(x);
32 if constexpr (
requires {{d._S_tuple_size};})
33 stdx::__for_each(d, [](
auto,
auto& element) {
34 fake_modify_one(element);
36 else if constexpr (
requires {{d._M_data};})
37 fake_modify_one(d._M_data);
42 if constexpr (
sizeof(x) < 16)
43 asm volatile(
"" :
"+g"(x));
45 asm volatile(
"" :
"+" VIR_SIMD_REG
"g,m"(x));
48 else if constexpr (
sizeof(x) >= 16)
49 asm volatile(
"" :
"+" VIR_SIMD_REG
"g,m"(x));
51 asm volatile(
"" :
"+g"(x));
54 template <
typename... Ts>
55 VIR_ALWAYS_INLINE
void
56 fake_modify(Ts&... more)
57 { (fake_modify_one(more), ...); }
60 VIR_ALWAYS_INLINE
void
61 fake_read_one(
const T& x)
63 if constexpr (std::is_floating_point_v<T>)
64 asm volatile(
"" ::VIR_SIMD_REG
"g,m"(x));
65 else if constexpr (stdx::is_simd_v<T> || stdx::is_simd_mask_v<T>)
67#if defined _GLIBCXX_EXPERIMENTAL_SIMD && __cpp_lib_experimental_parallel_simd >= 201803
68 const auto& d = stdx::__data(x);
69 if constexpr (
requires {{d._S_tuple_size};})
70 stdx::__for_each(d, [](
auto,
const auto& element) {
71 fake_read_one(element);
73 else if constexpr (
requires {{d._M_data};})
74 fake_read_one(d._M_data);
79 if constexpr (
sizeof(x) < 16)
80 asm volatile(
"" ::
"g"(x));
82 asm volatile(
"" ::VIR_SIMD_REG
"g,m"(x));
85 else if constexpr (
sizeof(x) >= 16)
86 asm volatile(
"" ::VIR_SIMD_REG
"g,m"(x));
88 asm volatile(
"" ::
"g"(x));
92 template <
typename... Ts>
93 VIR_ALWAYS_INLINE
void
94 fake_read(
const Ts&... more)
95 { (fake_read_one(more), ...); }
This namespace collects libraries and tools authored by Matthias Kretz.
Definition constexpr_wrapper.h:21