Implement .arith/sub subtraction.
This commit is contained in:
parent
f480943649
commit
19a7f3faeb
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* $Id: README.txt,v 1.26 2001/06/05 03:05:41 steve Exp $
|
||||
* $Id: README.txt,v 1.27 2001/06/07 03:09:03 steve Exp $
|
||||
*/
|
||||
|
||||
VVP SIMULATION ENGINE
|
||||
|
|
@ -405,6 +405,7 @@ functors. These operators are not in general bitwise, so special
|
|||
measures are needed to make them work in a functor environment. We
|
||||
create special statement types for the various arithmetic operators.
|
||||
|
||||
<label> .arith/sub <wid>, <symbols_list>;
|
||||
<label> .arith/sum <wid>, <symbols_list>;
|
||||
|
||||
Addition is represented by the .arith/sum statement. This creates an
|
||||
|
|
@ -416,6 +417,8 @@ The sum can add together up to 4 operands, specified in the
|
|||
(lsb first) are listed, then the bits of the second, and so on. The
|
||||
number of symbols must be an even multiple of the width of the operator.
|
||||
|
||||
Subtraction is similar to addition, except that the 2nd, 3rd and 4th
|
||||
vectors are subtracted from the first.
|
||||
|
||||
THREAD STATEMENTS:
|
||||
|
||||
|
|
|
|||
67
vvp/arith.cc
67
vvp/arith.cc
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: arith.cc,v 1.1 2001/06/05 03:05:41 steve Exp $"
|
||||
#ident "$Id: arith.cc,v 1.2 2001/06/07 03:09:03 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "arith.h"
|
||||
|
|
@ -26,12 +26,12 @@
|
|||
|
||||
# include <stdio.h>
|
||||
|
||||
vvp_arith_sum::vvp_arith_sum(vvp_ipoint_t b, unsigned w)
|
||||
vvp_arith_::vvp_arith_(vvp_ipoint_t b, unsigned w)
|
||||
: base_(b), wid_(w)
|
||||
{
|
||||
}
|
||||
|
||||
void vvp_arith_sum::output_x_(bool push)
|
||||
void vvp_arith_::output_x_(bool push)
|
||||
{
|
||||
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
||||
vvp_ipoint_t ptr = ipoint_index(base_,idx);
|
||||
|
|
@ -48,6 +48,11 @@ void vvp_arith_sum::output_x_(bool push)
|
|||
}
|
||||
}
|
||||
|
||||
vvp_arith_sum::vvp_arith_sum(vvp_ipoint_t b, unsigned w)
|
||||
: vvp_arith_(b, w)
|
||||
{
|
||||
}
|
||||
|
||||
void vvp_arith_sum::set(vvp_ipoint_t i, functor_t f, bool push)
|
||||
{
|
||||
assert(wid_ <= sizeof(unsigned long));
|
||||
|
|
@ -96,8 +101,64 @@ void vvp_arith_sum::set(vvp_ipoint_t i, functor_t f, bool push)
|
|||
}
|
||||
}
|
||||
|
||||
vvp_arith_sub::vvp_arith_sub(vvp_ipoint_t b, unsigned w)
|
||||
: vvp_arith_(b, w)
|
||||
{
|
||||
}
|
||||
|
||||
void vvp_arith_sub::set(vvp_ipoint_t i, functor_t f, bool push)
|
||||
{
|
||||
assert(wid_ <= sizeof(unsigned long));
|
||||
|
||||
unsigned long sum = 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;
|
||||
}
|
||||
|
||||
unsigned tmp = 0;
|
||||
if (ival & 0x01)
|
||||
tmp += 1;
|
||||
if (ival & 0x04)
|
||||
tmp -= 1;
|
||||
if (ival & 0x10)
|
||||
tmp -= 1;
|
||||
if (ival & 0x40)
|
||||
tmp -= 1;
|
||||
|
||||
sum += (tmp << idx);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* $Log: arith.cc,v $
|
||||
* Revision 1.2 2001/06/07 03:09:03 steve
|
||||
* Implement .arith/sub subtraction.
|
||||
*
|
||||
* Revision 1.1 2001/06/05 03:05:41 steve
|
||||
* Add structural addition.
|
||||
*
|
||||
|
|
|
|||
43
vvp/arith.h
43
vvp/arith.h
|
|
@ -19,36 +19,63 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: arith.h,v 1.1 2001/06/05 03:05:41 steve Exp $"
|
||||
#ident "$Id: arith.h,v 1.2 2001/06/07 03:09:03 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "functor.h"
|
||||
|
||||
class vvp_arith_ : public vvp_fobj_s {
|
||||
|
||||
public:
|
||||
explicit vvp_arith_(vvp_ipoint_t b, unsigned wid);
|
||||
|
||||
protected:
|
||||
vvp_ipoint_t base_;
|
||||
unsigned wid_;
|
||||
|
||||
protected:
|
||||
void output_x_(bool push);
|
||||
|
||||
private: // not implemented
|
||||
vvp_arith_(const vvp_arith_&);
|
||||
vvp_arith_& operator= (const vvp_arith_&);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* This class is a mode-42 object for arithmetic sum. Inputs that come
|
||||
* in cause the 4-input summation to be calculated, and output
|
||||
* functors that are affected cause propagations.
|
||||
*/
|
||||
class vvp_arith_sum : public vvp_fobj_s {
|
||||
class vvp_arith_sum : public vvp_arith_ {
|
||||
|
||||
public:
|
||||
explicit vvp_arith_sum(vvp_ipoint_t b, unsigned wid);
|
||||
|
||||
void set(vvp_ipoint_t i, functor_t f, bool push);
|
||||
|
||||
private:
|
||||
vvp_ipoint_t base_;
|
||||
unsigned wid_;
|
||||
|
||||
void output_x_(bool push);
|
||||
|
||||
private: // not implemented
|
||||
vvp_arith_sum(const vvp_arith_sum&);
|
||||
vvp_arith_sum& operator= (const vvp_arith_sum&);
|
||||
};
|
||||
|
||||
class vvp_arith_sub : public vvp_arith_ {
|
||||
|
||||
public:
|
||||
explicit vvp_arith_sub(vvp_ipoint_t b, unsigned wid);
|
||||
|
||||
void set(vvp_ipoint_t i, functor_t f, bool push);
|
||||
|
||||
private: // not implemented
|
||||
vvp_arith_sub(const vvp_arith_sub&);
|
||||
vvp_arith_sub& operator= (const vvp_arith_sub&);
|
||||
};
|
||||
|
||||
/*
|
||||
* $Log: arith.h,v $
|
||||
* Revision 1.2 2001/06/07 03:09:03 steve
|
||||
* Implement .arith/sub subtraction.
|
||||
*
|
||||
* Revision 1.1 2001/06/05 03:05:41 steve
|
||||
* Add structural addition.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: compile.cc,v 1.71 2001/06/05 03:05:41 steve Exp $"
|
||||
#ident "$Id: compile.cc,v 1.72 2001/06/07 03:09:03 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "arith.h"
|
||||
|
|
@ -401,6 +401,63 @@ void compile_functor(char*label, char*type, unsigned argc, struct symb_s*argv)
|
|||
free(type);
|
||||
}
|
||||
|
||||
static void connect_arith_inputs(vvp_ipoint_t fdx, long wid,
|
||||
vvp_arith_* arith,
|
||||
unsigned argc, struct symb_s*argv)
|
||||
{
|
||||
unsigned opcount = argc / wid;
|
||||
|
||||
struct symb_s tmp_argv[4];
|
||||
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
||||
vvp_ipoint_t ptr = ipoint_index(fdx,idx);
|
||||
functor_t obj = functor_index(ptr);
|
||||
|
||||
obj->ival = 0xaa >> 2*(4 - opcount);
|
||||
obj->oval = 2;
|
||||
obj->odrive0 = 6;
|
||||
obj->odrive1 = 6;
|
||||
obj->mode = M42;
|
||||
obj->obj = arith;
|
||||
#if defined(WITH_DEBUG)
|
||||
obj->breakpoint = 0;
|
||||
#endif
|
||||
|
||||
for (unsigned cdx = 0 ; cdx < opcount ; cdx += 1)
|
||||
tmp_argv[cdx] = argv[idx + wid*cdx];
|
||||
|
||||
inputs_connect(ptr, opcount, tmp_argv);
|
||||
}
|
||||
|
||||
free(argv);
|
||||
}
|
||||
|
||||
void compile_arith_sub(char*label, long wid, unsigned argc, struct symb_s*argv)
|
||||
{
|
||||
assert( wid > 0 );
|
||||
|
||||
if ((argc % wid) != 0) {
|
||||
fprintf(stderr, "%s; .arith has wrong number of symbols\n", label);
|
||||
compile_errors += 1;
|
||||
free(label);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned opcount = argc / wid;
|
||||
if (opcount > 4) {
|
||||
fprintf(stderr, "%s; .arith has too many operands.\n", label);
|
||||
compile_errors += 1;
|
||||
free(label);
|
||||
return;
|
||||
}
|
||||
|
||||
vvp_ipoint_t fdx = functor_allocate(wid);
|
||||
define_functor_symbol(label, fdx);
|
||||
|
||||
vvp_arith_sub*arith = new vvp_arith_sub(fdx, wid);
|
||||
|
||||
connect_arith_inputs(fdx, wid, arith, argc, argv);
|
||||
}
|
||||
|
||||
void compile_arith_sum(char*label, long wid, unsigned argc, struct symb_s*argv)
|
||||
{
|
||||
assert( wid > 0 );
|
||||
|
|
@ -425,28 +482,8 @@ void compile_arith_sum(char*label, long wid, unsigned argc, struct symb_s*argv)
|
|||
|
||||
vvp_arith_sum*arith = new vvp_arith_sum(fdx, wid);
|
||||
|
||||
struct symb_s tmp_argv[4];
|
||||
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
||||
vvp_ipoint_t ptr = ipoint_index(fdx,idx);
|
||||
functor_t obj = functor_index(ptr);
|
||||
connect_arith_inputs(fdx, wid, arith, argc, argv);
|
||||
|
||||
obj->ival = 0xaa >> 2*(4 - opcount);
|
||||
obj->oval = 2;
|
||||
obj->odrive0 = 6;
|
||||
obj->odrive1 = 6;
|
||||
obj->mode = M42;
|
||||
obj->obj = arith;
|
||||
#if defined(WITH_DEBUG)
|
||||
obj->breakpoint = 0;
|
||||
#endif
|
||||
|
||||
for (unsigned cdx = 0 ; cdx < opcount ; cdx += 1)
|
||||
tmp_argv[cdx] = argv[idx + wid*cdx];
|
||||
|
||||
inputs_connect(ptr, opcount, tmp_argv);
|
||||
}
|
||||
|
||||
free(argv);
|
||||
}
|
||||
|
||||
void compile_resolver(char*label, char*type, unsigned argc, struct symb_s*argv)
|
||||
|
|
@ -1262,6 +1299,9 @@ vvp_ipoint_t debug_lookup_functor(const char*name)
|
|||
|
||||
/*
|
||||
* $Log: compile.cc,v $
|
||||
* Revision 1.72 2001/06/07 03:09:03 steve
|
||||
* Implement .arith/sub subtraction.
|
||||
*
|
||||
* Revision 1.71 2001/06/05 03:05:41 steve
|
||||
* Add structural addition.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: compile.h,v 1.24 2001/06/05 03:05:41 steve Exp $"
|
||||
#ident "$Id: compile.h,v 1.25 2001/06/07 03:09:03 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include <stdio.h>
|
||||
|
|
@ -74,6 +74,8 @@ extern void compile_resolver(char*label, char*type,
|
|||
*/
|
||||
extern void compile_arith_sum(char*label, long width,
|
||||
unsigned argc, struct symb_s*argv);
|
||||
extern void compile_arith_sub(char*label, long width,
|
||||
unsigned argc, struct symb_s*argv);
|
||||
|
||||
|
||||
extern void compile_vpi_symbol(const char*label, vpiHandle obj);
|
||||
|
|
@ -188,6 +190,9 @@ extern void compile_net(char*label, char*name,
|
|||
|
||||
/*
|
||||
* $Log: compile.h,v $
|
||||
* Revision 1.25 2001/06/07 03:09:03 steve
|
||||
* Implement .arith/sub subtraction.
|
||||
*
|
||||
* Revision 1.24 2001/06/05 03:05:41 steve
|
||||
* Add structural addition.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: lexor.lex,v 1.19 2001/06/05 03:05:41 steve Exp $"
|
||||
#ident "$Id: lexor.lex,v 1.20 2001/06/07 03:09:03 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "parse_misc.h"
|
||||
|
|
@ -65,6 +65,7 @@
|
|||
|
||||
|
||||
/* These are some keywords that are recognized. */
|
||||
".arith/sub" { return K_ARITH_SUB; }
|
||||
".arith/sum" { return K_ARITH_SUM; }
|
||||
".event" { return K_EVENT; }
|
||||
".event/or" { return K_EVENT_OR; }
|
||||
|
|
@ -141,6 +142,9 @@ int yywrap()
|
|||
|
||||
/*
|
||||
* $Log: lexor.lex,v $
|
||||
* Revision 1.20 2001/06/07 03:09:03 steve
|
||||
* Implement .arith/sub subtraction.
|
||||
*
|
||||
* Revision 1.19 2001/06/05 03:05:41 steve
|
||||
* Add structural addition.
|
||||
*
|
||||
|
|
|
|||
12
vvp/parse.y
12
vvp/parse.y
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT)
|
||||
#ident "$Id: parse.y,v 1.28 2001/06/05 03:05:41 steve Exp $"
|
||||
#ident "$Id: parse.y,v 1.29 2001/06/07 03:09:03 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "parse_misc.h"
|
||||
|
|
@ -54,7 +54,7 @@ extern FILE*yyin;
|
|||
};
|
||||
|
||||
|
||||
%token K_ARITH_SUM K_EVENT K_EVENT_OR K_FUNCTOR K_NET K_NET_S
|
||||
%token K_ARITH_SUB K_ARITH_SUM K_EVENT K_EVENT_OR K_FUNCTOR K_NET K_NET_S
|
||||
%token K_RESOLV K_SCOPE K_THREAD
|
||||
%token K_UDP K_UDP_C K_UDP_S
|
||||
%token K_MEM K_MEM_P K_MEM_I
|
||||
|
|
@ -156,6 +156,11 @@ statement
|
|||
/* Arithmetic statements generate functor arrays of a given width
|
||||
that take like size input vectors. */
|
||||
|
||||
| T_LABEL K_ARITH_SUB T_NUMBER ',' symbols ';'
|
||||
{ struct symbv_s obj = $5;
|
||||
compile_arith_sub($1, $3, obj.cnt, obj.vect);
|
||||
}
|
||||
|
||||
| T_LABEL K_ARITH_SUM T_NUMBER ',' symbols ';'
|
||||
{ struct symbv_s obj = $5;
|
||||
compile_arith_sum($1, $3, obj.cnt, obj.vect);
|
||||
|
|
@ -453,6 +458,9 @@ int compile_design(const char*path)
|
|||
|
||||
/*
|
||||
* $Log: parse.y,v $
|
||||
* Revision 1.29 2001/06/07 03:09:03 steve
|
||||
* Implement .arith/sub subtraction.
|
||||
*
|
||||
* Revision 1.28 2001/06/05 03:05:41 steve
|
||||
* Add structural addition.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue