Permalink
Browse files

Add arithmetic shift operators.

  • Loading branch information...
1 parent ae418c6 commit 71a404a5467eb60815eaaacc854e4174dca4a727 steve committed Jun 18, 2003
Showing with 153 additions and 41 deletions.
  1. +7 −1 design_dump.cc
  2. +7 −3 elab_expr.cc
  3. +4 −2 lexor.lex
  4. +29 −1 net_expr.cc
  5. +4 −23 netlist.cc
  6. +6 −1 netlist.h
  7. +9 −3 parse.y
  8. +5 −1 set_width.cc
  9. +41 −1 tgt-vvp/eval_expr.c
  10. +5 −1 vvp/codes.h
  11. +5 −1 vvp/compile.cc
  12. +4 −2 vvp/opcodes.txt
  13. +27 −1 vvp/vthread.cc
View
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: design_dump.cc,v 1.140 2003/05/30 02:55:32 steve Exp $"
+#ident "$Id: design_dump.cc,v 1.141 2003/06/18 03:55:18 steve Exp $"
#endif
# include "config.h"
@@ -863,6 +863,9 @@ void NetEBinary::dump(ostream&o) const
case 'r':
o << ">>";
break;
+ case 'R':
+ o << ">>>";
+ break;
case 'X':
o << "~^";
break;
@@ -1040,6 +1043,9 @@ void Design::dump(ostream&o) const
/*
* $Log: design_dump.cc,v $
+ * Revision 1.141 2003/06/18 03:55:18 steve
+ * Add arithmetic shift operators.
+ *
* Revision 1.140 2003/05/30 02:55:32 steve
* Support parameters in real expressions and
* as real expressions, and fix multiply and
View
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: elab_expr.cc,v 1.78 2003/06/10 04:29:57 steve Exp $"
+#ident "$Id: elab_expr.cc,v 1.79 2003/06/18 03:55:18 steve Exp $"
#endif
# include "config.h"
@@ -135,8 +135,9 @@ NetEBinary* PEBinary::elaborate_expr_base_(Design*des,
tmp->set_line(*this);
break;
- case 'l':
- case 'r':
+ case 'l': // <<
+ case 'r': // >>
+ case 'R': // >>>
tmp = new NetEBShift(op_, lp, rp);
tmp->set_line(*this);
break;
@@ -961,6 +962,9 @@ NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope, bool) const
/*
* $Log: elab_expr.cc,v $
+ * Revision 1.79 2003/06/18 03:55:18 steve
+ * Add arithmetic shift operators.
+ *
* Revision 1.78 2003/06/10 04:29:57 steve
* PR735: bit select indices are signed constants.
*
View
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT) && !defined(macintosh)
-#ident "$Id: lexor.lex,v 1.81 2003/06/17 04:23:25 steve Exp $"
+#ident "$Id: lexor.lex,v 1.82 2003/06/18 03:55:18 steve Exp $"
#endif
# include "config.h"
@@ -128,7 +128,9 @@ W [ \t\b\f\r]+
"(*" { return K_PSTAR; }
"*)" { return K_STARP; }
"<<" { return K_LS; }
-">>" { return K_RS; }
+"<<<" { return K_LS; /* Note: Functionally, <<< is the same as <<. */}
+">>" { return K_RS; }
+">>>" { return K_RSS; }
"<=" { return K_LE; }
">=" { return K_GE; }
"=>" { return K_EG; }
View
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: net_expr.cc,v 1.19 2003/06/15 18:53:20 steve Exp $"
+#ident "$Id: net_expr.cc,v 1.20 2003/06/18 03:55:18 steve Exp $"
#endif
# include "config.h"
@@ -230,6 +230,31 @@ NetExpr::TYPE NetEBMult::expr_type() const
return ET_VECTOR;
}
+NetEBShift::NetEBShift(char op, NetExpr*l, NetExpr*r)
+: NetEBinary(op, l, r)
+{
+ expr_width(l->expr_width());
+
+ // The >>> is signed if the left operand is signed.
+ if (op == 'R') cast_signed(l->has_sign());
+}
+
+NetEBShift::~NetEBShift()
+{
+}
+
+bool NetEBShift::has_width() const
+{
+ return left_->has_width();
+}
+
+NetEBShift* NetEBShift::dup_expr() const
+{
+ NetEBShift*result = new NetEBShift(op_, left_->dup_expr(),
+ right_->dup_expr());
+ return result;
+}
+
NetEConcat::NetEConcat(unsigned cnt, NetExpr* r)
: parms_(cnt), repeat_(r)
{
@@ -491,6 +516,9 @@ NetExpr::TYPE NetESFunc::expr_type() const
/*
* $Log: net_expr.cc,v $
+ * Revision 1.20 2003/06/18 03:55:18 steve
+ * Add arithmetic shift operators.
+ *
* Revision 1.19 2003/06/15 18:53:20 steve
* Operands of unsigned multiply are unsigned.
*
View
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: netlist.cc,v 1.215 2003/05/01 01:13:57 steve Exp $"
+#ident "$Id: netlist.cc,v 1.216 2003/06/18 03:55:18 steve Exp $"
#endif
# include "config.h"
@@ -1836,28 +1836,6 @@ NetEBLogic* NetEBLogic::dup_expr() const
return result;
}
-NetEBShift::NetEBShift(char op, NetExpr*l, NetExpr*r)
-: NetEBinary(op, l, r)
-{
- expr_width(l->expr_width());
-}
-
-NetEBShift::~NetEBShift()
-{
-}
-
-bool NetEBShift::has_width() const
-{
- return left_->has_width();
-}
-
-NetEBShift* NetEBShift::dup_expr() const
-{
- NetEBShift*result = new NetEBShift(op_, left_->dup_expr(),
- right_->dup_expr());
- return result;
-}
-
NetEConst::NetEConst(const verinum&val)
: NetExpr(val.len()), value_(val)
{
@@ -2198,6 +2176,9 @@ const NetProc*NetTaskDef::proc() const
/*
* $Log: netlist.cc,v $
+ * Revision 1.216 2003/06/18 03:55:18 steve
+ * Add arithmetic shift operators.
+ *
* Revision 1.215 2003/05/01 01:13:57 steve
* More complete bit range internal error message,
* Better test of part select ranges on non-zero
View
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: netlist.h,v 1.289 2003/06/05 04:28:24 steve Exp $"
+#ident "$Id: netlist.h,v 1.290 2003/06/18 03:55:18 steve Exp $"
#endif
/*
@@ -2343,6 +2343,7 @@ class NetProcTop : public LineInfo, public Attrib {
* O -- Bit-wise NOR (~|)
* l -- Left shift (<<)
* r -- Right shift (>>)
+ * R -- signed right shift (>>>)
* X -- Bitwise exclusive NOR (~^)
*/
class NetEBinary : public NetExpr {
@@ -2535,6 +2536,7 @@ class NetEBMult : public NetEBinary {
*
* l -- left shift (<<)
* r -- right shift (>>)
+ * R -- right shift arithmetic (>>>)
*/
class NetEBShift : public NetEBinary {
@@ -3304,6 +3306,9 @@ extern ostream& operator << (ostream&, NetNet::Type);
/*
* $Log: netlist.h,v $
+ * Revision 1.290 2003/06/18 03:55:18 steve
+ * Add arithmetic shift operators.
+ *
* Revision 1.289 2003/06/05 04:28:24 steve
* Evaluate <= with real operands.
*
View
12 parse.y
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if HAVE_CVS_IDENT
-#ident "$Id: parse.y,v 1.178 2003/06/13 00:27:09 steve Exp $"
+#ident "$Id: parse.y,v 1.179 2003/06/18 03:55:18 steve Exp $"
#endif
# include "config.h"
@@ -127,7 +127,7 @@ const static struct str_pair_t str_strength = { PGate::STRONG, PGate::STRONG };
%token <text> PATHPULSE_IDENTIFIER
%token <number> BASED_NUMBER DEC_NUMBER
%token <realtime> REALTIME
-%token K_LE K_GE K_EG K_EQ K_NE K_CEQ K_CNE K_LS K_RS K_SG
+%token K_LE K_GE K_EG K_EQ K_NE K_CEQ K_CNE K_LS K_RS K_RSS K_SG
%token K_PO_POS K_PO_NEG
%token K_PSTAR K_STARP
%token K_LOR K_LAND K_NAND K_NOR K_NXOR K_TRIGGER
@@ -222,7 +222,7 @@ const static struct str_pair_t str_strength = { PGate::STRONG, PGate::STRONG };
%left '&' K_NAND
%left K_EQ K_NE K_CEQ K_CNE
%left K_GE K_LE '<' '>'
-%left K_LS K_RS
+%left K_LS K_RS K_RSS
%left '+' '-'
%left '*' '/' '%'
%left UNARY_PREC
@@ -810,6 +810,12 @@ expression
tmp->set_lineno(@2.first_line);
$$ = tmp;
}
+ | expression K_RSS expression
+ { PEBinary*tmp = new PEBinary('R', $1, $3);
+ tmp->set_file(@2.text);
+ tmp->set_lineno(@2.first_line);
+ $$ = tmp;
+ }
| expression K_EQ expression
{ PEBinary*tmp = new PEBinary('e', $1, $3);
tmp->set_file(@2.text);
View
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: set_width.cc,v 1.30 2003/05/20 15:05:33 steve Exp $"
+#ident "$Id: set_width.cc,v 1.31 2003/06/18 03:55:19 steve Exp $"
#endif
# include "config.h"
@@ -203,6 +203,7 @@ bool NetEBShift::set_width(unsigned w)
break;
case 'r':
+ case 'R':
if (left_->expr_width() < w)
left_ = pad_to_width(left_, w);
break;
@@ -410,6 +411,9 @@ bool NetEUReduce::set_width(unsigned w)
/*
* $Log: set_width.cc,v $
+ * Revision 1.31 2003/06/18 03:55:19 steve
+ * Add arithmetic shift operators.
+ *
* Revision 1.30 2003/05/20 15:05:33 steve
* Do not try to set constants to width 0.
*
View
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: eval_expr.c,v 1.101 2003/06/17 19:17:42 steve Exp $"
+#ident "$Id: eval_expr.c,v 1.102 2003/06/18 03:55:19 steve Exp $"
#endif
# include "vvp_priv.h"
@@ -773,6 +773,42 @@ static struct vector_info draw_binary_expr_lrs(ivl_expr_t exp, unsigned wid)
opcode = "%shiftr";
break;
+ case 'R': /* >>> (signed right shift) */
+
+ /* with the right shift, there may be high bits that are
+ shifted into the desired width of the expression, so
+ we let the expression size itself, if it is bigger
+ then what is requested of us. */
+ if (wid > ivl_expr_width(le)) {
+ lv = draw_eval_expr_wid(le, wid, 0);
+ } else {
+ lv = draw_eval_expr_wid(le, ivl_expr_width(le), 0);
+ }
+
+ /* shifting 0 gets 0. */
+ if (lv.base == 0)
+ break;
+
+ /* Sign extend any constant begets itself, if this
+ expression is signed. */
+ if ((lv.base < 4) && (ivl_expr_signed(exp)))
+ break;
+
+ if (lv.base < 4) {
+ struct vector_info tmp;
+ tmp.base = allocate_vector(lv.wid);
+ tmp.wid = lv.wid;
+ fprintf(vvp_out, " %%mov %u, %u, %u;\n",
+ tmp.base, lv.base, lv.wid);
+ lv = tmp;
+ }
+
+ if (ivl_expr_signed(exp))
+ opcode = "%shiftr/s";
+ else
+ opcode = "%shiftr";
+ break;
+
default:
assert(0);
}
@@ -1029,6 +1065,7 @@ static struct vector_info draw_binary_expr(ivl_expr_t exp,
case 'l': /* << */
case 'r': /* >> */
+ case 'R': /* >>> */
rv = draw_binary_expr_lrs(exp, wid);
break;
@@ -2036,6 +2073,9 @@ struct vector_info draw_eval_expr(ivl_expr_t exp, int stuff_ok_flag)
/*
* $Log: eval_expr.c,v $
+ * Revision 1.102 2003/06/18 03:55:19 steve
+ * Add arithmetic shift operators.
+ *
* Revision 1.101 2003/06/17 19:17:42 steve
* Remove short int restrictions from vvp opcodes.
*
View
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: codes.h,v 1.62 2003/06/17 19:17:42 steve Exp $"
+#ident "$Id: codes.h,v 1.63 2003/06/18 03:55:19 steve Exp $"
#endif
@@ -106,6 +106,7 @@ extern bool of_SET_X0(vthread_t thr, vvp_code_t code);
extern bool of_SET_X0_X(vthread_t thr, vvp_code_t code);
extern bool of_SHIFTL_I0(vthread_t thr, vvp_code_t code);
extern bool of_SHIFTR_I0(vthread_t thr, vvp_code_t code);
+extern bool of_SHIFTR_S_I0(vthread_t thr, vvp_code_t code);
extern bool of_SUB(vthread_t thr, vvp_code_t code);
extern bool of_SUB_WR(vthread_t thr, vvp_code_t code);
extern bool of_SUBI(vthread_t thr, vvp_code_t code);
@@ -173,6 +174,9 @@ extern vvp_code_t codespace_index(vvp_cpoint_t ptr);
/*
* $Log: codes.h,v $
+ * Revision 1.63 2003/06/18 03:55:19 steve
+ * Add arithmetic shift operators.
+ *
* Revision 1.62 2003/06/17 19:17:42 steve
* Remove short int restrictions from vvp opcodes.
*
Oops, something went wrong.

0 comments on commit 71a404a

Please sign in to comment.