Migrated C arrays to std::array containers.

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
This commit is contained in:
Maciej Kurc 2021-07-16 14:55:45 +02:00
parent 0336f55b16
commit 857961a6bb
2 changed files with 31 additions and 9 deletions

View File

@ -75,8 +75,7 @@ SiteLutMappingKey SiteLutMappingKey::create (const SiteInformation& siteInfo) {
cell.type = cellInfo->type; cell.type = cellInfo->type;
cell.belIndex = cellInfo->bel.index; cell.belIndex = cellInfo->bel.index;
memset((void*)cell.conns, 0, cell.conns.fill(0);
sizeof(int32_t) * SiteLutMappingKey::MAX_LUT_INPUTS);
size_t portId = 0; size_t portId = 0;
for (const auto& port : cellInfo->ports) { for (const auto& port : cellInfo->ports) {

View File

@ -41,13 +41,25 @@ struct SiteLutMappingKey {
// Port to net assignments. These are local net ids generated during // Port to net assignments. These are local net ids generated during
// key creation. This is to abstract connections from actual design // key creation. This is to abstract connections from actual design
// net names. the Id 0 means unconnected. // net names. the Id 0 means unconnected.
int32_t conns [MAX_LUT_INPUTS]; std::array<int32_t, MAX_LUT_INPUTS> conns;
bool operator == (const Cell& other) const {
return (type == other.type) &&
(belIndex == other.belIndex) &&
(conns == other.conns);
}
bool operator != (const Cell& other) const {
return (type != other.type) ||
(belIndex != other.belIndex) ||
(conns != other.conns);
}
}; };
int32_t tileType; // Tile type int32_t tileType; // Tile type
int32_t siteType; // Site type in that tile type int32_t siteType; // Site type in that tile type
size_t numCells; // LUT cell count size_t numCells; // LUT cell count
Cell cells[MAX_LUT_CELLS]; // LUT cell data std::array<Cell, MAX_LUT_CELLS> cells; // LUT cell data
unsigned int hash_; // Precomputed hash unsigned int hash_; // Precomputed hash
@ -67,20 +79,31 @@ struct SiteLutMappingKey {
} }
} }
bool compareCells (const SiteLutMappingKey &other) const {
if (numCells != other.numCells) {
return false;
}
for (size_t i=0; i<numCells; ++i) {
if (cells[i] != other.cells[i]) {
return false;
}
}
return true;
}
bool operator == (const SiteLutMappingKey &other) const { bool operator == (const SiteLutMappingKey &other) const {
return (hash_ == other.hash_) && return (hash_ == other.hash_) &&
(tileType == other.tileType) && (tileType == other.tileType) &&
(siteType == other.siteType) && (siteType == other.siteType) &&
(numCells == other.numCells) && compareCells(other);
(!memcmp(cells, other.cells, sizeof(Cell) * numCells));
} }
bool operator != (const SiteLutMappingKey &other) const { bool operator != (const SiteLutMappingKey &other) const {
return (hash_ != other.hash_) || return (hash_ != other.hash_) ||
(tileType != other.tileType) || (tileType != other.tileType) ||
(siteType != other.siteType) || (siteType != other.siteType) ||
(numCells != other.numCells) || !compareCells(other);
(memcmp(cells, other.cells, sizeof(Cell) * numCells));
} }
unsigned int hash () const { unsigned int hash () const {