Debian Codegraph @

himbaechel/uarch/gatemate/pack.h

raw
1 /*
2 * nextpnr -- Next Generation Place and Route
3 *
4 * Copyright (C) 2024 The Project Peppercorn Authors.
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 GATEMATE_PACK_H
21 #define GATEMATE_PACK_H
22
23 #include "gatemate.h"
24
25 NEXTPNR_NAMESPACE_BEGIN
26
27 enum CPELut
28 {
29 LUT_ZERO = 0b0000,
30 LUT_NOR = 0b0001,
31 LUT_AND_INV_D1 = 0b0010,
32 LUT_INV_D1 = 0b0011,
33 LUT_AND_INV_D0 = 0b0100,
34 LUT_INV_D0 = 0b0101,
35 LUT_XOR = 0b0110,
36 LUT_NAND = 0b0111,
37 LUT_AND = 0b1000,
38 LUT_XNOR = 0b1001,
39 LUT_D0 = 0b1010,
40 LUT_NAND_INV_D0 = 0b1011,
41 LUT_D1 = 0b1100,
42 LUT_NAND_INV_D1 = 0b1101,
43 LUT_OR = 0b1110,
44 LUT_ONE = 0b1111
45 };
46
47 struct GateMatePacker
48 {
49 GateMatePacker(Context *ctx, GateMateImpl *uarch) : ctx(ctx), uarch(uarch) { h.init(ctx); };
50
51 void pack_io();
52 void pack_io_sel();
53 void pack_cpe();
54 void pack_addf();
55 void pack_bufg();
56 void sort_bufg(unsigned max_num);
57 void insert_clocking();
58 void pack_pll();
59 void pack_misc();
60 void pack_mult();
61 void pack_constants();
62 void pack_ram();
63 void pack_serdes();
64
65 void remove_constants();
66 void remove_clocking();
67 void remove_double_constrained();
68
69 void cleanup();
70 void repack_cpe();
71 void repack_ram();
72 void reassign_clocks();
73 void copy_clocks();
74 void assign_clocks();
75 void find_regions();
76 void assign_regions();
77 void fix_regions();
78
79 private:
80 void rename_param(CellInfo *cell, IdString name, IdString new_name, int width);
81 void dff_to_cpe(CellInfo *dff);
82 void dff_update_params();
83 void disconnect_if_gnd(CellInfo *cell, IdString input);
84 void pll_out(CellInfo *cell, IdString origPort, Loc fixed);
85 void rewire_ram_o(CellInfo *first, IdString port, CellInfo *second);
86
87 void disconnect_not_used();
88 void optimize_lut();
89 void optimize_lut2(CellInfo &ci, IdString i0, IdString i1, IdString init);
90 void optimize_mx();
91 void optimize_ff();
92 void count_cell(CellInfo &ci);
93 void move_connections(NetInfo *from_net, NetInfo *to_net);
94 void remap_ram_half(CellInfo *half, CellInfo *cell, int num);
95
96 void strategy_mirror();
97 void strategy_clk1();
98 void strategy_full();
99
100 void override_region(CellInfo *first, CellInfo *second);
101 void recursiveAddToRegion(CellInfo *root, IdString die);
102
103 PllCfgRecord get_pll_settings(double f_ref, double f_core, int mode, int low_jitter, bool pdiv0_mux, bool feedback);
104
105 std::pair<CellInfo *, CellInfo *> move_ram_i(CellInfo *cell, IdString origPort, bool place = true,
106 Loc cpe_loc = Loc());
107 std::pair<CellInfo *, CellInfo *> move_ram_o(CellInfo *cell, IdString origPort, bool place = true,
108 Loc cpe_loc = Loc());
109 std::pair<CellInfo *, CellInfo *> move_ram_io(CellInfo *cell, IdString iPort, IdString oPort, bool place = true,
110 Loc cpe_loc = Loc());
111 std::pair<CellInfo *, CellInfo *> move_ram_i_fixed(CellInfo *cell, IdString origPort, Loc fixed);
112 std::pair<CellInfo *, CellInfo *> move_ram_o_fixed(CellInfo *cell, IdString origPort, Loc fixed);
113 std::pair<CellInfo *, CellInfo *> move_ram_io_fixed(CellInfo *cell, IdString iPort, IdString oPort, Loc fixed);
114 uint8_t ram_ctrl_signal(CellInfo *cell, IdString port, bool alt);
115 uint8_t ram_clk_signal(CellInfo *cell, IdString port);
116 bool is_gpio_valid_dff(CellInfo *dff);
117 bool are_ffs_compatible(CellInfo *dff, CellInfo *other);
118
119 // Cell creating
120 CellInfo *create_cell_ptr(IdString type, IdString name);
121 void flush_cells();
122 void pack_ram_cell(CellInfo &ci, CellInfo *cell, bool is_split);
123 void copy_constraint(const NetInfo *in_net, NetInfo *out_net);
124
125 pool<IdString> packed_cells;
126
127 Context *ctx;
128 GateMateImpl *uarch;
129
130 HimbaechelHelpers h;
131 NetInfo *net_PACKER_VCC;
132 NetInfo *net_PACKER_GND;
133 NetInfo *net_SER_CLK;
134 int count;
135 std::map<IdString, int> count_per_type;
136 };
137
138 NEXTPNR_NAMESPACE_END
139 #endif