From 7325863db26ab2eb9d129493315f08e1f503ec96 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Wed, 17 Jul 2024 18:57:47 +0200 Subject: [PATCH] sigspec: move construct --- kernel/rtlil.cc | 33 ++++++--------------------------- kernel/rtlil.h | 16 +++++++--------- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index a76e0d713..411ae31ef 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -4020,28 +4020,6 @@ RTLIL::SigSpec::SigSpec(bool bit) check(); } -void RTLIL::SigSpec::switch_to_packed() const -{ - // TODO change to debug asserts - // log_assert(!this->packed_); - // log_assert(bits_.size() == 0); - RTLIL::SigSpec *that = (RTLIL::SigSpec*)this; - that->bits_.~vector(); - that->packed_ = true; - (void)new (&that->chunks_) std::vector(); -} - -void RTLIL::SigSpec::switch_to_unpacked() const -{ - // TODO change to debug asserts - // log_assert(this->packed_); - // log_assert(chunks_.size() == 0); - RTLIL::SigSpec *that = (RTLIL::SigSpec*)this; - that->chunks_.~vector(); - that->packed_ = false; - (void)new (&that->bits_) std::vector(); -} - void RTLIL::SigSpec::pack() const { RTLIL::SigSpec *that = (RTLIL::SigSpec*)this; @@ -4075,8 +4053,9 @@ void RTLIL::SigSpec::pack() const last_end_offset = bit.offset + 1; } - that->switch_to_packed(); - that->chunks_.swap(new_chunks); + that->bits_.~vector(); + that->packed_ = true; + (void)new (&that->chunks_) std::vector(std::move(new_chunks)); check(); } @@ -4096,10 +4075,10 @@ void RTLIL::SigSpec::unpack() const for (int i = 0; i < c.width; i++) new_bits.emplace_back(c, i); - that->chunks_.clear(); that->hash_ = 0; - that->switch_to_unpacked(); - that->bits_.swap(new_bits); + that->chunks_.~vector(); + that->packed_ = false; + (void)new (&that->bits_) std::vector(std::move(new_bits)); } void RTLIL::SigSpec::updhash() const diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 179e892ec..5bd69a43f 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -838,7 +838,7 @@ struct RTLIL::SigSpecConstIterator inline void operator++() { index++; } }; -struct RTLIL::SigSpec +struct alignas(64) RTLIL::SigSpec { private: int width_; @@ -851,8 +851,6 @@ private: void pack() const; void unpack() const; - void switch_to_packed() const; - void switch_to_unpacked() const; void updhash() const; inline bool packed() const { @@ -890,13 +888,13 @@ public: { if (packed_ != other.packed_) { if (packed_) { - chunks_.clear(); - switch_to_unpacked(); - bits_ = other.bits_; + chunks_.~vector(); + packed_ = false; + (void)new (&bits_) std::vector(other.bits_); } else { - bits_.clear(); - switch_to_packed(); - chunks_ = other.chunks_; + bits_.~vector(); + packed_ = true; + (void)new (&chunks_) std::vector(other.chunks_); } } else { if (packed_)