Lazy processing of vvp_fun_part functor.

This commit is contained in:
steve 2005-09-20 00:51:53 +00:00
parent 2b07c7a685
commit ee22550047
3 changed files with 131 additions and 72 deletions

View File

@ -16,10 +16,10 @@
* 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: part.cc,v 1.8 2005/07/14 23:34:19 steve Exp $"
#ident "$Id: part.cc,v 1.9 2005/09/20 00:51:53 steve Exp $"
# include "compile.h"
# include "vvp_net.h"
# include "part.h"
# include <stdlib.h>
# include <limits.h>
#ifdef HAVE_MALLOC_H
@ -31,6 +31,7 @@
vvp_fun_part::vvp_fun_part(unsigned base, unsigned wid)
: base_(base), wid_(wid)
{
net_ = 0;
}
vvp_fun_part::~vvp_fun_part()
@ -41,16 +42,31 @@ void vvp_fun_part::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit)
{
assert(port.port() == 0);
vvp_vector4_t res(wid_);
if (val_ .eeq( bit ))
return;
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
if (idx + base_ < bit.size())
res.set_bit(idx, bit.value(base_+idx));
else
res.set_bit(idx, BIT4_X);
val_ = bit;
if (net_ == 0) {
net_ = port.ptr();
schedule_generic(this, 0, false);
}
}
vvp_send_vec4(port.ptr()->out, res);
void vvp_fun_part::run_run()
{
vvp_net_t*ptr = net_;
net_ = 0;
vvp_vector4_t res (wid_);
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
if (idx + base_ < val_.size())
res.set_bit(idx, val_.value(base_+idx));
else
res.set_bit(idx, BIT4_X);
}
vvp_send_vec4(ptr->out, res);
}
vvp_fun_part_pv::vvp_fun_part_pv(unsigned b, unsigned w, unsigned v)
@ -167,6 +183,9 @@ void compile_part_select_var(char*label, char*source, char*var,
/*
* $Log: part.cc,v $
* Revision 1.9 2005/09/20 00:51:53 steve
* Lazy processing of vvp_fun_part functor.
*
* Revision 1.8 2005/07/14 23:34:19 steve
* gcc4 compile errors.
*

99
vvp/part.h Normal file
View File

@ -0,0 +1,99 @@
#ifndef __part_H
#define __part_H
/*
* Copyright (c) 2005 Stephen Williams (steve@icarus.com)
*
* 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
*/
#ident "$Id: part.h,v 1.1 2005/09/20 00:51:53 steve Exp $"
# include "schedule.h"
/* vvp_fun_part
* This node takes a part select of the input vector. Input 0 is the
* vector to be selected from, and input 1 is the location where the
* select starts. Input 2, which is typically constant, is the width
* of the result.
*/
class vvp_fun_part : public vvp_net_fun_t, private vvp_gen_event_s {
public:
vvp_fun_part(unsigned base, unsigned wid);
~vvp_fun_part();
public:
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit);
private:
void run_run();
private:
unsigned base_;
unsigned wid_;
vvp_vector4_t val_;
vvp_net_t*net_;
};
/* vvp_fun_part_pv
* This node takes a vector input and turns it into the part select of
* a wider output network. It used the recv_vec4_pv methods of the
* destination nodes to propagate the part select.
*/
class vvp_fun_part_pv : public vvp_net_fun_t {
public:
vvp_fun_part_pv(unsigned base, unsigned wid, unsigned vec_wid);
~vvp_fun_part_pv();
public:
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit);
private:
unsigned base_;
unsigned wid_;
unsigned vwid_;
};
/*
* This part select is more flexible in that it takes the vector to
* part in port 0, and the base of the part in port 1. The width of
* the part to take out is fixed.
*/
class vvp_fun_part_var : public vvp_net_fun_t {
public:
explicit vvp_fun_part_var(unsigned wid);
~vvp_fun_part_var();
public:
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit);
private:
unsigned base_;
unsigned wid_;
vvp_vector4_t source_;
// Save the last output, for detecting change.
vvp_vector4_t ref_;
};
/*
* $Log: part.h,v $
* Revision 1.1 2005/09/20 00:51:53 steve
* Lazy processing of vvp_fun_part functor.
*
*/
#endif

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.45 2005/09/19 21:45:37 steve Exp $"
#ident "$Id: vvp_net.h,v 1.46 2005/09/20 00:51:53 steve Exp $"
# include "config.h"
# include <stddef.h>
@ -669,68 +669,6 @@ class vvp_fun_extend_signed : public vvp_net_fun_t {
unsigned width_;
};
/* vvp_fun_part
* This node takes a part select of the input vector. Input 0 is the
* vector to be selected from, and input 1 is the location where the
* select starts. Input 2, which is typically constant, is the width
* of the result.
*/
class vvp_fun_part : public vvp_net_fun_t {
public:
vvp_fun_part(unsigned base, unsigned wid);
~vvp_fun_part();
public:
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit);
private:
unsigned base_;
unsigned wid_;
};
/* vvp_fun_part_pv
* This node takes a vector input and turns it into the part select of
* a wider output network. It used the recv_vec4_pv methods of the
* destination nodes to propagate the part select.
*/
class vvp_fun_part_pv : public vvp_net_fun_t {
public:
vvp_fun_part_pv(unsigned base, unsigned wid, unsigned vec_wid);
~vvp_fun_part_pv();
public:
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit);
private:
unsigned base_;
unsigned wid_;
unsigned vwid_;
};
/*
* This part select is more flexible in that it takes the vector to
* part in port 0, and the base of the part in port 1. The width of
* the part to take out is fixed.
*/
class vvp_fun_part_var : public vvp_net_fun_t {
public:
explicit vvp_fun_part_var(unsigned wid);
~vvp_fun_part_var();
public:
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit);
private:
unsigned base_;
unsigned wid_;
vvp_vector4_t source_;
// Save the last output, for detecting change.
vvp_vector4_t ref_;
};
/* vvp_fun_signal
* This node is the place holder in a vvp network for signals,
* including nets of various sort. The output from a signal follows
@ -999,6 +937,9 @@ inline void vvp_send_vec4_pv(vvp_net_ptr_t ptr, const vvp_vector4_t&val,
/*
* $Log: vvp_net.h,v $
* Revision 1.46 2005/09/20 00:51:53 steve
* Lazy processing of vvp_fun_part functor.
*
* Revision 1.45 2005/09/19 21:45:37 steve
* Spelling patches from Larry.
*