nextpnr/cyclonev/archdefs.h

160 lines
4.3 KiB
C
Raw Normal View History

2020-06-13 05:09:46 +08:00
/*
* nextpnr -- Next Generation Place and Route
*
2021-01-07 00:22:17 +08:00
* Copyright (C) 2021 Lofty <dan.ravensloft@gmail.com
2020-06-13 05:09:46 +08:00
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
#ifndef MISTRAL_ARCHDEFS_H
#define MISTRAL_ARCHDEFS_H
2020-06-13 05:09:46 +08:00
#include <boost/functional/hash.hpp>
#include "cyclonev.h"
#include "idstring.h"
#include "nextpnr_assertions.h"
#include "nextpnr_namespaces.h"
2021-01-07 00:22:17 +08:00
2020-06-13 05:09:46 +08:00
NEXTPNR_NAMESPACE_BEGIN
2021-01-07 00:22:17 +08:00
using mistral::CycloneV;
2020-06-13 05:09:46 +08:00
typedef int delay_t;
// https://bugreports.qt.io/browse/QTBUG-80789
#ifndef Q_MOC_RUN
enum ConstIds
{
ID_NONE
#define X(t) , ID_##t
#include "constids.inc"
#undef X
};
#define X(t) static constexpr auto id_##t = IdString(ID_##t);
#include "constids.inc"
#undef X
#endif
2020-06-13 05:09:46 +08:00
struct DelayInfo
{
delay_t delay = 0;
delay_t minRaiseDelay() const { return delay; }
delay_t maxRaiseDelay() const { return delay; }
delay_t minFallDelay() const { return delay; }
delay_t maxFallDelay() const { return delay; }
delay_t minDelay() const { return delay; }
delay_t maxDelay() const { return delay; }
DelayInfo operator+(const DelayInfo &other) const
{
DelayInfo ret;
ret.delay = this->delay + other.delay;
return ret;
}
};
struct BelId
{
2021-02-04 10:29:59 +08:00
BelId() = default;
BelId(CycloneV::pos_t _pos, uint16_t _z) : pos{_pos}, z{_z} {}
2021-01-07 00:22:17 +08:00
// pos_t is used for X/Y, nextpnr-cyclonev uses its own Z coordinate system.
CycloneV::pos_t pos = 0;
uint16_t z = 0;
2020-06-13 05:09:46 +08:00
2021-01-07 00:22:17 +08:00
bool operator==(const BelId &other) const { return pos == other.pos && z == other.z; }
bool operator!=(const BelId &other) const { return pos != other.pos || z != other.z; }
bool operator<(const BelId &other) const { return pos < other.pos || (pos == other.pos && z < other.z); }
2020-06-13 05:09:46 +08:00
};
static constexpr auto invalid_rnode = std::numeric_limits<CycloneV::rnode_t>::max();
2020-06-13 05:09:46 +08:00
struct WireId
{
WireId() = default;
explicit WireId(CycloneV::rnode_t node) : node(node){};
CycloneV::rnode_t node = invalid_rnode;
// Wires created by nextpnr have rnode type >= 128
bool is_nextpnr_created() const
{
NPNR_ASSERT(node != invalid_rnode);
return CycloneV::rn2t(node) >= 128;
}
2020-06-13 05:09:46 +08:00
bool operator==(const WireId &other) const { return node == other.node; }
bool operator!=(const WireId &other) const { return node != other.node; }
bool operator<(const WireId &other) const { return node < other.node; }
2020-06-13 05:09:46 +08:00
};
struct PipId
{
PipId() = default;
PipId(CycloneV::rnode_t src, CycloneV::rnode_t dst) : src(src), dst(dst){};
CycloneV::rnode_t src = invalid_rnode, dst = invalid_rnode;
2020-06-13 05:09:46 +08:00
bool operator==(const PipId &other) const { return src == other.src && dst == other.dst; }
bool operator!=(const PipId &other) const { return src != other.src || dst != other.dst; }
bool operator<(const PipId &other) const { return dst < other.dst || (dst == other.dst && src < other.src); }
2020-06-13 05:09:46 +08:00
};
typedef IdString DecalId;
typedef IdString GroupId;
typedef IdString BelBucketId;
2020-06-13 05:09:46 +08:00
struct ArchNetInfo
{
};
struct ArchCellInfo
{
};
NEXTPNR_NAMESPACE_END
namespace std {
template <> struct hash<NEXTPNR_NAMESPACE_PREFIX BelId>
{
std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX BelId &bel) const noexcept
{
return hash<uint32_t>()((static_cast<uint32_t>(bel.pos) << 16) | bel.z);
}
2020-06-13 05:09:46 +08:00
};
template <> struct hash<NEXTPNR_NAMESPACE_PREFIX WireId>
{
std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX WireId &wire) const noexcept
{
return hash<uint32_t>()(wire.node);
2020-06-13 05:09:46 +08:00
}
};
template <> struct hash<NEXTPNR_NAMESPACE_PREFIX PipId>
{
std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX PipId &pip) const noexcept
{
return hash<uint64_t>()((uint64_t(pip.dst) << 32) | pip.src);
}
2020-06-13 05:09:46 +08:00
};
} // namespace std
#endif