@@ -43,6 +43,7 @@ struct data_header {
43
43
uint32_t off_ro;
44
44
uint32_t off_roh;
45
45
uint32_t off_ri;
46
+ uint32_t off_rsrc;
46
47
uint32_t off_line;
47
48
uint32_t off_p2r;
48
49
uint32_t off_p2p;
@@ -56,6 +57,7 @@ struct data_header {
56
57
57
58
uint32_t count_ro;
58
59
uint32_t count_ri;
60
+ uint32_t count_rsrc;
59
61
uint32_t count_p2r;
60
62
uint32_t count_p2p;
61
63
uint32_t count_inv;
@@ -183,6 +185,9 @@ int main(int argc, char **argv)
183
185
184
186
std::vector<uint32_t > rnode_vec;
185
187
std::vector<uint32_t > rnode_pos;
188
+ std::vector<uint8_t > source_patterns;
189
+ std::unordered_map<uint16_t , std::vector<uint32_t >> source_offsets;
190
+ uint32_t source_offsets_counts = 0 ;
186
191
187
192
uint8_t *opos = output.data () + dh->off_ro ;
188
193
while (rparse.rn || lparse.rn ) {
@@ -210,17 +215,57 @@ int main(int argc, char **argv)
210
215
rb.ro_line_info_index = lv ? get_line_info (lparse.li ) : 0xffff ;
211
216
rb.ro_driver_position = lv ? lparse.driver_position : 0 ;
212
217
rb.ro_fw_pos = rv ? rparse.fw_pos : 0 ;
213
-
214
218
uint32_t span = rv ? rparse.pattern == 0xfe ? 1 : rmux_patterns[rparse.pattern ].span : 0 ;
215
-
216
- memcpy (opos, &rb, sizeof (rb)) ;
219
+
220
+ uint8_t *rbpos = opos ;
217
221
opos += sizeof (rb);
218
222
219
223
if (span) {
220
- memcpy (opos, rparse.sources .data (), span*4 );
221
- opos += 4 *span;
224
+ uint8_t srcidx[64 ];
225
+ uint8_t backidx[64 ];
226
+ uint32_t srclen = 0 ;
227
+
228
+ for (uint32_t i = 0 ; i != span; i++) {
229
+ if (rparse.sources [i]) {
230
+ if (i != srclen)
231
+ rparse.sources [srclen] = rparse.sources [i];
232
+ srcidx[srclen] = i;
233
+ backidx[i] = srclen++;
234
+ } else
235
+ backidx[i] = 0xff ;
236
+ }
237
+
238
+ rb.ro_span = span;
239
+ rb.ro_srclen = srclen;
240
+
241
+ uint16_t key = (span << 8 ) | srclen;
242
+ auto &offs = source_offsets[key];
243
+ for (uint32_t off : offs)
244
+ if (!memcmp (source_patterns.data () + off, srcidx, srclen)) {
245
+ rb.ro_srcoff = off;
246
+ goto found;
247
+ }
248
+ {
249
+ uint32_t off = source_patterns.size ();
250
+ rb.ro_srcoff = off;
251
+ source_patterns.resize (off + srclen + span);
252
+ memcpy (source_patterns.data () + off, srcidx, srclen);
253
+ memcpy (source_patterns.data () + off + srclen, backidx, span);
254
+ offs.push_back (off);
255
+ source_offsets_counts ++;
256
+ }
257
+
258
+ found:
259
+ memcpy (opos, rparse.sources .data (), srclen*4 );
260
+ opos += 4 *srclen;
261
+ } else {
262
+ rb.ro_span = 0 ;
263
+ rb.ro_srclen = 0 ;
264
+ rb.ro_srcoff = 0xffff ;
222
265
}
223
266
267
+ memcpy (rbpos, &rb, sizeof (rb));
268
+
224
269
if (rb.ro_targets_count || rb.ro_targets_caps_count ) {
225
270
memcpy (opos, lparse.targets .data (), rb.ro_targets_count *4 );
226
271
opos += rb.ro_targets_count *4 ;
@@ -250,6 +295,7 @@ int main(int argc, char **argv)
250
295
auto hdata = bdz_ph_hash::make (rnode_vec);
251
296
size_t rohs = (hdata.size () + 3 ) & ~3 ;
252
297
size_t ris = 4 *bdz_ph_hash::output_range (hdata);
298
+ size_t rsrc = (source_patterns.size () + 3 ) & ~3 ;
253
299
size_t llines = sizeof (rnode_line_information)*rli_data.size ();
254
300
size_t p2rs = p2r.data .size ()*sizeof (p2r_info);
255
301
size_t p2ps = p2p.data .size ()*sizeof (p2p_info);
@@ -263,7 +309,8 @@ int main(int argc, char **argv)
263
309
264
310
dh->off_roh = opos - output.data ();
265
311
dh->off_ri = dh->off_roh + rohs;
266
- dh->off_line = dh->off_ri + ris;
312
+ dh->off_rsrc = dh->off_ri + ris;
313
+ dh->off_line = dh->off_rsrc + rsrc;
267
314
dh->off_p2r = dh->off_line + llines;
268
315
dh->off_p2p = dh->off_p2r + p2rs;
269
316
dh->off_inv = dh->off_p2p + p2ps;
@@ -277,6 +324,7 @@ int main(int argc, char **argv)
277
324
278
325
dh->count_ro = rnode_vec.size ();
279
326
dh->count_ri = bdz_ph_hash::output_range (hdata);
327
+ dh->count_rsrc = source_patterns.size () ;
280
328
dh->count_p2r = p2r.data .size ();
281
329
dh->count_p2p = p2p.data .size ();
282
330
dh->count_inv = inv.data .size ();
@@ -298,6 +346,7 @@ int main(int argc, char **argv)
298
346
ro->ro_ri = idx;
299
347
}
300
348
349
+ memcpy (output.data () + dh->off_rsrc , source_patterns.data (), dh->count_rsrc );
301
350
memcpy (output.data () + dh->off_line , rli_data.data (), llines);
302
351
memcpy (output.data () + dh->off_p2r , p2r.data .data (), p2rs);
303
352
memcpy (output.data () + dh->off_p2p , p2p.data .data (), p2ps);
@@ -310,13 +359,15 @@ int main(int argc, char **argv)
310
359
memcpy (output.data () + dh->off_dqs16 , dqs16_info.data (), dqs16s);
311
360
memcpy (output.data () + dh->off_iob , iob.data .data (), iobs);
312
361
313
- fprintf (stderr, " %-6s size %9d ro %9d rh %7d ri %8d rc %7d lines %5d p2r %5d p2p %4d inv %5d one %2d dcram %2d hps %2d fixed %2d dqs16 %2d iob %3d\n " ,
362
+ fprintf (stderr, " %-6s size %9d ro %9d rh %7d ri %8d rc %7d rsrc %d/%d lines %5d p2r %5d p2p %4d inv %5d one %2d dcram %2d hps %2d fixed %2d dqs16 %2d iob %3d\n " ,
314
363
chip.c_str (),
315
364
int (output.size ()),
316
365
dh->off_roh - dh->off_ro ,
317
366
dh->off_ri - dh->off_roh ,
318
367
dh->count_ri ,
319
368
dh->count_ro ,
369
+ source_offsets_counts,
370
+ dh->count_rsrc ,
320
371
int (rli_data.size ()),
321
372
int (p2r.data .size ()),
322
373
int (p2p.data .size ()),
0 commit comments