From 2522bcd49272d9a2b9ef68cbe8bf2bd27a581cbb Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Fri, 9 May 2025 14:21:10 +0200 Subject: [PATCH 1/9] aiger: fix -map and -vmap --- backends/aiger/aiger.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/aiger/aiger.cc b/backends/aiger/aiger.cc index f2cb5d9bc..0e5706a75 100644 --- a/backends/aiger/aiger.cc +++ b/backends/aiger/aiger.cc @@ -698,7 +698,7 @@ struct AigerWriter } if (wire->port_output) { - int o = ordered_outputs.at(sig[i]); + int o = ordered_outputs.at(SigSpec(wire, i)); output_lines[o] += stringf("output %d %d %s\n", o, index, log_id(wire)); } From cbf069849ec48669b67b8252e04662acc3a75eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Ji=C5=99=C3=AD=20Tywoniak?= Date: Fri, 9 May 2025 16:01:47 +0200 Subject: [PATCH 2/9] aiger: add regression test for sliced output segfault --- tests/aiger/io.ys | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/aiger/io.ys diff --git a/tests/aiger/io.ys b/tests/aiger/io.ys new file mode 100644 index 000000000..eae7f358d --- /dev/null +++ b/tests/aiger/io.ys @@ -0,0 +1,10 @@ +read_verilog < Date: Mon, 26 May 2025 12:16:58 +1200 Subject: [PATCH 3/9] Tests: Add svtypes/typedef_struct_global.ys --- tests/svtypes/typedef_struct_global.ys | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/svtypes/typedef_struct_global.ys diff --git a/tests/svtypes/typedef_struct_global.ys b/tests/svtypes/typedef_struct_global.ys new file mode 100644 index 000000000..0fed440e4 --- /dev/null +++ b/tests/svtypes/typedef_struct_global.ys @@ -0,0 +1,13 @@ +read_verilog -sv << EOF +typedef struct packed { + logic y; + logic x; +} Vec_2_B; + +module top; + + Vec_2_B two_dee; + wire foo = two_dee.x; + +endmodule +EOF From 32ce23458faaaae453f6ba5a1180b1931385179e Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Mon, 26 May 2025 12:19:33 +1200 Subject: [PATCH 4/9] read_verilog: Mark struct as custom type Being a custom type means that it will be resolved *before* (e.g.) a wire can use it as a type. --- frontends/ast/simplify.cc | 1 + frontends/verilog/verilog_parser.y | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/ast/simplify.cc b/frontends/ast/simplify.cc index 55087c772..749767743 100644 --- a/frontends/ast/simplify.cc +++ b/frontends/ast/simplify.cc @@ -1433,6 +1433,7 @@ bool AstNode::simplify(bool const_fold, int stage, int width_hint, bool sign_hin current_ast_mod->children.push_back(wnode); } basic_prep = true; + is_custom_type = false; } break; diff --git a/frontends/verilog/verilog_parser.y b/frontends/verilog/verilog_parser.y index 9d0956c8e..68c3ec6ff 100644 --- a/frontends/verilog/verilog_parser.y +++ b/frontends/verilog/verilog_parser.y @@ -1855,7 +1855,7 @@ struct_decl: } ; -struct_type: struct_union { astbuf2 = $1; } struct_body { $$ = astbuf2; } +struct_type: struct_union { astbuf2 = $1; astbuf2->is_custom_type = true; } struct_body { $$ = astbuf2; } ; struct_union: From 0072a267cc5380963917fa2971b8198cbc54b635 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Thu, 29 May 2025 16:20:16 +1200 Subject: [PATCH 5/9] write_aiger: Add no-sort option Prevents sorting input/output bits so that they remain in the same order they were read in. --- backends/aiger/aiger.cc | 70 ++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/backends/aiger/aiger.cc b/backends/aiger/aiger.cc index 617d7d85f..3da98d79d 100644 --- a/backends/aiger/aiger.cc +++ b/backends/aiger/aiger.cc @@ -132,7 +132,7 @@ struct AigerWriter return a; } - AigerWriter(Module *module, bool zinit_mode, bool imode, bool omode, bool bmode, bool lmode) : module(module), zinit_mode(zinit_mode), sigmap(module) + AigerWriter(Module *module, bool no_sort, bool zinit_mode, bool imode, bool omode, bool bmode, bool lmode) : module(module), zinit_mode(zinit_mode), sigmap(module) { pool undriven_bits; pool unused_bits; @@ -152,6 +152,34 @@ struct AigerWriter if (wire->port_input) sigmap.add(wire); + // handle ports + for (auto riter = module->ports.rbegin(); riter != module->ports.rend(); ++riter) { + auto *wire = module->wire(*riter); + for (int i = 0; i < GetSize(wire); i++) + { + SigBit wirebit(wire, i); + SigBit bit = sigmap(wirebit); + + if (bit.wire == nullptr) { + if (wire->port_output) { + aig_map[wirebit] = (bit == State::S1) ? 1 : 0; + output_bits.insert(wirebit); + } + continue; + } + + if (wire->port_input) + input_bits.insert(bit); + + if (wire->port_output) { + if (bit != wirebit) + alias_map[wirebit] = bit; + output_bits.insert(wirebit); + } + } + } + + // handle wires for (auto wire : module->wires()) { if (wire->attributes.count(ID::init)) { @@ -167,25 +195,13 @@ struct AigerWriter SigBit wirebit(wire, i); SigBit bit = sigmap(wirebit); - if (bit.wire == nullptr) { - if (wire->port_output) { - aig_map[wirebit] = (bit == State::S1) ? 1 : 0; - output_bits.insert(wirebit); - } + if (bit.wire == nullptr) + continue; + if (wire->port_input || wire->port_output) continue; - } undriven_bits.insert(bit); unused_bits.insert(bit); - - if (wire->port_input) - input_bits.insert(bit); - - if (wire->port_output) { - if (bit != wirebit) - alias_map[wirebit] = bit; - output_bits.insert(wirebit); - } } if (wire->width == 1) { @@ -200,12 +216,6 @@ struct AigerWriter } } - for (auto bit : input_bits) - undriven_bits.erase(bit); - - for (auto bit : output_bits) - unused_bits.erase(bit); - for (auto cell : module->cells()) { if (cell->type == ID($_NOT_)) @@ -343,8 +353,10 @@ struct AigerWriter } init_map.sort(); - input_bits.sort(); - output_bits.sort(); + if (!no_sort) { + input_bits.sort(); + output_bits.sort(); + } not_map.sort(); ff_map.sort(); and_map.sort(); @@ -901,6 +913,9 @@ struct AigerBackend : public Backend { log(" -symbols\n"); log(" include a symbol table in the generated AIGER file\n"); log("\n"); + log(" -no-sort\n"); + log(" don't sort input/output ports\n"); + log("\n"); log(" -map \n"); log(" write an extra file with port and latch symbols\n"); log("\n"); @@ -925,6 +940,7 @@ struct AigerBackend : public Backend { bool zinit_mode = false; bool miter_mode = false; bool symbols_mode = false; + bool no_sort = false; bool verbose_map = false; bool imode = false; bool omode = false; @@ -955,6 +971,10 @@ struct AigerBackend : public Backend { symbols_mode = true; continue; } + if (args[argidx] == "-no-sort") { + no_sort = true; + continue; + } if (map_filename.empty() && args[argidx] == "-map" && argidx+1 < args.size()) { map_filename = args[++argidx]; continue; @@ -1008,7 +1028,7 @@ struct AigerBackend : public Backend { if (!top_module->memories.empty()) log_error("Found unmapped memories in module %s: unmapped memories are not supported in AIGER backend!\n", log_id(top_module)); - AigerWriter writer(top_module, zinit_mode, imode, omode, bmode, lmode); + AigerWriter writer(top_module, no_sort, zinit_mode, imode, omode, bmode, lmode); writer.write_aiger(*f, ascii_mode, miter_mode, symbols_mode); if (!map_filename.empty()) { From e421a03d5aab5b16d86b4c4b2b8d842b064281ab Mon Sep 17 00:00:00 2001 From: Lofty Date: Fri, 30 May 2025 22:05:54 +0100 Subject: [PATCH 6/9] CODEOWNERS: add myself for the ABC doc --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) diff --git a/CODEOWNERS b/CODEOWNERS index 879bb8dee..ef8c803ed 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -20,6 +20,7 @@ passes/opt/opt_lut.cc @whitequark passes/techmap/abc9*.cc @eddiehung @Ravenslofty backends/aiger/xaiger.cc @eddiehung docs/ @KrystalDelusion +docs/source/using_yosys/synthesis/abc.rst @KrystalDelusion @Ravenslofty .github/workflows/*.yml @mmicko ## External Contributors From 06db8828b2aa4c06f9bd5dae069a016026abadc0 Mon Sep 17 00:00:00 2001 From: KrystalDelusion <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 31 May 2025 09:10:27 +1200 Subject: [PATCH 7/9] abc.rst: Clarify larger-but-slower --- docs/source/using_yosys/synthesis/abc.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/using_yosys/synthesis/abc.rst b/docs/source/using_yosys/synthesis/abc.rst index 0b24af3a1..ba12cabc1 100644 --- a/docs/source/using_yosys/synthesis/abc.rst +++ b/docs/source/using_yosys/synthesis/abc.rst @@ -176,5 +176,6 @@ implemented as whiteboxes too. Boxes are arguably the biggest advantage that ABC9 has over ABC: by being aware of carry chains and DSPs, it avoids optimising for a path that isn't the actual critical path, while the generally-longer paths result in ABC9 being able to -reduce design area by mapping other logic to smaller-but-slower cells. +reduce design area by mapping other logic to slower cells with greater logic +density. From aac562d36af6c8bf16072c2cc8ed0a2f778a3413 Mon Sep 17 00:00:00 2001 From: Krystine Sherwin <93062060+KrystalDelusion@users.noreply.github.com> Date: Sat, 31 May 2025 09:55:00 +1200 Subject: [PATCH 8/9] aiger.cc: Explicit unsorted-pool-as-LIFO --- backends/aiger/aiger.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backends/aiger/aiger.cc b/backends/aiger/aiger.cc index 3da98d79d..5b07a7195 100644 --- a/backends/aiger/aiger.cc +++ b/backends/aiger/aiger.cc @@ -153,6 +153,9 @@ struct AigerWriter sigmap.add(wire); // handle ports + // provided the input_bits and output_bits don't get sorted they + // will be returned in reverse order, so add them in reverse to + // match for (auto riter = module->ports.rbegin(); riter != module->ports.rend(); ++riter) { auto *wire = module->wire(*riter); for (int i = 0; i < GetSize(wire); i++) @@ -353,6 +356,7 @@ struct AigerWriter } init_map.sort(); + // we are relying here on unsorted pools iterating last-in-first-out if (!no_sort) { input_bits.sort(); output_bits.sort(); From 86282027c047c965f29d067e59a5c2bd17bf6a69 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 31 May 2025 00:23:36 +0000 Subject: [PATCH 9/9] Bump version --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ebf886d52..cff6796c3 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,7 @@ ifeq ($(OS), Haiku) CXXFLAGS += -D_DEFAULT_SOURCE endif -YOSYS_VER := 0.53+70 +YOSYS_VER := 0.53+81 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)