From 0d41fff3a70a298036aa6fdc103093631998a2bd Mon Sep 17 00:00:00 2001 From: Keith Rothman <537074+litghost@users.noreply.github.com> Date: Thu, 1 Apr 2021 13:18:07 -0700 Subject: [interchange] Add crude pseudo pip model. Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com> --- fpga_interchange/pseudo_pip_model.h | 147 ++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 fpga_interchange/pseudo_pip_model.h (limited to 'fpga_interchange/pseudo_pip_model.h') diff --git a/fpga_interchange/pseudo_pip_model.h b/fpga_interchange/pseudo_pip_model.h new file mode 100644 index 00000000..f0d93909 --- /dev/null +++ b/fpga_interchange/pseudo_pip_model.h @@ -0,0 +1,147 @@ +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2021 Symbiflow Authors + * + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifndef PSEUDO_PIP_MODEL_H +#define PSEUDO_PIP_MODEL_H + +#include + +#include "nextpnr_namespaces.h" +#include "nextpnr_types.h" +#include "site_router.h" +#include "dynamic_bitarray.h" +#include "hash_table.h" + +NEXTPNR_NAMESPACE_BEGIN + +struct PseudoPipBel { + // Which BEL in the tile does the pseudo pip use? + int32_t bel_index; + + // What is the index of the input BEL pin that the pseudo pip used? + // + // NOTE: This is **not** the name of the pin. + int32_t input_bel_pin; + + // What is the index of the output BEL pin that the pseudo pip used? + // + // NOTE: This is **not** the name of the pin. + int32_t output_bel_pin; +}; + +struct LogicBelKey { + int32_t tile_type; + int32_t pip_index; + int32_t site; + + std::tuple make_tuple() const { + return std::make_tuple(tile_type, pip_index, site); + } + + bool operator == (const LogicBelKey & other) const { + return make_tuple() == other.make_tuple(); + } + + bool operator < (const LogicBelKey & other) const { + return make_tuple() < other.make_tuple(); + } +}; + +NEXTPNR_NAMESPACE_END + +namespace std { +template <> struct hash +{ + std::size_t operator()(const NEXTPNR_NAMESPACE_PREFIX LogicBelKey &key) const noexcept + { + std::size_t seed = 0; + boost::hash_combine(seed, hash()(key.tile_type)); + boost::hash_combine(seed, hash()(key.pip_index)); + boost::hash_combine(seed, hash()(key.site)); + + return seed; + } +}; + +}; + + +NEXTPNR_NAMESPACE_BEGIN + +// Storage for tile type generic pseudo pip data and lookup. +struct PseudoPipData { + // Initial data for specified tile type, if not already initialized. + void init_tile_type(const Context *ctx, int32_t tile_type); + + // Get the highest PipId::index found in a specified tile type. + size_t get_max_pseudo_pip(int32_t tile_type) const; + + // Get the list of possible sites that a pseudo pip might be used in. + const std::vector &get_possible_sites_for_pip(const Context *ctx, PipId pip) const; + + // Get list of BELs the pseudo pip uses, and how it routes through them. + // + // This does **not** include site ports or site pips. + const std::vector &get_logic_bels_for_pip(const Context *ctx, int32_t site, PipId pip) const; + + HashTables::HashMap max_pseudo_pip_for_tile_type; + HashTables::HashMap, std::vector> possibles_sites_for_pip; + HashTables::HashMap> logic_bels_for_pip; +}; + +// Tile instance fast pseudo pip lookup. +struct PseudoPipModel { + int32_t tile; + DynamicBitarray<> allowed_pseudo_pips; + HashTables::HashMap pseudo_pip_sites; + HashTables::HashMap> site_to_pseudo_pips; + HashTables::HashSet active_pseudo_pips; + std::vector scratch; + + // Call when a tile is initialized. + void init(Context *ctx, int32_t tile); + + // Call after placement but before routing to update which pseudo pips are + // legal. This call is important to ensure that checkPipAvail returns the + // correct value. + // + // If the tile has no placed elements, then prepare_for_routing does not + // need to be called after init. + void prepare_for_routing(const Context *ctx, const std::vector & sites); + + // Returns true if the pseudo pip is allowed given current site placements + // and other pseudo pips. + bool checkPipAvail(const Context *ctx, PipId pip) const; + + // Enables a pseudo pip in the model. May cause other pseudo pips to + // become unavailable. + void bindPip(const Context *ctx, PipId pip); + + // Removes a pseudo pip from the model. May cause other pseudo pips to + // become available. + void unbindPip(const Context *ctx, PipId pip); + + // Internal method to update pseudo pips marked as part of a site. + void update_site(const Context *ctx, size_t site); +}; + +NEXTPNR_NAMESPACE_END + +#endif /* PSEUDO_PIP_MODEL_H */ -- cgit v1.2.3