From e394197bc5048e97effacb56b5e963fc64b1ab26 Mon Sep 17 00:00:00 2001 From: tondapusili Date: Fri, 6 Mar 2026 15:51:58 -0800 Subject: [PATCH] rtlil: parameterize SigSpec::is_mostly_const --- kernel/rtlil.cc | 4 ++-- kernel/rtlil.h | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 266aedfe0..9b3ee4cf3 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -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 diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 9dfe0c570..7044e609a 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -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;