Add initial support for assigning between queues and darrays
This commit is contained in:
parent
3a70a84e68
commit
bff115b9f7
16
netdarray.cc
16
netdarray.cc
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012 Stephen Williams (steve@icarus.com)
|
* Copyright (c) 2012-2020 Stephen Williams (steve@icarus.com)
|
||||||
*
|
*
|
||||||
* This source code is free software; you can redistribute it
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* and/or modify it in source code form under the terms of the GNU
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
# include "netdarray.h"
|
# include "netdarray.h"
|
||||||
|
# include "netqueue.h"
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -38,9 +39,16 @@ ivl_variable_type_t netdarray_t::base_type(void) const
|
||||||
|
|
||||||
bool netdarray_t::test_compatibility(ivl_type_t that) const
|
bool netdarray_t::test_compatibility(ivl_type_t that) const
|
||||||
{
|
{
|
||||||
const netdarray_t*that_da = dynamic_cast<const netdarray_t*>(that);
|
ivl_type_t elem_type = 0;
|
||||||
if (that_da == 0)
|
|
||||||
|
if (const netdarray_t*that_da = dynamic_cast<const netdarray_t*>(that))
|
||||||
|
elem_type = that_da->element_type();
|
||||||
|
|
||||||
|
if (const netqueue_t*that_q = dynamic_cast<const netqueue_t*>(that))
|
||||||
|
elem_type = that_q->element_type();
|
||||||
|
|
||||||
|
if (elem_type == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return element_type()->type_compatible(that_da->element_type());
|
return element_type()->type_compatible(elem_type);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
13
netqueue.cc
13
netqueue.cc
|
|
@ -38,9 +38,16 @@ ivl_variable_type_t netqueue_t::base_type() const
|
||||||
|
|
||||||
bool netqueue_t::test_compatibility(ivl_type_t that) const
|
bool netqueue_t::test_compatibility(ivl_type_t that) const
|
||||||
{
|
{
|
||||||
const netqueue_t*that_q = dynamic_cast<const netqueue_t*>(that);
|
ivl_type_t elem_type = 0;
|
||||||
if (that_q == 0)
|
|
||||||
|
if (const netqueue_t*that_q = dynamic_cast<const netqueue_t*>(that))
|
||||||
|
elem_type = that_q->element_type();
|
||||||
|
|
||||||
|
if (const netdarray_t*that_da = dynamic_cast<const netdarray_t*>(that))
|
||||||
|
elem_type = that_da->element_type();
|
||||||
|
|
||||||
|
if (elem_type == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return element_type()->type_compatible(that_q->element_type());
|
return element_type()->type_compatible(elem_type);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -949,6 +949,7 @@ static int show_stmt_assign_darray_pattern(ivl_statement_t net)
|
||||||
else if (ivl_type_base(element_type) == IVL_VT_LOGIC)
|
else if (ivl_type_base(element_type) == IVL_VT_LOGIC)
|
||||||
element_width = width_of_packed_type(element_type);
|
element_width = width_of_packed_type(element_type);
|
||||||
#endif
|
#endif
|
||||||
|
// FIXME: This should allocate enough space for the pattern if needed.
|
||||||
assert(ivl_expr_type(rval) == IVL_EX_ARRAY_PATTERN);
|
assert(ivl_expr_type(rval) == IVL_EX_ARRAY_PATTERN);
|
||||||
for (idx = 0 ; idx < ivl_expr_parms(rval) ; idx += 1) {
|
for (idx = 0 ; idx < ivl_expr_parms(rval) ; idx += 1) {
|
||||||
switch (ivl_type_base(element_type)) {
|
switch (ivl_type_base(element_type)) {
|
||||||
|
|
@ -1073,7 +1074,7 @@ static int show_stmt_assign_queue_pattern(ivl_signal_t var, ivl_expr_t rval,
|
||||||
case IVL_VT_LOGIC:
|
case IVL_VT_LOGIC:
|
||||||
draw_eval_vec4(ivl_expr_parm(rval,idx));
|
draw_eval_vec4(ivl_expr_parm(rval,idx));
|
||||||
fprintf(vvp_out, " %%ix/load 3, %u, 0;\n", idx);
|
fprintf(vvp_out, " %%ix/load 3, %u, 0;\n", idx);
|
||||||
fprintf(vvp_out, " %%store/qdar/vec4 v%p_0, %d, %u;\n", var, max_idx,
|
fprintf(vvp_out, " %%store/qdar/v v%p_0, %d, %u;\n", var, max_idx,
|
||||||
width_of_packed_type(element_type));
|
width_of_packed_type(element_type));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -1135,51 +1136,56 @@ static int show_stmt_assign_sig_queue(ivl_statement_t net)
|
||||||
if (ivl_expr_type(rval) == IVL_EX_NULL) {
|
if (ivl_expr_type(rval) == IVL_EX_NULL) {
|
||||||
errors += draw_eval_object(rval);
|
errors += draw_eval_object(rval);
|
||||||
fprintf(vvp_out, " %%store/obj v%p_0;\n", var);
|
fprintf(vvp_out, " %%store/obj v%p_0;\n", var);
|
||||||
} else if (mux && (ivl_type_base(element_type)==IVL_VT_REAL)) {
|
|
||||||
|
} else if (mux && (ivl_type_base(element_type) == IVL_VT_REAL)) {
|
||||||
draw_eval_real(rval);
|
draw_eval_real(rval);
|
||||||
/* The %store/dar expects the array index to be in
|
/* The %store/dar expects the array index to be in
|
||||||
index register 3. */
|
index register 3. */
|
||||||
draw_eval_expr_into_integer(mux, 3);
|
draw_eval_expr_into_integer(mux, 3);
|
||||||
fprintf(vvp_out, " %%store/qdar/r v%p_0, %d;\n", var, idx);
|
fprintf(vvp_out, " %%store/qdar/r v%p_0, %d;\n", var, idx);
|
||||||
} else if (mux && ivl_type_base(element_type)==IVL_VT_STRING) {
|
|
||||||
|
} else if (mux && ivl_type_base(element_type) == IVL_VT_STRING) {
|
||||||
draw_eval_string(rval);
|
draw_eval_string(rval);
|
||||||
/* The %store/dar expects the array index to be in
|
/* The %store/dar expects the array index to be in
|
||||||
index register 3. */
|
index register 3. */
|
||||||
draw_eval_expr_into_integer(mux, 3);
|
draw_eval_expr_into_integer(mux, 3);
|
||||||
fprintf(vvp_out, " %%store/qdar/str v%p_0, %d;\n", var, idx);
|
fprintf(vvp_out, " %%store/qdar/str v%p_0, %d;\n", var, idx);
|
||||||
|
|
||||||
} else if (mux) { // What is left must be some form of vector
|
} else if (mux) { // What is left must be some form of vector
|
||||||
|
assert(ivl_type_base(element_type) == IVL_VT_BOOL ||
|
||||||
|
ivl_type_base(element_type) == IVL_VT_LOGIC);
|
||||||
draw_eval_vec4(rval);
|
draw_eval_vec4(rval);
|
||||||
resize_vec4_wid(rval, ivl_stmt_lwidth(net));
|
resize_vec4_wid(rval, ivl_stmt_lwidth(net));
|
||||||
/* The %store/dar expects the array index to be in
|
/* The %store/dar expects the array index to be in
|
||||||
index register 3. */
|
index register 3. */
|
||||||
draw_eval_expr_into_integer(mux, 3);
|
draw_eval_expr_into_integer(mux, 3);
|
||||||
fprintf(vvp_out, " %%store/qdar/vec4 v%p_0, %d, %u;\n", var, idx,
|
fprintf(vvp_out, " %%store/qdar/v v%p_0, %d, %u;\n", var, idx,
|
||||||
width_of_packed_type(element_type));
|
width_of_packed_type(element_type));
|
||||||
|
|
||||||
} else if (ivl_expr_type(rval) == IVL_EX_ARRAY_PATTERN) {
|
} else if (ivl_expr_type(rval) == IVL_EX_ARRAY_PATTERN) {
|
||||||
/* There is no l-value mux, but the r-value is an array
|
/* There is no l-value mux, but the r-value is an array
|
||||||
pattern. This is a special case of an assignment to
|
pattern. This is a special case of an assignment to
|
||||||
elements of the l-value. */
|
the l-value. */
|
||||||
errors += show_stmt_assign_queue_pattern(var, rval, element_type, idx);
|
errors += show_stmt_assign_queue_pattern(var, rval, element_type, idx);
|
||||||
} else {
|
|
||||||
fprintf(stderr, "Sorry: I don't know how to handle expr_type=%d "
|
|
||||||
"being assigned to a queue.\n", ivl_expr_type(rval));
|
|
||||||
fprintf(vvp_out, " ; Sorry: Queues do not currently handle "
|
|
||||||
"expr_type=%d.\n", ivl_expr_type(rval));
|
|
||||||
errors += 1;
|
|
||||||
}
|
|
||||||
clr_word(idx);
|
|
||||||
// FIXME: This is probably needed to assign from an actual array.
|
|
||||||
#if 0
|
|
||||||
static int show_stmt_assign_sig_darray(ivl_statement_t net)
|
|
||||||
{
|
|
||||||
} else {
|
} else {
|
||||||
/* There is no l-value mux, so this must be an
|
/* There is no l-value mux, so this must be an
|
||||||
assignment to the array as a whole. Evaluate the
|
assignment to the array as a whole. Evaluate the
|
||||||
"object", and store the evaluated result. */
|
"object", and store the evaluated result. */
|
||||||
errors += draw_eval_object(rval);
|
errors += draw_eval_object(rval);
|
||||||
fprintf(vvp_out, " %%store/obj v%p_0;\n", var);
|
if (ivl_type_base(element_type) == IVL_VT_REAL)
|
||||||
|
fprintf(vvp_out, " %%store/qobj/r v%p_0, %d;\n", var, idx);
|
||||||
|
else if (ivl_type_base(element_type) == IVL_VT_STRING)
|
||||||
|
fprintf(vvp_out, " %%store/qobj/str v%p_0, %d;\n", var, idx);
|
||||||
|
else {
|
||||||
|
assert(ivl_type_base(element_type) == IVL_VT_BOOL ||
|
||||||
|
ivl_type_base(element_type) == IVL_VT_LOGIC);
|
||||||
|
fprintf(vvp_out, " %%store/qobj/v v%p_0, %d, %u;\n",
|
||||||
|
var, idx, width_of_packed_type(element_type));
|
||||||
}
|
}
|
||||||
#endif
|
}
|
||||||
|
clr_word(idx);
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
21
vvp/codes.h
21
vvp/codes.h
|
|
@ -229,21 +229,24 @@ extern bool of_SPLIT_VEC4(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_DAR_R(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_DAR_R(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_DAR_STR(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_DAR_STR(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_DAR_VEC4(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_DAR_VEC4(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_QB_R(vthread_t thr, vvp_code_t code);
|
|
||||||
extern bool of_STORE_QB_STR(vthread_t thr, vvp_code_t code);
|
|
||||||
extern bool of_STORE_QB_V(vthread_t thr, vvp_code_t code);
|
|
||||||
extern bool of_STORE_QDAR_R(vthread_t thr, vvp_code_t code);
|
|
||||||
extern bool of_STORE_QDAR_STR(vthread_t thr, vvp_code_t code);
|
|
||||||
extern bool of_STORE_QDAR_VEC4(vthread_t thr, vvp_code_t code);
|
|
||||||
extern bool of_STORE_QF_R(vthread_t thr, vvp_code_t code);
|
|
||||||
extern bool of_STORE_QF_STR(vthread_t thr, vvp_code_t code);
|
|
||||||
extern bool of_STORE_QF_V(vthread_t thr, vvp_code_t code);
|
|
||||||
extern bool of_STORE_OBJ(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_OBJ(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_OBJA(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_OBJA(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_PROP_OBJ(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_PROP_OBJ(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_PROP_R(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_PROP_R(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_PROP_STR(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_PROP_STR(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_PROP_V(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_PROP_V(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QB_R(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QB_STR(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QB_V(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QDAR_R(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QDAR_STR(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QDAR_V(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QF_R(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QF_STR(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QF_V(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QOBJ_R(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QOBJ_STR(vthread_t thr, vvp_code_t code);
|
||||||
|
extern bool of_STORE_QOBJ_V(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_REAL(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_REAL(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_REALA(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_REALA(vthread_t thr, vvp_code_t code);
|
||||||
extern bool of_STORE_STR(vthread_t thr, vvp_code_t code);
|
extern bool of_STORE_STR(vthread_t thr, vvp_code_t code);
|
||||||
|
|
|
||||||
|
|
@ -288,12 +288,15 @@ static const struct opcode_table_s opcode_table[] = {
|
||||||
{ "%store/qb/r", of_STORE_QB_R, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
{ "%store/qb/r", of_STORE_QB_R, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||||
{ "%store/qb/str", of_STORE_QB_STR, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
{ "%store/qb/str", of_STORE_QB_STR, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||||
{ "%store/qb/v", of_STORE_QB_V, 3, {OA_FUNC_PTR, OA_BIT1, OA_BIT2} },
|
{ "%store/qb/v", of_STORE_QB_V, 3, {OA_FUNC_PTR, OA_BIT1, OA_BIT2} },
|
||||||
{ "%store/qdar/r", of_STORE_QDAR_R, 2,{OA_FUNC_PTR,OA_BIT1,OA_NONE} },
|
{ "%store/qdar/r", of_STORE_QDAR_R, 2,{OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||||
{ "%store/qdar/str", of_STORE_QDAR_STR, 2,{OA_FUNC_PTR,OA_BIT1,OA_NONE} },
|
{ "%store/qdar/str",of_STORE_QDAR_STR,2,{OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||||
{ "%store/qdar/vec4",of_STORE_QDAR_VEC4,3,{OA_FUNC_PTR,OA_BIT1,OA_BIT2} },
|
{ "%store/qdar/v", of_STORE_QDAR_V, 3,{OA_FUNC_PTR, OA_BIT1, OA_BIT2} },
|
||||||
{ "%store/qf/r", of_STORE_QF_R, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
{ "%store/qf/r", of_STORE_QF_R, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||||
{ "%store/qf/str", of_STORE_QF_STR, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
{ "%store/qf/str", of_STORE_QF_STR, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||||
{ "%store/qf/v", of_STORE_QF_V, 3, {OA_FUNC_PTR, OA_BIT1, OA_BIT2} },
|
{ "%store/qf/v", of_STORE_QF_V, 3, {OA_FUNC_PTR, OA_BIT1, OA_BIT2} },
|
||||||
|
{ "%store/qobj/r", of_STORE_QOBJ_R, 2, {OA_FUNC_PTR,OA_BIT1, OA_NONE} },
|
||||||
|
{ "%store/qobj/str",of_STORE_QOBJ_STR,2, {OA_FUNC_PTR,OA_BIT1, OA_NONE} },
|
||||||
|
{ "%store/qobj/v", of_STORE_QOBJ_V, 3, {OA_FUNC_PTR,OA_BIT1, OA_BIT2} },
|
||||||
{ "%store/real", of_STORE_REAL, 1, {OA_FUNC_PTR,OA_NONE, OA_NONE} },
|
{ "%store/real", of_STORE_REAL, 1, {OA_FUNC_PTR,OA_NONE, OA_NONE} },
|
||||||
{ "%store/reala", of_STORE_REALA, 2, {OA_ARR_PTR, OA_BIT1, OA_NONE} },
|
{ "%store/reala", of_STORE_REALA, 2, {OA_ARR_PTR, OA_BIT1, OA_NONE} },
|
||||||
{ "%store/str", of_STORE_STR, 1, {OA_FUNC_PTR,OA_NONE, OA_NONE} },
|
{ "%store/str", of_STORE_STR, 1, {OA_FUNC_PTR,OA_NONE, OA_NONE} },
|
||||||
|
|
|
||||||
|
|
@ -6034,7 +6034,7 @@ static bool store_qdar(vthread_t thr, vvp_code_t cp, unsigned wid=0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* %store/qdar/real <var>, idx
|
* %store/qdar/r <var>, idx
|
||||||
*/
|
*/
|
||||||
bool of_STORE_QDAR_R(vthread_t thr, vvp_code_t cp)
|
bool of_STORE_QDAR_R(vthread_t thr, vvp_code_t cp)
|
||||||
{
|
{
|
||||||
|
|
@ -6050,14 +6050,13 @@ bool of_STORE_QDAR_STR(vthread_t thr, vvp_code_t cp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* %store/qdar/vec4 <var>, idx
|
* %store/qdar/v <var>, idx
|
||||||
*/
|
*/
|
||||||
bool of_STORE_QDAR_VEC4(vthread_t thr, vvp_code_t cp)
|
bool of_STORE_QDAR_V(vthread_t thr, vvp_code_t cp)
|
||||||
{
|
{
|
||||||
return store_qdar<vvp_vector4_t, vvp_queue_vec4>(thr, cp, cp->bit_idx[1]);
|
return store_qdar<vvp_vector4_t, vvp_queue_vec4>(thr, cp, cp->bit_idx[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename ELEM, class QTYPE>
|
template <typename ELEM, class QTYPE>
|
||||||
static bool store_qf(vthread_t thr, vvp_code_t cp, unsigned wid=0)
|
static bool store_qf(vthread_t thr, vvp_code_t cp, unsigned wid=0)
|
||||||
{
|
{
|
||||||
|
|
@ -6095,6 +6094,39 @@ bool of_STORE_QF_V(vthread_t thr, vvp_code_t cp)
|
||||||
return store_qf<vvp_vector4_t, vvp_queue_vec4>(thr, cp, cp->bit_idx[1]);
|
return store_qf<vvp_vector4_t, vvp_queue_vec4>(thr, cp, cp->bit_idx[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename ELEM, class QTYPE>
|
||||||
|
static bool store_qobj(vthread_t thr, vvp_code_t cp, unsigned wid=0)
|
||||||
|
{
|
||||||
|
// FIXME: Can we actually use wid here?
|
||||||
|
(void)wid;
|
||||||
|
vvp_net_t*net = cp->net;
|
||||||
|
unsigned max_size = thr->words[cp->bit_idx[0]].w_int;
|
||||||
|
|
||||||
|
vvp_queue*queue = get_queue_object<QTYPE>(thr, net);
|
||||||
|
assert(queue);
|
||||||
|
|
||||||
|
vvp_object_t src;
|
||||||
|
thr->pop_object(src);
|
||||||
|
|
||||||
|
queue->copy_elems(src, max_size);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool of_STORE_QOBJ_R(vthread_t thr, vvp_code_t cp)
|
||||||
|
{
|
||||||
|
return store_qobj<double, vvp_queue_real>(thr, cp);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool of_STORE_QOBJ_STR(vthread_t thr, vvp_code_t cp)
|
||||||
|
{
|
||||||
|
return store_qobj<string, vvp_queue_string>(thr, cp);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool of_STORE_QOBJ_V(vthread_t thr, vvp_code_t cp)
|
||||||
|
{
|
||||||
|
return store_qobj<vvp_vector4_t, vvp_queue_vec4>(thr, cp, cp->bit_idx[1]);
|
||||||
|
}
|
||||||
|
|
||||||
bool of_STORE_REAL(vthread_t thr, vvp_code_t cp)
|
bool of_STORE_REAL(vthread_t thr, vvp_code_t cp)
|
||||||
{
|
{
|
||||||
double val = thr->pop_real();
|
double val = thr->pop_real();
|
||||||
|
|
|
||||||
|
|
@ -410,6 +410,11 @@ vvp_queue::~vvp_queue()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vvp_queue::copy_elems(vvp_object_t, unsigned)
|
||||||
|
{
|
||||||
|
cerr << "Sorry: copy_elems() not implemented for " << typeid(*this).name() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
void vvp_queue::set_word_max(unsigned, const vvp_vector4_t&, unsigned)
|
void vvp_queue::set_word_max(unsigned, const vvp_vector4_t&, unsigned)
|
||||||
{
|
{
|
||||||
cerr << "XXXX set_word_max(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl;
|
cerr << "XXXX set_word_max(vvp_vector4_t) not implemented for " << typeid(*this).name() << endl;
|
||||||
|
|
@ -474,6 +479,59 @@ vvp_queue_real::~vvp_queue_real()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper functions used while copying multiple elements into a queue.
|
||||||
|
*/
|
||||||
|
static void print_copy_is_too_big(size_t src_size, unsigned max_size, string qtype)
|
||||||
|
{
|
||||||
|
cerr << "Warning: queue<" << qtype << "> is bounded to have at most "
|
||||||
|
<< max_size << " elements, source has " << src_size << " elements." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_copy_is_too_big(double&, size_t src_size, unsigned max_size)
|
||||||
|
{
|
||||||
|
print_copy_is_too_big(src_size, max_size, "real");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_copy_is_too_big(string&, size_t src_size, unsigned max_size)
|
||||||
|
{
|
||||||
|
print_copy_is_too_big(src_size, max_size, "string");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_copy_is_too_big(vvp_vector4_t&, size_t src_size, unsigned max_size)
|
||||||
|
{
|
||||||
|
print_copy_is_too_big(src_size, max_size, "vector");
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename ELEM, class QTYPE, class SRC_TYPE>
|
||||||
|
static void copy_elements(QTYPE*queue, SRC_TYPE*src, unsigned max_size)
|
||||||
|
{
|
||||||
|
size_t src_size = src->get_size();
|
||||||
|
if ((max_size != 0) && (src_size > max_size)) {
|
||||||
|
ELEM tmp;
|
||||||
|
print_copy_is_too_big(tmp, src_size, max_size);
|
||||||
|
}
|
||||||
|
unsigned copy_size = ((src_size < max_size) ||
|
||||||
|
(max_size == 0)) ? src_size : max_size;
|
||||||
|
if (copy_size < queue->get_size())
|
||||||
|
queue->erase_tail(copy_size);
|
||||||
|
for (unsigned idx=0; idx < copy_size; ++idx) {
|
||||||
|
ELEM value;
|
||||||
|
src->get_word(idx, value);
|
||||||
|
queue->set_word_max(idx, value, max_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void vvp_queue_real::copy_elems(vvp_object_t src, unsigned max_size)
|
||||||
|
{
|
||||||
|
if (vvp_queue*src_queue = src.peek<vvp_queue>())
|
||||||
|
copy_elements<double, vvp_queue_real, vvp_queue>(this, src_queue, max_size);
|
||||||
|
else if (vvp_darray*src_darray = src.peek<vvp_darray>())
|
||||||
|
copy_elements<double, vvp_queue_real, vvp_darray>(this, src_darray, max_size);
|
||||||
|
else
|
||||||
|
cerr << "Sorry: cannot copy object to real queue." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
void vvp_queue_real::set_word_max(unsigned adr, double value, unsigned max_size)
|
void vvp_queue_real::set_word_max(unsigned adr, double value, unsigned max_size)
|
||||||
{
|
{
|
||||||
if (adr == queue.size())
|
if (adr == queue.size())
|
||||||
|
|
@ -593,6 +651,16 @@ vvp_queue_string::~vvp_queue_string()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vvp_queue_string::copy_elems(vvp_object_t src, unsigned max_size)
|
||||||
|
{
|
||||||
|
if (vvp_queue*src_queue = src.peek<vvp_queue>())
|
||||||
|
copy_elements<string, vvp_queue_string, vvp_queue>(this, src_queue, max_size);
|
||||||
|
else if (vvp_darray*src_darray = src.peek<vvp_darray>())
|
||||||
|
copy_elements<string, vvp_queue_string, vvp_darray>(this, src_darray, max_size);
|
||||||
|
else
|
||||||
|
cerr << "Sorry: cannot copy object to string queue." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
void vvp_queue_string::set_word_max(unsigned adr, const string&value, unsigned max_size)
|
void vvp_queue_string::set_word_max(unsigned adr, const string&value, unsigned max_size)
|
||||||
{
|
{
|
||||||
if (adr == queue.size())
|
if (adr == queue.size())
|
||||||
|
|
@ -712,6 +780,16 @@ vvp_queue_vec4::~vvp_queue_vec4()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vvp_queue_vec4::copy_elems(vvp_object_t src, unsigned max_size)
|
||||||
|
{
|
||||||
|
if (vvp_queue*src_queue = src.peek<vvp_queue>())
|
||||||
|
copy_elements<vvp_vector4_t, vvp_queue_vec4, vvp_queue>(this, src_queue, max_size);
|
||||||
|
else if (vvp_darray*src_darray = src.peek<vvp_darray>())
|
||||||
|
copy_elements<vvp_vector4_t, vvp_queue_vec4, vvp_darray>(this, src_darray, max_size);
|
||||||
|
else
|
||||||
|
cerr << "Sorry: cannot copy object to vector queue." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
void vvp_queue_vec4::set_word_max(unsigned adr, const vvp_vector4_t&value, unsigned max_size)
|
void vvp_queue_vec4::set_word_max(unsigned adr, const vvp_vector4_t&value, unsigned max_size)
|
||||||
{
|
{
|
||||||
if (adr == queue.size())
|
if (adr == queue.size())
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,9 @@ class vvp_queue : public vvp_darray {
|
||||||
inline vvp_queue(void) { }
|
inline vvp_queue(void) { }
|
||||||
~vvp_queue();
|
~vvp_queue();
|
||||||
|
|
||||||
|
virtual size_t get_size(void) const =0;
|
||||||
|
virtual void copy_elems(vvp_object_t src, unsigned max_size);
|
||||||
|
|
||||||
virtual void set_word_max(unsigned adr, const vvp_vector4_t&value, unsigned max_size);
|
virtual void set_word_max(unsigned adr, const vvp_vector4_t&value, unsigned max_size);
|
||||||
virtual void insert(unsigned idx, const vvp_vector4_t&value, unsigned max_size);
|
virtual void insert(unsigned idx, const vvp_vector4_t&value, unsigned max_size);
|
||||||
virtual void push_back(const vvp_vector4_t&value, unsigned max_size);
|
virtual void push_back(const vvp_vector4_t&value, unsigned max_size);
|
||||||
|
|
@ -181,6 +184,7 @@ class vvp_queue_real : public vvp_queue {
|
||||||
~vvp_queue_real();
|
~vvp_queue_real();
|
||||||
|
|
||||||
size_t get_size(void) const { return queue.size(); };
|
size_t get_size(void) const { return queue.size(); };
|
||||||
|
void copy_elems(vvp_object_t src, unsigned max_size);
|
||||||
void set_word_max(unsigned adr, double value, unsigned max_size);
|
void set_word_max(unsigned adr, double value, unsigned max_size);
|
||||||
void set_word(unsigned adr, double value);
|
void set_word(unsigned adr, double value);
|
||||||
void get_word(unsigned adr, double&value);
|
void get_word(unsigned adr, double&value);
|
||||||
|
|
@ -202,6 +206,7 @@ class vvp_queue_string : public vvp_queue {
|
||||||
~vvp_queue_string();
|
~vvp_queue_string();
|
||||||
|
|
||||||
size_t get_size(void) const { return queue.size(); };
|
size_t get_size(void) const { return queue.size(); };
|
||||||
|
void copy_elems(vvp_object_t src, unsigned max_size);
|
||||||
void set_word_max(unsigned adr, const std::string&value, unsigned max_size);
|
void set_word_max(unsigned adr, const std::string&value, unsigned max_size);
|
||||||
void set_word(unsigned adr, const std::string&value);
|
void set_word(unsigned adr, const std::string&value);
|
||||||
void get_word(unsigned adr, std::string&value);
|
void get_word(unsigned adr, std::string&value);
|
||||||
|
|
@ -223,6 +228,7 @@ class vvp_queue_vec4 : public vvp_queue {
|
||||||
~vvp_queue_vec4();
|
~vvp_queue_vec4();
|
||||||
|
|
||||||
size_t get_size(void) const { return queue.size(); };
|
size_t get_size(void) const { return queue.size(); };
|
||||||
|
void copy_elems(vvp_object_t src, unsigned max_size);
|
||||||
void set_word_max(unsigned adr, const vvp_vector4_t&value, unsigned max_size);
|
void set_word_max(unsigned adr, const vvp_vector4_t&value, unsigned max_size);
|
||||||
void set_word(unsigned adr, const vvp_vector4_t&value);
|
void set_word(unsigned adr, const vvp_vector4_t&value);
|
||||||
void get_word(unsigned adr, vvp_vector4_t&value);
|
void get_word(unsigned adr, vvp_vector4_t&value);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue