| 1 |
/* |
| 2 |
* nextpnr -- Next Generation Place and Route |
| 3 |
* |
| 4 |
* Copyright (C) 2024 The Project Beyond 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 |
#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 "ng_ultra.h" |
| 30 |
|
| 31 |
#ifndef NG_ULTRA_PACK_H |
| 32 |
#define NG_ULTRA_PACK_H |
| 33 |
|
| 34 |
NEXTPNR_NAMESPACE_BEGIN |
| 35 |
|
| 36 |
struct NgUltraPacker |
| 37 |
{ |
| 38 |
NgUltraPacker(Context *ctx, NgUltraImpl *uarch) : ctx(ctx), uarch(uarch) { h.init(ctx); }; |
| 39 |
|
| 40 |
void remove_not_used(); |
| 41 |
// Constants |
| 42 |
void pack_constants(); |
| 43 |
void remove_constants(); |
| 44 |
|
| 45 |
// LUTs & FFs |
| 46 |
void update_lut_init(); |
| 47 |
void update_dffs(); |
| 48 |
void pack_xluts(); |
| 49 |
void pack_lut_multi_dffs(); |
| 50 |
void pack_dff_chains(); |
| 51 |
void pack_lut_dffs(); |
| 52 |
void pack_dffs(); |
| 53 |
void pack_cys(); |
| 54 |
void pack_rfs(); |
| 55 |
void pack_cdcs(); |
| 56 |
void pack_fifos(); |
| 57 |
|
| 58 |
void pack_rams(); |
| 59 |
void pack_dsps(); |
| 60 |
|
| 61 |
// IO |
| 62 |
void pack_iobs(); |
| 63 |
void pack_ioms(); |
| 64 |
|
| 65 |
void pack_gcks(); |
| 66 |
void pack_plls(); |
| 67 |
void pack_wfgs(); |
| 68 |
void pre_place(); |
| 69 |
|
| 70 |
void insert_ioms(); |
| 71 |
void insert_wfbs(); |
| 72 |
|
| 73 |
// Post placement |
| 74 |
void duplicate_gck(); |
| 75 |
void insert_bypass_gck(); |
| 76 |
void insert_csc(); |
| 77 |
|
| 78 |
/* clang-format off */ |
| 79 |
TESTABLE_PRIVATE: |
| 80 |
void set_lut_input_if_constant(CellInfo *cell, IdString input); |
| 81 |
/* clang-format on */ |
| 82 |
void lut_to_fe(CellInfo *lut, CellInfo *fe, bool no_dff, Property lut_table); |
| 83 |
void dff_to_fe(CellInfo *dff, CellInfo *fe, bool pass_thru_lut); |
| 84 |
void dff_rewrite(CellInfo *cell); |
| 85 |
void ddfr_rewrite(CellInfo *cell); |
| 86 |
|
| 87 |
void exchange_if_constant(CellInfo *cell, IdString input1, IdString input2); |
| 88 |
void pack_cy_input_and_output(CellInfo *cy, IdString cluster, IdString in_port, IdString out_port, int placer, |
| 89 |
int &lut_only, int &lut_and_ff, int &dff_only); |
| 90 |
|
| 91 |
void pack_xrf_input_and_output(CellInfo *cy, IdString cluster, IdString in_port, IdString out_port, |
| 92 |
ClusterPlacement placement, int &lut_only, int &lut_and_ff, int &dff_only); |
| 93 |
|
| 94 |
void connect_gnd_if_unconnected(CellInfo *cell, IdString input, bool warn); |
| 95 |
void disconnect_if_gnd(CellInfo *cell, IdString input); |
| 96 |
|
| 97 |
void insert_wfb(CellInfo *cell, IdString port); |
| 98 |
|
| 99 |
void mandatory_param(CellInfo *cell, IdString param); |
| 100 |
void disconnect_unused(CellInfo *cell, IdString port); |
| 101 |
void bind_attr_loc(CellInfo *cell, dict<IdString, Property> *attrs); |
| 102 |
BelId get_available_gck(int lobe, NetInfo *si1, NetInfo *si2); |
| 103 |
BelId getCSC(Loc l, int row); |
| 104 |
// General helper functions |
| 105 |
void flush_cells(); |
| 106 |
|
| 107 |
IdString assign_wfg(IdString ckg, IdString ckg2, CellInfo *cell); |
| 108 |
void dsp_same_driver(IdString port, CellInfo *cell, CellInfo **target); |
| 109 |
void dsp_same_sink(IdString port, CellInfo *cell, CellInfo **target); |
| 110 |
|
| 111 |
int make_init_with_const_input(int init, int input, bool value); |
| 112 |
|
| 113 |
int memory_width(int config, bool ecc); |
| 114 |
int memory_addr_bits(int config, bool ecc); |
| 115 |
|
| 116 |
void constrain_location(CellInfo *cell); |
| 117 |
void extract_lowskew_signals(CellInfo *cell, dict<IdString, dict<IdString, std::vector<PortRef>>> &lowskew_signals); |
| 118 |
// Cell creating |
| 119 |
CellInfo *create_cell_ptr(IdString type, IdString name); |
| 120 |
|
| 121 |
Context *ctx; |
| 122 |
NgUltraImpl *uarch; |
| 123 |
|
| 124 |
pool<IdString> packed_cells; |
| 125 |
pool<IdString> global_lowskew; |
| 126 |
|
| 127 |
HimbaechelHelpers h; |
| 128 |
}; |
| 129 |
|
| 130 |
NEXTPNR_NAMESPACE_END |
| 131 |
#endif |