Added more code comments, formatted the code

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
This commit is contained in:
Maciej Kurc 2021-07-16 16:01:21 +02:00
parent ccf2bb123c
commit 8fc16a57c9
6 changed files with 120 additions and 119 deletions

View File

@ -814,8 +814,10 @@ bool Arch::place()
archInfoToAttributes();
// Print site LUT mapping caching stats
log_info("Site LUT mapping cache miss ratio: %.1f%%\n",
getCtx()->site_lut_mapping_cache.getMissRatio() * 100.0f);
log_info("Site LUT mapping cache stats:\n");
log_info(" miss ratio: %.1f%%\n", getCtx()->site_lut_mapping_cache.getMissRatio() * 100.0f);
log_info(" peak size : %zuMB (%zu items)\n", getCtx()->site_lut_mapping_cache.getSizeMB(),
getCtx()->site_lut_mapping_cache.getCount());
getCtx()->check();

View File

@ -255,7 +255,8 @@ uint32_t LutMapper::check_wires(const std::vector<std::vector<int32_t>> &bel_to_
return vcc_mask;
}
bool LutMapper::remap_luts(const Context *ctx, SiteLutMappingResult* lut_mapping, pool<const LutBel *, hash_ptr_ops> *blocked_luts)
bool LutMapper::remap_luts(const Context *ctx, SiteLutMappingResult *lut_mapping,
pool<const LutBel *, hash_ptr_ops> *blocked_luts)
{
dict<NetInfo *, LutPin, hash_ptr_ops> lut_pin_map;
std::vector<const LutBel *> lut_bels;

View File

@ -70,12 +70,12 @@ struct LutBel
struct SiteLutMapping
{
struct LutCellMapping {
struct LutCellMapping
{
LutCell lut_cell;
};
};
// Work forward from cell definition and cell -> bel pin map and check that
// equation is valid.
void check_equation(const LutCell &lut_cell, const dict<IdString, IdString> &cell_to_bel_map, const LutBel &lut_bel,
@ -99,7 +99,8 @@ struct LutMapper
std::vector<CellInfo *> cells;
bool remap_luts(const Context *ctx, SiteLutMappingResult* lut_mapping, pool<const LutBel *, hash_ptr_ops> *blocked_luts);
bool remap_luts(const Context *ctx, SiteLutMappingResult *lut_mapping,
pool<const LutBel *, hash_ptr_ops> *blocked_luts);
// Determine which wires given the current mapping must be tied to the
// default constant.

View File

@ -17,16 +17,15 @@
*
*/
#include "nextpnr.h"
#include "archdefs.h"
#include "site_arch.h"
#include "site_lut_mapping_cache.h"
#include "nextpnr.h"
NEXTPNR_NAMESPACE_BEGIN
// ============================================================================
SiteLutMappingKey SiteLutMappingKey::create (const SiteInformation& siteInfo) {
SiteLutMappingKey SiteLutMappingKey::create(const SiteInformation &siteInfo)
{
const Context *ctx = siteInfo.ctx;
// Look for LUT cells in the site
@ -52,10 +51,7 @@ SiteLutMappingKey SiteLutMappingKey::create (const SiteInformation& siteInfo) {
// Sort cells by BEL indices to maintain always the same order
std::sort(lutCells.begin(), lutCells.end(),
[](const CellInfo* a, const CellInfo* b)
{
return a->bel.index > b->bel.index;
});
[](const CellInfo *a, const CellInfo *b) { return a->bel.index > b->bel.index; });
// Initialize the key
SiteLutMappingKey key;
@ -94,8 +90,7 @@ SiteLutMappingKey SiteLutMappingKey::create (const SiteInformation& siteInfo) {
auto it = netMap.find(netInfo->name);
if (it != netMap.end()) {
netId = it->second;
}
else {
} else {
netId = (int32_t)netMap.size() + 1;
netMap[netInfo->name] = netId;
}
@ -114,8 +109,8 @@ SiteLutMappingKey SiteLutMappingKey::create (const SiteInformation& siteInfo) {
// ============================================================================
bool SiteLutMappingResult::apply (const SiteInformation& siteInfo) {
bool SiteLutMappingResult::apply(const SiteInformation &siteInfo)
{
Context *ctx = const_cast<Context *>(siteInfo.ctx);
TileStatus &tileStatus = ctx->get_tile_status(siteInfo.tile);
@ -149,7 +144,8 @@ bool SiteLutMappingResult::apply (const SiteInformation& siteInfo) {
return true;
}
size_t SiteLutMappingResult::getSizeInBytes () const {
size_t SiteLutMappingResult::getSizeInBytes() const
{
size_t size = 0;
@ -166,14 +162,12 @@ size_t SiteLutMappingResult::getSizeInBytes () const {
// ============================================================================
void SiteLutMappingCache::add (const SiteLutMappingKey& key,
const SiteLutMappingResult& result)
void SiteLutMappingCache::add(const SiteLutMappingKey &key, const SiteLutMappingResult &result)
{
cache_[key] = result;
}
bool SiteLutMappingCache::get (const SiteLutMappingKey& key,
SiteLutMappingResult* result)
bool SiteLutMappingCache::get(const SiteLutMappingKey &key, SiteLutMappingResult *result)
{
if (cache_.count(key) == 0) {
numMisses++;
@ -185,12 +179,14 @@ bool SiteLutMappingCache::get (const SiteLutMappingKey& key,
return true;
}
void SiteLutMappingCache::clear () {
void SiteLutMappingCache::clear()
{
cache_.clear();
clearStats();
}
void SiteLutMappingCache::clearStats () {
void SiteLutMappingCache::clearStats()
{
numHits = 0;
numMisses = 0;
}
@ -198,4 +194,3 @@ void SiteLutMappingCache::clearStats () {
// ============================================================================
NEXTPNR_NAMESPACE_END

View File

@ -20,13 +20,15 @@
#ifndef SITE_LUT_MAPPING_CACHE_H
#define SITE_LUT_MAPPING_CACHE_H
#include "idstring.h"
#include "nextpnr_namespaces.h"
#include "idstring.h"
#include "site_arch.h"
NEXTPNR_NAMESPACE_BEGIN
// Key structure used in site LUT mapping cache
struct SiteLutMappingKey {
struct SiteLutMappingKey
{
// Maximum number of LUT cells per site
static constexpr size_t MAX_LUT_CELLS = 8;
@ -34,7 +36,8 @@ struct SiteLutMappingKey {
static constexpr size_t MAX_LUT_INPUTS = 6;
// LUT Cell data
struct Cell {
struct Cell
{
IdString type; // Cell type
int32_t belIndex; // Bound BEL index
@ -43,16 +46,14 @@ struct SiteLutMappingKey {
// net names. the Id 0 means unconnected.
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);
}
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);
}
};
@ -63,13 +64,15 @@ struct SiteLutMappingKey {
unsigned int hash_; // Precomputed hash
// Creates a key from the given site state
static SiteLutMappingKey create(const SiteInformation &siteInfo);
size_t getSizeInBytes () const {
return sizeof(SiteLutMappingKey);
}
// Returns size in bytes of the key
size_t getSizeInBytes() const { return sizeof(SiteLutMappingKey); }
void computeHash () {
// Precomputes hash of the key and stores it within
void computeHash()
{
hash_ = mkhash(0, tileType);
hash_ = mkhash(hash_, siteType);
hash_ = mkhash(hash_, numCells);
@ -83,7 +86,9 @@ struct SiteLutMappingKey {
}
}
bool compareCells (const SiteLutMappingKey &other) const {
// Compares cell data of this and other key
bool compareCells(const SiteLutMappingKey &other) const
{
if (numCells != other.numCells) {
return false;
}
@ -96,30 +101,28 @@ struct SiteLutMappingKey {
return true;
}
bool operator == (const SiteLutMappingKey &other) const {
return (hash_ == other.hash_) &&
(tileType == other.tileType) &&
(siteType == other.siteType) &&
bool operator==(const SiteLutMappingKey &other) const
{
return (hash_ == other.hash_) && (tileType == other.tileType) && (siteType == other.siteType) &&
compareCells(other);
}
bool operator != (const SiteLutMappingKey &other) const {
return (hash_ != other.hash_) ||
(tileType != other.tileType) ||
(siteType != other.siteType) ||
bool operator!=(const SiteLutMappingKey &other) const
{
return (hash_ != other.hash_) || (tileType != other.tileType) || (siteType != other.siteType) ||
!compareCells(other);
}
unsigned int hash () const {
return hash_;
}
unsigned int hash() const { return hash_; }
};
// Site LUT mapping result data
struct SiteLutMappingResult {
struct SiteLutMappingResult
{
// LUT cell data
struct Cell {
struct Cell
{
int32_t belIndex; // BEL in tile index
LutCell lutCell; // LUT mapping data
dict<IdString, IdString> belPins; // Cell to BEL pin mapping
@ -128,7 +131,7 @@ struct SiteLutMappingResult {
bool isValid; // Validity flag
std::vector<Cell> cells; // Cell data
pool<std::pair<IdString, IdString>> blockedWires;
pool<std::pair<IdString, IdString>> blockedWires; // Set of blocked wires
// Applies the mapping result to the site
bool apply(const SiteInformation &siteInfo);
@ -138,24 +141,28 @@ struct SiteLutMappingResult {
};
// Site LUT mapping cache object
class SiteLutMappingCache {
class SiteLutMappingCache
{
public:
// Adds an entry to the cache
void add(const SiteLutMappingKey &key, const SiteLutMappingResult &result);
// Retrieves an entry from the cache. Returns false if not found
bool get(const SiteLutMappingKey &key, SiteLutMappingResult *result);
// Clears the cache
void clear();
// Clears statistics counters of the cache
void clearStats();
float getMissRatio () const {
return (float)numMisses / (float)(numHits + numMisses);
}
// Return get() miss ratio
float getMissRatio() const { return (float)numMisses / (float)(numHits + numMisses); }
size_t getCount () const {
return cache_.size();
}
// Returns count of entries in the cache
size_t getCount() const { return cache_.size(); }
size_t getSizeMB () const {
// Returns size of the cache rounded upwards to full MBs.
size_t getSizeMB() const
{
size_t size = 0;
for (const auto &it : cache_) {
size += it.first.getSizeInBytes();
@ -167,14 +174,12 @@ public:
}
private:
dict<SiteLutMappingKey, SiteLutMappingResult> cache_; // The cache
dict<SiteLutMappingKey, SiteLutMappingResult> cache_;
size_t numHits = 0;
size_t numMisses = 0;
size_t numHits = 0; // Hit count
size_t numMisses = 0; // Miss count
};
NEXTPNR_NAMESPACE_END
#endif /* SITE_LUT_MAPPING_CACHE_H */

View File

@ -1099,10 +1099,7 @@ static bool map_luts_in_site(const SiteInformation &site_info, pool<std::pair<Id
lutMapping.apply(site_info);
blocked_wires->clear();
blocked_wires->insert(
lutMapping.blockedWires.begin(),
lutMapping.blockedWires.end()
);
blocked_wires->insert(lutMapping.blockedWires.begin(), lutMapping.blockedWires.end());
}
return lutMapping.isValid;