2001-11-06 04:07:21 +01:00
|
|
|
/*
|
2004-12-11 03:31:25 +01:00
|
|
|
* Copyright (c) 2001-2004 Stephen Williams (steve@icarus.com)
|
2001-11-06 04:07:21 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
2002-08-12 03:34:58 +02:00
|
|
|
#ifdef HAVE_CVS_IDENT
|
2005-04-13 08:34:20 +02:00
|
|
|
#ident "$Id: logic.cc,v 1.21 2005/04/13 06:34:20 steve Exp $"
|
2001-11-06 04:07:21 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# include "logic.h"
|
|
|
|
|
# include "compile.h"
|
|
|
|
|
# include "bufif.h"
|
|
|
|
|
# include "npmos.h"
|
2002-07-05 22:08:44 +02:00
|
|
|
# include "statistics.h"
|
2001-11-06 04:07:21 +01:00
|
|
|
# include <string.h>
|
|
|
|
|
# include <assert.h>
|
2001-11-16 05:22:27 +01:00
|
|
|
# include <stdlib.h>
|
2001-11-06 04:07:21 +01:00
|
|
|
#ifdef HAVE_MALLOC_H
|
|
|
|
|
# include <malloc.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-07-05 22:08:44 +02:00
|
|
|
|
2001-11-06 04:07:21 +01:00
|
|
|
/*
|
|
|
|
|
* Implementation of the table functor, which provides logic with up
|
|
|
|
|
* to 4 inputs.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-12-11 03:31:25 +01:00
|
|
|
table_functor_s::table_functor_s(truth_t t)
|
2004-10-04 03:10:51 +02:00
|
|
|
: table(t)
|
2001-12-14 03:04:49 +01:00
|
|
|
{
|
2002-07-05 22:08:44 +02:00
|
|
|
count_functors_table += 1;
|
2001-12-14 03:04:49 +01:00
|
|
|
}
|
2001-11-06 04:07:21 +01:00
|
|
|
|
2004-10-04 03:10:51 +02:00
|
|
|
table_functor_s::~table_functor_s()
|
2001-11-06 04:07:21 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-30 00:45:13 +01:00
|
|
|
/*
|
|
|
|
|
* WARNING: This function assumes that the table generator encodes the
|
|
|
|
|
* values 0/1/x/z the same as the vvp_bit4_t enumeration values.
|
|
|
|
|
*/
|
|
|
|
|
void table_functor_s::recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t val)
|
|
|
|
|
{
|
|
|
|
|
input_[ptr.port()] = val;
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t result (val.size());
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < val.size() ; idx += 1) {
|
|
|
|
|
|
|
|
|
|
unsigned lookup = 0;
|
|
|
|
|
for (unsigned pdx = 4 ; pdx > 0 ; pdx -= 1) {
|
|
|
|
|
lookup <<= 2;
|
|
|
|
|
if (idx < input_[pdx-1].size())
|
|
|
|
|
lookup |= input_[pdx-1].value(idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned off = lookup / 4;
|
|
|
|
|
unsigned shift = lookup % 4 * 2;
|
|
|
|
|
|
|
|
|
|
unsigned bit_val = table[off] >> shift;
|
|
|
|
|
bit_val &= 3;
|
|
|
|
|
result.set_bit(idx, (vvp_bit4_t)bit_val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_send_vec4(ptr.ptr()->out, result);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-29 18:52:06 +01:00
|
|
|
vvp_fun_and::vvp_fun_and()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_and::~vvp_fun_and()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_and::recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t bit)
|
|
|
|
|
{
|
|
|
|
|
input_[ptr.port()] = bit;
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t result (bit);
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < result.size() ; idx += 1) {
|
|
|
|
|
vvp_bit4_t bitbit = BIT4_1;
|
|
|
|
|
for (unsigned pdx = 0 ; pdx < 4 ; pdx += 1) {
|
|
|
|
|
if (input_[pdx].size() < idx) {
|
|
|
|
|
bitbit = BIT4_X;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bitbit = bitbit & input_[pdx].value(idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result.set_bit(idx, bitbit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_send_vec4(ptr.ptr()->out, result);
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-30 00:45:13 +01:00
|
|
|
vvp_fun_buf::vvp_fun_buf()
|
|
|
|
|
{
|
|
|
|
|
count_functors_table += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_buf::~vvp_fun_buf()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_buf::recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t bit)
|
2004-12-31 06:56:36 +01:00
|
|
|
{
|
|
|
|
|
if (ptr.port() != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < bit.size() ; idx += 1) {
|
|
|
|
|
if (bit.value(idx) == BIT4_Z)
|
|
|
|
|
bit.set_bit(idx, BIT4_X);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_send_vec4(ptr.ptr()->out, bit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_bufz::vvp_fun_bufz()
|
|
|
|
|
{
|
|
|
|
|
count_functors_table += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_bufz::~vvp_fun_bufz()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_bufz::recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t bit)
|
2004-12-30 00:45:13 +01:00
|
|
|
{
|
|
|
|
|
if (ptr.port() != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
vvp_send_vec4(ptr.ptr()->out, bit);
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-12 23:50:52 +01:00
|
|
|
vvp_fun_muxz::vvp_fun_muxz()
|
|
|
|
|
{
|
|
|
|
|
count_functors_table += 1;
|
|
|
|
|
select_ = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_muxz::~vvp_fun_muxz()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_muxz::recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t bit)
|
|
|
|
|
{
|
|
|
|
|
switch (ptr.port()) {
|
|
|
|
|
case 0:
|
|
|
|
|
a_ = bit;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
b_ = bit;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
assert(bit.size() == 1);
|
|
|
|
|
switch (bit.value(0)) {
|
|
|
|
|
case BIT4_0:
|
|
|
|
|
select_ = 0;
|
|
|
|
|
break;
|
|
|
|
|
case BIT4_1:
|
|
|
|
|
select_ = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
select_ = 2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (select_) {
|
|
|
|
|
case 0:
|
|
|
|
|
vvp_send_vec4(ptr.ptr()->out, a_);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
vvp_send_vec4(ptr.ptr()->out, b_);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
{
|
|
|
|
|
unsigned min_size = a_.size();
|
|
|
|
|
unsigned max_size = a_.size();
|
|
|
|
|
if (b_.size() < min_size)
|
|
|
|
|
min_size = b_.size();
|
|
|
|
|
if (b_.size() > max_size)
|
|
|
|
|
max_size = b_.size();
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t res (max_size);
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < min_size ; idx += 1) {
|
|
|
|
|
if (a_.value(idx) == b_.value(idx))
|
|
|
|
|
res.set_bit(idx, a_.value(idx));
|
|
|
|
|
else
|
|
|
|
|
res.set_bit(idx, BIT4_X);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = min_size ; idx < max_size ; idx += 1)
|
|
|
|
|
res.set_bit(idx, BIT4_X);
|
|
|
|
|
|
|
|
|
|
vvp_send_vec4(ptr.ptr()->out, res);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-06 04:07:21 +01:00
|
|
|
/*
|
|
|
|
|
* The parser calls this function to create a logic functor. I allocate a
|
|
|
|
|
* functor, and map the name to the vvp_ipoint_t address for the
|
|
|
|
|
* functor. Also resolve the inputs to the functor.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-12-06 04:31:24 +01:00
|
|
|
void compile_functor(char*label, char*type,
|
2005-04-03 07:45:51 +02:00
|
|
|
vvp_delay_t*delay, unsigned ostr0, unsigned ostr1,
|
2001-12-06 04:31:24 +01:00
|
|
|
unsigned argc, struct symb_s*argv)
|
2001-11-06 04:07:21 +01:00
|
|
|
{
|
2004-12-30 00:45:13 +01:00
|
|
|
vvp_net_fun_t* obj = 0;
|
2005-04-13 08:34:20 +02:00
|
|
|
bool strength_aware = false;
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
if (strcmp(type, "OR") == 0) {
|
2004-12-11 03:31:25 +01:00
|
|
|
obj = new table_functor_s(ft_OR);
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
} else if (strcmp(type, "AND") == 0) {
|
2005-01-29 18:52:06 +01:00
|
|
|
obj = new vvp_fun_and();
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
} else if (strcmp(type, "BUF") == 0) {
|
2004-12-30 00:45:13 +01:00
|
|
|
obj = new vvp_fun_buf();
|
2005-02-07 23:42:42 +01:00
|
|
|
|
2001-11-06 04:07:21 +01:00
|
|
|
} else if (strcmp(type, "BUFIF0") == 0) {
|
2005-02-07 23:42:42 +01:00
|
|
|
obj = new vvp_fun_bufif(true,false, ostr0, ostr1);
|
2005-04-13 08:34:20 +02:00
|
|
|
strength_aware = true;
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
} else if (strcmp(type, "BUFIF1") == 0) {
|
2005-02-07 23:42:42 +01:00
|
|
|
obj = new vvp_fun_bufif(false,false, ostr0, ostr1);
|
2005-04-13 08:34:20 +02:00
|
|
|
strength_aware = true;
|
2005-02-07 23:42:42 +01:00
|
|
|
|
2002-01-12 05:02:16 +01:00
|
|
|
} else if (strcmp(type, "BUFZ") == 0) {
|
2004-12-31 06:56:36 +01:00
|
|
|
obj = new vvp_fun_bufz();
|
2004-12-11 03:31:25 +01:00
|
|
|
#if 0
|
2001-11-06 04:07:21 +01:00
|
|
|
} else if (strcmp(type, "PMOS") == 0) {
|
|
|
|
|
obj = new vvp_pmos_s;
|
|
|
|
|
|
|
|
|
|
} else if (strcmp(type, "NMOS") == 0) {
|
|
|
|
|
obj= new vvp_nmos_s;
|
|
|
|
|
|
|
|
|
|
} else if (strcmp(type, "RPMOS") == 0) {
|
|
|
|
|
obj = new vvp_rpmos_s;
|
|
|
|
|
|
|
|
|
|
} else if (strcmp(type, "RNMOS") == 0) {
|
|
|
|
|
obj = new vvp_rnmos_s;
|
2004-12-11 03:31:25 +01:00
|
|
|
#endif
|
2002-08-29 05:04:01 +02:00
|
|
|
} else if (strcmp(type, "MUXX") == 0) {
|
|
|
|
|
obj = new table_functor_s(ft_MUXX);
|
|
|
|
|
|
2001-11-06 04:07:21 +01:00
|
|
|
} else if (strcmp(type, "MUXZ") == 0) {
|
2005-02-12 23:50:52 +01:00
|
|
|
obj = new vvp_fun_muxz();
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
} else if (strcmp(type, "EEQ") == 0) {
|
|
|
|
|
obj = new table_functor_s(ft_EEQ);
|
|
|
|
|
|
|
|
|
|
} else if (strcmp(type, "NAND") == 0) {
|
2004-12-11 03:31:25 +01:00
|
|
|
obj = new table_functor_s(ft_NAND);
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
} else if (strcmp(type, "NOR") == 0) {
|
2004-12-11 03:31:25 +01:00
|
|
|
obj = new table_functor_s(ft_NOR);
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
} else if (strcmp(type, "NOT") == 0) {
|
2004-12-11 03:31:25 +01:00
|
|
|
obj = new table_functor_s(ft_NOT);
|
|
|
|
|
#if 0
|
2001-12-14 07:03:17 +01:00
|
|
|
} else if (strcmp(type, "NOTIF0") == 0) {
|
2002-09-06 06:56:28 +02:00
|
|
|
obj = new vvp_bufif_s(true,true, ostr0, ostr1);
|
2001-12-14 07:03:17 +01:00
|
|
|
|
|
|
|
|
} else if (strcmp(type, "NOTIF1") == 0) {
|
2002-09-06 06:56:28 +02:00
|
|
|
obj = new vvp_bufif_s(false,true, ostr0, ostr1);
|
2004-12-11 03:31:25 +01:00
|
|
|
#endif
|
2001-11-06 04:07:21 +01:00
|
|
|
} else if (strcmp(type, "XNOR") == 0) {
|
2004-12-11 03:31:25 +01:00
|
|
|
obj = new table_functor_s(ft_XNOR);
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
} else if (strcmp(type, "XOR") == 0) {
|
2004-12-11 03:31:25 +01:00
|
|
|
obj = new table_functor_s(ft_XOR);
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
yyerror("invalid functor type.");
|
|
|
|
|
free(type);
|
|
|
|
|
free(argv);
|
|
|
|
|
free(label);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(type);
|
|
|
|
|
|
|
|
|
|
assert(argc <= 4);
|
2004-12-11 03:31:25 +01:00
|
|
|
vvp_net_t*net = new vvp_net_t;
|
2004-12-30 00:45:13 +01:00
|
|
|
net->fun = obj;
|
2001-11-06 04:07:21 +01:00
|
|
|
|
2004-12-11 03:31:25 +01:00
|
|
|
inputs_connect(net, argc, argv);
|
2001-11-06 04:07:21 +01:00
|
|
|
free(argv);
|
2005-04-13 08:34:20 +02:00
|
|
|
|
|
|
|
|
/* If both the strengths are the default strong drive, then
|
|
|
|
|
there is no need for a specialized driver. Attach the label
|
|
|
|
|
to this node and we are finished. */
|
|
|
|
|
if (strength_aware || ostr0 == 6 && ostr1 == 6) {
|
|
|
|
|
define_functor_symbol(label, net);
|
|
|
|
|
free(label);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_drive*obj_drv = new vvp_fun_drive(BIT4_X, ostr0, ostr1);
|
|
|
|
|
|
|
|
|
|
vvp_net_t*net_drv = new vvp_net_t;
|
|
|
|
|
net_drv->fun = obj_drv;
|
|
|
|
|
|
|
|
|
|
/* Point the gate to the drive node. */
|
|
|
|
|
net->out = vvp_net_ptr_t(net_drv, 0);
|
|
|
|
|
|
|
|
|
|
define_functor_symbol(label, net_drv);
|
|
|
|
|
free(label);
|
2001-11-06 04:07:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: logic.cc,v $
|
2005-04-13 08:34:20 +02:00
|
|
|
* Revision 1.21 2005/04/13 06:34:20 steve
|
|
|
|
|
* Add vvp driver functor for logic outputs,
|
|
|
|
|
* Add ostream output operators for debugging.
|
|
|
|
|
*
|
2005-04-03 07:45:51 +02:00
|
|
|
* Revision 1.20 2005/04/03 05:45:51 steve
|
|
|
|
|
* Rework the vvp_delay_t class.
|
|
|
|
|
*
|
2005-02-12 23:50:52 +01:00
|
|
|
* Revision 1.19 2005/02/12 22:50:52 steve
|
|
|
|
|
* Implement the vvp_fun_muxz functor.
|
|
|
|
|
*
|
2005-02-07 23:42:42 +01:00
|
|
|
* Revision 1.18 2005/02/07 22:42:42 steve
|
|
|
|
|
* Add .repeat functor and BIFIF functors.
|
|
|
|
|
*
|
2005-01-29 18:52:06 +01:00
|
|
|
* Revision 1.17 2005/01/29 17:52:06 steve
|
|
|
|
|
* move AND to buitin instead of table.
|
|
|
|
|
*
|
2004-12-31 06:56:36 +01:00
|
|
|
* Revision 1.16 2004/12/31 05:56:36 steve
|
|
|
|
|
* Add specific BUFZ functor.
|
|
|
|
|
*
|
2004-12-30 00:45:13 +01:00
|
|
|
* Revision 1.15 2004/12/29 23:45:13 steve
|
|
|
|
|
* Add the part concatenation node (.concat).
|
|
|
|
|
*
|
|
|
|
|
* Add a vvp_event_anyedge class to handle the special
|
|
|
|
|
* case of .event statements of edge type. This also
|
|
|
|
|
* frees the posedge/negedge types to handle all 4 inputs.
|
|
|
|
|
*
|
|
|
|
|
* Implement table functor recv_vec4 method to receive
|
|
|
|
|
* and process vectors.
|
|
|
|
|
*
|
2004-12-11 03:31:25 +01:00
|
|
|
* Revision 1.14 2004/12/11 02:31:29 steve
|
|
|
|
|
* Rework of internals to carry vectors through nexus instead
|
|
|
|
|
* of single bits. Make the ivl, tgt-vvp and vvp initial changes
|
|
|
|
|
* down this path.
|
2001-11-06 04:07:21 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|