2001-11-06 04:07:21 +01:00
|
|
|
/*
|
2008-03-20 23:32:54 +01:00
|
|
|
* Copyright (c) 2001-2008 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
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "logic.h"
|
|
|
|
|
# include "compile.h"
|
|
|
|
|
# include "bufif.h"
|
|
|
|
|
# include "npmos.h"
|
2005-05-13 07:13:12 +02:00
|
|
|
# include "schedule.h"
|
2005-06-26 20:06:29 +02:00
|
|
|
# include "delay.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
|
|
|
|
|
|
2005-06-26 23:08:38 +02:00
|
|
|
vvp_fun_boolean_::vvp_fun_boolean_(unsigned wid)
|
|
|
|
|
{
|
2005-09-20 00:47:28 +02:00
|
|
|
net_ = 0;
|
2005-06-26 23:08:38 +02:00
|
|
|
for (unsigned idx = 0 ; idx < 4 ; idx += 1)
|
|
|
|
|
input_[idx] = vvp_vector4_t(wid);
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-26 20:06:29 +02:00
|
|
|
vvp_fun_boolean_::~vvp_fun_boolean_()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_boolean_::recv_vec4(vvp_net_ptr_t ptr, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
2005-06-26 20:06:29 +02:00
|
|
|
{
|
|
|
|
|
unsigned port = ptr.port();
|
|
|
|
|
if (input_[port] .eeq( bit ))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
input_[ptr.port()] = bit;
|
2005-09-20 00:47:28 +02:00
|
|
|
if (net_ == 0) {
|
|
|
|
|
net_ = ptr.ptr();
|
|
|
|
|
schedule_generic(this, 0, false);
|
|
|
|
|
}
|
2005-06-26 20:06:29 +02:00
|
|
|
}
|
|
|
|
|
|
2007-08-29 01:52:44 +02:00
|
|
|
void vvp_fun_boolean_::recv_vec4_pv(vvp_net_ptr_t ptr, const vvp_vector4_t&bit,
|
2008-10-28 18:52:39 +01:00
|
|
|
unsigned base, unsigned wid, unsigned vwid,
|
|
|
|
|
vvp_context_t)
|
2007-08-29 01:52:44 +02:00
|
|
|
{
|
|
|
|
|
unsigned port = ptr.port();
|
|
|
|
|
|
|
|
|
|
assert(bit.size() == wid);
|
|
|
|
|
assert(base + bit.size() <= vwid);
|
|
|
|
|
|
|
|
|
|
if (input_[port].subvalue(base, wid) .eeq( bit ))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
input_[port] .set_vec(base, bit);
|
|
|
|
|
if (net_ == 0) {
|
|
|
|
|
net_ = ptr.ptr();
|
|
|
|
|
schedule_generic(this, 0, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-28 06:57:20 +01:00
|
|
|
vvp_fun_and::vvp_fun_and(unsigned wid, bool invert)
|
|
|
|
|
: vvp_fun_boolean_(wid), invert_(invert)
|
2005-01-29 18:52:06 +01:00
|
|
|
{
|
2007-12-02 17:47:06 +01:00
|
|
|
count_functors_logic += 1;
|
2005-01-29 18:52:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_and::~vvp_fun_and()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-26 20:06:29 +02:00
|
|
|
void vvp_fun_and::run_run()
|
2005-01-29 18:52:06 +01:00
|
|
|
{
|
2005-09-20 00:47:28 +02:00
|
|
|
vvp_net_t*ptr = net_;
|
|
|
|
|
net_ = 0;
|
|
|
|
|
|
2005-06-26 20:06:29 +02:00
|
|
|
vvp_vector4_t result (input_[0]);
|
2005-01-29 18:52:06 +01:00
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < result.size() ; idx += 1) {
|
2005-06-26 20:06:29 +02:00
|
|
|
vvp_bit4_t bitbit = result.value(idx);
|
|
|
|
|
for (unsigned pdx = 1 ; pdx < 4 ; pdx += 1) {
|
2005-01-29 18:52:06 +01:00
|
|
|
if (input_[pdx].size() < idx) {
|
|
|
|
|
bitbit = BIT4_X;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bitbit = bitbit & input_[pdx].value(idx);
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-12 06:08:27 +01:00
|
|
|
if (invert_)
|
|
|
|
|
bitbit = ~bitbit;
|
2005-01-29 18:52:06 +01:00
|
|
|
result.set_bit(idx, bitbit);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_vec4(ptr->out, result, 0);
|
2005-01-29 18:52:06 +01:00
|
|
|
}
|
|
|
|
|
|
2005-05-14 21:43:23 +02:00
|
|
|
vvp_fun_buf::vvp_fun_buf()
|
2004-12-30 00:45:13 +01:00
|
|
|
{
|
2005-09-20 00:47:28 +02:00
|
|
|
net_ = 0;
|
2007-12-02 17:47:06 +01:00
|
|
|
count_functors_logic += 1;
|
2004-12-30 00:45:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_buf::~vvp_fun_buf()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-22 00:48:23 +02:00
|
|
|
/*
|
|
|
|
|
* The buf functor is very simple--change the z bits to x bits in the
|
|
|
|
|
* vector it passes, and propagate the result.
|
|
|
|
|
*/
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_buf::recv_vec4(vvp_net_ptr_t ptr, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
2004-12-31 06:56:36 +01:00
|
|
|
{
|
|
|
|
|
if (ptr.port() != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2005-09-19 23:45:09 +02:00
|
|
|
if (input_ .eeq( bit ))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
input_ = bit;
|
2005-09-20 00:47:28 +02:00
|
|
|
|
|
|
|
|
if (net_ == 0) {
|
|
|
|
|
net_ = ptr.ptr();
|
|
|
|
|
schedule_generic(this, 0, false);
|
|
|
|
|
}
|
2005-09-19 23:45:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_buf::run_run()
|
|
|
|
|
{
|
2005-09-20 00:47:28 +02:00
|
|
|
vvp_net_t*ptr = net_;
|
|
|
|
|
net_ = 0;
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t tmp (input_);
|
|
|
|
|
tmp.change_z2x();
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_vec4(ptr->out, tmp, 0);
|
2004-12-31 06:56:36 +01:00
|
|
|
}
|
|
|
|
|
|
2005-05-14 21:43:23 +02:00
|
|
|
vvp_fun_bufz::vvp_fun_bufz()
|
2004-12-31 06:56:36 +01:00
|
|
|
{
|
2007-12-02 17:47:06 +01:00
|
|
|
count_functors_logic += 1;
|
2004-12-31 06:56:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_bufz::~vvp_fun_bufz()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-22 00:48:23 +02:00
|
|
|
/*
|
|
|
|
|
* The bufz is similar to the buf device, except that it does not
|
|
|
|
|
* bother translating z bits to x.
|
|
|
|
|
*/
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_bufz::recv_vec4(vvp_net_ptr_t ptr, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
2004-12-30 00:45:13 +01:00
|
|
|
{
|
|
|
|
|
if (ptr.port() != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_vec4(ptr.ptr()->out, bit, 0);
|
2004-12-30 00:45:13 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-28 01:19:30 +01:00
|
|
|
void vvp_fun_bufz::recv_vec8(vvp_net_ptr_t ptr, const vvp_vector8_t&bit)
|
|
|
|
|
{
|
|
|
|
|
if (ptr.port() != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
vvp_send_vec8(ptr.ptr()->out, bit);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_bufz::recv_real(vvp_net_ptr_t ptr, double bit,
|
|
|
|
|
vvp_context_t)
|
2005-07-06 06:29:25 +02:00
|
|
|
{
|
|
|
|
|
if (ptr.port() != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_real(ptr.ptr()->out, bit, 0);
|
2005-07-06 06:29:25 +02:00
|
|
|
}
|
|
|
|
|
|
2005-09-01 06:08:47 +02:00
|
|
|
vvp_fun_muxr::vvp_fun_muxr()
|
|
|
|
|
: a_(0.0), b_(0.0)
|
|
|
|
|
{
|
2008-03-20 23:32:54 +01:00
|
|
|
net_ = 0;
|
2007-12-02 17:47:06 +01:00
|
|
|
count_functors_logic += 1;
|
2008-04-08 18:17:51 +02:00
|
|
|
select_ = SEL_BOTH;
|
2005-09-01 06:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_muxr::~vvp_fun_muxr()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_muxr::recv_vec4(vvp_net_ptr_t ptr, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
2005-09-01 06:08:47 +02:00
|
|
|
{
|
|
|
|
|
/* The real valued mux can only take in the select as a
|
2008-03-20 23:32:54 +01:00
|
|
|
vector4_t. The muxed data is real. */
|
2005-09-01 06:08:47 +02:00
|
|
|
if (ptr.port() != 2)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
assert(bit.size() == 1);
|
|
|
|
|
|
|
|
|
|
switch (bit.value(0)) {
|
|
|
|
|
case BIT4_0:
|
2008-04-08 18:17:51 +02:00
|
|
|
if (select_ == SEL_PORT0) return;
|
|
|
|
|
select_ = SEL_PORT0;
|
2005-09-01 06:08:47 +02:00
|
|
|
break;
|
|
|
|
|
case BIT4_1:
|
2008-04-08 18:17:51 +02:00
|
|
|
if (select_ == SEL_PORT1) return;
|
|
|
|
|
select_ = SEL_PORT1;
|
2005-09-01 06:08:47 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2008-04-08 18:17:51 +02:00
|
|
|
if (select_ == SEL_BOTH) return;
|
|
|
|
|
select_ = SEL_BOTH;
|
2005-09-01 06:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
2008-03-20 23:32:54 +01:00
|
|
|
if (net_ == 0) {
|
|
|
|
|
net_ = ptr.ptr();
|
|
|
|
|
schedule_generic(this, 0, false);
|
2005-09-01 06:08:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_muxr::recv_real(vvp_net_ptr_t ptr, double bit,
|
|
|
|
|
vvp_context_t)
|
2005-09-01 06:08:47 +02:00
|
|
|
{
|
|
|
|
|
switch (ptr.port()) {
|
|
|
|
|
case 0:
|
2008-03-20 23:32:54 +01:00
|
|
|
if (a_ == bit) return;
|
2005-09-01 06:08:47 +02:00
|
|
|
a_ = bit;
|
2008-04-08 18:17:51 +02:00
|
|
|
if (select_ == SEL_PORT1) return; // The other port is selected.
|
2005-09-01 06:08:47 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 1:
|
2008-03-20 23:32:54 +01:00
|
|
|
if (b_ == bit) return;
|
2005-09-01 06:08:47 +02:00
|
|
|
b_ = bit;
|
2008-04-08 18:17:51 +02:00
|
|
|
if (select_ == SEL_PORT0) return; // The other port is selected.
|
2005-09-01 06:08:47 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2007-08-23 00:15:32 +02:00
|
|
|
fprintf(stderr, "Unsupported port type %d.\n", ptr.port());
|
2005-09-01 06:08:47 +02:00
|
|
|
assert(0);
|
|
|
|
|
}
|
2008-03-20 23:32:54 +01:00
|
|
|
|
|
|
|
|
if (net_ == 0) {
|
|
|
|
|
net_ = ptr.ptr();
|
|
|
|
|
schedule_generic(this, 0, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_muxr::run_run()
|
|
|
|
|
{
|
|
|
|
|
vvp_net_t*ptr = net_;
|
|
|
|
|
net_ = 0;
|
|
|
|
|
|
|
|
|
|
switch (select_) {
|
2008-04-08 18:17:51 +02:00
|
|
|
case SEL_PORT0:
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_real(ptr->out, a_, 0);
|
2008-03-20 23:32:54 +01:00
|
|
|
break;
|
2008-04-08 18:17:51 +02:00
|
|
|
case SEL_PORT1:
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_real(ptr->out, b_, 0);
|
2008-03-20 23:32:54 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (a_ == b_) {
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_real(ptr->out, a_, 0);
|
2008-03-20 23:32:54 +01:00
|
|
|
} else {
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_real(ptr->out, 0.0, 0); // Should this be NaN?
|
2008-03-20 23:32:54 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-09-01 06:08:47 +02:00
|
|
|
}
|
|
|
|
|
|
2005-06-17 05:46:52 +02:00
|
|
|
vvp_fun_muxz::vvp_fun_muxz(unsigned wid)
|
|
|
|
|
: a_(wid), b_(wid)
|
2005-02-12 23:50:52 +01:00
|
|
|
{
|
2008-03-20 23:32:54 +01:00
|
|
|
net_ = 0;
|
2007-12-02 17:47:06 +01:00
|
|
|
count_functors_logic += 1;
|
2008-04-08 18:17:51 +02:00
|
|
|
select_ = SEL_BOTH;
|
2008-04-08 02:18:21 +02:00
|
|
|
has_run_ = false;
|
2005-06-17 05:46:52 +02:00
|
|
|
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
|
|
|
|
a_.set_bit(idx, BIT4_X);
|
|
|
|
|
b_.set_bit(idx, BIT4_X);
|
|
|
|
|
}
|
2005-02-12 23:50:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_muxz::~vvp_fun_muxz()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_muxz::recv_vec4(vvp_net_ptr_t ptr, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
2005-02-12 23:50:52 +01:00
|
|
|
{
|
|
|
|
|
switch (ptr.port()) {
|
|
|
|
|
case 0:
|
2008-04-08 02:18:21 +02:00
|
|
|
if (a_ .eeq(bit) && has_run_) return;
|
2005-02-12 23:50:52 +01:00
|
|
|
a_ = bit;
|
2008-04-08 18:17:51 +02:00
|
|
|
if (select_ == SEL_PORT1) return; // The other port is selected.
|
2005-02-12 23:50:52 +01:00
|
|
|
break;
|
|
|
|
|
case 1:
|
2008-04-08 02:18:21 +02:00
|
|
|
if (b_ .eeq(bit) && has_run_) return;
|
2005-02-12 23:50:52 +01:00
|
|
|
b_ = bit;
|
2008-04-08 18:17:51 +02:00
|
|
|
if (select_ == SEL_PORT0) return; // The other port is selected.
|
2005-02-12 23:50:52 +01:00
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
assert(bit.size() == 1);
|
|
|
|
|
switch (bit.value(0)) {
|
|
|
|
|
case BIT4_0:
|
2008-04-08 18:17:51 +02:00
|
|
|
if (select_ == SEL_PORT0) return;
|
|
|
|
|
select_ = SEL_PORT0;
|
2005-02-12 23:50:52 +01:00
|
|
|
break;
|
|
|
|
|
case BIT4_1:
|
2008-04-08 18:17:51 +02:00
|
|
|
if (select_ == SEL_PORT1) return;
|
|
|
|
|
select_ = SEL_PORT1;
|
2005-02-12 23:50:52 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
2008-04-08 18:17:51 +02:00
|
|
|
if (select_ == SEL_BOTH && has_run_) return;
|
|
|
|
|
select_ = SEL_BOTH;
|
2005-02-12 23:50:52 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-03-20 23:32:54 +01:00
|
|
|
if (net_ == 0) {
|
|
|
|
|
net_ = ptr.ptr();
|
|
|
|
|
schedule_generic(this, 0, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_muxz::run_run()
|
|
|
|
|
{
|
2008-04-08 02:18:21 +02:00
|
|
|
has_run_ = true;
|
2008-03-20 23:32:54 +01:00
|
|
|
vvp_net_t*ptr = net_;
|
|
|
|
|
net_ = 0;
|
|
|
|
|
|
2005-02-12 23:50:52 +01:00
|
|
|
switch (select_) {
|
2008-04-08 18:17:51 +02:00
|
|
|
case SEL_PORT0:
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_vec4(ptr->out, a_, 0);
|
2005-02-12 23:50:52 +01:00
|
|
|
break;
|
2008-04-08 18:17:51 +02:00
|
|
|
case SEL_PORT1:
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_vec4(ptr->out, b_, 0);
|
2005-02-12 23:50:52 +01:00
|
|
|
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);
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_vec4(ptr->out, res, 0);
|
2005-02-12 23:50:52 +01:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-19 23:45:09 +02:00
|
|
|
vvp_fun_not::vvp_fun_not()
|
|
|
|
|
{
|
2005-09-20 00:47:28 +02:00
|
|
|
net_ = 0;
|
2007-12-02 17:47:06 +01:00
|
|
|
count_functors_logic += 1;
|
2005-09-19 23:45:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_not::~vvp_fun_not()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The buf functor is very simple--change the z bits to x bits in the
|
|
|
|
|
* vector it passes, and propagate the result.
|
|
|
|
|
*/
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_not::recv_vec4(vvp_net_ptr_t ptr, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
2005-09-19 23:45:09 +02:00
|
|
|
{
|
|
|
|
|
if (ptr.port() != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (input_ .eeq( bit ))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
input_ = bit;
|
2005-09-20 00:47:28 +02:00
|
|
|
if (net_ == 0) {
|
|
|
|
|
net_ = ptr.ptr();
|
|
|
|
|
schedule_generic(this, 0, false);
|
|
|
|
|
}
|
2005-09-19 23:45:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_not::run_run()
|
|
|
|
|
{
|
2005-09-20 00:47:28 +02:00
|
|
|
vvp_net_t*ptr = net_;
|
|
|
|
|
net_ = 0;
|
|
|
|
|
|
2005-09-19 23:45:09 +02:00
|
|
|
vvp_vector4_t result (input_);
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < result.size() ; idx += 1) {
|
|
|
|
|
vvp_bit4_t bitbit = ~ result.value(idx);
|
|
|
|
|
result.set_bit(idx, bitbit);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_vec4(ptr->out, result, 0);
|
2005-09-19 23:45:09 +02:00
|
|
|
}
|
|
|
|
|
|
2006-11-28 06:57:20 +01:00
|
|
|
vvp_fun_or::vvp_fun_or(unsigned wid, bool invert)
|
|
|
|
|
: vvp_fun_boolean_(wid), invert_(invert)
|
2005-09-19 23:45:09 +02:00
|
|
|
{
|
2007-12-02 17:47:06 +01:00
|
|
|
count_functors_logic += 1;
|
2005-09-19 23:45:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_or::~vvp_fun_or()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_or::run_run()
|
|
|
|
|
{
|
2005-09-20 00:47:28 +02:00
|
|
|
vvp_net_t*ptr = net_;
|
|
|
|
|
net_ = 0;
|
|
|
|
|
|
2005-09-19 23:45:09 +02:00
|
|
|
vvp_vector4_t result (input_[0]);
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < result.size() ; idx += 1) {
|
|
|
|
|
vvp_bit4_t bitbit = result.value(idx);
|
|
|
|
|
for (unsigned pdx = 1 ; pdx < 4 ; pdx += 1) {
|
|
|
|
|
if (input_[pdx].size() < idx) {
|
|
|
|
|
bitbit = BIT4_X;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bitbit = bitbit | input_[pdx].value(idx);
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-28 06:57:20 +01:00
|
|
|
if (invert_)
|
|
|
|
|
bitbit = ~bitbit;
|
2005-09-19 23:45:09 +02:00
|
|
|
result.set_bit(idx, bitbit);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_vec4(ptr->out, result, 0);
|
2005-09-19 23:45:09 +02:00
|
|
|
}
|
|
|
|
|
|
2006-11-28 06:57:20 +01:00
|
|
|
vvp_fun_xor::vvp_fun_xor(unsigned wid, bool invert)
|
|
|
|
|
: vvp_fun_boolean_(wid), invert_(invert)
|
2005-09-19 23:45:09 +02:00
|
|
|
{
|
2007-12-02 17:47:06 +01:00
|
|
|
count_functors_logic += 1;
|
2005-09-19 23:45:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_xor::~vvp_fun_xor()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_xor::run_run()
|
|
|
|
|
{
|
2005-09-20 00:47:28 +02:00
|
|
|
vvp_net_t*ptr = net_;
|
|
|
|
|
net_ = 0;
|
|
|
|
|
|
2005-09-19 23:45:09 +02:00
|
|
|
vvp_vector4_t result (input_[0]);
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < result.size() ; idx += 1) {
|
|
|
|
|
vvp_bit4_t bitbit = result.value(idx);
|
|
|
|
|
for (unsigned pdx = 1 ; pdx < 4 ; pdx += 1) {
|
|
|
|
|
if (input_[pdx].size() < idx) {
|
|
|
|
|
bitbit = BIT4_X;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bitbit = bitbit ^ input_[pdx].value(idx);
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-28 06:57:20 +01:00
|
|
|
if (invert_)
|
|
|
|
|
bitbit = ~bitbit;
|
2005-09-19 23:45:09 +02:00
|
|
|
result.set_bit(idx, bitbit);
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
vvp_send_vec4(ptr->out, result, 0);
|
2005-09-19 23:45:09 +02:00
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2005-06-17 05:46:52 +02:00
|
|
|
void compile_functor(char*label, char*type, unsigned width,
|
2006-01-02 06:32:06 +01:00
|
|
|
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) {
|
2006-11-28 06:57:20 +01:00
|
|
|
obj = new vvp_fun_or(width, false);
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
} else if (strcmp(type, "AND") == 0) {
|
2006-11-28 06:57:20 +01:00
|
|
|
obj = new vvp_fun_and(width, false);
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
} else if (strcmp(type, "BUF") == 0) {
|
2005-05-14 21:43:23 +02: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
|
|
|
|
2006-11-28 06:57:20 +01:00
|
|
|
} else if (strcmp(type, "NAND") == 0) {
|
|
|
|
|
obj = new vvp_fun_and(width, true);
|
|
|
|
|
|
|
|
|
|
} else if (strcmp(type, "NOR") == 0) {
|
|
|
|
|
obj = new vvp_fun_or(width, true);
|
|
|
|
|
|
2005-06-02 18:02:11 +02:00
|
|
|
} else if (strcmp(type, "NOTIF0") == 0) {
|
|
|
|
|
obj = new vvp_fun_bufif(true,true, ostr0, ostr1);
|
|
|
|
|
strength_aware = true;
|
|
|
|
|
|
|
|
|
|
} else if (strcmp(type, "NOTIF1") == 0) {
|
|
|
|
|
obj = new vvp_fun_bufif(false,true, ostr0, ostr1);
|
|
|
|
|
strength_aware = true;
|
|
|
|
|
|
2002-01-12 05:02:16 +01:00
|
|
|
} else if (strcmp(type, "BUFZ") == 0) {
|
2005-05-14 21:43:23 +02:00
|
|
|
obj = new vvp_fun_bufz();
|
2001-11-06 04:07:21 +01:00
|
|
|
|
2005-09-01 06:08:47 +02:00
|
|
|
} else if (strcmp(type, "MUXR") == 0) {
|
|
|
|
|
obj = new vvp_fun_muxr;
|
|
|
|
|
|
2001-11-06 04:07:21 +01:00
|
|
|
} else if (strcmp(type, "MUXZ") == 0) {
|
2005-06-17 05:46:52 +02:00
|
|
|
obj = new vvp_fun_muxz(width);
|
2001-11-06 04:07:21 +01:00
|
|
|
|
2007-09-07 03:46:22 +02:00
|
|
|
} else if (strcmp(type, "CMOS") == 0) {
|
|
|
|
|
obj = new vvp_fun_cmos();
|
|
|
|
|
|
2005-06-12 02:44:49 +02:00
|
|
|
} else if (strcmp(type, "NMOS") == 0) {
|
|
|
|
|
obj = new vvp_fun_pmos(true);
|
|
|
|
|
|
|
|
|
|
} else if (strcmp(type, "PMOS") == 0) {
|
|
|
|
|
obj = new vvp_fun_pmos(false);
|
|
|
|
|
|
2007-09-07 03:46:22 +02:00
|
|
|
} else if (strcmp(type, "RCMOS") == 0) {
|
|
|
|
|
obj = new vvp_fun_rcmos();
|
|
|
|
|
|
2005-06-12 17:13:37 +02:00
|
|
|
} else if (strcmp(type, "RNMOS") == 0) {
|
|
|
|
|
obj = new vvp_fun_rpmos(true);
|
|
|
|
|
|
|
|
|
|
} else if (strcmp(type, "RPMOS") == 0) {
|
|
|
|
|
obj = new vvp_fun_rpmos(false);
|
|
|
|
|
|
2001-11-06 04:07:21 +01:00
|
|
|
} else if (strcmp(type, "NOT") == 0) {
|
2005-09-19 23:45:09 +02:00
|
|
|
obj = new vvp_fun_not();
|
2001-12-14 07:03:17 +01:00
|
|
|
|
2001-11-06 04:07:21 +01:00
|
|
|
} else if (strcmp(type, "XNOR") == 0) {
|
2006-11-28 06:57:20 +01:00
|
|
|
obj = new vvp_fun_xor(width, true);
|
2001-11-06 04:07:21 +01:00
|
|
|
|
|
|
|
|
} else if (strcmp(type, "XOR") == 0) {
|
2006-11-28 06:57:20 +01:00
|
|
|
obj = new vvp_fun_xor(width, false);
|
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. */
|
2008-01-05 04:21:26 +01:00
|
|
|
if (strength_aware || (ostr0 == 6 && ostr1 == 6)) {
|
2005-04-13 08:34:20 +02:00
|
|
|
define_functor_symbol(label, net);
|
|
|
|
|
free(label);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-02 18:02:11 +02:00
|
|
|
vvp_net_t*net_drv = new vvp_net_t;
|
2006-01-02 06:32:06 +01:00
|
|
|
vvp_net_fun_t*obj_drv = new vvp_fun_drive(BIT4_X, ostr0, ostr1);
|
2005-04-13 08:34:20 +02:00
|
|
|
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
|
|
|
}
|