Skip to content

Commit c5666c4

Browse files
committed
mistral: fix corner cases related to 13x1-bit M10Ks
1 parent e5a5de5 commit c5666c4

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

mistral/pack.cc

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ struct MistralPacker
393393
auto dbits = ci->params.at(id_CFG_DBITS).as_int64();
394394
NPNR_ASSERT(abits >= 7 && abits <= 13);
395395
NPNR_ASSERT(dbits == 1 || dbits == 2 || dbits == 5 || dbits == 10 || dbits == 20);
396+
NPNR_ASSERT((1 << abits) * dbits <= 10240);
397+
398+
log_info("Setting up %ld-bit address, %ld-bit data M10K for %s.\n", abits, dbits, ci->name.str(ctx).c_str());
396399

397400
// Quartus doesn't seem to generate ADDRSTALL[AB], BYTEENABLE[AB][01].
398401

@@ -409,16 +412,18 @@ struct MistralPacker
409412
// Enables left unconnected.
410413

411414
// Address lines.
412-
int addr_offset = std::max(12 - std::max(abits, int64_t{9}), 0l);
413-
int bit_offset = 0;
415+
416+
// One could remove the std::max here and the `- bit_offset`s here,
417+
// because they would cancel out, but I think this way is less confusing.
418+
int addr_offset = std::max(12 - std::max(abits, 9L), 0L);
419+
int bit_offset = (abits == 13);
414420
if (abits == 13) {
415421
ci->pin_data[ctx->id("A1ADDR[0]")].bel_pins = {ctx->id("DATAAIN[4]")};
416422
ci->pin_data[ctx->id("B1ADDR[0]")].bel_pins = {ctx->id("DATABIN[19]")};
417-
bit_offset = 1;
418423
}
419424
for (int bit = bit_offset; bit < abits; bit++) {
420-
ci->pin_data[ctx->idf("A1ADDR[%d]", bit)].bel_pins = {ctx->idf("ADDRA[%d]", bit + addr_offset)};
421-
ci->pin_data[ctx->idf("B1ADDR[%d]", bit)].bel_pins = {ctx->idf("ADDRB[%d]", bit + addr_offset)};
425+
ci->pin_data[ctx->idf("A1ADDR[%d]", bit)].bel_pins = {ctx->idf("ADDRA[%d]", bit + addr_offset - bit_offset)};
426+
ci->pin_data[ctx->idf("B1ADDR[%d]", bit)].bel_pins = {ctx->idf("ADDRB[%d]", bit + addr_offset - bit_offset)};
422427
}
423428

424429
// Data lines
@@ -447,15 +452,23 @@ struct MistralPacker
447452
offsets.push_back(16);
448453
offsets.push_back(18);
449454
}
455+
456+
// In this corner case the pin name does not have indexing
457+
// because it's a single bit wide...
458+
if (abits == 13 && dbits == 1) {
459+
for (int offset : offsets)
460+
ci->pin_data[ctx->idf("A1DATA")].bel_pins.push_back(ctx->idf("DATAAIN[%d]", offset));
461+
ci->pin_data[ctx->idf("B1DATA")].bel_pins = {ctx->idf("DATABOUT[0]")};
462+
continue;
463+
}
464+
450465
for (int bit = 0; bit < dbits; bit++) {
451-
for (int offset : offsets) {
466+
for (int offset : offsets)
452467
ci->pin_data[ctx->idf("A1DATA[%d]", bit)].bel_pins.push_back(ctx->idf("DATAAIN[%d]", bit + offset));
453-
}
454468
}
455469

456-
for (int bit = 0; bit < dbits; bit++) {
470+
for (int bit = 0; bit < dbits; bit++)
457471
ci->pin_data[ctx->idf("B1DATA[%d]", bit)].bel_pins = {ctx->idf("DATABOUT[%d]", bit)};
458-
}
459472
}
460473
}
461474

0 commit comments

Comments
 (0)