From 23b3638c1e9a67c49e7e5f1208250c3e786da47a Mon Sep 17 00:00:00 2001 From: Adrian Parvin Ouano Date: Wed, 11 Oct 2023 06:59:04 +0800 Subject: [PATCH 1/2] alumacc: alternative cmp unification implementation --- passes/techmap/alumacc.cc | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/passes/techmap/alumacc.cc b/passes/techmap/alumacc.cc index d89a6fbec..040569745 100644 --- a/passes/techmap/alumacc.cc +++ b/passes/techmap/alumacc.cc @@ -405,11 +405,6 @@ struct AlumaccWorker RTLIL::SigSpec B = sigmap(cell->getPort(ID::B)); RTLIL::SigSpec Y = sigmap(cell->getPort(ID::Y)); - if (B < A && GetSize(B)) { - cmp_less = !cmp_less; - std::swap(A, B); - } - alunode_t *n = nullptr; for (auto node : sig_alu[RTLIL::SigSig(A, B)]) @@ -418,6 +413,16 @@ struct AlumaccWorker break; } + if (n == nullptr) { + for (auto node : sig_alu[RTLIL::SigSig(B, A)]) + if (node->invert_b && node->c == State::S1) { + n = node; + cmp_less = !cmp_less; + std::swap(A, B); + break; + } + } + if (n == nullptr) { n = new alunode_t; n->a = A; @@ -445,9 +450,6 @@ struct AlumaccWorker RTLIL::SigSpec B = sigmap(cell->getPort(ID::B)); RTLIL::SigSpec Y = sigmap(cell->getPort(ID::Y)); - if (B < A && GetSize(B)) - std::swap(A, B); - alunode_t *n = nullptr; for (auto node : sig_alu[RTLIL::SigSig(A, B)]) @@ -456,6 +458,14 @@ struct AlumaccWorker break; } + if (n == nullptr) { + for (auto node : sig_alu[RTLIL::SigSig(B, A)]) + if (node->invert_b && node->c == State::S1) { + n = node; + break; + } + } + if (n != nullptr) { log(" creating $alu model for %s (%s): merged with %s.\n", log_id(cell), log_id(cell->type), log_id(n->cells.front())); n->cells.push_back(cell); From b5752dfe16470acacf28c81a5447f0e2a8488e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Tue, 4 Feb 2025 13:05:53 +0100 Subject: [PATCH 2/2] alumacc: Fix missing signedness check --- passes/techmap/alumacc.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/passes/techmap/alumacc.cc b/passes/techmap/alumacc.cc index 040569745..591c51c74 100644 --- a/passes/techmap/alumacc.cc +++ b/passes/techmap/alumacc.cc @@ -415,7 +415,7 @@ struct AlumaccWorker if (n == nullptr) { for (auto node : sig_alu[RTLIL::SigSig(B, A)]) - if (node->invert_b && node->c == State::S1) { + if (node->is_signed == is_signed && node->invert_b && node->c == State::S1) { n = node; cmp_less = !cmp_less; std::swap(A, B); @@ -460,7 +460,7 @@ struct AlumaccWorker if (n == nullptr) { for (auto node : sig_alu[RTLIL::SigSig(B, A)]) - if (node->invert_b && node->c == State::S1) { + if (node->is_signed == is_signed && node->invert_b && node->c == State::S1) { n = node; break; }