19 #include <nvhls_int.h>
20 #include <nvhls_types.h>
21 #include <nvhls_array.h>
22 #include <nvhls_marshaller.h>
23 #include <TypeToBits.h>
27 template <
typename T,
int N>
33 for (
unsigned i = 0; i < N; i++) {
44 template <
typename T,
int N,
int A>
50 template <
typename T,
int N,
int A>
82 template <
typename T,
int NumEntries,
int NumBanks,
int NumByteEnables=1>
85 typedef Wrapped<T> WData_t;
86 static const unsigned int NumEntriesPerBank = NumEntries/NumBanks;
87 static const unsigned int WordWidth = WData_t::width;
88 static const unsigned int SliceWidth = WordWidth/NumByteEnables;
92 typedef sc_lv<WordWidth> Data_t;
93 typedef sc_lv<SliceWidth> Slice_t;
94 typedef NVUINTW(NumByteEnables) WriteMask;
97 typedef Slice_t BankType[NumEntriesPerBank*NumByteEnables];
99 static const int width = NumEntries * WordWidth;
103 for (
unsigned i = 0; i < NumBanks; i++) {
104 for (
unsigned j = 0; j < NumByteEnables* NumEntriesPerBank; j++) {
114 for (
unsigned i = 0; i < NumBanks; i++) {
115 for (
unsigned j = 0; j < NumByteEnables * NumEntriesPerBank; j++) {
121 T read(LocalIndex idx, BankIndex bank_sel=0, WriteMask read_mask=~
static_cast<WriteMask
>(0)) {
122 Data_t read_data = TypeToBits<NVUINTW(WordWidth)>(0);
123 #pragma hls_unroll yes
124 for (
int i = 0; i < NumByteEnables; i++) {
125 LocalSliceIndex local_slice_index = idx * NumByteEnables + i;
129 read_data.range((i+1)*SliceWidth-1, i*SliceWidth) = bank[bank_sel][local_slice_index];
131 if (read_mask[i] == 1) {
132 read_data.range((i+1)*SliceWidth-1, i*SliceWidth) = bank[bank_sel][local_slice_index];
136 CMOD_ASSERT_MSG(read_data.xor_reduce()!=sc_logic(
'X'),
"Read data is X");
137 return BitsToType<T>(read_data);
140 void write(LocalIndex idx, BankIndex bank_sel, T val, WriteMask write_mask=~
static_cast<WriteMask
>(0),
bool wce=1) {
141 Slice_t tmp[NumByteEnables];
142 Data_t write_data = TypeToBits<T>(val);
143 #pragma hls_unroll yes
144 for (
int i = 0; i < NumByteEnables; i++) {
145 tmp[i] = write_data.range((i+1)*SliceWidth-1, i*SliceWidth);
148 #pragma hls_unroll yes
149 for (
int i = 0; i < NumByteEnables; i++) {
150 if (write_mask[i] == 1) {
151 LocalSliceIndex local_slice_index = idx * NumByteEnables + i;
154 bank[bank_sel][local_slice_index] = tmp[i];
155 CMOD_ASSERT_MSG(tmp[i].xor_reduce()!=sc_logic(
'X'),
"Write data is X");
161 template<
unsigned int Size>
162 void Marshall(Marshaller<Size>& m) {
163 for (
unsigned i = 0; i < NumBanks; i++) {
164 for (
unsigned j = 0; j < NumByteEnables* NumEntriesPerBank; j++) {
198 template <
typename T,
int NumEntriesPerBank,
int NumBanks=1,
int NumByteEnables=1>
201 typedef Wrapped<T> WData_t;
202 static const unsigned int NumEntries = NumEntriesPerBank*NumBanks;
203 static const unsigned int WordWidth = WData_t::width;
204 static const unsigned int SliceWidth = WordWidth/NumByteEnables;
208 typedef sc_lv<WordWidth> Data_t;
209 typedef sc_lv<SliceWidth> Slice_t;
210 typedef NVUINTW(NumByteEnables) WriteMask;
213 typedef Slice_t BankType[NumEntriesPerBank*NumByteEnables];
214 #pragma hls_block_size NumEntriesPerBank
215 BankType bank[NumBanks];
216 static const int width = NumEntries * WordWidth;
220 for (
unsigned i = 0; i < NumBanks; i++) {
221 for (
unsigned j = 0; j < NumByteEnables* NumEntriesPerBank; j++) {
237 for (
unsigned i = 0; i < NumBanks; i++) {
238 for (
unsigned j = 0; j < NumByteEnables * NumEntriesPerBank; j++) {
244 T read(LocalIndex idx, BankIndex bank_sel=0, WriteMask read_mask=~
static_cast<WriteMask
>(0)) {
245 Data_t read_data = TypeToBits<NVUINTW(WordWidth)>(0);
246 #pragma hls_unroll yes
247 for (
int i = 0; i < NumByteEnables; i++) {
248 LocalSliceIndex local_slice_index = idx * NumByteEnables + i;
252 read_data.range((i+1)*SliceWidth-1, i*SliceWidth) = bank[bank_sel][local_slice_index];
254 if (read_mask[i] == 1) {
255 read_data.range((i+1)*SliceWidth-1, i*SliceWidth) = bank[bank_sel][local_slice_index];
259 CMOD_ASSERT_MSG(read_data.xor_reduce()!=sc_logic(
'X'),
"Read data is X");
260 return BitsToType<T>(read_data);
263 void write(LocalIndex idx, BankIndex bank_sel, T val, WriteMask write_mask=~
static_cast<WriteMask
>(0),
bool wce=1) {
264 Slice_t tmp[NumByteEnables];
265 Data_t write_data = TypeToBits<T>(val);
266 #pragma hls_unroll yes
267 for (
int i = 0; i < NumByteEnables; i++) {
268 tmp[i] = write_data.range((i+1)*SliceWidth-1, i*SliceWidth);
271 #pragma hls_unroll yes
272 for (
int i = 0; i < NumByteEnables; i++) {
273 if (write_mask[i] == 1) {
274 LocalSliceIndex local_slice_index = idx * NumByteEnables + i;
277 bank[bank_sel][local_slice_index] = tmp[i];
278 CMOD_ASSERT_MSG(tmp[i].xor_reduce()!=sc_logic(
'X'),
"Write data is X");
284 template<
unsigned int Size>
285 void Marshall(Marshaller<Size>& m) {
286 for (
unsigned i = 0; i < NumBanks; i++) {
287 for (
unsigned j = 0; j < NumByteEnables* NumEntriesPerBank; j++) {
#define NVHLS_ASSERT_MSG(X, MSG)
#define CMOD_ASSERT_MSG(X, MSG)
Compute index width of a constant.