Debian Codegraph @

himbaechel/uarch/xilinx/pack.h

raw
1 /*
2 * nextpnr -- Next Generation Place and Route
3 *
4 * Copyright (C) 2019-23 Myrtle Shah <[email protected]>
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 #include <algorithm>
21 #include <boost/optional.hpp>
22 #include <iterator>
23 #include <queue>
24 #include <unordered_set>
25 #include "chain_utils.h"
26 #include "design_utils.h"
27 #include "log.h"
28 #include "nextpnr.h"
29 #include "pins.h"
30 #include "xilinx.h"
31
32 #ifndef HB_XILINX_PACK_H
33 #define HB_XILINX_PACK_H
34
35 NEXTPNR_NAMESPACE_BEGIN
36
37 struct XilinxPacker
38 {
39 Context *ctx;
40 XilinxImpl *uarch;
41
42 XilinxPacker(Context *ctx, XilinxImpl *uarch) : ctx(ctx), uarch(uarch) {};
43
44 // Generic cell transformation
45 // Given cell name map and port map
46 // If port name is not found in port map; it will be copied as-is but stripping []
47 struct XFormRule
48 {
49 IdString new_type;
50 dict<IdString, IdString> port_xform;
51 dict<IdString, std::vector<IdString>> port_multixform;
52 dict<IdString, IdString> param_xform;
53 std::vector<std::pair<IdString, std::string>> set_attrs;
54 std::vector<std::pair<IdString, Property>> set_params;
55 };
56
57 // Distributed RAM control set
58 struct DRAMControlSet
59 {
60 std::vector<NetInfo *> wa;
61 NetInfo *wclk, *we;
62 bool wclk_inv;
63 IdString memtype;
64
65 bool operator==(const DRAMControlSet &other) const
66 {
67 return wa == other.wa && wclk == other.wclk && we == other.we && wclk_inv == other.wclk_inv &&
68 memtype == other.memtype;
69 }
70 bool operator!=(const DRAMControlSet &other) const
71 {
72 return wa != other.wa || wclk != other.wclk || we != other.we || wclk_inv != other.wclk_inv ||
73 memtype != other.memtype;
74 }
75 unsigned int hash() const
76 {
77 unsigned seed = 0;
78 seed = mkhash(seed, wa.size());
79 for (auto abit : wa)
80 seed = mkhash(seed, (abit == nullptr ? IdString() : abit->name).hash());
81 seed = mkhash(seed, (wclk == nullptr ? IdString() : wclk->name).hash());
82 seed = mkhash(seed, (we == nullptr ? IdString() : we->name).hash());
83 seed = mkhash(seed, wclk_inv);
84 seed = mkhash(seed, memtype.hash());
85 return seed;
86 }
87 };
88
89 struct DRAMType
90 {
91 int abits;
92 int dbits;
93 int rports;
94 };
95
96 struct CarryGroup
97 {
98 std::vector<CellInfo *> muxcys;
99 std::vector<CellInfo *> xorcys;
100 };
101
102 pool<IdString> packed_cells;
103
104 // General helper functions
105 void flush_cells();
106
107 void xform_cell(const dict<IdString, XFormRule> &rules, CellInfo *ci);
108 void generic_xform(const dict<IdString, XFormRule> &rules, bool print_summary = false);
109
110 CellInfo *feed_through_lut(NetInfo *net, const std::vector<PortRef> &feed_users);
111 CellInfo *feed_through_muxf(NetInfo *net, IdString type, const std::vector<PortRef> &feed_users);
112
113 IdString int_name(IdString base, const std::string &postfix, bool is_hierarchy = true);
114 NetInfo *create_internal_net(IdString base, const std::string &postfix, bool is_hierarchy = true);
115 void rename_net(IdString old, IdString newname);
116
117 void tie_port(CellInfo *ci, const std::string &port, bool value, bool inv = false);
118
119 // LUTs & FFs
120 void pack_inverters();
121 void pack_luts();
122 void pack_ffs();
123 void pack_lutffs();
124
125 bool is_constrained(const CellInfo *cell);
126 void pack_muxfs();
127 void finalise_muxfs();
128 void legalise_muxf_tree(CellInfo *curr, std::vector<CellInfo *> &mux_roots, pool<IdString> &seen_leaves);
129 void constrain_muxf_tree(CellInfo *curr, CellInfo *base, int zoffset);
130 void create_muxf_tree(CellInfo *base, const std::string &name_base, const std::vector<NetInfo *> &data,
131 const std::vector<NetInfo *> &select, NetInfo *out, int zoffset);
132
133 void pack_srls();
134
135 void split_carry4s();
136
137 // DistRAM
138 dict<IdString, XFormRule> dram_rules, dram32_6_rules, dram32_5_rules;
139 CellInfo *create_dram_lut(const std::string &name, CellInfo *base, const DRAMControlSet &ctrlset,
140 std::vector<NetInfo *> address, NetInfo *di, NetInfo *dout, int z);
141 CellInfo *create_dram32_lut(const std::string &name, CellInfo *base, const DRAMControlSet &ctrlset,
142 std::vector<NetInfo *> address, NetInfo *di, NetInfo *dout, bool o5, int z);
143 void pack_dram();
144
145 // Constant pins
146 dict<IdString, dict<IdString, bool>> tied_pins;
147 dict<IdString, pool<IdString>> invertible_pins;
148 void pack_constants();
149
150 // IO
151 dict<IdString, pool<IdString>> toplevel_ports;
152 NetInfo *invert_net(NetInfo *toinv);
153 CellInfo *insert_obuf(IdString name, IdString type, NetInfo *i, NetInfo *o, NetInfo *tri = nullptr);
154 CellInfo *insert_outinv(IdString name, NetInfo *i, NetInfo *o);
155 std::pair<CellInfo *, PortRef> insert_pad_and_buf(CellInfo *npnr_io);
156 CellInfo *create_iobuf(CellInfo *npnr_io, IdString &top_port);
157
158 // Clocking
159 BelId find_bel_with_short_route(WireId source, IdString beltype, IdString belpin);
160 void try_preplace(CellInfo *cell, IdString port);
161 void preplace_unique(CellInfo *cell);
162
163 // Cell creating
164 CellInfo *create_cell(IdString type, IdString name);
165 CellInfo *create_lut(const std::string &name, const std::vector<NetInfo *> &inputs, NetInfo *output,
166 const Property &init);
167
168 int autoidx = 0;
169 };
170
171 struct XC7Packer : public XilinxPacker
172 {
173 XC7Packer(Context *ctx, XilinxImpl *uarch) : XilinxPacker(ctx, uarch) {};
174
175 // Carries
176 bool has_illegal_fanout(NetInfo *carry);
177 void pack_carries();
178
179 // IO
180 CellInfo *insert_ibuf(IdString name, IdString type, NetInfo *i, NetInfo *o);
181 CellInfo *insert_diffibuf(IdString name, IdString type, const std::array<NetInfo *, 2> &i, NetInfo *o);
182
183 void decompose_iob(CellInfo *xil_iob, bool is_hr, const std::string &iostandard);
184 void pack_io();
185
186 // IOLOGIC
187 dict<IdString, XFormRule> hp_iol_rules, hd_iol_rules, ioctrl_rules;
188 void fold_inverter(CellInfo *cell, std::string port);
189 SiteIndex get_ologic_site(BelId io_bel);
190 SiteIndex get_ilogic_site(BelId io_bel);
191 SiteIndex get_ioctrl_site(BelId io_bel);
192 SiteIndex get_odelay_site(BelId io_bel);
193 SiteIndex get_idelay_site(BelId io_bel);
194 // Call before packing constants
195 void prepare_iologic();
196
197 void pack_iologic();
198 void pack_idelayctrl();
199
200 // Clocking
201 void prepare_clocking();
202 void pack_plls();
203 void pack_gbs();
204 void pack_clocking();
205
206 // BRAM
207 void pack_bram();
208
209 // DSP
210 void pack_dsps();
211
212 private:
213 unsigned walk_dsp(CellInfo *root, CellInfo *ci, int constr_z);
214 void check_valid_pad(CellInfo *ci, std::string type);
215 };
216
217 NEXTPNR_NAMESPACE_END
218 #endif