From d51503ffd850966272ef428fed95d8b70e49955e Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 29 Jan 2005 17:52:06 +0000 Subject: [PATCH] move AND to buitin instead of table. --- vvp/draw_tt.c | 8 ++++++-- vvp/logic.cc | 38 ++++++++++++++++++++++++++++++++++++-- vvp/logic.h | 21 +++++++++++++++++++-- vvp/vvp_net.cc | 48 +++++++++++++++++++++++++++++++++++++++++++++++- vvp/vvp_net.h | 10 +++++++++- 5 files changed, 117 insertions(+), 8 deletions(-) diff --git a/vvp/draw_tt.c b/vvp/draw_tt.c index 9294dd03f..955e689e0 100644 --- a/vvp/draw_tt.c +++ b/vvp/draw_tt.c @@ -17,11 +17,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: draw_tt.c,v 1.17 2004/12/31 05:57:25 steve Exp $" +#ident "$Id: draw_tt.c,v 1.18 2005/01/29 17:52:06 steve Exp $" #endif # include +#if 0 static void draw_AND(void) { unsigned i0, i1, i2, i3; @@ -55,6 +56,7 @@ static void draw_AND(void) printf("};\n"); } +#endif static void draw_NAND(void) { @@ -737,7 +739,6 @@ static void draw_oct_table() main() { printf("# include \"logic.h\"\n"); - draw_AND(); draw_BUFIF0(); draw_BUFIF1(); draw_PMOS(); @@ -760,6 +761,9 @@ main() /* * $Log: draw_tt.c,v $ + * Revision 1.18 2005/01/29 17:52:06 steve + * move AND to buitin instead of table. + * * Revision 1.17 2004/12/31 05:57:25 steve * No need to draw BUF or BUFZ tables. * diff --git a/vvp/logic.cc b/vvp/logic.cc index dddafd1d0..f3e1ba31c 100644 --- a/vvp/logic.cc +++ b/vvp/logic.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: logic.cc,v 1.16 2004/12/31 05:56:36 steve Exp $" +#ident "$Id: logic.cc,v 1.17 2005/01/29 17:52:06 steve Exp $" #endif # include "logic.h" @@ -78,6 +78,37 @@ void table_functor_s::recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t val) vvp_send_vec4(ptr.ptr()->out, result); } +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); +} + vvp_fun_buf::vvp_fun_buf() { count_functors_table += 1; @@ -133,7 +164,7 @@ void compile_functor(char*label, char*type, obj = new table_functor_s(ft_OR); } else if (strcmp(type, "AND") == 0) { - obj = new table_functor_s(ft_AND); + obj = new vvp_fun_and(); } else if (strcmp(type, "BUF") == 0) { obj = new vvp_fun_buf(); @@ -213,6 +244,9 @@ void compile_functor(char*label, char*type, /* * $Log: logic.cc,v $ + * Revision 1.17 2005/01/29 17:52:06 steve + * move AND to buitin instead of table. + * * Revision 1.16 2004/12/31 05:56:36 steve * Add specific BUFZ functor. * diff --git a/vvp/logic.h b/vvp/logic.h index d185c50d9..09a9ad155 100644 --- a/vvp/logic.h +++ b/vvp/logic.h @@ -1,7 +1,7 @@ #ifndef __logic_H #define __logic_H /* - * Copyright (c) 2000-2004 Stephen Williams (steve@icarus.com) + * Copyright (c) 2000-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 @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #ifdef HAVE_CVS_IDENT -#ident "$Id: logic.h,v 1.10 2004/12/31 05:56:36 steve Exp $" +#ident "$Id: logic.h,v 1.11 2005/01/29 17:52:06 steve Exp $" #endif # include "vvp_net.h" @@ -45,6 +45,20 @@ class table_functor_s: public vvp_net_fun_t { vvp_vector4_t input_[4]; }; +class vvp_fun_boolean_ : public vvp_net_fun_t { + + protected: + vvp_vector4_t input_[4]; +}; + +class vvp_fun_and : public vvp_fun_boolean_ { + + public: + explicit vvp_fun_and(); + ~vvp_fun_and(); + void recv_vec4(vvp_net_ptr_t p, vvp_vector4_t bit); +}; + /* * The buffer functor is a very primitive functor that takes the input * from port-0 (and only port-0) and retransmits it as a vvp_vector4_t. @@ -101,6 +115,9 @@ extern const unsigned char ft_var[]; /* * $Log: logic.h,v $ + * Revision 1.11 2005/01/29 17:52:06 steve + * move AND to buitin instead of table. + * * Revision 1.10 2004/12/31 05:56:36 steve * Add specific BUFZ functor. * diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index 039b5abeb..27a530219 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -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.9 2005/01/28 05:34:25 steve Exp $" +#ident "$Id: vvp_net.cc,v 1.10 2005/01/29 17:52:06 steve Exp $" # include "vvp_net.h" # include @@ -59,6 +59,19 @@ bool bit4_is_xz(vvp_bit4_t a) return false; } +vvp_bit4_t operator & (vvp_bit4_t a, vvp_bit4_t b) +{ + if (a == BIT4_0) + return BIT4_0; + if (b == BIT4_0) + return BIT4_0; + if (bit4_is_xz(a)) + return BIT4_X; + if (bit4_is_xz(b)) + return BIT4_X; + return BIT4_1; +} + void vvp_send_vec4(vvp_net_ptr_t ptr, vvp_vector4_t val) { while (struct vvp_net_t*cur = ptr.ptr()) { @@ -224,6 +237,36 @@ void vvp_vector4_t::set_bit(unsigned idx, vvp_bit4_t val) } } +char* vvp_vector4_t::as_string(char*buf, size_t buf_len) +{ + char*res = buf; + *buf++ = 'C'; + *buf++ = '4'; + *buf++ = '<'; + buf_len -= 3; + + for (unsigned idx = 0 ; idx < size() && buf_len >= 2 ; idx += 1) { + switch (value(size()-idx-1)) { + case BIT4_0: + *buf++ = '0'; + break; + case BIT4_1: + *buf++ = '1'; + break; + case BIT4_X: + *buf++ = 'x'; + break; + case BIT4_Z: + *buf++ = 'z'; + } + buf_len -= 1; + } + + *buf++ = '>'; + *buf++ = 0; + return res; +} + bool vector4_to_value(const vvp_vector4_t&vec, unsigned long&val) { unsigned long res = 0; @@ -809,6 +852,9 @@ vvp_bit4_t compare_gtge_signed(const vvp_vector4_t&a, /* * $Log: vvp_net.cc,v $ + * Revision 1.10 2005/01/29 17:52:06 steve + * move AND to buitin instead of table. + * * Revision 1.9 2005/01/28 05:34:25 steve * Add vector4 implementation of .arith/mult. * diff --git a/vvp/vvp_net.h b/vvp/vvp_net.h index 971e5a385..a0773e166 100644 --- a/vvp/vvp_net.h +++ b/vvp/vvp_net.h @@ -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.9 2005/01/28 05:34:25 steve Exp $" +#ident "$Id: vvp_net.h,v 1.10 2005/01/29 17:52:06 steve Exp $" # include @@ -52,6 +52,8 @@ enum vvp_bit4_t { extern vvp_bit4_t add_with_carry(vvp_bit4_t a, vvp_bit4_t b, vvp_bit4_t&c); /* Return TRUE if the bit is BIT4_X or BIT4_Z */ extern bool bit4_is_xz(vvp_bit4_t a); + /* Some common boolean operators */ +extern vvp_bit4_t operator & (vvp_bit4_t a, vvp_bit4_t b); /* * This class represents scaler values collected into vectors. The @@ -73,6 +75,9 @@ class vvp_vector4_t { vvp_bit4_t value(unsigned idx) const; void set_bit(unsigned idx, vvp_bit4_t val); + // Display the value into the buf as a string. + char*as_string(char*buf, size_t buf_len); + vvp_vector4_t(const vvp_vector4_t&that); vvp_vector4_t& operator= (const vvp_vector4_t&that); @@ -502,6 +507,9 @@ class vvp_fun_signal : public vvp_net_fun_t { /* * $Log: vvp_net.h,v $ + * Revision 1.10 2005/01/29 17:52:06 steve + * move AND to buitin instead of table. + * * Revision 1.9 2005/01/28 05:34:25 steve * Add vector4 implementation of .arith/mult. *