diff options
-rw-r--r-- | CMakeLists.txt | 13 | ||||
-rw-r--r-- | README.md | 230 | ||||
-rw-r--r-- | common/nextpnr.cc | 2 | ||||
-rw-r--r-- | common/router1.cc | 2 | ||||
-rw-r--r-- | common/timing.cc | 4 | ||||
-rw-r--r-- | ecp5/arch.cc | 62 | ||||
-rw-r--r-- | ecp5/arch.h | 4 | ||||
-rw-r--r-- | ecp5/archdefs.h | 13 | ||||
-rw-r--r-- | ecp5/gfx.h | 35 | ||||
-rw-r--r-- | ecp5/main.cc | 10 | ||||
-rw-r--r-- | generic/arch.cc | 2 | ||||
-rw-r--r-- | generic/arch.h | 4 | ||||
-rw-r--r-- | gui/basewindow.cc | 1 | ||||
-rw-r--r-- | gui/designwidget.cc | 383 | ||||
-rw-r--r-- | gui/designwidget.h | 41 | ||||
-rw-r--r-- | gui/ecp5/mainwindow.cc | 2 | ||||
-rw-r--r-- | gui/generic/mainwindow.cc | 2 | ||||
-rw-r--r-- | gui/treemodel.cc | 346 | ||||
-rw-r--r-- | gui/treemodel.h | 94 | ||||
-rw-r--r-- | ice40/arch.cc | 64 | ||||
-rw-r--r-- | ice40/arch.h | 23 | ||||
-rw-r--r-- | ice40/benchmark/Makefile | 6 | ||||
-rw-r--r-- | ice40/benchmark/report.ipynb | 40 | ||||
-rw-r--r-- | ice40/chipdb.py | 131 | ||||
-rw-r--r-- | ice40/family.cmake | 25 | ||||
-rw-r--r-- | ice40/place_legaliser.cc | 42 | ||||
-rw-r--r-- | python/functions.py | 21 | ||||
-rw-r--r-- | python/python_mod_test.py | 7 | ||||
-rw-r--r-- | python/python_test.py | 2 |
29 files changed, 1099 insertions, 512 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index cc712e72..4c222d71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,9 +58,9 @@ if (BUILD_GUI AND NOT BUILD_PYTHON) message(FATAL_ERROR "GUI requires Python to build") endif() +find_package(PythonInterp 3.5 REQUIRED) if (BUILD_PYTHON) # TODO: sensible minimum Python version - find_package(PythonInterp 3.5 REQUIRED) find_package(PythonLibs 3.5 REQUIRED) else() add_definitions("-DNO_PYTHON") @@ -182,12 +182,7 @@ foreach (family ${ARCH}) add_executable(nextpnr-${family} ${COMMON_FILES} ${${ufamily}_FILES}) install(TARGETS nextpnr-${family} RUNTIME DESTINATION bin) target_compile_definitions(nextpnr-${family} PRIVATE MAIN_EXECUTABLE) - - if (BUILD_PYTHON) - # Add the importable Python module target - PYTHON_ADD_MODULE(nextpnrpy_${family} ${COMMON_FILES} ${${ufamily}_FILES}) - endif() - + # Add any new per-architecture targets here if (BUILD_TESTS) aux_source_directory(tests/${family}/ ${ufamily}_TEST_FILES) @@ -210,10 +205,6 @@ foreach (family ${ARCH}) set(family_targets ${family_targets} nextpnr-${family}-test) endif() - if (BUILD_PYTHON) - set(family_targets ${family_targets} nextpnrpy_${family}) - endif() - # Include the family-specific CMakeFile include(${family}/family.cmake) foreach (target ${family_targets}) @@ -1,87 +1,169 @@ nextpnr -- a portable FPGA place and route tool =============================================== -Supported Architectures ------------------------ +nextpnr is an FPGA place and route tool with emphasis on supporting +timing-driven place and route for a wide range of real-world FPGA devices. +It currently supports Lattice iCE40 devices and Lattice ECP5 devices, +as well as a "generic" back-end for user-defined architectures. +(ECP5 and "generic" support are still experimental.) -- iCE40 -- ECP5 +Currently nextpnr is beta software at best. But we aim at replacing +arachne-pnr as official place-and-route tool for the icestorm flow soon. -Prequisites ------------ - - - CMake 3.3 or later - - Modern C++11 compiler (`clang-format` required for development) - - Qt5 or later (`qt5-default` for Ubuntu 16.04) - - Python 3.5 or later, including development libraries (`python3-dev` for Ubuntu) - - on Windows make sure to install same version as supported by [vcpkg](https://github.com/Microsoft/vcpkg/blob/master/ports/python3/CONTROL) - - Boost libraries (`libboost-dev` or `libboost-all-dev` for Ubuntu) - - Icestorm, with chipdbs installed in `/usr/local/share/icebox` - - Latest git Yosys is required to synthesise the demo design - - For building on Windows with MSVC, usage of vcpkg is advised for dependency installation. - - For 32 bit builds: `vcpkg install boost-filesystem boost-program-options boost-thread boost-python qt5-base` - - For 64 bit builds: `vcpkg install boost-filesystem:x64-windows boost-program-options:x64-windows boost-thread:x64-windows boost-python:x64-windows qt5-base:x64-windows` - - For building on macOS, brew utility is needed. - - Install all needed packages `brew install cmake python boost boost-python3 qt5` - - Do not forget to add qt5 in path as well `echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.bash_profile` - - For ECP5 support, you must download [Project Trellis](https://github.com/SymbiFlow/prjtrellis), then follow its instructions to - download the latest database and build _libtrellis_. - +Here is a screenshot of nextpnr for iCE40. Build instructions and getting +started notes can be found below. + + +<img src="https://i.imgur.com/0spmlBa.png" width="640"/> + + +Prerequisites +------------- + +The following packages need to be installed for building nextpnr, independent +of the selected architecture: + +- CMake 3.3 or later +- Modern C++11 compiler (`clang-format` required for development) +- Qt5 or later (`qt5-default` for Ubuntu 16.04) +- Python 3.5 or later, including development libraries (`python3-dev` for Ubuntu) + - on Windows make sure to install same version as supported by [vcpkg](https://github.com/Microsoft/vcpkg/blob/master/ports/python3/CONTROL) +- Boost libraries (`libboost-dev` or `libboost-all-dev` for Ubuntu) +- Latest git Yosys is required to synthesise the demo design +- For building on Windows with MSVC, usage of vcpkg is advised for dependency installation. + - For 32 bit builds: `vcpkg install boost-filesystem boost-program-options boost-thread boost-python qt5-base` + - For 64 bit builds: `vcpkg install boost-filesystem:x64-windows boost-program-options:x64-windows boost-thread:x64-windows boost-python:x64-windows qt5-base:x64-windows` +- For building on macOS, brew utility is needed. + - Install all needed packages `brew install cmake python boost boost-python3 qt5` + - Do not forget to add qt5 in path as well `echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.bash_profile` + +Getting started +--------------- + +### nextpnr-ice40 + +To build the iCE40 version of nextpnr, install [icestorm](http://www.clifford.at/icestorm/) with chipdbs installed in `/usr/local/share/icebox`. +Then build and install `nextpnr-ice40` using the following commands: + +``` +cmake -DARCH=ice40 . +make -j$(nproc) +sudo make install +``` + +A simple example that runs on the iCEstick dev board can be found in `ice40/blinky.*`. +Usage example: + +``` +cd ice40 +yosys -p 'synth_ice40 -top blinky -json blinky.json' blinky.v # synthesize into blinky.json +nextpnr-ice40 --hx1k --json blinky.json --pcf blinky.pcf --asc blinky.asc # run place and route +icepack blinky.asc blinky.bin # generate binary bitstream file +iceprog blinky.bin # upload design to iCEstick +``` + +Running nextpnr in GUI mode: + +``` +nextpnr-ice40 --json blinky.json --pcf blinky.pcf --asc blinky.asc --gui +``` + +(Use the toolbar buttons or the Python command console to perform actions +such as pack, place, route, and write output files.) + +### nextpnr-ecp5 + +For ECP5 support, you must download [Project Trellis](https://github.com/SymbiFlow/prjtrellis), +then follow its instructions to download the latest database and build _libtrellis_. + +``` +cmake -DARCH=ecp5 . +make -j$(nproc) +sudo make install +``` + + - For an ECP5 blinky, first synthesise using `yosys blinky.ys` in `ecp5/synth`. + - Then run ECP5 place-and route using `./nextpnr-ecp5 --json ecp5/synth/blinky.json --basecfg ecp5/synth/ulx3s_empty.config --bit ecp5/synth/ulx3s.bit` + - Note that `ulx3s_empty.config` contains fixed/unknown bits to be copied to the output bitstream + - You can also use `--textcfg out.config` to write a text file describing the bitstream for debugging + + - More examples of the ECP5 flow for a range of boards can be found in the [Project Trellis Examples](https://github.com/SymbiFlow/prjtrellis/tree/master/examples). + + - Currently the ECP5 flow supports LUTs, flipflops and IO. IO must be instantiated using `TRELLIS_IO` primitives and constraints specified + using `LOC` and `IO_TYPE` attributes on those instances, as is used in the examples. + +### nextpnr-generic + +The generic target allows to run place and route for an arbitrary custom architecture. + +``` +cmake -DARCH=generic . +make -j$(nproc) +sudo make install +``` + +TBD: Getting started example for generic target. + +Additional notes for building nextpnr +------------------------------------- + +Use cmake `-D` options to specify which version of nextpnr you want to build. + +Use `-DARCH=...` to set the architecture. It is semicolon separated list. +Use `cmake . -DARCH=all` to build all supported architectures. + +The following runs a debug build of the iCE40 architecture without GUI +and without Python support and only HX1K support: + +``` +cmake -DARCH=ice40 -DCMAKE_BUILD_TYPE=Debug -DBUILD_PYTHON=OFF -DBUILD_GUI=OFF -DICE40_HX1K_ONLY=1 . +make -j$(nproc) +``` + +Notes for developers +-------------------- -Building --------- - - - Specifying target architecture is mandatory use ARCH parameter to set it. It is semicolon separated list. - - Use `cmake . -DARCH=all` to build all supported targets - - For example `cmake . -DARCH=ice40` would build just ICE40 support - - Use CMake to generate the Makefiles (only needs to be done when `CMakeLists.txt` changes) - - For an iCE40 debug build, run `cmake -DARCH=ice40 -DCMAKE_BUILD_TYPE=Debug .` - - For an iCE40 debug build with HX1K support only, run `cmake -DARCH=ice40 -DCMAKE_BUILD_TYPE=Debug -DICE40_HX1K_ONLY=1 .` - - For an iCE40 and ECP5 release build, run `cmake -DARCH="ice40;ecp5" .` - - Add `-DCMAKE_INSTALL_PREFIX=/your/install/prefix` to use a different install prefix to the default `/usr/local` - - For MSVC build with vcpkg use `-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake` using your vcpkg location - - For MSVC x64 build adding `-G"Visual Studio 14 2015 Win64"` is needed. - - For ECP5 support, you must also specify the path to Project Trellis using `-DTRELLIS_ROOT=/path/trellis` - - Use Make to run the build itself - - For all binary targets, just run `make` - - For just the iCE40 CLI&GUI binary, run `make nextpnr-ice40` - - To build binary without Python support, use `-DBUILD_PYTHON=OFF` - - To build binary without GUI, use `-DBUILD_GUI=OFF` - - For minimal binary without Python and GUI, use `-DBUILD_PYTHON=OFF -DBUILD_GUI=OFF` - - For just the iCE40 Python module, run `make nextpnrpy_ice40` - - Using too many parallel jobs may lead to out-of-memory issues due to the significant memory needed to build the chipdbs - - To install nextpnr, run `make install` +- All code is formatted using `clang-format` according to the style rules in `.clang-format` (LLVM based with + increased indent widths and brace wraps after classes). +- To automatically format all source code, run `make clangformat`. +- See the wiki for additional documentation on the architecture API. Testing ------- - - To build test binaries as well, use `-DBUILD_TESTS=OFF` and after run `make tests` to run them, or you can run separate binaries. - - To use code sanitizers use the `cmake` options: - - `-DSANITIZE_ADDRESS=ON` - - `-DSANITIZE_MEMORY=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++` - - `-DSANITIZE_THREAD=ON` - - `-DSANITIZE_UNDEFINED=ON` - - Running valgrind example `valgrind --leak-check=yes --tool=memcheck ./nextpnr-ice40 --json ice40/blinky.json` +- To build test binaries as well, use `-DBUILD_TESTS=ON` and after `make` run `make tests` to run them, or you can run separate binaries. +- To use code sanitizers use the `cmake` options: + - `-DSANITIZE_ADDRESS=ON` + - `-DSANITIZE_MEMORY=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++` + - `-DSANITIZE_THREAD=ON` + - `-DSANITIZE_UNDEFINED=ON` +- Running valgrind example `valgrind --leak-check=yes --tool=memcheck ./nextpnr-ice40 --json ice40/blinky.json` -Running --------- +Links and references +-------------------- - - To run the CLI binary, just run `./nextpnr-ice40` (you should see command line help) - - To start the UI, run `./nextpnr-ice40 --gui` - - The Python module is called `nextpnrpy_ice40.so`. To test it, run `PYTHONPATH=. python3 python/python_mod_test.py` - - Run `yosys blinky.ys` in `ice40/` to synthesise the blinky design and - produce `blinky.json`. - - To place-and-route the blinky using nextpnr, run `./nextpnr-ice40 --hx1k --json ice40/blinky.json --pcf ice40/blinky.pcf --asc blinky.asc` +### Synthesis, simulation, and logic optimization - - For an ECP5 blinky, first synthesise using `yosys blinky.ys` in `ecp5/synth`. - - Then run ECP5 place-and route using - `./nextpnr-ecp5 --json ecp5/synth/blinky.json --basecfg ecp5/synth/ulx3s_empty.config --bit ecp5/synth/ulx3s.bit` - - Note that `ulx3s_empty.config` contains fixed/unknown bits to be copied to the output bitstream - - You can also use `--textcfg out.config` to write a text file describing the bitstream for debugging - -Notes -------- - - - All code is formatted using `clang-format` according to the style rules in `.clang-format` (LLVM based with - increased indent widths and brace wraps after classes). - - To automatically format all source code, run `make clangformat`. +- [Yosys](http://www.clifford.at/yosys/) +- [Icarus Verilog](http://iverilog.icarus.com/) +- [ABC](https://people.eecs.berkeley.edu/~alanmi/abc/) + +### FPGA bitstream documentation (and tools) projects + +- [Project IceStorm (Lattice iCE40)](http://www.clifford.at/icestorm/) +- [Project Trellis (Lattice ECP5)](https://symbiflow.github.io/prjtrellis-db/) +- [Project X-Ray (Xilinx 7-Series)](https://symbiflow.github.io/prjxray-db/) +- [Project Chibi (Intel MAX-V)](https://github.com/rqou/project-chibi) + +### Other FOSS FPGA place and route projects + +- [Arachne PNR](https://github.com/cseed/arachne-pnr) +- [VPR/VTR](https://verilogtorouting.org/) +- [SymbiFlow](https://github.com/SymbiFlow/symbiflow-arch-defs) +- [Gaffe](https://github.com/kc8apf/gaffe) +- [KinglerPAR](https://github.com/rqou/KinglerPAR) + +> SymbiFlow is working with the Verilog to Routing tool to extend the current +research tool to support real architectures. VtR is strongly focused on +architecture research but having support for real architectures might enable +research nextpnr zu providing documentation and explanation. diff --git a/common/nextpnr.cc b/common/nextpnr.cc index 2c50c9a1..cf1b5982 100644 --- a/common/nextpnr.cc +++ b/common/nextpnr.cc @@ -91,6 +91,8 @@ WireId Context::getNetinfoSinkWire(NetInfo *net_info, int user_idx) const delay_t Context::getNetinfoRouteDelay(NetInfo *net_info, int user_idx) const { WireId src_wire = getNetinfoSourceWire(net_info); + if (src_wire == WireId()) + return 0; WireId cursor = getNetinfoSinkWire(net_info, user_idx); delay_t delay = 0; diff --git a/common/router1.cc b/common/router1.cc index e18f27fb..0bd257fd 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -217,7 +217,7 @@ struct Router next_qw.pip = pip; next_qw.delay = next_delay; next_qw.togo = ctx->estimateDelay(next_wire, dst_wire); - qw.randtag = ctx->rng(); + next_qw.randtag = ctx->rng(); visited[next_qw.wire] = next_qw; queue.push(next_qw); diff --git a/common/timing.cc b/common/timing.cc index c9e1cabd..b1a5619d 100644 --- a/common/timing.cc +++ b/common/timing.cc @@ -51,7 +51,7 @@ static delay_t follow_user_port(Context *ctx, PortRef &user, int path_length, de // Follow outputs of the user for (auto port : user.cell->ports) { if (port.second.type == PORT_OUT) { - delay_t comb_delay; + DelayInfo comb_delay; // Look up delay through this path bool is_path = ctx->getCellDelay(user.cell, user.port, port.first, comb_delay); if (is_path) { @@ -112,7 +112,7 @@ static delay_t walk_paths(Context *ctx, bool update, PortRefList *crit_path) delay_t slack = default_slack; // TODO: clock constraints delay_t clkToQ; if (ctx->getCellDelay(cell.second.get(), clock_domain, port.first, clkToQ)) - slack -= clkToQ; + slack -= clkToQ.maxDelay(); if (port.second.net) follow_net(ctx, port.second.net, 0, slack, update, min_slack, ¤t_path, crit_path); } diff --git a/ecp5/arch.cc b/ecp5/arch.cc index b070014e..36cefded 100644 --- a/ecp5/arch.cc +++ b/ecp5/arch.cc @@ -21,6 +21,7 @@ #include <algorithm> #include <cmath> #include <cstring> +#include "gfx.h" #include "log.h" #include "nextpnr.h" #include "placer1.h" @@ -140,9 +141,8 @@ Arch::Arch(ArchArgs args) : args(args) // ----------------------------------------------------------------------- -std::string Arch::getChipName() +std::string Arch::getChipName() const { - if (args.type == ArchArgs::LFE5U_25F) { return "LFE5U-25F"; } else if (args.type == ArchArgs::LFE5U_45F) { @@ -423,16 +423,64 @@ bool Arch::route() { return router1(getCtx()); } // ----------------------------------------------------------------------- -std::vector<GraphicElement> Arch::getDecalGraphics(DecalId decalId) const +std::vector<GraphicElement> Arch::getDecalGraphics(DecalId decal) const { std::vector<GraphicElement> ret; - // FIXME + + if (decal.type == DecalId::TYPE_FRAME) { + /* nothing */ + } + + if (decal.type == DecalId::TYPE_BEL) { + BelId bel; + bel.index = decal.z; + bel.location = decal.location; + int z = locInfo(bel)->bel_data[bel.index].z; + auto bel_type = getBelType(bel); + + if (bel_type == TYPE_TRELLIS_SLICE) { + GraphicElement el; + el.type = GraphicElement::TYPE_BOX; + el.style = decal.active ? GraphicElement::STYLE_ACTIVE : GraphicElement::STYLE_INACTIVE; + el.x1 = bel.location.x + logic_cell_x1; + el.x2 = bel.location.x + logic_cell_x2; + el.y1 = bel.location.y + logic_cell_y1 + (z)*logic_cell_pitch; + el.y2 = bel.location.y + logic_cell_y2 + (z)*logic_cell_pitch; + ret.push_back(el); + } + + if (bel_type == TYPE_TRELLIS_IO) { + GraphicElement el; + el.type = GraphicElement::TYPE_BOX; + el.style = decal.active ? GraphicElement::STYLE_ACTIVE : GraphicElement::STYLE_INACTIVE; + el.x1 = bel.location.x + logic_cell_x1; + el.x2 = bel.location.x + logic_cell_x2; + el.y1 = bel.location.y + logic_cell_y1 + (2 * z) * logic_cell_pitch; + el.y2 = bel.location.y + logic_cell_y2 + (2 * z + 1) * logic_cell_pitch; + ret.push_back(el); + } + } + return ret; } -DecalXY Arch::getFrameDecal() const { return {}; } +DecalXY Arch::getFrameDecal() const +{ + DecalXY decalxy; + decalxy.decal.type = DecalId::TYPE_FRAME; + decalxy.decal.active = true; + return decalxy; +} -DecalXY Arch::getBelDecal(BelId bel) const { return {}; } +DecalXY Arch::getBelDecal(BelId bel) const +{ + DecalXY decalxy; + decalxy.decal.type = DecalId::TYPE_BEL; + decalxy.decal.location = bel.location; + decalxy.decal.z = bel.index; + decalxy.decal.active = bel_to_cell.count(bel) && (bel_to_cell.at(bel) != IdString()); + return decalxy; +} DecalXY Arch::getWireDecal(WireId wire) const { return {}; } @@ -442,7 +490,7 @@ DecalXY Arch::getGroupDecal(GroupId pip) const { return {}; }; // ----------------------------------------------------------------------- -bool Arch::getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, delay_t &delay) const +bool Arch::getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, DelayInfo &delay) const { return false; } diff --git a/ecp5/arch.h b/ecp5/arch.h index 445f0dbf..df0df311 100644 --- a/ecp5/arch.h +++ b/ecp5/arch.h @@ -399,7 +399,7 @@ struct Arch : BaseCtx ArchArgs args; Arch(ArchArgs args); - std::string getChipName(); + std::string getChipName() const; IdString archId() const { return id("ecp5"); } IdString archArgsToId(ArchArgs args) const; @@ -802,7 +802,7 @@ struct Arch : BaseCtx // Get the delay through a cell from one port to another, returning false // if no path exists - bool getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, delay_t &delay) const; + bool getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, DelayInfo &delay) const; // Get the associated clock to a port, or empty if the port is combinational IdString getPortClock(const CellInfo *cell, IdString port) const; // Return true if a port is a clock diff --git a/ecp5/archdefs.h b/ecp5/archdefs.h index 40442e1b..829db683 100644 --- a/ecp5/archdefs.h +++ b/ecp5/archdefs.h @@ -120,17 +120,21 @@ struct GroupId struct DecalId { - char type = 0; // Bel/Wire/Pip/Frame (b/w/p/f) + enum + { + TYPE_FRAME, + TYPE_BEL + } type; Location location; uint32_t z = 0; - + bool active = false; bool operator==(const DecalId &other) const { - return type == other.type && location == other.location && z == other.z; + return type == other.type && location == other.location && z == other.z && active == other.active; } bool operator!=(const DecalId &other) const { - return type != other.type || location != other.location || z != other.z; + return type != other.type || location != other.location || z != other.z || active != other.active; } }; @@ -200,6 +204,7 @@ template <> struct hash<NEXTPNR_NAMESPACE_PREFIX DecalId> boost::hash_combine(seed, hash<int>()(decal.type)); boost::hash_combine(seed, hash<NEXTPNR_NAMESPACE_PREFIX Location>()(decal.location)); boost::hash_combine(seed, hash<int>()(decal.z)); + boost::hash_combine(seed, hash<bool>()(decal.active)); return seed; } }; diff --git a/ecp5/gfx.h b/ecp5/gfx.h new file mode 100644 index 00000000..0290d2f6 --- /dev/null +++ b/ecp5/gfx.h @@ -0,0 +1,35 @@ +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2018 David Shah <david@symbioticeda.com> + * + * 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 ECP5_GFX_H +#define ECP5_GFX_H + +#include "nextpnr.h" + +NEXTPNR_NAMESPACE_BEGIN + +const float logic_cell_x1 = 0.76; +const float logic_cell_x2 = 0.95; +const float logic_cell_y1 = 0.05; +const float logic_cell_y2 = 0.15; +const float logic_cell_pitch = 0.125; + +NEXTPNR_NAMESPACE_END + +#endif diff --git a/ecp5/main.cc b/ecp5/main.cc index 9f683a7b..68660ced 100644 --- a/ecp5/main.cc +++ b/ecp5/main.cc @@ -100,16 +100,18 @@ int main(int argc, char *argv[]) } if (vm.count("help") || argc == 1) { - std::cout << boost::filesystem::basename(argv[0]) << " -- Next Generation Place and Route (git " - "sha1 " GIT_COMMIT_HASH_STR ")\n"; + std::cout << boost::filesystem::basename(argv[0]) + << " -- Next Generation Place and Route (git " + "sha1 " GIT_COMMIT_HASH_STR ")\n"; std::cout << "\n"; std::cout << options << "\n"; return argc != 1; } if (vm.count("version")) { - std::cout << boost::filesystem::basename(argv[0]) << " -- Next Generation Place and Route (git " - "sha1 " GIT_COMMIT_HASH_STR ")\n"; + std::cout << boost::filesystem::basename(argv[0]) + << " -- Next Generation Place and Route (git " + "sha1 " GIT_COMMIT_HASH_STR ")\n"; return 1; } diff --git a/generic/arch.cc b/generic/arch.cc index ce6fe50a..daaa8118 100644 --- a/generic/arch.cc +++ b/generic/arch.cc @@ -427,7 +427,7 @@ DecalXY Arch::getGroupDecal(GroupId group) const { return groups.at(group).decal // --------------------------------------------------------------- -bool Arch::getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, delay_t &delay) const +bool Arch::getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, DelayInfo &delay) const { return false; } diff --git a/generic/arch.h b/generic/arch.h index b6892c85..de06f730 100644 --- a/generic/arch.h +++ b/generic/arch.h @@ -122,7 +122,7 @@ struct Arch : BaseCtx Arch(ArchArgs args); - std::string getChipName() { return chipName; } + std::string getChipName() const { return chipName; } IdString archId() const { return id("generic"); } IdString archArgsToId(ArchArgs args) const { return id("none"); } @@ -211,7 +211,7 @@ struct Arch : BaseCtx DecalXY getPipDecal(PipId pip) const; DecalXY getGroupDecal(GroupId group) const; - bool getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, delay_t &delay) const; + bool getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, DelayInfo &delay) const; IdString getPortClock(const CellInfo *cell, IdString port) const; bool isClockPort(const CellInfo *cell, IdString port) const; diff --git a/gui/basewindow.cc b/gui/basewindow.cc index 6e997011..6d5e97f5 100644 --- a/gui/basewindow.cc +++ b/gui/basewindow.cc @@ -86,6 +86,7 @@ BaseMainWindow::BaseMainWindow(std::unique_ptr<Context> context, QWidget *parent connect(fpgaView, SIGNAL(clickedBel(BelId, bool)), designview, SLOT(onClickedBel(BelId, bool)));
connect(fpgaView, SIGNAL(clickedWire(WireId, bool)), designview, SLOT(onClickedWire(WireId, bool)));
connect(fpgaView, SIGNAL(clickedPip(PipId, bool)), designview, SLOT(onClickedPip(PipId, bool)));
+ connect(designview, SIGNAL(zoomSelected()), fpgaView, SLOT(zoomSelected()));
connect(designview, SIGNAL(highlight(std::vector<DecalXY>, int)), fpgaView,
SLOT(onHighlightGroupChanged(std::vector<DecalXY>, int)));
diff --git a/gui/designwidget.cc b/gui/designwidget.cc index d55c84e9..e8c05ef9 100644 --- a/gui/designwidget.cc +++ b/gui/designwidget.cc @@ -30,48 +30,14 @@ NEXTPNR_NAMESPACE_BEGIN
-class ElementTreeItem : public QTreeWidgetItem
+DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), selectionModel(nullptr)
{
- public:
- ElementTreeItem(ElementType t, QString str, QTreeWidgetItem *parent)
- : QTreeWidgetItem(parent, QStringList(str)), type(t)
- {
- this->setFlags(this->flags() & ~Qt::ItemIsSelectable);
- }
- virtual ~ElementTreeItem(){};
-
- ElementType getType() { return type; };
-
- private:
- ElementType type;
-};
-
-class IdStringTreeItem : public ElementTreeItem
-{
- public:
- IdStringTreeItem(IdString d, ElementType t, QString str, QTreeWidgetItem *parent) : ElementTreeItem(t, str, parent)
- {
- this->setFlags(this->flags() | Qt::ItemIsSelectable);
- this->data = d;
- }
- virtual ~IdStringTreeItem(){};
-
- IdString getData() { return this->data; };
-
- private:
- IdString data;
-};
-
-DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), nets_root(nullptr), cells_root(nullptr)
-{
-
- treeWidget = new QTreeWidget();
-
// Add tree view
- treeWidget->setColumnCount(1);
- treeWidget->setHeaderLabel("Items");
- treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
- treeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ treeView = new QTreeView();
+ treeModel = new ContextTreeModel();
+ treeView->setModel(treeModel);
+ treeView->setContextMenuPolicy(Qt::CustomContextMenu);
+ treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
// Add property view
variantManager = new QtVariantPropertyManager(this);
@@ -85,10 +51,11 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net propertyEditor->treeWidget()->setContextMenuPolicy(Qt::CustomContextMenu);
propertyEditor->treeWidget()->setSelectionMode(QAbstractItemView::ExtendedSelection);
- QLineEdit *lineEdit = new QLineEdit();
- lineEdit->setClearButtonEnabled(true);
- lineEdit->addAction(QIcon(":/icons/resources/zoom.png"), QLineEdit::LeadingPosition);
- lineEdit->setPlaceholderText("Search...");
+ searchEdit = new QLineEdit();
+ searchEdit->setClearButtonEnabled(true);
+ searchEdit->addAction(QIcon(":/icons/resources/zoom.png"), QLineEdit::LeadingPosition);
+ searchEdit->setPlaceholderText("Search...");
+ connect(searchEdit, SIGNAL(returnPressed()), this, SLOT(onSearchInserted()));
actionFirst = new QAction("", this);
actionFirst->setIcon(QIcon(":/icons/resources/resultset_first.png"));
@@ -96,7 +63,7 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net connect(actionFirst, &QAction::triggered, this, [this] {
history_ignore = true;
history_index = 0;
- treeWidget->setCurrentItem(history.at(history_index));
+ selectionModel->setCurrentIndex(history.at(history_index), QItemSelectionModel::ClearAndSelect);
updateButtons();
});
@@ -106,7 +73,7 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net connect(actionPrev, &QAction::triggered, this, [this] {
history_ignore = true;
history_index--;
- treeWidget->setCurrentItem(history.at(history_index));
+ selectionModel->setCurrentIndex(history.at(history_index), QItemSelectionModel::ClearAndSelect);
updateButtons();
});
@@ -116,7 +83,7 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net connect(actionNext, &QAction::triggered, this, [this] {
history_ignore = true;
history_index++;
- treeWidget->setCurrentItem(history.at(history_index));
+ selectionModel->setCurrentIndex(history.at(history_index), QItemSelectionModel::ClearAndSelect);
updateButtons();
});
@@ -126,7 +93,7 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net connect(actionLast, &QAction::triggered, this, [this] {
history_ignore = true;
history_index = int(history.size() - 1);
- treeWidget->setCurrentItem(history.at(history_index));
+ selectionModel->setCurrentIndex(history.at(history_index), QItemSelectionModel::ClearAndSelect);
updateButtons();
});
@@ -136,11 +103,11 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net connect(actionClear, &QAction::triggered, this, [this] {
history_index = -1;
history.clear();
- QTreeWidgetItem *clickItem = treeWidget->selectedItems().at(0);
- if (clickItem->parent()) {
- ElementType type = static_cast<ElementTreeItem *>(clickItem)->getType();
+ QModelIndex index = selectionModel->selectedIndexes().at(0);
+ if (index.isValid()) {
+ ElementType type = treeModel->nodeFromIndex(index)->type();
if (type != ElementType::NONE)
- addToHistory(treeWidget->selectedItems().at(0));
+ addToHistory(index);
}
updateButtons();
});
@@ -157,8 +124,8 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net topWidget->setLayout(vbox1);
vbox1->setSpacing(5);
vbox1->setContentsMargins(0, 0, 0, 0);
- vbox1->addWidget(lineEdit);
- vbox1->addWidget(treeWidget);
+ vbox1->addWidget(searchEdit);
+ vbox1->addWidget(treeView);
QWidget *toolbarWidget = new QWidget();
QHBoxLayout *hbox = new QHBoxLayout;
@@ -192,8 +159,11 @@ DesignWidget::DesignWidget(QWidget *parent) : QWidget(parent), ctx(nullptr), net &DesignWidget::prepareMenuProperty);
connect(propertyEditor->treeWidget(), &QTreeWidget::itemDoubleClicked, this, &DesignWidget::onItemDoubleClicked);
- connect(treeWidget, SIGNAL(itemSelectionChanged()), SLOT(onItemSelectionChanged()));
- connect(treeWidget, &QTreeWidget::customContextMenuRequested, this, &DesignWidget::prepareMenuTree);
+ connect(treeView, &QTreeView::customContextMenuRequested, this, &DesignWidget::prepareMenuTree);
+ connect(treeView, &QTreeView::doubleClicked, this, &DesignWidget::onDoubleClicked);
+ selectionModel = treeView->selectionModel();
+ connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
+ SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &)));
history_index = -1;
history_ignore = false;
@@ -219,7 +189,7 @@ void DesignWidget::updateButtons() actionLast->setEnabled(history_index < (count - 1));
}
-void DesignWidget::addToHistory(QTreeWidgetItem *item)
+void DesignWidget::addToHistory(QModelIndex item)
{
if (!history_ignore) {
int count = int(history.size());
@@ -234,194 +204,38 @@ void DesignWidget::addToHistory(QTreeWidgetItem *item) void DesignWidget::newContext(Context *ctx)
{
+ if (!ctx)
+ return;
+
highlightSelected.clear();
- treeWidget->clear();
- // reset pointers since they are not valid after clear
- nets_root = nullptr;
- cells_root = nullptr;
history_ignore = false;
history_index = -1;
history.clear();
updateButtons();
- for (int i = 0; i < 6; i++)
- nameToItem[i].clear();
-
+ highlightSelected.clear();
this->ctx = ctx;
-
- // Add bels to tree
- QTreeWidgetItem *bel_root = new QTreeWidgetItem(treeWidget);
- QMap<QString, QTreeWidgetItem *> bel_items;
- bel_root->setText(0, "Bels");
- bel_root->setFlags(bel_root->flags() & ~Qt::ItemIsSelectable);
- treeWidget->insertTopLevelItem(0, bel_root);
- if (ctx) {
- for (auto bel : ctx->getBels()) {
- auto id = ctx->getBelName(bel);
- QStringList items = QString(id.c_str(ctx)).split("/");
- QString name;
- QTreeWidgetItem *parent = nullptr;
- for (int i = 0; i < items.size(); i++) {
- if (!name.isEmpty())
- name += "/";
- name += items.at(i);
- if (!bel_items.contains(name)) {
- if (i == items.size() - 1)
- nameToItem[0].insert(name, new IdStringTreeItem(id, ElementType::BEL, items.at(i), parent));
- else
- bel_items.insert(name, new ElementTreeItem(ElementType::NONE, items.at(i), parent));
- }
- parent = bel_items[name];
- }
- }
- }
- for (auto bel : bel_items.toStdMap()) {
- bel_root->addChild(bel.second);
- }
- for (auto bel : nameToItem[0].toStdMap()) {
- bel_root->addChild(bel.second);
- }
-
- // Add wires to tree
- QTreeWidgetItem *wire_root = new QTreeWidgetItem(treeWidget);
- QMap<QString, QTreeWidgetItem *> wire_items;
- wire_root->setText(0, "Wires");
- wire_root->setFlags(wire_root->flags() & ~Qt::ItemIsSelectable);
- treeWidget->insertTopLevelItem(0, wire_root);
- if (ctx) {
- for (auto wire : ctx->getWires()) {
- auto id = ctx->getWireName(wire);
- QStringList items = QString(id.c_str(ctx)).split("/");
- QString name;
- QTreeWidgetItem *parent = nullptr;
- for (int i = 0; i < items.size(); i++) {
- if (!name.isEmpty())
- name += "/";
- name += items.at(i);
- if (!wire_items.contains(name)) {
- if (i == items.size() - 1)
- nameToItem[1].insert(name, new IdStringTreeItem(id, ElementType::WIRE, items.at(i), parent));
- else
- wire_items.insert(name, new ElementTreeItem(ElementType::NONE, items.at(i), parent));
- }
- parent = wire_items[name];
- }
- }
- }
- for (auto wire : wire_items.toStdMap()) {
- wire_root->addChild(wire.second);
- }
- for (auto wire : nameToItem[1].toStdMap()) {
- wire_root->addChild(wire.second);
- }
- // Add pips to tree
- QTreeWidgetItem *pip_root = new QTreeWidgetItem(treeWidget);
- QMap<QString, QTreeWidgetItem *> pip_items;
- pip_root->setText(0, "Pips");
- pip_root->setFlags(pip_root->flags() & ~Qt::ItemIsSelectable);
- treeWidget->insertTopLevelItem(0, pip_root);
-#ifndef ARCH_ECP5
- if (ctx) {
- for (auto pip : ctx->getPips()) {
- auto id = ctx->getPipName(pip);
- QStringList items = QString(id.c_str(ctx)).split("/");
- QString name;
- QTreeWidgetItem *parent = nullptr;
- for (int i = 0; i < items.size(); i++) {
- if (!name.isEmpty())
- name += "/";
- name += items.at(i);
- if (!pip_items.contains(name)) {
- if (i == items.size() - 1)
- nameToItem[2].insert(name, new IdStringTreeItem(id, ElementType::PIP, items.at(i), parent));
- else
- pip_items.insert(name, new ElementTreeItem(ElementType::NONE, items.at(i), parent));
- }
- parent = pip_items[name];
- }
- }
- }
- for (auto pip : pip_items.toStdMap()) {
- pip_root->addChild(pip.second);
- }
- for (auto pip : nameToItem[2].toStdMap()) {
- pip_root->addChild(pip.second);
- }
-#endif
-
- nets_root = new QTreeWidgetItem(treeWidget);
- nets_root->setText(0, "Nets");
- nets_root->setFlags(nets_root->flags() & ~Qt::ItemIsSelectable);
- treeWidget->insertTopLevelItem(0, nets_root);
-
- cells_root = new QTreeWidgetItem(treeWidget);
- cells_root->setText(0, "Cells");
- cells_root->setFlags(cells_root->flags() & ~Qt::ItemIsSelectable);
- treeWidget->insertTopLevelItem(0, cells_root);
-
+ treeModel->loadData(ctx);
updateTree();
}
void DesignWidget::updateTree()
{
- if (!ctx)
- return;
-
clearProperties();
- // treeWidget->setSortingEnabled(false);
-
- // Remove nets not existing any more
- QMap<QString, QTreeWidgetItem *>::iterator i = nameToItem[3].begin();
- while (i != nameToItem[3].end()) {
- QMap<QString, QTreeWidgetItem *>::iterator prev = i;
+ QMap<ContextTreeItem *, int>::iterator i = highlightSelected.begin();
+ while (i != highlightSelected.end()) {
+ QMap<ContextTreeItem *, int>::iterator prev = i;
++i;
- if (ctx->nets.find(ctx->id(prev.key().toStdString())) == ctx->nets.end()) {
- if (treeWidget->currentItem() == prev.value())
- treeWidget->setCurrentItem(nets_root);
- if (highlightSelected.contains(prev.value()))
- highlightSelected.remove(prev.value());
- delete prev.value();
- nameToItem[3].erase(prev);
+ if (prev.key()->type() == ElementType::NET && ctx->nets.find(prev.key()->id()) == ctx->nets.end()) {
+ highlightSelected.erase(prev);
}
- }
- // Add nets to tree
- for (auto &item : ctx->nets) {
- auto id = item.first;
- QString name = QString(id.c_str(ctx));
- if (!nameToItem[3].contains(name)) {
- IdStringTreeItem *newItem = new IdStringTreeItem(id, ElementType::NET, name, nullptr);
- nets_root->addChild(newItem);
- nameToItem[3].insert(name, newItem);
+ if (prev.key()->type() == ElementType::CELL && ctx->cells.find(prev.key()->id()) == ctx->cells.end()) {
+ highlightSelected.erase(prev);
}
}
- // Remove cells not existing any more
- i = nameToItem[4].begin();
- while (i != nameToItem[4].end()) {
- QMap<QString, QTreeWidgetItem *>::iterator prev = i;
- ++i;
- if (ctx->cells.find(ctx->id(prev.key().toStdString())) == ctx->cells.end()) {
- if (treeWidget->currentItem() == prev.value())
- treeWidget->setCurrentItem(cells_root);
- if (highlightSelected.contains(prev.value()))
- highlightSelected.remove(prev.value());
- delete prev.value();
- nameToItem[4].erase(prev);
- }
- }
- // Add cells to tree
- for (auto &item : ctx->cells) {
- auto id = item.first;
- QString name = QString(id.c_str(ctx));
- if (!nameToItem[4].contains(name)) {
- IdStringTreeItem *newItem = new IdStringTreeItem(id, ElementType::CELL, name, nullptr);
- cells_root->addChild(newItem);
- nameToItem[4].insert(name, newItem);
- }
- }
- // treeWidget->sortByColumn(0, Qt::AscendingOrder);
- // treeWidget->setSortingEnabled(true);
+ treeModel->updateData(ctx);
}
QtProperty *DesignWidget::addTopLevelProperty(const QString &id)
{
@@ -460,21 +274,6 @@ QString DesignWidget::getElementTypeName(ElementType type) return "CELL";
return "";
}
-int DesignWidget::getElementIndex(ElementType type)
-{
- if (type == ElementType::BEL)
- return 0;
- if (type == ElementType::WIRE)
- return 1;
- if (type == ElementType::PIP)
- return 2;
- if (type == ElementType::NET)
- return 3;
- if (type == ElementType::CELL)
- return 4;
- return -1;
-}
-
ElementType DesignWidget::getElementTypeByName(QString type)
{
if (type == "BEL")
@@ -510,59 +309,58 @@ QtProperty *DesignWidget::addSubGroup(QtProperty *topItem, const QString &name) void DesignWidget::onClickedBel(BelId bel, bool keep)
{
- QTreeWidgetItem *item = nameToItem[getElementIndex(ElementType::BEL)].value(ctx->getBelName(bel).c_str(ctx));
- treeWidget->setCurrentItem(item);
+ ContextTreeItem *item = treeModel->nodeForIdType(ElementType::BEL, ctx->getBelName(bel).c_str(ctx));
+ selectionModel->setCurrentIndex(treeModel->indexFromNode(item),
+ keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
Q_EMIT selected(getDecals(ElementType::BEL, ctx->getBelName(bel)), keep);
}
void DesignWidget::onClickedWire(WireId wire, bool keep)
{
- QTreeWidgetItem *item = nameToItem[getElementIndex(ElementType::WIRE)].value(ctx->getWireName(wire).c_str(ctx));
- treeWidget->setCurrentItem(item);
+ ContextTreeItem *item = treeModel->nodeForIdType(ElementType::WIRE, ctx->getWireName(wire).c_str(ctx));
+ selectionModel->setCurrentIndex(treeModel->indexFromNode(item),
+ keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
Q_EMIT selected(getDecals(ElementType::WIRE, ctx->getWireName(wire)), keep);
}
void DesignWidget::onClickedPip(PipId pip, bool keep)
{
- QTreeWidgetItem *item = nameToItem[getElementIndex(ElementType::PIP)].value(ctx->getPipName(pip).c_str(ctx));
- treeWidget->setCurrentItem(item);
+ ContextTreeItem *item = treeModel->nodeForIdType(ElementType::PIP, ctx->getPipName(pip).c_str(ctx));
+ selectionModel->setCurrentIndex(treeModel->indexFromNode(item),
+ keep ? QItemSelectionModel::Select : QItemSelectionModel::ClearAndSelect);
Q_EMIT selected(getDecals(ElementType::PIP, ctx->getPipName(pip)), keep);
}
-void DesignWidget::onItemSelectionChanged()
+void DesignWidget::onSelectionChanged(const QItemSelection &, const QItemSelection &)
{
- if (treeWidget->selectedItems().size() == 0)
+ if (selectionModel->selectedIndexes().size() == 0)
return;
- if (treeWidget->selectedItems().size() > 1) {
+ if (selectionModel->selectedIndexes().size() > 1) {
std::vector<DecalXY> decals;
- for (auto clickItem : treeWidget->selectedItems()) {
- IdString value = static_cast<IdStringTreeItem *>(clickItem)->getData();
- ElementType type = static_cast<ElementTreeItem *>(clickItem)->getType();
- std::vector<DecalXY> d = getDecals(type, value);
+ for (auto index : selectionModel->selectedIndexes()) {
+ ContextTreeItem *item = treeModel->nodeFromIndex(index);
+ std::vector<DecalXY> d = getDecals(item->type(), item->id());
std::move(d.begin(), d.end(), std::back_inserter(decals));
}
Q_EMIT selected(decals, false);
return;
}
-
- QTreeWidgetItem *clickItem = treeWidget->selectedItems().at(0);
-
- if (!clickItem->parent())
+ QModelIndex index = selectionModel->selectedIndexes().at(0);
+ if (!index.isValid())
return;
+ ContextTreeItem *clickItem = treeModel->nodeFromIndex(index);
- ElementType type = static_cast<ElementTreeItem *>(clickItem)->getType();
- if (type == ElementType::NONE) {
+ ElementType type = clickItem->type();
+ if (type == ElementType::NONE)
return;
- }
-
std::vector<DecalXY> decals;
- addToHistory(clickItem);
+ addToHistory(index);
clearProperties();
- IdString c = static_cast<IdStringTreeItem *>(clickItem)->getData();
+ IdString c = clickItem->id();
Q_EMIT selected(getDecals(type, c), false);
if (type == ElementType::BEL) {
@@ -799,7 +597,7 @@ std::vector<DecalXY> DesignWidget::getDecals(ElementType type, IdString value) return decals;
}
-void DesignWidget::updateHighlightGroup(QList<QTreeWidgetItem *> items, int group)
+void DesignWidget::updateHighlightGroup(QList<ContextTreeItem *> items, int group)
{
const bool shouldClear = items.size() == 1;
for (auto item : items) {
@@ -814,9 +612,7 @@ void DesignWidget::updateHighlightGroup(QList<QTreeWidgetItem *> items, int grou std::vector<DecalXY> decals[8];
for (auto it : highlightSelected.toStdMap()) {
- ElementType type = static_cast<ElementTreeItem *>(it.first)->getType();
- IdString value = static_cast<IdStringTreeItem *>(it.first)->getData();
- std::vector<DecalXY> d = getDecals(type, value);
+ std::vector<DecalXY> d = getDecals(it.first->type(), it.first->id());
std::move(d.begin(), d.end(), std::back_inserter(decals[it.second]));
}
for (int i = 0; i < 8; i++)
@@ -826,7 +622,7 @@ void DesignWidget::updateHighlightGroup(QList<QTreeWidgetItem *> items, int grou void DesignWidget::prepareMenuProperty(const QPoint &pos)
{
QTreeWidget *tree = propertyEditor->treeWidget();
- QList<QTreeWidgetItem *> items;
+ QList<ContextTreeItem *> items;
for (auto itemContextMenu : tree->selectedItems()) {
QtBrowserItem *browserItem = propertyEditor->itemToBrowserItem(itemContextMenu);
if (!browserItem)
@@ -836,11 +632,11 @@ void DesignWidget::prepareMenuProperty(const QPoint &pos) if (type == ElementType::NONE)
continue;
IdString value = ctx->id(selectedProperty->valueText().toStdString());
- items.append(nameToItem[getElementIndex(type)].value(value.c_str(ctx)));
+ items.append(treeModel->nodeForIdType(type, value.c_str(ctx)));
}
int selectedIndex = -1;
if (items.size() == 1) {
- QTreeWidgetItem *item = items.at(0);
+ ContextTreeItem *item = items.at(0);
if (highlightSelected.contains(item))
selectedIndex = highlightSelected[item];
}
@@ -850,9 +646,7 @@ void DesignWidget::prepareMenuProperty(const QPoint &pos) connect(selectAction, &QAction::triggered, this, [this, items] {
std::vector<DecalXY> decals;
for (auto clickItem : items) {
- IdString value = static_cast<IdStringTreeItem *>(clickItem)->getData();
- ElementType type = static_cast<ElementTreeItem *>(clickItem)->getType();
- std::vector<DecalXY> d = getDecals(type, value);
+ std::vector<DecalXY> d = getDecals(clickItem->type(), clickItem->id());
std::move(d.begin(), d.end(), std::back_inserter(decals));
}
Q_EMIT selected(decals, false);
@@ -878,12 +672,18 @@ void DesignWidget::prepareMenuProperty(const QPoint &pos) void DesignWidget::prepareMenuTree(const QPoint &pos)
{
- if (treeWidget->selectedItems().size() == 0)
- return;
int selectedIndex = -1;
- QList<QTreeWidgetItem *> items = treeWidget->selectedItems();
- if (treeWidget->selectedItems().size() == 1) {
- QTreeWidgetItem *item = treeWidget->selectedItems().at(0);
+
+ if (selectionModel->selectedIndexes().size() == 0)
+ return;
+
+ QList<ContextTreeItem *> items;
+ for (auto index : selectionModel->selectedIndexes()) {
+ ContextTreeItem *item = treeModel->nodeFromIndex(index);
+ items.append(item);
+ }
+ if (items.size() == 1) {
+ ContextTreeItem *item = items.at(0);
if (highlightSelected.contains(item))
selectedIndex = highlightSelected[item];
}
@@ -902,17 +702,32 @@ void DesignWidget::prepareMenuTree(const QPoint &pos) action->setChecked(true);
connect(action, &QAction::triggered, this, [this, i, items] { updateHighlightGroup(items, i); });
}
- menu.exec(treeWidget->mapToGlobal(pos));
+ menu.exec(treeView->mapToGlobal(pos));
}
void DesignWidget::onItemDoubleClicked(QTreeWidgetItem *item, int column)
{
QtProperty *selectedProperty = propertyEditor->itemToBrowserItem(item)->property();
ElementType type = getElementTypeByName(selectedProperty->propertyId());
- QString value = selectedProperty->valueText();
- int index = getElementIndex(type);
- if (type != ElementType::NONE && nameToItem[index].contains(value))
- treeWidget->setCurrentItem(nameToItem[index].value(value));
+ ContextTreeItem *it = treeModel->nodeForIdType(type, selectedProperty->valueText());
+ if (it)
+ selectionModel->setCurrentIndex(treeModel->indexFromNode(it), QItemSelectionModel::ClearAndSelect);
}
+void DesignWidget::onDoubleClicked(const QModelIndex &index) { Q_EMIT zoomSelected(); }
+
+void DesignWidget::onSearchInserted()
+{
+ if (currentSearch == searchEdit->text()) {
+ currentIndex++;
+ if (currentIndex >= currentSearchIndexes.size())
+ currentIndex = 0;
+ } else {
+ currentSearch = searchEdit->text();
+ currentSearchIndexes = treeModel->search(searchEdit->text());
+ currentIndex = 0;
+ }
+ if (currentSearchIndexes.size() > 0 && currentIndex < currentSearchIndexes.size())
+ selectionModel->setCurrentIndex(currentSearchIndexes.at(currentIndex), QItemSelectionModel::ClearAndSelect);
+}
NEXTPNR_NAMESPACE_END
diff --git a/gui/designwidget.h b/gui/designwidget.h index 60291cf3..535fd0c3 100644 --- a/gui/designwidget.h +++ b/gui/designwidget.h @@ -20,27 +20,17 @@ #ifndef DESIGNWIDGET_H
#define DESIGNWIDGET_H
-#include <QTreeWidget>
+#include <QTreeView>
#include <QVariant>
#include "nextpnr.h"
#include "qtgroupboxpropertybrowser.h"
#include "qtpropertymanager.h"
#include "qttreepropertybrowser.h"
#include "qtvariantproperty.h"
+#include "treemodel.h"
NEXTPNR_NAMESPACE_BEGIN
-enum class ElementType
-{
- NONE,
- BEL,
- WIRE,
- PIP,
- NET,
- CELL,
- GROUP
-};
-
class DesignWidget : public QWidget
{
Q_OBJECT
@@ -59,19 +49,22 @@ class DesignWidget : public QWidget ElementType getElementTypeByName(QString type);
int getElementIndex(ElementType type);
void updateButtons();
- void addToHistory(QTreeWidgetItem *item);
+ void addToHistory(QModelIndex item);
std::vector<DecalXY> getDecals(ElementType type, IdString value);
- void updateHighlightGroup(QList<QTreeWidgetItem *> item, int group);
+ void updateHighlightGroup(QList<ContextTreeItem *> item, int group);
Q_SIGNALS:
void info(std::string text);
void selected(std::vector<DecalXY> decal, bool keep);
void highlight(std::vector<DecalXY> decal, int group);
+ void zoomSelected();
private Q_SLOTS:
void prepareMenuProperty(const QPoint &pos);
void prepareMenuTree(const QPoint &pos);
- void onItemSelectionChanged();
+ void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void onItemDoubleClicked(QTreeWidgetItem *item, int column);
+ void onDoubleClicked(const QModelIndex &index);
+ void onSearchInserted();
public Q_SLOTS:
void newContext(Context *ctx);
void updateTree();
@@ -82,8 +75,10 @@ class DesignWidget : public QWidget private:
Context *ctx;
- QTreeWidget *treeWidget;
-
+ QTreeView *treeView;
+ QItemSelectionModel *selectionModel;
+ ContextTreeModel *treeModel;
+ QLineEdit *searchEdit;
QtVariantPropertyManager *variantManager;
QtVariantPropertyManager *readOnlyManager;
QtGroupPropertyManager *groupManager;
@@ -93,14 +88,10 @@ class DesignWidget : public QWidget QMap<QtProperty *, QString> propertyToId;
QMap<QString, QtProperty *> idToProperty;
- QMap<QString, QTreeWidgetItem *> nameToItem[6];
- std::vector<QTreeWidgetItem *> history;
+ std::vector<QModelIndex> history;
int history_index;
bool history_ignore;
- QTreeWidgetItem *nets_root;
- QTreeWidgetItem *cells_root;
-
QAction *actionFirst;
QAction *actionPrev;
QAction *actionNext;
@@ -108,7 +99,11 @@ class DesignWidget : public QWidget QAction *actionClear;
QColor highlightColors[8];
- QMap<QTreeWidgetItem *, int> highlightSelected;
+ QMap<ContextTreeItem *, int> highlightSelected;
+
+ QString currentSearch;
+ QList<QModelIndex> currentSearchIndexes;
+ int currentIndex;
};
NEXTPNR_NAMESPACE_END
diff --git a/gui/ecp5/mainwindow.cc b/gui/ecp5/mainwindow.cc index 1168a55c..4b1c7e3b 100644 --- a/gui/ecp5/mainwindow.cc +++ b/gui/ecp5/mainwindow.cc @@ -40,6 +40,8 @@ void MainWindow::createMenu() {
QMenu *menu_Custom = new QMenu("&Generic", menuBar);
menuBar->addAction(menu_Custom->menuAction());
+
+ createGraphicsBar();
}
void MainWindow::new_proj() {}
diff --git a/gui/generic/mainwindow.cc b/gui/generic/mainwindow.cc index 88e291e6..1efc73bb 100644 --- a/gui/generic/mainwindow.cc +++ b/gui/generic/mainwindow.cc @@ -40,6 +40,8 @@ void MainWindow::createMenu() {
QMenu *menu_Custom = new QMenu("&Generic", menuBar);
menuBar->addAction(menu_Custom->menuAction());
+
+ createGraphicsBar();
}
void MainWindow::new_proj() {}
diff --git a/gui/treemodel.cc b/gui/treemodel.cc new file mode 100644 index 00000000..d42dc401 --- /dev/null +++ b/gui/treemodel.cc @@ -0,0 +1,346 @@ +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2018 Miodrag Milanovic <miodrag@symbioticeda.com> + * + * 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. + * + */ + +#include "treemodel.h" + +NEXTPNR_NAMESPACE_BEGIN + +static bool contextTreeItemLessThan(const ContextTreeItem *v1, const ContextTreeItem *v2) + { + return v1->name() < v2->name(); + } + +ContextTreeItem::ContextTreeItem() { parentNode = nullptr; } + +ContextTreeItem::ContextTreeItem(QString name) + : parentNode(nullptr), itemId(IdString()), itemType(ElementType::NONE), itemName(name) +{ +} + +ContextTreeItem::ContextTreeItem(IdString id, ElementType type, QString name) + : parentNode(nullptr), itemId(id), itemType(type), itemName(name) +{ +} + +ContextTreeItem::~ContextTreeItem() +{ + if (parentNode) + parentNode->children.removeOne(this); + qDeleteAll(children); +} +void ContextTreeItem::addChild(ContextTreeItem *item) +{ + item->parentNode = this; + children.append(item); +} + +void ContextTreeItem::sort() +{ + for (auto item : children) + if (item->count()>1) item->sort(); + qSort(children.begin(), children.end(), contextTreeItemLessThan); +} + +ContextTreeModel::ContextTreeModel(QObject *parent) : QAbstractItemModel(parent) { root = new ContextTreeItem(); } + +ContextTreeModel::~ContextTreeModel() { delete root; } + +void ContextTreeModel::loadData(Context *ctx) +{ + if (!ctx) + return; + + beginResetModel(); + + delete root; + root = new ContextTreeItem(); + + for (int i = 0; i < 6; i++) + nameToItem[i].clear(); + + IdString none; + + ContextTreeItem *bels_root = new ContextTreeItem("Bels"); + root->addChild(bels_root); + QMap<QString, ContextTreeItem *> bel_items; + + // Add bels to tree + for (auto bel : ctx->getBels()) { + IdString id = ctx->getBelName(bel); + QStringList items = QString(id.c_str(ctx)).split("/"); + QString name; + ContextTreeItem *parent = bels_root; + for (int i = 0; i < items.size(); i++) { + if (!name.isEmpty()) + name += "/"; + name += items.at(i); + if (!bel_items.contains(name)) { + if (i == items.size() - 1) { + ContextTreeItem *item = new ContextTreeItem(id, ElementType::BEL, items.at(i)); + parent->addChild(item); + nameToItem[0].insert(name, item); + } else { + ContextTreeItem *item = new ContextTreeItem(none, ElementType::NONE, items.at(i)); + parent->addChild(item); + bel_items.insert(name, item); + } + } + parent = bel_items[name]; + } + } + bels_root->sort(); + + ContextTreeItem *wire_root = new ContextTreeItem("Wires"); + root->addChild(wire_root); + QMap<QString, ContextTreeItem *> wire_items; + + // Add wires to tree + for (auto wire : ctx->getWires()) { + auto id = ctx->getWireName(wire); + QStringList items = QString(id.c_str(ctx)).split("/"); + QString name; + ContextTreeItem *parent = wire_root; + for (int i = 0; i < items.size(); i++) { + if (!name.isEmpty()) + name += "/"; + name += items.at(i); + if (!wire_items.contains(name)) { + if (i == items.size() - 1) { + ContextTreeItem *item = new ContextTreeItem(id, ElementType::WIRE, items.at(i)); + parent->addChild(item); + nameToItem[1].insert(name, item); + } else { + ContextTreeItem *item = new ContextTreeItem(none, ElementType::NONE, items.at(i)); + parent->addChild(item); + wire_items.insert(name, item); + } + } + parent = wire_items[name]; + } + } + wire_root->sort(); + + ContextTreeItem *pip_root = new ContextTreeItem("Pips"); + root->addChild(pip_root); + QMap<QString, ContextTreeItem *> pip_items; + + // Add pips to tree +#ifndef ARCH_ECP5 + for (auto pip : ctx->getPips()) { + auto id = ctx->getPipName(pip); + QStringList items = QString(id.c_str(ctx)).split("/"); + QString name; + ContextTreeItem *parent = pip_root; + for (int i = 0; i < items.size(); i++) { + if (!name.isEmpty()) + name += "/"; + name += items.at(i); + if (!pip_items.contains(name)) { + if (i == items.size() - 1) { + ContextTreeItem *item = new ContextTreeItem(id, ElementType::PIP, items.at(i)); + parent->addChild(item); + nameToItem[2].insert(name, item); + } else { + ContextTreeItem *item = new ContextTreeItem(none, ElementType::NONE, items.at(i)); + parent->addChild(item); + pip_items.insert(name, item); + } + } + parent = pip_items[name]; + } + } +#endif + pip_root->sort(); + + nets_root = new ContextTreeItem("Nets"); + root->addChild(nets_root); + + cells_root = new ContextTreeItem("Cells"); + root->addChild(cells_root); + + endResetModel(); +} + +void ContextTreeModel::updateData(Context *ctx) +{ + if (!ctx) + return; + + beginResetModel(); + + //QModelIndex nets_index = indexFromNode(nets_root); + // Remove nets not existing any more + QMap<QString, ContextTreeItem *>::iterator i = nameToItem[3].begin(); + while (i != nameToItem[3].end()) { + QMap<QString, ContextTreeItem *>::iterator prev = i; + ++i; + if (ctx->nets.find(ctx->id(prev.key().toStdString())) == ctx->nets.end()) { + //int pos = prev.value()->parent()->indexOf(prev.value()); + //beginRemoveRows(nets_index, pos, pos); + delete prev.value(); + nameToItem[3].erase(prev); + //endRemoveRows(); + } + } + // Add nets to tree + for (auto &item : ctx->nets) { + auto id = item.first; + QString name = QString(id.c_str(ctx)); + if (!nameToItem[3].contains(name)) { + //beginInsertRows(nets_index, nets_root->count() + 1, nets_root->count() + 1); + ContextTreeItem *newItem = new ContextTreeItem(id, ElementType::NET, name); + nets_root->addChild(newItem); + nameToItem[3].insert(name, newItem); + //endInsertRows(); + } + } + + nets_root->sort(); + + //QModelIndex cell_index = indexFromNode(cells_root); + // Remove cells not existing any more + i = nameToItem[4].begin(); + while (i != nameToItem[4].end()) { + QMap<QString, ContextTreeItem *>::iterator prev = i; + ++i; + if (ctx->cells.find(ctx->id(prev.key().toStdString())) == ctx->cells.end()) { + //int pos = prev.value()->parent()->indexOf(prev.value()); + //beginRemoveRows(cell_index, pos, pos); + delete prev.value(); + nameToItem[4].erase(prev); + //endRemoveRows(); + } + } + // Add cells to tree + for (auto &item : ctx->cells) { + auto id = item.first; + QString name = QString(id.c_str(ctx)); + if (!nameToItem[4].contains(name)) { + //beginInsertRows(cell_index, cells_root->count() + 1, cells_root->count() + 1); + ContextTreeItem *newItem = new ContextTreeItem(id, ElementType::CELL, name); + cells_root->addChild(newItem); + nameToItem[4].insert(name, newItem); + //endInsertRows(); + } + } + + cells_root->sort(); + + endResetModel(); +} + +int ContextTreeModel::rowCount(const QModelIndex &parent) const { return nodeFromIndex(parent)->count(); } + +int ContextTreeModel::columnCount(const QModelIndex &parent) const { return 1; } + +QModelIndex ContextTreeModel::index(int row, int column, const QModelIndex &parent) const +{ + ContextTreeItem *node = nodeFromIndex(parent); + if (row >= node->count()) + return QModelIndex(); + return createIndex(row, column, node->at(row)); +} + +QModelIndex ContextTreeModel::parent(const QModelIndex &child) const +{ + ContextTreeItem *parent = nodeFromIndex(child)->parent(); + if (parent == root) + return QModelIndex(); + ContextTreeItem *node = parent->parent(); + return createIndex(node->indexOf(parent), 0, parent); +} + +QVariant ContextTreeModel::data(const QModelIndex &index, int role) const +{ + if (index.column() != 0) + return QVariant(); + if (role != Qt::DisplayRole) + return QVariant(); + ContextTreeItem *node = nodeFromIndex(index); + return node->name(); +} + +QVariant ContextTreeModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + Q_UNUSED(section); + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return QString("Items"); + + return QVariant(); +} + +ContextTreeItem *ContextTreeModel::nodeFromIndex(const QModelIndex &idx) const +{ + if (idx.isValid()) + return (ContextTreeItem *)idx.internalPointer(); + return root; +} + +static int getElementIndex(ElementType type) +{ + if (type == ElementType::BEL) + return 0; + if (type == ElementType::WIRE) + return 1; + if (type == ElementType::PIP) + return 2; + if (type == ElementType::NET) + return 3; + if (type == ElementType::CELL) + return 4; + return -1; +} + +ContextTreeItem *ContextTreeModel::nodeForIdType(const ElementType type, const QString name) const +{ + int index = getElementIndex(type); + if (type != ElementType::NONE && nameToItem[index].contains(name)) + return nameToItem[index].value(name); + return nullptr; +} + +QModelIndex ContextTreeModel::indexFromNode(ContextTreeItem *node) +{ + ContextTreeItem *parent = node->parent(); + if (parent == root) + return QModelIndex(); + return createIndex(parent->indexOf(node), 0, node); +} + +Qt::ItemFlags ContextTreeModel::flags(const QModelIndex &index) const +{ + ContextTreeItem *node = nodeFromIndex(index); + return Qt::ItemIsEnabled | (node->type() != ElementType::NONE ? Qt::ItemIsSelectable : Qt::NoItemFlags); +} + +QList<QModelIndex> ContextTreeModel::search(QString text) +{ + QList<QModelIndex> list; + for (int i = 0; i < 6; i++) { + for (auto key : nameToItem[i].keys()) { + if (key.contains(text, Qt::CaseInsensitive)) { + list.append(indexFromNode(nameToItem[i].value(key))); + if (list.count() > 500) + break; // limit to 500 results + } + } + } + return list; +} +NEXTPNR_NAMESPACE_END diff --git a/gui/treemodel.h b/gui/treemodel.h new file mode 100644 index 00000000..c14efa90 --- /dev/null +++ b/gui/treemodel.h @@ -0,0 +1,94 @@ +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2018 Miodrag Milanovic <miodrag@symbioticeda.com> + * + * 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 TREEMODEL_H +#define TREEMODEL_H + +#include <QAbstractItemModel> +#include "nextpnr.h" + +NEXTPNR_NAMESPACE_BEGIN + +enum class ElementType +{ + NONE, + BEL, + WIRE, + PIP, + NET, + CELL, + GROUP +}; + +class ContextTreeItem +{ + public: + ContextTreeItem(); + ContextTreeItem(QString name); + ContextTreeItem(IdString id, ElementType type, QString name); + ~ContextTreeItem(); + + void addChild(ContextTreeItem *item); + int indexOf(ContextTreeItem *n) const { return children.indexOf(n); } + ContextTreeItem *at(int idx) const { return children.at(idx); } + int count() const { return children.count(); } + ContextTreeItem *parent() const { return parentNode; } + IdString id() const { return itemId; } + ElementType type() const { return itemType; } + QString name() const { return itemName; } + void sort(); + private: + ContextTreeItem *parentNode; + QList<ContextTreeItem *> children; + IdString itemId; + ElementType itemType; + QString itemName; +}; + +class ContextTreeModel : public QAbstractItemModel +{ + public: + ContextTreeModel(QObject *parent = nullptr); + ~ContextTreeModel(); + + void loadData(Context *ctx); + void updateData(Context *ctx); + ContextTreeItem *nodeFromIndex(const QModelIndex &idx) const; + QModelIndex indexFromNode(ContextTreeItem *node); + ContextTreeItem *nodeForIdType(const ElementType type, const QString name) const; + QList<QModelIndex> search(QString text); + // Override QAbstractItemModel methods + int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; + QModelIndex parent(const QModelIndex &child) const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + QVariant headerData(int section, Qt::Orientation orientation, int role) const Q_DECL_OVERRIDE; + Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; + + private: + ContextTreeItem *root; + QMap<QString, ContextTreeItem *> nameToItem[6]; + ContextTreeItem *nets_root; + ContextTreeItem *cells_root; +}; + +NEXTPNR_NAMESPACE_END + +#endif // TREEMODEL_H diff --git a/ice40/arch.cc b/ice40/arch.cc index 2ca8b665..e15abdd1 100644 --- a/ice40/arch.cc +++ b/ice40/arch.cc @@ -141,18 +141,23 @@ Arch::Arch(ArchArgs args) : args(args) #ifdef ICE40_HX1K_ONLY if (args.type == ArchArgs::HX1K) { + fast_part = true; chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_1k)); } else { log_error("Unsupported iCE40 chip type.\n"); } #else if (args.type == ArchArgs::LP384) { + fast_part = false; chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_384)); } else if (args.type == ArchArgs::LP1K || args.type == ArchArgs::HX1K) { + fast_part = args.type == ArchArgs::HX1K; chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_1k)); } else if (args.type == ArchArgs::UP5K) { + fast_part = false; chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_5k)); } else if (args.type == ArchArgs::LP8K || args.type == ArchArgs::HX8K) { + fast_part = args.type == ArchArgs::HX8K; chip_info = get_chip_info(reinterpret_cast<const RelPtr<ChipInfoPOD> *>(chipdb_blob_8k)); } else { log_error("Unsupported iCE40 chip type.\n"); @@ -199,7 +204,7 @@ Arch::Arch(ArchArgs args) : args(args) // ----------------------------------------------------------------------- -std::string Arch::getChipName() +std::string Arch::getChipName() const { #ifdef ICE40_HX1K_ONLY if (args.type == ArchArgs::HX1K) { @@ -306,9 +311,23 @@ PortType Arch::getBelPinType(BelId bel, PortPin pin) const int num_bel_wires = chip_info->bel_data[bel.index].num_bel_wires; const BelWirePOD *bel_wires = chip_info->bel_data[bel.index].bel_wires.get(); - for (int i = 0; i < num_bel_wires; i++) - if (bel_wires[i].port == pin) - return PortType(bel_wires[i].type); + if (num_bel_wires < 7) { + for (int i = 0; i < num_bel_wires; i++) { + if (bel_wires[i].port == pin) + return PortType(bel_wires[i].type); + } + } else { + int b = 0, e = num_bel_wires-1; + while (b <= e) { + int i = (b+e) / 2; + if (bel_wires[i].port == pin) + return PortType(bel_wires[i].type); + if (bel_wires[i].port > pin) + e = i-1; + else + b = i+1; + } + } return PORT_INOUT; } @@ -322,10 +341,25 @@ WireId Arch::getBelPinWire(BelId bel, PortPin pin) const int num_bel_wires = chip_info->bel_data[bel.index].num_bel_wires; const BelWirePOD *bel_wires = chip_info->bel_data[bel.index].bel_wires.get(); - for (int i = 0; i < num_bel_wires; i++) { - if (bel_wires[i].port == pin) { - ret.index = bel_wires[i].wire_index; - break; + if (num_bel_wires < 7) { + for (int i = 0; i < num_bel_wires; i++) { + if (bel_wires[i].port == pin) { + ret.index = bel_wires[i].wire_index; + break; + } + } + } else { + int b = 0, e = num_bel_wires-1; + while (b <= e) { + int i = (b+e) / 2; + if (bel_wires[i].port == pin) { + ret.index = bel_wires[i].wire_index; + break; + } + if (bel_wires[i].port > pin) + e = i-1; + else + b = i+1; } } @@ -801,29 +835,29 @@ std::vector<GraphicElement> Arch::getDecalGraphics(DecalId decal) const // ----------------------------------------------------------------------- -bool Arch::getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, delay_t &delay) const +bool Arch::getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, DelayInfo &delay) const { if (cell->type == id_icestorm_lc) { if ((fromPort == id_i0 || fromPort == id_i1 || fromPort == id_i2 || fromPort == id_i3) && (toPort == id_o || toPort == id_lo)) { - delay = 450; + delay.delay = 450; return true; } else if (fromPort == id_cin && toPort == id_cout) { - delay = 120; + delay.delay = 120; return true; } else if (fromPort == id_i1 && toPort == id_cout) { - delay = 260; + delay.delay = 260; return true; } else if (fromPort == id_i2 && toPort == id_cout) { - delay = 230; + delay.delay = 230; return true; } else if (fromPort == id_clk && toPort == id_o) { - delay = 540; + delay.delay = 540; return true; } } else if (cell->type == id_icestorm_ram) { if (fromPort == id_rclk) { - delay = 2140; + delay.delay = 2140; return true; } } diff --git a/ice40/arch.h b/ice40/arch.h index e2d14e3c..f81fd21d 100644 --- a/ice40/arch.h +++ b/ice40/arch.h @@ -44,9 +44,9 @@ template <typename T> struct RelPtr }; NPNR_PACKED_STRUCT(struct BelWirePOD { - int32_t wire_index; PortPin port; int32_t type; + int32_t wire_index; }); NPNR_PACKED_STRUCT(struct BelInfoPOD { @@ -66,7 +66,8 @@ NPNR_PACKED_STRUCT(struct BelPortPOD { NPNR_PACKED_STRUCT(struct PipInfoPOD { // RelPtr<char> name; int32_t src, dst; - int32_t delay; + int32_t fast_delay; + int32_t slow_delay; int8_t x, y; int16_t src_seg, dst_seg; int16_t switch_mask; @@ -89,6 +90,9 @@ NPNR_PACKED_STRUCT(struct WireInfoPOD { int32_t num_segments; RelPtr<WireSegmentPOD> segments; + int32_t fast_delay; + int32_t slow_delay; + int8_t x, y; WireType type; int8_t padding_0; @@ -344,6 +348,7 @@ struct ArchArgs struct Arch : BaseCtx { + bool fast_part; const ChipInfoPOD *chip_info; const PackageInfoPOD *package_info; @@ -360,7 +365,7 @@ struct Arch : BaseCtx ArchArgs args; Arch(ArchArgs args); - std::string getChipName(); + std::string getChipName() const; IdString archId() const { return id("ice40"); } IdString archArgsToId(ArchArgs args) const; @@ -524,6 +529,11 @@ struct Arch : BaseCtx DelayInfo getWireDelay(WireId wire) const { DelayInfo delay; + NPNR_ASSERT(wire != WireId()); + if (fast_part) + delay.delay = chip_info->wire_data[wire.index].fast_delay; + else + delay.delay = chip_info->wire_data[wire.index].slow_delay; return delay; } @@ -637,7 +647,10 @@ struct Arch : BaseCtx { DelayInfo delay; NPNR_ASSERT(pip != PipId()); - delay.delay = chip_info->pip_data[pip.index].delay; + if (fast_part) + delay.delay = chip_info->pip_data[pip.index].fast_delay; + else + delay.delay = chip_info->pip_data[pip.index].slow_delay; return delay; } @@ -710,7 +723,7 @@ struct Arch : BaseCtx // Get the delay through a cell from one port to another, returning false // if no path exists - bool getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, delay_t &delay) const; + bool getCellDelay(const CellInfo *cell, IdString fromPort, IdString toPort, DelayInfo &delay) const; // Get the associated clock to a port, or empty if the port is combinational IdString getPortClock(const CellInfo *cell, IdString port) const; // Return true if a port is a clock diff --git a/ice40/benchmark/Makefile b/ice40/benchmark/Makefile index 5e16d9b0..5a276b18 100644 --- a/ice40/benchmark/Makefile +++ b/ice40/benchmark/Makefile @@ -1,3 +1,5 @@ +SHELL = /bin/bash + reports:: define mkreport @@ -10,10 +12,10 @@ report_n$1.txt: hx8kdemo_n$1.asc icetime -m -r report_n$1.txt -d hx8k hx8kdemo_n$1.asc hx8kdemo_a$1.asc: hx8kdemo.blif - arachne-pnr -d 8k -p hx8kdemo.pcf -o hx8kdemo_a$1.asc -s 1$1 hx8kdemo.blif > hx8kdemo_a$1.log 2>&1 + { time arachne-pnr -d 8k -p hx8kdemo.pcf -o hx8kdemo_a$1.asc -s 1$1 hx8kdemo.blif; } > hx8kdemo_a$1.log 2>&1 hx8kdemo_n$1.asc: hx8kdemo.json - ../../nextpnr-ice40 --asc hx8kdemo_n$1.asc --json hx8kdemo.json --pcf hx8kdemo.pcf --hx8k --seed 1$1 > hx8kdemo_n$1.log 2>&1 + { time ../../nextpnr-ice40 --asc hx8kdemo_n$1.asc --json hx8kdemo.json --pcf hx8kdemo.pcf --hx8k --seed 1$1; } > hx8kdemo_n$1.log 2>&1 endef $(foreach i,0 1 2 3 4 5 6 7 8 9,$(eval $(call mkreport,$(i)))) diff --git a/ice40/benchmark/report.ipynb b/ice40/benchmark/report.ipynb index 3232f38c..b4e03283 100644 --- a/ice40/benchmark/report.ipynb +++ b/ice40/benchmark/report.ipynb @@ -11,36 +11,58 @@ "%matplotlib inline\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", - "import subprocess\n", + "import subprocess, re\n", "\n", "gitrev = subprocess.getoutput(\"git rev-parse --short HEAD\")\n", "\n", - "data_a = 1 + np.zeros(10)\n", - "data_n = 1 + np.zeros(10)\n", + "data_a = np.zeros((10, 2))\n", + "data_n = np.zeros((10, 2))\n", "\n", "for i in range(10):\n", " try:\n", " with open(\"report_a%d.txt\" % i, \"r\") as f:\n", " for line in f:\n", " if line.startswith(\"Total path delay:\"):\n", - " data_a[i] = float(line.split()[3])\n", + " data_a[i, 0] = float(line.split()[3])\n", " except:\n", - " pass\n", + " data_a[i, 0] = 1.0\n", + " \n", " try:\n", " with open(\"report_n%d.txt\" % i, \"r\") as f:\n", " for line in f:\n", " if line.startswith(\"Total path delay:\"):\n", - " data_n[i] = float(line.split()[3])\n", + " data_n[i, 0] = float(line.split()[3])\n", " except:\n", - " pass\n", + " data_n[i, 0] = 1.0\n", + " \n", + " with open(\"hx8kdemo_a%d.log\" % i, \"r\") as f:\n", + " for line in f:\n", + " match = re.match(r\"real\\s+(\\d+)m(\\d+)\", line)\n", + " if match:\n", + " data_a[i, 1] = float(match.group(1)) + float(match.group(2))/60\n", + " \n", + " with open(\"hx8kdemo_n%d.log\" % i, \"r\") as f:\n", + " for line in f:\n", + " match = re.match(r\"real\\s+(\\d+)m(\\d+)\", line)\n", + " if match:\n", + " data_n[i, 1] = float(match.group(1)) + float(match.group(2))/60\n", "\n", "plt.figure(figsize=(9,3))\n", "plt.title(\"nextpnr -- ice40/benchmark/ -- %s\" % gitrev)\n", - "plt.bar(np.arange(10), data_a, color='blue')\n", - "plt.bar(15+np.arange(10), data_n, color='red')\n", + "plt.bar(np.arange(10), data_a[:, 0], color='blue')\n", + "plt.bar(15+np.arange(10), data_n[:, 0], color='red')\n", "plt.ylabel('Longest path (ns)')\n", "plt.xticks([5, 20], [\"arachne-pnr\", \"nextpnr\"])\n", "plt.xlim(-2, 27)\n", + "plt.show()\n", + "\n", + "plt.figure(figsize=(9,3))\n", + "plt.title(\"nextpnr -- ice40/benchmark/ -- %s\" % gitrev)\n", + "plt.bar(np.arange(10), data_a[:, 1], color='blue')\n", + "plt.bar(15+np.arange(10), data_n[:, 1], color='red')\n", + "plt.ylabel('Runtime (minutes)')\n", + "plt.xticks([5, 20], [\"arachne-pnr\", \"nextpnr\"])\n", + "plt.xlim(-2, 27)\n", "plt.show()" ] } diff --git a/ice40/chipdb.py b/ice40/chipdb.py index b6af8fcf..97ccbe48 100644 --- a/ice40/chipdb.py +++ b/ice40/chipdb.py @@ -9,6 +9,8 @@ parser = argparse.ArgumentParser(description="convert ICE40 chip database") parser.add_argument("filename", type=str, help="chipdb input filename") parser.add_argument("-p", "--portspins", type=str, help="path to portpins.inc") parser.add_argument("-g", "--gfxh", type=str, help="path to gfx.h") +parser.add_argument("--fast", type=str, help="path to timing data for fast part") +parser.add_argument("--slow", type=str, help="path to timing data for slow part") args = parser.parse_args() dev_name = None @@ -51,6 +53,9 @@ wiretypes = dict() gfx_wire_ids = dict() wire_segments = dict() +fast_timings = None +slow_timings = None + with open(args.portspins) as f: for line in f: line = line.replace("(", " ") @@ -77,6 +82,31 @@ with open(args.gfxh) as f: name = line.strip().rstrip(",") gfx_wire_ids[name] = idx +def read_timings(filename): + db = dict() + with open(filename) as f: + cell = None + for line in f: + line = line.split() + if len(line) == 0: + continue + if line[0] == "CELL": + cell = line[1] + if line[0] == "IOPATH": + key = "%s.%s.%s" % (cell, line[1], line[2]) + v1 = line[3].split(":")[2] + v2 = line[4].split(":")[2] + v1 = 0 if v1 == "*" else float(v1) + v2 = 0 if v2 == "*" else float(v2) + db[key] = max(v1, v2) + return db + +if args.fast is not None: + fast_timings = read_timings(args.fast) + +if args.slow is not None: + slow_timings = read_timings(args.slow) + beltypes["ICESTORM_LC"] = 1 beltypes["ICESTORM_RAM"] = 2 beltypes["SB_IO"] = 3 @@ -184,46 +214,75 @@ def wire_type(name): assert 0 return wt -def pipdelay(src, dst): - src = wire_names_r[src] - dst = wire_names_r[dst] +def pipdelay(src_idx, dst_idx, db): + if db is None: + return 0 + + src = wire_names_r[src_idx] + dst = wire_names_r[dst_idx] src_type = wire_type(src[2]) dst_type = wire_type(dst[2]) - if src_type == "LOCAL" and dst_type == "LOCAL": - return 250 + if dst[2].startswith("sp4_") or dst[2].startswith("span4_"): + if src[2].startswith("sp12_") or src[2].startswith("span12_"): + return db["Sp12to4.I.O"] + + if src[2].startswith("span4_"): + return db["IoSpan4Mux.I.O"] + + if dst[2].startswith("sp4_h_"): + return db["Span4Mux_h4.I.O"] + else: + return db["Span4Mux_v4.I.O"] + + if dst[2].startswith("sp12_") or dst[2].startswith("span12_"): + if dst[2].startswith("sp12_h_"): + return db["Span12Mux_h12.I.O"] + else: + return db["Span12Mux_v12.I.O"] - if src_type == "GLOBAL" and dst_type == "LOCAL": - return 400 + if dst[2] in ("fabout", "clk"): + return 0 # FIXME? - # Local -> Span + if src[2].startswith("glb_netwk_") and dst[2].startswith("glb2local_"): + return 0 # FIXME? - if src_type == "LOCAL" and dst_type in ("SP4_HORZ", "SP4_VERT"): - return 350 + if dst[2] == "carry_in_mux": + return db["ICE_CARRY_IN_MUX.carryinitin.carryinitout"] - if src_type == "LOCAL" and dst_type in ("SP12_HORZ", "SP12_VERT"): - return 500 + if dst[2] in ("lutff_global/clk", "io_global/inclk", "io_global/outclk", "ram/RCLK", "ram/WCLK"): + return db["ClkMux.I.O"] - # Span -> Local + if dst[2] in ("lutff_global/s_r", "io_global/latch", "ram/RE", "ram/WE"): + return db["SRMux.I.O"] - if src_type in ("SP4_HORZ", "SP4_VERT", "SP12_HORZ", "SP12_VERT") and dst_type == "LOCAL": - return 300 + if dst[2] in ("lutff_global/cen", "io_global/cen", "ram/RCLKE", "ram/WCLKE"): + return db["CEMux.I.O"] - # Span -> Span + if dst[2].startswith("local_"): + return db["LocalMux.I.O"] - if src_type in ("SP12_HORZ", "SP12_VERT") and dst_type in ("SP12_HORZ", "SP12_VERT"): - return 450 + if src[2].startswith("local_") and dst[2] in ("io_0/D_OUT_0", "io_0/D_OUT_1", "io_0/OUT_ENB", "io_1/D_OUT_0", "io_1/D_OUT_1", "io_1/OUT_ENB"): + return db["IoInMux.I.O"] - if src_type in ("SP4_HORZ", "SP4_VERT") and dst_type in ("SP4_HORZ", "SP4_VERT"): - return 300 + if re.match(r"lutff_\d+/in_\d+", dst[2]): + return db["InMux.I.O"] - if src_type in ("SP12_HORZ", "SP12_VERT") and dst_type in ("SP4_HORZ", "SP4_VERT"): - return 380 + if re.match(r"ram/(MASK|RADDR|WADDR|WDATA)_", dst[2]): + return db["InMux.I.O"] - # print(src, dst, src_type, dst_type, file=sys.stderr) + print(src, dst, src_idx, dst_idx, src_type, dst_type, file=sys.stderr) assert 0 +def wiredelay(wire_idx, db): + if db is None: + return 0 + wire = wire_names_r[wire_idx] + wtype = wire_type(wire[2]) + + # FIXME + return 0 def init_tiletypes(device): global num_tile_types, tile_sizes, tile_bits @@ -448,13 +507,13 @@ def add_bel_input(bel, wire, port): if wire not in wire_belports: wire_belports[wire] = set() wire_belports[wire].add((bel, port)) - bel_wires[bel].append((wire, port, 0)) + bel_wires[bel].append((portpins[port], 0, wire)) def add_bel_output(bel, wire, port): if wire not in wire_belports: wire_belports[wire] = set() wire_belports[wire].add((bel, port)) - bel_wires[bel].append((wire, port, 1)) + bel_wires[bel].append((portpins[port], 1, wire)) def add_bel_lc(x, y, z): bel = len(bel_name) @@ -715,14 +774,12 @@ bba.post('NEXTPNR_NAMESPACE_END') bba.push("chipdb_blob_%s" % dev_name) bba.r("chip_info_%s" % dev_name, "chip_info") -index = 0 for bel in range(len(bel_name)): bba.l("bel_wires_%d" % bel, "BelWirePOD") - for i in range(len(bel_wires[bel])): - bba.u32(bel_wires[bel][i][0], "wire_index") - bba.u32(portpins[bel_wires[bel][i][1]], "port") - bba.u32(bel_wires[bel][i][2], "type") - index += 1 + for data in sorted(bel_wires[bel]): + bba.u32(data[0], "port") + bba.u32(data[1], "type") + bba.u32(data[2], "wire_index") bba.l("bel_data_%s" % dev_name, "BelInfoPOD") for bel in range(len(bel_name)): @@ -748,7 +805,8 @@ for wire in range(num_wires): pi = dict() pi["src"] = src pi["dst"] = wire - pi["delay"] = pipdelay(src, wire) + pi["fast_delay"] = pipdelay(src, wire, fast_timings) + pi["slow_delay"] = pipdelay(src, wire, slow_timings) pi["x"] = pip_xy[(src, wire)][0] pi["y"] = pip_xy[(src, wire)][1] pi["switch_mask"] = pip_xy[(src, wire)][2] @@ -772,7 +830,8 @@ for wire in range(num_wires): pi = dict() pi["src"] = wire pi["dst"] = dst - pi["delay"] = pipdelay(wire, dst) + pi["fast_delay"] = pipdelay(wire, dst, fast_timings) + pi["slow_delay"] = pipdelay(wire, dst, slow_timings) pi["x"] = pip_xy[(wire, dst)][0] pi["y"] = pip_xy[(wire, dst)][1] pi["switch_mask"] = pip_xy[(wire, dst)][2] @@ -891,6 +950,9 @@ for wire, info in enumerate(wireinfo): else: bba.u32(0, "segments") + bba.u32(wiredelay(wire, fast_timings), "fast_delay") + bba.u32(wiredelay(wire, slow_timings), "slow_delay") + bba.u8(info["x"], "x") bba.u8(info["y"], "y") bba.u8(wiretypes[wire_type(info["name"])], "type") @@ -923,7 +985,8 @@ for info in pipinfo: # bba.s("X%d/Y%d/%s->%s" % (info["x"], info["y"], src_segname, dst_segname), "name") bba.u32(info["src"], "src") bba.u32(info["dst"], "dst") - bba.u32(info["delay"], "delay") + bba.u32(info["fast_delay"], "fast_delay") + bba.u32(info["slow_delay"], "slow_delay") bba.u8(info["x"], "x") bba.u8(info["y"], "y") bba.u16(src_seg, "src_seg") diff --git a/ice40/family.cmake b/ice40/family.cmake index 75061f44..02d4b4d8 100644 --- a/ice40/family.cmake +++ b/ice40/family.cmake @@ -14,17 +14,28 @@ file(MAKE_DIRECTORY ice40/chipdbs/) add_library(ice40_chipdb OBJECT ice40/chipdbs/) target_compile_definitions(ice40_chipdb PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family}) target_include_directories(ice40_chipdb PRIVATE ${family}/) + if (MSVC) target_sources(ice40_chipdb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ice40/resource/embed.cc) set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/ice40/resources/chipdb.rc PROPERTIES LANGUAGE RC) foreach (dev ${devices}) + if (dev EQUAL "5k") + set(OPT_FAST "") + set(OPT_SLOW --slow ${ICEBOX_ROOT}/timings-up5k.txt) + elseif(dev EQUAL "384") + set(OPT_FAST "") + set(OPT_SLOW --slow ${ICEBOX_ROOT}/timings-lp384.txt) + else() + set(OPT_FAST --fast ${ICEBOX_ROOT}/timings-hx${dev}.txt) + set(OPT_SLOW --slow ${ICEBOX_ROOT}/timings-lp${dev}.txt) + endif() set(DEV_TXT_DB ${ICEBOX_ROOT}/chipdb-${dev}.txt) set(DEV_CC_BBA_DB ${CMAKE_CURRENT_SOURCE_DIR}/ice40/chipdbs/chipdb-${dev}.bba) set(DEV_CC_DB ${CMAKE_CURRENT_SOURCE_DIR}/ice40/chipdbs/chipdb-${dev}.bin) set(DEV_PORTS_INC ${CMAKE_CURRENT_SOURCE_DIR}/ice40/portpins.inc) set(DEV_GFXH ${CMAKE_CURRENT_SOURCE_DIR}/ice40/gfx.h) add_custom_command(OUTPUT ${DEV_CC_BBA_DB} - COMMAND ${PYTHON_EXECUTABLE} ${DB_PY} -p ${DEV_PORTS_INC} -g ${DEV_GFXH} ${DEV_TXT_DB} > ${DEV_CC_BBA_DB} + COMMAND ${PYTHON_EXECUTABLE} ${DB_PY} -p ${DEV_PORTS_INC} -g ${DEV_GFXH} ${OPT_FAST} ${OPT_SLOW} ${DEV_TXT_DB} > ${DEV_CC_BBA_DB} DEPENDS ${DEV_TXT_DB} ${DB_PY} ) add_custom_command(OUTPUT ${DEV_CC_DB} @@ -40,13 +51,23 @@ if (MSVC) else() target_compile_options(ice40_chipdb PRIVATE -g0 -O0 -w) foreach (dev ${devices}) + if (dev EQUAL "5k") + set(OPT_FAST "") + set(OPT_SLOW --slow ${ICEBOX_ROOT}/timings_up5k.txt) + elseif(dev EQUAL "384") + set(OPT_FAST "") + set(OPT_SLOW --slow ${ICEBOX_ROOT}/timings_lp384.txt) + else() + set(OPT_FAST --fast ${ICEBOX_ROOT}/timings_hx${dev}.txt) + set(OPT_SLOW --slow ${ICEBOX_ROOT}/timings_lp${dev}.txt) + endif() set(DEV_TXT_DB ${ICEBOX_ROOT}/chipdb-${dev}.txt) set(DEV_CC_BBA_DB ${CMAKE_CURRENT_SOURCE_DIR}/ice40/chipdbs/chipdb-${dev}.bba) set(DEV_CC_DB ${CMAKE_CURRENT_SOURCE_DIR}/ice40/chipdbs/chipdb-${dev}.cc) set(DEV_PORTS_INC ${CMAKE_CURRENT_SOURCE_DIR}/ice40/portpins.inc) set(DEV_GFXH ${CMAKE_CURRENT_SOURCE_DIR}/ice40/gfx.h) add_custom_command(OUTPUT ${DEV_CC_BBA_DB} - COMMAND ${PYTHON_EXECUTABLE} ${DB_PY} -p ${DEV_PORTS_INC} -g ${DEV_GFXH} ${DEV_TXT_DB} > ${DEV_CC_BBA_DB}.new + COMMAND ${PYTHON_EXECUTABLE} ${DB_PY} -p ${DEV_PORTS_INC} -g ${DEV_GFXH} ${OPT_FAST} ${OPT_SLOW} ${DEV_TXT_DB} > ${DEV_CC_BBA_DB}.new COMMAND mv ${DEV_CC_BBA_DB}.new ${DEV_CC_BBA_DB} DEPENDS ${DEV_TXT_DB} ${DB_PY} ) diff --git a/ice40/place_legaliser.cc b/ice40/place_legaliser.cc index 9fde179d..0d14fb35 100644 --- a/ice40/place_legaliser.cc +++ b/ice40/place_legaliser.cc @@ -114,17 +114,58 @@ class PlacementLegaliser public: PlacementLegaliser(Context *ctx) : ctx(ctx){}; + void print_stats(const char *point) + { + float distance_sum = 0; + float max_distance = 0; + int moved_cells = 0; + int unplaced_cells = 0; + for (auto orig : originalPositions) { + if (ctx->cells.at(orig.first)->bel == BelId()) { + unplaced_cells++; + continue; + } + Loc newLoc = ctx->getBelLocation(ctx->cells.at(orig.first)->bel); + if (newLoc != orig.second) { + float distance = std::sqrt(std::pow(newLoc.x - orig.second.x, 2) + pow(newLoc.y - orig.second.y, 2)); + moved_cells++; + distance_sum += distance; + if (distance > max_distance) + max_distance = distance; + } + } + log_info(" moved %d cells, %d unplaced (after %s)\n", moved_cells, unplaced_cells, point); + if (moved_cells > 0) { + log_info(" average distance %f\n", (distance_sum / moved_cells)); + log_info(" maximum distance %f\n", max_distance); + } + } + bool legalise() { log_info("Legalising design..\n"); + for (auto &cell : ctx->cells) { + CellInfo *ci = cell.second.get(); + if (!ctx->getBelGlobalBuf(ci->bel) && cell.second->type == ctx->id("ICESTORM_LC")) { + originalPositions[cell.first] = ctx->getBelLocation(ci->bel); + } + } init_logic_cells(); bool legalised_carries = legalise_carries(); if (!legalised_carries && !ctx->force) return false; + print_stats("carry legalisation"); legalise_others(); + print_stats("misc. cell legalisation"); legalise_logic_tiles(); + print_stats("logic cell legalisation"); bool replaced_cells = replace_cells(); + print_stats("cell replacement"); + ctx->assignArchInfo(); + + + return legalised_carries && replaced_cells; } @@ -501,6 +542,7 @@ class PlacementLegaliser Context *ctx; std::unordered_set<IdString> rippedCells; std::unordered_set<IdString> createdCells; + std::unordered_map<IdString, Loc> originalPositions; // Go from X and Y position to logic cells, setting occupied to true if a Bel is unavailable std::vector<std::vector<std::vector<std::pair<BelId, bool>>>> logic_bels; }; diff --git a/python/functions.py b/python/functions.py deleted file mode 100644 index 8d2e2fb8..00000000 --- a/python/functions.py +++ /dev/null @@ -1,21 +0,0 @@ -def get_drivers(wire): - wid = chip.getWireByName(wire) - assert not wid.nil(), "wire {} not found".format(wire) - bp = chip.getBelPinUphill(wid) - if not bp.bel.nil(): - print("Bel pin: {}.{}".format(chip.getBelName(bp.bel), str(bp.pin))) - for pip in sorted(chip.getPipsUphill(wid), key=lambda x: x.index): - print("Pip: {}".format(chip.getWireName(chip.getPipSrcWire(pip)))) - - -def get_loads(wire): - wid = chip.getWireByName(wire) - assert not wid.nil(), "wire {} not found".format(wire) - for bp in sorted(chip.getBelPinsDownhill(wid), key=lambda x: (x.bel.index, x.pin)): - print("Bel pin: {}.{}".format(chip.getBelName(bp.bel), str(bp.pin))) - for pip in sorted(chip.getPipsDownhill(wid), key=lambda x: x.index): - print("Pip: {}".format(chip.getWireName(chip.getPipDstWire(pip)))) - - -#get_drivers("12_14_lutff_7/in_3") -#get_loads("12_14_lutff_global/clk") diff --git a/python/python_mod_test.py b/python/python_mod_test.py deleted file mode 100644 index e7a8de94..00000000 --- a/python/python_mod_test.py +++ /dev/null @@ -1,7 +0,0 @@ -# Run: PYTHONPATH=. python3 python/python_mod_test.py -from nextpnrpy_ice40 import Chip, ChipArgs, iCE40Type -args = ChipArgs() -args.type = iCE40Type.HX1K -chip = Chip(args) -for wire in chip.getWires(): - print(chip.getWireName(wire)) diff --git a/python/python_test.py b/python/python_test.py deleted file mode 100644 index 31d066b2..00000000 --- a/python/python_test.py +++ /dev/null @@ -1,2 +0,0 @@ -for wire in chip.getWires(): - print(chip.getWireName(wire)) |