From 9e26147ccd9c1b33aa9bd3c781f9bbb945378ae7 Mon Sep 17 00:00:00 2001 From: Rick Altherr Date: Fri, 29 Jan 2016 22:40:17 -0800 Subject: rtlil: change IdString comparison operators to take references instead of copies --- kernel/rtlil.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'kernel') diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 7b669536e..0444834ac 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -192,12 +192,12 @@ namespace RTLIL return std::string(global_id_storage_.at(index_)); } - bool operator<(IdString rhs) const { + bool operator<(const IdString &rhs) const { return index_ < rhs.index_; } - bool operator==(IdString rhs) const { return index_ == rhs.index_; } - bool operator!=(IdString rhs) const { return index_ != rhs.index_; } + bool operator==(const IdString &rhs) const { return index_ == rhs.index_; } + bool operator!=(const IdString &rhs) const { return index_ != rhs.index_; } // The methods below are just convenience functions for better compatibility with std::string. -- cgit v1.2.3 From 12ebdef17c66bc5d1fc9acf6fdafac0795f872f3 Mon Sep 17 00:00:00 2001 From: Rick Altherr Date: Fri, 29 Jan 2016 22:03:12 -0800 Subject: rtlil: duplicate remove2() for std::set<> --- kernel/rtlil.cc | 39 +++++++++++++++++++++++++++++++++++++++ kernel/rtlil.h | 2 ++ 2 files changed, 41 insertions(+) (limited to 'kernel') diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 4403bcfdc..dfccc78f8 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -2718,6 +2718,45 @@ void RTLIL::SigSpec::remove2(const pool &pattern, RTLIL::SigSpec check(); } +void RTLIL::SigSpec::remove2(const std::set &pattern, RTLIL::SigSpec *other) +{ + if (other) + cover("kernel.rtlil.sigspec.remove_other"); + else + cover("kernel.rtlil.sigspec.remove"); + + unpack(); + + if (other != NULL) { + log_assert(width_ == other->width_); + other->unpack(); + } + + std::vector new_bits, new_other_bits; + + new_bits.reserve(GetSize(bits_)); + if (other != NULL) + new_other_bits.reserve(GetSize(bits_)); + + for (int i = 0; i < GetSize(bits_); i++) { + if (bits_[i].wire != NULL && pattern.count(bits_[i])) + continue; + if (other != NULL) + new_other_bits.push_back(other->bits_[i]); + new_bits.push_back(bits_[i]); + } + + bits_.swap(new_bits); + width_ = GetSize(bits_); + + if (other != NULL) { + other->bits_.swap(new_other_bits); + other->width_ = GetSize(other->bits_); + } + + check(); +} + RTLIL::SigSpec RTLIL::SigSpec::extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other) const { pool pattern_bits = pattern.to_sigbit_pool(); diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 0444834ac..5dff5579f 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -670,6 +670,8 @@ public: void remove(const pool &pattern, RTLIL::SigSpec *other) const; void remove2(const pool &pattern, RTLIL::SigSpec *other); + void remove2(const std::set &pattern, RTLIL::SigSpec *other); + void remove(int offset, int length = 1); void remove_const(); -- cgit v1.2.3 From 43756559d8b2e0c19deaa95b45832c1acb837907 Mon Sep 17 00:00:00 2001 From: Rick Altherr Date: Fri, 29 Jan 2016 22:40:45 -0800 Subject: rtlil: rewrite remove2() to avoid copying --- kernel/rtlil.cc | 63 +++++++++++++++++---------------------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) (limited to 'kernel') diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index dfccc78f8..7878eaae7 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -2688,31 +2688,15 @@ void RTLIL::SigSpec::remove2(const pool &pattern, RTLIL::SigSpec other->unpack(); } - std::vector new_bits, new_other_bits; - - new_bits.resize(GetSize(bits_)); - if (other != NULL) - new_other_bits.resize(GetSize(bits_)); - - int k = 0; - for (int i = 0; i < GetSize(bits_); i++) { - if (bits_[i].wire != NULL && pattern.count(bits_[i])) - continue; - if (other != NULL) - new_other_bits[k] = other->bits_[i]; - new_bits[k++] = bits_[i]; - } - - new_bits.resize(k); - if (other != NULL) - new_other_bits.resize(k); - - bits_.swap(new_bits); - width_ = GetSize(bits_); - - if (other != NULL) { - other->bits_.swap(new_other_bits); - other->width_ = GetSize(other->bits_); + for (int i = GetSize(bits_) - 1; i >= 0; i--) { + if (bits_[i].wire != NULL && pattern.count(bits_[i])) { + bits_.erase(bits_.begin() + i); + width_--; + if (other != NULL) { + other->bits_.erase(other->bits_.begin() + i); + other->width_--; + } + } } check(); @@ -2732,26 +2716,15 @@ void RTLIL::SigSpec::remove2(const std::set &pattern, RTLIL::SigS other->unpack(); } - std::vector new_bits, new_other_bits; - - new_bits.reserve(GetSize(bits_)); - if (other != NULL) - new_other_bits.reserve(GetSize(bits_)); - - for (int i = 0; i < GetSize(bits_); i++) { - if (bits_[i].wire != NULL && pattern.count(bits_[i])) - continue; - if (other != NULL) - new_other_bits.push_back(other->bits_[i]); - new_bits.push_back(bits_[i]); - } - - bits_.swap(new_bits); - width_ = GetSize(bits_); - - if (other != NULL) { - other->bits_.swap(new_other_bits); - other->width_ = GetSize(other->bits_); + for (int i = GetSize(bits_) - 1; i >= 0; i--) { + if (bits_[i].wire != NULL && pattern.count(bits_[i])) { + bits_.erase(bits_.begin() + i); + width_--; + if (other != NULL) { + other->bits_.erase(other->bits_.begin() + i); + other->width_--; + } + } } check(); -- cgit v1.2.3