Add structural equality compare nodes.

This commit is contained in:
steve 2004-06-16 16:33:25 +00:00
parent bdc6cb8723
commit 35619771dd
7 changed files with 163 additions and 10 deletions

View File

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com) * Copyright (c) 2001 Stephen Williams (steve@icarus.com)
* *
* $Id: README.txt,v 1.45 2003/09/04 20:26:30 steve Exp $ * $Id: README.txt,v 1.46 2004/06/16 16:33:25 steve Exp $
*/ */
VVP SIMULATION ENGINE VVP SIMULATION ENGINE
@ -500,6 +500,8 @@ have wide outputs, but the comparators have single bit output, so they
are implemented a bit differently. The syntax, however, is very are implemented a bit differently. The syntax, however, is very
similar: similar:
<label> .cmp/eq <wid>, <symbols_list>;
<label> .cmp/ne <wid>, <symbols_list>;
<label> .cmp/ge <wid>, <symbols_list>; <label> .cmp/ge <wid>, <symbols_list>;
<label> .cmp/gt <wid>, <symbols_list>; <label> .cmp/gt <wid>, <symbols_list>;
<label> .cmp/ge.s <wid>, <symbols_list>; <label> .cmp/ge.s <wid>, <symbols_list>;
@ -507,9 +509,10 @@ similar:
Whereas the arithmetic statements create an array of functor outputs, Whereas the arithmetic statements create an array of functor outputs,
there is only one useful functor output for the comparators. That there is only one useful functor output for the comparators. That
functor output is 1 of the comparison is true, 0 if false, and x functor output is 1 1f the comparison is true, 0 if false, and x
otherwise. The plain versions do unsigned comparison, but the ".s" otherwise. The plain versions do unsigned comparison, but the ".s"
versions to signed comparisons. versions to signed comparisons. (Eqlality doesn't need to care about
sign.)
STRUCTURAL SHIFTER STATEMENTS: STRUCTURAL SHIFTER STATEMENTS:

View File

