From aa3942ab249f89610d8bc38e3dc0a2c4f04f1662 Mon Sep 17 00:00:00 2001 From: Trung Nguyen <57174311+trungnt2910@users.noreply.github.com> Date: Mon, 10 Feb 2025 14:45:50 +1100 Subject: [PATCH] Internals: `constexpr` for `VlUnpacked` data access (#5725) (#5770) Add `constexpr` to data access functions of `VlUnpacked` whose `std::array` equivalent in C++14 is `constexpr`. --- docs/CONTRIBUTORS | 1 + include/verilated_types.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index 9fd2ac91ea..5fffcca538 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -215,6 +215,7 @@ Todd Strader Tomasz Gorochowik Topa Topino Toru Niina +Trung Nguyen Tudor Timi Tymoteusz Blazejczyk Udi Finkelstein diff --git a/include/verilated_types.h b/include/verilated_types.h index c7ef5e35dd..3f8b7006d0 100644 --- a/include/verilated_types.h +++ b/include/verilated_types.h @@ -1319,7 +1319,7 @@ class VlUnpacked final { WData* data() { return &m_storage[0]; } const WData* data() const { return &m_storage[0]; } - std::size_t size() const { return N_Depth; } + constexpr std::size_t size() const { return N_Depth; } // To fit C++14 template int find_length(int dimension, std::false_type) const { @@ -1357,7 +1357,7 @@ class VlUnpacked final { } T_Value& operator[](size_t index) { return m_storage[index]; } - const T_Value& operator[](size_t index) const { return m_storage[index]; } + constexpr const T_Value& operator[](size_t index) const { return m_storage[index]; } // *this != that, which might be used for change detection/trigger computation, but avoid // operator overloading in VlUnpacked for safety in other contexts.