[14] | 1 | /**CFile*********************************************************************** |
---|
| 2 | |
---|
| 3 | FileName [puresatUtil.c] |
---|
| 4 | |
---|
| 5 | PackageName [puresat] |
---|
| 6 | |
---|
| 7 | Synopsis [Abstraction refinement for large scale invariant checking.] |
---|
| 8 | |
---|
| 9 | Description [This file contains the functions to check invariant properties |
---|
| 10 | by the PureSAT abstraction refinement algorithm, which is entirely based on |
---|
| 11 | SAT solver, the input of which could be either CNF or AIG. It has several |
---|
| 12 | parts: |
---|
| 13 | |
---|
| 14 | * Localization-reduction base Abstraction |
---|
| 15 | * K-induction or interpolation to prove the truth of a property |
---|
| 16 | * Bounded Model Checking to find bugs |
---|
| 17 | * Incremental concretization based methods to verify abstract bugs |
---|
| 18 | * Incremental SAT solver to improve efficiency |
---|
| 19 | * UNSAT proof based method to obtain refinement |
---|
| 20 | * AROSAT to bring in only necessary latches into unsat proofs |
---|
| 21 | * Bridge abstraction to get compact coarse refinement |
---|
| 22 | * Refinement minization to guarrantee minimal refinements |
---|
| 23 | * Unsat proof-based refinement minimization to eliminate multiple candidate |
---|
| 24 | by on SAT test |
---|
| 25 | * Refinement prediction to decrease the number of refinement iterations |
---|
| 26 | * Dynamic switching to redistribute computional resources to improve |
---|
| 27 | efficiency |
---|
| 28 | |
---|
| 29 | For more information, please check the BMC'03, ICCAD'04, STTT'05 and TACAS'05 |
---|
| 30 | paper of Li et al., "A satisfiability-based appraoch to abstraction |
---|
| 31 | refinement in model checking", " Abstraction in symbolic model checking |
---|
| 32 | using satisfiability as the only decision procedure", "Efficient computation |
---|
| 33 | of small abstraction refinements", and "Efficient abstraction refinement in |
---|
| 34 | interpolation-based unbounded model checking"] |
---|
| 35 | |
---|
| 36 | Author [Bing Li] |
---|
| 37 | |
---|
| 38 | Copyright [Copyright (c) 2004 The Regents of the Univ. of Colorado. |
---|
| 39 | All rights reserved. |
---|
| 40 | |
---|
| 41 | Permission is hereby granted, without written agreement and without |
---|
| 42 | license or royalty fees, to use, copy, modify, and distribute this |
---|
| 43 | software and its documentation for any purpose, provided that the |
---|
| 44 | above copyright notice and the following two paragraphs appear in |
---|
| 45 | all copies of this software.] |
---|
| 46 | |
---|
| 47 | ******************************************************************************/ |
---|
| 48 | |
---|
| 49 | #include "puresatInt.h" |
---|
| 50 | #include "sat.h" |
---|
| 51 | |
---|
| 52 | /*---------------------------------------------------------------------------*/ |
---|
| 53 | /* Constant declarations */ |
---|
| 54 | /*---------------------------------------------------------------------------*/ |
---|
| 55 | |
---|
| 56 | /*---------------------------------------------------------------------------*/ |
---|
| 57 | /* Structure declarations */ |
---|
| 58 | /*---------------------------------------------------------------------------*/ |
---|
| 59 | |
---|
| 60 | /*---------------------------------------------------------------------------*/ |
---|
| 61 | /* Type declarations */ |
---|
| 62 | /*---------------------------------------------------------------------------*/ |
---|
| 63 | |
---|
| 64 | /*---------------------------------------------------------------------------*/ |
---|
| 65 | /* Variable declarations */ |
---|
| 66 | /*---------------------------------------------------------------------------*/ |
---|
| 67 | static array_t *RCArray; |
---|
| 68 | |
---|
| 69 | /*---------------------------------------------------------------------------*/ |
---|
| 70 | /* Macro declarations */ |
---|
| 71 | /*---------------------------------------------------------------------------*/ |
---|
| 72 | |
---|
| 73 | /**AutomaticStart*************************************************************/ |
---|
| 74 | |
---|
| 75 | /*---------------------------------------------------------------------------*/ |
---|
| 76 | /* Static function prototypes */ |
---|
| 77 | /*---------------------------------------------------------------------------*/ |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | /**AutomaticEnd***************************************************************/ |
---|
| 81 | |
---|
| 82 | /*---------------------------------------------------------------------------*/ |
---|
| 83 | /* Definition of exported functions */ |
---|
| 84 | /*---------------------------------------------------------------------------*/ |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | /*---------------------------------------------------------------------------*/ |
---|
| 88 | /* Definition of internal functions */ |
---|
| 89 | /*---------------------------------------------------------------------------*/ |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | /**Function******************************************************************** |
---|
| 93 | |
---|
| 94 | Synopsis [time out function] |
---|
| 95 | |
---|
| 96 | Description [time out function] |
---|
| 97 | |
---|
| 98 | SideEffects [] |
---|
| 99 | |
---|
| 100 | SeeAlso [] |
---|
| 101 | |
---|
| 102 | *******************************************************************************/ |
---|
| 103 | |
---|
| 104 | static int DfsLevel = 0; |
---|
| 105 | static array_t *NumInCone; |
---|
| 106 | static array_t *NumInAbs; |
---|
| 107 | static array_t *DfsArray; |
---|
| 108 | /*static array_t *RCArray;*/ |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | /**Function******************************************************************** |
---|
| 112 | |
---|
| 113 | Synopsis [Allocate a puresat manager] |
---|
| 114 | |
---|
| 115 | Description [Allocate a puresat manager] |
---|
| 116 | |
---|
| 117 | SideEffects [] |
---|
| 118 | |
---|
| 119 | SeeAlso [] |
---|
| 120 | |
---|
| 121 | ******************************************************************************/ |
---|
| 122 | |
---|
| 123 | PureSat_Manager_t * PureSatManagerAlloc(void) |
---|
| 124 | { |
---|
| 125 | PureSat_Manager_t * pm = ALLOC(PureSat_Manager_t,1); |
---|
| 126 | memset(pm,0,sizeof(PureSat_Manager_t)); |
---|
| 127 | pm->incre = TRUE; |
---|
| 128 | pm->ltlFileName = ALLOC(char,200); |
---|
| 129 | pm->timeOutPeriod = 10000000; |
---|
| 130 | pm->Arosat = TRUE;; |
---|
| 131 | pm->CoreRefMin = TRUE; |
---|
| 132 | pm->RefPredict = TRUE; |
---|
| 133 | pm->Switch = TRUE; |
---|
| 134 | return pm; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | /**Function******************************************************************** |
---|
| 138 | |
---|
| 139 | Synopsis [Free a puresat manager] |
---|
| 140 | |
---|
| 141 | Description [Free a puresat manager] |
---|
| 142 | |
---|
| 143 | SideEffects [] |
---|
| 144 | |
---|
| 145 | SeeAlso [] |
---|
| 146 | |
---|
| 147 | ******************************************************************************/ |
---|
| 148 | void |
---|
| 149 | PureSatManagerFree(PureSat_Manager_t * pm){ |
---|
| 150 | if(pm->latchToTableBaigNodes) |
---|
| 151 | st_free_table(pm->latchToTableBaigNodes); |
---|
| 152 | if(pm->ClsidxToLatchTable) |
---|
| 153 | st_free_table(pm->ClsidxToLatchTable); |
---|
| 154 | if(pm->CoiTable) |
---|
| 155 | st_free_table(pm->CoiTable); |
---|
| 156 | if(pm->AbsTable) |
---|
| 157 | st_free_table(pm->AbsTable); |
---|
| 158 | if(pm->vertexTable) |
---|
| 159 | st_free_table(pm->vertexTable); |
---|
| 160 | if(pm->SufAbsTable) |
---|
| 161 | st_free_table(pm->SufAbsTable);; |
---|
| 162 | if(pm->supportTable) |
---|
| 163 | st_free_table(pm->supportTable); |
---|
| 164 | if(pm->node2dfsTable) |
---|
| 165 | st_free_table(pm->node2dfsTable); |
---|
| 166 | if(pm->result!=NIL(array_t)) |
---|
| 167 | array_free(pm->result); |
---|
| 168 | FREE(pm->ltlFileName); |
---|
| 169 | FREE(pm); |
---|
| 170 | |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | /**Function******************************************************************** |
---|
| 174 | |
---|
| 175 | Synopsis [Allocate a puresat incremental SAT manager] |
---|
| 176 | |
---|
| 177 | Description [Allocate a puresat incremental SAT manager] |
---|
| 178 | |
---|
| 179 | SideEffects [] |
---|
| 180 | |
---|
| 181 | SeeAlso [] |
---|
| 182 | |
---|
| 183 | ******************************************************************************/ |
---|
| 184 | PureSat_IncreSATManager_t * PureSatIncreSATManagerAlloc(PureSat_Manager_t * pm) |
---|
| 185 | { |
---|
| 186 | PureSat_IncreSATManager_t * pism = ALLOC(PureSat_IncreSATManager_t,1); |
---|
| 187 | pism->beginPosition = 0; |
---|
| 188 | pism->Length = 0; |
---|
| 189 | pism->oldLength = 0; |
---|
| 190 | pism->propertyPos = 0; |
---|
| 191 | memset(pism,0,sizeof(PureSat_IncreSATManager_t)); |
---|
| 192 | if(pm->sss){ |
---|
| 193 | pism->cnfClauses = BmcCnfClausesAlloc(); |
---|
| 194 | pism->cm = sat_InitManager(0); |
---|
| 195 | pism->cm->comment = ALLOC(char, 2); |
---|
| 196 | pism->cm->comment[0] = ' '; |
---|
| 197 | pism->cm->comment[1] = '\0'; |
---|
| 198 | |
---|
| 199 | pism->cm->maxNodesArraySize = 1; |
---|
| 200 | pism->cm->nodesArray = ALLOC(long, pism->cm->maxNodesArraySize ); |
---|
| 201 | pism->cm->nodesArraySize = satNodeSize; |
---|
| 202 | pism->cm->stdErr = vis_stderr; |
---|
| 203 | pism->cm->stdOut = vis_stdout; |
---|
| 204 | pism->cm->unitLits = sat_ArrayAlloc(16); |
---|
| 205 | pism->cm->pureLits = sat_ArrayAlloc(16); |
---|
| 206 | pism->cm->each = sat_InitStatistics(); |
---|
| 207 | pism->cm->option = sat_InitOption(); |
---|
| 208 | pism->cm->option->ForceFinish = 1; |
---|
| 209 | pism->cm->option->incTraceObjective = 1; |
---|
| 210 | pism->cm->option->includeLevelZeroLiteral = 1; |
---|
| 211 | pism->cm->option->minimizeConflictClause = 0; |
---|
| 212 | pism->cm->option->SSS = 1; |
---|
| 213 | } |
---|
| 214 | return pism; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | /**Function******************************************************************** |
---|
| 218 | |
---|
| 219 | Synopsis [Free a puresat incremental SAT manager] |
---|
| 220 | |
---|
| 221 | Description [Free a puresat incremental SAT manager] |
---|
| 222 | |
---|
| 223 | SideEffects [] |
---|
| 224 | |
---|
| 225 | SeeAlso [] |
---|
| 226 | |
---|
| 227 | ******************************************************************************/ |
---|
| 228 | |
---|
| 229 | void |
---|
| 230 | PureSatIncreSATManagerFree(PureSat_Manager_t *pm, |
---|
| 231 | PureSat_IncreSATManager_t * pism) |
---|
| 232 | { |
---|
| 233 | if(pm->sss){ |
---|
| 234 | BmcCnfClausesFree(pism->cnfClauses); |
---|
| 235 | FREE(pism->cm->nodesArray); |
---|
| 236 | sat_ArrayFree(pism->cm->unitLits); |
---|
| 237 | sat_ArrayFree(pism->cm->pureLits); |
---|
| 238 | sat_FreeStatistics(pism->cm->each); |
---|
| 239 | sat_FreeOption(pism->cm->option); |
---|
| 240 | FREE(pism->cm); |
---|
| 241 | } |
---|
| 242 | FREE(pism); |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | /**Function******************************************************************** |
---|
| 246 | |
---|
| 247 | Synopsis [Get the cone of influence for a network node] |
---|
| 248 | |
---|
| 249 | Description [Get the cone of influence for a network node] |
---|
| 250 | |
---|
| 251 | SideEffects [] |
---|
| 252 | |
---|
| 253 | SeeAlso [] |
---|
| 254 | |
---|
| 255 | ******************************************************************************/ |
---|
| 256 | |
---|
| 257 | void |
---|
| 258 | PureSatBmcGetCoiForNtkNode( |
---|
| 259 | Ntk_Node_t *node, |
---|
| 260 | st_table *CoiTable, |
---|
| 261 | st_table *visited) |
---|
| 262 | { |
---|
| 263 | int i, j; |
---|
| 264 | Ntk_Node_t *faninNode; |
---|
| 265 | |
---|
| 266 | if(node == NIL(Ntk_Node_t)){ |
---|
| 267 | return; |
---|
| 268 | } |
---|
| 269 | if(Ntk_NodeTestIsLatch(node)){ |
---|
| 270 | DfsLevel++; |
---|
| 271 | if (st_lookup_int(CoiTable, node, &j)&&j<=DfsLevel){ |
---|
| 272 | DfsLevel--; |
---|
| 273 | return; |
---|
| 274 | } |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | if (st_lookup_int(visited, node, &j)&&j<=DfsLevel){ |
---|
| 278 | if(Ntk_NodeTestIsLatch(node)) |
---|
| 279 | DfsLevel--; |
---|
| 280 | return; |
---|
| 281 | } |
---|
| 282 | st_insert(visited, node, (char *)(long)DfsLevel); |
---|
| 283 | if (Ntk_NodeTestIsLatch(node)){ |
---|
| 284 | st_insert(CoiTable, node, (char *)(long)DfsLevel); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | if(Ntk_NodeTestIsInput(node)) |
---|
| 288 | { |
---|
| 289 | return; |
---|
| 290 | } |
---|
| 291 | |
---|
| 292 | Ntk_NodeForEachFanin(node, i, faninNode) { |
---|
| 293 | PureSatBmcGetCoiForNtkNode(faninNode, CoiTable, visited); |
---|
| 294 | } |
---|
| 295 | if(Ntk_NodeTestIsLatch(node)) |
---|
| 296 | DfsLevel--; |
---|
| 297 | return; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | /**Function******************************************************************** |
---|
| 301 | |
---|
| 302 | Synopsis [Get the cone of influence for a ltl formula] |
---|
| 303 | |
---|
| 304 | Description [Get the cone of influence for a ltl formula] |
---|
| 305 | |
---|
| 306 | SideEffects [] |
---|
| 307 | |
---|
| 308 | SeeAlso [] |
---|
| 309 | |
---|
| 310 | ******************************************************************************/ |
---|
| 311 | |
---|
| 312 | void |
---|
| 313 | PureSatBmcGetCoiForLtlFormulaRecursive( |
---|
| 314 | Ntk_Network_t *network, |
---|
| 315 | Ctlsp_Formula_t *formula, |
---|
| 316 | st_table *ltlCoiTable, |
---|
| 317 | st_table *visited) |
---|
| 318 | { |
---|
| 319 | if (formula == NIL(Ctlsp_Formula_t)) { |
---|
| 320 | return; |
---|
| 321 | } |
---|
| 322 | /* leaf node */ |
---|
| 323 | if (formula->type == Ctlsp_ID_c){ |
---|
| 324 | char *name = Ctlsp_FormulaReadVariableName(formula); |
---|
| 325 | Ntk_Node_t *node = Ntk_NetworkFindNodeByName(network, name); |
---|
| 326 | int tmp; |
---|
| 327 | |
---|
| 328 | if (st_lookup_int(visited, node, &tmp)){ |
---|
| 329 | /* Node already visited */ |
---|
| 330 | return; |
---|
| 331 | } |
---|
| 332 | PureSatBmcGetCoiForNtkNode(node, ltlCoiTable, visited); |
---|
| 333 | return; |
---|
| 334 | } |
---|
| 335 | PureSatBmcGetCoiForLtlFormulaRecursive(network, formula->left, ltlCoiTable, visited); |
---|
| 336 | PureSatBmcGetCoiForLtlFormulaRecursive(network, formula->right, ltlCoiTable, visited); |
---|
| 337 | |
---|
| 338 | return; |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | /**Function******************************************************************** |
---|
| 342 | |
---|
| 343 | Synopsis [Get the color of a node] |
---|
| 344 | |
---|
| 345 | Description [Get the color of a node] |
---|
| 346 | |
---|
| 347 | SideEffects [] |
---|
| 348 | |
---|
| 349 | SeeAlso [] |
---|
| 350 | |
---|
| 351 | ******************************************************************************/ |
---|
| 352 | DfsColor |
---|
| 353 | PureSatNodeReadColor( |
---|
| 354 | Ntk_Node_t * node) |
---|
| 355 | { |
---|
| 356 | return ((DfsColor) (long) Ntk_NodeReadUndef(node)); |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | /**Function******************************************************************** |
---|
| 360 | |
---|
| 361 | Synopsis [Set the color of a node] |
---|
| 362 | |
---|
| 363 | Description [Set the color of a node] |
---|
| 364 | |
---|
| 365 | SideEffects [] |
---|
| 366 | |
---|
| 367 | SeeAlso [] |
---|
| 368 | |
---|
| 369 | ******************************************************************************/ |
---|
| 370 | void |
---|
| 371 | PureSatNodeSetColor( |
---|
| 372 | Ntk_Node_t * node, |
---|
| 373 | DfsColor color) |
---|
| 374 | { |
---|
| 375 | Ntk_NodeSetUndef(node, (void *) (long) color); |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | /**Function******************************************************************** |
---|
| 379 | |
---|
| 380 | Synopsis [Recursively compute the transitive fan in nodes of a node] |
---|
| 381 | |
---|
| 382 | Description [Recursively compute the transitive fan in nodes of a node] |
---|
| 383 | |
---|
| 384 | SideEffects [] |
---|
| 385 | |
---|
| 386 | SeeAlso [] |
---|
| 387 | |
---|
| 388 | ******************************************************************************/ |
---|
| 389 | void |
---|
| 390 | PureSatNodeRecursivelyComputeTransitiveFaninNodes_AllNodes( |
---|
| 391 | Ntk_Node_t *node, |
---|
| 392 | int * NumofSupports, |
---|
| 393 | boolean stopAtLatches) |
---|
| 394 | { |
---|
| 395 | int i; |
---|
| 396 | Ntk_Node_t * fanin; |
---|
| 397 | |
---|
| 398 | /* test if we have already started processing this node */ |
---|
| 399 | if ( PureSatNodeReadColor( node ) == dfsBlack_c ) { |
---|
| 400 | return; |
---|
| 401 | } |
---|
| 402 | PureSatNodeSetColor( node, dfsBlack_c ); |
---|
| 403 | |
---|
| 404 | /* if ( Ntk_NodeTestIsCombInput( node ) ) { |
---|
| 405 | st_insert( resultTable, (char *) node, (char *) 0 ); |
---|
| 406 | }*/ |
---|
| 407 | |
---|
| 408 | (*NumofSupports)++; |
---|
| 409 | |
---|
| 410 | if ( Ntk_NodeTestIsInput(node) || ((stopAtLatches == TRUE)&&(Ntk_NodeTestIsLatch(node))) ) { |
---|
| 411 | return; |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | Ntk_NodeForEachFanin( node, i, fanin ) { |
---|
| 415 | PureSatNodeRecursivelyComputeTransitiveFaninNodes_AllNodes( fanin, NumofSupports, stopAtLatches ); |
---|
| 416 | } |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | /**Function******************************************************************** |
---|
| 420 | |
---|
| 421 | Synopsis [Get the number of combination support of a node] |
---|
| 422 | |
---|
| 423 | Description [Get the number of combination support of a node] |
---|
| 424 | |
---|
| 425 | SideEffects [] |
---|
| 426 | |
---|
| 427 | SeeAlso [] |
---|
| 428 | |
---|
| 429 | ******************************************************************************/ |
---|
| 430 | |
---|
| 431 | int |
---|
| 432 | PureSatNodeComputeCombinationalSupport_AllNodes( |
---|
| 433 | Ntk_Network_t *network, |
---|
| 434 | array_t * nodeArray, |
---|
| 435 | boolean stopAtLatches ) |
---|
| 436 | { |
---|
| 437 | lsGen gen; |
---|
| 438 | int i, NumofSupports=0; |
---|
| 439 | Ntk_Node_t *node; |
---|
| 440 | |
---|
| 441 | Ntk_NetworkForEachNode( network, gen, node ) { |
---|
| 442 | PureSatNodeSetColor( node, dfsWhite_c ); |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | /* for each lacthes(node) in the nodeArray, compute the number of gates in |
---|
| 446 | the cone of this latch, put the number in NumofSupports*/ |
---|
| 447 | arrayForEachItem( Ntk_Node_t *, nodeArray, i, node ) { |
---|
| 448 | NumofSupports = 0; |
---|
| 449 | PureSatNodeRecursivelyComputeTransitiveFaninNodes_AllNodes( node, &NumofSupports, stopAtLatches ); |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | return NumofSupports; |
---|
| 453 | } |
---|
| 454 | |
---|
| 455 | /**Function******************************************************************** |
---|
| 456 | |
---|
| 457 | Synopsis [Build a support table,each value associated with a latch is the |
---|
| 458 | number of gates in its cone of influence ] |
---|
| 459 | |
---|
| 460 | Description [Build a support table,each value associated with a latch is the |
---|
| 461 | number of gates in its cone of influence ] |
---|
| 462 | |
---|
| 463 | SideEffects [] |
---|
| 464 | |
---|
| 465 | SeeAlso [] |
---|
| 466 | |
---|
| 467 | ******************************************************************************/ |
---|
| 468 | /*build a supportTable, each value associated with a latch is NumofGatesInCone*/ |
---|
| 469 | void PureSatGenerateSupportTable( |
---|
| 470 | Ntk_Network_t *network, |
---|
| 471 | PureSat_Manager_t *pm) |
---|
| 472 | { |
---|
| 473 | array_t *roots = array_alloc(Ntk_Node_t *,0); /*supports;*/ |
---|
| 474 | st_generator *stgen; |
---|
| 475 | Ntk_Node_t *node,*DataNode=(Ntk_Node_t *)0; |
---|
| 476 | int count, NumofSupports; |
---|
| 477 | |
---|
| 478 | st_foreach_item_int(pm->CoiTable, stgen, &node, &count) { |
---|
| 479 | if (Ntk_NodeTestIsLatch(node)) |
---|
| 480 | DataNode = Ntk_LatchReadDataInput(node); |
---|
| 481 | array_insert(Ntk_Node_t *, roots, 0, DataNode); |
---|
| 482 | NumofSupports = PureSatNodeComputeCombinationalSupport_AllNodes(network, roots,FALSE); |
---|
| 483 | |
---|
| 484 | st_insert(pm->supportTable,node, (char *)(long)NumofSupports); |
---|
| 485 | } |
---|
| 486 | array_free(roots); |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | /**Function******************************************************************** |
---|
| 490 | |
---|
| 491 | Synopsis [Compute the cone of influence for a ltl formula] |
---|
| 492 | |
---|
| 493 | Description [Compute the cone of influence for a ltl formula] |
---|
| 494 | |
---|
| 495 | SideEffects [] |
---|
| 496 | |
---|
| 497 | SeeAlso [] |
---|
| 498 | |
---|
| 499 | ******************************************************************************/ |
---|
| 500 | void |
---|
| 501 | PureSatBmcGetCoiForLtlFormula( |
---|
| 502 | Ntk_Network_t *network, |
---|
| 503 | Ctlsp_Formula_t *formula, |
---|
| 504 | st_table *ltlCoiTable) |
---|
| 505 | { |
---|
| 506 | st_table *visited = st_init_table(st_ptrcmp, st_ptrhash); |
---|
| 507 | |
---|
| 508 | PureSatBmcGetCoiForLtlFormulaRecursive(network, formula, ltlCoiTable, visited); |
---|
| 509 | st_free_table(visited); |
---|
| 510 | return; |
---|
| 511 | } |
---|
| 512 | |
---|
| 513 | |
---|
| 514 | /**Function******************************************************************** |
---|
| 515 | |
---|
| 516 | Synopsis [] |
---|
| 517 | |
---|
| 518 | Description [recursively compute the nodes in a ltl formula and put them in |
---|
| 519 | an array] |
---|
| 520 | |
---|
| 521 | SideEffects [] |
---|
| 522 | |
---|
| 523 | SeeAlso [] |
---|
| 524 | |
---|
| 525 | ******************************************************************************/ |
---|
| 526 | |
---|
| 527 | void |
---|
| 528 | PureSatGetFormulaNodes( |
---|
| 529 | Ntk_Network_t *network, |
---|
| 530 | Ctlsp_Formula_t *F, |
---|
| 531 | array_t *formulaNodes) |
---|
| 532 | { |
---|
| 533 | |
---|
| 534 | if (F == NIL(Ctlsp_Formula_t)) |
---|
| 535 | return; |
---|
| 536 | |
---|
| 537 | if (Ctlsp_FormulaReadType(F) == Ctlsp_ID_c) { |
---|
| 538 | char *nodeNameString = Ctlsp_FormulaReadVariableName(F); |
---|
| 539 | Ntk_Node_t *node = Ntk_NetworkFindNodeByName(network, nodeNameString); |
---|
| 540 | assert(node); |
---|
| 541 | array_insert_last(Ntk_Node_t *, formulaNodes, node); |
---|
| 542 | return; |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | PureSatGetFormulaNodes(network, Ctlsp_FormulaReadRightChild(F), formulaNodes); |
---|
| 546 | PureSatGetFormulaNodes(network, Ctlsp_FormulaReadLeftChild(F), formulaNodes); |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | |
---|
| 550 | |
---|
| 551 | /**Function******************************************************************** |
---|
| 552 | |
---|
| 553 | Synopsis [Get direct fan in latches for a node] |
---|
| 554 | |
---|
| 555 | Description [Get direct fan in latches for a node] |
---|
| 556 | |
---|
| 557 | SideEffects [] |
---|
| 558 | |
---|
| 559 | SeeAlso [] |
---|
| 560 | |
---|
| 561 | ******************************************************************************/ |
---|
| 562 | |
---|
| 563 | void |
---|
| 564 | PureSatGetFaninLatches( |
---|
| 565 | Ntk_Node_t *node, |
---|
| 566 | st_table *visited, |
---|
| 567 | st_table *vertexTable) |
---|
| 568 | { |
---|
| 569 | if (st_is_member(visited, node)) |
---|
| 570 | return; |
---|
| 571 | |
---|
| 572 | st_insert(visited, node, (char *)0); |
---|
| 573 | |
---|
| 574 | if (Ntk_NodeTestIsLatch(node)) |
---|
| 575 | st_insert(vertexTable, Ntk_NodeReadName(node), (char *)0); |
---|
| 576 | else { |
---|
| 577 | int i; |
---|
| 578 | Ntk_Node_t *fanin; |
---|
| 579 | Ntk_NodeForEachFanin(node, i, fanin) { |
---|
| 580 | PureSatGetFaninLatches(fanin, visited, vertexTable); |
---|
| 581 | } |
---|
| 582 | } |
---|
| 583 | } |
---|
| 584 | /**Function******************************************************************** |
---|
| 585 | |
---|
| 586 | Synopsis [Build a vertex table which stores all the latches in the |
---|
| 587 | beginning abstract model] |
---|
| 588 | |
---|
| 589 | Description [The table contains only those immediate fanin latches of the |
---|
| 590 | given formula.] |
---|
| 591 | |
---|
| 592 | SideEffects [] |
---|
| 593 | |
---|
| 594 | SeeAlso [] |
---|
| 595 | ******************************************************************************/ |
---|
| 596 | |
---|
| 597 | st_table * |
---|
| 598 | PureSatCreateInitialAbstraction( |
---|
| 599 | Ntk_Network_t *network, |
---|
| 600 | Ctlsp_Formula_t *invFormula, |
---|
| 601 | int * Num, |
---|
| 602 | PureSat_Manager_t *pm) |
---|
| 603 | { |
---|
| 604 | array_t *formulaNodes = array_alloc(Ntk_Node_t *, 0); |
---|
| 605 | Ntk_Node_t *node; |
---|
| 606 | int i; |
---|
| 607 | |
---|
| 608 | st_table *vertexTable = st_init_table(strcmp, st_strhash); |
---|
| 609 | st_table *visited = st_init_table(st_ptrcmp, st_ptrhash); |
---|
| 610 | *Num=0; |
---|
| 611 | |
---|
| 612 | PureSatGetFormulaNodes(network, invFormula, formulaNodes); |
---|
| 613 | arrayForEachItem(Ntk_Node_t *, formulaNodes, i, node) { |
---|
| 614 | PureSatGetFaninLatches(node, visited, vertexTable); |
---|
| 615 | } |
---|
| 616 | |
---|
| 617 | st_free_table(visited); |
---|
| 618 | array_free(formulaNodes); |
---|
| 619 | |
---|
| 620 | if (1) { |
---|
| 621 | st_generator *stgen; |
---|
| 622 | char *nodeNameString; |
---|
| 623 | |
---|
| 624 | if(pm->verbosity>=1) |
---|
| 625 | fprintf(vis_stdout, "\n Create_InitialAbstraction() =\n"); |
---|
| 626 | st_foreach_item(vertexTable, stgen, &nodeNameString, 0) { |
---|
| 627 | if(pm->verbosity>=1) |
---|
| 628 | fprintf(vis_stdout, "%s\n", nodeNameString); |
---|
| 629 | (*Num)++; |
---|
| 630 | } |
---|
| 631 | if(pm->verbosity>=1){ |
---|
| 632 | fprintf(vis_stdout, "\n"); |
---|
| 633 | fflush(vis_stdout); |
---|
| 634 | } |
---|
| 635 | } |
---|
| 636 | |
---|
| 637 | |
---|
| 638 | return vertexTable; |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | |
---|
| 642 | /**Function******************************************************************** |
---|
| 643 | |
---|
| 644 | Synopsis [Recursively get direct fan in gates of a node] |
---|
| 645 | |
---|
| 646 | Description [Recursively get direct fan in gates of a node] |
---|
| 647 | |
---|
| 648 | SideEffects [] |
---|
| 649 | |
---|
| 650 | SeeAlso [] |
---|
| 651 | |
---|
| 652 | ******************************************************************************/ |
---|
| 653 | |
---|
| 654 | void |
---|
| 655 | PureSatRecursivelyComputeTableForLatch(Ntk_Network_t * network, |
---|
| 656 | st_table *Table, |
---|
| 657 | Ntk_Node_t * node) |
---|
| 658 | { |
---|
| 659 | int i; |
---|
| 660 | Ntk_Node_t * fanin; |
---|
| 661 | |
---|
| 662 | //want input to be in the Table |
---|
| 663 | if(Ntk_NodeTestIsLatch(node)) |
---|
| 664 | return; |
---|
| 665 | |
---|
| 666 | if(!st_lookup(Table,node,NIL(char *))) |
---|
| 667 | st_insert(Table,node, (char *)0); |
---|
| 668 | else |
---|
| 669 | return; |
---|
| 670 | |
---|
| 671 | if ( Ntk_NodeTestIsCombInput(node)) { |
---|
| 672 | return; |
---|
| 673 | } |
---|
| 674 | |
---|
| 675 | Ntk_NodeForEachFanin( node,i,fanin) |
---|
| 676 | PureSatRecursivelyComputeTableForLatch(network,Table,fanin); |
---|
| 677 | } |
---|
| 678 | |
---|
| 679 | |
---|
| 680 | /**Function******************************************************************** |
---|
| 681 | |
---|
| 682 | Synopsis [Get direct fan in gates of a node] |
---|
| 683 | |
---|
| 684 | Description [Get direct fan in gates of a node] |
---|
| 685 | |
---|
| 686 | SideEffects [] |
---|
| 687 | |
---|
| 688 | SeeAlso [] |
---|
| 689 | |
---|
| 690 | ******************************************************************************/ |
---|
| 691 | /* put all the gates of Abs model to the Table */ |
---|
| 692 | void |
---|
| 693 | PureSatComputeTableForLatch(Ntk_Network_t * network, |
---|
| 694 | st_table * Table, |
---|
| 695 | Ntk_Node_t * Latch) |
---|
| 696 | { |
---|
| 697 | Ntk_Node_t * fanin; |
---|
| 698 | int i; |
---|
| 699 | |
---|
| 700 | if(!Ntk_NodeTestIsLatch(Latch)) |
---|
| 701 | { |
---|
| 702 | char * name = Ntk_NodeReadName(Latch); |
---|
| 703 | fprintf(vis_stdout,"%s is not a latch!\n",name); |
---|
| 704 | exit (0); |
---|
| 705 | } |
---|
| 706 | |
---|
| 707 | if(!st_lookup(Table,Latch,NIL(char *))) |
---|
| 708 | { |
---|
| 709 | st_insert(Table,Latch, (char *)0); |
---|
| 710 | Ntk_NodeForEachFanin(Latch,i,fanin) |
---|
| 711 | PureSatRecursivelyComputeTableForLatch(network,Table,fanin); |
---|
| 712 | } |
---|
| 713 | } |
---|
| 714 | |
---|
| 715 | |
---|
| 716 | /**Function******************************************************************** |
---|
| 717 | |
---|
| 718 | Synopsis [Take latches in visibleArray as the first level |
---|
| 719 | compute the DFS level of each latch in ltlCoiTable] |
---|
| 720 | |
---|
| 721 | Description [Take latches in visibleArray as the first level |
---|
| 722 | compute the DFS level of each latch in ltlCoiTable] |
---|
| 723 | |
---|
| 724 | SideEffects [] |
---|
| 725 | |
---|
| 726 | SeeAlso [] |
---|
| 727 | |
---|
| 728 | ******************************************************************************/ |
---|
| 729 | |
---|
| 730 | void |
---|
| 731 | PureSatGetCoiForVisibleArray_Ring( |
---|
| 732 | Ntk_Network_t *network, |
---|
| 733 | array_t *visibleArray, |
---|
| 734 | int position, |
---|
| 735 | st_table *ltlCoiTable) |
---|
| 736 | { |
---|
| 737 | int i; |
---|
| 738 | char * name; |
---|
| 739 | Ntk_Node_t * node; |
---|
| 740 | |
---|
| 741 | st_table *visited = st_init_table(st_ptrcmp, st_ptrhash); |
---|
| 742 | |
---|
| 743 | |
---|
| 744 | for(i=position;i<array_n(visibleArray);i++){ |
---|
| 745 | name = array_fetch(char *,visibleArray,i); |
---|
| 746 | node = Ntk_NetworkFindNodeByName(network,name); |
---|
| 747 | DfsLevel = 0; |
---|
| 748 | PureSatBmcGetCoiForNtkNode(node,ltlCoiTable, visited); |
---|
| 749 | } |
---|
| 750 | st_free_table(visited); |
---|
| 751 | return; |
---|
| 752 | } |
---|
| 753 | |
---|
| 754 | |
---|
| 755 | /**Function******************************************************************** |
---|
| 756 | |
---|
| 757 | Synopsis [Compare function for quick sort] |
---|
| 758 | |
---|
| 759 | Description [Compare function for quick sort] |
---|
| 760 | |
---|
| 761 | SideEffects [] |
---|
| 762 | |
---|
| 763 | SeeAlso [] |
---|
| 764 | |
---|
| 765 | ******************************************************************************/ |
---|
| 766 | |
---|
| 767 | int |
---|
| 768 | NumInConeCompare(int *ptrX, |
---|
| 769 | int *ptrY) |
---|
| 770 | { |
---|
| 771 | int a,b; |
---|
| 772 | int c,d; |
---|
| 773 | double e,f; |
---|
| 774 | a = array_fetch(int,NumInCone,(int)*ptrX); |
---|
| 775 | b = array_fetch(int,NumInCone,(int)*ptrY); |
---|
| 776 | c = array_fetch(int,NumInAbs,(int)*ptrX); |
---|
| 777 | d = array_fetch(int,NumInAbs,(int)*ptrY); |
---|
| 778 | e = (double)c/(double)a; |
---|
| 779 | f = (double)d/(double)b; |
---|
| 780 | if(e > f) |
---|
| 781 | return -1; |
---|
| 782 | if( e < f) |
---|
| 783 | return 1; |
---|
| 784 | return 0; |
---|
| 785 | } |
---|
| 786 | |
---|
| 787 | |
---|
| 788 | /**Function******************************************************************** |
---|
| 789 | |
---|
| 790 | Synopsis [Compare function for quick sort] |
---|
| 791 | |
---|
| 792 | Description [Compare function for quick sort] |
---|
| 793 | |
---|
| 794 | SideEffects [] |
---|
| 795 | |
---|
| 796 | SeeAlso [] |
---|
| 797 | |
---|
| 798 | ******************************************************************************/ |
---|
| 799 | |
---|
| 800 | int |
---|
| 801 | NumInConeCompare_Ring(int *ptrX, |
---|
| 802 | int *ptrY) |
---|
| 803 | { |
---|
| 804 | int a,b; |
---|
| 805 | double c,d; |
---|
| 806 | double e,f; |
---|
| 807 | a = array_fetch(int,DfsArray,(int)*ptrX); |
---|
| 808 | b = array_fetch(int,DfsArray,(int)*ptrY); |
---|
| 809 | c = array_fetch(double,RCArray,(int)*ptrX); |
---|
| 810 | d = array_fetch(double,RCArray,(int)*ptrY); |
---|
| 811 | e = (double)((a)*1000000)-c; |
---|
| 812 | f = (double)((b)*1000000)-d; |
---|
| 813 | if(e > f) |
---|
| 814 | return 1; |
---|
| 815 | if( e < f) |
---|
| 816 | return -1; |
---|
| 817 | return 0; |
---|
| 818 | } |
---|
| 819 | |
---|
| 820 | |
---|
| 821 | /**Function******************************************************************** |
---|
| 822 | |
---|
| 823 | Synopsis [Recursively compute the relative correlation of a latch. |
---|
| 824 | For more information of Relative Correlation, please check the BMC'03 and STTT'05 |
---|
| 825 | paper of Li et al., "A satisfiability-based appraoch to abstraction |
---|
| 826 | refinement in model checking", and " Abstraction in symbolic model checking |
---|
| 827 | using satisfiability as the only decision procedure"] |
---|
| 828 | |
---|
| 829 | Description [Recursively compute the relative correlation of a latch. |
---|
| 830 | For more information of Relative Correlation, please check the BMC'03 and STTT'05 |
---|
| 831 | paper of Li et al., "A satisfiability-based appraoch to abstraction |
---|
| 832 | refinement in model checking", and " Abstraction in symbolic model checking |
---|
| 833 | using satisfiability as the only decision procedure"] |
---|
| 834 | |
---|
| 835 | SideEffects [] |
---|
| 836 | |
---|
| 837 | SeeAlso [] |
---|
| 838 | |
---|
| 839 | ******************************************************************************/ |
---|
| 840 | |
---|
| 841 | void PureSatRecursivelyComputeCorrelationforLatch(Ntk_Network_t *network, |
---|
| 842 | st_table *AbsTable, |
---|
| 843 | st_table * visited, |
---|
| 844 | Ntk_Node_t *node, |
---|
| 845 | int *count) |
---|
| 846 | { |
---|
| 847 | Ntk_Node_t * fanin; |
---|
| 848 | int i; |
---|
| 849 | |
---|
| 850 | if(!st_lookup(visited,node,NIL(char *))) |
---|
| 851 | { |
---|
| 852 | st_insert(visited,node,(char *)0); |
---|
| 853 | if(st_lookup(AbsTable,node,NIL(char *))) |
---|
| 854 | { |
---|
| 855 | (*count)++; |
---|
| 856 | } |
---|
| 857 | } |
---|
| 858 | else |
---|
| 859 | return; |
---|
| 860 | |
---|
| 861 | if(Ntk_NodeTestIsCombInput(node)) |
---|
| 862 | return; |
---|
| 863 | |
---|
| 864 | Ntk_NodeForEachFanin(node,i,fanin) |
---|
| 865 | PureSatRecursivelyComputeCorrelationforLatch(network,AbsTable,visited,fanin,count); |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | |
---|
| 869 | |
---|
| 870 | /**Function******************************************************************** |
---|
| 871 | |
---|
| 872 | Synopsis [Compute the relative correlation of a latch. |
---|
| 873 | For more information of Relative Correlation, please check the BMC'03 and STTT'05 |
---|
| 874 | paper of Li et al., "A satisfiability-based appraoch to abstraction |
---|
| 875 | refinement in model checking", and " Abstraction in symbolic model checking |
---|
| 876 | using satisfiability as the only decision procedure"] |
---|
| 877 | |
---|
| 878 | Description [Compute the relative correlation of a latch. |
---|
| 879 | For more information of Relative Correlation, please check the BMC'03 and STTT'05 |
---|
| 880 | paper of Li et al., "A satisfiability-based appraoch to abstraction |
---|
| 881 | refinement in model checking", and " Abstraction in symbolic model checking |
---|
| 882 | using satisfiability as the only decision procedure"] |
---|
| 883 | |
---|
| 884 | SideEffects [] |
---|
| 885 | |
---|
| 886 | SeeAlso [] |
---|
| 887 | |
---|
| 888 | ******************************************************************************/ |
---|
| 889 | |
---|
| 890 | int PureSatComputeCorrelationforLatch(Ntk_Network_t * network, st_table * |
---|
| 891 | AbsTable, Ntk_Node_t *Latch) |
---|
| 892 | { |
---|
| 893 | int count =0,i; |
---|
| 894 | Ntk_Node_t * fanin; |
---|
| 895 | |
---|
| 896 | st_table *visited = st_init_table(st_ptrcmp,st_ptrhash); |
---|
| 897 | Ntk_NodeForEachFanin(Latch,i,fanin) |
---|
| 898 | PureSatRecursivelyComputeCorrelationforLatch(network,AbsTable,visited,fanin,&count); |
---|
| 899 | st_free_table(visited); |
---|
| 900 | return count*10000; |
---|
| 901 | } |
---|
| 902 | |
---|
| 903 | /**Function******************************************************************** |
---|
| 904 | |
---|
| 905 | Synopsis [Generating the ring information needed for the computation of |
---|
| 906 | the relative correlation of a latch. For more information of Relative |
---|
| 907 | Correlation, please check the BMC'03 and STTT'05 paper of Li et al., "A |
---|
| 908 | satisfiability-based appraoch to abstraction refinement in model checking", |
---|
| 909 | and " Abstraction in symbolic model checking |
---|
| 910 | using satisfiability as the only decision procedure] |
---|
| 911 | |
---|
| 912 | Description [Generating the ring information needed for the computation of |
---|
| 913 | the relative correlation of a latch. For more information of Relative |
---|
| 914 | Correlation, please check the BMC'03 and STTT'05 paper of Li et al., "A |
---|
| 915 | satisfiability-based appraoch to abstraction refinement in model checking", |
---|
| 916 | and " Abstraction in symbolic model checking |
---|
| 917 | using satisfiability as the only decision procedure"] |
---|
| 918 | |
---|
| 919 | SideEffects [] |
---|
| 920 | |
---|
| 921 | SeeAlso [] |
---|
| 922 | |
---|
| 923 | ******************************************************************************/ |
---|
| 924 | |
---|
| 925 | array_t * PureSatGenerateRingFromAbs(Ntk_Network_t *network, |
---|
| 926 | PureSat_Manager_t *pm, |
---|
| 927 | array_t *invisibleArray, |
---|
| 928 | int * NumInSecondLevel) |
---|
| 929 | { |
---|
| 930 | st_table *CoiTable = pm->CoiTable; |
---|
| 931 | st_table *supportTable = pm->supportTable; |
---|
| 932 | st_table *AbsTable= pm->AbsTable; |
---|
| 933 | |
---|
| 934 | array_t * arrayRC = array_alloc(char *,array_n(invisibleArray)),* NumInConeArray = array_alloc(int,0),* NumInAbsArray = array_alloc(int,0); |
---|
| 935 | array_t * tmpNumInCone = array_alloc(int,0),* tmpNumInAbs = array_alloc(int,0); |
---|
| 936 | array_t * tmpDfsArray = array_alloc(int,0), *tmpRCArray = array_alloc(double,0); |
---|
| 937 | array_t * tmpDfsArray1 = array_alloc(int,0), *tmpRCArray1 = array_alloc(double,0); |
---|
| 938 | int numincone,i,j,dfs; |
---|
| 939 | char *name; |
---|
| 940 | double d1; |
---|
| 941 | |
---|
| 942 | (*NumInSecondLevel) = 0; |
---|
| 943 | |
---|
| 944 | for(i=0;i<array_n(invisibleArray);i++) |
---|
| 945 | { |
---|
| 946 | int tmp; |
---|
| 947 | Ntk_Node_t *tmpnode; |
---|
| 948 | name = array_fetch(char *,invisibleArray,i); |
---|
| 949 | tmpnode = Ntk_NetworkFindNodeByName(network,name); |
---|
| 950 | tmp = PureSatComputeCorrelationforLatch(network,AbsTable,tmpnode); |
---|
| 951 | tmp = tmp/10000; |
---|
| 952 | |
---|
| 953 | if(!st_lookup_int(CoiTable,tmpnode,&dfs)){ |
---|
| 954 | fprintf(vis_stderr,"not in Coitable, Wrong"); |
---|
| 955 | exit(0); |
---|
| 956 | } |
---|
| 957 | if(!st_lookup_int(supportTable,tmpnode, &numincone)){ |
---|
| 958 | fprintf(vis_stderr,"not in supporttable, Wrong"); |
---|
| 959 | exit(0); |
---|
| 960 | } |
---|
| 961 | d1 = (double)tmp/(double)numincone; |
---|
| 962 | array_insert_last(double,tmpRCArray,d1); |
---|
| 963 | array_insert_last(int,tmpDfsArray,dfs); |
---|
| 964 | |
---|
| 965 | } |
---|
| 966 | |
---|
| 967 | |
---|
| 968 | DfsArray = tmpDfsArray; |
---|
| 969 | RCArray = tmpRCArray; |
---|
| 970 | { |
---|
| 971 | int tmpvalue; |
---|
| 972 | double dvalue; |
---|
| 973 | int nn = array_n(invisibleArray); |
---|
| 974 | int *tay=ALLOC(int,nn); |
---|
| 975 | for(j=0;j<nn;j++) |
---|
| 976 | tay[j]=j; |
---|
| 977 | qsort((void *)tay, nn, sizeof(int), |
---|
| 978 | (int (*)(const void *, const void *))NumInConeCompare_Ring); |
---|
| 979 | for(i=0;i<nn;i++) |
---|
| 980 | { |
---|
| 981 | char *str=ALLOC(char,100); |
---|
| 982 | name = array_fetch(char *,invisibleArray,tay[i]); |
---|
| 983 | strcpy(str,name); |
---|
| 984 | array_insert(char *,arrayRC,i,str); |
---|
| 985 | tmpvalue = array_fetch(int,tmpDfsArray,tay[i]); |
---|
| 986 | if(tmpvalue == 2) |
---|
| 987 | (*NumInSecondLevel)++; |
---|
| 988 | array_insert(int,tmpDfsArray1,i,tmpvalue); |
---|
| 989 | dvalue = array_fetch(double,tmpRCArray,tay[i]); |
---|
| 990 | array_insert(double,tmpRCArray1,i,dvalue); |
---|
| 991 | if(pm->verbosity>=2){ |
---|
| 992 | int i1; |
---|
| 993 | double d1,d2; |
---|
| 994 | i1 = array_fetch(int,tmpDfsArray1,i)*1000000; |
---|
| 995 | d1 = array_fetch(double,tmpRCArray1,i); |
---|
| 996 | d2 = (double)array_fetch(int,tmpDfsArray1,i)*1000000 - d1; |
---|
| 997 | if(pm->verbosity>=1) |
---|
| 998 | fprintf(vis_stdout,"arrayRC %s: %d-%f = %f\n",name,i1,d1,d2); |
---|
| 999 | /* fprintf(vis_stdout,"arrayRC %s: %d-%f = %f\n",name,array_fetch(int,tmpDfsArray1,i)*1000000,array_fetch(double,tmpRCArray1,i), |
---|
| 1000 | (double)array_fetch(int,tmpDfsArray1,i)*1000000-(double)array_fetch(double,tmpRCArray1,i));*/ |
---|
| 1001 | } |
---|
| 1002 | } |
---|
| 1003 | FREE(tay); |
---|
| 1004 | } |
---|
| 1005 | array_free(NumInConeArray); |
---|
| 1006 | array_free(NumInAbsArray); |
---|
| 1007 | array_free(tmpNumInCone); |
---|
| 1008 | array_free(tmpNumInAbs); |
---|
| 1009 | array_free(tmpDfsArray); |
---|
| 1010 | array_free(tmpRCArray); |
---|
| 1011 | array_free(tmpDfsArray1); |
---|
| 1012 | array_free(tmpRCArray1); |
---|
| 1013 | return arrayRC; |
---|
| 1014 | } |
---|
| 1015 | |
---|
| 1016 | /**Function******************************************************************** |
---|
| 1017 | |
---|
| 1018 | Synopsis [Clean the SAT solver after a SAT solving procedure is done] |
---|
| 1019 | |
---|
| 1020 | Description [Clean the SAT solver after a SAT solving procedure is done] |
---|
| 1021 | |
---|
| 1022 | SideEffects [] |
---|
| 1023 | |
---|
| 1024 | SeeAlso [] |
---|
| 1025 | |
---|
| 1026 | ******************************************************************************/ |
---|
| 1027 | |
---|
| 1028 | void PureSatCleanSat(satManager_t * cm) |
---|
| 1029 | { |
---|
| 1030 | int i; |
---|
| 1031 | satVariable_t *var; |
---|
| 1032 | satLevel_t *d; |
---|
| 1033 | |
---|
| 1034 | cm->nodesArraySize = satNodeSize; |
---|
| 1035 | sat_ArrayFree(cm->unitLits); |
---|
| 1036 | sat_ArrayFree(cm->pureLits); |
---|
| 1037 | cm->unitLits = sat_ArrayAlloc(16); |
---|
| 1038 | cm->pureLits = sat_ArrayAlloc(16); |
---|
| 1039 | memset(cm->each,0,sizeof(satStatistics_t)); |
---|
| 1040 | cm->literals->last = cm->literals->begin+1; |
---|
| 1041 | cm->literals->initialSize = cm->literals->last; |
---|
| 1042 | cm->status = 0; |
---|
| 1043 | cm->currentVarPos = 0; |
---|
| 1044 | cm->currentTopConflict = 0; |
---|
| 1045 | cm->lowestBacktrackLevel = 0; |
---|
| 1046 | cm->implicatedSoFar = 0; |
---|
| 1047 | /*cm->decisionHead = ALLOC(satLevel_t, cm->decisionHeadSize);*/ |
---|
| 1048 | memset(cm->decisionHead, 0, sizeof(satLevel_t) * cm->decisionHeadSize); |
---|
| 1049 | /* FREE(cm->variableArray); |
---|
| 1050 | cm->variableArray = 0;*/ |
---|
| 1051 | if(cm->variableArray) { |
---|
| 1052 | for(i=0; i<=cm->initNumVariables; i++) { |
---|
| 1053 | var = &(cm->variableArray[i]); |
---|
| 1054 | if(var->wl[0]) { |
---|
| 1055 | sat_ArrayFree(var->wl[0]); |
---|
| 1056 | var->wl[0] = 0; |
---|
| 1057 | } |
---|
| 1058 | if(var->wl[1]) { |
---|
| 1059 | sat_ArrayFree(var->wl[1]); |
---|
| 1060 | var->wl[1] = 0; |
---|
| 1061 | } |
---|
| 1062 | } |
---|
| 1063 | free(cm->variableArray); |
---|
| 1064 | cm->variableArray = 0; |
---|
| 1065 | } |
---|
| 1066 | |
---|
| 1067 | if(cm->decisionHead) { |
---|
| 1068 | for(i=0; i<cm->decisionHeadSize; i++) { |
---|
| 1069 | d = &(cm->decisionHead[i]); |
---|
| 1070 | if(d->implied) |
---|
| 1071 | sat_ArrayFree(d->implied); |
---|
| 1072 | if(d->satisfied) |
---|
| 1073 | sat_ArrayFree(d->satisfied); |
---|
| 1074 | } |
---|
| 1075 | free(cm->decisionHead); |
---|
| 1076 | cm->decisionHead = 0; |
---|
| 1077 | cm->decisionHeadSize = 0; |
---|
| 1078 | } |
---|
| 1079 | |
---|
| 1080 | sat_FreeQueue(cm->queue); |
---|
| 1081 | cm->queue = 0; |
---|
| 1082 | sat_FreeQueue(cm->BDDQueue); |
---|
| 1083 | cm->BDDQueue = 0; |
---|
| 1084 | sat_FreeQueue(cm->unusedAigQueue); |
---|
| 1085 | cm->unusedAigQueue = 0; |
---|
| 1086 | sat_ArrayFree(cm->auxArray); |
---|
| 1087 | sat_ArrayFree(cm->nonobjUnitLitArray); |
---|
| 1088 | sat_ArrayFree(cm->objUnitLitArray); |
---|
| 1089 | |
---|
| 1090 | } |
---|
| 1091 | |
---|
| 1092 | /**Function******************************************************************** |
---|
| 1093 | |
---|
| 1094 | Synopsis [Read clauses from a puresat incremental SAT manager to the |
---|
| 1095 | CirCUs SAT solver] |
---|
| 1096 | |
---|
| 1097 | Description [Read clauses from a puresat incremental SAT manager to the |
---|
| 1098 | CirCUs SAT solver] |
---|
| 1099 | |
---|
| 1100 | SideEffects [] |
---|
| 1101 | |
---|
| 1102 | SeeAlso [] |
---|
| 1103 | |
---|
| 1104 | ******************************************************************************/ |
---|
| 1105 | |
---|
| 1106 | void PureSatReadClauses(PureSat_IncreSATManager_t * pism, |
---|
| 1107 | PureSat_Manager_t * pm) |
---|
| 1108 | { |
---|
| 1109 | int i,node,nVar = pism->cnfClauses->cnfGlobalIndex - 1; |
---|
| 1110 | satManager_t * cm = pism->cm; |
---|
| 1111 | satArray_t * clauseArray; |
---|
| 1112 | |
---|
| 1113 | cm->option->verbose = pm->verbosity; |
---|
| 1114 | cm->initNumVariables = nVar; |
---|
| 1115 | cm->variableArray = ALLOC(satVariable_t, cm->initNumVariables+1); |
---|
| 1116 | memset(cm->variableArray, 0, sizeof(satVariable_t) * |
---|
| 1117 | (cm->initNumVariables+1)); |
---|
| 1118 | if(cm->maxNodesArraySize <= (cm->initNumVariables+2)*satNodeSize){ |
---|
| 1119 | cm->nodesArray = ALLOC(long, (cm->initNumVariables+2)*satNodeSize); |
---|
| 1120 | cm->maxNodesArraySize = (cm->initNumVariables+2)*satNodeSize; |
---|
| 1121 | } |
---|
| 1122 | |
---|
| 1123 | |
---|
| 1124 | if(pism->cm->option->coreGeneration){ |
---|
| 1125 | pism->cm->dependenceTable = st_init_table(st_ptrcmp, st_ptrhash); |
---|
| 1126 | |
---|
| 1127 | /*the tables stroes entry of (var_node_idx,cls_idx);*/ |
---|
| 1128 | pism->cm->anteTable = st_init_table(st_numcmp, st_numhash); |
---|
| 1129 | |
---|
| 1130 | } |
---|
| 1131 | sat_AllocLiteralsDB(cm); |
---|
| 1132 | |
---|
| 1133 | for(i=1;i<=nVar;i++){ |
---|
| 1134 | node = sat_CreateNode(cm,2,2); |
---|
| 1135 | SATflags(node) |= CoiMask; |
---|
| 1136 | SATvalue(node) = 2; |
---|
| 1137 | /*SATfanout(node) = 0;*/ |
---|
| 1138 | cm->nodesArray[node+satFanout] = 0; |
---|
| 1139 | SATnFanout(node) = 0; |
---|
| 1140 | } |
---|
| 1141 | |
---|
| 1142 | clauseArray = sat_ArrayAlloc(4096); |
---|
| 1143 | for(i=0; i<pism->cnfClauses->nextIndex;i++){ |
---|
| 1144 | int k, cls_idx,v; |
---|
| 1145 | k = array_fetch(int,pism->cnfClauses->clauseArray,i); |
---|
| 1146 | if(k!=0){ |
---|
| 1147 | int sign = 1; |
---|
| 1148 | if(k<0){ |
---|
| 1149 | sign = 0; |
---|
| 1150 | k = -k; |
---|
| 1151 | } |
---|
| 1152 | v = k*satNodeSize + sign; |
---|
| 1153 | sat_ArrayInsert(clauseArray, v); |
---|
| 1154 | } |
---|
| 1155 | else{ |
---|
| 1156 | if(clauseArray->num == 1) { |
---|
| 1157 | v = clauseArray->space[0]; |
---|
| 1158 | sat_ArrayInsert(cm->unitLits, SATnot(v)); |
---|
| 1159 | cls_idx = sat_AddUnitClause(cm, clauseArray); |
---|
| 1160 | if(pism->cm->option->coreGeneration){ |
---|
| 1161 | v = SATnormalNode(v); |
---|
| 1162 | st_insert(pism->cm->anteTable,(char *)(long)v,(char *)(long)cls_idx); |
---|
| 1163 | } |
---|
| 1164 | } |
---|
| 1165 | else{ |
---|
| 1166 | cls_idx = sat_AddClause(cm, clauseArray); |
---|
| 1167 | } |
---|
| 1168 | cm->initNumClauses++; |
---|
| 1169 | cm->initNumLiterals += clauseArray->num; |
---|
| 1170 | if(i>pism->propertyPos) |
---|
| 1171 | SATflags(cls_idx) |= ObjMask; |
---|
| 1172 | clauseArray->num = 0; |
---|
| 1173 | } |
---|
| 1174 | } |
---|
| 1175 | sat_ArrayFree(clauseArray); |
---|
| 1176 | |
---|
| 1177 | } |
---|
| 1178 | |
---|
| 1179 | /**Function******************************************************************** |
---|
| 1180 | |
---|
| 1181 | Synopsis [Get immediate latch supports for latches in latchNameArray] |
---|
| 1182 | |
---|
| 1183 | Description [Get immediate latch supports for latches in latchNameArray] |
---|
| 1184 | |
---|
| 1185 | SideEffects [] |
---|
| 1186 | |
---|
| 1187 | SeeAlso [] |
---|
| 1188 | |
---|
| 1189 | ******************************************************************************/ |
---|
| 1190 | |
---|
| 1191 | array_t * PureSatGetImmediateSupportLatches( |
---|
| 1192 | Ntk_Network_t *network, |
---|
| 1193 | int beginPosition, |
---|
| 1194 | array_t *latchNameArray) |
---|
| 1195 | { |
---|
| 1196 | /* old support, form 0 to 'beginPosition'-1*/ |
---|
| 1197 | array_t *dataInputs, *supports; |
---|
| 1198 | /* new support, from 'beginPosition' to array_n(latchNameArray)-1*/ |
---|
| 1199 | array_t *dataInputs2, *supports2, *supportLatches2; |
---|
| 1200 | /* The result should be {new support}-{old support}*/ |
---|
| 1201 | st_table *oldSupportTable; |
---|
| 1202 | Ntk_Node_t *latch, *dataInput; |
---|
| 1203 | int i; |
---|
| 1204 | char *latchName; |
---|
| 1205 | |
---|
| 1206 | dataInputs = array_alloc(Ntk_Node_t *, 0); |
---|
| 1207 | dataInputs2 = array_alloc(Ntk_Node_t *, 0); |
---|
| 1208 | arrayForEachItem(char *, latchNameArray, i, latchName) { |
---|
| 1209 | latch = Ntk_NetworkFindNodeByName(network, latchName); |
---|
| 1210 | assert(latch); |
---|
| 1211 | assert(Ntk_NodeTestIsLatch(latch)); |
---|
| 1212 | dataInput = Ntk_LatchReadDataInput(latch); |
---|
| 1213 | if (i < beginPosition) |
---|
| 1214 | array_insert_last(Ntk_Node_t *, dataInputs, dataInput); |
---|
| 1215 | else |
---|
| 1216 | array_insert_last(Ntk_Node_t *, dataInputs2, dataInput); |
---|
| 1217 | } |
---|
| 1218 | |
---|
| 1219 | supports = Ntk_NodeComputeCombinationalSupport(network, dataInputs, 1); |
---|
| 1220 | supports2 = Ntk_NodeComputeCombinationalSupport(network, dataInputs2, 1); |
---|
| 1221 | array_free(dataInputs); |
---|
| 1222 | array_free(dataInputs2); |
---|
| 1223 | |
---|
| 1224 | oldSupportTable = st_init_table(st_ptrcmp, st_ptrhash); |
---|
| 1225 | arrayForEachItem(Ntk_Node_t *, supports, i, latch) { |
---|
| 1226 | st_insert(oldSupportTable, latch, NIL(char)); |
---|
| 1227 | } |
---|
| 1228 | array_free(supports); |
---|
| 1229 | |
---|
| 1230 | supportLatches2 = array_alloc(char *, 0); |
---|
| 1231 | arrayForEachItem(Ntk_Node_t *, supports2, i, latch) { |
---|
| 1232 | if (Ntk_NodeTestIsLatch(latch) && |
---|
| 1233 | !st_is_member(oldSupportTable,latch)) |
---|
| 1234 | array_insert_last(char *, supportLatches2, Ntk_NodeReadName(latch)); |
---|
| 1235 | } |
---|
| 1236 | array_free(supports2); |
---|
| 1237 | |
---|
| 1238 | arrayForEachItem(char *, latchNameArray, i, latchName) { |
---|
| 1239 | if (i < beginPosition) continue; |
---|
| 1240 | latch = Ntk_NetworkFindNodeByName(network, latchName); |
---|
| 1241 | if (!st_is_member(oldSupportTable, latch)) |
---|
| 1242 | array_insert_last(char *, supportLatches2, latchName); |
---|
| 1243 | } |
---|
| 1244 | st_free_table(oldSupportTable); |
---|
| 1245 | |
---|
| 1246 | return supportLatches2; |
---|
| 1247 | } |
---|
| 1248 | |
---|
| 1249 | |
---|
| 1250 | /**Function******************************************************************** |
---|
| 1251 | |
---|
| 1252 | Synopsis [Dump out clauses to a file] |
---|
| 1253 | |
---|
| 1254 | Description [Dump out clauses to a file] |
---|
| 1255 | |
---|
| 1256 | SideEffects [] |
---|
| 1257 | |
---|
| 1258 | SeeAlso [] |
---|
| 1259 | |
---|
| 1260 | ******************************************************************************/ |
---|
| 1261 | void PureSatWriteClausesToFile(PureSat_IncreSATManager_t * pism, |
---|
| 1262 | mAig_Manager_t *maigManager, |
---|
| 1263 | char *coreFile) |
---|
| 1264 | { |
---|
| 1265 | |
---|
| 1266 | BmcCnfClauses_t *cnfClauses = pism->cnfClauses; |
---|
| 1267 | st_generator *stGen; |
---|
| 1268 | char *name; |
---|
| 1269 | int cnfIndex, i, k; |
---|
| 1270 | FILE *cnfFile; |
---|
| 1271 | |
---|
| 1272 | coreFile = BmcCreateTmpFile(); |
---|
| 1273 | cnfFile = fopen(coreFile,"w"); |
---|
| 1274 | |
---|
| 1275 | fprintf(vis_stdout, "coreFile is %s\n", coreFile); |
---|
| 1276 | fprintf(vis_stdout, |
---|
| 1277 | "Number of Variables = %d Number of Clauses = %d\n", |
---|
| 1278 | cnfClauses->cnfGlobalIndex-1, cnfClauses->noOfClauses); |
---|
| 1279 | |
---|
| 1280 | |
---|
| 1281 | st_foreach_item_int(cnfClauses->cnfIndexTable, stGen, &name, &cnfIndex) { |
---|
| 1282 | fprintf(cnfFile, "c %s %d\n",name, cnfIndex); |
---|
| 1283 | } |
---|
| 1284 | (void) fprintf(cnfFile, "p cnf %d %d\n", cnfClauses->cnfGlobalIndex-1, |
---|
| 1285 | cnfClauses->noOfClauses); |
---|
| 1286 | if (cnfClauses->clauseArray != NIL(array_t)) { |
---|
| 1287 | for (i = 0; i < cnfClauses->nextIndex; i++) { |
---|
| 1288 | k = array_fetch(int, cnfClauses->clauseArray, i); |
---|
| 1289 | (void) fprintf(cnfFile, "%d%c", k, (k == 0) ? '\n' : ' '); |
---|
| 1290 | } |
---|
| 1291 | } |
---|
| 1292 | fclose(cnfFile); |
---|
| 1293 | FREE(coreFile); |
---|
| 1294 | return; |
---|
| 1295 | } |
---|
| 1296 | |
---|
| 1297 | |
---|
| 1298 | /**Function******************************************************************** |
---|
| 1299 | |
---|
| 1300 | Synopsis [Dump out all the clauses, including conflict clauses, to a file] |
---|
| 1301 | |
---|
| 1302 | Description [Dump out all the clauses, including conflict clauses, to a file] |
---|
| 1303 | |
---|
| 1304 | SideEffects [] |
---|
| 1305 | |
---|
| 1306 | SeeAlso [] |
---|
| 1307 | |
---|
| 1308 | ******************************************************************************/ |
---|
| 1309 | |
---|
| 1310 | void PureSatWriteAllClausesToFile(PureSat_IncreSATManager_t * pism, |
---|
| 1311 | char *coreFile) |
---|
| 1312 | { |
---|
| 1313 | satManager_t *cm = pism->cm; |
---|
| 1314 | char *tmpallcnfFile = BmcCreateTmpFile(); |
---|
| 1315 | FILE *fp1 = fopen(coreFile,"r"); |
---|
| 1316 | FILE *fp2 = fopen(tmpallcnfFile,"w"); |
---|
| 1317 | char buffer[1024], buffer1[1024]; |
---|
| 1318 | long *space; |
---|
| 1319 | int i, numOfConCls=0, numOfVar, sign,var; |
---|
| 1320 | satArray_t *saved = cm->savedConflictClauses; |
---|
| 1321 | |
---|
| 1322 | for(i=0, space=saved->space; i<saved->num; i++,space++){ |
---|
| 1323 | if(*space<0) |
---|
| 1324 | numOfConCls++; |
---|
| 1325 | } |
---|
| 1326 | if(numOfConCls%2!=0){ |
---|
| 1327 | fprintf(vis_stdout,"should be times of 2\n"); |
---|
| 1328 | exit(0); |
---|
| 1329 | } |
---|
| 1330 | numOfConCls/=2; |
---|
| 1331 | |
---|
| 1332 | numOfConCls += cm->initNumClauses; |
---|
| 1333 | numOfVar = cm->initNumVariables; |
---|
| 1334 | i=0; |
---|
| 1335 | /*sprintf(buffer,"p cnf %d %d 0\n", numOfConCls, numOfVar); |
---|
| 1336 | fputs(buffer, fp2);*/ |
---|
| 1337 | while(fgets(buffer,1024,fp1)){ |
---|
| 1338 | if(strncmp(buffer,"c ",2)!=0){ |
---|
| 1339 | if(strncmp(buffer,"p cnf ",6)==0){ |
---|
| 1340 | sprintf(buffer1,"p cnf %d %d 0\n", numOfVar, numOfConCls); |
---|
| 1341 | fputs(buffer1, fp2); |
---|
| 1342 | } |
---|
| 1343 | else |
---|
| 1344 | fputs(buffer, fp2); |
---|
| 1345 | } |
---|
| 1346 | } |
---|
| 1347 | |
---|
| 1348 | saved = cm->savedConflictClauses; |
---|
| 1349 | |
---|
| 1350 | for(i=0, space=saved->space; i<saved->num; i++){ |
---|
| 1351 | if(*space<0){ |
---|
| 1352 | space++; |
---|
| 1353 | i++; |
---|
| 1354 | while(*space>0){ |
---|
| 1355 | sign = !SATisInverted(*space); |
---|
| 1356 | var = SATnormalNode(*space); |
---|
| 1357 | if(sign == 0) |
---|
| 1358 | var = -var; |
---|
| 1359 | fprintf(fp2,"%d ",var); |
---|
| 1360 | space++; |
---|
| 1361 | i++; |
---|
| 1362 | } |
---|
| 1363 | fprintf(fp2,"0\n"); |
---|
| 1364 | space++; |
---|
| 1365 | i++; |
---|
| 1366 | } |
---|
| 1367 | } |
---|
| 1368 | fclose(fp1); |
---|
| 1369 | fclose(fp2); |
---|
| 1370 | FREE(tmpallcnfFile); |
---|
| 1371 | } |
---|
| 1372 | |
---|
| 1373 | |
---|
| 1374 | |
---|
| 1375 | /**Function******************************************************************** |
---|
| 1376 | |
---|
| 1377 | Synopsis [Generate refinement latches from UNSAT proof] |
---|
| 1378 | |
---|
| 1379 | Description [Generate refinement latches from UNSAT proof] |
---|
| 1380 | |
---|
| 1381 | SideEffects [] |
---|
| 1382 | |
---|
| 1383 | SeeAlso [] |
---|
| 1384 | |
---|
| 1385 | ******************************************************************************/ |
---|
| 1386 | |
---|
| 1387 | array_t * PureSatGetLatchFromTable(Ntk_Network_t *network, |
---|
| 1388 | PureSat_Manager_t * pm, |
---|
| 1389 | char *coreFile) |
---|
| 1390 | { |
---|
| 1391 | FILE *fp; |
---|
| 1392 | char buffer[1024],*nodeName; |
---|
| 1393 | int idx; |
---|
| 1394 | st_table * localTable = st_init_table(strcmp,st_strhash); |
---|
| 1395 | array_t * refinement = array_alloc(char *,0); |
---|
| 1396 | st_table *ClsidxToLatchTable = pm->ClsidxToLatchTable; |
---|
| 1397 | st_table *vertexTable = pm->vertexTable; |
---|
| 1398 | |
---|
| 1399 | fp = fopen(coreFile,"r"); |
---|
| 1400 | while(fgets(buffer,1024,fp)){ |
---|
| 1401 | if(strncmp(buffer,"#clause index:",14)==0){ |
---|
| 1402 | sscanf(buffer,"#clause index:%d\n",&idx); |
---|
| 1403 | if(st_lookup(ClsidxToLatchTable,(char *)(long)idx,&nodeName)) |
---|
| 1404 | if(!st_lookup(vertexTable,nodeName,NIL(char *))&&!st_lookup(localTable,nodeName,NIL(char *))) |
---|
| 1405 | { |
---|
| 1406 | st_insert(localTable,nodeName,(char *)0); |
---|
| 1407 | array_insert_last(char *,refinement,nodeName); |
---|
| 1408 | } |
---|
| 1409 | } |
---|
| 1410 | } |
---|
| 1411 | st_free_table(localTable); |
---|
| 1412 | return refinement; |
---|
| 1413 | } |
---|
| 1414 | |
---|
| 1415 | |
---|
| 1416 | |
---|
| 1417 | /**Function******************************************************************** |
---|
| 1418 | |
---|
| 1419 | Synopsis [remove the ith member of a certain array] |
---|
| 1420 | |
---|
| 1421 | Description [remove the ith member of a certain array] |
---|
| 1422 | |
---|
| 1423 | SideEffects [] |
---|
| 1424 | |
---|
| 1425 | SeeAlso [] |
---|
| 1426 | |
---|
| 1427 | ******************************************************************************/ |
---|
| 1428 | |
---|
| 1429 | |
---|
| 1430 | array_t * PureSatRemove_char(array_t * array1, int i) |
---|
| 1431 | { |
---|
| 1432 | int j; |
---|
| 1433 | char * str; |
---|
| 1434 | array_t * array2=array_alloc(char *,0); |
---|
| 1435 | assert(i<array_n(array1)); |
---|
| 1436 | arrayForEachItem(char *,array1,j,str) |
---|
| 1437 | { |
---|
| 1438 | if(j!=i) |
---|
| 1439 | { |
---|
| 1440 | |
---|
| 1441 | array_insert_last(char *,array2,str); |
---|
| 1442 | } |
---|
| 1443 | } |
---|
| 1444 | return array2; |
---|
| 1445 | } |
---|
| 1446 | |
---|
| 1447 | |
---|
| 1448 | /**Function******************************************************************** |
---|
| 1449 | |
---|
| 1450 | Synopsis [For one node: count number of gates and how many of them are already in abstraction] |
---|
| 1451 | |
---|
| 1452 | Description [] |
---|
| 1453 | |
---|
| 1454 | SideEffects [] |
---|
| 1455 | |
---|
| 1456 | SeeAlso [] |
---|
| 1457 | |
---|
| 1458 | ******************************************************************************/ |
---|
| 1459 | |
---|
| 1460 | void PureSatComputeNumGatesInAbsForNode(Ntk_Network_t * network, |
---|
| 1461 | PureSat_Manager_t * pm, |
---|
| 1462 | Ntk_Node_t * node, |
---|
| 1463 | st_table * visited, |
---|
| 1464 | int * ct, |
---|
| 1465 | int * ct1) |
---|
| 1466 | { |
---|
| 1467 | int i; |
---|
| 1468 | Ntk_Node_t *fanin; |
---|
| 1469 | |
---|
| 1470 | |
---|
| 1471 | st_insert(visited,node,(char *)0); |
---|
| 1472 | |
---|
| 1473 | (*ct1)++; |
---|
| 1474 | if(st_lookup(pm->AbsTable,node,NIL(char*))) |
---|
| 1475 | (*ct)++; |
---|
| 1476 | |
---|
| 1477 | if(Ntk_NodeTestIsCombInput(node)) |
---|
| 1478 | return; |
---|
| 1479 | |
---|
| 1480 | Ntk_NodeForEachFanin(node,i,fanin){ |
---|
| 1481 | if(!st_lookup(visited,(char *)fanin,NIL(char *))&& |
---|
| 1482 | !Ntk_NodeTestIsLatch(fanin)) |
---|
| 1483 | PureSatComputeNumGatesInAbsForNode(network,pm,fanin,visited,ct,ct1); |
---|
| 1484 | } |
---|
| 1485 | return; |
---|
| 1486 | |
---|
| 1487 | } |
---|
| 1488 | |
---|
| 1489 | |
---|
| 1490 | /**Function******************************************************************** |
---|
| 1491 | |
---|
| 1492 | Synopsis [For nodes in one array: count number of gates and how many of |
---|
| 1493 | them are already in abstraction] |
---|
| 1494 | |
---|
| 1495 | Description [] |
---|
| 1496 | |
---|
| 1497 | SideEffects [] |
---|
| 1498 | |
---|
| 1499 | SeeAlso [] |
---|
| 1500 | |
---|
| 1501 | ******************************************************************************/ |
---|
| 1502 | |
---|
| 1503 | void PureSatComputeNumGatesInAbs(Ntk_Network_t *network, |
---|
| 1504 | PureSat_Manager_t *pm, |
---|
| 1505 | array_t * invisibleArray) |
---|
| 1506 | { |
---|
| 1507 | int i,ct,ct1,j; |
---|
| 1508 | char * name; |
---|
| 1509 | Ntk_Node_t * node,*fanin; |
---|
| 1510 | st_table * visited; |
---|
| 1511 | |
---|
| 1512 | |
---|
| 1513 | arrayForEachItem(char*,invisibleArray,i,name){ |
---|
| 1514 | node = Ntk_NetworkFindNodeByName(network,name); |
---|
| 1515 | ct = 0; |
---|
| 1516 | ct1 = 0; |
---|
| 1517 | visited = st_init_table(st_ptrcmp,st_ptrhash); |
---|
| 1518 | st_insert(visited,node,(char *)0); |
---|
| 1519 | |
---|
| 1520 | ct1++; |
---|
| 1521 | |
---|
| 1522 | Ntk_NodeForEachFanin(node,j,fanin){ |
---|
| 1523 | if(!st_lookup(visited,(char *)fanin,NIL(char *))&& |
---|
| 1524 | !Ntk_NodeTestIsLatch(fanin)) |
---|
| 1525 | PureSatComputeNumGatesInAbsForNode(network,pm, |
---|
| 1526 | fanin,visited,&ct,&ct1); |
---|
| 1527 | } |
---|
| 1528 | st_insert(pm->niaTable,name,(char*)(long)ct); |
---|
| 1529 | |
---|
| 1530 | st_free_table(visited); |
---|
| 1531 | } |
---|
| 1532 | return; |
---|
| 1533 | |
---|
| 1534 | } |
---|
| 1535 | |
---|
| 1536 | |
---|
| 1537 | /**Function******************************************************************** |
---|
| 1538 | |
---|
| 1539 | Synopsis [For one node: count how many nodes are in its cone] |
---|
| 1540 | |
---|
| 1541 | Description [] |
---|
| 1542 | |
---|
| 1543 | SideEffects [] |
---|
| 1544 | |
---|
| 1545 | SeeAlso [] |
---|
| 1546 | |
---|
| 1547 | ******************************************************************************/ |
---|
| 1548 | |
---|
| 1549 | void PureSatComputeNumGatesInConeForNode(Ntk_Network_t * network, |
---|
| 1550 | PureSat_Manager_t * pm, |
---|
| 1551 | Ntk_Node_t * node, |
---|
| 1552 | st_table * visited, |
---|
| 1553 | int * ct) |
---|
| 1554 | { |
---|
| 1555 | int i; |
---|
| 1556 | Ntk_Node_t *fanin; |
---|
| 1557 | |
---|
| 1558 | |
---|
| 1559 | st_insert(visited,node,(char *)0); |
---|
| 1560 | |
---|
| 1561 | (*ct)++; |
---|
| 1562 | |
---|
| 1563 | if(Ntk_NodeTestIsCombInput(node)) |
---|
| 1564 | return; |
---|
| 1565 | |
---|
| 1566 | Ntk_NodeForEachFanin(node,i,fanin){ |
---|
| 1567 | if(!st_lookup(visited,(char *)fanin,NIL(char *))&& |
---|
| 1568 | !Ntk_NodeTestIsLatch(fanin)) |
---|
| 1569 | PureSatComputeNumGatesInConeForNode(network,pm,fanin,visited,ct); |
---|
| 1570 | } |
---|
| 1571 | return; |
---|
| 1572 | |
---|
| 1573 | } |
---|
| 1574 | |
---|
| 1575 | |
---|
| 1576 | /**Function******************************************************************** |
---|
| 1577 | |
---|
| 1578 | Synopsis [For each node in one array: count how many nodes are in its cone] |
---|
| 1579 | |
---|
| 1580 | Description [] |
---|
| 1581 | |
---|
| 1582 | SideEffects [] |
---|
| 1583 | |
---|
| 1584 | SeeAlso [] |
---|
| 1585 | |
---|
| 1586 | ******************************************************************************/ |
---|
| 1587 | |
---|
| 1588 | void PureSatComputeNumGatesInCone(Ntk_Network_t *network, |
---|
| 1589 | PureSat_Manager_t *pm, |
---|
| 1590 | array_t * latchArray) |
---|
| 1591 | { |
---|
| 1592 | int i,ct,j; |
---|
| 1593 | char * name; |
---|
| 1594 | Ntk_Node_t * node,* fanin; |
---|
| 1595 | st_table * visited; |
---|
| 1596 | |
---|
| 1597 | |
---|
| 1598 | arrayForEachItem(char*,latchArray,i,name){ |
---|
| 1599 | node = Ntk_NetworkFindNodeByName(network,name); |
---|
| 1600 | ct = 0; |
---|
| 1601 | visited = st_init_table(st_ptrcmp,st_ptrhash); |
---|
| 1602 | st_insert(visited,node,(char *)0); |
---|
| 1603 | ct++; |
---|
| 1604 | |
---|
| 1605 | Ntk_NodeForEachFanin(node,j,fanin){ |
---|
| 1606 | if(!st_lookup(visited,(char *)fanin,NIL(char *))&& |
---|
| 1607 | !Ntk_NodeTestIsLatch(fanin)) |
---|
| 1608 | PureSatComputeNumGatesInConeForNode(network,pm |
---|
| 1609 | ,fanin,visited,&ct); |
---|
| 1610 | } |
---|
| 1611 | st_insert(pm->nicTable,name,(char*)(long)ct); |
---|
| 1612 | |
---|
| 1613 | st_free_table(visited); |
---|
| 1614 | } |
---|
| 1615 | return; |
---|
| 1616 | |
---|
| 1617 | } |
---|
| 1618 | |
---|
| 1619 | |
---|
| 1620 | /**Function******************************************************************** |
---|
| 1621 | |
---|
| 1622 | Synopsis [Generate latch candidate array based on BFS ring and RC information] |
---|
| 1623 | |
---|
| 1624 | Description [] |
---|
| 1625 | |
---|
| 1626 | SideEffects [] |
---|
| 1627 | |
---|
| 1628 | SeeAlso [] |
---|
| 1629 | |
---|
| 1630 | ******************************************************************************/ |
---|
| 1631 | |
---|
| 1632 | array_t * PureSatGenerateRCArray_2(Ntk_Network_t *network, |
---|
| 1633 | PureSat_Manager_t *pm, |
---|
| 1634 | array_t *invisibleArray, |
---|
| 1635 | int *NumInSecondLevel) |
---|
| 1636 | { |
---|
| 1637 | array_t * tmpRCArray = array_alloc(double,0); |
---|
| 1638 | array_t * tmpDfsArray = array_alloc(int,0); |
---|
| 1639 | array_t * arrayRC = array_alloc(char*,array_n(invisibleArray)); |
---|
| 1640 | int i,j; |
---|
| 1641 | char * name; |
---|
| 1642 | |
---|
| 1643 | if(pm->RefPredict) |
---|
| 1644 | pm->latchArray = array_alloc(char *,0); |
---|
| 1645 | |
---|
| 1646 | PureSatComputeNumGatesInAbs(network,pm,invisibleArray); |
---|
| 1647 | |
---|
| 1648 | for(i=0;i<array_n(invisibleArray);i++){ |
---|
| 1649 | int nic,nia,dfs; |
---|
| 1650 | Ntk_Node_t *tmpnode; |
---|
| 1651 | int retVal; |
---|
| 1652 | name = array_fetch(char *,invisibleArray,i); |
---|
| 1653 | tmpnode = Ntk_NetworkFindNodeByName(network,name); |
---|
| 1654 | retVal = st_lookup(pm->node2dfsTable,name,&dfs); |
---|
| 1655 | assert(retVal); |
---|
| 1656 | array_insert_last(int,tmpDfsArray,dfs); |
---|
| 1657 | retVal = st_lookup(pm->nicTable,name,&nic); |
---|
| 1658 | assert(retVal); |
---|
| 1659 | retVal = st_lookup(pm->niaTable,name,&nia); |
---|
| 1660 | assert(retVal); |
---|
| 1661 | array_insert_last(double,tmpRCArray, |
---|
| 1662 | (double)nia/(double)nic); |
---|
| 1663 | } |
---|
| 1664 | |
---|
| 1665 | |
---|
| 1666 | DfsArray = tmpDfsArray; |
---|
| 1667 | RCArray = tmpRCArray; |
---|
| 1668 | *NumInSecondLevel = 0; |
---|
| 1669 | |
---|
| 1670 | { |
---|
| 1671 | int tmpvalue; |
---|
| 1672 | double rcvalue; |
---|
| 1673 | int nn = array_n(invisibleArray); |
---|
| 1674 | int *tay=ALLOC(int,nn); |
---|
| 1675 | for(j=0;j<nn;j++) |
---|
| 1676 | tay[j]=j; |
---|
| 1677 | qsort((void *)tay, nn, sizeof(int), |
---|
| 1678 | (int (*)(const void *, const void *))NumInConeCompare_Ring); |
---|
| 1679 | for(i=0;i<nn;i++) |
---|
| 1680 | { |
---|
| 1681 | name = array_fetch(char *,invisibleArray,tay[i]); |
---|
| 1682 | array_insert(char *,arrayRC,i,name); |
---|
| 1683 | tmpvalue = array_fetch(int,tmpDfsArray,tay[i]); |
---|
| 1684 | if(tmpvalue == 2) |
---|
| 1685 | (*NumInSecondLevel)++; |
---|
| 1686 | rcvalue = array_fetch(double,tmpRCArray,tay[i]); |
---|
| 1687 | if(pm->verbosity>=1) |
---|
| 1688 | fprintf(vis_stdout,"arrayRC %s: %f-%f = %f\n",name, |
---|
| 1689 | (double)tmpvalue*1000000,rcvalue,(double)tmpvalue*1000000-rcvalue); |
---|
| 1690 | |
---|
| 1691 | if(pm->RefPredict){ |
---|
| 1692 | if(rcvalue>=0.87&&tmpvalue==2){ |
---|
| 1693 | array_insert_last(char*,pm->latchArray,name); |
---|
| 1694 | if(pm->verbosity>=1) |
---|
| 1695 | fprintf(vis_stdout,"add %s into pm->latchArray\n",name); |
---|
| 1696 | } |
---|
| 1697 | } |
---|
| 1698 | |
---|
| 1699 | } |
---|
| 1700 | FREE(tay); |
---|
| 1701 | } |
---|
| 1702 | |
---|
| 1703 | array_free(DfsArray); |
---|
| 1704 | array_free(RCArray); |
---|
| 1705 | |
---|
| 1706 | return arrayRC; |
---|
| 1707 | } |
---|
| 1708 | |
---|
| 1709 | /*---------------------------------------------------------------------------*/ |
---|
| 1710 | /* Definition of static functions */ |
---|
| 1711 | /*---------------------------------------------------------------------------*/ |
---|