From 08479a0ceca75f84dc0f39e587c32ed73df2b678 Mon Sep 17 00:00:00 2001 From: George Rennie Date: Thu, 28 Nov 2024 17:49:52 +0100 Subject: [PATCH] proc_dff: optimize repeated values at bit granularity --- passes/proc/proc_dff.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/passes/proc/proc_dff.cc b/passes/proc/proc_dff.cc index d6b23bfc4cb..d3209f81f67 100644 --- a/passes/proc/proc_dff.cc +++ b/passes/proc/proc_dff.cc @@ -154,10 +154,24 @@ class Dff { // Combine adjacent async rules that assign the same value into one rule // with a disjunction of triggers. The resulting trigger is optimized by - // constant evaluation. + // constant evaluation. We apply all of these optimizations that can be + // done to the LSB and shrink the size of the signal we are considering if + // higher bits cannot be optimized in the same way. void optimize_same_value(ConstEval& ce) { for (size_t i = 0; i + 1 < async_rules.size();) { - if (async_rules[i].value != async_rules[i + 1].value) { + const auto bit_optimizable = [&](const size_t bit) { + return async_rules[i].value[bit] == async_rules[i + 1].value[bit]; + }; + + const bool lsb_optimizable = bit_optimizable(0); + + size_t new_size; + for (new_size = 1; new_size < size(); new_size++) + if (bit_optimizable(new_size) != lsb_optimizable) + break; + resize(new_size); + + if (!lsb_optimizable) { i++; continue; }