Skip to content

Commit

Permalink
Put off evaluation of concatenation repeat expresions
Browse files Browse the repository at this point in the history
 until after parameters are defined. This allows parms
 to be used in repeat expresions.

 Add the builtin $signed system function.
  • Loading branch information
steve committed May 5, 2002
1 parent 00defb0 commit 8667b9a
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 72 deletions.
29 changes: 29 additions & 0 deletions README.txt
Expand Up @@ -405,6 +405,35 @@ constructs.
- force to nets are not supported. Force to variables, and - force to nets are not supported. Force to variables, and
assign/deassign, are supported. assign/deassign, are supported.


5.0 Nonstandard Constructs

Icarus Verilog includes some features that are not part of the
IEEE1364 standard, but have well defined meaning. These are extensions
to the language.

$sizeof(<expr>)
This system function returns the size in bits of the
expression that is its argument. The result of this
function is undefined if the argument doesn't have a
self-determined size.

Builtin system functions

Certain of the system functions have well defined meanings, so
can theoretically be evaluated at compile time, instead of
using runtime VPI code. Doing so means that VPI cannot
override the definitions of functions handled in this
manner. On the other hand, this makes them synthesizeable, and
also allows for more agressive constant propagation. The
functions handled in this manner are:

$signed
$sizeof
$unsigned

Implementations of these system functions in VPI modules will
be ignored.

6.0 CREDITS 6.0 CREDITS


Except where otherwise noted, Icarus Verilog, ivl and ivlpp are Except where otherwise noted, Icarus Verilog, ivl and ivlpp are
Expand Down
13 changes: 10 additions & 3 deletions design_dump.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) && !defined(macintosh) #if !defined(WINNT) && !defined(macintosh)
#ident "$Id: design_dump.cc,v 1.122 2002/03/09 02:10:22 steve Exp $" #ident "$Id: design_dump.cc,v 1.123 2002/05/05 21:11:49 steve Exp $"
#endif #endif


# include "config.h" # include "config.h"
Expand Down Expand Up @@ -850,8 +850,8 @@ void NetEBinary::dump(ostream&o) const


void NetEConcat::dump(ostream&o) const void NetEConcat::dump(ostream&o) const
{ {
if (repeat_ != 1) if (repeat_)
o << repeat_; o << *repeat_;


if (parms_[0]) if (parms_[0])
o << "{" << *parms_[0]; o << "{" << *parms_[0];
Expand Down Expand Up @@ -980,6 +980,13 @@ void Design::dump(ostream&o) const


/* /*
* $Log: design_dump.cc,v $ * $Log: design_dump.cc,v $
* Revision 1.123 2002/05/05 21:11:49 steve
* Put off evaluation of concatenation repeat expresions
* until after parameters are defined. This allows parms
* to be used in repeat expresions.
*
* Add the builtin $signed system function.
*
* Revision 1.122 2002/03/09 02:10:22 steve * Revision 1.122 2002/03/09 02:10:22 steve
* Add the NetUserFunc netlist node. * Add the NetUserFunc netlist node.
* *
Expand Down
37 changes: 33 additions & 4 deletions elab_expr.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) && !defined(macintosh) #if !defined(WINNT) && !defined(macintosh)
#ident "$Id: elab_expr.cc,v 1.57 2002/04/27 05:03:46 steve Exp $" #ident "$Id: elab_expr.cc,v 1.58 2002/05/05 21:11:49 steve Exp $"
#endif #endif


# include "config.h" # include "config.h"
Expand Down Expand Up @@ -182,6 +182,29 @@ NetExpr* PECallFunction::elaborate_sfunc_(Design*des, NetScope*scope) const
return sub; return sub;
} }


/* Interpret the internal $sizeof system function to return
the bit width of the sub-expression. The value of the
sub-expression is not used, so the expression itself can be
deleted. */
if (strcmp(path_.peek_name(0), "$sizeof") == 0) {
if ((parms_.count() != 1) || (parms_[0] == 0)) {
cerr << get_line() << ": error: The $sizeof() function "
<< "takes exactly one(1) argument." << endl;
des->errors += 1;
return 0;
}

PExpr*expr = parms_[0];
NetExpr*sub = expr->elaborate_expr(des, scope, true);
verinum val (sub->expr_width(), sizeof(unsigned));
delete sub;

sub = new NetEConst(val);
sub->set_line(*this);

return sub;
}

unsigned wid = 32; unsigned wid = 32;


if (strcmp(path_.peek_name(0), "$time") == 0) if (strcmp(path_.peek_name(0), "$time") == 0)
Expand Down Expand Up @@ -322,7 +345,7 @@ NetExpr* PECallFunction::elaborate_expr(Design*des, NetScope*scope, bool) const


NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope, bool) const NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope, bool) const
{ {
unsigned repeat = 1; NetExpr* repeat = 0;


/* If there is a repeat expression, then evaluate the constant /* If there is a repeat expression, then evaluate the constant
value and set the repeat count. */ value and set the repeat count. */
Expand All @@ -338,10 +361,9 @@ NetExpr* PEConcat::elaborate_expr(Design*des, NetScope*scope, bool) const
cerr << get_line() << ": : The expression is: " cerr << get_line() << ": : The expression is: "
<< *tmp << endl; << *tmp << endl;
des->errors += 1; des->errors += 1;
return 0;
} }


