rtlil: parameterize SigSpec::is_mostly_const

This commit is contained in:
tondapusili 2026-03-06 15:51:58 -08:00
parent a67471d7f9
commit e394197bc5
2 changed files with 5 additions and 3 deletions

View File

@ -5605,13 +5605,13 @@ bool RTLIL::SigSpec::is_chunk() const
return ++it == cs.end();
}
bool RTLIL::SigSpec::is_mostly_const() const
bool RTLIL::SigSpec::is_mostly_const(double const_ratio_threshold) const
{
int constbits = 0;
for (auto &chunk : chunks())
if (chunk.width > 0 && chunk.wire == NULL)
constbits += chunk.width;
return (constbits > size()/2);
return (constbits > size() * const_ratio_threshold);
}
bool RTLIL::SigSpec::known_driver() const

View File

@ -1684,7 +1684,9 @@ public:
bool known_driver() const;
bool is_mostly_const() const;
// const_ratio_threshold is expected in [0.0, 1.0]
// boundary is exclusive, returns true only if const bit ratio > const_ratio_threshold
bool is_mostly_const(double const_ratio_threshold = 0.5) const;
bool is_fully_const() const;
bool is_fully_zero() const;
bool is_fully_ones() const;