| 1 |
/* |
| 2 |
* nextpnr -- Next Generation Place and Route |
| 3 |
* |
| 4 |
* Copyright (C) 2021-22 gatecat <[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 |
#ifndef VALIDITY_CHECKING_H |
| 20 |
#define VALIDITY_CHECKING_H |
| 21 |
|
| 22 |
#include "fab_cfg.h" |
| 23 |
#include "fab_defs.h" |
| 24 |
#include "sso_array.h" |
| 25 |
|
| 26 |
#include "nextpnr.h" |
| 27 |
|
| 28 |
NEXTPNR_NAMESPACE_BEGIN |
| 29 |
|
| 30 |
// The validity checking engine for the fabulous configurable CLB |
| 31 |
|
| 32 |
// data that we tag onto cells for fast lookup, so we aren't doing slow hash map accesses in the inner-loop-critical |
| 33 |
// validity checking code |
| 34 |
struct ControlSig |
| 35 |
{ |
| 36 |
ControlSig() : net(), invert(false) {}; |
| 37 |
ControlSig(IdString net, bool invert) : net(net), invert(invert) {}; |
| 38 |
IdString net; |
| 39 |
bool invert; |
| 40 |
bool operator==(const ControlSig &other) const { return net == other.net && invert == other.invert; } |
| 41 |
bool operator!=(const ControlSig &other) const { return net != other.net || invert != other.invert; } |
| 42 |
}; |
| 43 |
|
| 44 |
struct CellTags |
| 45 |
{ |
| 46 |
struct |
| 47 |
{ |
| 48 |
SSOArray<IdString, MAX_LUTK> lut_inputs; // for checking fracturable LUTs |
| 49 |
bool carry_used = false; |
| 50 |
const NetInfo *lut_out = nullptr; |
| 51 |
// ... |
| 52 |
} comb; // data for LUTs, or the LUT part of combined LUT+FF cells |
| 53 |
struct |
| 54 |
{ |
| 55 |
ControlSig clk, sr, en; |
| 56 |
bool ff_used = false; |
| 57 |
bool async = false; |
| 58 |
bool latch = false; |
| 59 |
const NetInfo *d = nullptr, *q = nullptr; |
| 60 |
} ff; // data for FFs, or the FF part of combined LUT+FF cells |
| 61 |
}; |
| 62 |
|
| 63 |
// map between cell and tags, using the flat_index that viaduct defines for this purpose |
| 64 |
struct CellTagger |
| 65 |
{ |
| 66 |
std::vector<CellTags> data; |
| 67 |
const CellTags &get(const CellInfo *ci) const { return data.at(ci->flat_index); } |
| 68 |
void assign_for(const Context *ctx, const FabricConfig &cfg, const CellInfo *ci); |
| 69 |
}; |
| 70 |
|
| 71 |
// we need to add some extra data to CLB bels to track what they do, so we can update CLBState accordingly |
| 72 |
struct BelFlags |
| 73 |
{ |
| 74 |
enum BlockType : uint8_t |
| 75 |
{ |
| 76 |
BLOCK_OTHER, |
| 77 |
BLOCK_CLB, |
| 78 |
// ... |
| 79 |
} block = BlockType::BLOCK_OTHER; |
| 80 |
enum FuncType : uint8_t |
| 81 |
{ |
| 82 |
FUNC_LC_COMB, |
| 83 |
FUNC_FF, |
| 84 |
FUNC_MUX, |
| 85 |
FUNC_OTHER, |
| 86 |
} func; |
| 87 |
uint8_t index; |
| 88 |
// ... |
| 89 |
}; |
| 90 |
|
| 91 |
// state of a CLB, for fast bel->cell lookup |
| 92 |
// TODO: add valid/dirty tracking for incremental validity re-checking, important once we have bigger/more complex CLBs |
| 93 |
// (cf. xilinx/intel arches in nextpnr) |
| 94 |
struct CLBState |
| 95 |
{ |
| 96 |
explicit CLBState(const LogicConfig &cfg); |
| 97 |
// In combined-LC mode (LC bel contains LUT and FF), this indexes the entire LC bel to cell. In separate mode, this |
| 98 |
// indexes the combinational part (LUT or LUT+carry only). |
| 99 |
std::unique_ptr<CellInfo *[]> lc_comb; |
| 100 |
// In split-LC mode only, this maps FF bel (in CLB) index to cell |
| 101 |
std::unique_ptr<CellInfo *[]> ff; |
| 102 |
// If there is (a) separate mux bel(s), map them to cells |
| 103 |
std::unique_ptr<CellInfo *[]> mux; |
| 104 |
bool check_validity(const LogicConfig &cfg, const CellTagger &cell_data); |
| 105 |
}; |
| 106 |
|
| 107 |
struct BlockTracker |
| 108 |
{ |
| 109 |
Context *ctx; |
| 110 |
const FabricConfig &cfg; |
| 111 |
std::vector<BelFlags> bel_data; |
| 112 |
|
| 113 |
BlockTracker(Context *ctx, const FabricConfig &cfg) : ctx(ctx), cfg(cfg) {}; |
| 114 |
void set_bel_type(BelId bel, BelFlags::BlockType block, BelFlags::FuncType func, uint8_t index); |
| 115 |
void update_bel(BelId bel, CellInfo *old_cell, CellInfo *new_cell); |
| 116 |
struct TileData |
| 117 |
{ |
| 118 |
std::unique_ptr<CLBState> clb; |
| 119 |
// ... |
| 120 |
}; |
| 121 |
std::vector<std::vector<TileData>> tiles; |
| 122 |
bool check_validity(BelId bel, const FabricConfig &cfg, const CellTagger &cell_data); |
| 123 |
}; |
| 124 |
|
| 125 |
struct PseudoPipTags |
| 126 |
{ |
| 127 |
BelId bel; |
| 128 |
enum PPType : uint16_t |
| 129 |
{ |
| 130 |
NONE, |
| 131 |
LUT_CONST, |
| 132 |
LUT_PERM, |
| 133 |
} type; |
| 134 |
uint16_t data; |
| 135 |
PseudoPipTags(PPType type = NONE, BelId bel = BelId(), uint16_t data = 0x0) : bel(bel), type(type), data(data) {} |
| 136 |
}; |
| 137 |
|
| 138 |
NEXTPNR_NAMESPACE_END |
| 139 |
|
| 140 |
#endif |