16 #ifndef _COMP_TREES_H_
17 #define _COMP_TREES_H_
26 #include <nvhls_marshaller.h>
71 template <
typename ArrT,
typename ElemT,
typename IdxT,
bool is_max,
75 static IdxT minmax(ArrT inputs, IdxT start, IdxT end) {
76 const unsigned TotalElems = Wrapped<ArrT>::width / Wrapped<ElemT>::width;
77 const unsigned ElemWidth = Wrapped<ElemT>::width;
78 ElemT temp[TotalElems];
79 #pragma hls_unroll yes
80 for (
unsigned i = 0; i < TotalElems; i++)
81 temp[i] = inputs.range((i + 1) * ElemWidth - 1, i * ElemWidth);
83 IdxT upper_branch =
Minmax<ArrT, ElemT, IdxT, is_max, Width / 2>::minmax(
84 inputs, (start + end) / 2 + 1, end);
85 IdxT lower_branch =
Minmax<ArrT, ElemT, IdxT, is_max, Width / 2>::minmax(
86 inputs, start, (start + end) / 2);
88 return temp[upper_branch] > temp[lower_branch] ? upper_branch
91 return temp[upper_branch] < temp[lower_branch] ? upper_branch
97 template <
typename ArrT,
typename ElemT,
typename IdxT,
bool is_max>
98 class Minmax<ArrT, ElemT, IdxT, is_max, 2> {
100 static IdxT minmax(ArrT inputs, IdxT start, IdxT end) {
101 const unsigned TotalElems = Wrapped<ArrT>::width / Wrapped<ElemT>::width;
102 const unsigned ElemWidth = Wrapped<ElemT>::width;
103 ElemT temp[TotalElems];
104 #pragma hls_unroll yes
105 for (
unsigned i = 0; i < TotalElems; i++)
106 temp[i] = inputs.range((i + 1) * ElemWidth - 1, i * ElemWidth);
109 return temp[start] > temp[end] ? start : end;
111 return temp[start] < temp[end] ? start : end;
116 template <
typename ArrT,
typename ElemT,
typename IdxT,
bool is_max>
117 class Minmax<ArrT, ElemT, IdxT, is_max, 1> {
120 static IdxT minmax(ArrT inputs, IdxT start, IdxT end) {
return start; }
136 template <
template <
int>
class BaseTemplate,
unsigned ElemW,
137 unsigned NumElements>
140 typedef BaseTemplate<ElemW * NumElements> concat_t;
141 typedef BaseTemplate<ElemW * NumElements / 2> concat_half_t;
143 static concat_t concat(BaseTemplate<ElemW> components[],
unsigned start,
145 BaseTemplate<ElemW*(NumElements - 1)> retval =
148 return (retval, components[start]);
153 template <
template <
int>
class BaseTemplate,
unsigned ElemW>
156 typedef BaseTemplate<ElemW * 2> concat_t;
158 static concat_t concat(BaseTemplate<ElemW> components[],
unsigned start,
160 return (components[end], components[start]);
165 template <
template <
int>
class BaseTemplate,
unsigned ElemW>
168 typedef BaseTemplate<ElemW> concat_t;
170 static concat_t concat(BaseTemplate<ElemW> components[],
unsigned start,
172 return components[start];
191 template <
typename VecT,
typename ValT,
typename IdxT,
unsigned W
idth>
195 static IdxT val(VecT inputs, ValT comp_value) {
202 static IdxT val(VecT inputs, ValT comp_value, IdxT start, IdxT end) {
203 if (inputs[start] == comp_value) {
205 }
else if (start == end) {
209 inputs, comp_value, start + 1, start + Width - 1);
216 template <
typename VecT,
typename ValT,
typename IdxT>
219 static IdxT val(VecT inputs, ValT comp_value) {
220 if (inputs[0] == comp_value) {
227 static IdxT val(VecT inputs, ValT comp_value, IdxT start, IdxT end) {
228 if (inputs[end] == comp_value) {
Compile-time minmax tree.