Merge pull request #1419 from muhammadjawadkhan/split/03-sv-locator-methods
SV: queue/darray locator methods (find*, unique*, min/max)
This commit is contained in:
commit
35a809d55b
17
PExpr.cc
17
PExpr.cc
|
|
@ -284,16 +284,26 @@ PECallFunction::PECallFunction(PExpr* chain_prefix, const pform_name_t &method,
|
|||
{
|
||||
}
|
||||
|
||||
void PECallFunction::set_with_clause(PExpr* with_expr)
|
||||
{
|
||||
delete with_expr_;
|
||||
with_expr_ = with_expr;
|
||||
}
|
||||
|
||||
PECallFunction::~PECallFunction()
|
||||
{
|
||||
delete chain_prefix_;
|
||||
delete with_expr_;
|
||||
}
|
||||
|
||||
void PECallFunction::declare_implicit_nets(LexicalScope*scope, NetNet::Type type)
|
||||
{
|
||||
if (chain_prefix_) {
|
||||
chain_prefix_->declare_implicit_nets(scope, type);
|
||||
}
|
||||
}
|
||||
if (with_expr_) {
|
||||
with_expr_->declare_implicit_nets(scope, type);
|
||||
}
|
||||
for (const auto &parm : parms_) {
|
||||
if (parm.parm) {
|
||||
parm.parm->declare_implicit_nets(scope, type);
|
||||
|
|
@ -305,7 +315,10 @@ bool PECallFunction::has_aa_term(Design*des, NetScope*scope) const
|
|||
{
|
||||
if (chain_prefix_ && chain_prefix_->has_aa_term(des, scope)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (with_expr_ && with_expr_->has_aa_term(des, scope)) {
|
||||
return true;
|
||||
}
|
||||
for (const auto &parm : parms_) {
|
||||
if (parm.parm && parm.parm->has_aa_term(des, scope)) {
|
||||
return true;
|
||||
|
|
|
|||
5
PExpr.h
5
PExpr.h
|
|
@ -926,6 +926,10 @@ class PECallFunction : public PExpr {
|
|||
explicit PECallFunction(PExpr* chain_prefix, const pform_name_t &method,
|
||||
const std::list<named_pexpr_t> &parms);
|
||||
|
||||
// SystemVerilog: q.find with (expr) — iterator "item"/"index" in expr.
|
||||
void set_with_clause(PExpr* with_expr);
|
||||
const PExpr* peek_with_clause(void) const { return with_expr_; }
|
||||
|
||||
~PECallFunction() override;
|
||||
|
||||
// For chained-call resolution (path is only the final method name).
|
||||
|
|
@ -952,6 +956,7 @@ class PECallFunction : public PExpr {
|
|||
std::vector<named_pexpr_t> parms_;
|
||||
// If non-null, this call is prefix().tail_name(...) (SV method chain).
|
||||
PExpr* chain_prefix_ = nullptr;
|
||||
PExpr* with_expr_ = nullptr;
|
||||
|
||||
// For system functions.
|
||||
bool is_overridden_;
|
||||
|
|
|
|||
|
|
@ -235,7 +235,9 @@ NetESelect* NetESelect::dup_expr() const
|
|||
|
||||
NetESFunc* NetESFunc::dup_expr() const
|
||||
{
|
||||
NetESFunc*tmp = new NetESFunc(name_, type_, expr_width(), nparms(), is_overridden_);
|
||||
NetESFunc*tmp = net_type()
|
||||
? new NetESFunc(name_, net_type(), nparms())
|
||||
: new NetESFunc(name_, type_, expr_width(), nparms(), is_overridden_);
|
||||
ivl_assert(*this, tmp);
|
||||
|
||||
tmp->cast_signed(has_sign());
|
||||
|
|
|
|||
512
elab_expr.cc
512
elab_expr.cc
|
|
@ -41,9 +41,178 @@
|
|||
# include "util.h"
|
||||
# include "ivl_assert.h"
|
||||
# include "map_named_args.h"
|
||||
# include "HName.h"
|
||||
# include "netvector.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
static netqueue_t ivl_queue_unique_index_ret(&netvector_t::atom2s32, -1);
|
||||
|
||||
static bool queue_method_element_is_integral_vec4(ivl_type_t et)
|
||||
{
|
||||
ivl_variable_type_t bt = ivl_type_base(et);
|
||||
return bt == IVL_VT_BOOL || bt == IVL_VT_LOGIC;
|
||||
}
|
||||
|
||||
/* One argument: value to match using == (same as find with (item == arg)). */
|
||||
static NetExpr* elab_queue_locator_cmp_arg(Design* des, NetScope* scope,
|
||||
const LineInfo& loc,
|
||||
const vector<named_pexpr_t>& parms,
|
||||
ivl_type_t element_type)
|
||||
{
|
||||
if (parms.size() != 1) {
|
||||
cerr << loc.get_fileline() << ": error: Array locator method requires "
|
||||
"exactly one argument (value to compare using ==)." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
}
|
||||
const named_pexpr_t& arg = parms.front();
|
||||
if (arg.parm == 0) {
|
||||
cerr << loc.get_fileline() << ": error: Missing argument to array locator method."
|
||||
<< endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
}
|
||||
unsigned ew = ivl_type_packed_width(element_type);
|
||||
return elab_and_eval(des, scope, arg.parm, (int)ew, false, false,
|
||||
ivl_type_base(element_type));
|
||||
}
|
||||
|
||||
/* Elaborate `with (expr)` for array locator methods: implicit item/index nets. */
|
||||
static NetExpr* elab_queue_locator_with_predicate(
|
||||
Design* des, NetScope* scope, const LineInfo& loc,
|
||||
PExpr* with_expr, NetExpr* queue_arg, ivl_type_t element_type,
|
||||
ivl_type_t result_type, perm_string method_suffix)
|
||||
{
|
||||
static unsigned with_scope_counter = 0;
|
||||
char buf[64];
|
||||
snprintf(buf, sizeof buf, "$ivl_qwith%u", with_scope_counter++);
|
||||
NetScope* ws = new NetScope(scope, hname_t(lex_strings.make(buf)),
|
||||
NetScope::BEGIN_END);
|
||||
ws->set_line(&loc);
|
||||
|
||||
unsigned ew = ivl_type_packed_width(element_type);
|
||||
const netvector_t* item_vec = new netvector_t(ivl_type_base(element_type),
|
||||
(long)ew - 1, 0,
|
||||
ivl_type_signed(element_type));
|
||||
NetNet* item_net = new NetNet(ws, lex_strings.make("item"), NetNet::REG,
|
||||
item_vec);
|
||||
item_net->set_line(loc);
|
||||
item_net->local_flag(true);
|
||||
|
||||
NetNet* index_net = new NetNet(ws, lex_strings.make("index"), NetNet::REG,
|
||||
&netvector_t::atom2s32);
|
||||
index_net->set_line(loc);
|
||||
index_net->local_flag(true);
|
||||
|
||||
NetExpr* pred = elab_and_eval(des, ws, with_expr, 1, false, false,
|
||||
IVL_VT_BOOL);
|
||||
if (!pred) return 0;
|
||||
|
||||
perm_string sfunc_name;
|
||||
if (method_suffix == "find") {
|
||||
sfunc_name = lex_strings.make("$ivl_queue_method$find_with");
|
||||
} else if (method_suffix == "find_index") {
|
||||
sfunc_name = lex_strings.make("$ivl_queue_method$find_index_with");
|
||||
} else if (method_suffix == "find_first") {
|
||||
sfunc_name = lex_strings.make("$ivl_queue_method$find_first_with");
|
||||
} else if (method_suffix == "find_first_index") {
|
||||
sfunc_name = lex_strings.make("$ivl_queue_method$find_first_index_with");
|
||||
} else if (method_suffix == "find_last") {
|
||||
sfunc_name = lex_strings.make("$ivl_queue_method$find_last_with");
|
||||
} else if (method_suffix == "find_last_index") {
|
||||
sfunc_name = lex_strings.make("$ivl_queue_method$find_last_index_with");
|
||||
} else {
|
||||
ivl_assert(loc, 0);
|
||||
}
|
||||
|
||||
NetESFunc* out = new NetESFunc(sfunc_name, result_type, 4);
|
||||
out->set_line(loc);
|
||||
out->parm(0, queue_arg);
|
||||
out->parm(1, pred);
|
||||
out->parm(2, new NetESignal(item_net));
|
||||
out->parm(3, new NetESignal(index_net));
|
||||
return out;
|
||||
}
|
||||
|
||||
static bool is_array_locator_method(perm_string name)
|
||||
{
|
||||
return name == "find" || name == "find_index" ||
|
||||
name == "find_first" || name == "find_first_index" ||
|
||||
name == "find_last" || name == "find_last_index" ||
|
||||
name == "unique" || name == "unique_index";
|
||||
}
|
||||
|
||||
static bool locator_returns_indices(perm_string name)
|
||||
{
|
||||
return name == "find_index" || name == "find_first_index" ||
|
||||
name == "find_last_index" || name == "unique_index";
|
||||
}
|
||||
|
||||
/*
|
||||
* Elaborate unique* / find* on a queue or dynamic array expression.
|
||||
* value_queue_type is the result type for value-returning find/unique
|
||||
* (typically the array own queue/darray type).
|
||||
*/
|
||||
static NetExpr* elab_array_locator_method(Design* des, NetScope* scope,
|
||||
const LineInfo& loc,
|
||||
perm_string method_name,
|
||||
NetExpr* array_arg,
|
||||
ivl_type_t element_type,
|
||||
ivl_type_t value_queue_type,
|
||||
const vector<named_pexpr_t>& parms,
|
||||
PExpr* with_expr, const char* kind)
|
||||
{
|
||||
if (!queue_method_element_is_integral_vec4(element_type)) {
|
||||
cerr << loc.get_fileline() << ": sorry: " << kind << " "
|
||||
<< method_name << "() for this "
|
||||
<< "element type is not yet supported." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ivl_type_t result_type = locator_returns_indices(method_name)
|
||||
? static_cast<ivl_type_t>(&ivl_queue_unique_index_ret)
|
||||
: value_queue_type;
|
||||
|
||||
char sfunc[64];
|
||||
snprintf(sfunc, sizeof sfunc, "$ivl_queue_method$%s", method_name.str());
|
||||
|
||||
if (method_name == "unique" || method_name == "unique_index") {
|
||||
if (parms.size() != 0) {
|
||||
cerr << loc.get_fileline() << ": error: " << method_name
|
||||
<< "() method takes no arguments" << endl;
|
||||
des->errors += 1;
|
||||
}
|
||||
NetESFunc*sys_expr = new NetESFunc(sfunc, result_type, 1);
|
||||
sys_expr->set_line(loc);
|
||||
sys_expr->parm(0, array_arg);
|
||||
return sys_expr;
|
||||
}
|
||||
|
||||
if (with_expr) {
|
||||
if (!parms.empty()) {
|
||||
cerr << loc.get_fileline() << ": error: array locator "
|
||||
<< "`with` clause cannot be combined with a "
|
||||
<< "method argument." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
}
|
||||
return elab_queue_locator_with_predicate(des, scope, loc, with_expr,
|
||||
array_arg, element_type,
|
||||
result_type, method_name);
|
||||
}
|
||||
|
||||
NetExpr* cmp = elab_queue_locator_cmp_arg(des, scope, loc, parms,
|
||||
element_type);
|
||||
if (!cmp) return 0;
|
||||
NetESFunc*sys_expr = new NetESFunc(sfunc, result_type, 2);
|
||||
sys_expr->set_line(loc);
|
||||
sys_expr->parm(0, array_arg);
|
||||
sys_expr->parm(1, cmp);
|
||||
return sys_expr;
|
||||
}
|
||||
|
||||
bool type_is_vectorable(ivl_variable_type_t type)
|
||||
{
|
||||
switch (type) {
|
||||
|
|
@ -1649,6 +1818,30 @@ unsigned PECallFunction::test_width_method_(Design*, NetScope*,
|
|||
return expr_width_;
|
||||
}
|
||||
|
||||
if (method_name == "find" || method_name == "find_index") {
|
||||
expr_type_ = IVL_VT_QUEUE;
|
||||
expr_width_ = 1;
|
||||
min_width_ = 1;
|
||||
signed_flag_ = false;
|
||||
return expr_width_;
|
||||
}
|
||||
|
||||
if (method_name == "find_first" || method_name == "find_last") {
|
||||
expr_type_ = darray->element_base_type();
|
||||
expr_width_ = darray->element_width();
|
||||
min_width_ = expr_width_;
|
||||
signed_flag_ = darray->get_signed();
|
||||
return expr_width_;
|
||||
}
|
||||
|
||||
if (method_name == "find_first_index" || method_name == "find_last_index") {
|
||||
expr_type_ = IVL_VT_BOOL;
|
||||
expr_width_ = 32;
|
||||
min_width_ = 32;
|
||||
signed_flag_= true;
|
||||
return expr_width_;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1680,6 +1873,38 @@ unsigned PECallFunction::test_width_method_(Design*, NetScope*,
|
|||
return expr_width_;
|
||||
}
|
||||
|
||||
if (method_name == "unique" || method_name == "unique_index") {
|
||||
expr_type_ = IVL_VT_QUEUE;
|
||||
expr_width_ = 1;
|
||||
min_width_ = 1;
|
||||
signed_flag_ = false;
|
||||
return expr_width_;
|
||||
}
|
||||
|
||||
if (method_name == "find" || method_name == "find_index") {
|
||||
expr_type_ = IVL_VT_QUEUE;
|
||||
expr_width_ = 1;
|
||||
min_width_ = 1;
|
||||
signed_flag_ = false;
|
||||
return expr_width_;
|
||||
}
|
||||
|
||||
if (method_name == "find_first" || method_name == "find_last") {
|
||||
expr_type_ = darray->element_base_type();
|
||||
expr_width_ = darray->element_width();
|
||||
min_width_ = expr_width_;
|
||||
signed_flag_ = darray->get_signed();
|
||||
return expr_width_;
|
||||
}
|
||||
|
||||
if (method_name == "find_first_index" || method_name == "find_last_index") {
|
||||
expr_type_ = IVL_VT_BOOL;
|
||||
expr_width_ = 32;
|
||||
min_width_ = 32;
|
||||
signed_flag_= true;
|
||||
return expr_width_;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -3599,6 +3824,12 @@ NetExpr* PECallFunction::elaborate_expr_method_(Design*des, NetScope*scope,
|
|||
sys_expr->parm(0, prop);
|
||||
return sys_expr;
|
||||
}
|
||||
if (is_array_locator_method(method_name)) {
|
||||
return elab_array_locator_method(des, scope, *this,
|
||||
method_name, prop, element_type,
|
||||
static_cast<ivl_type_t>(queue),
|
||||
parms_, with_expr_, "queue");
|
||||
}
|
||||
}
|
||||
if (ptype && ptype->base_type() == IVL_VT_DARRAY) {
|
||||
NetEProperty*prop = new NetEProperty(search_results.net, pidx, nullptr);
|
||||
|
|
@ -3672,8 +3903,7 @@ NetExpr* PECallFunction::elaborate_expr_method_(Design*des, NetScope*scope,
|
|||
ivl_assert(*this, use_index.lsb == 0);
|
||||
|
||||
NetExpr*mux = elab_and_eval(des, scope, use_index.msb, -1, false);
|
||||
if (!mux)
|
||||
return 0;
|
||||
if (!mux) return 0;
|
||||
|
||||
NetESelect*tmp = new NetESelect(sub_expr, mux, darray->element_width(), darray->element_type());
|
||||
tmp->set_line(*this);
|
||||
|
|
@ -3710,6 +3940,20 @@ NetExpr* PECallFunction::elaborate_expr_method_(Design*des, NetScope*scope,
|
|||
return sys_expr;
|
||||
}
|
||||
|
||||
const netdarray_t*dar = search_results.net->darray_type();
|
||||
ivl_assert(*this, dar);
|
||||
ivl_type_t element_type = dar->element_type();
|
||||
const netqueue_t*queue = search_results.net->queue_type();
|
||||
ivl_type_t queue_rtype = queue ? static_cast<ivl_type_t>(queue)
|
||||
: static_cast<ivl_type_t>(dar);
|
||||
|
||||
if (is_array_locator_method(method_name)) {
|
||||
return elab_array_locator_method(des, scope, *this, method_name,
|
||||
sub_expr, element_type,
|
||||
queue_rtype, parms_, with_expr_,
|
||||
"dynamic array");
|
||||
}
|
||||
|
||||
cerr << get_fileline() << ": error: Method " << method_name
|
||||
<< " is not a dynamic array method." << endl;
|
||||
return 0;
|
||||
|
|
@ -3762,6 +4006,13 @@ NetExpr* PECallFunction::elaborate_expr_method_(Design*des, NetScope*scope,
|
|||
return sys_expr;
|
||||
}
|
||||
|
||||
if (is_array_locator_method(method_name)) {
|
||||
return elab_array_locator_method(des, scope, *this, method_name,
|
||||
sub_expr, element_type,
|
||||
static_cast<ivl_type_t>(queue),
|
||||
parms_, with_expr_, "queue");
|
||||
}
|
||||
|
||||
cerr << get_fileline() << ": error: Method " << method_name
|
||||
<< " is not a queue method." << endl;
|
||||
des->errors += 1;
|
||||
|
|
@ -4917,9 +5168,85 @@ NetExpr* PEIdent::elaborate_expr(Design*des, NetScope*scope,
|
|||
<< "Found net " << net->name() << " for expr " << *this << endl;
|
||||
}
|
||||
|
||||
// Queue methods (e.g. q.unique) need NetESFunc. The width-based
|
||||
// elaborate_expr_() path can still fall through to NetESignal(net)
|
||||
// for typed queue-to-queue assignments, so resolve methods here.
|
||||
// Use path_.back(): symbol_search may leave path_tail empty while
|
||||
// the method name is still the last component of path_.
|
||||
if (sr.net->queue_type() && path_.size() > 1) {
|
||||
const name_component_t member_comp = path_.back();
|
||||
const netqueue_t*queue = sr.net->queue_type();
|
||||
ivl_type_t element_type = queue->element_type();
|
||||
if (member_comp.name == "size") {
|
||||
NetESFunc*fun = new NetESFunc("$size",
|
||||
&netvector_t::atom2s32,
|
||||
1);
|
||||
fun->set_line(*this);
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
if (member_comp.name == "pop_back") {
|
||||
NetESFunc*fun = new NetESFunc("$ivl_queue_method$pop_back",
|
||||
element_type, 1);
|
||||
fun->set_line(*this);
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
if (member_comp.name == "pop_front") {
|
||||
NetESFunc*fun = new NetESFunc("$ivl_queue_method$pop_front",
|
||||
element_type, 1);
|
||||
fun->set_line(*this);
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
if (member_comp.name == "unique") {
|
||||
if (!queue_method_element_is_integral_vec4(element_type)) {
|
||||
cerr << get_fileline() << ": sorry: queue unique() for this "
|
||||
<< "element type is not yet supported." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
}
|
||||
NetESFunc*fun = new NetESFunc(
|
||||
"$ivl_queue_method$unique",
|
||||
static_cast<ivl_type_t>(queue), 1);
|
||||
fun->set_line(*this);
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
if (member_comp.name == "unique_index") {
|
||||
if (!queue_method_element_is_integral_vec4(element_type)) {
|
||||
cerr << get_fileline() << ": sorry: queue unique_index() for this "
|
||||
<< "element type is not yet supported." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
}
|
||||
NetESFunc*fun = new NetESFunc(
|
||||
"$ivl_queue_method$unique_index",
|
||||
static_cast<ivl_type_t>(&ivl_queue_unique_index_ret), 1);
|
||||
fun->set_line(*this);
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
cerr << get_fileline() << ": error: Unknown or unsupported queue "
|
||||
<< "member `" << member_comp.name << "'." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ivl_type_t check_type = ntype;
|
||||
if (const netdarray_t*array_type = dynamic_cast<const netdarray_t*> (ntype)) {
|
||||
if (array_type->type_compatible(net->net_type())) {
|
||||
if (array_type->type_compatible(net->net_type()) &&
|
||||
sr.path_tail.empty()) {
|
||||
NetESignal*tmp = new NetESignal(net);
|
||||
tmp->set_line(*this);
|
||||
return tmp;
|
||||
|
|
@ -5139,9 +5466,99 @@ NetExpr* PEIdent::elaborate_expr_(Design*des, NetScope*scope,
|
|||
sr.path_tail);
|
||||
}
|
||||
|
||||
// If this is an array object, and there are members in
|
||||
// the sr.path_tail, check for array properties.
|
||||
if (sr.net->darray_type() && !sr.path_tail.empty()) {
|
||||
// If this is a queue object, handle queue methods before the
|
||||
// dynamic-array branch: netqueue_t inherits netdarray_t, so
|
||||
// darray_type() is also true for queues.
|
||||
// For q.unique, path_ is {q,unique} but symbol_search may leave
|
||||
// path_tail empty; the method is then path_.back().
|
||||
if (sr.net->queue_type() &&
|
||||
(path_.size() > 1 || !sr.path_tail.empty())) {
|
||||
if (debug_elaborate) {
|
||||
cerr << get_fileline() << ": PEIdent::elaborate_expr: "
|
||||
<< "Ident " << sr.path_head
|
||||
<< " looking for queue property " << sr.path_tail
|
||||
<< endl;
|
||||
}
|
||||
|
||||
const name_component_t member_comp = path_.size() > 1
|
||||
? path_.back()
|
||||
: sr.path_tail.front();
|
||||
const netqueue_t*queue = sr.net->queue_type();
|
||||
ivl_type_t element_type = queue->element_type();
|
||||
if (member_comp.name == "size") {
|
||||
NetESFunc*fun = new NetESFunc("$size",
|
||||
&netvector_t::atom2s32,
|
||||
1);
|
||||
fun->set_line(*this);
|
||||
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
if (member_comp.name == "pop_back") {
|
||||
NetESFunc*fun = new NetESFunc("$ivl_queue_method$pop_back",
|
||||
element_type, 1);
|
||||
fun->set_line(*this);
|
||||
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
|
||||
if (member_comp.name == "pop_front") {
|
||||
NetESFunc*fun = new NetESFunc("$ivl_queue_method$pop_front",
|
||||
element_type, 1);
|
||||
fun->set_line(*this);
|
||||
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
|
||||
if (member_comp.name == "unique") {
|
||||
if (!queue_method_element_is_integral_vec4(element_type)) {
|
||||
cerr << get_fileline() << ": sorry: queue unique() for this "
|
||||
<< "element type is not yet supported." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
}
|
||||
NetESFunc*fun = new NetESFunc(
|
||||
"$ivl_queue_method$unique",
|
||||
static_cast<ivl_type_t>(queue), 1);
|
||||
fun->set_line(*this);
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
|
||||
if (member_comp.name == "unique_index") {
|
||||
if (!queue_method_element_is_integral_vec4(element_type)) {
|
||||
cerr << get_fileline() << ": sorry: queue unique_index() for this "
|
||||
<< "element type is not yet supported." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
}
|
||||
NetESFunc*fun = new NetESFunc(
|
||||
"$ivl_queue_method$unique_index",
|
||||
static_cast<ivl_type_t>(&ivl_queue_unique_index_ret), 1);
|
||||
fun->set_line(*this);
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
}
|
||||
|
||||
// Dynamic array (not queue) — array location / reduction methods.
|
||||
if (sr.net->darray_type() && !sr.net->queue_type() &&
|
||||
!sr.path_tail.empty()) {
|
||||
if (debug_elaborate) {
|
||||
cerr << get_fileline() << ": PEIdent::elaborate_expr: "
|
||||
"Ident " << sr.path_head
|
||||
|
|
@ -5162,40 +5579,16 @@ NetExpr* PEIdent::elaborate_expr_(Design*des, NetScope*scope,
|
|||
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
} else if (member_comp.name == "find") {
|
||||
cerr << get_fileline() << ": sorry: 'find()' "
|
||||
"array location method is not currently "
|
||||
"implemented." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
} else if (member_comp.name == "find_index") {
|
||||
cerr << get_fileline() << ": sorry: 'find_index()' "
|
||||
"array location method is not currently "
|
||||
"implemented." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
} else if (member_comp.name == "find_first") {
|
||||
cerr << get_fileline() << ": sorry: 'find_first()' "
|
||||
"array location method is not currently "
|
||||
"implemented." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
} else if (member_comp.name == "find_first_index") {
|
||||
cerr << get_fileline() << ": sorry: 'find_first_index()' "
|
||||
"array location method is not currently "
|
||||
"implemented." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
} else if (member_comp.name == "find_last") {
|
||||
cerr << get_fileline() << ": sorry: 'find_last()' "
|
||||
"array location method is not currently "
|
||||
"implemented." << endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
} else if (member_comp.name == "find_last_index") {
|
||||
cerr << get_fileline() << ": sorry: 'find_last_index()' "
|
||||
"array location method is not currently "
|
||||
"implemented." << endl;
|
||||
} else if (member_comp.name == "find" ||
|
||||
member_comp.name == "find_index" ||
|
||||
member_comp.name == "find_first" ||
|
||||
member_comp.name == "find_first_index" ||
|
||||
member_comp.name == "find_last" ||
|
||||
member_comp.name == "find_last_index") {
|
||||
cerr << get_fileline() << ": error: Array locator method `"
|
||||
<< member_comp.name << "' must be called with one "
|
||||
<< "argument, e.g. " << member_comp.name << "(value)."
|
||||
<< endl;
|
||||
des->errors += 1;
|
||||
return 0;
|
||||
} else if (member_comp.name == "min") {
|
||||
|
|
@ -5257,45 +5650,6 @@ NetExpr* PEIdent::elaborate_expr_(Design*des, NetScope*scope,
|
|||
}
|
||||
}
|
||||
|
||||
// If this is a queue object, and there are members in
|
||||
// the sr.path_tail, check for array properties.
|
||||
if (sr.net->queue_type() && !sr.path_tail.empty()) {
|
||||
if (debug_elaborate) {
|
||||
cerr << get_fileline() << ": PEIdent::elaborate_expr: "
|
||||
<< "Ident " << sr.path_head
|
||||
<< " looking for queue property " << sr.path_tail
|
||||
<< endl;
|
||||
}
|
||||
|
||||
ivl_assert(*this, sr.path_tail.size() == 1);
|
||||
const name_component_t member_comp = sr.path_tail.front();
|
||||
const netqueue_t*queue = sr.net->queue_type();
|
||||
ivl_type_t element_type = queue->element_type();
|
||||
if (member_comp.name == "pop_back") {
|
||||
NetESFunc*fun = new NetESFunc("$ivl_queue_method$pop_back",
|
||||
element_type, 1);
|
||||
fun->set_line(*this);
|
||||
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
|
||||
if (member_comp.name == "pop_front") {
|
||||
NetESFunc*fun = new NetESFunc("$ivl_queue_method$pop_front",
|
||||
element_type, 1);
|
||||
fun->set_line(*this);
|
||||
|
||||
NetESignal*arg = new NetESignal(sr.net);
|
||||
arg->set_line(*sr.net);
|
||||
|
||||
fun->parm(0, arg);
|
||||
return fun;
|
||||
}
|
||||
}
|
||||
|
||||
if ((sr.net->data_type() == IVL_VT_STRING) && !sr.path_tail.empty()) {
|
||||
if (debug_elaborate) {
|
||||
cerr << get_fileline() << ": PEIdent::elaborate_expr: "
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
// Regression: dynamic array locator methods (find* with predicate); results are queues.
|
||||
|
||||
module top;
|
||||
|
||||
bit failed = 0;
|
||||
|
||||
`define CHK(cond) \
|
||||
if (!(cond)) begin \
|
||||
$display("FAILED line %0d", `__LINE__); \
|
||||
failed = 1; \
|
||||
end
|
||||
|
||||
int array[] = '{4, 7, 2, 5, 7, 1, 6, 3, 1};
|
||||
int res[$];
|
||||
|
||||
initial begin
|
||||
res = array.find() with (item > 3);
|
||||
`CHK(res.size == 5);
|
||||
`CHK(res[0] == 4);
|
||||
`CHK(res[1] == 7);
|
||||
`CHK(res[2] == 5);
|
||||
`CHK(res[3] == 7);
|
||||
`CHK(res[4] == 6);
|
||||
|
||||
res = array.find_index() with (item == 4);
|
||||
`CHK(res.size == 1);
|
||||
`CHK(res[0] == 0);
|
||||
|
||||
res = array.find_first() with (item < 5 && item >= 3);
|
||||
`CHK(res.size == 1);
|
||||
`CHK(res[0] == 4);
|
||||
|
||||
res = array.find_first_index() with (item > 5);
|
||||
`CHK(res.size == 1);
|
||||
`CHK(res[0] == 1);
|
||||
|
||||
res = array.find_last() with (item <= 7 && item > 3);
|
||||
`CHK(res.size == 1);
|
||||
`CHK(res[0] == 6);
|
||||
|
||||
res = array.find_last_index() with (item < 3);
|
||||
`CHK(res.size == 1);
|
||||
`CHK(res[0] == 8);
|
||||
|
||||
if (!failed)
|
||||
$display("PASSED");
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
// Regression: queue find* locator methods (one argument: value matched with ==).
|
||||
|
||||
module top;
|
||||
|
||||
bit failed = 0;
|
||||
|
||||
`define CHK(cond) \
|
||||
if (!(cond)) begin \
|
||||
$display("FAILED line %0d", `__LINE__); \
|
||||
failed = 1; \
|
||||
end
|
||||
|
||||
int q[$];
|
||||
int f[$];
|
||||
int ix[$];
|
||||
int ff[$];
|
||||
int fi[$];
|
||||
int lf[$];
|
||||
int li[$];
|
||||
|
||||
initial begin
|
||||
q.delete();
|
||||
q.push_back(2);
|
||||
q.push_back(1);
|
||||
q.push_back(2);
|
||||
q.push_back(3);
|
||||
|
||||
f = q.find(2);
|
||||
`CHK(f.size == 2);
|
||||
`CHK(f[0] == 2);
|
||||
`CHK(f[1] == 2);
|
||||
|
||||
ix = q.find_index(2);
|
||||
`CHK(ix.size == 2);
|
||||
`CHK(ix[0] == 0);
|
||||
`CHK(ix[1] == 2);
|
||||
|
||||
ff = q.find_first(3);
|
||||
`CHK(ff.size == 1);
|
||||
`CHK(ff[0] == 3);
|
||||
fi = q.find_first_index(3);
|
||||
`CHK(fi.size == 1);
|
||||
`CHK(fi[0] == 3);
|
||||
|
||||
lf = q.find_last(2);
|
||||
`CHK(lf.size == 1);
|
||||
`CHK(lf[0] == 2);
|
||||
li = q.find_last_index(2);
|
||||
`CHK(li.size == 1);
|
||||
`CHK(li[0] == 2);
|
||||
|
||||
ff = q.find_first(99);
|
||||
`CHK(ff.size == 0);
|
||||
fi = q.find_first_index(99);
|
||||
`CHK(fi.size == 0);
|
||||
|
||||
if (!failed)
|
||||
$display("PASSED");
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
// Regression: queue locator methods with `with` — compound predicates and longer sequences.
|
||||
|
||||
module top;
|
||||
|
||||
bit failed = 0;
|
||||
|
||||
`define CHK(cond) \
|
||||
if (!(cond)) begin \
|
||||
$display("FAILED line %0d", `__LINE__); \
|
||||
failed = 1; \
|
||||
end
|
||||
|
||||
int q[$];
|
||||
int res[$];
|
||||
|
||||
initial begin
|
||||
q.delete();
|
||||
q.push_back(4);
|
||||
q.push_back(7);
|
||||
q.push_back(2);
|
||||
q.push_back(5);
|
||||
q.push_back(7);
|
||||
q.push_back(1);
|
||||
q.push_back(6);
|
||||
q.push_back(3);
|
||||
q.push_back(1);
|
||||
|
||||
res = q.find() with (item > 3);
|
||||
`CHK(res.size == 5);
|
||||
`CHK(res[0] == 4);
|
||||
`CHK(res[1] == 7);
|
||||
`CHK(res[2] == 5);
|
||||
`CHK(res[3] == 7);
|
||||
`CHK(res[4] == 6);
|
||||
|
||||
res = q.find_index() with (item == 4);
|
||||
`CHK(res.size == 1);
|
||||
`CHK(res[0] == 0);
|
||||
|
||||
res = q.find_first() with (item < 5 && item >= 3);
|
||||
`CHK(res.size == 1);
|
||||
`CHK(res[0] == 4);
|
||||
|
||||
res = q.find_first_index() with (item > 5);
|
||||
`CHK(res.size == 1);
|
||||
`CHK(res[0] == 1);
|
||||
|
||||
res = q.find_last() with (item <= 7 && item > 3);
|
||||
`CHK(res.size == 1);
|
||||
`CHK(res[0] == 6);
|
||||
|
||||
res = q.find_last_index() with (item < 3);
|
||||
`CHK(res.size == 1);
|
||||
`CHK(res[0] == 8);
|
||||
|
||||
if (!failed)
|
||||
$display("PASSED");
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
// Regression: queue find* locator methods with `with (predicate)` (item, index).
|
||||
|
||||
module top;
|
||||
|
||||
bit failed = 0;
|
||||
|
||||
`define CHK(cond) \
|
||||
if (!(cond)) begin \
|
||||
$display("FAILED line %0d", `__LINE__); \
|
||||
failed = 1; \
|
||||
end
|
||||
|
||||
int q[$];
|
||||
int f[$];
|
||||
int ix[$];
|
||||
int ff[$];
|
||||
int fi[$];
|
||||
int lf[$];
|
||||
int li[$];
|
||||
|
||||
initial begin
|
||||
q.delete();
|
||||
q.push_back(2);
|
||||
q.push_back(1);
|
||||
q.push_back(2);
|
||||
q.push_back(3);
|
||||
|
||||
f = q.find() with (item == 2);
|
||||
`CHK(f.size == 2);
|
||||
`CHK(f[0] == 2);
|
||||
`CHK(f[1] == 2);
|
||||
|
||||
ix = q.find_index() with (item == 2);
|
||||
`CHK(ix.size == 2);
|
||||
`CHK(ix[0] == 0);
|
||||
`CHK(ix[1] == 2);
|
||||
|
||||
ix = q.find_index() with (index > 0);
|
||||
`CHK(ix.size == 3);
|
||||
`CHK(ix[0] == 1);
|
||||
`CHK(ix[1] == 2);
|
||||
`CHK(ix[2] == 3);
|
||||
|
||||
ff = q.find_first() with (item == 3);
|
||||
`CHK(ff.size == 1);
|
||||
`CHK(ff[0] == 3);
|
||||
fi = q.find_first_index() with (item == 2 && index > 0);
|
||||
`CHK(fi.size == 1);
|
||||
`CHK(fi[0] == 2);
|
||||
|
||||
lf = q.find_last() with (item < 3);
|
||||
`CHK(lf.size == 1);
|
||||
`CHK(lf[0] == 2);
|
||||
li = q.find_last_index() with (item == 2);
|
||||
`CHK(li.size == 1);
|
||||
`CHK(li[0] == 2);
|
||||
|
||||
ff = q.find_first() with (item == 99);
|
||||
`CHK(ff.size == 0);
|
||||
fi = q.find_first_index() with (item == 99);
|
||||
`CHK(fi.size == 0);
|
||||
|
||||
if (!failed)
|
||||
$display("PASSED");
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Regression: queue unique() and unique_index() for integral packed queues.
|
||||
|
||||
module top;
|
||||
|
||||
bit failed = 0;
|
||||
|
||||
`define CHK(cond) \
|
||||
if (!(cond)) begin \
|
||||
$display("FAILED line %0d", `__LINE__); \
|
||||
failed = 1; \
|
||||
end
|
||||
|
||||
int q[$];
|
||||
int u[$];
|
||||
int ix[$];
|
||||
|
||||
initial begin
|
||||
q.delete();
|
||||
q.push_back(1);
|
||||
q.push_back(2);
|
||||
q.push_back(1);
|
||||
q.push_back(3);
|
||||
q.push_back(2);
|
||||
|
||||
u = q.unique();
|
||||
`CHK(u.size == 3);
|
||||
`CHK(u[0] == 1);
|
||||
`CHK(u[1] == 2);
|
||||
`CHK(u[2] == 3);
|
||||
|
||||
ix = q.unique_index();
|
||||
`CHK(ix.size == 3);
|
||||
`CHK(ix[0] == 0);
|
||||
`CHK(ix[1] == 1);
|
||||
`CHK(ix[2] == 3);
|
||||
|
||||
if (!failed)
|
||||
$display("PASSED");
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -308,6 +308,7 @@ sv_const_fail7 vvp_tests/sv_const_fail7.json
|
|||
sv_const_fail8 vvp_tests/sv_const_fail8.json
|
||||
sv_const_fail9 vvp_tests/sv_const_fail9.json
|
||||
sv_darray_assign_op vvp_tests/sv_darray_assign_op.json
|
||||
sv_darray_find_locators vvp_tests/sv_darray_find_locators.json
|
||||
sv_default_port_value1 vvp_tests/sv_default_port_value1.json
|
||||
sv_default_port_value2 vvp_tests/sv_default_port_value2.json
|
||||
sv_default_port_value3 vvp_tests/sv_default_port_value3.json
|
||||
|
|
@ -383,12 +384,16 @@ sv_parameter_type vvp_tests/sv_parameter_type.json
|
|||
sv_partsel_var_negative_packed vvp_tests/sv_partsel_var_negative_packed.json
|
||||
sv_queue_ap_method vvp_tests/sv_queue_ap_method.json
|
||||
sv_queue_assign_op vvp_tests/sv_queue_assign_op.json
|
||||
sv_queue_find vvp_tests/sv_queue_find.json
|
||||
sv_queue_find_locators_ext vvp_tests/sv_queue_find_locators_ext.json
|
||||
sv_queue_find_with vvp_tests/sv_queue_find_with.json
|
||||
sv_queue_method_insert_too_few_arg_fail vvp_tests/sv_queue_method_insert_too_few_arg_fail.json
|
||||
sv_queue_method_insert_too_many_arg_fail vvp_tests/sv_queue_method_insert_too_many_arg_fail.json
|
||||
sv_queue_method_push_back_too_few_arg_fail vvp_tests/sv_queue_method_push_back_too_few_arg_fail.json
|
||||
sv_queue_method_push_back_too_many_arg_fail vvp_tests/sv_queue_method_push_back_too_many_arg_fail.json
|
||||
sv_queue_method_push_front_too_few_arg_fail vvp_tests/sv_queue_method_push_front_too_few_arg_fail.json
|
||||
sv_queue_method_push_front_too_many_arg_fail vvp_tests/sv_queue_method_push_front_too_many_arg_fail.json
|
||||
sv_queue_unique vvp_tests/sv_queue_unique.json
|
||||
sv_soft_packed_union vvp_tests/sv_soft_packed_union.json
|
||||
sv_soft_packed_union_fail1 vvp_tests/sv_soft_packed_union_fail1.json
|
||||
sv_string_method_substr_too_few_arg_fail vvp_tests/sv_string_method_substr_too_few_arg_fail.json
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"type" : "normal",
|
||||
"source" : "sv_darray_find_locators.v",
|
||||
"iverilog-args" : [ "-g2005-sv" ],
|
||||
"vlog95" : {
|
||||
"__comment" : "SystemVerilog dynamic array locator methods",
|
||||
"type" : "CE"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"type" : "normal",
|
||||
"source" : "sv_queue_find.v",
|
||||
"iverilog-args" : [ "-g2005-sv" ],
|
||||
"vlog95" : {
|
||||
"__comment" : "SystemVerilog queues",
|
||||
"type" : "CE"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"type" : "normal",
|
||||
"source" : "sv_queue_find_locators_ext.v",
|
||||
"iverilog-args" : [ "-g2005-sv" ],
|
||||
"vlog95" : {
|
||||
"__comment" : "SystemVerilog queue locator methods",
|
||||
"type" : "CE"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"type" : "normal",
|
||||
"source" : "sv_queue_find_with.v",
|
||||
"iverilog-args" : [ "-g2005-sv" ],
|
||||
"vlog95" : {
|
||||
"__comment" : "SystemVerilog queues",
|
||||
"type" : "CE"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"type" : "normal",
|
||||
"source" : "sv_queue_unique.v",
|
||||
"iverilog-args" : [ "-g2005-sv" ],
|
||||
"vlog95" : {
|
||||
"__comment" : "SystemVerilog queues",
|
||||
"type" : "CE"
|
||||
}
|
||||
}
|
||||
16
netdarray.cc
16
netdarray.cc
|
|
@ -39,10 +39,20 @@ ivl_variable_type_t netdarray_t::base_type(void) const
|
|||
|
||||
bool netdarray_t::test_equivalence(ivl_type_t that) const
|
||||
{
|
||||
// Queues and dynamic arrays are not equivalent, so check for the base
|
||||
// type to make sure both are either dynamic array or queue.
|
||||
if (base_type() != that->base_type())
|
||||
const netdarray_t* that_da = dynamic_cast<const netdarray_t*>(that);
|
||||
if (!that_da) return false;
|
||||
|
||||
/* Queue vs unpacked dynamic array: same element type is assignable
|
||||
* (e.g. int[$] = array.find_first(...), locator return is a queue). */
|
||||
if (base_type() != that->base_type()) {
|
||||
if ((base_type() == IVL_VT_QUEUE &&
|
||||
that->base_type() == IVL_VT_DARRAY) ||
|
||||
(base_type() == IVL_VT_DARRAY &&
|
||||
that->base_type() == IVL_VT_QUEUE)) {
|
||||
return element_type()->type_equivalent(that_da->element_type());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return test_compatibility(that);
|
||||
}
|
||||
|
|
|
|||
71
netmisc.cc
71
netmisc.cc
|
|
@ -899,32 +899,38 @@ NetExpr* elab_and_eval(Design*des, NetScope*scope, PExpr*pe,
|
|||
if (tmp == 0) return 0;
|
||||
|
||||
if ((cast_type != IVL_VT_NO_TYPE) && (cast_type != tmp->expr_type())) {
|
||||
switch (tmp->expr_type()) {
|
||||
case IVL_VT_BOOL:
|
||||
case IVL_VT_LOGIC:
|
||||
case IVL_VT_REAL:
|
||||
break;
|
||||
default:
|
||||
cerr << tmp->get_fileline() << ": error: "
|
||||
"The expression '" << *pe << "' cannot be implicitly "
|
||||
"cast to the target type." << endl;
|
||||
des->errors += 1;
|
||||
delete tmp;
|
||||
return 0;
|
||||
}
|
||||
switch (cast_type) {
|
||||
case IVL_VT_REAL:
|
||||
tmp = cast_to_real(tmp);
|
||||
break;
|
||||
case IVL_VT_BOOL:
|
||||
tmp = cast_to_int2(tmp, pos_context_width);
|
||||
break;
|
||||
case IVL_VT_LOGIC:
|
||||
tmp = cast_to_int4(tmp, pos_context_width);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
bool qdar_mix = (cast_type == IVL_VT_QUEUE ||
|
||||
cast_type == IVL_VT_DARRAY) &&
|
||||
(tmp->expr_type() == IVL_VT_QUEUE ||
|
||||
tmp->expr_type() == IVL_VT_DARRAY);
|
||||
if (!qdar_mix) {
|
||||
switch (tmp->expr_type()) {
|
||||
case IVL_VT_BOOL:
|
||||
case IVL_VT_LOGIC:
|
||||
case IVL_VT_REAL:
|
||||
break;
|
||||
default:
|
||||
cerr << tmp->get_fileline() << ": error: "
|
||||
"The expression '" << *pe << "' cannot be implicitly "
|
||||
"cast to the target type." << endl;
|
||||
des->errors += 1;
|
||||
delete tmp;
|
||||
return 0;
|
||||
}
|
||||
switch (cast_type) {
|
||||
case IVL_VT_REAL:
|
||||
tmp = cast_to_real(tmp);
|
||||
break;
|
||||
case IVL_VT_BOOL:
|
||||
tmp = cast_to_int2(tmp, pos_context_width);
|
||||
break;
|
||||
case IVL_VT_LOGIC:
|
||||
tmp = cast_to_int4(tmp, pos_context_width);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eval_expr(tmp, context_width);
|
||||
|
|
@ -967,12 +973,25 @@ NetExpr* elab_and_eval(Design*des, NetScope*scope, PExpr*pe,
|
|||
compatible = lv_net_type->type_compatible(tmp->net_type());
|
||||
else
|
||||
compatible = false;
|
||||
} else if ((cast_type == IVL_VT_QUEUE || cast_type == IVL_VT_DARRAY) &&
|
||||
(expr_type == IVL_VT_QUEUE || expr_type == IVL_VT_DARRAY)) {
|
||||
if (tmp->net_type()) {
|
||||
compatible = lv_net_type->type_compatible(tmp->net_type());
|
||||
} else {
|
||||
compatible = cast_type == expr_type;
|
||||
}
|
||||
} else if (cast_type == IVL_VT_NO_TYPE) {
|
||||
compatible = true;
|
||||
} else {
|
||||
compatible = cast_type == expr_type;
|
||||
}
|
||||
|
||||
/* R-value may report a coarse expr_type while net_type matches (e.g.
|
||||
* queue locators); prefer structural compatibility when available. */
|
||||
if (!compatible && tmp->net_type()) {
|
||||
compatible = lv_net_type->type_compatible(tmp->net_type());
|
||||
}
|
||||
|
||||
if (!compatible) {
|
||||
// Catch some special cases.
|
||||
switch (cast_type) {
|
||||
|
|
|
|||
39
parse.y
39
parse.y
|
|
@ -4256,6 +4256,21 @@ call_chain_expr
|
|||
delete $5;
|
||||
$$ = tmp;
|
||||
}
|
||||
| call_chain_expr K_with '(' expression ')'
|
||||
{ PECallFunction* cf = dynamic_cast<PECallFunction*>($1);
|
||||
if (cf == 0) {
|
||||
if (gn_system_verilog())
|
||||
yyerror(@2, "Error: `with` clause must follow a method call.");
|
||||
else
|
||||
yyerror(@2, "Error: Enable SystemVerilog for `with` clause on method calls.");
|
||||
delete $1;
|
||||
delete $4;
|
||||
$$ = 0;
|
||||
} else {
|
||||
cf->set_with_clause($4);
|
||||
$$ = cf;
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
expr_primary
|
||||
|
|
@ -4321,6 +4336,15 @@ expr_primary
|
|||
so `id (` is not reduced as PEIdent + error. */
|
||||
| call_chain_expr
|
||||
{ $$ = $1; }
|
||||
/* SV: q.find with (item == 1) — iterator names item, index */
|
||||
| hierarchy_identifier K_with '(' expression ')'
|
||||
{ std::vector<named_pexpr_t> empty;
|
||||
PECallFunction* tmp = new PECallFunction(*$1, empty);
|
||||
FILE_NAME(tmp, @1);
|
||||
tmp->set_with_clause($4);
|
||||
delete $1;
|
||||
$$ = tmp;
|
||||
}
|
||||
| hierarchy_identifier
|
||||
{ PEIdent*tmp = pform_new_ident(@1, *$1);
|
||||
FILE_NAME(tmp, @1);
|
||||
|
|
@ -4344,14 +4368,6 @@ expr_primary
|
|||
$$ = tmp;
|
||||
delete nm;
|
||||
}
|
||||
| hierarchy_identifier '.' K_unique
|
||||
{ pform_name_t * nm = $1;
|
||||
nm->push_back(name_component_t(lex_strings.make("unique")));
|
||||
PEIdent*tmp = pform_new_ident(@1, *nm);
|
||||
FILE_NAME(tmp, @1);
|
||||
$$ = tmp;
|
||||
delete nm;
|
||||
}
|
||||
| hierarchy_identifier '.' K_xor
|
||||
{ pform_name_t * nm = $1;
|
||||
nm->push_back(name_component_t(lex_strings.make("xor")));
|
||||
|
|
@ -4360,7 +4376,6 @@ expr_primary
|
|||
$$ = tmp;
|
||||
delete nm;
|
||||
}
|
||||
|
||||
| package_scope hierarchy_identifier
|
||||
{ lex_in_package_scope(0);
|
||||
$$ = pform_package_ident(@2, $1, $2);
|
||||
|
|
@ -4860,6 +4875,12 @@ hierarchy_identifier
|
|||
delete[]$3;
|
||||
$$ = tmp;
|
||||
}
|
||||
/* "unique" is a keyword (K_unique) but also a queue/array method name. */
|
||||
| hierarchy_identifier '.' K_unique
|
||||
{ pform_name_t * tmp = $1;
|
||||
tmp->push_back(name_component_t(lex_strings.make("unique")));
|
||||
$$ = tmp;
|
||||
}
|
||||
| hierarchy_identifier '[' expression ']'
|
||||
{ pform_name_t * tmp = $1;
|
||||
name_component_t&tail = tmp->back();
|
||||
|
|
|
|||
|
|
@ -426,6 +426,9 @@ void PECallFunction::dump(ostream &out) const
|
|||
out << ".";
|
||||
}
|
||||
out << path_ << "(" << parms_ << ")";
|
||||
if (peek_with_clause()) {
|
||||
out << " with (" << *peek_with_clause() << ")";
|
||||
}
|
||||
}
|
||||
|
||||
void PECastSize::dump(ostream &out) const
|
||||
|
|
|
|||
|
|
@ -257,6 +257,340 @@ static int eval_object_ufunc(ivl_expr_t ex)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static unsigned queue_unique_src_elem_wid(ivl_expr_t arg)
|
||||
{
|
||||
ivl_type_t src_q = 0;
|
||||
if (ivl_expr_type(arg) == IVL_EX_PROPERTY) {
|
||||
ivl_signal_t cl = ivl_expr_signal(arg);
|
||||
unsigned pidx = ivl_expr_property_idx(arg);
|
||||
src_q = ivl_type_prop_type(ivl_signal_net_type(cl), pidx);
|
||||
} else if (ivl_expr_type(arg) == IVL_EX_SIGNAL) {
|
||||
src_q = ivl_signal_net_type(ivl_expr_signal(arg));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
if (ivl_type_base(src_q) == IVL_VT_QUEUE ||
|
||||
ivl_type_base(src_q) == IVL_VT_DARRAY) {
|
||||
return ivl_type_packed_width(ivl_type_element(src_q));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Emit a queue locator opcode. Plain signal uses `op_v`; class property
|
||||
* uses `op_prop_v`. Returning a queue object leaves it on the object stack.
|
||||
*
|
||||
* Note: opcode names are still type-specific (vec4) for this slice. Future
|
||||
* real/string/class support should prefer parameterized opcodes or typed
|
||||
* helpers rather than cloning this table per element type.
|
||||
*/
|
||||
static int emit_queue_locator_opcode(ivl_expr_t arg, unsigned elem_wid,
|
||||
const char* op_v, const char* op_prop_v)
|
||||
{
|
||||
if (ivl_expr_type(arg) == IVL_EX_PROPERTY) {
|
||||
ivl_signal_t cl = ivl_expr_signal(arg);
|
||||
unsigned pidx = ivl_expr_property_idx(arg);
|
||||
fprintf(vvp_out, " %%load/obj v%p_0;\n", cl);
|
||||
fprintf(vvp_out, " %s %u, %u;\n", op_prop_v, pidx, elem_wid);
|
||||
fprintf(vvp_out, " %%pop/obj 1, 0;\n");
|
||||
} else {
|
||||
ivl_signal_t sig = ivl_expr_signal(arg);
|
||||
fprintf(vvp_out, " %s v%p_0, %u;\n", op_v, sig, elem_wid);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int eval_queue_method_unique(ivl_expr_t expr)
|
||||
{
|
||||
static const struct {
|
||||
const char* name;
|
||||
const char* op_v;
|
||||
const char* op_prop_v;
|
||||
} table[] = {
|
||||
{ "$ivl_queue_method$unique",
|
||||
"%queue/unique/v", "%queue/unique/prop/v" },
|
||||
{ "$ivl_queue_method$unique_index",
|
||||
"%queue/unique/index/v", "%queue/unique/index/prop/v" },
|
||||
};
|
||||
|
||||
const char* name = ivl_expr_name(expr);
|
||||
ivl_expr_t arg = ivl_expr_parm(expr, 0);
|
||||
unsigned elem_wid = queue_unique_src_elem_wid(arg);
|
||||
if (elem_wid == 0) return 1;
|
||||
|
||||
for (unsigned idx = 0; idx < sizeof table / sizeof table[0]; idx += 1) {
|
||||
if (strcmp(name, table[idx].name) == 0) {
|
||||
return emit_queue_locator_opcode(arg, elem_wid,
|
||||
table[idx].op_v,
|
||||
table[idx].op_prop_v);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Array locator methods with `with (predicate)` — parms:
|
||||
* 0: queue, 1: predicate, 2: item ivl_signal, 3: index ivl_signal
|
||||
*/
|
||||
enum queue_locator_with_mode_e {
|
||||
QUEUE_WITH_FIND,
|
||||
QUEUE_WITH_FIND_INDEX,
|
||||
QUEUE_WITH_FIND_FIRST,
|
||||
QUEUE_WITH_FIND_FIRST_INDEX,
|
||||
QUEUE_WITH_FIND_LAST,
|
||||
QUEUE_WITH_FIND_LAST_INDEX
|
||||
};
|
||||
|
||||
static enum queue_locator_with_mode_e queue_locator_with_mode_from_name(
|
||||
const char* name)
|
||||
{
|
||||
if (strcmp(name, "$ivl_queue_method$find_with") == 0) {
|
||||
return QUEUE_WITH_FIND;
|
||||
} else if (strcmp(name, "$ivl_queue_method$find_index_with") == 0) {
|
||||
return QUEUE_WITH_FIND_INDEX;
|
||||
} else if (strcmp(name, "$ivl_queue_method$find_first_with") == 0) {
|
||||
return QUEUE_WITH_FIND_FIRST;
|
||||
} else if (strcmp(name, "$ivl_queue_method$find_first_index_with") == 0) {
|
||||
return QUEUE_WITH_FIND_FIRST_INDEX;
|
||||
} else if (strcmp(name, "$ivl_queue_method$find_last_with") == 0) {
|
||||
return QUEUE_WITH_FIND_LAST;
|
||||
} else if (strcmp(name, "$ivl_queue_method$find_last_index_with") == 0) {
|
||||
return QUEUE_WITH_FIND_LAST_INDEX;
|
||||
}
|
||||
return (enum queue_locator_with_mode_e) -1;
|
||||
}
|
||||
|
||||
static int queue_with_reverse(enum queue_locator_with_mode_e mode)
|
||||
{
|
||||
return mode == QUEUE_WITH_FIND_LAST ||
|
||||
mode == QUEUE_WITH_FIND_LAST_INDEX;
|
||||
}
|
||||
|
||||
static int queue_with_multi(enum queue_locator_with_mode_e mode)
|
||||
{
|
||||
return mode == QUEUE_WITH_FIND || mode == QUEUE_WITH_FIND_INDEX;
|
||||
}
|
||||
|
||||
static int queue_with_as_index(enum queue_locator_with_mode_e mode)
|
||||
{
|
||||
return mode == QUEUE_WITH_FIND_INDEX ||
|
||||
mode == QUEUE_WITH_FIND_FIRST_INDEX ||
|
||||
mode == QUEUE_WITH_FIND_LAST_INDEX;
|
||||
}
|
||||
|
||||
/* On predicate match: append value/index and continue or stop. */
|
||||
static void emit_queue_with_on_match(enum queue_locator_with_mode_e mode,
|
||||
ivl_signal_t item_sig, int i_reg,
|
||||
unsigned elem_wid, unsigned match_lab)
|
||||
{
|
||||
int multi = queue_with_multi(mode);
|
||||
int as_index = queue_with_as_index(mode);
|
||||
|
||||
if (!multi) {
|
||||
fprintf(vvp_out, " %%queue/new_empty/v;\n");
|
||||
}
|
||||
if (as_index) {
|
||||
fprintf(vvp_out, " %%push/ix/vec4 %u, 32, 1;\n", i_reg);
|
||||
fprintf(vvp_out, " %%queue/append_word/v 32;\n");
|
||||
} else {
|
||||
fprintf(vvp_out, " %%load/vec4 v%p_0;\n", item_sig);
|
||||
fprintf(vvp_out, " %%queue/append_word/v %u;\n", elem_wid);
|
||||
}
|
||||
fprintf(vvp_out, " %%jmp T_%u.%u;\n", thread_count, match_lab);
|
||||
}
|
||||
|
||||
static void emit_queue_with_init_index(int reverse, int i_reg, int n_reg)
|
||||
{
|
||||
if (!reverse) {
|
||||
fprintf(vvp_out, " %%ix/load %u, 0, 0;\n", i_reg);
|
||||
fprintf(vvp_out, " %%flag_set/imm 4, 0;\n");
|
||||
} else {
|
||||
fprintf(vvp_out, " %%ix/load %u, 0, 0;\n", i_reg);
|
||||
fprintf(vvp_out, " %%ix/mov %u, %u;\n", i_reg, n_reg);
|
||||
fprintf(vvp_out, " %%ix/sub %u, 1, 0;\n", i_reg);
|
||||
}
|
||||
}
|
||||
|
||||
static void emit_queue_with_loop_test(int reverse, int i_reg, int n_reg,
|
||||
unsigned lab_loop_end)
|
||||
{
|
||||
if (!reverse) {
|
||||
fprintf(vvp_out, " %%cmpix/ltu %u, %u;\n", i_reg, n_reg);
|
||||
fprintf(vvp_out, " %%jmp/0 T_%u.%u, 4;\n", thread_count,
|
||||
lab_loop_end);
|
||||
} else {
|
||||
fprintf(vvp_out, " %%cmpix/slt0 %u;\n", i_reg);
|
||||
fprintf(vvp_out, " %%jmp/1 T_%u.%u, 4;\n", thread_count,
|
||||
lab_loop_end);
|
||||
}
|
||||
}
|
||||
|
||||
static void emit_queue_with_step_index(int reverse, int i_reg, unsigned lab_top)
|
||||
{
|
||||
if (!reverse) {
|
||||
fprintf(vvp_out, " %%ix/add %u, 1, 0;\n", i_reg);
|
||||
} else {
|
||||
fprintf(vvp_out, " %%ix/sub %u, 1, 0;\n", i_reg);
|
||||
}
|
||||
fprintf(vvp_out, " %%jmp T_%u.%u;\n", thread_count, lab_top);
|
||||
}
|
||||
|
||||
static int eval_queue_method_find_with(ivl_expr_t expr)
|
||||
{
|
||||
const char* name = ivl_expr_name(expr);
|
||||
if (ivl_expr_parms(expr) != 4) return 1;
|
||||
if (strncmp(name, "$ivl_queue_method$",
|
||||
sizeof("$ivl_queue_method$") - 1) != 0) return 1;
|
||||
if (strstr(name, "_with") == 0) return 1;
|
||||
|
||||
ivl_expr_t qarg = ivl_expr_parm(expr, 0);
|
||||
ivl_expr_t pred = ivl_expr_parm(expr, 1);
|
||||
ivl_signal_t item_sig = ivl_expr_signal(ivl_expr_parm(expr, 2));
|
||||
ivl_signal_t idx_sig = ivl_expr_signal(ivl_expr_parm(expr, 3));
|
||||
unsigned elem_wid = queue_unique_src_elem_wid(qarg);
|
||||
if (elem_wid == 0) return 1;
|
||||
|
||||
enum queue_locator_with_mode_e mode =
|
||||
queue_locator_with_mode_from_name(name);
|
||||
if ((int) mode < 0) return 1;
|
||||
|
||||
int i_reg = allocate_word();
|
||||
int n_reg = allocate_word();
|
||||
unsigned lab_top = local_count++;
|
||||
unsigned lab_loop_end = local_count++;
|
||||
unsigned lab_nom = local_count++;
|
||||
unsigned lab_found = local_count++;
|
||||
unsigned lab_end = local_count++;
|
||||
int reverse = queue_with_reverse(mode);
|
||||
int multi = queue_with_multi(mode);
|
||||
int is_prop = (ivl_expr_type(qarg) == IVL_EX_PROPERTY);
|
||||
/* First/last stop label: property path needs an extra pop. */
|
||||
unsigned stop_lab = is_prop ? lab_found : lab_end;
|
||||
unsigned match_lab = multi ? lab_nom : stop_lab;
|
||||
|
||||
if (is_prop) {
|
||||
ivl_signal_t cl = ivl_expr_signal(qarg);
|
||||
unsigned pidx = ivl_expr_property_idx(qarg);
|
||||
fprintf(vvp_out, " %%load/obj v%p_0;\n", cl);
|
||||
fprintf(vvp_out, " %%prop/queue/size %u;\n", pidx);
|
||||
fprintf(vvp_out, " %%ix/vec4/s %u;\n", n_reg);
|
||||
if (multi) {
|
||||
fprintf(vvp_out, " %%queue/new_empty/v;\n");
|
||||
}
|
||||
emit_queue_with_init_index(reverse, i_reg, n_reg);
|
||||
fprintf(vvp_out, "T_%u.%u ; queue with loop\n", thread_count, lab_top);
|
||||
emit_queue_with_loop_test(reverse, i_reg, n_reg, lab_loop_end);
|
||||
/* cmpix leaves flag 4 set; %queue/word* uses flag 4 for X push */
|
||||
fprintf(vvp_out, " %%flag_set/imm 4, 0;\n");
|
||||
fprintf(vvp_out, " %%queue/word/prop/v %u, %u, %u;\n", pidx,
|
||||
elem_wid, i_reg);
|
||||
} else {
|
||||
ivl_signal_t sig = ivl_expr_signal(qarg);
|
||||
fprintf(vvp_out, " %%queue/size/v v%p_0;\n", sig);
|
||||
fprintf(vvp_out, " %%ix/vec4/s %u;\n", n_reg);
|
||||
if (multi) {
|
||||
fprintf(vvp_out, " %%queue/new_empty/v;\n");
|
||||
}
|
||||
emit_queue_with_init_index(reverse, i_reg, n_reg);
|
||||
fprintf(vvp_out, "T_%u.%u ; queue with loop (var)\n", thread_count,
|
||||
lab_top);
|
||||
emit_queue_with_loop_test(reverse, i_reg, n_reg, lab_loop_end);
|
||||
fprintf(vvp_out, " %%flag_set/imm 4, 0;\n");
|
||||
fprintf(vvp_out, " %%queue/word/v v%p_0, %u, %u;\n", sig, elem_wid,
|
||||
i_reg);
|
||||
}
|
||||
|
||||
fprintf(vvp_out, " %%store/vec4 v%p_0, 0, %u;\n", item_sig, elem_wid);
|
||||
fprintf(vvp_out, " %%push/ix/vec4 %u, 32, 1;\n", i_reg);
|
||||
fprintf(vvp_out, " %%store/vec4 v%p_0, 0, 32;\n", idx_sig);
|
||||
|
||||
int pf = draw_eval_condition(pred);
|
||||
fprintf(vvp_out, " %%jmp/0 T_%u.%u, %d;\n", thread_count, lab_nom, pf);
|
||||
clr_flag(pf);
|
||||
|
||||
emit_queue_with_on_match(mode, item_sig, i_reg, elem_wid, match_lab);
|
||||
|
||||
fprintf(vvp_out, "T_%u.%u ; nomatch\n", thread_count, lab_nom);
|
||||
emit_queue_with_step_index(reverse, i_reg, lab_top);
|
||||
|
||||
if (is_prop) {
|
||||
fprintf(vvp_out, "T_%u.%u ; found (queue prop)\n", thread_count,
|
||||
lab_found);
|
||||
fprintf(vvp_out, " %%pop/obj 1, 1;\n");
|
||||
fprintf(vvp_out, " %%jmp T_%u.%u;\n", thread_count, lab_end);
|
||||
|
||||
fprintf(vvp_out, "T_%u.%u ; loop end (prop)\n", thread_count,
|
||||
lab_loop_end);
|
||||
if (multi) {
|
||||
fprintf(vvp_out, " %%pop/obj 1, 0;\n");
|
||||
} else {
|
||||
fprintf(vvp_out, " %%queue/new_empty/v;\n");
|
||||
fprintf(vvp_out, " %%pop/obj 1, 1;\n");
|
||||
}
|
||||
fprintf(vvp_out, "T_%u.%u ; with end (prop)\n", thread_count, lab_end);
|
||||
} else {
|
||||
fprintf(vvp_out, "T_%u.%u ; loop end (var)\n", thread_count,
|
||||
lab_loop_end);
|
||||
if (!multi) {
|
||||
fprintf(vvp_out, " %%queue/new_empty/v;\n");
|
||||
}
|
||||
fprintf(vvp_out, "T_%u.%u ; with end (var)\n", thread_count, lab_end);
|
||||
}
|
||||
|
||||
clr_word(i_reg);
|
||||
clr_word(n_reg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int eval_queue_method_find(ivl_expr_t expr)
|
||||
{
|
||||
static const struct {
|
||||
const char* name;
|
||||
const char* op_v;
|
||||
const char* op_prop_v;
|
||||
} table[] = {
|
||||
{ "$ivl_queue_method$find",
|
||||
"%queue/find/v", "%queue/find/prop/v" },
|
||||
{ "$ivl_queue_method$find_index",
|
||||
"%queue/find/index/v", "%queue/find/index/prop/v" },
|
||||
{ "$ivl_queue_method$find_first",
|
||||
"%queue/find_first/v", "%queue/find_first/prop/v" },
|
||||
{ "$ivl_queue_method$find_first_index",
|
||||
"%queue/find_first/index/v", "%queue/find_first/index/prop/v" },
|
||||
{ "$ivl_queue_method$find_last",
|
||||
"%queue/find_last/v", "%queue/find_last/prop/v" },
|
||||
{ "$ivl_queue_method$find_last_index",
|
||||
"%queue/find_last/index/v", "%queue/find_last/index/prop/v" },
|
||||
};
|
||||
|
||||
const char* name = ivl_expr_name(expr);
|
||||
if (ivl_expr_parms(expr) == 4 &&
|
||||
strstr(ivl_expr_name(expr), "_with") != 0) {
|
||||
return eval_queue_method_find_with(expr);
|
||||
}
|
||||
|
||||
ivl_expr_t qarg = ivl_expr_parm(expr, 0);
|
||||
ivl_expr_t carg = ivl_expr_parm(expr, 1);
|
||||
unsigned elem_wid = queue_unique_src_elem_wid(qarg);
|
||||
if (elem_wid == 0) return 1;
|
||||
|
||||
draw_eval_vec4(carg);
|
||||
|
||||
for (unsigned idx = 0; idx < sizeof table / sizeof table[0]; idx += 1) {
|
||||
if (strcmp(name, table[idx].name) == 0) {
|
||||
return emit_queue_locator_opcode(qarg, elem_wid,
|
||||
table[idx].op_v,
|
||||
table[idx].op_prop_v);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int draw_queue_method_find_sfunc(ivl_expr_t expr)
|
||||
{
|
||||
return eval_queue_method_find(expr);
|
||||
}
|
||||
|
||||
int draw_eval_object(ivl_expr_t ex)
|
||||
{
|
||||
switch (ivl_expr_type(ex)) {
|
||||
|
|
@ -288,6 +622,23 @@ int draw_eval_object(ivl_expr_t ex)
|
|||
case IVL_EX_UFUNC:
|
||||
return eval_object_ufunc(ex);
|
||||
|
||||
case IVL_EX_SFUNC:
|
||||
/* Queue locator `with` may report IVL_VT_DARRAY in ivl; handle by name. */
|
||||
if (ivl_expr_parms(ex) == 4 &&
|
||||
strncmp(ivl_expr_name(ex), "$ivl_queue_method$",
|
||||
sizeof("$ivl_queue_method$") - 1) == 0 &&
|
||||
strstr(ivl_expr_name(ex), "_with") != 0) {
|
||||
if (draw_queue_method_find_sfunc(ex) == 0) return 0;
|
||||
}
|
||||
if (ivl_expr_value(ex) == IVL_VT_QUEUE ||
|
||||
ivl_expr_value(ex) == IVL_VT_DARRAY) {
|
||||
if (eval_queue_method_unique(ex) == 0) return 0;
|
||||
if (eval_queue_method_find(ex) == 0) return 0;
|
||||
}
|
||||
fprintf(vvp_out, "; ERROR: draw_eval_object: unsupported IVL_EX_SFUNC "
|
||||
"for object context\n");
|
||||
return 1;
|
||||
|
||||
default:
|
||||
fprintf(vvp_out, "; ERROR: draw_eval_object: Invalid expression type %d\n", ivl_expr_type(ex));
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -1110,6 +1110,14 @@ static void draw_sfunc_vec4(ivl_expr_t expr)
|
|||
return;
|
||||
}
|
||||
|
||||
/* find*_with has four parameters and is lowered in eval_object.c */
|
||||
if (parm_count == 4 &&
|
||||
strncmp(ivl_expr_name(expr), "$ivl_queue_method$",
|
||||
sizeof("$ivl_queue_method$") - 1) == 0 &&
|
||||
strstr(ivl_expr_name(expr), "_with") != 0) {
|
||||
if (draw_queue_method_find_sfunc(expr) == 0) return;
|
||||
}
|
||||
|
||||
if (strcmp(ivl_expr_name(expr), "$size")==0 && parm_count==1) {
|
||||
ivl_expr_t arg = ivl_expr_parm(expr, 0);
|
||||
if (ivl_expr_type(arg) == IVL_EX_PROPERTY) {
|
||||
|
|
|
|||
|
|
@ -228,6 +228,12 @@ extern void draw_eval_string(ivl_expr_t ex);
|
|||
*/
|
||||
extern int draw_eval_object(ivl_expr_t ex);
|
||||
|
||||
/*
|
||||
* Emit vvp for $ivl_queue_method$find* / find*_with when the call appears
|
||||
* as a vector SFUNC (e.g. find_first with (...) returning int).
|
||||
*/
|
||||
extern int draw_queue_method_find_sfunc(ivl_expr_t expr);
|
||||
|
||||
extern int show_stmt_assign(ivl_statement_t net);
|
||||
extern void show_stmt_file_line(ivl_statement_t net, const char*desc);
|
||||
|
||||
|
|
|
|||
24
vvp/codes.h
24
vvp/codes.h
|
|
@ -250,6 +250,30 @@ extern bool of_QPOP_PROP_F_REAL(vthread_t thr, vvp_code_t code);
|
|||
extern bool of_QPOP_PROP_F_STR(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QPOP_PROP_F_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_PROP_QUEUE_SIZE(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_APPEND_WORD_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_NEW_EMPTY_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_SIZE_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_WORD_PROP_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_WORD_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_CMPIX_LTU(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_CMPIX_SLT0(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_PUSH_IX_VEC4(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_INDEX_PROP_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_INDEX_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_PROP_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_FIRST_INDEX_PROP_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_FIRST_INDEX_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_FIRST_PROP_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_FIRST_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_LAST_INDEX_PROP_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_LAST_INDEX_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_LAST_PROP_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_FIND_LAST_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_UNIQUE_INDEX_PROP_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_UNIQUE_INDEX_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_UNIQUE_PROP_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_QUEUE_UNIQUE_V(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_DELETE_PROP_ELEM(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_DELETE_PROP_OBJ(vthread_t thr, vvp_code_t code);
|
||||
extern bool of_STORE_QB_R(vthread_t thr, vvp_code_t code);
|
||||
|
|
|
|||
|
|
@ -139,6 +139,8 @@ static const struct opcode_table_s opcode_table[] = {
|
|||
{ "%cmpi/ne", of_CMPINE, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
|
||||
{ "%cmpi/s", of_CMPIS, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
|
||||
{ "%cmpi/u", of_CMPIU, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
|
||||
{ "%cmpix/ltu", of_CMPIX_LTU, 2, {OA_NUMBER, OA_BIT1, OA_NONE} },
|
||||
{ "%cmpix/slt0", of_CMPIX_SLT0, 1, {OA_NUMBER, OA_NONE, OA_NONE} },
|
||||
{ "%concat/str", of_CONCAT_STR, 0,{OA_NONE, OA_NONE, OA_NONE} },
|
||||
{ "%concat/vec4", of_CONCAT_VEC4, 0,{OA_NONE, OA_NONE, OA_NONE} },
|
||||
{ "%concati/str", of_CONCATI_STR, 1,{OA_STRING,OA_NONE, OA_NONE} },
|
||||
|
|
@ -253,6 +255,7 @@ static const struct opcode_table_s opcode_table[] = {
|
|||
{ "%prop/r", of_PROP_R, 1, {OA_NUMBER, OA_NONE, OA_NONE} },
|
||||
{ "%prop/str",of_PROP_STR,1, {OA_NUMBER, OA_NONE, OA_NONE} },
|
||||
{ "%prop/v", of_PROP_V, 1, {OA_NUMBER, OA_NONE, OA_NONE} },
|
||||
{ "%push/ix/vec4", of_PUSH_IX_VEC4, 3, {OA_NUMBER, OA_BIT1, OA_BIT2} },
|
||||
{ "%pushi/real",of_PUSHI_REAL,2,{OA_BIT1, OA_BIT2, OA_NONE} },
|
||||
{ "%pushi/str", of_PUSHI_STR, 1,{OA_STRING, OA_NONE, OA_NONE} },
|
||||
{ "%pushi/vec4",of_PUSHI_VEC4,3,{OA_BIT1, OA_BIT2, OA_NUMBER} },
|
||||
|
|
@ -276,6 +279,27 @@ static const struct opcode_table_s opcode_table[] = {
|
|||
{ "%qpop/prop/f/r", of_QPOP_PROP_F_REAL, 1, {OA_NUMBER, OA_NONE, OA_NONE} },
|
||||
{ "%qpop/prop/f/str", of_QPOP_PROP_F_STR, 1, {OA_NUMBER, OA_NONE, OA_NONE} },
|
||||
{ "%qpop/prop/f/v", of_QPOP_PROP_F_V, 2, {OA_NUMBER, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/append_word/v", of_QUEUE_APPEND_WORD_V, 1, {OA_BIT1, OA_NONE, OA_NONE} },
|
||||
{ "%queue/find/index/prop/v", of_QUEUE_FIND_INDEX_PROP_V, 2, {OA_NUMBER, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/find/index/v", of_QUEUE_FIND_INDEX_V, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/find/prop/v", of_QUEUE_FIND_PROP_V, 2, {OA_NUMBER, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/find/v", of_QUEUE_FIND_V, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/find_first/index/prop/v", of_QUEUE_FIND_FIRST_INDEX_PROP_V, 2, {OA_NUMBER, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/find_first/index/v", of_QUEUE_FIND_FIRST_INDEX_V, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/find_first/prop/v", of_QUEUE_FIND_FIRST_PROP_V, 2, {OA_NUMBER, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/find_first/v", of_QUEUE_FIND_FIRST_V, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/find_last/index/prop/v", of_QUEUE_FIND_LAST_INDEX_PROP_V, 2, {OA_NUMBER, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/find_last/index/v", of_QUEUE_FIND_LAST_INDEX_V, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/find_last/prop/v", of_QUEUE_FIND_LAST_PROP_V, 2, {OA_NUMBER, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/find_last/v", of_QUEUE_FIND_LAST_V, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/new_empty/v", of_QUEUE_NEW_EMPTY_V, 0, {OA_NONE, OA_NONE, OA_NONE} },
|
||||
{ "%queue/size/v", of_QUEUE_SIZE_V, 1, {OA_FUNC_PTR, OA_NONE, OA_NONE} },
|
||||
{ "%queue/unique/index/prop/v", of_QUEUE_UNIQUE_INDEX_PROP_V, 2, {OA_NUMBER, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/unique/index/v", of_QUEUE_UNIQUE_INDEX_V, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/unique/prop/v", of_QUEUE_UNIQUE_PROP_V, 2, {OA_NUMBER, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/unique/v", of_QUEUE_UNIQUE_V, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
|
||||
{ "%queue/word/prop/v", of_QUEUE_WORD_PROP_V, 3, {OA_NUMBER, OA_BIT1, OA_BIT2} },
|
||||
{ "%queue/word/v", of_QUEUE_WORD_V, 3, {OA_FUNC_PTR, OA_BIT1, OA_BIT2} },
|
||||
{ "%release/net",of_RELEASE_NET,3,{OA_FUNC_PTR,OA_BIT1,OA_BIT2} },
|
||||
{ "%release/reg",of_RELEASE_REG,3,{OA_FUNC_PTR,OA_BIT1,OA_BIT2} },
|
||||
{ "%release/wr", of_RELEASE_WR, 2,{OA_FUNC_PTR,OA_BIT1,OA_NONE} },
|
||||
|
|
|
|||
642
vvp/vthread.cc
642
vvp/vthread.cc
|
|
@ -504,6 +504,42 @@ template <class VVP_QUEUE> static vvp_queue*get_queue_object(vthread_t thr, vvp_
|
|||
return queue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Locator and size/word opcodes use the same VVP net for a queue ($) or a
|
||||
* dynamic array ([]). Queues are vvp_queue_vec4; dynamic arrays may be
|
||||
* vvp_darray_vec4, vvp_darray_atom<>, etc. (all vvp_darray, but vvp_queue
|
||||
* also derives from vvp_darray — test queue vec4 first).
|
||||
*/
|
||||
static void get_queue_or_darray_vec4_from_net(vthread_t thr, vvp_net_t* net,
|
||||
vvp_queue_vec4*& qsrc,
|
||||
vvp_darray*& dsrc)
|
||||
{
|
||||
vvp_fun_signal_object* obj = dynamic_cast<vvp_fun_signal_object*>(net->fun);
|
||||
assert(obj);
|
||||
vvp_object_t top = obj->get_object();
|
||||
qsrc = top.peek<vvp_queue_vec4>();
|
||||
if (qsrc) {
|
||||
dsrc = 0;
|
||||
return;
|
||||
}
|
||||
vvp_darray* dany = top.peek<vvp_darray>();
|
||||
if (dany && dynamic_cast<vvp_queue*>(dany) == 0) {
|
||||
dsrc = dany;
|
||||
return;
|
||||
}
|
||||
if (top.test_nil()) {
|
||||
qsrc = new vvp_queue_vec4();
|
||||
vvp_object_t val(qsrc);
|
||||
vvp_net_ptr_t ptr(net, 0);
|
||||
vvp_send_object(ptr, val, thr->wt_context);
|
||||
dsrc = 0;
|
||||
return;
|
||||
}
|
||||
/* e.g. real/string queue — not vec4 queue or plain darray */
|
||||
qsrc = 0;
|
||||
dsrc = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* The following are used to allow a common template to be written for
|
||||
* queue real/string/vec4 operations
|
||||
|
|
@ -6128,6 +6164,449 @@ bool of_QPOP_PROP_F_V(vthread_t thr, vvp_code_t cp)
|
|||
return qpop_f_prop<vvp_vector4_t, vvp_queue_vec4>(thr, cp, cp->bit_idx[0]);
|
||||
}
|
||||
|
||||
static vvp_vector4_t queue_unique_ulong_to_vec4(unsigned long ul, unsigned bits)
|
||||
{
|
||||
vvp_vector4_t val(bits, BIT4_0);
|
||||
for (unsigned idx = 0; idx < bits && idx < 8 * sizeof(unsigned long); idx += 1) {
|
||||
if (ul & 1UL) {
|
||||
val.set_bit(idx, BIT4_1);
|
||||
} else {
|
||||
val.set_bit(idx, BIT4_0);
|
||||
}
|
||||
ul >>= 1;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
template <class SRC> static vvp_queue_vec4* queue_run_unique_src(SRC* src,
|
||||
unsigned wid,
|
||||
bool as_index)
|
||||
{
|
||||
vvp_queue_vec4* dst = new vvp_queue_vec4();
|
||||
if (!src) return dst;
|
||||
size_t n = src->get_size();
|
||||
for (size_t i = 0; i < n; i += 1) {
|
||||
vvp_vector4_t vi(wid);
|
||||
src->get_word(i, vi);
|
||||
bool seen = false;
|
||||
for (size_t j = 0; j < i; j += 1) {
|
||||
vvp_vector4_t vj(wid);
|
||||
src->get_word(j, vj);
|
||||
if (vi.eeq(vj)) {
|
||||
seen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (seen) continue;
|
||||
if (as_index) {
|
||||
dst->push_back(queue_unique_ulong_to_vec4((unsigned long)i, 32), 0);
|
||||
} else {
|
||||
dst->push_back(vi, 0);
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
template <class SRC>
|
||||
static vvp_queue_vec4* queue_run_find_matches_src(SRC* src, unsigned wid,
|
||||
const vvp_vector4_t& cmp,
|
||||
bool as_index)
|
||||
{
|
||||
vvp_queue_vec4* dst = new vvp_queue_vec4();
|
||||
if (!src) return dst;
|
||||
size_t n = src->get_size();
|
||||
for (size_t i = 0; i < n; i += 1) {
|
||||
vvp_vector4_t vi(wid);
|
||||
src->get_word(i, vi);
|
||||
if (vi.eeq(cmp)) {
|
||||
if (as_index) {
|
||||
dst->push_back(queue_unique_ulong_to_vec4((unsigned long)i, 32), 0);
|
||||
} else {
|
||||
dst->push_back(vi, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
/* Array/queue locator methods return a queue with 0 or 1 elements (LRM). */
|
||||
template <class SRC>
|
||||
static vvp_queue_vec4* queue_find_first_last_to_queue_src(SRC* src,
|
||||
unsigned wid,
|
||||
const vvp_vector4_t& cmp,
|
||||
bool want_first,
|
||||
bool want_index)
|
||||
{
|
||||
vvp_queue_vec4* dst = new vvp_queue_vec4();
|
||||
if (!src || src->get_size() == 0) return dst;
|
||||
size_t n = src->get_size();
|
||||
if (want_first) {
|
||||
for (size_t i = 0; i < n; i += 1) {
|
||||
vvp_vector4_t vi(wid);
|
||||
src->get_word(i, vi);
|
||||
if (vi.eeq(cmp)) {
|
||||
if (want_index) {
|
||||
dst->push_back(
|
||||
queue_unique_ulong_to_vec4((unsigned long)i, 32),
|
||||
0);
|
||||
} else {
|
||||
dst->push_back(vi, 0);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (size_t i = n; i > 0; ) {
|
||||
i -= 1;
|
||||
vvp_vector4_t vi(wid);
|
||||
src->get_word(i, vi);
|
||||
if (vi.eeq(cmp)) {
|
||||
if (want_index) {
|
||||
dst->push_back(
|
||||
queue_unique_ulong_to_vec4((unsigned long)i, 32),
|
||||
0);
|
||||
} else {
|
||||
dst->push_back(vi, 0);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
vvp_net_t* net = cp->net;
|
||||
vvp_queue_vec4* qsrc = 0;
|
||||
vvp_darray* dsrc = 0;
|
||||
get_queue_or_darray_vec4_from_net(thr, net, qsrc, dsrc);
|
||||
vvp_queue_vec4* dst;
|
||||
if (qsrc) dst = queue_run_find_matches_src(qsrc, wid, cmp, false);
|
||||
else if (dsrc) dst = queue_run_find_matches_src(dsrc, wid, cmp, false);
|
||||
else {
|
||||
vvp_queue* src_q = get_queue_object<vvp_queue_vec4>(thr, net);
|
||||
vvp_queue_vec4* src = dynamic_cast<vvp_queue_vec4*>(src_q);
|
||||
dst = queue_run_find_matches_src(src, wid, cmp, false);
|
||||
}
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_PROP_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
size_t pid = cp->number;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
|
||||
vvp_object_t& top = thr->peek_object();
|
||||
vvp_cobject*cobj = top.peek<vvp_cobject>();
|
||||
assert(cobj);
|
||||
|
||||
vvp_object_t qobj;
|
||||
cobj->get_object(pid, qobj, 0);
|
||||
vvp_queue_vec4* src = qobj.peek<vvp_queue_vec4>();
|
||||
if (src == 0) {
|
||||
thr->push_object(vvp_object_t(new vvp_queue_vec4()));
|
||||
return true;
|
||||
}
|
||||
vvp_queue_vec4* dst = queue_run_find_matches_src(src, wid, cmp, false);
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_INDEX_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
vvp_net_t* net = cp->net;
|
||||
vvp_queue_vec4* qsrc = 0;
|
||||
vvp_darray* dsrc = 0;
|
||||
get_queue_or_darray_vec4_from_net(thr, net, qsrc, dsrc);
|
||||
vvp_queue_vec4* dst;
|
||||
if (qsrc) dst = queue_run_find_matches_src(qsrc, wid, cmp, true);
|
||||
else if (dsrc) dst = queue_run_find_matches_src(dsrc, wid, cmp, true);
|
||||
else {
|
||||
vvp_queue* src_q = get_queue_object<vvp_queue_vec4>(thr, net);
|
||||
vvp_queue_vec4* src = dynamic_cast<vvp_queue_vec4*>(src_q);
|
||||
dst = queue_run_find_matches_src(src, wid, cmp, true);
|
||||
}
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_INDEX_PROP_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
size_t pid = cp->number;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
|
||||
vvp_object_t& top = thr->peek_object();
|
||||
vvp_cobject*cobj = top.peek<vvp_cobject>();
|
||||
assert(cobj);
|
||||
|
||||
vvp_object_t qobj;
|
||||
cobj->get_object(pid, qobj, 0);
|
||||
vvp_queue_vec4* src = qobj.peek<vvp_queue_vec4>();
|
||||
if (src == 0) {
|
||||
thr->push_object(vvp_object_t(new vvp_queue_vec4()));
|
||||
return true;
|
||||
}
|
||||
vvp_queue_vec4* dst = queue_run_find_matches_src(src, wid, cmp, true);
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_FIRST_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
vvp_net_t* net = cp->net;
|
||||
vvp_queue_vec4* qsrc = 0;
|
||||
vvp_darray* dsrc = 0;
|
||||
get_queue_or_darray_vec4_from_net(thr, net, qsrc, dsrc);
|
||||
vvp_queue_vec4* dst;
|
||||
if (qsrc) dst = queue_find_first_last_to_queue_src(qsrc, wid, cmp, true, false);
|
||||
else if (dsrc) dst = queue_find_first_last_to_queue_src(dsrc, wid, cmp, true, false);
|
||||
else {
|
||||
vvp_queue* src_q = get_queue_object<vvp_queue_vec4>(thr, net);
|
||||
vvp_queue_vec4* src = dynamic_cast<vvp_queue_vec4*>(src_q);
|
||||
dst = queue_find_first_last_to_queue_src(src, wid, cmp, true, false);
|
||||
}
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_FIRST_PROP_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
size_t pid = cp->number;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
|
||||
vvp_object_t& top = thr->peek_object();
|
||||
vvp_cobject*cobj = top.peek<vvp_cobject>();
|
||||
assert(cobj);
|
||||
|
||||
vvp_object_t qobj;
|
||||
cobj->get_object(pid, qobj, 0);
|
||||
vvp_queue_vec4* src = qobj.peek<vvp_queue_vec4>();
|
||||
vvp_queue_vec4* dst =
|
||||
queue_find_first_last_to_queue_src(src, wid, cmp, true, false);
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_FIRST_INDEX_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
vvp_net_t* net = cp->net;
|
||||
vvp_queue_vec4* qsrc = 0;
|
||||
vvp_darray* dsrc = 0;
|
||||
get_queue_or_darray_vec4_from_net(thr, net, qsrc, dsrc);
|
||||
vvp_queue_vec4* dst;
|
||||
if (qsrc) dst = queue_find_first_last_to_queue_src(qsrc, wid, cmp, true, true);
|
||||
else if (dsrc) dst = queue_find_first_last_to_queue_src(dsrc, wid, cmp, true, true);
|
||||
else {
|
||||
vvp_queue* src_q = get_queue_object<vvp_queue_vec4>(thr, net);
|
||||
vvp_queue_vec4* src = dynamic_cast<vvp_queue_vec4*>(src_q);
|
||||
dst = queue_find_first_last_to_queue_src(src, wid, cmp, true, true);
|
||||
}
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_FIRST_INDEX_PROP_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
size_t pid = cp->number;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
|
||||
vvp_object_t& top = thr->peek_object();
|
||||
vvp_cobject*cobj = top.peek<vvp_cobject>();
|
||||
assert(cobj);
|
||||
|
||||
vvp_object_t qobj;
|
||||
cobj->get_object(pid, qobj, 0);
|
||||
vvp_queue_vec4* src = qobj.peek<vvp_queue_vec4>();
|
||||
vvp_queue_vec4* dst =
|
||||
queue_find_first_last_to_queue_src(src, wid, cmp, true, true);
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_LAST_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
vvp_net_t* net = cp->net;
|
||||
vvp_queue_vec4* qsrc = 0;
|
||||
vvp_darray* dsrc = 0;
|
||||
get_queue_or_darray_vec4_from_net(thr, net, qsrc, dsrc);
|
||||
vvp_queue_vec4* dst;
|
||||
if (qsrc) dst = queue_find_first_last_to_queue_src(qsrc, wid, cmp, false, false);
|
||||
else if (dsrc) dst = queue_find_first_last_to_queue_src(dsrc, wid, cmp, false, false);
|
||||
else {
|
||||
vvp_queue* src_q = get_queue_object<vvp_queue_vec4>(thr, net);
|
||||
vvp_queue_vec4* src = dynamic_cast<vvp_queue_vec4*>(src_q);
|
||||
dst = queue_find_first_last_to_queue_src(src, wid, cmp, false, false);
|
||||
}
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_LAST_PROP_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
size_t pid = cp->number;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
|
||||
vvp_object_t& top = thr->peek_object();
|
||||
vvp_cobject*cobj = top.peek<vvp_cobject>();
|
||||
assert(cobj);
|
||||
|
||||
vvp_object_t qobj;
|
||||
cobj->get_object(pid, qobj, 0);
|
||||
vvp_queue_vec4* src = qobj.peek<vvp_queue_vec4>();
|
||||
vvp_queue_vec4* dst =
|
||||
queue_find_first_last_to_queue_src(src, wid, cmp, false, false);
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_LAST_INDEX_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
vvp_net_t* net = cp->net;
|
||||
vvp_queue_vec4* qsrc = 0;
|
||||
vvp_darray* dsrc = 0;
|
||||
get_queue_or_darray_vec4_from_net(thr, net, qsrc, dsrc);
|
||||
vvp_queue_vec4* dst;
|
||||
if (qsrc) dst = queue_find_first_last_to_queue_src(qsrc, wid, cmp, false, true);
|
||||
else if (dsrc) dst = queue_find_first_last_to_queue_src(dsrc, wid, cmp, false, true);
|
||||
else {
|
||||
vvp_queue* src_q = get_queue_object<vvp_queue_vec4>(thr, net);
|
||||
vvp_queue_vec4* src = dynamic_cast<vvp_queue_vec4*>(src_q);
|
||||
dst = queue_find_first_last_to_queue_src(src, wid, cmp, false, true);
|
||||
}
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_FIND_LAST_INDEX_PROP_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_vector4_t cmp = thr->pop_vec4();
|
||||
size_t pid = cp->number;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
assert(cmp.size() == wid);
|
||||
|
||||
vvp_object_t& top = thr->peek_object();
|
||||
vvp_cobject*cobj = top.peek<vvp_cobject>();
|
||||
assert(cobj);
|
||||
|
||||
vvp_object_t qobj;
|
||||
cobj->get_object(pid, qobj, 0);
|
||||
vvp_queue_vec4* src = qobj.peek<vvp_queue_vec4>();
|
||||
vvp_queue_vec4* dst =
|
||||
queue_find_first_last_to_queue_src(src, wid, cmp, false, true);
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_UNIQUE_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_net_t*net = cp->net;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
vvp_queue_vec4* qsrc = 0;
|
||||
vvp_darray* dsrc = 0;
|
||||
get_queue_or_darray_vec4_from_net(thr, net, qsrc, dsrc);
|
||||
vvp_queue_vec4* dst;
|
||||
if (qsrc) dst = queue_run_unique_src(qsrc, wid, false);
|
||||
else if (dsrc) dst = queue_run_unique_src(dsrc, wid, false);
|
||||
else {
|
||||
vvp_queue* src_q = get_queue_object<vvp_queue_vec4>(thr, net);
|
||||
vvp_queue_vec4* src = dynamic_cast<vvp_queue_vec4*>(src_q);
|
||||
dst = queue_run_unique_src(src, wid, false);
|
||||
}
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_UNIQUE_PROP_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
size_t pid = cp->number;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
|
||||
vvp_object_t& top = thr->peek_object();
|
||||
vvp_cobject*cobj = top.peek<vvp_cobject>();
|
||||
assert(cobj);
|
||||
|
||||
vvp_object_t qobj;
|
||||
cobj->get_object(pid, qobj, 0);
|
||||
vvp_queue_vec4* src = qobj.peek<vvp_queue_vec4>();
|
||||
if (src == 0) {
|
||||
thr->push_object(vvp_object_t(new vvp_queue_vec4()));
|
||||
return true;
|
||||
}
|
||||
vvp_queue_vec4* dst = queue_run_unique_src(src, wid, false);
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_UNIQUE_INDEX_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_net_t*net = cp->net;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
vvp_queue_vec4* qsrc = 0;
|
||||
vvp_darray* dsrc = 0;
|
||||
get_queue_or_darray_vec4_from_net(thr, net, qsrc, dsrc);
|
||||
vvp_queue_vec4* dst;
|
||||
if (qsrc) dst = queue_run_unique_src(qsrc, wid, true);
|
||||
else if (dsrc) dst = queue_run_unique_src(dsrc, wid, true);
|
||||
else {
|
||||
vvp_queue* src_q = get_queue_object<vvp_queue_vec4>(thr, net);
|
||||
vvp_queue_vec4* src = dynamic_cast<vvp_queue_vec4*>(src_q);
|
||||
dst = queue_run_unique_src(src, wid, true);
|
||||
}
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_UNIQUE_INDEX_PROP_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
size_t pid = cp->number;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
|
||||
vvp_object_t& top = thr->peek_object();
|
||||
vvp_cobject*cobj = top.peek<vvp_cobject>();
|
||||
assert(cobj);
|
||||
|
||||
vvp_object_t qobj;
|
||||
cobj->get_object(pid, qobj, 0);
|
||||
vvp_queue_vec4* src = qobj.peek<vvp_queue_vec4>();
|
||||
if (src == 0) {
|
||||
thr->push_object(vvp_object_t(new vvp_queue_vec4()));
|
||||
return true;
|
||||
}
|
||||
vvp_queue_vec4* dst = queue_run_unique_src(src, wid, true);
|
||||
thr->push_object(vvp_object_t(dst));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_PROP_QUEUE_SIZE(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
size_t pid = cp->number;
|
||||
|
|
@ -6156,6 +6635,169 @@ bool of_PROP_QUEUE_SIZE(vthread_t thr, vvp_code_t cp)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_SIZE_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
vvp_net_t* net = cp->net;
|
||||
vvp_queue_vec4* qsrc = 0;
|
||||
vvp_darray* dsrc = 0;
|
||||
get_queue_or_darray_vec4_from_net(thr, net, qsrc, dsrc);
|
||||
size_t sz =
|
||||
qsrc ? qsrc->get_size() : (dsrc ? dsrc->get_size() : 0);
|
||||
|
||||
vvp_vector4_t val(32, BIT4_0);
|
||||
unsigned long ul = sz;
|
||||
for (unsigned idx = 0; idx < 32; idx++) {
|
||||
if (ul & 1UL) {
|
||||
val.set_bit(idx, BIT4_1);
|
||||
} else {
|
||||
val.set_bit(idx, BIT4_0);
|
||||
}
|
||||
ul >>= 1;
|
||||
}
|
||||
thr->push_vec4(val);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_WORD_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
unsigned ix_reg = cp->bit_idx[1];
|
||||
int64_t adr = thr->words[ix_reg].w_int;
|
||||
if (thr->flags[4] == BIT4_1) {
|
||||
thr->push_vec4(vvp_vector4_t(wid));
|
||||
return true;
|
||||
}
|
||||
if (adr < 0) {
|
||||
thr->push_vec4(vvp_vector4_t(wid));
|
||||
return true;
|
||||
}
|
||||
vvp_net_t* net = cp->net;
|
||||
vvp_queue_vec4* qsrc = 0;
|
||||
vvp_darray* dsrc = 0;
|
||||
get_queue_or_darray_vec4_from_net(thr, net, qsrc, dsrc);
|
||||
vvp_vector4_t out(wid);
|
||||
if (qsrc) {
|
||||
if ((size_t)adr >= qsrc->get_size()) {
|
||||
thr->push_vec4(out);
|
||||
return true;
|
||||
}
|
||||
qsrc->get_word((unsigned)adr, out);
|
||||
} else if (dsrc) {
|
||||
if ((size_t)adr >= dsrc->get_size()) {
|
||||
thr->push_vec4(out);
|
||||
return true;
|
||||
}
|
||||
dsrc->get_word((unsigned)adr, out);
|
||||
} else {
|
||||
vvp_queue* src_q = get_queue_object<vvp_queue_vec4>(thr, net);
|
||||
vvp_queue_vec4* src = dynamic_cast<vvp_queue_vec4*>(src_q);
|
||||
if (!src || (size_t)adr >= src->get_size()) {
|
||||
thr->push_vec4(out);
|
||||
return true;
|
||||
}
|
||||
src->get_word((unsigned)adr, out);
|
||||
}
|
||||
thr->push_vec4(out);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_WORD_PROP_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
size_t pid = cp->number;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
unsigned ix_reg = cp->bit_idx[1];
|
||||
int64_t adr = thr->words[ix_reg].w_int;
|
||||
if (thr->flags[4] == BIT4_1) {
|
||||
thr->push_vec4(vvp_vector4_t(wid));
|
||||
return true;
|
||||
}
|
||||
if (adr < 0) {
|
||||
thr->push_vec4(vvp_vector4_t(wid));
|
||||
return true;
|
||||
}
|
||||
|
||||
vvp_object_t& top = thr->peek_object();
|
||||
vvp_cobject*cobj = top.peek<vvp_cobject>();
|
||||
assert(cobj);
|
||||
|
||||
vvp_object_t qobj;
|
||||
cobj->get_object(pid, qobj, 0);
|
||||
vvp_queue_vec4* src = qobj.peek<vvp_queue_vec4>();
|
||||
vvp_vector4_t out(wid);
|
||||
if (src == 0 || (size_t)adr >= src->get_size()) {
|
||||
thr->push_vec4(out);
|
||||
return true;
|
||||
}
|
||||
src->get_word((unsigned)adr, out);
|
||||
thr->push_vec4(out);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_CMPIX_LTU(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
unsigned a = cp->number;
|
||||
unsigned b = cp->bit_idx[0];
|
||||
if (thr->words[a].w_uint < thr->words[b].w_uint) {
|
||||
thr->flags[4] = BIT4_1;
|
||||
} else {
|
||||
thr->flags[4] = BIT4_0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_CMPIX_SLT0(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
unsigned r = cp->number;
|
||||
thr->flags[4] = (thr->words[r].w_int < 0) ? BIT4_1 : BIT4_0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_PUSH_IX_VEC4(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
unsigned ix = cp->number;
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
unsigned sgn = cp->bit_idx[1];
|
||||
uint32_t ubits;
|
||||
if (sgn) {
|
||||
int32_t sv = (int32_t)thr->words[ix].w_int;
|
||||
ubits = (uint32_t)sv;
|
||||
} else {
|
||||
ubits = (uint32_t)thr->words[ix].w_uint;
|
||||
}
|
||||
if (wid > 32) wid = 32;
|
||||
vvp_vector4_t tmp(wid, BIT4_0);
|
||||
for (unsigned idx = 0; idx < wid; idx++) {
|
||||
if (ubits & 1u) {
|
||||
tmp.set_bit(idx, BIT4_1);
|
||||
} else {
|
||||
tmp.set_bit(idx, BIT4_0);
|
||||
}
|
||||
ubits >>= 1;
|
||||
}
|
||||
thr->push_vec4(tmp);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_NEW_EMPTY_V(vthread_t thr, vvp_code_t)
|
||||
{
|
||||
thr->push_object(vvp_object_t(new vvp_queue_vec4()));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_QUEUE_APPEND_WORD_V(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
unsigned wid = cp->bit_idx[0];
|
||||
vvp_vector4_t elem = thr->pop_vec4();
|
||||
assert(elem.size() == wid);
|
||||
vvp_object_t qobj;
|
||||
thr->pop_object(qobj);
|
||||
vvp_queue_vec4* q = qobj.peek<vvp_queue_vec4>();
|
||||
assert(q);
|
||||
q->push_back(elem, 0);
|
||||
thr->push_object(qobj);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool of_DELETE_PROP_ELEM(vthread_t thr, vvp_code_t cp)
|
||||
{
|
||||
size_t pid = cp->number;
|
||||
|
|
|
|||
Loading…
Reference in New Issue