VIS
|
00001 00017 #include "truesimInt.h" 00018 00019 /*---------------------------------------------------------------------------*/ 00020 /* Constant declarations */ 00021 /*---------------------------------------------------------------------------*/ 00022 00023 00024 /*---------------------------------------------------------------------------*/ 00025 /* Type declarations */ 00026 /*---------------------------------------------------------------------------*/ 00027 00028 00029 /*---------------------------------------------------------------------------*/ 00030 /* Structure declarations */ 00031 /*---------------------------------------------------------------------------*/ 00032 00033 00034 /*---------------------------------------------------------------------------*/ 00035 /* Variable declarations */ 00036 /*---------------------------------------------------------------------------*/ 00037 00038 /* Global variables used in truesim package. */ 00039 extern int truesimVerbose; 00040 extern int truesimRptHeader; 00041 00044 /*---------------------------------------------------------------------------*/ 00045 /* Static function prototypes */ 00046 /*---------------------------------------------------------------------------*/ 00047 00048 static void SetInputValues(array_t *inputArray, char *vector, st_table *nodeToSimTable); 00049 00053 /*---------------------------------------------------------------------------*/ 00054 /* Definition of exported functions */ 00055 /*---------------------------------------------------------------------------*/ 00069 int 00070 Truesim_ZeroDelayPatternSimulate( 00071 Ntk_Network_t *network, 00072 array_t *inputArray, 00073 array_t *patternArray) 00074 { 00075 graph_t *partition; 00076 TrueSim_t *sim; 00077 st_table *nodeToSimTable; 00078 Ntk_Node_t *node; 00079 array_t *depthArray; 00080 bdd_manager *ddManager = Ntk_NetworkReadMddManager(network); 00081 lsGen gen; 00082 char prev,next; 00083 long numVectors = array_n(patternArray); 00084 int maxDepth; 00085 int i,j,k; 00086 00087 nodeToSimTable = TruesimNetworkReadSimTable(network); 00088 if (nodeToSimTable == NIL(st_table)) { 00089 (void) fprintf(vis_stderr, 00090 "** truesim error: Simulation structures not initialized\n"); 00091 (void) fprintf(vis_stderr, 00092 "** truesim error: Call Truesim_InitializeSimulation before "); 00093 (void) fprintf(vis_stderr,"calling this function.\n"); 00094 return -1; 00095 } 00096 00097 depthArray = TruesimNetworkReadDepthArray(network); 00098 maxDepth = array_n(depthArray); 00099 00100 partition = Part_NetworkReadPartition(network); 00101 00102 /* Initialize the prob and switching fields of the simulation structure for 00103 each node in the network. */ 00104 TruesimInitializeActivityFields(network,nodeToSimTable); 00105 00106 /* Warm up simulation */ 00107 TruesimWarmUpPatternSimulate(network,inputArray, 00108 array_fetch(char *,patternArray,0)); 00109 00110 for (i = 1; i < numVectors; i++) { 00111 char *vector; 00112 vector = array_fetch(char *,patternArray,i); 00113 /* Set the input nodes to the input pattern vector. Do not update 00114 the switching field of the sim structure if it is the first 00115 vector */ 00116 SetInputValues(inputArray,vector,nodeToSimTable); 00117 for (j = 1; j < maxDepth; j++) { 00118 array_t *nodeList; 00119 00120 nodeList = array_fetch(array_t *,depthArray,j); 00121 arrayForEachItem(Ntk_Node_t *,nodeList,k,node) { 00122 TrueSim_t *sim; 00123 00124 st_lookup(nodeToSimTable,(char *)node,&sim); 00125 next = TruesimEvaluateNode(node,partition,ddManager, 00126 nodeToSimTable); 00127 if (i != 0) { 00128 prev = sim->value; 00129 if (prev != next) 00130 (sim->switching)++; 00131 } 00132 sim->value = next; 00133 if (next == '1') 00134 (sim->prob)++; 00135 } 00136 } 00137 if (truesimVerbose) { 00138 if (truesimRptHeader != -1) { 00139 if (i % truesimRptHeader == 0) 00140 TruesimPrintNameHeader(network); 00141 } 00142 TruesimPrintNetworkNodeLogicState(network); 00143 } 00144 } 00145 00146 /* Update the statistics for each node */ 00147 Ntk_NetworkForEachNode(network,gen,node) { 00148 if (!st_lookup(nodeToSimTable,(char *)node,&sim)) { 00149 (void) fprintf(vis_stderr, 00150 "** truesim fatal: In Truesim_ZeroDelayPatternSimulate\n"); 00151 assert(0); 00152 } 00153 sim->switching /= ((float) array_n(patternArray)); 00154 sim->prob /= ((float) array_n(patternArray)); 00155 } 00156 00157 return 1; 00158 00159 } /* End of Truesim_ZeroDelayPatternSimulate */ 00160 00161 /*---------------------------------------------------------------------------*/ 00162 /* Definition of internal functions */ 00163 /*---------------------------------------------------------------------------*/ 00164 00175 void 00176 TruesimWarmUpPatternSimulate( 00177 Ntk_Network_t *network, 00178 array_t *inputArray, 00179 char *vector) 00180 { 00181 graph_t *partition; 00182 st_table *nodeToSimTable; 00183 array_t *depthArray; 00184 Ntk_Node_t *node; 00185 bdd_manager *ddManager = Ntk_NetworkReadMddManager(network); 00186 long maxDepth; 00187 int j,k; 00188 00189 nodeToSimTable = TruesimNetworkReadSimTable(network); 00190 00191 depthArray = TruesimNetworkReadDepthArray(network); 00192 maxDepth = array_n(depthArray); 00193 00194 partition = Part_NetworkReadPartition(network); 00195 /* Set the input nodes to the input pattern vector. Do not update 00196 the switching field of the sim structure if it is the first 00197 vector */ 00198 SetInputValues(inputArray,vector,nodeToSimTable); 00199 for (j = 1; j < maxDepth; j++) { 00200 array_t *nodeList; 00201 00202 nodeList = array_fetch(array_t *,depthArray,j); 00203 arrayForEachItem(Ntk_Node_t *,nodeList,k,node) { 00204 TrueSim_t *sim; 00205 00206 st_lookup(nodeToSimTable,(char *)node,&sim); 00207 sim->value = TruesimEvaluateNode(node,partition,ddManager, 00208 nodeToSimTable); 00209 } 00210 } 00211 00212 /* Print network status */ 00213 if (truesimVerbose) { 00214 TruesimPrintNameHeader(network); 00215 TruesimPrintNetworkNodeLogicState(network); 00216 } 00217 00218 return ; 00219 00220 } /* End of TruesimWarmUpPatternSimulate */ 00221 00222 /*---------------------------------------------------------------------------*/ 00223 /* Definition of static functions */ 00224 /*---------------------------------------------------------------------------*/ 00236 static void 00237 SetInputValues( 00238 array_t *inputArray, 00239 char *vector, 00240 st_table *nodeToSimTable) 00241 { 00242 Ntk_Node_t *node; 00243 TrueSim_t *sim; 00244 int i; 00245 char prev; 00246 00247 arrayForEachItem(Ntk_Node_t *,inputArray,i,node) { 00248 st_lookup(nodeToSimTable,(char *)node,&sim); 00249 prev = sim->value; 00250 if (prev != vector[i]) 00251 (sim->switching)++; 00252 sim->value = vector[i]; 00253 if (vector[i] == '1') 00254 (sim->prob)++; 00255 } 00256 } /* End of SetInputValues */ 00257