22 #include <nvhls_int.h>
23 #include <nvhls_assert.h>
25 enum arbiter_type { Static, Roundrobin };
60 template <
unsigned int size_, arbiter_type ArbiterType = Roundrobin>
63 typedef NVUINTW(size_) Mask;
67 UNROLLED_SIZE = 2 * size_ - 1,
73 typedef NVUINTW(UNROLLED_SIZE) UnrolledMask;
80 inline void reset() { next = ~static_cast<Mask>(0); }
86 Mask pick(
const Mask& valid) {
90 UnrolledMask unrolled_valid =
static_cast<UnrolledMask
>(0);
92 nvhls::set_slc(unrolled_valid, nvhls::get_slc<size_ - 1>(valid, 1), 0) |
95 UnrolledMask unrolled_next =
static_cast<UnrolledMask
>(0);
96 NVUINTW(size_ - 1) temp = ~static_cast<NVUINTW(size_ - 1)>(0);
100 UnrolledMask priority(unrolled_next & unrolled_valid);
102 NVUINTW(log_unrolled_size) first_one_idx, num_zeros;
103 UnrolledMask unrolled_choice =
static_cast<UnrolledMask
>(0);
105 Mask choice =
static_cast<Mask
>(0);
106 Mask choice_temp =
static_cast<Mask
>(0);
109 NVUINTW(log_unrolled_size)>(priority);
110 unrolled_choice[first_one_idx] = 1;
111 choice_temp[0] = unrolled_choice[size_ - 1];
113 temp2 = (
nvhls::get_slc<UNROLLED_SIZE - size_>(unrolled_choice, size_)) |
117 if (first_one_idx != (size_ - 1)) {
119 #pragma hls_unroll yes
120 for (
unsigned i = size_ - 2; i > 0; --i) {
121 next[i] = next[i + 1] | choice[i + 1];
124 next = ~static_cast<Mask>(0);
140 typedef NVUINT1 Mask;
146 inline void reset() { }
149 Mask pick(
const Mask& valid) {
151 return static_cast<Mask
>(1);
153 return static_cast<Mask
>(0);
166 template <
unsigned int size_>
169 typedef NVUINTW(size_) Mask;
179 Mask pick(
const Mask& valid) {
180 Mask select =
static_cast<Mask
>(0);
181 NVUINTW(log_size) first_one_idx;
184 nvhls::leading_ones<size_, Mask, NVUINTW(log_size)>(valid);
185 select[first_one_idx] = 1;
A generalized implementation of generic n-way roundrobin arbiter.
type1 set_slc(type1 X, type2 Y, const unsigned int i)
Function that replaces slice of bits.
nvhls_t< W >::nvuint_t get_slc(type X, const unsigned int i)
Function that returns slice of bits.
type2 leading_ones(type1 X)
LeadingOne Detector.
Compute Celing of log2 of a constant.