From 82bccd335d6fdb0aa0c3d79f248e08b97ccbe7f9 Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 8 Aug 2001 01:05:06 +0000 Subject: [PATCH] Initial implementation of vvp_fvectors. (Stephan Boettcher) --- vvp/Makefile.in | 4 +- vvp/compile.cc | 148 +++++++++++++++++++++++--------------------- vvp/functor.cc | 13 ++-- vvp/functor.h | 34 +++++++--- vvp/fvectors.cc | 84 +++++++++++++++++++++++++ vvp/pointers.h | 11 +++- vvp/vpi_callback.cc | 117 +++++++++++++++++++++------------- vvp/vpi_priv.h | 21 +++---- vvp/vpi_signal.cc | 61 ++++++++---------- 9 files changed, 317 insertions(+), 176 deletions(-) create mode 100644 vvp/fvectors.cc diff --git a/vvp/Makefile.in b/vvp/Makefile.in index 0fddd2cb5..06feb6cbb 100644 --- a/vvp/Makefile.in +++ b/vvp/Makefile.in @@ -16,7 +16,7 @@ # 59 Temple Place - Suite 330 # Boston, MA 02111-1307, USA # -#ident "$Id: Makefile.in,v 1.25 2001/07/21 04:34:25 steve Exp $" +#ident "$Id: Makefile.in,v 1.26 2001/08/08 01:05:06 steve Exp $" # # SHELL = /bin/sh @@ -64,7 +64,7 @@ vpi_priv.o vpi_scope.o vpi_signal.o vpi_tasks.o vpi_time.o vpi_memory.o \ vpi_vthr_vector.o vvp_vpi.o O = main.o parse.o parse_misc.o lexor.o arith.o bufif.o compile.o debug.o \ -functor.o resolv.o symbols.o codes.o vthread.o schedule.o \ +functor.o fvectors.o resolv.o symbols.o codes.o vthread.o schedule.o \ tables.o udp.o memory.o $V vvp: $O diff --git a/vvp/compile.cc b/vvp/compile.cc index c70aa4919..9ff8e922d 100644 --- a/vvp/compile.cc +++ b/vvp/compile.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: compile.cc,v 1.92 2001/07/30 03:53:01 steve Exp $" +#ident "$Id: compile.cc,v 1.93 2001/08/08 01:05:06 steve Exp $" #endif # include "arith.h" @@ -182,7 +182,7 @@ static void postpone_functor_input(vvp_ipoint_t ptr, char*lab, unsigned idx) struct resolv_list_s*res = (struct resolv_list_s*) calloc(1, sizeof(struct resolv_list_s)); - res->port = ptr; + res->port = ptr; res->source = lab; res->idx = idx; res->next = resolv_list; @@ -247,11 +247,17 @@ void compile_vpi_time_precision(long pre) * Add a functor to the symbol table */ -static void define_functor_symbol(char*label, vvp_ipoint_t fdx) +static void define_fvector_symbol(char*label, vvp_fvector_t v) { - symbol_value_t val; - val.num = fdx; - sym_set_value(sym_functors, label, val); + symbol_value_t val; + val.ptr = v; + sym_set_value(sym_functors, label, val); +} + +static void define_functor_symbol(char*label, vvp_ipoint_t ipt, unsigned wid) +{ + vvp_fvector_t v = vvp_fvector_continuous_new(wid, ipt); + define_fvector_symbol(label, v); } /* @@ -328,10 +334,10 @@ static void inputs_connect(vvp_ipoint_t fdx, unsigned argc, struct symb_s*argv) } symbol_value_t val = sym_get_value(sym_functors, argv[idx].text); - vvp_ipoint_t tmp = val.num; + vvp_fvector_t vec = (vvp_fvector_t) val.ptr; - if (tmp) { - tmp = ipoint_index(tmp, argv[idx].idx); + if (vec) { + vvp_ipoint_t tmp = vvp_fvector_get(vec, argv[idx].idx); functor_t fport = functor_index(tmp); iobj->port[ipoint_port(ifdx)] = fport->out; fport->out = ifdx; @@ -352,7 +358,7 @@ void compile_functor(char*label, char*type, unsigned argc, struct symb_s*argv) vvp_ipoint_t fdx = functor_allocate(1); functor_t obj = functor_index(fdx); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, 1); assert(argc <= 4); @@ -431,7 +437,7 @@ static void connect_arith_inputs(vvp_ipoint_t fdx, long wid, unsigned opcount = argc / wid; struct symb_s tmp_argv[4]; - for (unsigned idx = 0 ; idx < wid ; idx += 1) { + for (int idx = 0 ; idx < wid ; idx += 1) { vvp_ipoint_t ptr = ipoint_index(fdx,idx); functor_t obj = functor_index(ptr); @@ -459,7 +465,7 @@ void compile_arith_mult(char*label, long wid, { assert( wid > 0 ); - if (argc != 2*wid) { + if ((long)argc != 2*wid) { fprintf(stderr, "%s; .arith has wrong number of symbols\n", label); compile_errors += 1; free(label); @@ -467,7 +473,7 @@ void compile_arith_mult(char*label, long wid, } vvp_ipoint_t fdx = functor_allocate(wid); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, wid); vvp_arith_mult*arith = new vvp_arith_mult(fdx, wid); @@ -494,7 +500,7 @@ void compile_arith_sub(char*label, long wid, unsigned argc, struct symb_s*argv) } vvp_ipoint_t fdx = functor_allocate(wid); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, wid); vvp_arith_sub*arith = new vvp_arith_sub(fdx, wid); @@ -521,19 +527,18 @@ void compile_arith_sum(char*label, long wid, unsigned argc, struct symb_s*argv) } vvp_ipoint_t fdx = functor_allocate(wid); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, wid); vvp_arith_sum*arith = new vvp_arith_sum(fdx, wid); connect_arith_inputs(fdx, wid, arith, argc, argv); - } void compile_cmp_ge(char*label, long wid, unsigned argc, struct symb_s*argv) { assert( wid > 0 ); - if (argc != 2*wid) { + if ((long)argc != 2*wid) { fprintf(stderr, "%s; .cmp has wrong number of symbols\n", label); compile_errors += 1; free(label); @@ -541,19 +546,18 @@ void compile_cmp_ge(char*label, long wid, unsigned argc, struct symb_s*argv) } vvp_ipoint_t fdx = functor_allocate(wid); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, wid); vvp_cmp_ge*cmp = new vvp_cmp_ge(fdx, wid); connect_arith_inputs(fdx, wid, cmp, argc, argv); - } void compile_cmp_gt(char*label, long wid, unsigned argc, struct symb_s*argv) { assert( wid > 0 ); - if (argc != 2*wid) { + if ((long)argc != 2*wid) { fprintf(stderr, "%s; .cmp has wrong number of symbols\n", label); compile_errors += 1; free(label); @@ -561,22 +565,21 @@ void compile_cmp_gt(char*label, long wid, unsigned argc, struct symb_s*argv) } vvp_ipoint_t fdx = functor_allocate(wid); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, wid); vvp_cmp_gt*cmp = new vvp_cmp_gt(fdx, wid); connect_arith_inputs(fdx, wid, cmp, argc, argv); - } static void compile_shift_inputs(vvp_arith_*dev, vvp_ipoint_t fdx, long wid, unsigned argc, struct symb_s*argv) { - for (unsigned idx = 0 ; idx < wid ; idx += 1) { + for (int idx = 0 ; idx < wid ; idx += 1) { vvp_ipoint_t ptr = ipoint_index(fdx,idx); functor_t obj = functor_index(ptr); - if ((wid+idx) >= argc) + if ((wid+idx) >= (long)argc) obj->ival = 0x02; else obj->ival = 0x0a; @@ -593,7 +596,7 @@ static void compile_shift_inputs(vvp_arith_*dev, vvp_ipoint_t fdx, struct symb_s tmp_argv[3]; unsigned tmp_argc = 1; tmp_argv[0] = argv[idx]; - if ((wid+idx) < argc) { + if ((wid+idx) < (long)argc) { tmp_argv[1] = argv[wid+idx]; tmp_argc += 1; } @@ -611,14 +614,14 @@ void compile_shiftl(char*label, long wid, unsigned argc, struct symb_s*argv) { assert( wid > 0 ); - if (argc < (wid+1)) { + if ((long)argc < (wid+1)) { fprintf(stderr, "%s; .shift/l has too few symbols\n", label); compile_errors += 1; free(label); return; } - if (argc > (wid*2)) { + if ((long)argc > (wid*2)) { fprintf(stderr, "%s; .shift/l has too many symbols\n", label); compile_errors += 1; free(label); @@ -626,7 +629,7 @@ void compile_shiftl(char*label, long wid, unsigned argc, struct symb_s*argv) } vvp_ipoint_t fdx = functor_allocate(wid); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, wid); vvp_shiftl*dev = new vvp_shiftl(fdx, wid); @@ -639,14 +642,14 @@ void compile_shiftr(char*label, long wid, unsigned argc, struct symb_s*argv) { assert( wid > 0 ); - if (argc < (wid+1)) { + if ((long)argc < (wid+1)) { fprintf(stderr, "%s; .shift/r has too few symbols\n", label); compile_errors += 1; free(label); return; } - if (argc > (wid*2)) { + if ((long)argc > (wid*2)) { fprintf(stderr, "%s; .shift/r has too many symbols\n", label); compile_errors += 1; free(label); @@ -654,7 +657,7 @@ void compile_shiftr(char*label, long wid, unsigned argc, struct symb_s*argv) } vvp_ipoint_t fdx = functor_allocate(wid); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, wid); vvp_shiftr*dev = new vvp_shiftr(fdx, wid); @@ -668,7 +671,7 @@ void compile_resolver(char*label, char*type, unsigned argc, struct symb_s*argv) vvp_ipoint_t fdx = functor_allocate(1); functor_t obj = functor_index(fdx); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, 1); assert(argc <= 4); @@ -742,7 +745,7 @@ void compile_udp_functor(char*label, char*type, vvp_ipoint_t fdx = functor_allocate(nfun); functor_t obj = functor_index(fdx); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, nfun); free(label); for (unsigned idx = 0; idx < argc; idx += 4) @@ -794,8 +797,8 @@ void compile_memory_port(char *label, char *memid, free(memid); assert(mem); - // These is not a Verilog bit range. - // These is a data port bit range. + // This is not a Verilog bit range. + // This is a data port bit range. assert (lsb >= 0 && lsb<=msb); assert (msb < memory_data_width(mem)); unsigned nbits = msb-lsb+1; @@ -812,7 +815,7 @@ void compile_memory_port(char *label, char *memid, vvp_ipoint_t ix = functor_allocate(nfun); - define_functor_symbol(label, ix); + define_functor_symbol(label, ix, nfun); free(label); inputs_connect(ix, argc, argv); @@ -843,7 +846,7 @@ void compile_event(char*label, char*type, vvp_ipoint_t fdx = functor_allocate(1); functor_t obj = functor_index(fdx); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, 1); assert(argc <= 4); @@ -891,7 +894,7 @@ void compile_named_event(char*label, char*name) vvp_ipoint_t fdx = functor_allocate(1); functor_t obj = functor_index(fdx); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, 1); obj->ival = 0xaa; obj->oval = 2; @@ -916,7 +919,7 @@ void compile_event_or(char*label, unsigned argc, struct symb_s*argv) vvp_ipoint_t fdx = functor_allocate(1); functor_t obj = functor_index(fdx); - define_functor_symbol(label, fdx); + define_functor_symbol(label, fdx, 1); obj->ival = 0xaa; obj->oval = 2; @@ -937,17 +940,15 @@ void compile_event_or(char*label, unsigned argc, struct symb_s*argv) for (unsigned idx = 0 ; idx < argc ; idx += 1) { symbol_value_t val = sym_get_value(sym_functors, argv[idx].text); - vvp_ipoint_t tmp = val.num; - - assert(tmp); - - tmp = ipoint_index(tmp, argv[idx].idx); - + vvp_fvector_t vec = (vvp_fvector_t) val.ptr; + assert(vec); + vvp_ipoint_t tmp = vvp_fvector_get(vec, argv[idx].idx); + functor_t fport = functor_index(tmp); assert(fport); assert(fport->out == 0); fport->out = fdx; - + free(argv[idx].text); } @@ -988,7 +989,7 @@ void compile_code(char*label, char*mnem, comp_operands_t opa) assert(op); /* Build up the code from the information about the opcode and - the information from the comiler. */ + the information from the compiler. */ vvp_code_t code = codespace_index(ptr); code->opcode = op->opcode; @@ -1059,19 +1060,19 @@ void compile_code(char*label, char*mnem, comp_operands_t opa) } tmp = sym_get_value(sym_functors, opa->argv[idx].symb.text); - if (tmp.num == 0) { + if (tmp.ptr == 0) { struct cresolv_list_s*res = new struct cresolv_list_s; res->cp = code; res->lab = opa->argv[idx].symb.text; res->idx = opa->argv[idx].symb.idx; res->next = cresolv_flist; cresolv_flist = res; - break; + } else { + vvp_fvector_t v = (vvp_fvector_t) tmp.ptr; + code->iptr = + vvp_fvector_get(v, opa->argv[idx].symb.idx); + free(opa->argv[idx].symb.text); } - - code->iptr = ipoint_index(tmp.num, opa->argv[idx].symb.idx); - - free(opa->argv[idx].symb.text); break; case OA_NUMBER: @@ -1316,7 +1317,8 @@ void compile_variable(char*label, char*name, int msb, int lsb, unsigned wid = ((msb > lsb)? msb-lsb : lsb-msb) + 1; vvp_ipoint_t fdx = functor_allocate(wid); - define_functor_symbol(label, fdx); + vvp_fvector_t vec = vvp_fvector_continuous_new(wid, fdx); + define_fvector_symbol(label, vec); for (unsigned idx = 0 ; idx < wid ; idx += 1) { functor_t obj = functor_index(ipoint_index(fdx,idx)); @@ -1332,7 +1334,7 @@ void compile_variable(char*label, char*name, int msb, int lsb, } /* Make the vpiHandle for the reg. */ - vpiHandle obj = vpip_make_reg(name, msb, lsb, signed_flag, fdx); + vpiHandle obj = vpip_make_reg(name, msb, lsb, signed_flag, vec); compile_vpi_symbol(label, obj); vpip_attach_to_current_scope(obj); @@ -1345,7 +1347,8 @@ void compile_net(char*label, char*name, int msb, int lsb, bool signed_flag, unsigned wid = ((msb > lsb)? msb-lsb : lsb-msb) + 1; vvp_ipoint_t fdx = functor_allocate(wid); - define_functor_symbol(label, fdx); + vvp_fvector_t vec = vvp_fvector_continuous_new(wid, fdx); + define_fvector_symbol(label, vec); /* Allocate all the functors for the net itself. */ for (unsigned idx = 0 ; idx < wid ; idx += 1) { @@ -1415,10 +1418,10 @@ void compile_net(char*label, char*name, int msb, int lsb, bool signed_flag, } symbol_value_t val = sym_get_value(sym_functors, argv[idx].text); - if (val.num) { - - functor_t src = functor_index(ipoint_index(val.num, - argv[idx].idx)); + if (val.ptr) { + vvp_fvector_t vec = (vvp_fvector_t) val.ptr; + functor_t src = + functor_index(vvp_fvector_get(vec, argv[idx].idx)); obj->port[0] = src->out; src->out = ptr; @@ -1430,7 +1433,7 @@ void compile_net(char*label, char*name, int msb, int lsb, bool signed_flag, } /* Make the vpiHandle for the reg. */ - vpiHandle obj = vpip_make_net(name, msb, lsb, signed_flag, fdx); + vpiHandle obj = vpip_make_net(name, msb, lsb, signed_flag, vec); compile_vpi_symbol(label, obj); vpip_attach_to_current_scope(obj); @@ -1459,13 +1462,13 @@ void compile_cleanup(void) /* Try again to look up the symbol that was not defined the first time around. */ symbol_value_t val = sym_get_value(sym_functors, res->source); - vvp_ipoint_t tmp = val.num; + vvp_fvector_t vec = (vvp_fvector_t) val.ptr; - if (tmp != 0) { + if (vec != 0) { /* The symbol is defined, link the functor input to the resolved output. */ - tmp = ipoint_index(tmp, res->idx); + vvp_ipoint_t tmp = vvp_fvector_get(vec, res->idx); functor_t fport = functor_index(tmp); obj->port[idx] = fport->out; fport->out = res->port; @@ -1518,10 +1521,10 @@ void compile_cleanup(void) tmp_clist = res->next; symbol_value_t val = sym_get_value(sym_functors, res->lab); - vvp_ipoint_t tmp = val.num; + vvp_fvector_t vec = (vvp_fvector_t) val.ptr; - if (tmp != 0) { - res->cp->iptr = ipoint_index(tmp, res->idx); + if (vec != 0) { + res->cp->iptr = vvp_fvector_get(vec, res->idx); free(res->lab); } else { @@ -1556,17 +1559,24 @@ void compile_cleanup(void) * * debug_lookup_functor * Use a name to locate a functor address. This only gets the LSB - * of a vector, but it is enough to locate the object. + * of a vector, but it is enough to locate the object, or, is it? */ vvp_ipoint_t debug_lookup_functor(const char*name) { symbol_value_t val = sym_get_value(sym_functors, name); - return val.num; + vvp_fvector_t vec = (vvp_fvector_t) val.ptr; + if (!vec) + return 0; + return vvp_fvector_get(vec, 0); } /* * $Log: compile.cc,v $ + * Revision 1.93 2001/08/08 01:05:06 steve + * Initial implementation of vvp_fvectors. + * (Stephan Boettcher) + * * Revision 1.92 2001/07/30 03:53:01 steve * Initialize initial functor tables. * diff --git a/vvp/functor.cc b/vvp/functor.cc index 635b2b443..e74aae1c0 100644 --- a/vvp/functor.cc +++ b/vvp/functor.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: functor.cc,v 1.25 2001/07/30 03:53:01 steve Exp $" +#ident "$Id: functor.cc,v 1.26 2001/08/08 01:05:06 steve Exp $" #endif # include "functor.h" @@ -295,17 +295,12 @@ void functor_set(vvp_ipoint_t ptr, unsigned bit, unsigned str, bool push) if (!fp->obj) { ptr = fp->out; fp = functor_index(ptr); + assert(fp->mode == M42); } - assert(fp->mode == M42); fp->obj->set(ptr, fp, push); break; } - if (fp->callback) { - fp->callback = 0; - vpip_trip_functor_callbacks(ptr); - } - #if defined(WITH_DEBUG) if (fp->breakpoint) breakpoint(); @@ -375,6 +370,10 @@ const unsigned char ft_var[16] = { /* * $Log: functor.cc,v $ + * Revision 1.26 2001/08/08 01:05:06 steve + * Initial implementation of vvp_fvectors. + * (Stephan Boettcher) + * * Revision 1.25 2001/07/30 03:53:01 steve * Initialize initial functor tables. * diff --git a/vvp/functor.h b/vvp/functor.h index f33469987..69c851be2 100644 --- a/vvp/functor.h +++ b/vvp/functor.h @@ -19,12 +19,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: functor.h,v 1.29 2001/07/28 03:12:39 steve Exp $" +#ident "$Id: functor.h,v 1.30 2001/08/08 01:05:06 steve Exp $" #endif # include "pointers.h" - /* * * The major mode is selected by the mode parameter. @@ -140,9 +139,6 @@ struct functor_s { unsigned odrive1 : 3; /* Strength form of the output value. */ unsigned ostr : 8; - /* set this flag if there might be a waiting callback. - union member sig must be valid */ - unsigned callback : 1; #if defined(WITH_DEBUG) /* True if this functor triggers a breakpoint. */ unsigned breakpoint : 1; @@ -152,8 +148,6 @@ struct functor_s { unsigned mode : 2; union { unsigned char old_ival; // mode 3 - /* Which signal are we representing */ - struct __vpiSignal *sig; }; }; @@ -283,6 +277,28 @@ inline unsigned functor_oval(vvp_ipoint_t fptr) return fp->oval & 3; } +/* + * Vectors of functors + */ + +extern unsigned vvp_fvector_size(vvp_fvector_t v); +extern vvp_ipoint_t vvp_fvector_get(vvp_fvector_t v, unsigned i); +extern void vvp_fvector_set(vvp_fvector_t v, unsigned i, vvp_ipoint_t p); +extern vvp_fvector_t vvp_fvector_new(unsigned size); +extern vvp_fvector_t vvp_fvector_continuous_new(unsigned size, vvp_ipoint_t p); + +/* + * M42 functor type for callback events + */ + +struct vvp_cb_fobj_s: public vvp_fobj_s { + virtual void set(vvp_ipoint_t i, functor_t f, bool push); + struct __vpiCallback *cb_handle; + unsigned permanent : 1; +}; + +struct vvp_cb_fobj_s *vvp_fvector_make_callback(vvp_fvector_t vec, + const unsigned char *edge = 0); extern const unsigned char ft_AND[]; extern const unsigned char ft_BUF[]; @@ -300,6 +316,10 @@ extern const unsigned char ft_var[]; /* * $Log: functor.h,v $ + * Revision 1.30 2001/08/08 01:05:06 steve + * Initial implementation of vvp_fvectors. + * (Stephan Boettcher) + * * Revision 1.29 2001/07/28 03:12:39 steve * Support C and C special symbols. * diff --git a/vvp/fvectors.cc b/vvp/fvectors.cc new file mode 100644 index 000000000..353a75152 --- /dev/null +++ b/vvp/fvectors.cc @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2001 Stephan Boettcher + * + * 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 + */ +#if !defined(WINNT) +#ident "$Id: fvectors.cc,v 1.1 2001/08/08 01:05:06 steve Exp $" +#endif + +# include "functor.h" +# include +# include +# include + +struct vvp_fvector_s { + unsigned size; + union { + vvp_ipoint_t iptrs[1]; + struct { + unsigned size; + vvp_ipoint_t iptr; + } cont; + }; +}; + +unsigned vvp_fvector_size(vvp_fvector_t v) +{ + return v->size ? v->size : v->cont.size; +} + +vvp_ipoint_t vvp_fvector_get(vvp_fvector_t v, unsigned i) +{ + if (!v->size) + return ipoint_index(v->cont.iptr, i); + assert(i < v->size); + return v->iptrs[i]; +} + +void vvp_fvector_set(vvp_fvector_t v, unsigned i, vvp_ipoint_t p) +{ + if (v->size) { + assert(i < v->size); + v->iptrs[i] = p; + } else { + assert(i==0); + v->cont.iptr = p; + } +} + +vvp_fvector_t vvp_fvector_continuous_new(unsigned size, vvp_ipoint_t p) +{ + vvp_fvector_t v = (vvp_fvector_t) + malloc(sizeof(struct vvp_fvector_s)); + v->size = 0; + v->cont.size = size; + v->cont.iptr = p; + return v; +} + +vvp_fvector_t vvp_fvector_new(unsigned size) +{ + assert(size>0); + vvp_fvector_t v = (vvp_fvector_t) + malloc(sizeof(struct vvp_fvector_s) + + (size-1)*sizeof(vvp_ipoint_t)); + assert(v); + v->size = size; + memset(v->iptrs, 0, size*sizeof(vvp_ipoint_t)); + return v; +} + diff --git a/vvp/pointers.h b/vvp/pointers.h index 8c2c00aae..82cd4f42c 100644 --- a/vvp/pointers.h +++ b/vvp/pointers.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: pointers.h,v 1.4 2001/04/26 03:10:55 steve Exp $" +#ident "$Id: pointers.h,v 1.5 2001/08/08 01:05:06 steve Exp $" #endif /* @@ -100,8 +100,17 @@ typedef struct vvp_event_s *vvp_event_t; typedef struct vthread_s*vthread_t; + +/* vector of functors */ + +typedef struct vvp_fvector_s *vvp_fvector_t; + /* * $Log: pointers.h,v $ + * Revision 1.5 2001/08/08 01:05:06 steve + * Initial implementation of vvp_fvectors. + * (Stephan Boettcher) + * * Revision 1.4 2001/04/26 03:10:55 steve * Redo and simplify UDP behavior. * diff --git a/vvp/vpi_callback.cc b/vvp/vpi_callback.cc index 8160a379c..9c8a4a1c7 100644 --- a/vvp/vpi_callback.cc +++ b/vvp/vpi_callback.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: vpi_callback.cc,v 1.4 2001/07/13 03:02:34 steve Exp $" +#ident "$Id: vpi_callback.cc,v 1.5 2001/08/08 01:05:06 steve Exp $" #endif /* @@ -30,9 +30,10 @@ # include # include "vpi_priv.h" # include "schedule.h" +# include "functor.h" # include # include - +# include const struct __vpirt callback_rt = { vpiCallback, @@ -63,22 +64,65 @@ inline static struct __vpiCallback* new_vpi_callback() return obj; } -#if 1 - inline static void free_vpi_callback(struct __vpiCallback* obj) { obj->next = free_callback_root; free_callback_root = obj; } -#else +/* + * A signal get equipped with an M42 event functor to trigger + * callbacks. + */ -inline static void free_vpi_callback(struct __vpiCallback* obj) +struct vvp_cb_fobj_s *vvp_fvector_make_callback(vvp_fvector_t vec, + const unsigned char *edge) { - delete obj; -} + struct vvp_cb_fobj_s *obj = new vvp_cb_fobj_s; + unsigned nvec = vvp_fvector_size(vec); + unsigned nfun = (nvec+3)/4; + if (edge) + nfun ++ ; + else if (nfun > 1 && 4*nfun == nvec) + nfun ++; + + vvp_ipoint_t fdx = functor_allocate(nfun); + unsigned vi = 0; + for (unsigned i = 0; iival = 0xaa; + fu->oval = 2; + fu->odrive0 = 6; + fu->odrive0 = 6; + fu->out = 0; +#if defined(WITH_DEBUG) + fu->breakpoint = 0; #endif + if (i == nfun-1) { + fu->mode = M42; + fu->obj = obj; + } else { + fu->mode = edge ? 1 : 2; + fu->event = (struct vvp_event_s*) + malloc(sizeof (struct vvp_event_s)); + fu->event->threads = 0; + fu->event->ival = fu->ival; + fu->event->vvp_edge_tab = edge; + fu->out = ipoint_input_index(ipoint_index(fdx, nfun-1), 3); + } + for (unsigned j=0; j<4 && vi < nvec; j++, vi++) { + vvp_ipoint_t vipt = vvp_fvector_get(vec, vi); + functor_t vfu = functor_index(vipt); + fu->port[j] = vfu->out; + vfu->out = ipoint_input_index(ipt, j); + } + } + obj->permanent = 0; + obj->cb_handle = 0; + return obj; +} /* * A value change callback is tripped when a bit of a signal @@ -99,20 +143,13 @@ static struct __vpiCallback* make_value_change(p_cb_data data) || (data->obj->vpi_type->type_code == vpiNet)); struct __vpiSignal*sig = reinterpret_cast<__vpiSignal*>(data->obj); - /* Attach the callback to the signal who's value I'm waiting for. */ - obj->next = sig->callbacks; - sig->callbacks = obj; - - unsigned wid = (sig->msb >= sig->lsb) - ? sig->msb - sig->lsb + 1 - : sig->lsb - sig->msb + 1; - - /* Make sure the functors are tickled to trigger a callback. */ - for (unsigned idx = 0 ; idx < wid ; idx += 1) { - vvp_ipoint_t ptr = ipoint_index(sig->bits, idx); - functor_t fun = functor_index(ptr); - fun->callback |= 1; + if (!sig->callback) { + sig->callback = vvp_fvector_make_callback(sig->bits); + assert(sig->callback); } + + obj->next = sig->callback->cb_handle; + sig->callback->cb_handle = obj; return obj; } @@ -186,43 +223,33 @@ int vpi_remove_cb(vpiHandle ref) assert(ref->vpi_type); assert(ref->vpi_type->type_code == vpiCallback); - struct __vpiCallback*obj = reinterpret_cast<__vpiCallback*>(ref); - fprintf(stderr, "vpi error: vpi_remove_cb not supported\n"); return 0; } /* - * A functor callback trips when a functor is set by the functor_set - * function. This only happens when a propagated value passes - * through. This causes a callback only if the callback flag in the - * functor is set. - * - * When I get to this point, I locate the signal is associated with - * this functor and call all the callbacks on its callback list. The - * callbacks are deleted as I go. + * A callback event happened. */ -void vpip_trip_functor_callbacks(vvp_ipoint_t ptr) + +void vvp_cb_fobj_s::set(vvp_ipoint_t i, functor_t f, bool push) { - struct __vpiSignal*sig = vpip_sig_from_ptr(ptr); - assert(sig); - - struct __vpiCallback*callbacks = sig->callbacks; - sig->callbacks = 0; - - while (callbacks) { - struct __vpiCallback*cur = callbacks; - callbacks = cur->next; - + struct __vpiCallback *next = cb_handle; + if (!permanent) + cb_handle = 0; + while (next) { + struct __vpiCallback * cur = next; + next = cur->next; cur->cb_data.time->type = vpiSimTime; cur->cb_data.time->low = schedule_simtime(); cur->cb_data.time->high = 0; (cur->cb_data.cb_rtn)(&cur->cb_data); - free_vpi_callback(cur); + if (!permanent) + free_vpi_callback(cur); } } + void vpip_trip_monitor_callbacks(void) { } @@ -230,6 +257,10 @@ void vpip_trip_monitor_callbacks(void) /* * $Log: vpi_callback.cc,v $ + * Revision 1.5 2001/08/08 01:05:06 steve + * Initial implementation of vvp_fvectors. + * (Stephan Boettcher) + * * Revision 1.4 2001/07/13 03:02:34 steve * Rewire signal callback support for fast lookup. (Stephan Boettcher) * diff --git a/vvp/vpi_priv.h b/vvp/vpi_priv.h index 90f2d9703..6bfb4497c 100644 --- a/vvp/vpi_priv.h +++ b/vvp/vpi_priv.h @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: vpi_priv.h,v 1.21 2001/07/30 02:44:05 steve Exp $" +#ident "$Id: vpi_priv.h,v 1.22 2001/08/08 01:05:06 steve Exp $" #endif # include "vpi_user.h" @@ -108,17 +108,14 @@ struct __vpiSignal { /* Flags */ unsigned signed_flag : 1; /* The represented value is here. */ - vvp_ipoint_t bits; - /* Call these items on a callback event. */ - struct __vpiCallback*callbacks; - /* Keep in a binary tree, ordered by bits member. */ - struct __vpiSignal* by_bits[2]; + vvp_fvector_t bits; + /* This is the callback event finctor object */ + struct vvp_cb_fobj_s *callback; }; extern vpiHandle vpip_make_reg(char*name, int msb, int lsb, bool signed_flag, - vvp_ipoint_t base); + vvp_fvector_t vec); extern vpiHandle vpip_make_net(char*name, int msb, int lsb, bool signed_flag, - vvp_ipoint_t base); -extern struct __vpiSignal*vpip_sig_from_ptr(vvp_ipoint_t ptr); + vvp_fvector_t vec); /* * Callback handles are created when the VPI function registers a @@ -138,8 +135,6 @@ struct __vpiCallback { struct __vpiCallback*next; }; -extern void vpip_trip_functor_callbacks(vvp_ipoint_t ptr); - /* * Memory is an array of bits that is accessible in N-bit chunks, with * N being the width of a word. The memory word handle just points @@ -263,6 +258,10 @@ extern void vpip_set_time_precision(int pres); /* * $Log: vpi_priv.h,v $ + * Revision 1.22 2001/08/08 01:05:06 steve + * Initial implementation of vvp_fvectors. + * (Stephan Boettcher) + * * Revision 1.21 2001/07/30 02:44:05 steve * Cleanup defines and types for mingw compile. * diff --git a/vvp/vpi_signal.cc b/vvp/vpi_signal.cc index 066aefaeb..53e87fe53 100644 --- a/vvp/vpi_signal.cc +++ b/vvp/vpi_signal.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #if !defined(WINNT) -#ident "$Id: vpi_signal.cc,v 1.21 2001/07/24 01:34:56 steve Exp $" +#ident "$Id: vpi_signal.cc,v 1.22 2001/08/08 01:05:06 steve Exp $" #endif /* @@ -109,7 +109,7 @@ static void signal_vpiDecStrVal(struct __vpiSignal*rfp, s_vpi_value*vp) unsigned count_x = 0, count_z = 0; for (unsigned idx = 0 ; idx < wid ; idx += 1) { - vvp_ipoint_t fptr = ipoint_index(rfp->bits, wid-idx-1); + vvp_ipoint_t fptr = vvp_fvector_get(rfp->bits, wid-idx-1); val *= 2; switch (functor_oval(fptr)) { case 0: @@ -183,7 +183,7 @@ static void signal_vpiStringVal(struct __vpiSignal*rfp, s_vpi_value*vp) unsigned bdx; for (bdx = 8 ; bdx > 0 ; bdx -= 1) { - vvp_ipoint_t fptr = ipoint_index(rfp->bits, idx-8+bdx-1); + vvp_ipoint_t fptr = vvp_fvector_get(rfp->bits, idx-8+bdx-1); tmp <<= 1; switch (functor_oval(fptr)) { case 0: @@ -222,7 +222,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp) assert(wid <= 8 * sizeof vp->value.integer); vp->value.integer = 0; for (unsigned idx = 0 ; idx < wid ; idx += 1) { - vvp_ipoint_t fptr = ipoint_index(rfp->bits, idx); + vvp_ipoint_t fptr = vvp_fvector_get(rfp->bits, idx); switch (functor_oval(fptr)) { case 0: break; @@ -239,7 +239,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp) case vpiBinStrVal: for (unsigned idx = 0 ; idx < wid ; idx += 1) { - vvp_ipoint_t fptr = ipoint_index(rfp->bits, idx); + vvp_ipoint_t fptr = vvp_fvector_get(rfp->bits, idx); buf[wid-idx-1] = "01xz"[functor_oval(fptr)]; } buf[wid] = 0; @@ -252,7 +252,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp) buf[hwid] = 0; hval = 0; for (unsigned idx = 0 ; idx < wid ; idx += 1) { - vvp_ipoint_t fptr = ipoint_index(rfp->bits, idx); + vvp_ipoint_t fptr = vvp_fvector_get(rfp->bits, idx); hval = hval | (functor_oval(fptr) << 2*(idx % 4)); if (idx%4 == 3) { @@ -287,7 +287,7 @@ static void signal_get_value(vpiHandle ref, s_vpi_value*vp) buf[hwid] = 0; hval = 0; for (unsigned idx = 0 ; idx < wid ; idx += 1) { - vvp_ipoint_t fptr = ipoint_index(rfp->bits, idx); + vvp_ipoint_t fptr = vvp_fvector_get(rfp->bits, idx); hval = hval | (functor_oval(fptr) << 2*(idx % 3)); if (idx%3 == 2) { @@ -369,7 +369,7 @@ static vpiHandle signal_put_value(vpiHandle ref, s_vpi_value*vp, long val = vp->value.integer; for (unsigned idx = 0 ; idx < wid ; idx += 1) { - functor_set(ipoint_index(rfp->bits,idx), val&1, + functor_set(vvp_fvector_get(rfp->bits,idx), val&1, (val&1)? St1 : St0, true); val >>= 1; } @@ -379,16 +379,16 @@ static vpiHandle signal_put_value(vpiHandle ref, s_vpi_value*vp, case vpiScalarVal: switch (vp->value.scalar) { case vpi0: - functor_set(rfp->bits, 0, St0, true); + functor_set(vvp_fvector_get(rfp->bits,0), 0, St0, true); break; case vpi1: - functor_set(rfp->bits, 1, St1, true); + functor_set(vvp_fvector_get(rfp->bits,0), 1, St1, true); break; case vpiX: - functor_set(rfp->bits, 2, StX, true); + functor_set(vvp_fvector_get(rfp->bits,0), 2, StX, true); break; case vpiZ: - functor_set(rfp->bits, 3, HiZ, true); + functor_set(vvp_fvector_get(rfp->bits,0), 3, HiZ, true); break; default: assert(0); @@ -404,19 +404,19 @@ static vpiHandle signal_put_value(vpiHandle ref, s_vpi_value*vp, int bit = (aval&1) | ((bval<<1)&2); switch (bit) { case 0: /* zero */ - functor_set(ipoint_index(rfp->bits,idx), + functor_set(vvp_fvector_get(rfp->bits,idx), 0, St0, true); break; case 1: /* one */ - functor_set(ipoint_index(rfp->bits,idx), + functor_set(vvp_fvector_get(rfp->bits,idx), 1, St1, true); break; case 2: /* z */ - functor_set(ipoint_index(rfp->bits,idx), + functor_set(vvp_fvector_get(rfp->bits,idx), 3, HiZ, true); break; case 3: /* x */ - functor_set(ipoint_index(rfp->bits,idx), + functor_set(vvp_fvector_get(rfp->bits,idx), 2, StX, true); break; } @@ -434,12 +434,6 @@ static vpiHandle signal_put_value(vpiHandle ref, s_vpi_value*vp, return ref; } -struct __vpiSignal* vpip_sig_from_ptr(vvp_ipoint_t ptr) -{ - functor_t fu = functor_index(ptr); - return fu->sig; -} - static const struct __vpirt vpip_reg_rt = { vpiReg, signal_get, @@ -464,9 +458,9 @@ static const struct __vpirt vpip_net_rt = { * Construct a vpiReg object. It's like a net, except for the type. */ vpiHandle vpip_make_reg(char*name, int msb, int lsb, bool signed_flag, - vvp_ipoint_t base) + vvp_fvector_t vec) { - vpiHandle obj = vpip_make_net(name, msb,lsb, signed_flag, base); + vpiHandle obj = vpip_make_net(name, msb,lsb, signed_flag, vec); obj->vpi_type = &vpip_reg_rt; return obj; } @@ -476,7 +470,7 @@ vpiHandle vpip_make_reg(char*name, int msb, int lsb, bool signed_flag, * and point to the specified functor for the lsb. */ vpiHandle vpip_make_net(char*name, int msb, int lsb, bool signed_flag, - vvp_ipoint_t base) + vvp_fvector_t vec) { struct __vpiSignal*obj = (struct __vpiSignal*) malloc(sizeof(struct __vpiSignal)); @@ -485,26 +479,21 @@ vpiHandle vpip_make_net(char*name, int msb, int lsb, bool signed_flag, obj->msb = msb; obj->lsb = lsb; obj->signed_flag = signed_flag? 1 : 0; - obj->bits = base; - obj->callbacks = 0; + obj->bits = vec; + obj->callback = 0; obj->scope = vpip_peek_current_scope(); - unsigned wid = (obj->msb > obj->lsb) - ? obj->msb - obj->lsb + 1 - : obj->lsb - obj->msb + 1; - for (unsigned i=0; ibits, i); - functor_t fu = functor_index(ii); - fu->sig = obj; - } - return &obj->base; } /* * $Log: vpi_signal.cc,v $ + * Revision 1.22 2001/08/08 01:05:06 steve + * Initial implementation of vvp_fvectors. + * (Stephan Boettcher) + * * Revision 1.21 2001/07/24 01:34:56 steve * Implement string value for signals. *