From 0d621ecc110641bf912dd61efe031ef2bd066843 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Fri, 9 May 2025 11:36:39 +0200 Subject: [PATCH 1/9] libcache: add -quiet and -verbose --- passes/techmap/libcache.cc | 29 +++++++++++++++++++++++++---- passes/techmap/libparse.cc | 6 ++++-- passes/techmap/libparse.h | 1 + 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/passes/techmap/libcache.cc b/passes/techmap/libcache.cc index 19f1fa87d..177258e7f 100644 --- a/passes/techmap/libcache.cc +++ b/passes/techmap/libcache.cc @@ -29,7 +29,7 @@ { // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| log("\n"); - log(" libcache {-enable|-disable|-purge} { -all | [path]... }\n"); + log(" libcache [-verbose] {-enable|-disable|-purge} { -all | [path]... }\n"); log("\n"); log("Controls the default and per path caching of liberty file data.\n"); log("\n"); @@ -47,6 +47,13 @@ log("\n"); log("Displays the current cache settings and cached paths.\n"); log("\n"); + log(" libcache {-verbose|-quiet}\n"); + log("\n"); + log("Controls cache use logging.\n"); + log("\n"); + log(" -verbose Enable printing info when cache is used\n"); + log(" -quiet Disable printing info when cache is used (default)\n"); + log("\n"); } void execute(std::vector args, RTLIL::Design *) override { @@ -55,6 +62,8 @@ bool purge = false; bool all = false; bool list = false; + bool verbose = false; + bool quiet = false; std::vector paths; size_t argidx; @@ -79,16 +88,24 @@ list = true; continue; } + if (args[argidx] == "-verbose") { + verbose = true; + continue; + } + if (args[argidx] == "-quiet") { + quiet = true; + continue; + } std::string fname = args[argidx]; rewrite_filename(fname); paths.push_back(fname); break; } - int modes = enable + disable + purge + list; + int modes = enable + disable + purge + list + verbose + quiet; if (modes == 0) - log_cmd_error("At least one of -enable, -disable, -purge or -list is required.\n"); + log_cmd_error("At least one of -enable, -disable, -purge, -list,\n-verbose, or -quiet is required.\n"); if (modes > 1) - log_cmd_error("Only one of -enable, -disable, -purge or -list may be present.\n"); + log_cmd_error("Only one of -enable, -disable, -purge, -list,\n-verbose, or -quiet may be present.\n"); if (all && !paths.empty()) log_cmd_error("The -all option cannot be combined with a list of paths.\n"); @@ -121,6 +138,10 @@ LibertyAstCache::instance.cache_path.erase(path); } } + } else if (verbose) { + LibertyAstCache::instance.verbose = true; + } else if (quiet) { + LibertyAstCache::instance.verbose = false; } else { log_assert(false); } diff --git a/passes/techmap/libparse.cc b/passes/techmap/libparse.cc index 5594d5443..85ed35ea1 100644 --- a/passes/techmap/libparse.cc +++ b/passes/techmap/libparse.cc @@ -41,7 +41,8 @@ std::shared_ptr LibertyAstCache::cached_ast(const std::string auto it = cached.find(fname); if (it == cached.end()) return nullptr; - log("Using cached data for liberty file `%s'\n", fname.c_str()); + if (verbose) + log("Using cached data for liberty file `%s'\n", fname.c_str()); return it->second; } @@ -51,7 +52,8 @@ void LibertyAstCache::parsed_ast(const std::string &fname, const std::shared_ptr bool should_cache = it == cache_path.end() ? cache_by_default : it->second; if (!should_cache) return; - log("Caching data for liberty file `%s'\n", fname.c_str()); + if (verbose) + log("Caching data for liberty file `%s'\n", fname.c_str()); cached.emplace(fname, ast); } diff --git a/passes/techmap/libparse.h b/passes/techmap/libparse.h index 61dc83867..949adbdcf 100644 --- a/passes/techmap/libparse.h +++ b/passes/techmap/libparse.h @@ -140,6 +140,7 @@ namespace Yosys dict> cached; bool cache_by_default = false; + bool verbose = false; dict cache_path; std::shared_ptr cached_ast(const std::string &fname); From 9d2f9f7557c145daa156d7fefcbdba838ff61616 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Fri, 9 May 2025 12:40:38 +0200 Subject: [PATCH 2/9] libcache: fix test --- tests/liberty/libcache.ys | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/liberty/libcache.ys b/tests/liberty/libcache.ys index a741a9df1..04257aa92 100644 --- a/tests/liberty/libcache.ys +++ b/tests/liberty/libcache.ys @@ -1,3 +1,4 @@ +libcache -verbose libcache -enable busdef.lib logger -expect log "Caching is disabled by default." 1 @@ -14,8 +15,8 @@ logger -expect log "Caching data" 1 read_liberty -lib busdef.lib; design -reset logger -check-expected -logger -expect log "Using caching data" 1 -log Using caching data +logger -expect log "Using cached data" 1 +log Using cached data read_liberty normal.lib; design -reset logger -check-expected @@ -23,6 +24,13 @@ logger -expect log "Using cached data" 1 read_liberty -lib busdef.lib; design -reset logger -check-expected +libcache -quiet +logger -expect log "Using cached data" 1 +log Using cached data +read_liberty -lib busdef.lib; design -reset +logger -check-expected +libcache -verbose + libcache -purge busdef.lib logger -expect log "Caching is disabled by default." 1 From 2ca2ecaa1cc93f4449862f3283ffd696b9c7e204 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Fri, 9 May 2025 12:40:45 +0200 Subject: [PATCH 3/9] libcache: fix help --- passes/techmap/libcache.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/passes/techmap/libcache.cc b/passes/techmap/libcache.cc index 177258e7f..e299f43ec 100644 --- a/passes/techmap/libcache.cc +++ b/passes/techmap/libcache.cc @@ -29,7 +29,7 @@ { // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| log("\n"); - log(" libcache [-verbose] {-enable|-disable|-purge} { -all | [path]... }\n"); + log(" libcache {-enable|-disable|-purge} { -all | [path]... }\n"); log("\n"); log("Controls the default and per path caching of liberty file data.\n"); log("\n"); From 5e72464a15b70b25d89bd2cd999c76e7d8506b32 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Tue, 6 May 2025 12:02:00 +0200 Subject: [PATCH 4/9] rtlil: enable single-bit vector wires --- backends/verilog/verilog_backend.cc | 3 +++ frontends/ast/genrtlil.cc | 1 + frontends/ast/simplify.cc | 6 ++++++ kernel/constids.inc | 1 + tests/verilog/sbvector.ys | 20 ++++++++++++++++++++ 5 files changed, 31 insertions(+) create mode 100644 tests/verilog/sbvector.ys diff --git a/backends/verilog/verilog_backend.cc b/backends/verilog/verilog_backend.cc index 2bc6ff3b8..1b828dcbd 100644 --- a/backends/verilog/verilog_backend.cc +++ b/backends/verilog/verilog_backend.cc @@ -419,6 +419,9 @@ void dump_wire(std::ostream &f, std::string indent, RTLIL::Wire *wire) range = stringf(" [%d:%d]", wire->start_offset, wire->width - 1 + wire->start_offset); else range = stringf(" [%d:%d]", wire->width - 1 + wire->start_offset, wire->start_offset); + } else { + if (wire->attributes.count(ID::single_bit_vector)) + range = stringf(" [%d:%d]", wire->start_offset, wire->start_offset); } if (wire->port_input && !wire->port_output) f << stringf("%s" "input%s %s;\n", indent.c_str(), range.c_str(), id(wire->name).c_str()); diff --git a/frontends/ast/genrtlil.cc b/frontends/ast/genrtlil.cc index d3982b92b..26ed0e3e4 100644 --- a/frontends/ast/genrtlil.cc +++ b/frontends/ast/genrtlil.cc @@ -1446,6 +1446,7 @@ RTLIL::SigSpec AstNode::genRTLIL(int width_hint, bool sign_hint) wire->port_input = is_input; wire->port_output = is_output; wire->upto = range_swapped; + wire->is_signed = is_signed; for (auto &attr : attributes) { diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index 3411d6c03..a45eb1cc1 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -2084,6 +2084,8 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin std::swap(range_left, range_right); range_swapped = force_upto; } + if (range_left == range_right) + set_attribute(ID::single_bit_vector, mkconst_int(1, false)); } } else { if (!range_valid) @@ -2092,6 +2094,10 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin range_swapped = false; range_left = 0; range_right = 0; + if (attributes.count(ID::single_bit_vector)) { + delete attributes[ID::single_bit_vector]; + attributes.erase(ID::single_bit_vector); + } } } diff --git a/kernel/constids.inc b/kernel/constids.inc index 4fdbb3dc8..055ebf2a8 100644 --- a/kernel/constids.inc +++ b/kernel/constids.inc @@ -184,6 +184,7 @@ X(romstyle) X(S) X(SET) X(SET_POLARITY) +X(single_bit_vector) X(SIZE) X(SRC) X(src) diff --git a/tests/verilog/sbvector.ys b/tests/verilog/sbvector.ys new file mode 100644 index 000000000..3481f6f45 --- /dev/null +++ b/tests/verilog/sbvector.ys @@ -0,0 +1,20 @@ +read_verilog < Date: Mon, 12 May 2025 13:23:02 +0200 Subject: [PATCH 5/9] verific: support single_bit_vector --- frontends/verific/verific.cc | 4 ++++ tests/verilog/sbvector.ys | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/frontends/verific/verific.cc b/frontends/verific/verific.cc index 95bede420..411804566 100644 --- a/frontends/verific/verific.cc +++ b/frontends/verific/verific.cc @@ -1557,6 +1557,8 @@ void VerificImporter::import_netlist(RTLIL::Design *design, Netlist *nl, std::ma wire->start_offset = min(portbus->LeftIndex(), portbus->RightIndex()); wire->upto = portbus->IsUp(); import_attributes(wire->attributes, portbus, nl, portbus->Size()); + if (portbus->Size() == 1) + wire->set_bool_attribute(ID::single_bit_vector); SetIter si ; Port *port ; FOREACH_PORT_OF_PORTBUS(portbus, si, port) { @@ -1755,6 +1757,8 @@ void VerificImporter::import_netlist(RTLIL::Design *design, Netlist *nl, std::ma break; } import_attributes(wire->attributes, netbus, nl, netbus->Size()); + if (netbus->Size() == 1) + wire->set_bool_attribute(ID::single_bit_vector); RTLIL::Const initval = Const(State::Sx, GetSize(wire)); bool initval_valid = false; diff --git a/tests/verilog/sbvector.ys b/tests/verilog/sbvector.ys index 3481f6f45..ab8092700 100644 --- a/tests/verilog/sbvector.ys +++ b/tests/verilog/sbvector.ys @@ -4,17 +4,27 @@ module foo( input [0:0] i1, input i2 ); - assign o = i1 ^ i2; + wire [0:0] w1 = i1 ^ i2; + wire w2 = ~i1; + assign o = w1 ^ w2; endmodule EOT -logger -expect log "wire width 1 input 2 \\i1" 1 -logger -expect log "wire input 3 \\i2" 1 -dump -logger -check-expected +hierarchy +proc +select -assert-count 1 w:i1 +select -assert-count 1 w:i1 a:single_bit_vector %i +select -assert-count 1 w:i2 +select -assert-count 0 w:i2 a:single_bit_vector %i +select -assert-count 1 w:w1 +select -assert-count 1 w:w1 a:single_bit_vector %i +select -assert-count 1 w:w2 +select -assert-count 0 w:w2 a:single_bit_vector %i write_verilog verilog_sbvector.out !grep -qF 'wire [0:0] i1;' verilog_sbvector.out !grep -qF 'input [0:0] i1;' verilog_sbvector.out !grep -qF 'wire i2;' verilog_sbvector.out !grep -qF 'input i2;' verilog_sbvector.out +!grep -qF 'wire [0:0] w1;' verilog_sbvector.out +!grep -qF 'wire w2;' verilog_sbvector.out From f73c6a9c9ac1dcaee9ce283c73a6cf9fae07bc6e Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Mon, 12 May 2025 13:36:25 +0200 Subject: [PATCH 6/9] write_verilog: don't dump single_bit_vector attribute --- backends/verilog/verilog_backend.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/backends/verilog/verilog_backend.cc b/backends/verilog/verilog_backend.cc index 1b828dcbd..10cf7c52e 100644 --- a/backends/verilog/verilog_backend.cc +++ b/backends/verilog/verilog_backend.cc @@ -383,6 +383,7 @@ void dump_attributes(std::ostream &f, std::string indent, dictfirst == ID::single_bit_vector) continue; if (it->first == ID::init && regattr) continue; f << stringf("%s" "%s %s", indent.c_str(), as_comment ? "/*" : "(*", id(it->first).c_str()); f << stringf(" = "); From 6c67b29bbb52cc7f0fbb86ebde87c46503efb5e2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 00:24:38 +0000 Subject: [PATCH 7/9] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 304753d98..74857d3a8 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,7 @@ ifeq ($(OS), Haiku) CXXFLAGS += -D_DEFAULT_SOURCE endif -YOSYS_VER := 0.53+39 +YOSYS_VER := 0.53+49 YOSYS_MAJOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f1) YOSYS_MINOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f2 | cut -d'+' -f1) YOSYS_COMMIT := $(shell echo $(YOSYS_VER) | cut -d'+' -f2) From 4f0cbf2ee6c38faed20a1896e5b93c2c3f45a460 Mon Sep 17 00:00:00 2001 From: Gary Wong Date: Thu, 22 May 2025 18:52:33 -0600 Subject: [PATCH 8/9] Fix typo ("exist" -> "exit"). --- passes/cmds/logger.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/passes/cmds/logger.cc b/passes/cmds/logger.cc index 3277e1608..241a8799f 100644 --- a/passes/cmds/logger.cc +++ b/passes/cmds/logger.cc @@ -67,7 +67,7 @@ struct LoggerPass : public Pass { log(" -check-expected\n"); log(" verifies that the patterns previously set up by -expect have actually\n"); log(" been met, then clears the expected log list. If this is not called\n"); - log(" manually, the check will happen at yosys exist time instead.\n"); + log(" manually, the check will happen at yosys exit time instead.\n"); log("\n"); } From 209df95fb94602394e70665ceeacced2f081cf82 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 24 May 2025 00:23:33 +0000 Subject: [PATCH 9/9] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 74857d3a8..6ea8e3949 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,7 @@ ifeq ($(OS), Haiku) CXXFLAGS += -D_DEFAULT_SOURCE endif -YOSYS_VER := 0.53+49 +YOSYS_VER := 0.53+60 YOSYS_MAJOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f1) YOSYS_MINOR := $(shell echo $(YOSYS_VER) | cut -d'.' -f2 | cut -d'+' -f1) YOSYS_COMMIT := $(shell echo $(YOSYS_VER) | cut -d'+' -f2)