Reimplement combinational UDPs.

This commit is contained in:
steve 2005-04-01 06:02:45 +00:00
parent becda0e26c
commit b7ef2fcb0a
8 changed files with 484 additions and 592 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: compile.cc,v 1.195 2005/03/22 05:18:34 steve Exp $"
#ident "$Id: compile.cc,v 1.196 2005/04/01 06:02:45 steve Exp $"
#endif
# include "arith.h"
@ -773,6 +773,26 @@ void inputs_connect(vvp_net_t*fdx, unsigned argc, struct symb_s*argv)
}
}
void wide_inputs_connect(vvp_wide_fun_core*core,
unsigned argc, struct symb_s*argv)
{
/* Create input functors to receive values from the
network. These functors pass the data to the core. */
unsigned input_functors = (argc+3) / 4;
for (unsigned idx = 0 ; idx < input_functors ; idx += 1) {
unsigned base = idx*4;
unsigned trans = 4;
if (base+trans > argc)
trans = argc - base;
vvp_wide_fun_t*cur = new vvp_wide_fun_t(core, base);
vvp_net_t*ptr = new vvp_net_t;
ptr->fun = cur;
inputs_connect(ptr, trans, argv+base);
}
}
struct const_functor_s: public functor_s {
const_functor_s(unsigned str0, unsigned str1)
@ -1118,13 +1138,9 @@ void compile_force(char*label, struct symb_s signal,
void compile_udp_def(int sequ, char *label, char *name,
unsigned nin, unsigned init, char **table)
{
struct vvp_udp_s *u = udp_create(label);
u->name = name;
u->sequ = sequ;
u->nin = nin;
u->init = init;
u->compile_table(table);
free(label);
vvp_udp_s *u = new vvp_udp_s(label, name, nin, sequ? true : false);
u->compile_table(table);
free(label);
}
char **compile_udp_table(char **table, char *row)
@ -1143,42 +1159,6 @@ char **compile_udp_table(char **table, char *row)
return table;
}
void compile_udp_functor(char*label, char*type,
vvp_delay_t delay,
unsigned argc, struct symb_s*argv)
{
struct vvp_udp_s *u = udp_find(type);
assert (argc == u->nin);
#if 0
functor_t udp = new udp_functor_s(u);
unsigned nfun = (argc+3)/4;
vvp_ipoint_t fdx = functor_allocate(nfun);
functor_define(fdx, udp);
define_functor_symbol(label, fdx);
free(label);
if (nfun > 1) {
for (unsigned i=0; i < nfun-1; i++) {
functor_t fu = new edge_inputs_functor_s;
vvp_ipoint_t ipt = ipoint_index(fdx, i+1);
functor_define(ipt, fu);
fu->out = fdx;
}
}
udp->delay = delay;
inputs_connect(fdx, argc, argv);
free(argv);
if (u->sequ)
udp->put_oval(u->init, false);
#else
fprintf(stderr, "XXXX compile_udp_functor not implemented\n");
#endif
}
/*
* Take the detailed parse items from a .mem statement and generate
* the necessary internal structures.
@ -1587,6 +1567,9 @@ void compile_param_string(char*label, char*name, char*str, char*value)
/*
* $Log: compile.cc,v $
* Revision 1.196 2005/04/01 06:02:45 steve
* Reimplement combinational UDPs.
*
* Revision 1.195 2005/03/22 05:18:34 steve
* The indexed set can write a vector, not just a bit.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: compile.h,v 1.66 2005/03/18 02:56:04 steve Exp $"
#ident "$Id: compile.h,v 1.67 2005/04/01 06:02:45 steve Exp $"
#endif
# include <stdio.h>
@ -49,6 +49,16 @@ extern bool verbose_flag;
extern void inputs_connect(vvp_net_t*fdx, unsigned argc, struct symb_s*argv);
extern void input_connect(vvp_net_t*fdx, unsigned port, char*label);
/*
* This function is an expansion of the inputs_connect function. It
* uses the inputs_connect function, but it creates vvp_wide_fun_t
* nodes to handle arbitrary width nodes, and connects those nodes to
* the vvp_wide_fun_core object passed in.
*/
extern void wide_inputs_connect(vvp_wide_fun_core*core,
unsigned argc, struct symb_s*argv);
/*
* Add a functor to the symbol table
*/
@ -300,6 +310,9 @@ extern void compile_net(char*label, char*name,
/*
* $Log: compile.h,v $
* Revision 1.67 2005/04/01 06:02:45 steve
* Reimplement combinational UDPs.
*
* Revision 1.66 2005/03/18 02:56:04 steve
* Add support for LPM_UFUNC user defined functions.
*

View File

@ -1,6 +1,8 @@
/*
* Copyright (c) 2000 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001 Stephan Boettcher <stephan@nevis.columbia.edu>
* Copyright (c) 2005 Stephen Williams (steve@icarus.com)
*
* (This is a rewrite of code that was ...
* Copyright (c) 2001 Stephan Boettcher <stephan@nevis.columbia.edu>)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -18,445 +20,231 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: udp.cc,v 1.26 2004/10/04 01:10:59 steve Exp $"
#ident "$Id: udp.cc,v 1.27 2005/04/01 06:02:45 steve Exp $"
#endif
#include "udp.h"
#include "schedule.h"
#include "symbols.h"
#include "compile.h"
#include <assert.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
/*
* This method is called when the input of a slice of the UDP
* changes. All the slices of the UDP point to this common functor,
* that manages the output of the UDP device. The input functors are
* all edge_inputs_functors_s objects.
*/
void udp_functor_s::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
{
// Save the input in the ival member of this functor. It will
// be read by the propagate method. The old_ival method of the
// edge_input_functor (I am that) will be set by propagate.
put(i, val);
unsigned char out = udp->propagate(this, i);
// Send the result to the output. If this is a combinational
// UDP, then push according to the push flag. However, do
// *not* push sequential outputs.
// Sequential primitive outputs are scheduled as active
// events, no matter what common sense and reason say.
put_oval(out, push & !udp->sequ, false);
}
static symbol_table_t udp_table;
struct vvp_udp_s *udp_create(char *label)
struct vvp_udp_s *udp_find(const char *label)
{
if (!udp_table)
udp_table = new_symbol_table();
assert(!udp_find(label));
struct vvp_udp_s *u = new vvp_udp_s;
symbol_value_t v;
v.ptr = u;
sym_set_value(udp_table, label, v);
u->name = 0x0;
u->sequ = 0;
u->nin = 0;
u->init = 3;
u->table = 0x0;
return u;
symbol_value_t v = sym_get_value(udp_table, label);
return (struct vvp_udp_s *)v.ptr;
}
struct vvp_udp_s *udp_find(char *label)
vvp_udp_s::vvp_udp_s(char*label, char*name, unsigned ports, bool sequ)
{
symbol_value_t v = sym_get_value(udp_table, label);
return (struct vvp_udp_s *)v.ptr;
assert(!sequ); // XXXX sequential UDPs not supported yet.
if (!udp_table)
udp_table = new_symbol_table();
assert(!udp_find(label));
symbol_value_t v;
v.ptr = this;
sym_set_value(udp_table, label, v);
name_ = name;
ports_ = ports;
levels0_ = 0;
levels1_ = 0;
nlevels0_ = 0;
nlevels1_ = 0;
}
typedef unsigned int udp_vec_t;
struct udp_table_entry_s
vvp_udp_s::~vvp_udp_s()
{
udp_vec_t not_0; // all inputs that must not be 0
udp_vec_t not_1x; // all inputs that must not be 1, x
unsigned char edge_idx; // input index of the edge
unsigned char edge_type; // permissible transitions. 0: no edge.
unsigned char out; // new output, 0..2
};
if (levels0_) delete[] levels0_;
if (levels1_) delete[] levels1_;
}
enum edge_type_e
unsigned vvp_udp_s::port_count() const
{
EDGE_0 = 0x01,
EDGE_1 = 0x02,
EDGE_x = 0x0c,
EDGE_any = 0x0f,
};
return ports_;
}
vvp_bit4_t vvp_udp_s::test_levels(const udp_levels_table&cur)
{
for (unsigned idx = 0 ; idx < nlevels0_ ; idx += 1) {
if (cur.mask0 != levels0_[idx].mask0)
continue;
if (cur.mask1 != levels0_[idx].mask1)
continue;
if (cur.maskx != levels0_[idx].maskx)
continue;
return BIT4_0;
}
for (unsigned idx = 0 ; idx < nlevels1_ ; idx += 1) {
if (cur.mask0 != levels1_[idx].mask0)
continue;
if (cur.mask1 != levels1_[idx].mask1)
continue;
if (cur.maskx != levels1_[idx].maskx)
continue;
return BIT4_1;
}
return BIT4_X;
}
void vvp_udp_s::compile_table(char**tab)
{
unsigned nrows0 = 0, nrows1 = 0;
/* First run through the table to figure out the number of
rows I need for each kind of table. */
for (unsigned idx = 0 ; tab[idx] ; idx += 1) {
assert(strlen(tab[idx]) == ports_ + 1);
switch (tab[idx][ports_]) {
case '0':
nrows0 += 1;
break;
case '1':
nrows1 += 1;
break;
case 'x':
break;
default:
assert(0);
}
}
nlevels0_ = nrows0;
levels0_ = new udp_levels_table[nlevels0_];
nlevels1_ = nrows1;
levels1_ = new udp_levels_table[nlevels1_];
nrows0 = 0;
nrows1 = 0;
for (unsigned idx = 0 ; tab[idx] ; idx += 1) {
struct udp_levels_table cur;
cur.mask0 = 0;
cur.mask1 = 0;
cur.maskx = 0;
assert(ports_ <= sizeof(cur.mask0));
for (unsigned pp = 0 ; pp < ports_ ; pp += 1) {
unsigned long mask_bit = 1UL << pp;
switch (tab[idx][pp]) {
case '0':
cur.mask0 |= mask_bit;
break;
case '1':
cur.mask1 |= mask_bit;
break;
case 'x':
cur.maskx |= mask_bit;
break;
default:
assert(0);
}
}
switch (tab[idx][ports_]) {
case '0':
levels0_[nrows0++] = cur;
break;
case '1':
levels1_[nrows1++] = cur;
break;
default:
break;
}
}
assert(nrows0 == nlevels0_);
assert(nrows1 == nlevels1_);
}
vvp_udp_fun_core::vvp_udp_fun_core(vvp_net_t*net, vvp_udp_s*def)
: vvp_wide_fun_core(net, def->port_count())
{
def_ = def;
// Assume initially that all the inputs are 1'bx
current_.mask0 = 0;
current_.mask1 = 0;
current_.maskx = ~ ((-1UL) << port_count());
}
vvp_udp_fun_core::~vvp_udp_fun_core()
{
}
void vvp_udp_fun_core::recv_vec4_from_inputs(unsigned port)
{
/* For now, assume udps are 1-bit wide. */
assert(value(port).size() == 1);
unsigned long mask = 1UL << port;
switch (value(port).value(0)) {
case BIT4_0:
current_.mask0 |= mask;
current_.mask1 &= ~mask;
current_.maskx &= ~mask;
break;
case BIT4_1:
current_.mask0 &= ~mask;
current_.mask1 |= mask;
current_.maskx &= ~mask;
break;
default:
current_.mask0 &= ~mask;
current_.mask1 &= ~mask;
current_.maskx |= mask;
break;
}
vvp_vector4_t out (1);
out.set_bit(0, def_->test_levels(current_));
propagate_vec4(out);
}
/*
* This method of the common table object for the UDP calculates the
* output based on the new input of the functor calling me.
* This function is called by the parser in response to a .udp
* node. We create the nodes needed to integrate the UDP into the
* netlist. The definition should be parsed already.
*/
unsigned char vvp_udp_s::propagate(functor_t fu, vvp_ipoint_t uix)
void compile_udp_functor(char*label, char*type,
vvp_delay_t delay,
unsigned argc, struct symb_s*argv)
{
vvp_ipoint_t base = ipoint_make(uix, 0);
struct vvp_udp_s *def = udp_find(type);
assert(def);
free(type);
unsigned char ret = 2;
unsigned edge_idx = 0; // input index that changed
unsigned edge_type = 0; // input transition
udp_vec_t invec = 0x0; // vector of 2-bit inputs
for (unsigned i=0; i < nin; i+=4)
{
int idx = ipoint_input_index(base, i);
edge_inputs_functor_s *pfun =
dynamic_cast<edge_inputs_functor_s *>(functor_index(idx));
assert(pfun);
invec |= pfun->ival << (2*i);
unsigned char diff = pfun->ival ^ pfun->old_ival;
if (diff)
{
unsigned ii = 0;
if (diff & 0x03) ii = 0;
if (diff & 0x0c) ii = 1;
if (diff & 0x30) ii = 2;
if (diff & 0xc0) ii = 3;
edge_idx = i+ii;
unsigned old_in = (pfun->old_ival >> (2*ii)) & 3;
edge_type = (1<<old_in);
}
pfun->old_ival = pfun->ival;
}
if (sequ)
{
if (edge_type == 0)
return fu->get_oval();
invec <<= 2;
invec |= (fu->get_oval() & 3);
}
udp_vec_t inx = invec & 0xaaaaaaaaU; // all 'x'/'z'
udp_vec_t in01 = ~(inx>>1); // masks all 'x'/'z'
udp_vec_t in1x = invec & in01; // all 'x' and '1'
udp_vec_t in0 = ~invec & in01; // all '0'
for (unsigned ri=0; ri < ntable; ri++)
{
udp_table_entry_t row = table+ri;
if ((in1x & row->not_1x) || (in0 & row->not_0))
continue;
if (!row->edge_type)
{
ret = row->out;
break;
}
if (row->edge_idx != edge_idx)
continue;
if (row->edge_type & edge_type)
{
ret = row->out;
break;
}
}
if (ret>2)
ret = fu->get_oval();
return ret;
}
void vvp_udp_s::compile_table(char **tab)
{
ntable = 0;
for (char **ss = tab; *ss; ss++)
ntable++;
table = new struct udp_table_entry_s[ntable];
for (unsigned i = 0; i < ntable; i++)
{
compile_row_(&table[i], tab[i]);
free(tab[i]);
}
free(tab);
}
void vvp_udp_s::compile_row_(udp_table_entry_t row, char *rchr)
{
row->not_0 = 0; // all inputs that must not be 0
row->not_1x = 0; // all inputs that must not be 1 or x
row->edge_idx = 0; // input index of the edge
row->edge_type = 0; // permissible transitions. 0: no edge.
char *s = rchr;
for (unsigned i = (sequ ? 0 : 1); i <= nin; i++)
{
char c = *s;
s++;
unsigned char n0 = 0;
unsigned char n1x = 0;
unsigned char edge = 0;
switch (c)
{
default:
fprintf(stderr, "vvp: Illegal character (%d) in UDP table\n", c);
assert(0);
break;
case '?':
break;
case '0':
n1x = 3; // 1, x not allowed
break;
case '1':
n0 = 1; // 0 not allowed
n1x = 2; // x not allowed
break;
case 'x':
n0 = 1; // 0 not allowed
n1x = 1; // 1 not allowed
break;
case 'b':
n1x = 2; // x not allowed
break;
case 'l':
n1x = 1; // 1 not allowed
break;
case 'h':
n0 = 1; // 0 not allowed
break;
case '*':
edge = EDGE_any;
break;
case '+':
n0 = 1; // 0 not allowed
n1x = 2; // x not allowed
edge = EDGE_any;
break;
case '_':
n1x = 3; // 1, x not allowed
edge = EDGE_any;
break;
case '%':
n0 = 1; // 0 not allowed
n1x = 1; // 1 not allowed
edge = EDGE_any;
break;
case 'N':
edge = EDGE_1;
break;
case 'P':
edge = EDGE_0;
break;
case 'B':
edge = EDGE_x;
break;
case 'r':
n0 = 1; // 0 not allowed
n1x = 2; // x not allowed
edge = EDGE_0;
break;
case 'R':
n0 = 1; // 0 not allowed
n1x = 2; // x not allowed
edge = EDGE_x;
break;
case 'f':
n1x = 3; // 1, x not allowed
edge = EDGE_1;
break;
case 'F':
n1x = 3; // 1, x not allowed
edge = EDGE_x;
break;
case 'Q':
n0 = 1; // 0 not allowed
n1x = 1; // 1 not allowed
edge = EDGE_0;
break;
case 'q':
n0 = 1; // 0 not allowed
n1x = 1; // 1 not allowed
edge = EDGE_0 | EDGE_1;
break;
case 'M':
n0 = 1; // 0 not allowed
n1x = 1; // 1 not allowed
edge = EDGE_1;
break;
case 'n':
n1x = 1; // 1 not allowed
edge = EDGE_1 | EDGE_x;
break;
case 'p':
n0 = 1; // 0 not allowed
edge = EDGE_0 | EDGE_x;
break;
case 'v':
n1x = 2; // x not allowed
edge = EDGE_0 | EDGE_1;
break;
}
if (edge)
{
if (!sequ)
{
fprintf(stderr, "vvp: edge in combinatorial UDP\n");
assert(0);
}
if (!i)
{
fprintf(stderr, "vvp: edge in UDP output state\n");
assert(0);
}
row->edge_idx = i-1;
if (row->edge_type)
{
fprintf(stderr, "vvp: multiple edges in UDP table row\n");
assert(0);
}
row->edge_type = edge;
}
int j = sequ ? i : i-1;
row->not_0 |= n0 << (2*j);
row->not_1x |= n1x << (2*j);
}
switch (*s)
{
case '0':
row->out = 0;
break;
case '1':
row->out = 1;
break;
case 'x':
row->out = 2;
break;
case '-':
row->out = 4;
break;
default:
fprintf(stderr, "vvp: illegal character (%d) in udp output spec\n", *s);
assert(0);
}
vvp_net_t*ptr = new vvp_net_t;
vvp_udp_fun_core*core = new vvp_udp_fun_core(ptr, def);
ptr->fun = core;
define_functor_symbol(label, ptr);
free(label);
wide_inputs_connect(core, argc, argv);
free(argv);
}
/*
* $Log: udp.cc,v $
* Revision 1.26 2004/10/04 01:10:59 steve
* Clean up spurious trailing white space.
*
* Revision 1.25 2003/09/24 20:46:48 steve
* Standard udp scheduling behavior.
*
* Revision 1.24 2003/09/17 03:39:55 steve
* Internal documentation of UDP devices.
*
* Revision 1.23 2003/09/13 00:59:02 steve
* Comments.
*
* Revision 1.22 2003/09/09 00:56:45 steve
* Reimpelement scheduler to divide nonblocking assign queue out.
*
* Revision 1.21 2003/06/17 21:28:59 steve
* Remove short int restrictions from vvp opcodes. (part 2)
*
* Revision 1.20 2003/04/01 05:32:56 steve
* Propagate output of sequential udp like non-blocksing assign.
*
* Revision 1.19 2003/03/18 01:32:33 steve
* Add the q edge flag.
*
* Revision 1.18 2003/02/09 23:33:26 steve
* Spelling fixes.
*
* Revision 1.17 2002/08/12 01:35:08 steve
* conditional ident string using autoconfig.
*
* Revision 1.16 2002/01/20 23:27:51 steve
* return calculated oval from UDP (Stephan Boettcher)
*
* Revision 1.15 2002/01/06 17:35:01 steve
* Feedback output, not propagated output. (Stephan Boettcher)
*
* Revision 1.14 2001/12/06 03:31:25 steve
* Support functor delays for gates and UDP devices.
* (Stephan Boettcher)
*
* Revision 1.13 2001/11/07 03:34:42 steve
* Use functor pointers where vvp_ipoint_t is unneeded.
*
* Revision 1.12 2001/10/31 04:27:47 steve
* Rewrite the functor type to have fewer functor modes,
* and use objects to manage the different types.
* (Stephan Boettcher)
*
* Revision 1.11 2001/09/19 04:10:40 steve
* Change UDP output only if table matches.
*
* Revision 1.10 2001/09/15 18:27:05 steve
* Make configure detect malloc.h
*
* Revision 1.9 2001/08/09 19:38:23 steve
* Nets (wires) do not use their own functors.
* Modifications to propagation of values.
* (Stephan Boettcher)
*
* Revision 1.8 2001/07/24 01:44:50 steve
* Fast UDP tables (Stephan Boettcher)
*
* Revision 1.7 2001/07/16 19:08:32 steve
* Schedule instead of propagating UDP output. (Stephan Boettcher)
*
* Revision 1.6 2001/06/18 00:51:23 steve
* Add more UDP edge types, and finish up compile
* and run-time support. (Stephan Boettcher)
*
* Revision 1.5 2001/05/31 04:12:43 steve
* Make the bufif0 and bufif1 gates strength aware,
* and accurately propagate strengths of outputs.
*
* Revision 1.4 2001/05/06 03:51:37 steve
* Regularize the mode-42 functor handling.
*
* Revision 1.3 2001/04/26 15:52:22 steve
* Add the mode-42 functor concept to UDPs.
*
* Revision 1.2 2001/04/26 03:10:55 steve
* Redo and simplify UDP behavior.
*
* Revision 1.1 2001/04/24 02:23:59 steve
* Support for UDP devices in VVP (Stephen Boettcher)
* Revision 1.27 2005/04/01 06:02:45 steve
* Reimplement combinational UDPs.
*
*/

