1 /*
2  *  nextpnr -- Next Generation Place and Route
3  *
4  *  Copyright (C) 2018  Clifford Wolf <clifford@symbioticeda.com>
5  *
6  *  Permission to use, copy, modify, and/or distribute this software for any
7  *  purpose with or without fee is hereby granted, provided that the above
8  *  copyright notice and this permission notice appear in all copies.
9  *
10  *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  *
18  */
19 
20 #ifndef NEXTPNR_H
21 #error Include "archdefs.h" via "nextpnr.h" only.
22 #endif
23 
24 NEXTPNR_NAMESPACE_BEGIN
25 
26 typedef int delay_t;
27 
28 struct DelayInfo
29 {
30     delay_t delay = 0;
31 
minRaiseDelayDelayInfo32     delay_t minRaiseDelay() const { return delay; }
maxRaiseDelayDelayInfo33     delay_t maxRaiseDelay() const { return delay; }
34 
minFallDelayDelayInfo35     delay_t minFallDelay() const { return delay; }
maxFallDelayDelayInfo36     delay_t maxFallDelay() const { return delay; }
37 
minDelayDelayInfo38     delay_t minDelay() const { return delay; }
maxDelayDelayInfo39     delay_t maxDelay() const { return delay; }
40 
41     DelayInfo operator+(const DelayInfo &other) const
42     {
43         DelayInfo ret;
44         ret.delay = this->delay + other.delay;
45         return ret;
46     }
47 };
48 
49 // -----------------------------------------------------------------------
50 
51 // https://bugreports.qt.io/browse/QTBUG-80789
52 
53 #ifndef Q_MOC_RUN
54 enum ConstIds
55 {
56     ID_NONE
57 #define X(t) , ID_##t
58 #include "constids.inc"
59 #undef X
60 };
61 
62 #define X(t) static constexpr auto id_##t = IdString(ID_##t);
63 #include "constids.inc"
64 #undef X
65 #endif
66 
67 struct BelId
68 {
69     int32_t index = -1;
70 
71     bool operator==(const BelId &other) const { return index == other.index; }
72     bool operator!=(const BelId &other) const { return index != other.index; }
73     bool operator<(const BelId &other) const { return index < other.index; }
74 };
75 
76 struct WireId
77 {
78     int32_t index = -1;
79 
80     bool operator==(const WireId &other) const { return index == other.index; }
81     bool operator!=(const WireId &other) const { return index != other.index; }
82     bool operator<(const WireId &other) const { return index < other.index; }
83 };
84 
85 struct PipId
86 {
87     int32_t index = -1;
88 
89     bool operator==(const PipId &other) const { return index == other.index; }
90     bool operator!=(const PipId &other) const { return index != other.index; }
91     bool operator<(const PipId &other) const { return index < other.index; }
92 };
93 
94 struct GroupId
95 {
96     enum : int8_t
97     {
98         TYPE_NONE,
99         TYPE_FRAME,
100         TYPE_MAIN_SW,
101         TYPE_LOCAL_SW,
102         TYPE_LC0_SW,
103         TYPE_LC1_SW,
104         TYPE_LC2_SW,
105         TYPE_LC3_SW,
106         TYPE_LC4_SW,
107         TYPE_LC5_SW,
108         TYPE_LC6_SW,
109         TYPE_LC7_SW
110     } type = TYPE_NONE;
111     int8_t x = 0, y = 0;
112 
113     bool operator==(const GroupId &other) const { return (type == other.type) && (x == other.x) && (y == other.y); }
114     bool operator!=(const GroupId &other) const { return (type != other.type) || (x != other.x) || (y == other.y); }
115 };
116 
117 struct DecalId
118 {
119     enum : int8_t
120     {
121         TYPE_NONE,
122         TYPE_BEL,
123         TYPE_WIRE,
124         TYPE_PIP,
125         TYPE_GROUP
126     } type = TYPE_NONE;
127     int32_t index = -1;
128     bool active = false;
129 
130     bool operator==(const DecalId &other) const { return (type == other.type) && (index == other.index); }
131     bool operator!=(const DecalId &other) const { return (type != other.type) || (index != other.index); }
132 };
133 
134 struct ArchNetInfo
135 {
136     bool is_global = false;
137     bool is_reset = false, is_enable = false;
138 };
139 
140 struct NetInfo;
141 
142 struct ArchCellInfo
143 {
144     union
145     {
146         struct
147         {
148             bool dffEnable;
149             bool carryEnable;
150             bool negClk;
151             int inputCount;
152             const NetInfo *clk, *cen, *sr;
153         } lcInfo;
154         struct
155         {
156             bool lvds;
157             bool global;
158             bool negtrig;
159             int pintype;
160             // TODO: clk packing checks...
161         } ioInfo;
162         struct
163         {
164             bool forPadIn;
165         } gbInfo;
166         struct
167         {
168             bool ledCurConnected;
169         } ledInfo;
170     };
171 };
172 
173 NEXTPNR_NAMESPACE_END
174 
175 namespace std {
176 template <> struct hash<NEXTPNR_NAMESPACE_PREFIX BelId>
177 {
178     std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX BelId &bel) const noexcept { return hash<int>()(bel.index); }
179 };
180 
181 template <> struct hash<NEXTPNR_NAMESPACE_PREFIX WireId>
182 {
183     std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX WireId &wire) const noexcept
184     {
185         return hash<int>()(wire.index);
186     }
187 };
188 
189 template <> struct hash<NEXTPNR_NAMESPACE_PREFIX PipId>
190 {
191     std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX PipId &pip) const noexcept { return hash<int>()(pip.index); }
192 };
193 
194 template <> struct hash<NEXTPNR_NAMESPACE_PREFIX GroupId>
195 {
196     std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX GroupId &group) const noexcept
197     {
198         std::size_t seed = 0;
199         boost::hash_combine(seed, hash<int>()(group.type));
200         boost::hash_combine(seed, hash<int>()(group.x));
201         boost::hash_combine(seed, hash<int>()(group.y));
202         return seed;
203     }
204 };
205 
206 template <> struct hash<NEXTPNR_NAMESPACE_PREFIX DecalId>
207 {
208     std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX DecalId &decal) const noexcept
209     {
210         std::size_t seed = 0;
211         boost::hash_combine(seed, hash<int>()(decal.type));
212         boost::hash_combine(seed, hash<int>()(decal.index));
213         return seed;
214     }
215 };
216 } // namespace std
217