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) {
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;
128 read_data.range((i+1)*SliceWidth-1, i*SliceWidth) = bank[bank_sel][local_slice_index];
130 CMOD_ASSERT_MSG(read_data.xor_reduce()!=sc_logic(
'X'),
"Read data is X");
131 return BitsToType<T>(read_data);
134 void write(LocalIndex idx, BankIndex bank_sel, T val, WriteMask write_mask=~static_cast<WriteMask>(0),
bool wce=1) {
135 Slice_t tmp[NumByteEnables];
136 Data_t write_data = TypeToBits<T>(val);
137 #pragma hls_unroll yes 138 for (
int i = 0; i < NumByteEnables; i++) {
139 tmp[i] = write_data.range((i+1)*SliceWidth-1, i*SliceWidth);
142 #pragma hls_unroll yes 143 for (
int i = 0; i < NumByteEnables; i++) {
144 if (write_mask[i] == 1) {
145 LocalSliceIndex local_slice_index = idx * NumByteEnables + i;
148 bank[bank_sel][local_slice_index] = tmp[i];
149 CMOD_ASSERT_MSG(tmp[i].xor_reduce()!=sc_logic(
'X'),
"Write data is X");
155 template<
unsigned int Size>
156 void Marshall(Marshaller<Size>& m) {
157 for (
unsigned i = 0; i < NumBanks; i++) {
158 for (
unsigned j = 0; j < NumByteEnables* NumEntriesPerBank; j++) {
NVUINTW(Wrapped< T >::width) TypeToNVUINT(T in)
Convert Type to NVUINT.
Compute index width of a constant.
#define NVHLS_ASSERT_MSG(X, MSG)
#define CMOD_ASSERT_MSG(X, MSG)