161
vvp/udp.h
View File

@ -1,8 +1,10 @@
#ifndef __udp_H
#define __udp_H
/*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001 Stephan Boettcher <stephan@nevis.columbia.edu>
* Copyright (c) 2005 Stephen Williams (steve@icarus.com)
*
* (This is a rewrite of code that was ...
* Copyright (c) 2001 Stephan Boettcher <stephan@nevis.columbia.edu>)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -20,106 +22,97 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: udp.h,v 1.14 2004/10/04 01:10:59 steve Exp $"
#ident "$Id: udp.h,v 1.15 2005/04/01 06:02:45 steve Exp $"
#endif
#include "functor.h"
# include <vvp_net.h>
// UDP implementation:
/*
* The vvp_udp_s instance represents a *definition* of a
* primitive. netlist instances refer to these definitions.
*
* The ports argument of the constructor is the number of input ports
* to the device. The single output port is not counted. The port
* count must be greater then 0.
*
* A level sensitive UDP has a table that includes all the rows that
* generate a 0 output and another table that includes all the rows
* that generate a 1 output. A set of inputs is tested against the
* entries in both sets, and if there are no matches, the output is
* set to x.
*
* The levels0 and levels1 tables are each an array of levels
* tables. Each levels table is a mask of positions that are supposed
* to be 0, 1 and x. The LSB of each mask represents first port, and
* so on. If the bit is set in mask0, a bit4_0 is expected at that
* position, and similarly for mask1 and maskx. Only exactly 1 bit
* will be set in the three masks for each bit position.
*
* This table structure implies that the number of inputs to the level
* sensitive device is limited to the number of bits in an unsigned long.
*/
typedef struct udp_table_entry_s *udp_table_entry_t;
struct udp_levels_table {
unsigned long mask0;
unsigned long mask1;
unsigned long maskx;
};
struct vvp_udp_s
{
char *name;
udp_table_entry_t table;
unsigned ntable;
unsigned sequ;
unsigned nin;
unsigned char init;
class vvp_udp_s {
void compile_table(char **tab);
unsigned char propagate(functor_t fu, vvp_ipoint_t i);
public:
vvp_udp_s(char*label, char*name, unsigned ports, bool sequ);
~vvp_udp_s();
void compile_table(char**tab);
// Return the number of input ports for the defined UDP.
unsigned port_count() const;
// Test the cur table with the compiled rows, and return the
// bit value that matches.
vvp_bit4_t test_levels(const udp_levels_table&cur);
private:
void compile_row_(udp_table_entry_t, char *);
char*name_;
unsigned ports_;
// Level sensitive rows of the device.
struct udp_levels_table*levels0_;
struct udp_levels_table*levels1_;
unsigned nlevels0_, nlevels1_;
};
struct vvp_udp_s *udp_create(char *label);
struct vvp_udp_s *udp_find(char *label);
// UDP instances:
/*
* A complete UDP instance includes one udp_functor_s functor that
* holds the output of the UDP, as well as the first 4 inputs. This
* also points to the vvp_udp_s table that is the behavior for the
* device.
*
* If there are more then 4 inputs to the device, then enough
* edge_inputs_functor_s functors is created to receive all the
* inputs. All the edge_inputs_functors_s ::out members point to the
* leading udp_functor_s object, so the ::set methods all invoke the
* ::set method of this functor.
*
* +---+ First object is a udp_functor_s object
* <----+ +--
* | +--
* | +--
* | +--
* +---+
* ^
* | +---+ Subsequent objects are edge_inputs_functor_s
* \-+ +-- that point their outputs to the leading
* ^ | +-- udp_functor_s object. There are as many
* | | +-- edge_inputs_functor_s objects as needed
* | | +-- to accommodate all the inputs of the user
* | +---+ defined primitive.
* |
* | +---+
* \-+ +--
* | +--
* | +--
* | +--
* +---+
* .
* .
* .
* (The propagate method of the vvp_udp_s object relies on the fact
* that the initial udp_functor_s and the subsequend
* edge_inputs_functor_s objects are consecutive in functor space.)
* Ths looks up a UDP definition from its LABEL.
*/
class udp_functor_s : public edge_inputs_functor_s
{
struct vvp_udp_s *udp_find(const char *label);
/*
* The udp_fun_core is the core of the udp instance in the
* netlist. This core is a vvp_wide_fun_core that takes care of
* dispatching the output. This class also receives the inputs from
* the vvp_wide_fun_t objects and processes them to generate the
* output to be sent.
*/
class vvp_udp_fun_core : public vvp_wide_fun_core {
public:
explicit udp_functor_s(vvp_udp_s *u) : udp(u) {}
void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
vvp_udp_s *udp;
vvp_udp_fun_core(vvp_net_t*net, vvp_udp_s*def);
~vvp_udp_fun_core();
void recv_vec4_from_inputs(unsigned);
private:
vvp_udp_s*def_;
udp_levels_table current_;
};
/*
* $Log: udp.h,v $
* Revision 1.14 2004/10/04 01:10:59 steve
* Clean up spurious trailing white space.
* Revision 1.15 2005/04/01 06:02:45 steve
* Reimplement combinational UDPs.
*
* Revision 1.13 2003/09/17 03:39:55 steve
* Internal documentation of UDP devices.
*
* Revision 1.12 2003/06/17 21:28:59 steve
* Remove short int restrictions from vvp opcodes. (part 2)
*
* Revision 1.11 2002/08/12 01:35:08 steve
* conditional ident string using autoconfig.
*
* Revision 1.10 2001/10/31 04:27:47 steve
* Rewrite the functor type to have fewer functor modes,
* and use objects to manage the different types.
* (Stephan Boettcher)
*
* Revision 1.9 2001/08/09 19:38:23 steve
* Nets (wires) do not use their own functors.
* Modifications to propagation of values.
* (Stephan Boettcher)
*/
#endif

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: ufunc.cc,v 1.6 2005/03/18 02:56:04 steve Exp $"
#ident "$Id: ufunc.cc,v 1.7 2005/04/01 06:02:45 steve Exp $"
#endif
# include "compile.h"
@ -43,12 +43,10 @@ ufunc_core::ufunc_core(unsigned owid, vvp_net_t*ptr,
unsigned nports, vvp_net_t**ports,
vvp_code_t sa, struct __vpiScope*run_scope,
char*result_label)
: vvp_wide_fun_core(ptr, nports)
{
owid_ = owid;
onet_ = ptr;
nports_ = nports;
ports_ = ports;
port_values_ = new vvp_vector4_t[nports];
code_ = sa;
thread_ = 0;
scope_ = run_scope;
@ -58,7 +56,6 @@ ufunc_core::ufunc_core(unsigned owid, vvp_net_t*ptr,
ufunc_core::~ufunc_core()
{
delete[]port_values_;
}
/*
@ -68,10 +65,10 @@ ufunc_core::~ufunc_core()
*/
void ufunc_core::assign_bits_to_ports(void)
{
for (unsigned idx = 0 ; idx < nports_ ; idx += 1) {
for (unsigned idx = 0 ; idx < port_count() ; idx += 1) {
vvp_net_t*net = ports_[idx];
vvp_net_ptr_t pp (net, 0);
net->fun->recv_vec4(pp, port_values_[idx]);
net->fun->recv_vec4(pp, value(idx));
}
}
@ -83,10 +80,8 @@ void ufunc_core::assign_bits_to_ports(void)
void ufunc_core::finish_thread(vthread_t thr)
{
thread_ = 0;
vvp_fun_signal*sig = reinterpret_cast<vvp_fun_signal*>(result_->fun);
vvp_send_vec4(onet_->out, sig->vec4_value());
propagate_vec4(sig->vec4_value());
}
/*
@ -94,32 +89,14 @@ void ufunc_core::finish_thread(vthread_t thr)
* input value to the port of the functor. I save the input value and
* arrange for the function to be called.
*/
void ufunc_core::recv_vec4_from_inputs(unsigned port, vvp_vector4_t bit)
void ufunc_core::recv_vec4_from_inputs(unsigned port)
{
assert(port < nports_);
port_values_[port] = bit;
if (thread_ == 0) {
thread_ = vthread_new(code_, scope_);
schedule_vthread(thread_, 0);
}
}
ufunc_input_functor::ufunc_input_functor(ufunc_core*c, unsigned base)
: core_(c), port_base_(base)
{
}
ufunc_input_functor::~ufunc_input_functor()
{
}
void ufunc_input_functor::recv_vec4(vvp_net_ptr_t port, vvp_vector4_t bit)
{
unsigned pidx = port_base_ + port.port();
core_->recv_vec4_from_inputs(pidx, bit);
}
/*
* This function compiles the .ufunc statement that is discovered in
* the source file. Create all the functors and the thread, and
@ -198,21 +175,7 @@ void compile_ufunc(char*label, char*code, unsigned wid,
start_code->ufunc_core_ptr = fcore;
ujoin_code->ufunc_core_ptr = fcore;
/* Create input functors to receive values from the
network. These functors pass the data to the core. */
unsigned input_functors = (argc+3) / 4;
for (unsigned idx = 0 ; idx < input_functors ; idx += 1) {
unsigned base = idx*4;
unsigned trans = 4;
if (base+trans > argc)
trans = argc - base;
ufunc_input_functor*cur = new ufunc_input_functor(fcore, base);
ptr = new vvp_net_t;
ptr->fun = cur;
inputs_connect(ptr, trans, argv+base);
}
wide_inputs_connect(fcore, argc, argv);
free(argv);
free(portv);
@ -221,6 +184,9 @@ void compile_ufunc(char*label, char*code, unsigned wid,
/*
* $Log: ufunc.cc,v $
* Revision 1.7 2005/04/01 06:02:45 steve
* Reimplement combinational UDPs.
*
* Revision 1.6 2005/03/18 02:56:04 steve
* Add support for LPM_UFUNC user defined functions.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: ufunc.h,v 1.4 2005/03/18 02:56:04 steve Exp $"
#ident "$Id: ufunc.h,v 1.5 2005/04/01 06:02:45 steve Exp $"
#endif
# include "pointers.h"
@ -46,9 +46,11 @@
* ufunc_core is also a functor whose output is connected to the rest
* of the netlist. This is where the result is delivered back to the
* netlist.
*
* This class relies to the vvp_wide_fun_* classes in vvp_net.h.
*/
class ufunc_core : public vvp_net_fun_t {
class ufunc_core : public vvp_wide_fun_core {
public:
ufunc_core(unsigned ow, vvp_net_t*ptr,
@ -64,18 +66,15 @@ class ufunc_core : public vvp_net_fun_t {
void finish_thread(vthread_t thr);
private:
friend class ufunc_input_functor;
void recv_vec4_from_inputs(unsigned port, vvp_vector4_t bit);
void recv_vec4_from_inputs(unsigned port);
private:
// output width of the function node.
unsigned owid_;
// Pointer to the "self" vvp_net_t that points to this functor.
vvp_net_t*onet_;
// Structure to track the input values from the input functors.
unsigned nports_;
// The vvp_net_t* objects for the function input ports. We use
// these to write the input values to the reg input variable
// functors for the thread.
vvp_net_t**ports_;
vvp_vector4_t*port_values_;
// This is a thread to execute the behavioral portion of the
// function.
@ -87,6 +86,7 @@ class ufunc_core : public vvp_net_fun_t {
vvp_net_t*result_;
};
#if 0
/*
* The job of the input functor is only to monitor inputs to the
* function and pass them to the ufunc_core object. Each functor takes
@ -105,9 +105,13 @@ class ufunc_input_functor : public vvp_net_fun_t {
ufunc_core*core_;
unsigned port_base_;
};
#endif
/*
* $Log: ufunc.h,v $
* Revision 1.5 2005/04/01 06:02:45 steve
* Reimplement combinational UDPs.
*
* Revision 1.4 2005/03/18 02:56:04 steve
* Add support for LPM_UFUNC user defined functions.
*

View File

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ident "$Id: vvp_net.cc,v 1.19 2005/03/18 02:56:04 steve Exp $"
#ident "$Id: vvp_net.cc,v 1.20 2005/04/01 06:02:45 steve Exp $"
# include "vvp_net.h"
# include <stdio.h>
@ -781,6 +781,70 @@ vvp_vector4_t vvp_fun_signal::vec4_value() const
return bits4_;
}
/* **** vvp_wide_fun_* methods **** */
vvp_wide_fun_core::vvp_wide_fun_core(vvp_net_t*net, unsigned nports)
{
delay_ = 0;
ptr_ = net;
nports_ = nports;
port_values_ = new vvp_vector4_t [nports_];
}
vvp_wide_fun_core::~vvp_wide_fun_core()
{
delete[]port_values_;
}
void vvp_wide_fun_core::set_output_delay(vvp_time64_t delay)
{
delay_ = delay;
}
void vvp_wide_fun_core::propagate_vec4(const vvp_vector4_t&bit)
{
if (delay_)
schedule_assign_vector(ptr_->out, bit, delay_);
else
vvp_send_vec4(ptr_->out, bit);
}
unsigned vvp_wide_fun_core::port_count() const
{
return nports_;
}
vvp_vector4_t& vvp_wide_fun_core::value(unsigned idx)
{
assert(idx < nports_);
return port_values_[idx];
}
void vvp_wide_fun_core::dispatch_vec4_from_input_(unsigned port,
vvp_vector4_t bit)
{
assert(port < nports_);
port_values_[port] = bit;
recv_vec4_from_inputs(port);
}
vvp_wide_fun_t::vvp_wide_fun_t(vvp_wide_fun_core*c, unsigned base)
: core_(c), port_base_(base)
{
}
vvp_wide_fun_t::~vvp_wide_fun_t()
{
}
void vvp_wide_fun_t::recv_vec4(vvp_net_ptr_t port, vvp_vector4_t bit)
{
unsigned pidx = port_base_ + port.port();
core_->dispatch_vec4_from_input_(pidx, bit);
}
/* **** vvp_scalar_t methods **** */
/*
@ -1178,6 +1242,9 @@ vvp_bit4_t compare_gtge_signed(const vvp_vector4_t&a,
/*
* $Log: vvp_net.cc,v $
* Revision 1.20 2005/04/01 06:02:45 steve
* Reimplement combinational UDPs.
*
* Revision 1.19 2005/03/18 02:56:04 steve
* Add support for LPM_UFUNC user defined functions.
*

View File

@ -18,7 +18,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ident "$Id: vvp_net.h,v 1.19 2005/03/18 02:56:04 steve Exp $"
#ident "$Id: vvp_net.h,v 1.20 2005/04/01 06:02:45 steve Exp $"
# include <stdio.h>
# include <assert.h>
@ -602,8 +602,86 @@ class vvp_fun_signal : public vvp_net_fun_t {
void run_vpi_callbacks();
};
/*
* Wide Functors:
* Wide functors represent special devices that may have more then 4
* input ports. These devices need a set of N/4 actual functors to
* catch the inputs, and use another to deliver the output.
*
* vvp_wide_fun_t --+--> vvp_wide_fun_core --> ...
* |
* vvp_wide_fun_t --+
* |
* vvp_wide_fun_t --+
*
* There are enough input functors to take all the functor inputs, 4
* per functor. These inputs deliver the changed input value to the
* wide_fun_core, which carries the infastructure for the thread. The
* wide_fun_core is also a functor whose output is connected to the rest
* of the netlist. This is where the result is delivered back to the
* netlist.
*
* The vvp_wide_fun_core keeps a store of the inputs from all the
* input functors, and makes them available to the derived class that
* does the processing.
*/
class vvp_wide_fun_core : public vvp_net_fun_t {
public:
vvp_wide_fun_core(vvp_net_t*net, unsigned nports);
virtual ~vvp_wide_fun_core();
void set_output_delay(vvp_time64_t delay);
protected:
void propagate_vec4(const vvp_vector4_t&bit);
unsigned port_count() const;
vvp_vector4_t& value(unsigned);
private:
// the derived class implements this to receive an indication
// that one of the port input values changed.
virtual void recv_vec4_from_inputs(unsigned port) =0;
friend class vvp_wide_fun_t;
void dispatch_vec4_from_input_(unsigned port, vvp_vector4_t bit);
private:
// Propagation delay, if any, for the output from the device.
vvp_time64_t delay_;
// Back-point to the vvp_net_t that points to me.
vvp_net_t*ptr_;
// Structure to track the input values from the input functors.
unsigned nports_;
vvp_vector4_t*port_values_;
};
/*
* The job of the input functor is only to monitor inputs to the
* function and pass them to the ufunc_core object. Each functor takes
* up to 4 inputs, with the base the port number for the first
* function input that this functor represents.
*/
class vvp_wide_fun_t : public vvp_net_fun_t {
public:
vvp_wide_fun_t(vvp_wide_fun_core*c, unsigned base);
~vvp_wide_fun_t();
void recv_vec4(vvp_net_ptr_t port, vvp_vector4_t bit);
private:
vvp_wide_fun_core*core_;
unsigned port_base_;
};
/*
* $Log: vvp_net.h,v $
* Revision 1.20 2005/04/01 06:02:45 steve
* Reimplement combinational UDPs.
*
* Revision 1.19 2005/03/18 02:56:04 steve
* Add support for LPM_UFUNC user defined functions.
*