From 7d33fd463b2291954c7f9ca1f2dbeff3843a63ea Mon Sep 17 00:00:00 2001 From: Akash Levy Date: Thu, 13 Feb 2025 11:11:33 -0800 Subject: [PATCH] Add is_mostly_const to SigSpec --- kernel/rtlil.cc | 12 ++++++++++++ kernel/rtlil.h | 1 + 2 files changed, 13 insertions(+) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 97968b5f5..8f3a72e6f 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -5164,6 +5164,18 @@ bool RTLIL::SigSpec::is_chunk() const return GetSize(chunks_) == 1; } +bool RTLIL::SigSpec::is_mostly_const() const +{ + cover("kernel.rtlil.sigspec.is_mostly_const"); + + pack(); + int constbits = 0; + for (auto it = chunks_.begin(); it != chunks_.end(); it++) + if (it->width > 0 && it->wire == NULL) + constbits += it->width; + return (constbits > width_/2); +} + bool RTLIL::SigSpec::is_fully_const() const { cover("kernel.rtlil.sigspec.is_fully_const"); diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 4ddce7d25..f77869a82 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -1094,6 +1094,7 @@ public: bool is_chunk() const; inline bool is_bit() const { return width_ == 1; } + bool is_mostly_const() const; bool is_fully_const() const; bool is_fully_zero() const; bool is_fully_ones() const;