From f292fd31278bffe6fa6362db53d54fd9af57bd0b Mon Sep 17 00:00:00 2001 From: lvolpin Date: Fri, 7 Oct 2022 16:23:10 +0200 Subject: [PATCH] modif max_pow2 pour avoir II=2 (avant II=3) --- sources/modules/max.hpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/sources/modules/max.hpp b/sources/modules/max.hpp index cefbe26..4819368 100644 --- a/sources/modules/max.hpp +++ b/sources/modules/max.hpp @@ -39,20 +39,17 @@ uint16_t do_max_loop_127(const uint16_t in_array[64]); #endif +template +constexpr T max_scalar(T a, T b) { + return (a < b ? b : a); +} + template struct max_pow2 { template static T process(const T values[N]) { static_assert(N > 2, "N cannot be less than 3!"); - T half_values[N / 2]; -#pragma HLS array_partition variable=half_values complete - for (uint8_t i = 0; i < N / 2; i++) { -#pragma HLS unroll - const uint8_t j = i << 1; - const uint8_t jp1 = j + 1; - half_values[i] = (values[j] < values[jp1] ? values[jp1] : values[j]); - } - return max_pow2::process(half_values); + return max_scalar(max_pow2::process(values), max_pow2::process(values + N / 2)); } }; @@ -60,10 +57,25 @@ template <> struct max_pow2<2> { template static T process(const T values[2]) { - return (values[0] < values[1] ? values[1] : values[0]); + return max_scalar(values[0], values[1]); } }; + +template +struct max_naif { + template + static T process(const T values[N]) { + T res = values[0]; + for(uint8_t i = 1; i < N; i++){ +#pragma HLS pipeline + res = max_scalar(res, values[i]); + } + return res; + } +}; + + /* TRUE MAX TEMPLATE BELOW */ /**