DP-HLS
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
shift_reg.h
Go to the documentation of this file.
1 #ifndef SHIFT_REGISTER_H
2 #define SHIFT_REGISTER_H
3 
4 #include "params.h"
5 
6 template <typename T, int LEN> class ShiftRegister { // This is a shift register, for data index 1, 2, 3, ...
7 /*
8 * WARNING: This only works when used to hold scores
9 */
10 public:
11  ShiftRegister(void) {
12 #pragma HLS ARRAY_PARTITION variable=data dim=1 type=complete
13  for (int i = 0; i < LEN; i++) {
14 #pragma HLS unroll
15 
16  data[i] = zero_fp;
17  }
18  }
19 
20  T operator[](int index) {
21  return data[index]; // returning array is not allowed
22  };
23 
24  void shift_right(T input) {
25  for (int i = LEN - 1; i > 0; i--) { // shift towards the larger index
26 #pragma HLS unroll
27  // expect to be done within one cycle
28 
29  data[i] = data[i - 1];
30 
31 
32  }
33 
34  data[0] = input;
35 
36  };
37 
38  void shift_right() {
39  for (int i = LEN - 1; i > 0; i--) { // shift towards the larger index
40 #pragma HLS unroll
41  // expect to be done within one cycle
42 
43  data[i] = data[i - 1];
44 
45  }
46 
47  data[0] = zero_fp;
48 
49  };
50 
51  void shift_left(T input) {
52  for (int i = 0; i < LEN - 1; i++) { // shift towards the smaller index
53 #pragma HLS unroll
54  // expect to be done within one cycle
55 
56  data[i] = data[i + 1];
57 
58  }
59 
60  data[LEN - 1] = input;
61 
62  };
63 
64  void shift_left() {
65  for (int i = 0; i < LEN - 1; i++) { // shift towards the smaller index
66 #pragma HLS unroll
67  // expect to be done within one cycle
68 
69  data[i] = data[i + 1];
70 
71  }
72 
73  data[LEN - 1] = zero_fp;
74 
75  };
76 
77  void clear() {
78  for (int i = 0; i < LEN; i++) {
79  shift_left();
80  }
81  }
82 
83 private:
84  T data[LEN];
85 };
86 
87 template <typename T, int NUM, int LEN> class ShiftRegisterBlock {
88 public:
91 #pragma HLS ARRAY_PARTITION variable=data dim=1 type=complete
92  }
93 
94  void shift_right(T input[NUM]) {
95  for (int i = 0; i < NUM; i++) {
96 #pragma HLS unroll
97  data[i].shift_right(input[i]);
98  }
99  }
100 
101  void shift_left(T input[NUM]) {
102  for (int i = 0; i < NUM; i++) {
103 #pragma HLS unroll
104  data[i].shift_left(input[i]);
105  }
106  }
107 
108  void shift_right() {
109  for (int i = 0; i < NUM; i++) {
110 
111 #pragma HLS unroll
112  data[i].shift_right();
113  }
114  }
115 
116  void shift_left() {
117  for (int i = 0; i < NUM; i++) {
118 #pragma HLS unroll
119  data[i].shift_left();
120  }
121  }
122 
123  void clear() {
124  for (int i = 0; i < NUM; i++) {
125  data[i].clear();
126  }
127  }
128 
130  return data[index];
131  }
132 };
133 
134 #endif // !SHIFT_REGISTER_H
135 
136 
ShiftRegister(void)
Definition: shift_reg.h:11
void shift_right(T input)
Definition: shift_reg.h:24
ShiftRegister< T, LEN > data[NUM]
Definition: shift_reg.h:89
void shift_left()
Definition: shift_reg.h:116
void clear()
Definition: shift_reg.h:123
void shift_right(T input[NUM])
Definition: shift_reg.h:94
ShiftRegisterBlock(void)
Definition: shift_reg.h:90
Definition: shift_reg.h:87
void shift_left(T input[NUM])
Definition: shift_reg.h:101
ShiftRegister< T, LEN > & operator[](int index)
Definition: shift_reg.h:129
void shift_left()
Definition: shift_reg.h:64
void shift_right()
Definition: shift_reg.h:38
void shift_right()
Definition: shift_reg.h:108
void shift_left(T input)
Definition: shift_reg.h:51
T operator[](int index)
Definition: shift_reg.h:20
void clear()
Definition: shift_reg.h:77
Definition: shift_reg.h:6