@ -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
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: arith.cc,v 1.26 2003/08/01 00:58:34 steve Exp $" #ident "$Id: arith.cc,v 1.27 2004/06/16 16:33:26 steve Exp $"
#endif #endif
# include "arith.h" # include "arith.h"
@ -383,12 +383,82 @@ void vvp_arith_sub::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
output_val_(base, push); output_val_(base, push);
} }
vvp_cmp_eq::vvp_cmp_eq(unsigned wid)
: vvp_arith_(wid)
{
}
void vvp_cmp_eq::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
{
put(i, val);
vvp_ipoint_t base = ipoint_make(i,0);
unsigned out_val = 1;
for (unsigned idx = wid_ ; idx > 0 ; idx -= 1) {
vvp_ipoint_t ptr = ipoint_index(base,idx-1);
functor_t obj = functor_index(ptr);
unsigned val = obj->ival;
if (val & 0x0a) {
out_val = 2;
break;
}
unsigned a = (val & 0x01)? 1 : 0;
unsigned b = (val & 0x04)? 1 : 0;
if (a != b) {
out_val = 0;
break;
}
}
put_oval(out_val, push);
}
vvp_cmp_ne::vvp_cmp_ne(unsigned wid)
: vvp_arith_(wid)
{
}
void vvp_cmp_ne::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
{
put(i, val);
vvp_ipoint_t base = ipoint_make(i,0);
unsigned out_val = 0;
for (unsigned idx = wid_ ; idx > 0 ; idx -= 1) {
vvp_ipoint_t ptr = ipoint_index(base,idx-1);
functor_t obj = functor_index(ptr);
unsigned val = obj->ival;
if (val & 0x0a) {
out_val = 2;
break;
}
unsigned a = (val & 0x01)? 1 : 0;
unsigned b = (val & 0x04)? 1 : 0;
if (a != b) {
out_val = 1;
break;
}
}
put_oval(out_val, push);
}
vvp_cmp_ge::vvp_cmp_ge(unsigned wid, bool flag) vvp_cmp_ge::vvp_cmp_ge(unsigned wid, bool flag)
: vvp_arith_(wid), signed_flag_(flag) : vvp_arith_(wid), signed_flag_(flag)
{ {
} }
void vvp_cmp_ge::set(vvp_ipoint_t i, bool push, unsigned val, unsigned) void vvp_cmp_ge::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
{ {
put(i, val); put(i, val);
@ -610,6 +680,9 @@ void vvp_shiftr::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
/* /*
* $Log: arith.cc,v $ * $Log: arith.cc,v $
* Revision 1.27 2004/06/16 16:33:26 steve
* Add structural equality compare nodes.
*
* Revision 1.26 2003/08/01 00:58:34 steve * Revision 1.26 2003/08/01 00:58:34 steve
* Fix arithmetic operators in 64bit processors. * Fix arithmetic operators in 64bit processors.
* *

View File

@ -19,7 +19,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
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: arith.h,v 1.15 2003/04/11 05:15:38 steve Exp $" #ident "$Id: arith.h,v 1.16 2004/06/16 16:33:26 steve Exp $"
#endif #endif
# include "functor.h" # include "functor.h"
@ -101,6 +101,22 @@ class vvp_arith_sub : public vvp_wide_arith_ {
void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str); void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
}; };
class vvp_cmp_eq : public vvp_arith_ {
public:
explicit vvp_cmp_eq(unsigned wid);
void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
};
class vvp_cmp_ne : public vvp_arith_ {
public:
explicit vvp_cmp_ne(unsigned wid);
void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
};
class vvp_cmp_ge : public vvp_arith_ { class vvp_cmp_ge : public vvp_arith_ {
public: public:
@ -139,6 +155,9 @@ class vvp_shiftr : public vvp_arith_ {
/* /*
* $Log: arith.h,v $ * $Log: arith.h,v $
* Revision 1.16 2004/06/16 16:33:26 steve
* Add structural equality compare nodes.
*
* Revision 1.15 2003/04/11 05:15:38 steve * Revision 1.15 2003/04/11 05:15:38 steve
* Add signed versions of .cmp/gt/ge * Add signed versions of .cmp/gt/ge
* *

View File

@ -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
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: compile.cc,v 1.171 2004/05/19 03:26:24 steve Exp $" #ident "$Id: compile.cc,v 1.172 2004/06/16 16:33:26 steve Exp $"
#endif #endif
# include "arith.h" # include "arith.h"
@ -921,6 +921,36 @@ void compile_arith_sum(char*label, long wid, unsigned argc, struct symb_s*argv)
make_arith(arith, label, wid, argc, argv); make_arith(arith, label, wid, argc, argv);
} }
void compile_cmp_eq(char*label, long wid, unsigned argc, struct symb_s*argv)
{
assert( wid > 0 );
if ((long)argc != 2*wid) {
fprintf(stderr, "%s; .cmp has wrong number of symbols\n", label);
compile_errors += 1;
return;
}
vvp_arith_ *arith = new vvp_cmp_eq(wid);
make_arith(arith, label, wid, argc, argv);
}
void compile_cmp_ne(char*label, long wid, unsigned argc, struct symb_s*argv)
{
assert( wid > 0 );
if ((long)argc != 2*wid) {
fprintf(stderr, "%s; .cmp has wrong number of symbols\n", label);
compile_errors += 1;
return;
}
vvp_arith_ *arith = new vvp_cmp_ne(wid);
make_arith(arith, label, wid, argc, argv);
}
void compile_cmp_ge(char*label, long wid, bool signed_flag, void compile_cmp_ge(char*label, long wid, bool signed_flag,
unsigned argc, struct symb_s*argv) unsigned argc, struct symb_s*argv)
{ {
@ -1548,6 +1578,9 @@ void compile_param_string(char*label, char*name, char*str, char*value)
/* /*
* $Log: compile.cc,v $ * $Log: compile.cc,v $
* Revision 1.172 2004/06/16 16:33:26 steve
* Add structural equality compare nodes.
*
* Revision 1.171 2004/05/19 03:26:24 steve * Revision 1.171 2004/05/19 03:26:24 steve
* Support delayed/non-blocking assignment to reals and others. * Support delayed/non-blocking assignment to reals and others.
* *

View File

@ -19,7 +19,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
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: compile.h,v 1.53 2003/09/04 20:26:31 steve Exp $" #ident "$Id: compile.h,v 1.54 2004/06/16 16:33:26 steve Exp $"
#endif #endif
# include <stdio.h> # include <stdio.h>
@ -107,6 +107,10 @@ extern void compile_arith_sum(char*label, long width,
unsigned argc, struct symb_s*argv); unsigned argc, struct symb_s*argv);
extern void compile_arith_sub(char*label, long width, extern void compile_arith_sub(char*label, long width,
unsigned argc, struct symb_s*argv); unsigned argc, struct symb_s*argv);
extern void compile_cmp_eq(char*label, long width,
unsigned argc, struct symb_s*argv);
extern void compile_cmp_ne(char*label, long width,
unsigned argc, struct symb_s*argv);
extern void compile_cmp_ge(char*label, long width, bool signed_flag, extern void compile_cmp_ge(char*label, long width, bool signed_flag,
unsigned argc, struct symb_s*argv); unsigned argc, struct symb_s*argv);
extern void compile_cmp_gt(char*label, long width, bool signed_flag, extern void compile_cmp_gt(char*label, long width, bool signed_flag,
@ -264,6 +268,9 @@ extern void compile_net(char*label, char*name,
/* /*
* $Log: compile.h,v $ * $Log: compile.h,v $
* Revision 1.54 2004/06/16 16:33:26 steve
* Add structural equality compare nodes.
*
* Revision 1.53 2003/09/04 20:26:31 steve * Revision 1.53 2003/09/04 20:26:31 steve
* Add $push flag for threads. * Add $push flag for threads.
* *

View File

@ -19,7 +19,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
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: lexor.lex,v 1.41 2003/08/26 16:26:02 steve Exp $" #ident "$Id: lexor.lex,v 1.42 2004/06/16 16:33:26 steve Exp $"
#endif #endif
# include "parse_misc.h" # include "parse_misc.h"
@ -88,6 +88,8 @@
".arith/mult" { return K_ARITH_MULT; } ".arith/mult" { return K_ARITH_MULT; }
".arith/sub" { return K_ARITH_SUB; } ".arith/sub" { return K_ARITH_SUB; }
".arith/sum" { return K_ARITH_SUM; } ".arith/sum" { return K_ARITH_SUM; }
".cmp/eq" { return K_CMP_EQ; }
".cmp/ne" { return K_CMP_NE; }
".cmp/ge" { return K_CMP_GE; } ".cmp/ge" { return K_CMP_GE; }
".cmp/ge.s" { return K_CMP_GE_S; } ".cmp/ge.s" { return K_CMP_GE_S; }
".cmp/gt" { return K_CMP_GT; } ".cmp/gt" { return K_CMP_GT; }
@ -179,6 +181,9 @@ int yywrap()
/* /*
* $Log: lexor.lex,v $ * $Log: lexor.lex,v $
* Revision 1.42 2004/06/16 16:33:26 steve
* Add structural equality compare nodes.
*
* Revision 1.41 2003/08/26 16:26:02 steve * Revision 1.41 2003/08/26 16:26:02 steve
* ifdef idents correctly. * ifdef idents correctly.
* *

View File

@ -19,7 +19,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
*/ */
#ifdef HAVE_CVS_IDENT #ifdef HAVE_CVS_IDENT
#ident "$Id: parse.y,v 1.56 2003/09/04 20:26:31 steve Exp $" #ident "$Id: parse.y,v 1.57 2004/06/16 16:33:26 steve Exp $"
#endif #endif
# include "parse_misc.h" # include "parse_misc.h"
@ -58,7 +58,7 @@ extern FILE*yyin;
%token K_ARITH_DIV K_ARITH_MOD K_ARITH_MULT K_ARITH_SUB K_ARITH_SUM %token K_ARITH_DIV K_ARITH_MOD K_ARITH_MULT K_ARITH_SUB K_ARITH_SUM
%token K_CMP_GE K_CMP_GE_S K_CMP_GT K_CMP_GT_S %token K_CMP_EQ K_CMP_NE K_CMP_GE K_CMP_GE_S K_CMP_GT K_CMP_GT_S
%token K_EVENT K_EVENT_OR K_FUNCTOR K_NET K_NET_S K_PARAM %token K_EVENT K_EVENT_OR K_FUNCTOR K_NET K_NET_S K_PARAM
%token K_RESOLV K_SCOPE K_SHIFTL K_SHIFTR K_THREAD K_TIMESCALE K_UFUNC %token K_RESOLV K_SCOPE K_SHIFTL K_SHIFTR K_THREAD K_TIMESCALE K_UFUNC
%token K_UDP K_UDP_C K_UDP_S %token K_UDP K_UDP_C K_UDP_S
@ -216,6 +216,16 @@ statement
compile_arith_sum($1, $3, obj.cnt, obj.vect); compile_arith_sum($1, $3, obj.cnt, obj.vect);
} }
| T_LABEL K_CMP_EQ T_NUMBER ',' symbols ';'
{ struct symbv_s obj = $5;
compile_cmp_eq($1, $3, obj.cnt, obj.vect);
}
| T_LABEL K_CMP_NE T_NUMBER ',' symbols ';'
{ struct symbv_s obj = $5;
compile_cmp_ne($1, $3, obj.cnt, obj.vect);
}
| T_LABEL K_CMP_GE T_NUMBER ',' symbols ';' | T_LABEL K_CMP_GE T_NUMBER ',' symbols ';'
{ struct symbv_s obj = $5; { struct symbv_s obj = $5;
compile_cmp_ge($1, $3, false, obj.cnt, obj.vect); compile_cmp_ge($1, $3, false, obj.cnt, obj.vect);
@ -617,6 +627,9 @@ int compile_design(const char*path)
/* /*
* $Log: parse.y,v $ * $Log: parse.y,v $
* Revision 1.57 2004/06/16 16:33:26 steve
* Add structural equality compare nodes.
*
* Revision 1.56 2003/09/04 20:26:31 steve * Revision 1.56 2003/09/04 20:26:31 steve
* Add $push flag for threads. * Add $push flag for threads.
* *