From 8dbe8b7771a747a412b5f4a13fcd3f2e4f5fb20c Mon Sep 17 00:00:00 2001 From: Stefan Frederik Date: Thu, 28 Oct 2021 10:36:23 +0200 Subject: [PATCH] simplified simdata struct --- src/hilight.c | 57 +++++++++++++++++++++++++++------------------------ src/netlist.c | 2 +- src/xinit.c | 4 ++-- src/xschem.h | 10 +++------ 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/hilight.c b/src/hilight.c index c1c22ca6..a98dd4c7 100644 --- a/src/hilight.c +++ b/src/hilight.c @@ -1127,7 +1127,7 @@ int eval_logic_expr(int inst, int output) char *str; int res = 0; - str = xctx->simdata.inst[inst].pin[output].function; + str = xctx->simdata[inst].pin[output].function; dbg(1, "eval_logic_expr(): inst=%d pin=%d function=%s\n", inst, output, str ? str : "NULL"); if(!str) return 2; /* no logic function defined, return LOGIC_X */ while(str[pos]) { @@ -1275,29 +1275,30 @@ int eval_logic_expr(int inst, int output) /* fast access to symbol "function#" and symbol pin "clock" and "goto" attributes * to minimize get_token_value() lookups in simulation loops */ + void create_simdata(void) { int i, j; const char *str; free_simdata(); - my_realloc(60, &xctx->simdata.inst, xctx->instances * sizeof(struct simdata_inst)); - xctx->simdata.ninst = xctx->instances; + my_realloc(60, &xctx->simdata, xctx->instances * sizeof(struct simdata)); + xctx->simdata_ninst = xctx->instances; for(i = 0; i < xctx->instances; i++) { xSymbol *symbol = xctx->inst[i].ptr + xctx->sym; int npin = symbol->rects[PINLAYER]; - xctx->simdata.inst[i].pin = NULL; - my_realloc(61, &xctx->simdata.inst[i].pin, npin * sizeof(struct simdata_pin)); - xctx->simdata.inst[i].npin = npin; + xctx->simdata[i].pin = NULL; + my_realloc(61, &xctx->simdata[i].pin, npin * sizeof(struct simdata_pin)); + xctx->simdata[i].npin = npin; for(j = 0; j < npin; j++) { char function[20]; - xctx->simdata.inst[i].pin[j].function=NULL; - xctx->simdata.inst[i].pin[j].go_to=NULL; + xctx->simdata[i].pin[j].function=NULL; + xctx->simdata[i].pin[j].go_to=NULL; my_snprintf(function, S(function), "function%d", j); - my_strdup(717, &xctx->simdata.inst[i].pin[j].function, get_tok_value(symbol->prop_ptr, function, 0)); - my_strdup(963, &xctx->simdata.inst[i].pin[j].go_to, + my_strdup(717, &xctx->simdata[i].pin[j].function, get_tok_value(symbol->prop_ptr, function, 0)); + my_strdup(963, &xctx->simdata[i].pin[j].go_to, get_tok_value(symbol->rect[PINLAYER][j].prop_ptr, "goto", 0)); str = get_tok_value(symbol->rect[PINLAYER][j].prop_ptr, "clock", 0); - xctx->simdata.inst[i].pin[j].clock = str[0] ? str[0] - '0' : -1; + xctx->simdata[i].pin[j].clock = str[0] ? str[0] - '0' : -1; } } } @@ -1306,20 +1307,21 @@ void free_simdata(void) { int i, j; - if(xctx->simdata.inst) { - for(i = 0; i < xctx->simdata.ninst; i++) { - int npin = xctx->simdata.inst[i].npin; + if(xctx->simdata) { + for(i = 0; i < xctx->simdata_ninst; i++) { /* can not use xctx->instances if a new sch is loaded */ + int npin = xctx->simdata[i].npin; for(j = 0; j < npin; j++) { - my_free(1219, &xctx->simdata.inst[i].pin[j].function); - my_free(1220, &xctx->simdata.inst[i].pin[j].go_to); + my_free(1219, &xctx->simdata[i].pin[j].function); + my_free(1220, &xctx->simdata[i].pin[j].go_to); } - my_free(1221, &xctx->simdata.inst[i].pin); + my_free(1221, &xctx->simdata[i].pin); } - my_free(1222, &xctx->simdata.inst); + my_free(1222, &xctx->simdata); } + xctx->simdata_ninst = 0; } -#define DELAYED_ASSIGN +#define DELAYED_ASSIGN /* fixes bidirectional devices (avoid infinite loops) */ void propagate_logic() { /* char *propagated_net=NULL; */ @@ -1335,20 +1337,21 @@ void propagate_logic() #endif prepare_netlist_structs(0); + if(!xctx->simdata) create_simdata(); while(1) { found=0; - for(i=0; isimdata.ninst; i++) { - npin = xctx->simdata.inst[i].npin; + for(i=0; iinstances; i++) { + npin = xctx->simdata[i].npin; #ifdef DELAYED_ASSIGN my_realloc(778, &newval_arr, npin * sizeof(int)); for(j=0; jsimdata.inst && xctx->simdata.inst[i].pin && xctx->simdata.inst[i].pin[j].go_to) { + if(xctx->simdata && xctx->simdata[i].pin && xctx->simdata[i].pin[j].go_to) { int n = 1; const char *propag; int clock_pin, clock_val, clock_oldval; - clock_pin = xctx->simdata.inst[i].pin[j].clock; + clock_pin = xctx->simdata[i].pin[j].clock; if(clock_pin != -1) { /* no bus_hilight_lookup --> no bus expansion */ entry = hilight_lookup(xctx->inst[i].node[j], 0, XLOOKUP); /* clock pin */ @@ -1370,15 +1373,15 @@ void propagate_logic() } } } - dbg(1, "propagate_logic(): inst=%d pin %d, goto=%s\n", i,j, xctx->simdata.inst[i].pin[j].go_to); + dbg(1, "propagate_logic(): inst=%d pin %d, goto=%s\n", i,j, xctx->simdata[i].pin[j].go_to); while(1) { - propag = find_nth(xctx->simdata.inst[i].pin[j].go_to, ',', n); + propag = find_nth(xctx->simdata[i].pin[j].go_to, ',', n); n++; if(!propag[0]) break; propagate = atoi(propag); if(propagate < 0 || propagate >= npin) { dbg(0, "Error: inst: %s, pin %d, goto set to %s <<%d>>\n", - xctx->inst[i].instname, j, xctx->simdata.inst[i].pin[j].go_to, propagate); + xctx->inst[i].instname, j, xctx->simdata[i].pin[j].go_to, propagate); continue; } if(!xctx->inst[i].node[propagate]) { @@ -1442,7 +1445,7 @@ void logic_set(int value, int num) tclsetvar("tclstop", "0"); prepare_netlist_structs(0); - if(!xctx->simdata.inst) create_simdata(); + if(!xctx->simdata) create_simdata(); rebuild_selected_array(); newval = value; if(!xctx->no_draw && !big) { diff --git a/src/netlist.c b/src/netlist.c index 7aca674d..559f94ee 100644 --- a/src/netlist.c +++ b/src/netlist.c @@ -652,7 +652,7 @@ void prepare_netlist_structs(int for_netlist) if (for_netlist>0 && xctx->prep_net_structs) return; else if (!for_netlist && xctx->prep_hi_structs) return; /* delete instance pins spatial hash, wires spatial hash, node_hash, wires and inst nodes.*/ - else delete_netlist_structs(); + delete_netlist_structs(); free_simdata(); /* invalidate simulation cache */ dbg(1, "prepare_netlist_structs(): extraction\n"); if(xctx->netlist_count == 0 ) startlevel = xctx->currsch; diff --git a/src/xinit.c b/src/xinit.c index 6534cfcd..8598e588 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -406,8 +406,8 @@ void alloc_xschem_data() xctx->maxsel = 0; xctx->prep_net_structs = 0; xctx->prep_hi_structs = 0; - xctx->simdata.inst = NULL; - xctx->simdata.ninst = 0; + xctx->simdata = NULL; + xctx->simdata_ninst = 0; xctx->prep_hash_inst = 0; xctx->prep_hash_wires = 0; xctx->modified = 0; diff --git a/src/xschem.h b/src/xschem.h index 592c3db1..edd18cce 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -495,16 +495,11 @@ struct simdata_pin { short clock; }; -struct simdata_inst { +struct simdata { struct simdata_pin *pin; int npin; }; -struct simdata { - struct simdata_inst *inst; - int ninst; - }; - typedef struct { xWire *wire; xText *text; @@ -564,7 +559,8 @@ typedef struct { int prep_hi_structs; int prep_hash_inst; int prep_hash_wires; - struct simdata simdata; + struct simdata *simdata; + int simdata_ninst; int modified; int semaphore; int get_tok_size;