|
1 | 1 | #ifndef ZOO_SWAR_ASSOCIATIVE_ITERATION_H |
2 | 2 | #define ZOO_SWAR_ASSOCIATIVE_ITERATION_H |
3 | 3 |
|
4 | | -#include <iostream> |
5 | 4 | #include "zoo/swar/SWAR.h" |
6 | 5 |
|
7 | | -// include std::cout etc |
8 | | - |
9 | | -template<typename ...Args> |
10 | | -void print(Args... args) { |
11 | | - (std::cout << ... << args); |
12 | | -} |
13 | | - |
14 | 6 | namespace zoo::swar { |
15 | 7 |
|
16 | 8 | /// \note This code should be substituted by an application of "progressive" algebraic iteration |
@@ -199,26 +191,20 @@ template< |
199 | 191 | typename CountHalver |
200 | 192 | > |
201 | 193 | constexpr auto associativeOperatorIterated_regressive( |
202 | | - const Base base, // 4 |
203 | | - const Base neutral, // 1 |
204 | | - IterationCount count, // 2 |
205 | | - const IterationCount forSquaring, // ?? |
206 | | - const Operator op, // plus |
207 | | - unsigned log2Count, // big number |
208 | | - const CountHalver ch // halver |
| 194 | + const Base base, |
| 195 | + const Base neutral, |
| 196 | + IterationCount count, |
| 197 | + const IterationCount forSquaring, |
| 198 | + const Operator op, |
| 199 | + unsigned log2Count, |
| 200 | + const CountHalver ch |
209 | 201 | ) { |
210 | | - auto result = neutral; // result = 1 |
211 | | - if (!log2Count) { return result; } // still going |
| 202 | + auto result = neutral; |
| 203 | + if (!log2Count) { return result; } |
212 | 204 | for (;;) { |
213 | | - result = op(result, base, count); // result = 1 + 4 |
214 | | - if constexpr (std::is_same_v<IterationCount, int>) { |
215 | | - print("result1: ", result, "\n"); |
216 | | - } |
| 205 | + result = op(result, base, count); |
217 | 206 | if(!--log2Count) { break; } |
218 | 207 | result = op(result, result, forSquaring); |
219 | | - if constexpr (std::is_same_v<IterationCount, int>) { |
220 | | - print("result2: ", result, "\n"); |
221 | | - } |
222 | 208 | count = ch(count); |
223 | 209 | } |
224 | 210 | return result; |
@@ -280,27 +266,6 @@ constexpr auto multiplication_OverflowUnsafe_SpecificBitCount( |
280 | 266 | ); |
281 | 267 | } |
282 | 268 |
|
283 | | - |
284 | | -/* |
285 | | - // extended from mathematics to generic programming |
286 | | - // see https://github.com/jamierpond/fmtgp/blob/main/2_first_algo/main.cpp |
287 | | -
|
288 | | - template <typename T> constexpr T exp_acc(T r, T a, T n) { |
289 | | - for (;;) { |
290 | | - if (is_odd(n)) { |
291 | | - r = multiply(r, a); |
292 | | - if (n == 1) { |
293 | | - return r; |
294 | | - } |
295 | | - } |
296 | | - n = half(n); |
297 | | - a = multiply(a, a); |
298 | | - } |
299 | | - } |
300 | | -*/ |
301 | | - |
302 | | - |
303 | | - |
304 | 269 | template<int ActualBits, int NB, typename T> |
305 | 270 | constexpr auto expo_OverflowUnsafe_SpecificBitCount( |
306 | 271 | SWAR<NB, T> x, |
|
0 commit comments