From 1c73011e7e8236c88157d37bd22a456b47c459d1 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Thu, 25 Sep 2025 03:04:17 +0000 Subject: [PATCH 1/2] Swap SigSpecs using std::swap with moves --- kernel/rtlil.h | 6 +++++- passes/opt/opt_merge.cc | 9 +++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 88594859a..e240cf885 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -1244,7 +1244,8 @@ private: public: SigSpec() : width_(0), hash_(0) {} SigSpec(std::initializer_list parts); - + SigSpec(const SigSpec &) = default; + SigSpec(SigSpec &&) = default; SigSpec(const RTLIL::Const &value); SigSpec(RTLIL::Const &&value); SigSpec(const RTLIL::SigChunk &chunk); @@ -1261,6 +1262,9 @@ public: SigSpec(const std::set &bits); explicit SigSpec(bool bit); + SigSpec &operator=(const SigSpec &rhs) = default; + SigSpec &operator=(SigSpec &&rhs) = default; + inline const std::vector &chunks() const { pack(); return chunks_; } inline const std::vector &bits() const { inline_unpack(); return bits_; } diff --git a/passes/opt/opt_merge.cc b/passes/opt/opt_merge.cc index 541459c27..e1c3f0269 100644 --- a/passes/opt/opt_merge.cc +++ b/passes/opt/opt_merge.cc @@ -25,6 +25,7 @@ #include "libs/sha1/sha1.h" #include #include +#include #include #include #include @@ -173,14 +174,10 @@ struct OptMergeWorker if (cell1->type == ID($and) || cell1->type == ID($or) || cell1->type == ID($xor) || cell1->type == ID($xnor) || cell1->type == ID($add) || cell1->type == ID($mul) || cell1->type == ID($logic_and) || cell1->type == ID($logic_or) || cell1->type == ID($_AND_) || cell1->type == ID($_OR_) || cell1->type == ID($_XOR_)) { if (conn1.at(ID::A) < conn1.at(ID::B)) { - RTLIL::SigSpec tmp = conn1[ID::A]; - conn1[ID::A] = conn1[ID::B]; - conn1[ID::B] = tmp; + std::swap(conn1[ID::A], conn1[ID::B]); } if (conn2.at(ID::A) < conn2.at(ID::B)) { - RTLIL::SigSpec tmp = conn2[ID::A]; - conn2[ID::A] = conn2[ID::B]; - conn2[ID::B] = tmp; + std::swap(conn2[ID::A], conn2[ID::B]); } } else if (cell1->type == ID($reduce_xor) || cell1->type == ID($reduce_xnor)) { From 4d209c187d02cb858701a1b4777d73c90cb80592 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Wed, 17 Sep 2025 02:52:30 +0000 Subject: [PATCH 2/2] Switch OptMergeWorker cell type switching to use IdString::in() --- passes/opt/opt_merge.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/passes/opt/opt_merge.cc b/passes/opt/opt_merge.cc index e1c3f0269..13b1cb293 100644 --- a/passes/opt/opt_merge.cc +++ b/passes/opt/opt_merge.cc @@ -171,8 +171,8 @@ struct OptMergeWorker } } - if (cell1->type == ID($and) || cell1->type == ID($or) || cell1->type == ID($xor) || cell1->type == ID($xnor) || cell1->type == ID($add) || cell1->type == ID($mul) || - cell1->type == ID($logic_and) || cell1->type == ID($logic_or) || cell1->type == ID($_AND_) || cell1->type == ID($_OR_) || cell1->type == ID($_XOR_)) { + if (cell1->type.in(ID($and), ID($or), ID($xor), ID($xnor), ID($add), ID($mul), + ID($logic_and), ID($logic_or), ID($_AND_), ID($_OR_), ID($_XOR_))) { if (conn1.at(ID::A) < conn1.at(ID::B)) { std::swap(conn1[ID::A], conn1[ID::B]); } @@ -180,11 +180,11 @@ struct OptMergeWorker std::swap(conn2[ID::A], conn2[ID::B]); } } else - if (cell1->type == ID($reduce_xor) || cell1->type == ID($reduce_xnor)) { + if (cell1->type.in(ID($reduce_xor), ID($reduce_xnor))) { conn1[ID::A].sort(); conn2[ID::A].sort(); } else - if (cell1->type == ID($reduce_and) || cell1->type == ID($reduce_or) || cell1->type == ID($reduce_bool)) { + if (cell1->type.in(ID($reduce_and), ID($reduce_or), ID($reduce_bool))) { conn1[ID::A].sort_and_unify(); conn2[ID::A].sort_and_unify(); } else