Improve iCE40 and common Loc code

Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
Clifford Wolf 2018-07-20 17:33:57 +02:00
parent e16b4a325e
commit f6fa0300ae
4 changed files with 52 additions and 15 deletions

View File

@ -27,6 +27,8 @@
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include <boost/functional/hash.hpp>
#ifndef NEXTPNR_H #ifndef NEXTPNR_H
#define NEXTPNR_H #define NEXTPNR_H
@ -161,10 +163,27 @@ struct GraphicElement
struct Loc struct Loc
{ {
int x = -1, y = -1, z = -1; int x = -1, y = -1, z = -1;
bool operator==(const Loc &other) const { return (x == other.x) && (y == other.y) && (z == other.z); }
bool operator!=(const Loc &other) const { return (x != other.x) || (y != other.y) || (z == other.z); }
}; };
NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_END
namespace std {
template <> struct hash<NEXTPNR_NAMESPACE_PREFIX Loc>
{
std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX Loc &obj) const noexcept
{
std::size_t seed = 0;
boost::hash_combine(seed, hash<int>()(obj.x));
boost::hash_combine(seed, hash<int>()(obj.y));
boost::hash_combine(seed, hash<int>()(obj.z));
return seed;
}
};
} // namespace std
#include "archdefs.h" #include "archdefs.h"
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN

View File

@ -255,11 +255,40 @@ BelId Arch::getBelByName(IdString name) const
return ret; return ret;
} }
BelId Arch::getBelByLocation(int x, int y, int z) const
{
if (bel_by_loc.empty()) {
for (int i = 0; i < chip_info->num_bels; i++)
bel_by_loc[getBelLocation(BelId{i})] = i;
}
auto it = bel_by_loc.find(Loc{x, y, z});
if (it != bel_by_loc.end())
return BelId{it->second};
return BelId();
}
BelRange Arch::getBelsByTile(int x, int y) const
{
// In iCE40 chipdb bels at the same tile are consecutive and dense z ordinates are used
BelRange br;
br.b.cursor = Arch::getBelByLocation(x, y, 0);
br.e.cursor = br.b.cursor;
if (br.e.cursor != -1) {
while (br.e.cursor < chip_info->num_bels &&
chip_info->bel_data[br.e.cursor].x == x &&
chip_info->bel_data[br.e.cursor].y == y)
br.e.cursor++;
}
return br;
}
BelRange Arch::getBelsAtSameTile(BelId bel) const BelRange Arch::getBelsAtSameTile(BelId bel) const
{ {
BelRange br; BelRange br;
NPNR_ASSERT(bel != BelId()); NPNR_ASSERT(bel != BelId());
// This requires Bels at the same tile are consecutive
int x = chip_info->bel_data[bel.index].x; int x = chip_info->bel_data[bel.index].x;
int y = chip_info->bel_data[bel.index].y; int y = chip_info->bel_data[bel.index].y;
int start = bel.index, end = bel.index; int start = bel.index, end = bel.index;

View File

@ -350,6 +350,7 @@ struct Arch : BaseCtx
mutable std::unordered_map<IdString, int> bel_by_name; mutable std::unordered_map<IdString, int> bel_by_name;
mutable std::unordered_map<IdString, int> wire_by_name; mutable std::unordered_map<IdString, int> wire_by_name;
mutable std::unordered_map<IdString, int> pip_by_name; mutable std::unordered_map<IdString, int> pip_by_name;
mutable std::unordered_map<Loc, int> bel_by_loc;
std::vector<IdString> bel_to_cell; std::vector<IdString> bel_to_cell;
std::vector<IdString> wire_to_net; std::vector<IdString> wire_to_net;
@ -449,18 +450,8 @@ struct Arch : BaseCtx
return loc; return loc;
} }
BelId getBelByLocation(int x, int y, int z) const BelId getBelByLocation(int x, int y, int z) const;
{ BelRange getBelsByTile(int x, int y) const;
// FIXME
return BelId();
}
BelRange getBelsByTile(int x, int y) const
{
BelRange range;
// FIXME
return range;
}
bool getBelGlobalBuf(BelId bel) const bool getBelGlobalBuf(BelId bel) const
{ {

View File

@ -21,8 +21,6 @@
#error Include "archdefs.h" via "nextpnr.h" only. #error Include "archdefs.h" via "nextpnr.h" only.
#endif #endif
#include <boost/functional/hash.hpp>
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
typedef int delay_t; typedef int delay_t;