From 08778917dbd8ba026382694c57c1e8a02a473455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Mon, 16 Dec 2024 12:56:44 +0100 Subject: [PATCH 01/11] wreduce: Optimize signedness when possible --- passes/opt/wreduce.cc | 51 +++++++++++++++++++++++++++++++++++++++ tests/various/wreduce2.ys | 22 +++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tests/various/wreduce2.ys diff --git a/passes/opt/wreduce.cc b/passes/opt/wreduce.cc index 02678d676..9c0fcc7e1 100644 --- a/passes/opt/wreduce.cc +++ b/passes/opt/wreduce.cc @@ -263,6 +263,19 @@ struct WreduceWorker } } + int reduced_opsize(const SigSpec &inp, bool signed_) + { + int size = GetSize(inp); + if (signed_) { + while (size >= 2 && inp[size - 1] == inp[size - 2]) + size--; + } else { + while (size >= 1 && inp[size - 1] == State::S0) + size--; + } + return size; + } + void run_cell(Cell *cell) { bool did_something = false; @@ -295,6 +308,44 @@ struct WreduceWorker bool port_a_signed = false; bool port_b_signed = false; + // Under certain conditions we are free to choose the signedness of the operands + if (cell->type.in(ID($mul), ID($add), ID($sub)) && + max_port_a_size == GetSize(sig) && + max_port_b_size == GetSize(sig)) { + SigSpec sig_a = mi.sigmap(cell->getPort(ID::A)), sig_b = mi.sigmap(cell->getPort(ID::B)); + + // Remove top bits from sig_a and sig_b which are not visible on the output + sig_a.extend_u0(max_port_a_size); + sig_b.extend_u0(max_port_b_size); + + int signed_size, unsigned_size; + if (cell->type == ID($mul)) { + signed_size = reduced_opsize(sig_a, true) * reduced_opsize(sig_b, true); + unsigned_size = reduced_opsize(sig_a, false) * reduced_opsize(sig_b, false); + } else { + signed_size = max(reduced_opsize(sig_a, true), reduced_opsize(sig_b, true)); + unsigned_size = max(reduced_opsize(sig_a, false), reduced_opsize(sig_b, false)); + } + + if (!port_a_signed && !port_b_signed && signed_size < unsigned_size) { + log("Converting cell %s.%s (%s) from unsigned to signed.\n", + log_id(module), log_id(cell), log_id(cell->type)); + cell->setParam(ID::A_SIGNED, 1); + cell->setParam(ID::B_SIGNED, 1); + port_a_signed = true; + port_b_signed = true; + did_something = true; + } else if (port_a_signed && port_b_signed && unsigned_size < signed_size) { + log("Converting cell %s.%s (%s) from signed to unsigned.\n", + log_id(module), log_id(cell), log_id(cell->type)); + cell->setParam(ID::A_SIGNED, 0); + cell->setParam(ID::B_SIGNED, 0); + port_a_signed = false; + port_b_signed = false; + did_something = true; + } + } + if (max_port_a_size >= 0 && cell->type != ID($shiftx)) run_reduce_inport(cell, 'A', max_port_a_size, port_a_signed, did_something); diff --git a/tests/various/wreduce2.ys b/tests/various/wreduce2.ys new file mode 100644 index 000000000..496aa97e9 --- /dev/null +++ b/tests/various/wreduce2.ys @@ -0,0 +1,22 @@ +read_verilog < Date: Fri, 3 Jan 2025 12:54:34 +0100 Subject: [PATCH 02/11] wreduce: Adjust naming and comments --- passes/opt/wreduce.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/passes/opt/wreduce.cc b/passes/opt/wreduce.cc index 9c0fcc7e1..5b3b1edc8 100644 --- a/passes/opt/wreduce.cc +++ b/passes/opt/wreduce.cc @@ -308,7 +308,8 @@ struct WreduceWorker bool port_a_signed = false; bool port_b_signed = false; - // Under certain conditions we are free to choose the signedness of the operands + // For some operations if the output is no wider than either of the inputs + // we are free to choose the signedness of the operands if (cell->type.in(ID($mul), ID($add), ID($sub)) && max_port_a_size == GetSize(sig) && max_port_b_size == GetSize(sig)) { @@ -318,16 +319,16 @@ struct WreduceWorker sig_a.extend_u0(max_port_a_size); sig_b.extend_u0(max_port_b_size); - int signed_size, unsigned_size; + int signed_cost, unsigned_cost; if (cell->type == ID($mul)) { - signed_size = reduced_opsize(sig_a, true) * reduced_opsize(sig_b, true); - unsigned_size = reduced_opsize(sig_a, false) * reduced_opsize(sig_b, false); + signed_cost = reduced_opsize(sig_a, true) * reduced_opsize(sig_b, true); + unsigned_cost = reduced_opsize(sig_a, false) * reduced_opsize(sig_b, false); } else { - signed_size = max(reduced_opsize(sig_a, true), reduced_opsize(sig_b, true)); - unsigned_size = max(reduced_opsize(sig_a, false), reduced_opsize(sig_b, false)); + signed_cost = max(reduced_opsize(sig_a, true), reduced_opsize(sig_b, true)); + unsigned_cost = max(reduced_opsize(sig_a, false), reduced_opsize(sig_b, false)); } - if (!port_a_signed && !port_b_signed && signed_size < unsigned_size) { + if (!port_a_signed && !port_b_signed && signed_cost < unsigned_cost) { log("Converting cell %s.%s (%s) from unsigned to signed.\n", log_id(module), log_id(cell), log_id(cell->type)); cell->setParam(ID::A_SIGNED, 1); @@ -335,7 +336,7 @@ struct WreduceWorker port_a_signed = true; port_b_signed = true; did_something = true; - } else if (port_a_signed && port_b_signed && unsigned_size < signed_size) { + } else if (port_a_signed && port_b_signed && unsigned_cost < signed_cost) { log("Converting cell %s.%s (%s) from signed to unsigned.\n", log_id(module), log_id(cell), log_id(cell->type)); cell->setParam(ID::A_SIGNED, 0); From 9e039095e9fe25ef49a5993ab6b9699c008d8325 Mon Sep 17 00:00:00 2001 From: KrystalDelusion <93062060+KrystalDelusion@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:08:00 +1300 Subject: [PATCH 03/11] Docs: Remove restructure note It's been almost a year since the restructure, so it's not recent anymore and doesn't need to link back to the old version. --- docs/source/index.rst | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index ab1742424..61dc114ef 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -7,17 +7,6 @@ see :doc:`/introduction`. For a quick guide on how to get started using Yosys, check out :doc:`/getting_started/index`. For the complete list of commands available, go to :ref:`commandindex`. -.. note:: - - This documentation recently went through a major restructure. If you're - looking for something from the previous version and can't find it here, - please `let us know`_. Documentation from before the restructure can still - be found by switching to `version 0.36`_ or earlier. Note that the previous - theme does not include a version switcher. - -.. _let us know: https://github.com/YosysHQ/yosys/issues/new/choose -.. _version 0.36: https://yosyshq.readthedocs.io/projects/yosys/en/0.36/ - .. todo:: look into command ref improvements - Search bar with live drop down suggestions for matching on title / From f6c0e184ce0747195a403c67787a671bd795f6c5 Mon Sep 17 00:00:00 2001 From: Alain Dargelas Date: Mon, 6 Jan 2025 14:58:00 -0800 Subject: [PATCH 04/11] Enable formal passes --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index d43620f16..ecdac8e53 100644 --- a/Makefile +++ b/Makefile @@ -709,6 +709,7 @@ include $(YOSYS_SRC)/frontends/ast/Makefile.inc include $(YOSYS_SRC)/frontends/blif/Makefile.inc include $(YOSYS_SRC)/frontends/liberty/Makefile.inc +include $(YOSYS_SRC)/passes/equiv/Makefile.inc OBJS += passes/cmds/select.o OBJS += passes/cmds/show.o From d37449605d1d66279f81cbe71dbf2e8ec4937215 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 00:21:35 +0000 Subject: [PATCH 05/11] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6f5fec6a2..c31fc2626 100644 --- a/Makefile +++ b/Makefile @@ -153,7 +153,7 @@ ifeq ($(OS), Haiku) CXXFLAGS += -D_DEFAULT_SOURCE endif -YOSYS_VER := 0.48+51 +YOSYS_VER := 0.48+57 # Note: We arrange for .gitcommit to contain the (short) commit hash in # tarballs generated with git-archive(1) using .gitattributes. The git repo From 2cf97cf744e93a1a6e08e4ec74b37e91cde99c1b Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Tue, 7 Jan 2025 01:51:00 -0800 Subject: [PATCH 06/11] Splitfanout index fix --- passes/cmds/splitfanout.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/passes/cmds/splitfanout.cc b/passes/cmds/splitfanout.cc index 95af756d1..9dbdce49b 100644 --- a/passes/cmds/splitfanout.cc +++ b/passes/cmds/splitfanout.cc @@ -136,7 +136,7 @@ struct SplitfanoutWorker // Configure the driver cell IdString new_name; Cell *new_cell; - if (bit_user_i-- != 0) { // create a new cell + if (bit_user_i != 0) { // create a new cell new_name = module->uniquify(stringf("%s_splfo%d", cell->name.c_str(), bit_user_i)); new_cell = module->addCell(new_name, cell); // Add new cell to the bit_users_db @@ -173,6 +173,9 @@ struct SplitfanoutWorker new_cell->setPort(outport, new_wire); } + // Decrement bit user index + bit_user_i--; + // Log the new cell log_debug(" slice %d: %s => %s\n", foi++, log_id(new_name), log_signal(new_cell->getPort(outport))); } From 91687da279358097dae7b06604cc5459c2ee8cf9 Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Thu, 9 Jan 2025 14:44:47 -0800 Subject: [PATCH 07/11] Add delete command --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 24048c889..6837939c5 100644 --- a/Makefile +++ b/Makefile @@ -735,6 +735,7 @@ OBJS += passes/sat/sim.o OBJS += passes/techmap/bufnorm.o OBJS += passes/cmds/rename.o OBJS += passes/cmds/segv.o +OBJS += passes/cmds/delete.o include $(YOSYS_SRC)/passes/hierarchy/Makefile.inc include $(YOSYS_SRC)/passes/memory/Makefile.inc From 8ec83c8189541e95442286b055175ad5664b260b Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Thu, 9 Jan 2025 15:12:59 -0800 Subject: [PATCH 08/11] Install share directory properly --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 6837939c5..040b58959 100644 --- a/Makefile +++ b/Makefile @@ -1014,6 +1014,8 @@ ifneq ($(filter $(PROGRAM_PREFIX)yosys-filterlib,$(TARGETS)),) endif $(INSTALL_SUDO) mkdir -p $(DESTDIR)$(PYTHON_DESTDIR)/$(subst -,_,$(PROGRAM_PREFIX))pyosys $(INSTALL_SUDO) cp -r share $(DESTDIR)$(PYTHON_DESTDIR)/$(subst -,_,$(PROGRAM_PREFIX))pyosys + $(INSTALL_SUDO) mkdir -p $(DESTDIR)$(DATDIR) + $(INSTALL_SUDO) cp -r share $(DESTDIR)$(DATDIR)/ ifeq ($(ENABLE_LIBYOSYS),1) $(INSTALL_SUDO) mkdir -p $(DESTDIR)$(LIBDIR) $(INSTALL_SUDO) cp libyosys.so $(DESTDIR)$(LIBDIR)/ From 2b4e1756984a51aded32b19d3a4877dd2a59657f Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Thu, 9 Jan 2025 19:24:54 -0800 Subject: [PATCH 09/11] bufnorm log_debug to reduce time --- passes/techmap/bufnorm.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/passes/techmap/bufnorm.cc b/passes/techmap/bufnorm.cc index a4552c71b..affb7dd21 100644 --- a/passes/techmap/bufnorm.cc +++ b/passes/techmap/bufnorm.cc @@ -391,7 +391,7 @@ struct BufnormPass : public Pass { } if (w->name.isPublic()) - log(" directly driven by cell %s port %s: %s\n", + log_debug(" directly driven by cell %s port %s: %s\n", log_id(cell), log_id(conn.first), log_id(w)); for (auto bit : SigSpec(w)) From 60d7723a649cc7bd03d6bf18a4066a5ab0922d1d Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Fri, 10 Jan 2025 11:50:59 -0800 Subject: [PATCH 10/11] Smallfixes to reconstruct busses to use logger and ignore blackboxes --- passes/cmds/reconstructbusses.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/passes/cmds/reconstructbusses.cc b/passes/cmds/reconstructbusses.cc index 3285fca41..740f438b7 100644 --- a/passes/cmds/reconstructbusses.cc +++ b/passes/cmds/reconstructbusses.cc @@ -47,6 +47,8 @@ struct ReconstructBusses : public ScriptPass { log("Running reconstructbusses pass\n"); log_flush(); for (auto module : design->modules()) { + if (module->get_bool_attribute("\\blackbox")) + continue; log("Creating bus groups for module %s\n", module->name.str().c_str()); log_flush(); // Collect all wires with a common prefix @@ -104,7 +106,7 @@ struct ReconstructBusses : public ScriptPass { } log("Found %ld groups\n", wire_groups.size()); if (wire_groups.size() == 0) { - std::cout << "No busses to reconstruct. Done." << std::endl; + log("No busses to reconstruct. Done.\n"); continue; } log("Creating busses\n"); From 737e95d3e91ea412fe094199fa8df59e28992515 Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Fri, 10 Jan 2025 11:52:10 -0800 Subject: [PATCH 11/11] Move signal outside Py_IsInitialized --- kernel/yosys.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 818137992..cd98cdc0a 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -561,8 +561,8 @@ void yosys_setup() PyImport_AppendInittab((char*)"libyosys", INIT_MODULE); Py_Initialize(); PyRun_SimpleString("import sys"); - signal(SIGINT, SIG_DFL); } + signal(SIGINT, SIG_DFL); #endif init_share_dirname();