repeat = rep->value().as_ulong(); repeat = rep;
} }


/* Make the empty concat expression. */ /* Make the empty concat expression. */
Expand Down Expand Up @@ -842,6 +864,13 @@ NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope, bool) const


/* /*
* $Log: elab_expr.cc,v $ * $Log: elab_expr.cc,v $
* Revision 1.58 2002/05/05 21:11:49 steve
* Put off evaluation of concatenation repeat expresions
* until after parameters are defined. This allows parms
* to be used in repeat expresions.
*
* Add the builtin $signed system function.
*
* Revision 1.57 2002/04/27 05:03:46 steve * Revision 1.57 2002/04/27 05:03:46 steve
* Preserve stringiness string part select and concatenation. * Preserve stringiness string part select and concatenation.
* *
Expand Down
28 changes: 14 additions & 14 deletions elab_pexpr.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) && !defined(macintosh) #if !defined(WINNT) && !defined(macintosh)
#ident "$Id: elab_pexpr.cc,v 1.13 2002/01/28 00:52:41 steve Exp $" #ident "$Id: elab_pexpr.cc,v 1.14 2002/05/05 21:11:50 steve Exp $"
#endif #endif


# include "config.h" # include "config.h"
Expand Down Expand Up @@ -66,28 +66,21 @@ NetExpr*PEBinary::elaborate_pexpr (Design*des, NetScope*scope) const
*/ */
NetEConcat* PEConcat::elaborate_pexpr(Design*des, NetScope*scope) const NetEConcat* PEConcat::elaborate_pexpr(Design*des, NetScope*scope) const
{ {
unsigned repeat = 1; NetExpr* repeat = 0;


/* If there is a repeat expression, then evaluate the constant /* If there is a repeat expression, then evaluate the constant
value and set the repeat count. value and set the repeat count. */
XXXX Potential bug XXX In principle, the repeat expression
can have a parameter name in it. Since where are in the
working of parameters now, we will not be able to
accurately evaluate such expressions. So eventually, I will
need to be able to defer the evaluation of the expression. */
if (repeat_) { if (repeat_) {
verinum*vrep = repeat_->eval_const(des, scope); repeat = repeat_->elaborate_pexpr(des, scope);
if (vrep == 0) { if (repeat == 0) {
cerr << get_line() << ": error: " cerr << get_line() << ": error: "
"concatenation repeat expression cannot be evaluated." "concatenation repeat expression cannot be evaluated."
<< endl; << endl;
des->errors += 1; des->errors += 1;
return 0;
} }


repeat = vrep->as_ulong(); /* continue on even if the repeat expression doesn't
delete vrep; work, as we can find more errors. */
} }


/* Make the empty concat expression. */ /* Make the empty concat expression. */
Expand Down Expand Up @@ -224,6 +217,13 @@ NetExpr*PEUnary::elaborate_pexpr (Design*des, NetScope*scope) const


/* /*
* $Log: elab_pexpr.cc,v $ * $Log: elab_pexpr.cc,v $
* Revision 1.14 2002/05/05 21:11:50 steve
* Put off evaluation of concatenation repeat expresions
* until after parameters are defined. This allows parms
* to be used in repeat expresions.
*
* Add the builtin $signed system function.
*
* Revision 1.13 2002/01/28 00:52:41 steve * Revision 1.13 2002/01/28 00:52:41 steve
* Add support for bit select of parameters. * Add support for bit select of parameters.
* This leads to a NetESelect node and the * This leads to a NetESelect node and the
Expand Down
30 changes: 22 additions & 8 deletions eval_tree.cc
Expand Up @@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#if !defined(WINNT) && !defined(macintosh) #if !defined(WINNT) && !defined(macintosh)
#ident "$Id: eval_tree.cc,v 1.37 2002/04/27 05:03:46 steve Exp $" #ident "$Id: eval_tree.cc,v 1.38 2002/05/05 21:11:50 steve Exp $"
#endif #endif


# include "config.h" # include "config.h"
Expand Down Expand Up @@ -705,17 +705,23 @@ NetEConst* NetEBShift::eval_tree()


NetEConst* NetEConcat::eval_tree() NetEConst* NetEConcat::eval_tree()
{ {
unsigned repeat_val = repeat();

unsigned gap = 0;
for (unsigned idx = 0 ; idx < parms_.count() ; idx += 1) { for (unsigned idx = 0 ; idx < parms_.count() ; idx += 1) {


// Parameter not here? This is an error, but presumably // Parameter not here? This is an error, but presumably
// already caught and we are here just to catch more. // already caught and we are here just to catch more.
if (parms_[idx] == 0) if (parms_[idx] == 0)
continue; continue;



// If this parameter is already a constant, all is well // If this parameter is already a constant, all is well
// so go on. // so go on.
if (dynamic_cast<NetEConst*>(parms_[idx])) if (dynamic_cast<NetEConst*>(parms_[idx])) {
gap += parms_[idx]->expr_width();
continue; continue;
}


// Finally, try to evaluate the parameter expression // Finally, try to evaluate the parameter expression
// that is here. If I succeed, reset the parameter to // that is here. If I succeed, reset the parameter to
Expand All @@ -725,23 +731,24 @@ NetEConst* NetEConcat::eval_tree()
if (expr) { if (expr) {
delete parms_[idx]; delete parms_[idx];
parms_[idx] = expr; parms_[idx] = expr;
gap += expr->expr_width();
} }
} }


// Handle the special case that the repeat expression is // Handle the special case that the repeat expression is
// zero. In this case, just return a 0 value with the expected // zero. In this case, just return a 0 value with the expected
// width. // width.
if (repeat_ == 0) { if (repeat_val == 0) {
verinum val (verinum::V0, expr_width()); verinum val (verinum::V0, expr_width());
NetEConst*res = new NetEConst(val); NetEConst*res = new NetEConst(val);
res->set_width(val.len()); res->set_width(val.len());
return res; return res;
} }


// Figure out the width of the repeated expression, and make a // At this point, the "gap" is the width of a single repeat of
// verinum to hold the result. // the concatenation. The total width of the result is the gap
unsigned gap = expr_width() / repeat_; // times the repeat count.
verinum val (verinum::Vx, repeat_ * gap); verinum val (verinum::Vx, repeat_val * gap);


// build up the result from least significant to most. // build up the result from least significant to most.


Expand All @@ -754,7 +761,7 @@ NetEConst* NetEConcat::eval_tree()


verinum tmp = expr->value(); verinum tmp = expr->value();
for (unsigned bit = 0; bit < tmp.len(); bit += 1, cur += 1) for (unsigned bit = 0; bit < tmp.len(); bit += 1, cur += 1)
for (unsigned rep = 0 ; rep < repeat_ ; rep += 1) for (unsigned rep = 0 ; rep < repeat_val ; rep += 1)
val.set(rep*gap+cur, tmp[bit]); val.set(rep*gap+cur, tmp[bit]);


is_string_flag = is_string_flag && tmp.is_string(); is_string_flag = is_string_flag && tmp.is_string();
Expand Down Expand Up @@ -1079,6 +1086,13 @@ NetEConst* NetEUReduce::eval_tree()


/* /*
* $Log: eval_tree.cc,v $ * $Log: eval_tree.cc,v $
* Revision 1.38 2002/05/05 21:11:50 steve
* Put off evaluation of concatenation repeat expresions
* until after parameters are defined. This allows parms
* to be used in repeat expresions.
*
* Add the builtin $signed system function.
*
* Revision 1.37 2002/04/27 05:03:46 steve * Revision 1.37 2002/04/27 05:03:46 steve
* Preserve stringiness string part select and concatenation. * Preserve stringiness string part select and concatenation.
* *
Expand Down

0 comments on commit 8667b9a

Please sign in to comment.