18 #if !defined(__FLECSI_PRIVATE__) 19 #error Do not include this file directly! 22 #include "../run/backend.hh" 31 namespace exec::fold {
42 static constexpr T identity{std::numeric_limits<T>::max()};
44 template<
bool EXCLUSIVE>
45 static void apply(LHS & lhs, RHS rhs) {
46 if constexpr(EXCLUSIVE) {
47 lhs = lhs < rhs ? lhs : rhs;
50 int64_t * target =
reinterpret_cast<int64_t *
>(&lhs);
59 std::memcpy(&oldval.as_int, target,
sizeof(int64_t));
60 newval.as_T = std::min(oldval.as_T, rhs);
62 !__sync_bool_compare_and_swap(target, oldval.as_int, newval.as_int));
66 template<
bool EXCLUSIVE>
67 static void fold(RHS & rhs1, RHS rhs2) {
69 if constexpr(EXCLUSIVE) {
70 rhs1 = std::min(rhs1, rhs2);
73 int64_t * target =
reinterpret_cast<int64_t *
>(&rhs1);
82 std::memcpy(&oldval.as_int, target,
sizeof(int64_t));
83 newval.as_T = std::min(oldval.as_T, rhs2);
85 !__sync_bool_compare_and_swap(target, oldval.as_int, newval.as_int));
100 static constexpr T identity{std::numeric_limits<T>::min()};
102 template<
bool EXCLUSIVE = true>
103 static void apply(LHS & lhs, RHS rhs) {
104 if constexpr(EXCLUSIVE) {
105 lhs = lhs > rhs ? lhs : rhs;
108 int64_t * target =
reinterpret_cast<int64_t *
>(&lhs);
117 std::memcpy(&oldval.as_int, target,
sizeof(int64_t));
118 newval.as_T = std::max(oldval.as_T, rhs);
120 !__sync_bool_compare_and_swap(target, oldval.as_int, newval.as_int));
124 template<
bool EXCLUSIVE = true>
125 static void fold(RHS & rhs1, RHS rhs2) {
127 if constexpr(EXCLUSIVE) {
128 rhs1 = std::max(rhs1, rhs2);
131 int64_t * target =
reinterpret_cast<int64_t *
>(&rhs1);
140 std::memcpy(&oldval.as_int, target,
sizeof(int64_t));
141 newval.as_T = std::max(oldval.as_T, rhs2);
143 !__sync_bool_compare_and_swap(target, oldval.as_int, newval.as_int));
158 static constexpr T identity{};
160 template<
bool EXCLUSIVE = true>
161 static void apply(LHS & lhs, RHS rhs) {
163 if constexpr(EXCLUSIVE) {
167 int64_t * target =
reinterpret_cast<int64_t *
>(&lhs);
176 std::memcpy(&oldval.as_int, target,
sizeof(int64_t));
177 newval.as_T = oldval.as_T + rhs;
179 !__sync_bool_compare_and_swap(target, oldval.as_int, newval.as_int));
184 template<
bool EXCLUSIVE = true>
185 static void fold(RHS & rhs1, RHS rhs2) {
187 if constexpr(EXCLUSIVE) {
191 int64_t * target =
reinterpret_cast<int64_t *
>(&rhs1);
200 std::memcpy(&oldval.as_int, target,
sizeof(int64_t));
201 newval.as_T = oldval.as_T + rhs2;
203 !__sync_bool_compare_and_swap(target, oldval.as_int, newval.as_int));
219 static constexpr T identity{};
221 template<
bool EXCLUSIVE = true>
222 static void apply(LHS & lhs, RHS rhs) {
224 if constexpr(EXCLUSIVE) {
228 int64_t * target =
reinterpret_cast<int64_t *
>(&lhs);
237 std::memcpy(&oldval.as_int, target,
sizeof(int64_t));
238 newval.as_T = oldval.as_T * rhs;
240 !__sync_bool_compare_and_swap(target, oldval.as_int, newval.as_int));
245 template<
bool EXCLUSIVE = true>
246 static void fold(RHS & rhs1, RHS rhs2) {
248 if constexpr(EXCLUSIVE) {
252 int64_t * target =
reinterpret_cast<int64_t *
>(&rhs1);
261 std::memcpy(&oldval.as_int, target,
sizeof(int64_t));
262 newval.as_T = oldval.as_T * rhs2;
264 !__sync_bool_compare_and_swap(target, oldval.as_int, newval.as_int));
Definition: control.hh:31