From 9378bbf3373201754220e2ced28a86abb967681d Mon Sep 17 00:00:00 2001 From: mjoekhan Date: Tue, 21 Jul 2026 11:48:54 +0500 Subject: [PATCH] SV: address review feedback for array ordering methods Drop redundant eeq checks in descending vec4 sorts, brace reverse loops, and merge duplicate queue/darray class-property method elab. --- elaborate.cc | 51 ++++++++++------------------------------------- vvp/vvp_darray.cc | 22 ++++++++++---------- 2 files changed, 22 insertions(+), 51 deletions(-) diff --git a/elaborate.cc b/elaborate.cc index 214a72f88..5fb337569 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -4336,11 +4336,14 @@ NetProc* PCallTask::elaborate_method_(Design*des, NetScope*scope, int pidx = cls->property_idx_from_name(prop_name); if (pidx >= 0) { ivl_type_t ptype = cls->get_prop_type(pidx); - if (ptype && dynamic_cast(ptype)) { + if (ptype && + (dynamic_cast(ptype) || + ptype->base_type() == IVL_VT_DARRAY)) { + const netqueue_t*queue = dynamic_cast(ptype); const netdarray_t*use_darray = dynamic_cast(ptype); ivl_assert(*this, use_darray); - if (method_name == "push_back") { + if (queue && method_name == "push_back") { static const std::vector parm_names = { perm_string::literal("item") }; @@ -4349,7 +4352,7 @@ NetProc* PCallTask::elaborate_method_(Design*des, NetScope*scope, "$ivl_queue_method$push_back", parm_names); } - if (method_name == "push_front") { + if (queue && method_name == "push_front") { static const std::vector parm_names = { perm_string::literal("item") }; @@ -4358,7 +4361,7 @@ NetProc* PCallTask::elaborate_method_(Design*des, NetScope*scope, "$ivl_queue_method$push_front", parm_names); } - if (method_name == "insert") { + if (queue && method_name == "insert") { static const std::vector parm_names = { perm_string::literal("index"), perm_string::literal("item") @@ -4368,53 +4371,19 @@ NetProc* PCallTask::elaborate_method_(Design*des, NetScope*scope, "$ivl_queue_method$insert", parm_names); } - if (method_name == "pop_front") { + if (queue && method_name == "pop_front") { return elaborate_method_property_func_(scope, net, pidx, use_darray->element_type(), method_name, "$ivl_queue_method$pop_front"); } - if (method_name == "pop_back") { + if (queue && method_name == "pop_back") { return elaborate_method_property_func_(scope, net, pidx, use_darray->element_type(), method_name, "$ivl_queue_method$pop_back"); } - if (method_name == "size") { - return elaborate_method_property_func_(scope, net, pidx, - &netvector_t::atom2s32, - method_name, "$size"); - } - if (method_name == "reverse") { - static const std::vector parm_names; - return elaborate_sys_task_property_method_(des, scope, net, pidx, - method_name, - "$ivl_darray_method$reverse", - parm_names); - } - if (method_name == "sort") { - static const std::vector parm_names; - return elaborate_sys_task_property_method_(des, scope, net, pidx, - method_name, - "$ivl_darray_method$sort", - parm_names); - } - if (method_name == "rsort") { - static const std::vector parm_names; - return elaborate_sys_task_property_method_(des, scope, net, pidx, - method_name, - "$ivl_darray_method$rsort", - parm_names); - } - if (method_name == "shuffle") { - static const std::vector parm_names; - return elaborate_sys_task_property_method_(des, scope, net, pidx, - method_name, - "$ivl_darray_method$shuffle", - parm_names); - } - } else if (ptype && ptype->base_type() == IVL_VT_DARRAY) { - if (method_name == "delete") { + if (!queue && method_name == "delete") { static const std::vector parm_names = { perm_string::literal("index") }; diff --git a/vvp/vvp_darray.cc b/vvp/vvp_darray.cc index 94157ce5c..b258c5a9d 100644 --- a/vvp/vvp_darray.cc +++ b/vvp/vvp_darray.cc @@ -124,8 +124,9 @@ template size_t vvp_darray_atom::get_size() const template void vvp_darray_atom::reverse_elems(void) { size_t n = array_.size(); - for (size_t idx = 0 ; idx < n/2 ; idx += 1) + for (size_t idx = 0 ; idx < n/2 ; idx += 1) { std::swap(array_[idx], array_[n-1-idx]); + } } template void vvp_darray_atom::sort_elems(bool ascending) @@ -285,8 +286,9 @@ vvp_vector4_t vvp_darray_vec4::get_bitstream(bool as_vec4) void vvp_darray_vec4::reverse_elems(void) { size_t n = array_.size(); - for (size_t idx = 0 ; idx < n/2 ; idx += 1) + for (size_t idx = 0 ; idx < n/2 ; idx += 1) { std::swap(array_[idx], array_[n-1-idx]); + } } void vvp_darray_vec4::sort_elems(bool ascending) @@ -296,8 +298,6 @@ void vvp_darray_vec4::sort_elems(bool ascending) } else { std::sort(array_.begin(), array_.end(), [](const vvp_vector4_t&a, const vvp_vector4_t&b) { - if (a.eeq(b)) - return false; return vec4_lt_unsigned(b, a); }); } @@ -311,8 +311,9 @@ void vvp_darray_vec4::shuffle_elems(void) void vvp_darray_vec2::reverse_elems(void) { size_t n = array_.size(); - for (size_t idx = 0 ; idx < n/2 ; idx += 1) + for (size_t idx = 0 ; idx < n/2 ; idx += 1) { std::swap(array_[idx], array_[n-1-idx]); + } } void vvp_darray_vec2::sort_elems(bool ascending) @@ -432,8 +433,9 @@ void vvp_darray_object::shallow_copy(const vvp_object*obj) void vvp_darray_object::reverse_elems(void) { size_t n = array_.size(); - for (size_t idx = 0 ; idx < n/2 ; idx += 1) + for (size_t idx = 0 ; idx < n/2 ; idx += 1) { std::swap(array_[idx], array_[n-1-idx]); + } } void vvp_darray_object::sort_elems(bool ascending) @@ -495,8 +497,9 @@ void vvp_darray_real::shallow_copy(const vvp_object*obj) void vvp_darray_real::reverse_elems(void) { size_t n = array_.size(); - for (size_t idx = 0 ; idx < n/2 ; idx += 1) + for (size_t idx = 0 ; idx < n/2 ; idx += 1) { std::swap(array_[idx], array_[n-1-idx]); + } } void vvp_darray_real::sort_elems(bool ascending) @@ -585,8 +588,9 @@ void vvp_darray_string::shallow_copy(const vvp_object*obj) void vvp_darray_string::reverse_elems(void) { size_t n = array_.size(); - for (size_t idx = 0 ; idx < n/2 ; idx += 1) + for (size_t idx = 0 ; idx < n/2 ; idx += 1) { std::swap(array_[idx], array_[n-1-idx]); + } } void vvp_darray_string::sort_elems(bool ascending) @@ -1091,8 +1095,6 @@ void vvp_queue_vec4::sort_elems(bool ascending) } else { std::sort(queue.begin(), queue.end(), [](const vvp_vector4_t&a, const vvp_vector4_t&b) { - if (a.eeq(b)) - return false; return vec4_lt_unsigned(b, a); }); }