Skip to content

Commit 08479a0

Browse files
committed
proc_dff: optimize repeated values at bit granularity
1 parent ed989f8 commit 08479a0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

passes/proc/proc_dff.cc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,24 @@ class Dff {
154154

155155
// Combine adjacent async rules that assign the same value into one rule
156156
// with a disjunction of triggers. The resulting trigger is optimized by
157-
// constant evaluation.
157+
// constant evaluation. We apply all of these optimizations that can be
158+
// done to the LSB and shrink the size of the signal we are considering if
159+
// higher bits cannot be optimized in the same way.
158160
void optimize_same_value(ConstEval& ce) {
159161
for (size_t i = 0; i + 1 < async_rules.size();) {
160-
if (async_rules[i].value != async_rules[i + 1].value) {
162+
const auto bit_optimizable = [&](const size_t bit) {
163+
return async_rules[i].value[bit] == async_rules[i + 1].value[bit];
164+
};
165+
166+
const bool lsb_optimizable = bit_optimizable(0);
167+
168+
size_t new_size;
169+
for (new_size = 1; new_size < size(); new_size++)
170+
if (bit_optimizable(new_size) != lsb_optimizable)
171+
break;
172+
resize(new_size);
173+
174+
if (!lsb_optimizable) {
161175
i++;
162176
continue;
163177
}

0 commit comments

Comments
 (0)