Add arith/div object.

This commit is contained in:
steve 2001-10-16 02:47:37 +00:00
parent 177fa4062b
commit 36e1eab3f4
7 changed files with 122 additions and 11 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.36 2001/08/25 17:22:32 steve Exp $ * $Id: README.txt,v 1.37 2001/10/16 02:47:37 steve Exp $
*/ */
VVP SIMULATION ENGINE VVP SIMULATION ENGINE
@ -408,6 +408,7 @@ create special statement types for the various arithmetic operators.
<label> .arith/sub <wid>, <symbols_list>; <label> .arith/sub <wid>, <symbols_list>;
<label> .arith/sum <wid>, <symbols_list>; <label> .arith/sum <wid>, <symbols_list>;
<label> .arith/mult <wid>, <symbols_list>; <label> .arith/mult <wid>, <symbols_list>;
<label> .arith/div <wid>, <symbols_list>;
Addition is represented by the .arith/sum statement. This creates an Addition is represented by the .arith/sum statement. This creates an
array of functors based at the label. The width of the array is given array of functors based at the label. The width of the array is given

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
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: arith.cc,v 1.13 2001/10/14 17:36:18 steve Exp $" #ident "$Id: arith.cc,v 1.14 2001/10/16 02:47:37 steve Exp $"
#endif #endif
# include "arith.h" # include "arith.h"
@ -49,6 +49,58 @@ void vvp_arith_::output_x_(bool push)
} }
} }
vvp_arith_div::vvp_arith_div(vvp_ipoint_t b, unsigned w)
: vvp_arith_(b, w)
{
}
void vvp_arith_div::set(vvp_ipoint_t i, functor_t f, bool push)
{
if (wid_ <= 8*sizeof(unsigned long)) {
unsigned long a = 0, b = 0;
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
vvp_ipoint_t ptr = ipoint_index(base_,idx);
functor_t obj = functor_index(ptr);
unsigned ival = obj->ival;
if (ival & 0xaa) {
output_x_(push);
return;
}
if (ival & 0x01)
a += 1 << idx;
if (ival & 0x04)
b += 1 << idx;
}
unsigned long sum = a / b;
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
vvp_ipoint_t ptr = ipoint_index(base_,idx);
functor_t obj = functor_index(ptr);
unsigned oval = sum & 1;
sum >>= 1;
if (obj->oval == oval)
continue;
obj->oval = oval;
if (push)
functor_propagate(ptr);
else
schedule_functor(ptr, 0);
}
} else {
assert(0);
}
}
vvp_arith_mult::vvp_arith_mult(vvp_ipoint_t b, unsigned w) vvp_arith_mult::vvp_arith_mult(vvp_ipoint_t b, unsigned w)
: vvp_arith_(b, w) : vvp_arith_(b, w)
{ {
@ -574,6 +626,9 @@ void vvp_shiftr::set(vvp_ipoint_t i, functor_t f, bool push)
/* /*
* $Log: arith.cc,v $ * $Log: arith.cc,v $
* Revision 1.14 2001/10/16 02:47:37 steve
* Add arith/div object.
*
* Revision 1.13 2001/10/14 17:36:18 steve * Revision 1.13 2001/10/14 17:36:18 steve
* Forgot to propagate carry. * Forgot to propagate carry.
* *

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
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: arith.h,v 1.8 2001/07/13 00:38:57 steve Exp $" #ident "$Id: arith.h,v 1.9 2001/10/16 02:47:37 steve Exp $"
#endif #endif
# include "functor.h" # include "functor.h"
@ -43,10 +43,22 @@ class vvp_arith_ : public vvp_fobj_s {
/* /*
* This class is a mode-42 object for arithmetic sum. Inputs that come * This class is a mode-42 object for arithmetic operators. Inputs
* in cause the 4-input summation to be calculated, and output * that come in cause the 4-input summation to be calculated, and
* functors that are affected cause propagations. * output functors that are affected cause propagations.
*/ */
class vvp_arith_div : public vvp_arith_ {
public:
explicit vvp_arith_div(vvp_ipoint_t b, unsigned wid);
void set(vvp_ipoint_t i, functor_t f, bool push);
private: // not implemented
vvp_arith_div(const vvp_arith_div&);
vvp_arith_div& operator= (const vvp_arith_div&);
};
class vvp_arith_mult : public vvp_arith_ { class vvp_arith_mult : public vvp_arith_ {
public: public:
@ -147,6 +159,9 @@ class vvp_shiftr : public vvp_arith_ {
/* /*
* $Log: arith.h,v $ * $Log: arith.h,v $
* Revision 1.9 2001/10/16 02:47:37 steve
* Add arith/div object.
*
* Revision 1.8 2001/07/13 00:38:57 steve * Revision 1.8 2001/07/13 00:38:57 steve
* Remove width restriction on subtraction. * Remove width restriction on subtraction.
* *

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
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: compile.cc,v 1.107 2001/10/16 01:26:54 steve Exp $" #ident "$Id: compile.cc,v 1.108 2001/10/16 02:47:37 steve Exp $"
#endif #endif
# include "arith.h" # include "arith.h"
@ -761,6 +761,26 @@ static void connect_arith_inputs(vvp_ipoint_t fdx, long wid,
free(argv); free(argv);
} }
void compile_arith_div(char*label, long wid,
unsigned argc, struct symb_s*argv)
{
assert( wid > 0 );
if ((long)argc != 2*wid) {
fprintf(stderr, "%s; .arith has wrong number of symbols\n", label);
compile_errors += 1;
free(label);
return;
}
vvp_ipoint_t fdx = functor_allocate(wid);
define_functor_symbol(label, fdx);
vvp_arith_div*arith = new vvp_arith_div(fdx, wid);
connect_arith_inputs(fdx, wid, arith, argc, argv);
}
void compile_arith_mult(char*label, long wid, void compile_arith_mult(char*label, long wid,
unsigned argc, struct symb_s*argv) unsigned argc, struct symb_s*argv)
{ {
@ -1574,6 +1594,9 @@ vvp_ipoint_t debug_lookup_functor(const char*name)
/* /*
* $Log: compile.cc,v $ * $Log: compile.cc,v $
* Revision 1.108 2001/10/16 02:47:37 steve
* Add arith/div object.
*
* Revision 1.107 2001/10/16 01:26:54 steve * Revision 1.107 2001/10/16 01:26:54 steve
* Add %div support (Anthony Bybell) * Add %div support (Anthony Bybell)
* *

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
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: compile.h,v 1.33 2001/10/15 02:58:27 steve Exp $" #ident "$Id: compile.h,v 1.34 2001/10/16 02:47:37 steve Exp $"
#endif #endif
# include <stdio.h> # include <stdio.h>
@ -75,6 +75,8 @@ extern void compile_resolver(char*label, char*type,
* This is called by the parser to make the various arithmetic and * This is called by the parser to make the various arithmetic and
* comparison functors. * comparison functors.
*/ */
extern void compile_arith_div(char*label, long width,
unsigned argc, struct symb_s*argv);
extern void compile_arith_mult(char*label, long width, extern void compile_arith_mult(char*label, long width,
unsigned argc, struct symb_s*argv); unsigned argc, struct symb_s*argv);
extern void compile_arith_sum(char*label, long width, extern void compile_arith_sum(char*label, long width,
@ -204,6 +206,9 @@ extern void compile_net(char*label, char*name,
/* /*
* $Log: compile.h,v $ * $Log: compile.h,v $
* Revision 1.34 2001/10/16 02:47:37 steve
* Add arith/div object.
*
* Revision 1.33 2001/10/15 02:58:27 steve * Revision 1.33 2001/10/15 02:58:27 steve
* Carry the type of the scope (Stephan Boettcher) * Carry the type of the scope (Stephan Boettcher)
* *

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
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: lexor.lex,v 1.26 2001/07/07 02:57:33 steve Exp $" #ident "$Id: lexor.lex,v 1.27 2001/10/16 02:47:37 steve Exp $"
#endif #endif
# include "parse_misc.h" # include "parse_misc.h"
@ -66,6 +66,7 @@
/* These are some keywords that are recognized. */ /* These are some keywords that are recognized. */
".arith/div" { return K_ARITH_DIV; }
".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; }
@ -148,6 +149,9 @@ int yywrap()
/* /*
* $Log: lexor.lex,v $ * $Log: lexor.lex,v $
* Revision 1.27 2001/10/16 02:47:37 steve
* Add arith/div object.
*
* Revision 1.26 2001/07/07 02:57:33 steve * Revision 1.26 2001/07/07 02:57:33 steve
* Add the .shift/r functor. * Add the .shift/r functor.
* *

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
*/ */
#if !defined(WINNT) #if !defined(WINNT)
#ident "$Id: parse.y,v 1.37 2001/10/15 02:58:27 steve Exp $" #ident "$Id: parse.y,v 1.38 2001/10/16 02:47:37 steve Exp $"
#endif #endif
# include "parse_misc.h" # include "parse_misc.h"
@ -54,7 +54,7 @@ extern FILE*yyin;
}; };
%token K_ARITH_MULT K_ARITH_SUB K_ARITH_SUM K_CMP_GE K_CMP_GT %token K_ARITH_DIV K_ARITH_MULT K_ARITH_SUB K_ARITH_SUM K_CMP_GE K_CMP_GT
%token K_EVENT K_EVENT_OR K_FUNCTOR K_NET K_NET_S %token K_EVENT K_EVENT_OR K_FUNCTOR K_NET K_NET_S
%token K_RESOLV K_SCOPE K_SHIFTL K_SHIFTR K_THREAD %token K_RESOLV K_SCOPE K_SHIFTL K_SHIFTR K_THREAD
%token K_UDP K_UDP_C K_UDP_S %token K_UDP K_UDP_C K_UDP_S
@ -161,6 +161,11 @@ statement
/* Arithmetic statements generate functor arrays of a given width /* Arithmetic statements generate functor arrays of a given width
that take like size input vectors. */ that take like size input vectors. */
| T_LABEL K_ARITH_DIV T_NUMBER ',' symbols ';'
{ struct symbv_s obj = $5;
compile_arith_div($1, $3, obj.cnt, obj.vect);
}
| T_LABEL K_ARITH_MULT T_NUMBER ',' symbols ';' | T_LABEL K_ARITH_MULT T_NUMBER ',' symbols ';'
{ struct symbv_s obj = $5; { struct symbv_s obj = $5;
compile_arith_mult($1, $3, obj.cnt, obj.vect); compile_arith_mult($1, $3, obj.cnt, obj.vect);
@ -504,6 +509,9 @@ int compile_design(const char*path)
/* /*
* $Log: parse.y,v $ * $Log: parse.y,v $
* Revision 1.38 2001/10/16 02:47:37 steve
* Add arith/div object.
*
* Revision 1.37 2001/10/15 02:58:27 steve * Revision 1.37 2001/10/15 02:58:27 steve
* Carry the type of the scope (Stephan Boettcher) * Carry the type of the scope (Stephan Boettcher)
* *