@@ -31,37 +31,41 @@ template<class DataType, unsigned int NBIT_BX, unsigned int NBIT_ADDR>
31
31
// (1<<NBIT_ADDR): depth of the memory for each BX
32
32
class MemoryTemplate
33
33
{
34
+ private:
34
35
#ifdef CMSSW_GIT_HASH
35
36
static constexpr unsigned int NBIT_BX = 0 ;
36
37
#endif
37
-
38
+
38
39
public:
40
+ static constexpr unsigned int DEPTH_BX = 1 <<NBIT_BX;
41
+ static constexpr unsigned int DEPTH_ADDR = 1 <<NBIT_ADDR;
42
+
39
43
typedef typename DataType::BitWidths BitWidths;
40
44
typedef ap_uint<NBIT_BX> BunchXingT;
41
45
typedef ap_uint<NBIT_ADDR> NEntryT;
42
46
43
47
protected:
44
48
45
- DataType dataarray_[1 <<NBIT_BX][ 1 <<NBIT_ADDR ]; // data array
46
- NEntryT nentries_[1 <<NBIT_BX ]; // number of entries
49
+ DataType dataarray_[DEPTH_BX][DEPTH_ADDR ]; // data array
50
+ NEntryT nentries_[DEPTH_BX ]; // number of entries
47
51
48
52
public:
49
53
50
- unsigned int getDepth () const {return ( 1 <<NBIT_ADDR) ;}
51
- unsigned int getNBX () const {return ( 1 <<NBIT_BX) ;}
54
+ unsigned int getDepth () const {return DEPTH_ADDR ;}
55
+ unsigned int getNBX () const {return DEPTH_BX ;}
52
56
53
57
NEntryT getEntries (BunchXingT bx) const {
54
58
#pragma HLS ARRAY_PARTITION variable=nentries_ complete dim=0
55
- return nentries_[bx];
59
+ return nentries_[bx];
56
60
}
57
61
58
- const DataType (&get_mem () const )[1<<NBIT_BX][1<<NBIT_ADDR ] {return dataarray_;}
62
+ const DataType (&get_mem () const )[DEPTH_BX][DEPTH_ADDR ] {return dataarray_;}
59
63
60
64
DataType read_mem (BunchXingT ibx, ap_uint<NBIT_ADDR> index) const
61
65
{
62
- // TODO: check if valid
63
- if (!NBIT_BX) ibx = 0 ;
64
- return dataarray_[ibx][index ];
66
+ // TODO: check if valid
67
+ if (!NBIT_BX) ibx = 0 ;
68
+ return dataarray_[ibx][index ];
65
69
}
66
70
67
71
template <class SpecType >
@@ -72,7 +76,7 @@ class MemoryTemplate
72
76
#ifdef __SYNTHESIS__
73
77
0 ;
74
78
#else
75
- nentries_[ibx];
79
+ nentries_[ibx];
76
80
#endif
77
81
return write_mem (ibx,data,addr_index);
78
82
}
@@ -83,10 +87,10 @@ class MemoryTemplate
83
87
#pragma HLS inline
84
88
if (!NBIT_BX) ibx = 0 ;
85
89
static_assert (
86
- std::is_same<DataType, SpecType>::value
87
- || (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISKPS> >::value)
88
- || (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISK2S> >::value)
89
- , " Invalid conversion between data types" );
90
+ std::is_same<DataType, SpecType>::value
91
+ || (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISKPS> >::value)
92
+ || (std::is_same<DataType, AllStub<DISK> >::value && std::is_same<SpecType, AllStub<DISK2S> >::value)
93
+ , " Invalid conversion between data types" );
90
94
DataType sameData (data.raw ());
91
95
return write_mem (ibx,sameData,addr_index);
92
96
}
@@ -98,7 +102,7 @@ class MemoryTemplate
98
102
#ifdef __SYNTHESIS__
99
103
0 ;
100
104
#else
101
- nentries_[ibx];
105
+ nentries_[ibx];
102
106
#endif
103
107
return write_mem (ibx,data,addr_index);
104
108
}
@@ -108,7 +112,7 @@ class MemoryTemplate
108
112
#pragma HLS ARRAY_PARTITION variable=nentries_ complete dim=0
109
113
#pragma HLS inline
110
114
if (!NBIT_BX) ibx = 0 ;
111
- if (addr_index < ( 1 <<NBIT_ADDR) ) {
115
+ if (addr_index < DEPTH_ADDR ) {
112
116
#if defined __SYNTHESIS__ && !defined SYNTHESIS_TEST_BENCH
113
117
// The vhd memory implementation will write to the correct address!!
114
118
dataarray_[ibx][0 ] = data;
@@ -126,28 +130,23 @@ class MemoryTemplate
126
130
}
127
131
}
128
132
129
- bool write_mem_new (BunchXingT ibx, DataType data, NEntryT addr_index )
133
+ bool write_mem_new (BunchXingT ibx, DataType data, ap_uint< 1 > overwrite )
130
134
{
131
135
#pragma HLS ARRAY_PARTITION variable=nentries_ complete dim=0
132
136
#pragma HLS inline
133
137
if (!NBIT_BX) ibx = 0 ;
134
- if (addr_index < (1 <<NBIT_ADDR)) {
135
- // dataarray_[ibx][addr_index] = data;
138
+ if (nentries_[ibx] < DEPTH_ADDR) {
136
139
#if defined __SYNTHESIS__ && !defined SYNTHESIS_TEST_BENCH
137
140
// The vhd memory implementation will write to the correct address!!
138
141
dataarray_[ibx][0 ] = data;
139
142
#else
140
- if (addr_index == 0 ) {
141
- dataarray_[ibx][nentries_[ibx]++] = data;
143
+ if (overwrite == 0 ) {
144
+ dataarray_[ibx][nentries_[ibx]++] = data;
142
145
} else {
143
- dataarray_[ibx][nentries_[ibx]-1 ] = data;
146
+ dataarray_[ibx][nentries_[ibx]-1 ] = data;
144
147
}
145
148
#endif
146
149
147
- #ifdef CMSSW_GIT_HASH
148
- nentries_[ibx] = addr_index + 1 ;
149
- #endif
150
-
151
150
return true ;
152
151
} else {
153
152
return false ;
@@ -158,17 +157,17 @@ class MemoryTemplate
158
157
#ifndef __SYNTHESIS__
159
158
MemoryTemplate ()
160
159
{
161
- clear ();
160
+ clear ();
162
161
}
163
162
164
163
~MemoryTemplate (){}
165
164
166
165
void clear ()
167
166
{
168
167
DataType data (" 0" ,16 );
169
- MEM_RST: for (size_t ibx=0 ; ibx<( 1 <<NBIT_BX) ; ++ibx) {
168
+ MEM_RST: for (size_t ibx=0 ; ibx<DEPTH_BX ; ++ibx) {
170
169
nentries_[ibx] = 0 ;
171
- for (size_t addr=0 ; addr<( 1 <<NBIT_ADDR) ; ++addr) {
170
+ for (size_t addr=0 ; addr<DEPTH_ADDR ; ++addr) {
172
171
write_mem (ibx,data,addr);
173
172
}
174
173
}
@@ -177,47 +176,47 @@ class MemoryTemplate
177
176
// write memory from text file
178
177
bool write_mem (BunchXingT ibx, const char * datastr, int base=16 )
179
178
{
180
- if (!NBIT_BX) ibx = 0 ;
181
- DataType data (datastr, base);
182
- NEntryT nent = nentries_[ibx];
183
- bool success = write_mem (ibx, data, nent);
179
+ if (!NBIT_BX) ibx = 0 ;
180
+ DataType data (datastr, base);
181
+ NEntryT nent = nentries_[ibx];
182
+ bool success = write_mem (ibx, data, nent);
184
183
185
- return success;
184
+ return success;
186
185
}
187
186
188
- bool write_mem (BunchXingT ibx, const std::string datastr, int base=16 )
187
+ bool write_mem (BunchXingT ibx, const std::string& datastr, int base=16 )
189
188
{
190
- return write_mem (ibx, datastr.c_str (), base);
189
+ return write_mem (ibx, datastr.c_str (), base);
191
190
}
192
191
193
192
// print memory contents
194
193
void print_data (const DataType data) const
195
194
{
196
195
edm::LogVerbatim (" L1trackHLS" ) << std::hex << data.raw () << std::endl;
197
- // TODO: overload '<<' in data class
196
+ // TODO: overload '<<' in data class
198
197
}
199
198
200
199
void print_entry (BunchXingT bx, NEntryT index) const
201
200
{
202
- print_data (dataarray_[bx][index ]);
201
+ print_data (dataarray_[bx][index ]);
203
202
}
204
203
205
204
void print_mem (BunchXingT bx) const
206
205
{
207
- for (unsigned int i = 0 ; i < nentries_[bx]; ++i) {
208
- edm::LogVerbatim (" L1trackHLS" ) << bx << " " << i << " " ;
209
- print_entry (bx,i);
210
- }
206
+ for (unsigned int i = 0 ; i < nentries_[bx]; ++i) {
207
+ edm::LogVerbatim (" L1trackHLS" ) << bx << " " << i << " " ;
208
+ print_entry (bx,i);
209
+ }
211
210
}
212
211
213
212
void print_mem () const
214
213
{
215
- for (unsigned int ibx = 0 ; ibx < ( 1 <<NBIT_BX) ; ++ibx) {
216
- for (unsigned int i = 0 ; i < nentries_[ibx]; ++i) {
217
- edm::LogVerbatim (" L1trackHLS" ) << ibx << " " << i << " " ;
218
- print_entry (ibx,i);
219
- }
220
- }
214
+ for (unsigned int ibx = 0 ; ibx < DEPTH_BX ; ++ibx) {
215
+ for (unsigned int i = 0 ; i < nentries_[ibx]; ++i) {
216
+ edm::LogVerbatim (" L1trackHLS" ) << ibx << " " << i << " " ;
217
+ print_entry (ibx,i);
218
+ }
219
+ }
221
220
}
222
221
223
222
static constexpr int getWidth () {return DataType::getWidth ();}
0 commit comments