aboutsummaryrefslogtreecommitdiffstats
path: root/machxo2/archdefs.h
diff options
context:
space:
mode:
authorWilliam D. Jones <thor0505@comcast.net>2020-12-05 22:01:28 -0500
committergatecat <gatecat@ds0.me>2021-02-12 10:36:59 +0000
commitdc07054ee8c28b9c553be4a61562c5b294de0c06 (patch)
tree485e6b07fbe045d0883f8823478348624f38c5a5 /machxo2/archdefs.h
parentec4a9685abf0fd7d7b2cfecc5dbfc09b963b6ea8 (diff)
downloadnextpnr-dc07054ee8c28b9c553be4a61562c5b294de0c06.tar.gz
nextpnr-dc07054ee8c28b9c553be4a61562c5b294de0c06.tar.bz2
nextpnr-dc07054ee8c28b9c553be4a61562c5b294de0c06.zip
machxo2: Implement functions to get device utilization (throws std::out_of_range during place phase).
Diffstat (limited to 'machxo2/archdefs.h')
-rw-r--r--machxo2/archdefs.h52
1 files changed, 51 insertions, 1 deletions
diff --git a/machxo2/archdefs.h b/machxo2/archdefs.h
index 56b546da..d33a3a3d 100644
--- a/machxo2/archdefs.h
+++ b/machxo2/archdefs.h
@@ -62,7 +62,34 @@ enum ConstIds
NPNR_PACKED_STRUCT(struct LocationPOD { int16_t x, y; });
-typedef IdString BelId;
+struct Location
+{
+ int16_t x = -1, y = -1;
+ Location() : x(-1), y(-1){};
+ Location(int16_t x, int16_t y) : x(x), y(y){};
+ Location(const LocationPOD &pod) : x(pod.x), y(pod.y){};
+ Location(const Location &loc) : x(loc.x), y(loc.y){};
+
+ bool operator==(const Location &other) const { return x == other.x && y == other.y; }
+ bool operator!=(const Location &other) const { return x != other.x || y != other.y; }
+ bool operator<(const Location &other) const { return y == other.y ? x < other.x : y < other.y; }
+};
+
+inline Location operator+(const Location &a, const Location &b) { return Location(a.x + b.x, a.y + b.y); }
+
+struct BelId
+{
+ Location location;
+ int32_t index = -1;
+
+ bool operator==(const BelId &other) const { return index == other.index && location == other.location; }
+ bool operator!=(const BelId &other) const { return index != other.index || location != other.location; }
+ bool operator<(const BelId &other) const
+ {
+ return location == other.location ? index < other.index : location < other.location;
+ }
+};
+
typedef IdString WireId;
typedef IdString PipId;
typedef IdString GroupId;
@@ -86,3 +113,26 @@ struct ArchCellInfo
};
NEXTPNR_NAMESPACE_END
+
+namespace std {
+template <> struct hash<NEXTPNR_NAMESPACE_PREFIX Location>
+{
+ std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX Location &loc) const noexcept
+ {
+ std::size_t seed = std::hash<int>()(loc.x);
+ seed ^= std::hash<int>()(loc.y) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
+ return seed;
+ }
+};
+
+template <> struct hash<NEXTPNR_NAMESPACE_PREFIX BelId>
+{
+ std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX BelId &bel) const noexcept
+ {
+ std::size_t seed = std::hash<NEXTPNR_NAMESPACE_PREFIX Location>()(bel.location);
+ seed ^= std::hash<int>()(bel.index) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
+ return seed;
+ }
+};
+
+}