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.
This commit is contained in:
parent
f796a59367
commit
9378bbf337
51
elaborate.cc
51
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<const netqueue_t*>(ptype)) {
|
||||
if (ptype &&
|
||||
(dynamic_cast<const netqueue_t*>(ptype) ||
|
||||
ptype->base_type() == IVL_VT_DARRAY)) {
|
||||
const netqueue_t*queue = dynamic_cast<const netqueue_t*>(ptype);
|
||||
const netdarray_t*use_darray = dynamic_cast<const netdarray_t*>(ptype);
|
||||
ivl_assert(*this, use_darray);
|
||||
|
||||
if (method_name == "push_back") {
|
||||
if (queue && method_name == "push_back") {
|
||||
static const std::vector<perm_string> 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<perm_string> 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<perm_string> 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<perm_string> 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<perm_string> 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<perm_string> 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<perm_string> 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<perm_string> parm_names = {
|
||||
perm_string::literal("index")
|
||||
};
|
||||
|
|
|
|||
|
|
@ -124,8 +124,9 @@ template <class TYPE> size_t vvp_darray_atom<TYPE>::get_size() const
|
|||
template <class TYPE> void vvp_darray_atom<TYPE>::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 <class TYPE> void vvp_darray_atom<TYPE>::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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue