VIS
|
00001 00049 #include "puresatInt.h" 00050 00051 /*---------------------------------------------------------------------------*/ 00052 /* Constant declarations */ 00053 /*---------------------------------------------------------------------------*/ 00054 00055 /*---------------------------------------------------------------------------*/ 00056 /* Type declarations */ 00057 /*---------------------------------------------------------------------------*/ 00058 00059 00060 /*---------------------------------------------------------------------------*/ 00061 /* Structure declarations */ 00062 /*---------------------------------------------------------------------------*/ 00063 00064 00065 /*---------------------------------------------------------------------------*/ 00066 /* Variable declarations */ 00067 /*---------------------------------------------------------------------------*/ 00068 00069 /*---------------------------------------------------------------------------*/ 00070 /* Macro declarations */ 00071 /*---------------------------------------------------------------------------*/ 00072 00075 /*---------------------------------------------------------------------------*/ 00076 /* Static function prototypes */ 00077 /*---------------------------------------------------------------------------*/ 00078 00079 00082 /*---------------------------------------------------------------------------*/ 00083 /* Definition of exported functions */ 00084 /*---------------------------------------------------------------------------*/ 00085 00086 00087 /*---------------------------------------------------------------------------*/ 00088 /* Definition of internal functions */ 00089 /*---------------------------------------------------------------------------*/ 00090 00115 static int 00116 NodeIndexCompare(const void *x, const void *y) 00117 { 00118 int n1, n2; 00119 00120 n1 = *(int *)x; 00121 n2 = *(int *)y; 00122 return(n1 > n2); 00123 } 00124 00137 static int 00138 StringCheckIsInteger( 00139 char *string, 00140 int *value) 00141 { 00142 char *ptr; 00143 long l; 00144 00145 l = strtol (string, &ptr, 0) ; 00146 if(*ptr != '\0') 00147 return 0; 00148 if ((l > MAXINT) || (l < -1 - MAXINT)) 00149 return 1 ; 00150 *value = (int) l; 00151 return 2 ; 00152 } 00153 00154 00157 /*---------------------------------------------------------------------------*/ 00158 /* Definition of exported functions */ 00159 /*---------------------------------------------------------------------------*/ 00173 RTnode_t RTCreateNode(RTManager_t * rm) 00174 { 00175 RTnode_t node; 00176 00177 if(rm->nArray==0){ 00178 rm->nArray = ALLOC(long, RTnodeSize*RT_BLOCK); 00179 rm->maxSize = RTnodeSize*RT_BLOCK; 00180 rm->aSize = 0; 00181 } 00182 00183 if(rm->maxSize<=rm->aSize+RTnodeSize){ 00184 rm->nArray = REALLOC(long, rm->nArray,rm->maxSize+RTnodeSize*RT_BLOCK); 00185 if(rm->nArray == 0){ 00186 fprintf(vis_stdout,"memout when alloc %ld bytes\n", 00187 (rm->maxSize+RTnodeSize*RT_BLOCK)*4); 00188 exit(0); 00189 } 00190 rm->maxSize = rm->maxSize+RTnodeSize*1000; 00191 } 00192 rm->aSize += RTnodeSize; 00193 node = rm->aSize; 00194 00195 RT_fSize(node) = 0; 00196 RT_formula(node) = 0; 00197 RT_oriClsIdx(node) = 0; 00198 RT_pivot(node) = 0; 00199 RT_flag(node) = 0; 00200 RT_IPnode(node) = -1; 00201 RT_left(node) = 0; 00202 RT_right(node) = 0; 00203 00204 if(rm->fArray==0){ 00205 rm->fArray = ALLOC(long,FORMULA_BLOCK); 00206 00207 rm->cpos = 0; 00208 rm->maxpos = FORMULA_BLOCK; 00209 } 00210 00211 return node; 00212 } 00213 00227 IP_Manager_t * IPManagerAlloc() 00228 { 00229 IP_Manager_t * ipm = ALLOC(IP_Manager_t, 1); 00230 memset(ipm,0,sizeof(IP_Manager_t)); 00231 return ipm; 00232 } 00233 00234 00248 void IPManagerFree(IP_Manager_t *ipm) 00249 { 00250 FREE(ipm); 00251 } 00252 00277 int PureSat_IdentifyConflict( 00278 satManager_t *cm, 00279 long left, 00280 bAigEdge_t right, 00281 bAigEdge_t node) 00282 { 00283 int result; /*1:left 2:right 3:both*/ 00284 int value = SATgetValue(left,right,node); 00285 switch(value){ 00286 case 1: 00287 case 5: 00288 case 9: 00289 case 13: 00290 result = 1; 00291 break; 00292 case 17: 00293 case 33: 00294 case 49: 00295 result = 2; 00296 break; 00297 case 20: 00298 result = 3; 00299 break; 00300 default: 00301 fprintf(vis_stdout,"can't identify the conflict, exit\n"); 00302 exit(0); 00303 } 00304 00305 return result; 00306 } 00307 00321 void 00322 PureSatBmcGetCoiForNtkNode_New( 00323 Ntk_Node_t *node, 00324 st_table *CoiTable, 00325 st_table *visited) 00326 { 00327 int i; 00328 Ntk_Node_t *faninNode; 00329 00330 if(node == NIL(Ntk_Node_t)){ 00331 return; 00332 } 00333 00334 00335 if (st_lookup_int(visited, (char *) node, NIL(int))){ 00336 return; 00337 } 00338 st_insert(visited, (char *) node, (char *) 0); 00339 00340 if(Ntk_NodeTestIsInput(node)) 00341 return; 00342 00343 if (Ntk_NodeTestIsLatch(node)){ 00344 st_insert(CoiTable, (char *) node, (char *)0); 00345 } 00346 00347 Ntk_NodeForEachFanin(node, i, faninNode) { 00348 PureSatBmcGetCoiForNtkNode_New(faninNode, CoiTable, visited); 00349 } 00350 00351 return; 00352 } 00353 00366 void 00367 PureSatBmcGetCoiForLtlFormulaRecursive_New( 00368 Ntk_Network_t *network, 00369 Ctlsp_Formula_t *formula, 00370 st_table *ltlCoiTable, 00371 st_table *visited) 00372 { 00373 if (formula == NIL(Ctlsp_Formula_t)) { 00374 return; 00375 } 00376 /* leaf node */ 00377 if (formula->type == Ctlsp_ID_c){ 00378 char *name = Ctlsp_FormulaReadVariableName(formula); 00379 Ntk_Node_t *node = Ntk_NetworkFindNodeByName(network, name); 00380 int tmp; 00381 00382 if (st_lookup_int(visited, (char *) node, &tmp)){ 00383 /* Node already visited */ 00384 return; 00385 } 00386 PureSatBmcGetCoiForNtkNode_New(node, ltlCoiTable, visited); 00387 return; 00388 } 00389 PureSatBmcGetCoiForLtlFormulaRecursive_New(network, formula->left, ltlCoiTable, visited); 00390 PureSatBmcGetCoiForLtlFormulaRecursive_New(network, formula->right, ltlCoiTable, visited); 00391 00392 return; 00393 } 00394 00407 void 00408 PureSatBmcGetCoiForLtlFormula_New( 00409 Ntk_Network_t *network, 00410 Ctlsp_Formula_t *formula, 00411 st_table *ltlCoiTable) 00412 { 00413 st_table *visited = st_init_table(st_ptrcmp, st_ptrhash); 00414 00415 PureSatBmcGetCoiForLtlFormulaRecursive_New(network, formula, ltlCoiTable, visited); 00416 st_free_table(visited); 00417 return; 00418 } /* BmcGetCoiForLtlFormula() */ 00419 00420 00434 void PureSat_MarkTransitiveFaninForNode( 00435 satManager_t *cm, 00436 bAigEdge_t v, 00437 unsigned int mask) 00438 { 00439 if(v == bAig_NULL) return; 00440 00441 v = SATnormalNode(v); 00442 00443 if(SATflags(v) & mask) return; 00444 00445 SATflags(v) |= mask; 00446 if(SATflags(v) & Visited3Mask) return; 00447 00448 PureSat_MarkTransitiveFaninForNode(cm, SATleftChild(v), mask); 00449 PureSat_MarkTransitiveFaninForNode(cm, SATrightChild(v), mask); 00450 } 00451 00465 void PureSat_MarkTransitiveFaninForArray( 00466 satManager_t *cm, 00467 satArray_t *arr, 00468 unsigned int mask) 00469 { 00470 int i, size; 00471 bAigEdge_t v; 00472 00473 if(arr == 0) return; 00474 size = arr->num; 00475 00476 for(i=0; i<size; i++) { 00477 v = arr->space[i]; 00478 PureSat_MarkTransitiveFaninForNode(cm, v, mask); 00479 } 00480 } 00481 00494 void PureSat_MarkTransitiveFaninForNode2( 00495 mAig_Manager_t *manager, 00496 bAigEdge_t v, 00497 unsigned int mask) 00498 { 00499 if(v == bAig_NULL) return; 00500 00501 v = SATnormalNode(v); 00502 00503 if(flags(v) & mask) return; 00504 00505 flags(v) |= mask; 00506 if(flags(v) & Visited3Mask) return; 00507 00508 PureSat_MarkTransitiveFaninForNode2(manager, leftChild(v), mask); 00509 PureSat_MarkTransitiveFaninForNode2(manager, rightChild(v), mask); 00510 } 00511 00525 void PureSat_MarkTransitiveFaninForArray2( 00526 mAig_Manager_t *manager, 00527 satArray_t *arr, 00528 unsigned int mask) 00529 { 00530 bAigEdge_t v; 00531 int i, size; 00532 00533 if(arr == 0) return; 00534 size = arr->num; 00535 00536 for(i=0; i<size; i++) { 00537 v = arr->space[i]; 00538 PureSat_MarkTransitiveFaninForNode2(manager, v, mask); 00539 } 00540 } 00541 00556 void PureSat_MarkTransitiveFaninForNode3( 00557 mAig_Manager_t *manager, 00558 bAigEdge_t v, 00559 unsigned int mask) 00560 { 00561 if(v == 2) return; 00562 00563 v = SATnormalNode(v); 00564 00565 if(flags(v) & mask) return; 00566 00567 flags(v) |= mask; 00568 00569 PureSat_MarkTransitiveFaninForNode3(manager, leftChild(v), mask); 00570 PureSat_MarkTransitiveFaninForNode3(manager, rightChild(v), mask); 00571 } 00572 00585 void PureSat_MarkTransitiveFaninForArray3( 00586 mAig_Manager_t *manager, 00587 satArray_t *arr, 00588 unsigned int mask) 00589 { 00590 bAigEdge_t v; 00591 int i, size; 00592 00593 if(arr == 0) return; 00594 size = arr->num; 00595 00596 for(i=0; i<size; i++) { 00597 v = arr->space[i]; 00598 PureSat_MarkTransitiveFaninForNode3(manager, v, mask); 00599 } 00600 } 00601 00602 00616 void PureSat_MarkTransitiveFaninForNode4( 00617 mAig_Manager_t *manager, 00618 bAigEdge_t v, 00619 unsigned int mask, 00620 int bound) 00621 { 00622 if(v == bAig_NULL) return; 00623 00624 v = SATnormalNode(v); 00625 00626 if(flags(v) & mask) return; 00627 00628 flags(v) |= mask; 00629 00630 if((flags(v)&StateBitMask)&& 00631 !(flags(v)&VisibleVarMask)&& 00632 (bAig_Class(v)>0)){ 00633 00634 return; 00635 } 00636 00637 PureSat_MarkTransitiveFaninForNode4(manager, leftChild(v), mask,bound); 00638 PureSat_MarkTransitiveFaninForNode4(manager, rightChild(v), mask,bound); 00639 } 00640 00653 void PureSat_MarkTransitiveFaninForArray4( 00654 mAig_Manager_t *manager, 00655 satArray_t *arr, 00656 unsigned int mask, 00657 int bound) 00658 { 00659 bAigEdge_t v; 00660 int i, size; 00661 00662 if(arr == 0) return; 00663 size = arr->num; 00664 00665 for(i=0; i<size; i++) { 00666 v = arr->space[i]; 00667 00668 v = SATnormalNode(v); 00669 PureSat_MarkTransitiveFaninForNode4(manager,v,mask,bound); 00670 00671 } 00672 } 00673 00688 void PureSat_CleanMask(mAig_Manager_t *manager, 00689 unsigned int mask) 00690 { 00691 bAigEdge_t i; 00692 00693 for(i=bAigNodeSize; i<manager->nodesArraySize;i+=bAigNodeSize) 00694 flags(i)&=mask; 00695 00696 } 00697 00711 void PureSat_SetCOI(satManager_t *cm) 00712 { 00713 00714 PureSat_MarkTransitiveFaninForArray(cm, cm->auxObj, CoiMask); 00715 PureSat_MarkTransitiveFaninForArray(cm, cm->obj, CoiMask); 00716 PureSat_MarkTransitiveFaninForArray(cm, cm->assertArray, CoiMask); 00717 00718 } 00719 00720 00733 void PureSat_ResetCoi(satManager_t *cm) 00734 { 00735 bAigEdge_t i; 00736 for(i=satNodeSize;i<cm->nodesArraySize;i+=satNodeSize){ 00737 if(SATflags(i) & CoiMask) 00738 SATflags(i) &= ResetCoiMask; 00739 } 00740 } 00741 00754 void PureSatSetLatchCOI(Ntk_Network_t * network, 00755 PureSat_Manager_t *pm, 00756 satManager_t * cm, 00757 /*deletable*/ 00758 st_table * AbsTable, 00759 int from, 00760 int to) 00761 { 00762 00763 mAig_Manager_t * manager = Ntk_NetworkReadMAigManager(network); 00764 00765 bAigTimeFrame_t *tf = manager->timeframeWOI; 00766 int i,j; 00767 bAigEdge_t *L0,*L1,*bL0,*bL1; 00768 satArray_t * assert; 00769 int nLatches = tf->nLatches, nbLatches = tf->nbLatches; 00770 00771 if(from>=to) return; 00772 00773 PureSat_ResetCoi(cm); 00774 00775 assert = sat_ArrayAlloc(1); 00776 sat_ArrayInsert(assert,manager->InitState); 00777 PureSat_MarkTransitiveFaninForArray3(manager,assert,CoiMask); 00778 sat_ArrayFree(assert); 00779 00780 for(i=from; i<to; i++){ 00781 assert = sat_ArrayAlloc(1); 00782 00783 L0 = tf->latchInputs[i]; 00784 L1 = tf->latchInputs[i+1]; 00785 bL0 = tf->blatchInputs[i]; 00786 bL1 = tf->blatchInputs[i+1]; 00787 00788 for(j=0;j<nLatches;j++){ 00789 if(L1[j]!=bAig_One&&L1[j]!=bAig_Zero){ 00790 if(flags(L1[j])&VisibleVarMask) 00791 sat_ArrayInsert(assert,L1[j]); 00792 } 00793 if(L0[j]!=bAig_One&&L0[j]!=bAig_Zero&& 00794 !(flags(L0[j])&VisibleVarMask)) 00795 flags(L0[j]) |= Visited3Mask; 00796 } 00797 00798 for(j=0;j<nbLatches;j++){ 00799 if(bL1[j]!=bAig_One&&bL1[j]!=bAig_Zero){ 00800 if(flags(bL1[j])&VisibleVarMask) 00801 sat_ArrayInsert(assert,bL1[j]); 00802 } 00803 if(bL0[j]!=bAig_One&&bL0[j]!=bAig_Zero&& 00804 !(flags(bL0[j])&VisibleVarMask)) 00805 flags(bL0[j]) |= Visited3Mask; 00806 } 00807 00808 PureSat_MarkTransitiveFaninForArray2(manager,assert,CoiMask); 00809 sat_ArrayFree(assert); 00810 } 00811 00812 } 00813 00827 void PureSatSetLatchCOI2(Ntk_Network_t * network, 00828 PureSat_Manager_t *pm, 00829 satManager_t * cm, 00830 bAigEdge_t obj, 00831 int bound) 00832 { 00833 00834 mAig_Manager_t * manager = Ntk_NetworkReadMAigManager(network); 00835 satArray_t * assert; 00836 00837 PureSat_ResetCoi(cm); 00838 00839 assert = sat_ArrayAlloc(1); 00840 sat_ArrayInsert(assert,obj); 00841 PureSat_MarkTransitiveFaninForArray4(manager,assert,CoiMask,bound); 00842 PureSat_MarkTransitiveFaninForArray4(manager,cm->assertArray,CoiMask,bound); 00843 sat_ArrayFree(assert); 00844 00845 } 00846 00859 void PureSatSetCOI(Ntk_Network_t * network, 00860 PureSat_Manager_t *pm, 00861 satManager_t * cm, 00862 st_table * AbsTable, 00863 int from, 00864 int to, 00865 int bound) 00866 { 00867 mAig_Manager_t * manager = Ntk_NetworkReadMAigManager(network); 00868 bAigEdge_t property; 00869 00870 if(cm->obj->num>0){ 00871 property = cm->obj->space[0]; 00872 PureSatSetLatchCOI2(network,pm,cm,property,bound); 00873 } 00874 else{ 00875 PureSatSetLatchCOI(network,pm,cm,AbsTable,from,to); 00876 PureSat_CleanMask(manager,ResetVisited3Mask); 00877 } 00878 00879 00880 } 00881 00894 void PureSatAbstractLatch(bAig_Manager_t *manager, 00895 bAigEdge_t v, 00896 st_table * tmpTable) 00897 { 00898 bAigEdge_t nv; 00899 00900 /*fanin: set left and right to bAig_NULL*/ 00901 nv = bAig_NonInvertedEdge(v); 00902 00903 if(leftChild(nv)!=bAig_NULL){ 00904 if(!(flags(leftChild(nv))&CoiMask)) 00905 flags(leftChild(nv)) |= Visited3Mask; 00906 manager->NodesArray[nv+bAigLeft]=bAig_NULL; 00907 } 00908 00909 if(rightChild(nv)!=bAig_NULL){ 00910 if(!(flags(rightChild(nv))&CoiMask)) 00911 flags(rightChild(nv)) |= Visited3Mask; 00912 manager->NodesArray[nv+bAigRight]=bAig_NULL; 00913 } 00914 00915 } 00916 00929 void PureSatKillPseudoGVNode(bAig_Manager_t *manager, 00930 bAigEdge_t v, 00931 st_table * tmpTable) 00932 { 00933 long size = nFanout(v),i,inv=0; 00934 bAigEdge_t v1,v2,nv; 00935 bAigEdge_t * fan = (bAigEdge_t *)fanout(v),left; 00936 00937 /*fanin: set left and right to bAig_NULL*/ 00938 nv = bAig_NonInvertedEdge(v); 00939 flags(nv) |= PGVMask; 00940 00941 if(leftChild(nv)!=bAig_NULL){ 00942 if(!(flags(leftChild(nv))&CoiMask)) 00943 flags(leftChild(nv)) |= Visited3Mask; 00944 manager->NodesArray[nv+bAigLeft]=bAig_NULL; 00945 } 00946 00947 if(rightChild(nv)!=bAig_NULL){ 00948 if(!(flags(rightChild(nv))&CoiMask)) 00949 flags(rightChild(nv)) |= Visited3Mask; 00950 manager->NodesArray[nv+bAigRight]=bAig_NULL; 00951 } 00952 00953 00954 manager->class_ = 2; 00955 00956 /*fanout: connection to vars in next tf is disconnected, and a new pseudo var 00957 is created, and used as a replacement*/ 00958 for(i=0;i<size;i++){ 00959 v1 = bAig_NonInvertedEdge(fan[i]>>1); 00960 if(!(flags(v1)&CoiMask)) 00961 continue; 00962 if(bAig_Class(v1)>1){ 00963 /*igonre invSV since its left and right will be processed to 2*/ 00964 if(!(flags(v1)&VisibleVarMask)&&(flags(v1)&StateBitMask)) 00965 continue; 00966 /*if nonSV, create new Node as replacement*/ 00967 if(!st_lookup(tmpTable,(char*)nv,&v2)){ 00968 v2 = bAig_CreateNode(manager,bAig_NULL, bAig_NULL); 00969 00970 flags(v2) |= DummyMask; 00971 st_insert(tmpTable,(char*)nv,(char*)v2); 00972 } 00973 00974 left = 1; 00975 if(bAig_IsInverted(fan[i])) 00976 left = 0; 00977 inv = bAig_IsInverted(fan[i]>>1)?1:0; 00978 v2 = inv ? bAig_Not(v2) : v2; 00979 if(left){ 00980 #if DBG 00981 assert(manager->NodesArray[v1+bAigLeft] != v2); 00982 #endif 00983 manager->NodesArray[v1+bAigLeft] = v2; 00984 PureSat_connectOutput(manager, v2, v1,0); 00985 flags(v2) |= CoiMask; 00986 } 00987 else{ 00988 #if DBG 00989 assert(manager->NodesArray[v1+bAigRight] != v2); 00990 #endif 00991 manager->NodesArray[v1+bAigRight] = v2; 00992 PureSat_connectOutput(manager, v2, v1,1); 00993 flags(v2) |= CoiMask; 00994 } 00995 } 00996 } 00997 00998 } 00999 01000 01013 void PureSatKillPseudoGV(Ntk_Network_t * network, 01014 PureSat_Manager_t *pm, 01015 st_table * AbsTable, 01016 int from, 01017 int to) 01018 { 01019 bAig_Manager_t * manager = Ntk_NetworkReadMAigManager(network); 01020 bAigTimeFrame_t *tf = manager->timeframeWOI; 01021 array_t *bVarList,*mVarList; 01022 bAigEdge_t * li, *bli,node; 01023 int i,j; 01024 st_table * tmpTable, *DoneTable; 01025 01026 01027 pm->oldPos = manager->nodesArraySize-bAigNodeSize; 01028 01029 bVarList = mAigReadBinVarList(manager); 01030 mVarList = mAigReadMulVarList(manager); 01031 01032 if(from < 1) 01033 from = 1; 01034 01035 if(to>pm->Length) 01036 to=pm->Length; 01037 01038 li = tf->latchInputs[1]; 01039 bli = tf->blatchInputs[1]; 01040 for(j=0;j<tf->nLatches;j++) 01041 flags(li[j])&=ResetPGVMask; 01042 for(j=0;j<tf->nbLatches;j++) 01043 flags(bli[j])&=ResetPGVMask; 01044 01045 for(i=from;i<=to;i++){ 01046 li = tf->latchInputs[i]; 01047 bli = tf->blatchInputs[i]; 01048 manager->class_ = i; 01049 tmpTable = st_init_table(st_numcmp,st_numhash); 01050 DoneTable = st_init_table(st_numcmp,st_numhash); 01051 01052 for(j=0; j<tf->nLatches; j++){ 01053 node = bAig_NonInvertedEdge(li[j]); 01054 if(st_lookup(DoneTable,(char*)node,NIL(char*))) 01055 continue; 01056 st_insert(DoneTable,(char*)node,(char*)0); 01057 if((flags(node)&StateBitMask)&& 01058 !(flags(node)&VisibleVarMask)&& 01059 (flags(node)&CoiMask)){ 01060 if(i==1) 01061 PureSatKillPseudoGVNode(manager,node,tmpTable); 01062 else 01063 PureSatAbstractLatch(manager,node,tmpTable); 01064 } 01065 } 01066 01067 for(j=0; j<tf->nbLatches; j++){ 01068 node = bAig_NonInvertedEdge(bli[j]); 01069 if(st_lookup(DoneTable,(char*)node,NIL(char*))) 01070 continue; 01071 st_insert(DoneTable,(char*)node,(char*)0); 01072 if((flags(node)&StateBitMask)&& 01073 !(flags(node)&VisibleVarMask)&& 01074 (flags(node)&CoiMask)){ 01075 if(i==1) 01076 PureSatKillPseudoGVNode(manager,node,tmpTable); 01077 else 01078 PureSatAbstractLatch(manager,node,tmpTable); 01079 } 01080 } 01081 st_free_table(tmpTable); 01082 st_free_table(DoneTable); 01083 } 01084 } 01085 01086 01100 int PureSat_CountNodesInCoi(satManager_t* cm) 01101 { 01102 int ct=0; 01103 bAigEdge_t i; 01104 01105 for(i=satNodeSize;i<cm->nodesArraySize;i+=satNodeSize){ 01106 if(SATflags(i) & CoiMask){ 01107 ct++; 01108 01109 } 01110 } 01111 /*fprintf(vis_stdout,"There are %d node in COI\n",ct);*/ 01112 return ct; 01113 } 01114 01128 void PureSat_Check(bAig_Manager_t *manager, bAigEdge_t v) 01129 { 01130 bAigEdge_t *fan,*fan1,nfan1; 01131 bAigEdge_t nfan,cur,child,tmpchild,v1,other,cur1; 01132 int size,i,j,find=0,inver,left,left1; 01133 01134 nfan = nFanout(v); 01135 fan = (bAigEdge_t *)fanout(v); 01136 if(fan == 0){ 01137 assert(nfan==0); 01138 return; 01139 } 01140 01141 size = 0; 01142 01143 for(i=0; fan[i]!=0; i++){ 01144 size++; 01145 cur = fan[i]; 01146 left = 1; 01147 inver = 0; 01148 if(SATisInverted(cur)) 01149 left = 0; 01150 cur >>= 1; 01151 if(SATisInverted(cur)) 01152 inver = 1; 01153 cur = SATnormalNode(cur); 01154 child = inver? SATnormalNode(v)+1:SATnormalNode(v); 01155 if(left) 01156 tmpchild = leftChild(cur); 01157 else 01158 tmpchild = rightChild(cur); 01159 assert(tmpchild == child); 01160 01161 /*check the other child*/ 01162 find = 0; 01163 other = left?rightChild(cur):leftChild(cur); 01164 assert(other!=bAig_NULL); 01165 v1 = SATnormalNode(other); 01166 nfan1 = nFanout(v1); 01167 fan1 = (bAigEdge_t *)fanout(v1); 01168 assert(nfan1!=0&&fan1!=0); 01169 for(j=0; fan1[j]!=0; j++){ 01170 cur1 = fan1[j]; 01171 left1 = 1; 01172 if(SATisInverted(cur1)) 01173 left1 = 0; 01174 assert(j<nfan1); 01175 if((SATnormalNode(cur1>>1)==cur)&&(left1!=left)){ 01176 find = 1; 01177 01178 break; 01179 } 01180 } 01181 assert(find); 01182 } 01183 01184 assert(nfan==size); 01185 } 01186 01187 01201 void PureSat_CheckFanoutFanin(bAig_Manager_t *manager) 01202 { 01203 bAigEdge_t i,v; 01204 01205 for(i=bAigNodeSize;i<manager->nodesArraySize;i+=bAigNodeSize){ 01206 v = i; 01207 if((flags(v) & IsCNFMask)) 01208 continue; 01209 PureSat_Check(manager,v); 01210 } 01211 } 01212 01225 /*1. eliminate concls, 2. free variableArray 01226 3. adjust nodeArray(size and new nodes)*/ 01227 void PureSat_ResetManager(mAig_Manager_t *manager, 01228 satManager_t *cm, int clean) 01229 { 01230 01231 int i; 01232 satVariable_t var; 01233 satLevel_t *d; 01234 01235 if(cm->variableArray) { 01236 for(i=0; i<cm->initNumVariables; i++) { 01237 var = cm->variableArray[i]; 01238 if(var.wl[0]) { 01239 sat_ArrayFree(var.wl[0]); 01240 var.wl[0] = 0; 01241 } 01242 if(var.wl[1]) { 01243 sat_ArrayFree(var.wl[1]); 01244 var.wl[1] = 0; 01245 } 01246 } 01247 free(cm->variableArray); 01248 cm->variableArray = 0; 01249 } 01250 01251 if(cm->decisionHead) { 01252 for(i=0; i<cm->decisionHeadSize; i++) { 01253 d = &(cm->decisionHead[i]); 01254 if(d->implied) 01255 sat_ArrayFree(d->implied); 01256 if(d->satisfied) 01257 sat_ArrayFree(d->satisfied); 01258 } 01259 free(cm->decisionHead); 01260 cm->decisionHead = 0; 01261 cm->decisionHeadSize = 0; 01262 cm->currentDecision = 0; 01263 } 01264 01265 if(cm->literals){ 01266 sat_FreeLiteralsDB(cm->literals); 01267 cm->literals=0; 01268 sat_AllocLiteralsDB(cm); 01269 } 01270 if(cm->each){ 01271 FREE(cm->each); 01272 cm->each = sat_InitStatistics(); 01273 } 01274 01275 if(cm->queue) sat_FreeQueue(cm->queue); 01276 if(cm->BDDQueue) sat_FreeQueue(cm->BDDQueue); 01277 if(cm->unusedAigQueue)sat_FreeQueue(cm->unusedAigQueue); 01278 cm->queue = 0; 01279 cm->BDDQueue = 0; 01280 cm->unusedAigQueue = 0; 01281 01282 01283 if(cm->nonobjUnitLitArray) sat_ArrayFree(cm->nonobjUnitLitArray); 01284 if(cm->objUnitLitArray) sat_ArrayFree(cm->objUnitLitArray); 01285 if(cm->orderedVariableArray) sat_ArrayFree(cm->orderedVariableArray); 01286 if(cm->dormantConflictArray) sat_ArrayFree(cm->dormantConflictArray); 01287 if(cm->shrinkArray) sat_ArrayFree(cm->shrinkArray); 01288 01289 cm->nonobjUnitLitArray = 0; 01290 cm->objUnitLitArray = 0; 01291 cm->orderedVariableArray = 0; 01292 cm->dormantConflictArray = 0; 01293 cm->shrinkArray = 0; 01294 01295 /*change initNumVariable after cm->variableArray has been freed, 01296 otherwise, initNumVariable may change*/ 01297 cm->nodesArray = manager->NodesArray; 01298 cm->nodesArraySize = manager->nodesArraySize; 01299 cm->initNodesArraySize = manager->nodesArraySize; 01300 cm->maxNodesArraySize = manager->maxNodesArraySize; 01301 cm->initNumVariables = (manager->nodesArraySize/bAigNodeSize)-1; 01302 cm->initNumClauses = 0; 01303 cm->initNumLiterals = 0; 01304 01305 cm->ipm = manager->ipm; 01306 cm->assertArray = manager->assertArray; 01307 cm->assertArray2 = manager->assertArray2; 01308 cm->InitState = manager->InitState; 01309 cm->CoiAssertArray = manager->CoiAssertArray; 01310 cm->EqArray = manager->EqArray; 01311 01312 cm->currentVarPos = 0; 01313 cm->currentTopConflict = 0; 01314 cm->currentTopConflictCount = 0; 01315 cm->lowestBacktrackLevel = 0; 01316 cm->implicatedSoFar = 0; 01317 //cm->status = 0; 01318 01319 if(clean){ 01320 for(i=bAigNodeSize;i<cm->nodesArraySize;i+=bAigNodeSize) 01321 cm->nodesArray[i] = 2; 01322 } 01323 } 01324 01325 01338 void PureSat_RestoreAigForDummyNode(mAig_Manager_t *manager, 01339 int oldPosition) 01340 { 01341 01342 bAigEdge_t i; 01343 01344 for(i=manager->nodesArraySize-bAigNodeSize; 01345 i>oldPosition;i=i-bAigNodeSize){ 01346 #if DBG 01347 assert(leftChild(i)==bAig_NULL&& 01348 rightChild(i)==bAig_NULL); 01349 assert(flags(i)&DummyMask); 01350 #endif 01351 FREE(fanout(i)); 01352 } 01353 01354 manager->nodesArraySize = oldPosition+bAigNodeSize; 01355 01356 return; 01357 01358 } 01359 01372 /*after this funct, all nodes' fanout, either COI or not 01373 are in COI, not InvSV, and if this node is InvSV, not to a node in the next tf*/ 01374 void PureSatProcessFanout(satManager_t * cm) 01375 { 01376 01377 long bufSize, bufIndex; 01378 bAigEdge_t *buf,left,right,*fan,v,cur; 01379 int i, j; 01380 long size, tsize; 01381 01382 int InvStateVar,l; 01383 01384 01385 bufSize = 1024; 01386 bufIndex = 0; 01387 buf = malloc(sizeof(bAigEdge_t) * bufSize); 01388 for(i=satNodeSize; i<cm->nodesArraySize; i+=satNodeSize) { 01389 v = i; 01390 01391 if(!(SATflags(v) & CoiMask)) 01392 continue; 01393 01394 InvStateVar = 0; 01395 if((SATflags(v)&StateBitMask)&& 01396 !(SATflags(v)&VisibleVarMask)) 01397 InvStateVar = 1; 01398 01399 size = SATnFanout(v); 01400 if(size >= bufSize) { 01401 bufSize <<= 1; 01402 if(size >= bufSize) 01403 bufSize = size + 1; 01404 buf = realloc(buf, sizeof(bAigEdge_t) * bufSize); 01405 } 01406 01407 bufIndex = 0; 01408 for(j=0, fan = SATfanout(v); j<size; j++) { 01409 cur = fan[j]; 01410 cur >>= 1; 01411 cur = SATnormalNode(cur); 01412 /*Not in COI , pass */ 01413 if(!(SATflags(cur) & CoiMask)) 01414 continue; 01415 /*cur is invisible var*/ 01416 left = SATleftChild(cur); 01417 right = SATrightChild(cur); 01418 if(left==bAig_NULL||right==bAig_NULL){ 01419 #if DBG 01420 01421 assert(left==bAig_NULL&&right==bAig_NULL); 01422 assert((SATflags(cur)&StateBitMask)&& 01423 !(SATflags(cur)&VisibleVarMask)); 01424 #endif 01425 continue; 01426 } 01427 /*v itself is InvStateVar and cur is not InvSV*/ 01428 01429 if(SATflags(v)&PGVMask){ 01430 01431 if(SATclass(cur)>=2){ 01432 l = SATisInverted(fan[j]) ? 0 : 1; 01433 if(l){ 01434 #if DBG 01435 bAigEdge_t v1 = SATnormalNode(SATleftChild(cur)); 01436 assert(v1!=v); 01437 assert(SATflags(v1)&DummyMask); 01438 #endif 01439 } 01440 else{ 01441 #if DBG 01442 bAigEdge_t v1 = SATnormalNode(SATrightChild(cur)); 01443 assert(v1!=v); 01444 assert(SATflags(v1)&DummyMask); 01445 #endif 01446 } 01447 continue; 01448 } 01449 } 01450 buf[bufIndex++] = fan[j]; 01451 } 01452 01453 if(bufIndex > 0) { 01454 tsize = bufIndex; 01455 for(j=0, fan=SATfanout(v); j<size; j++) { 01456 cur = fan[j]; 01457 cur >>= 1; 01458 cur = SATnormalNode(cur); 01459 if(!(SATflags(cur) & CoiMask)) { 01460 buf[bufIndex++] = fan[j]; 01461 continue; 01462 } 01463 01464 left = SATleftChild(cur); 01465 right = SATrightChild(cur); 01466 01467 if(left==bAig_NULL||right==bAig_NULL){ 01468 buf[bufIndex++] = fan[j]; 01469 continue; 01470 } 01471 01472 01473 if(SATflags(v)&PGVMask){ 01474 if(SATclass(cur)>=2){ 01475 buf[bufIndex++] = fan[j]; 01476 continue; 01477 } 01478 } 01479 01480 }/*for(j=0, fan=SATfanout(v); j<size; j++) {*/ 01481 buf[bufIndex] = 0; 01482 memcpy(fan, buf, sizeof(bAigEdge_t)*(size+1)); 01483 SATnFanout(v) = tsize; 01484 } 01485 else 01486 SATnFanout(v) = 0; 01487 } 01488 01489 free(buf); 01490 01491 for(i=satNodeSize; i<cm->nodesArraySize; i+=satNodeSize) { 01492 v = i; 01493 if(!(SATflags(v) & CoiMask)) 01494 continue; 01495 fan = SATfanout(v); 01496 size = SATnFanout(v); 01497 qsort(fan, size, sizeof(bAigEdge_t), NodeIndexCompare); 01498 } 01499 } 01512 long PureSatRecoverFanoutNode(satManager_t * cm, 01513 bAigEdge_t v) 01514 { 01515 bAigEdge_t *fan,nfan,child,cur; 01516 long i; 01517 int left,inver; 01518 int InvStateVar = 0; 01519 01520 if(!(SATflags(v)&VisibleVarMask)&&(SATflags(v)&StateBitMask)) 01521 InvStateVar = 1; 01522 01523 nfan = SATnFanout(v); 01524 01525 fan = SATfanout(v); 01526 if(fan == 0) return(0); 01527 01528 /*recover left and right children for latch nodes*/ 01529 01530 for(i=nfan; fan[i]!=0; i++){ 01531 cur = fan[i]; 01532 if(!(SATflags(SATnormalNode(cur>>1))&CoiMask)) 01533 continue; 01534 /*cur is InvSV*/ 01535 if((SATleftChild(SATnormalNode(cur>>1))==bAig_NULL)|| 01536 (SATrightChild(SATnormalNode(cur>>1))==bAig_NULL)){ 01537 #if DBG 01538 assert((SATflags(SATnormalNode(cur>>1))&StateBitMask)&& 01539 !(SATflags(SATnormalNode(cur>>1))&VisibleVarMask)); 01540 #endif 01541 left = 1; 01542 inver = 0; 01543 if(SATisInverted(cur)) 01544 left = 0; 01545 cur >>= 1; 01546 if(SATisInverted(cur)) 01547 inver = 1; 01548 cur = SATnormalNode(cur); 01549 child = inver? SATnormalNode(v)+1:SATnormalNode(v); 01550 if(left) 01551 SATleftChild(cur)=child; 01552 else 01553 SATrightChild(cur)=child; 01554 continue; 01555 } 01556 01557 /*v is InvSV, cur is not InvSV*/ 01558 01559 if(SATflags(v)&PGVMask){ 01560 01561 if(SATclass(SATnormalNode(cur>>1))>=2){ 01562 left = 1; 01563 inver = 0; 01564 if(SATisInverted(cur)) 01565 left = 0; 01566 cur >>= 1; 01567 if(SATisInverted(cur)) 01568 inver = 1; 01569 cur = SATnormalNode(cur); 01570 child = inver? SATnormalNode(v)+1:SATnormalNode(v); 01571 if(left) 01572 SATleftChild(cur)=child; 01573 else 01574 SATrightChild(cur)=child; 01575 } 01576 } 01577 } 01578 //recover all fanout 01579 return(i); 01580 } 01581 01593 void 01594 PureSatRecoverISVNode(satManager_t *cm, 01595 bAigEdge_t v) 01596 { 01597 01598 bAigEdge_t size = SATnFanout(v),cur,node,child; 01599 bAigEdge_t * fan = SATfanout(v); 01600 int inv,i,left; 01601 01602 for(i=0;i<size;i++){ 01603 cur = fan[i]>>1; 01604 node = SATnormalNode(cur); 01605 /*not in coi*/ 01606 if(!(SATflags(node)&CoiMask)) 01607 continue; 01608 /*not invisible var*/ 01609 if(!((SATflags(node)&StateBitMask)&& 01610 !(SATflags(node)&VisibleVarMask))) 01611 continue; 01612 01613 left=SATisInverted(fan[i])?0:1; 01614 inv=SATisInverted(cur)?1:0; 01615 child = inv?SATnormalNode(v)+1:SATnormalNode(v); 01616 if(left) 01617 SATleftChild(node) = child; 01618 else 01619 SATrightChild(node) = child; 01620 } 01621 } 01622 01635 void PureSatRecoverFanout(satManager_t * cm, 01636 PureSat_Manager_t *pm) 01637 { 01638 bAigEdge_t i, v; 01639 01640 /*dummy node can't be recovered*/ 01641 for(i=satNodeSize; i<=pm->oldPos; i+=satNodeSize) { 01642 v = i; 01643 if(SATflags(v) & IsCNFMask) 01644 continue; 01645 01646 if((SATflags(v)&CoiMask)){ 01647 SATnFanout(v) = PureSatRecoverFanoutNode(cm, v); 01648 continue; 01649 } 01650 /*for some node not in coi, but a child of one coi(ISV) node*/ 01651 if(SATflags(v)&Visited3Mask){ 01652 PureSatRecoverISVNode(cm,v); 01653 continue; 01654 } 01655 } 01656 01657 } 01658 01671 void PureSatCheckCoiNode(bAig_Manager_t * manager, 01672 bAigEdge_t node) 01673 { 01674 int i; 01675 long *fan; 01676 long nfan,child, cur; 01677 int left,inv; 01678 01679 nfan = nFanout(node); 01680 fan = (bAigEdge_t*)fanout(node); 01681 if(fan==0) return; 01682 /*check child*/ 01683 assert((leftChild(node)==bAig_NULL)|| 01684 (flags(leftChild(node))&CoiMask)); 01685 assert((rightChild(node)==bAig_NULL)|| 01686 (flags(rightChild(node))&CoiMask)); 01687 if((leftChild(node)==bAig_NULL)||(rightChild(node)==bAig_NULL)) 01688 assert((leftChild(node)==bAig_NULL)&&(rightChild(node)==bAig_NULL)); 01689 /*check fanout*/ 01690 for(i=0; i<nfan; i++){ 01691 cur = fan[i]>>1; 01692 assert(flags(cur)&CoiMask); 01693 left=SATisInverted(fan[i])?0:1; 01694 inv=SATisInverted(cur)?1:0; 01695 child = inv?SATnormalNode(node)+1:SATnormalNode(node); 01696 if(left){ 01697 assert(child==leftChild(cur)); 01698 } 01699 else{ 01700 assert(child==rightChild(cur)); 01701 } 01702 } 01703 01704 } 01705 01718 void PureSatCheckCoi(bAig_Manager_t *manager) 01719 { 01720 long i; 01721 for(i=bAigNodeSize;i<manager->nodesArraySize;i+=bAigNodeSize){ 01722 if(flags(i) & IsCNFMask) 01723 continue; 01724 if(!(flags(i) & CoiMask)) 01725 continue; 01726 PureSatCheckCoiNode(manager,i); 01727 } 01728 01729 } 01730 01744 void PureSatPreprocess(Ntk_Network_t * network, 01745 satManager_t *cm, 01746 PureSat_Manager_t *pm, 01747 st_table *vertexTable, 01748 int Length) 01749 01750 { 01751 bAig_Manager_t * manager = Ntk_NetworkReadMAigManager(network); 01752 01753 PureSatSetCOI(network,pm,cm,vertexTable,0, Length,Length); 01754 /*for interpolation*/ 01755 PureSatKillPseudoGV(network,pm,vertexTable,1,Length); 01756 PureSat_ResetManager(manager,cm,0); 01757 /*for abstraction*/ 01758 PureSatProcessFanout(cm); 01759 } 01760 01774 void PureSatPostprocess(bAig_Manager_t *manager, 01775 satManager_t *cm, 01776 PureSat_Manager_t *pm) 01777 { 01778 01779 PureSatRecoverFanout(cm,pm); 01780 PureSat_RestoreAigForDummyNode(manager,pm->oldPos); 01781 PureSat_CleanMask(manager,ResetVisited3Mask); 01782 } 01783 01784 01798 /*test if state1 contains state2*/ 01799 int PureSat_TestConvergeForIP(mAig_Manager_t *manager, 01800 PureSat_Manager_t *pm, 01801 satManager_t *cm, 01802 bAigEdge_t state1, 01803 bAigEdge_t state2) 01804 { 01805 satArray_t * tmp1,*tmp2,*tmp3, *tmp4,*tmp5, *tmp6, *tmp7; 01806 int status, nodes_in_coi = 0; 01807 01808 if(state2 == bAig_Zero) 01809 return 1; 01810 if(state1 == bAig_One) 01811 return 1; 01812 if(state1 == bAig_Zero && state2 != bAig_Zero) 01813 return 0; 01814 if(state1 != bAig_One && state2 == bAig_One) 01815 return 0; 01816 01817 if(pm->verbosity>=1) 01818 fprintf(vis_stdout,"Test convergence:\n"); 01819 PureSat_ResetCoi(cm); 01820 if(pm->verbosity>=1){ 01821 fprintf(vis_stdout,"after reset COI\n"); 01822 nodes_in_coi = PureSat_CountNodesInCoi(cm); 01823 fprintf(vis_stdout,"There are %d node in COI\n",nodes_in_coi); 01824 } 01825 tmp1 = cm->obj; 01826 tmp2 = cm->auxObj; 01827 tmp3 = cm->assertion; 01828 tmp4 = cm->assertArray; 01829 //Bing: 01830 tmp5 = cm->unitLits; 01831 tmp6 = cm->pureLits; 01832 tmp7 = cm->nonobjUnitLitArray; 01833 cm->obj = 0; 01834 cm->auxObj = 0; 01835 cm->assertion = 0; 01836 //cm->assertArray2 = 0; 01837 cm->assertArray = sat_ArrayAlloc(1); 01838 sat_ArrayInsert(cm->assertArray,SATnot(state1)); 01839 sat_ArrayInsert(cm->assertArray,state2); 01840 sat_SetConeOfInfluence(cm); 01841 if(pm->verbosity>=1){ 01842 fprintf(vis_stdout,"after add new init states:\n"); 01843 nodes_in_coi = PureSat_CountNodesInCoi(cm); 01844 fprintf(vis_stdout,"There are %d node in COI\n",nodes_in_coi); 01845 } 01846 cm->option->coreGeneration = 0; 01847 //cm->option->effIP = 0; 01848 cm->option->IP = 0; 01849 cm->status = 0; 01850 sat_Main(cm); 01851 if(manager->NodesArray!=cm->nodesArray) 01852 /*cm->nodesArray may be reallocated*/ 01853 manager->NodesArray = cm->nodesArray; 01854 cm->obj = tmp1; 01855 cm->auxObj = tmp2; 01856 cm->assertion = tmp3; 01857 sat_ArrayFree(cm->assertArray); 01858 cm->assertArray = tmp4; 01859 01860 cm->unitLits = tmp5; 01861 cm->pureLits = tmp6; 01862 cm->nonobjUnitLitArray = tmp7; 01863 01864 cm->option->coreGeneration = 1; 01865 01866 cm->option->IP = 1; 01867 status = cm->status; 01868 #if DBG 01869 assert(cm->currentDecision>=-1); 01870 #endif 01871 if(cm->currentDecision!=-1) 01872 sat_Backtrack(cm,-1); 01873 cm->status = 0; 01874 01875 if(status == SAT_UNSAT) 01876 /*state2 contains state1, reach convergence*/ 01877 return 1; 01878 else 01879 return 0; 01880 } 01881 01898 /*test if state1 contains state2 for abstract refinement*/ 01899 int PureSat_TestConvergeForIP_AbRf(Ntk_Network_t *network, 01900 satManager_t *cm, 01901 PureSat_Manager_t *pm, 01902 array_t * CoiArray, 01903 bAigEdge_t state1, 01904 bAigEdge_t state2) 01905 { 01906 satArray_t * tmp1,*tmp2,*tmp3, *tmp4,*tmp5, *tmp6, *tmp7; 01907 int status, nodes_in_coi = 0; 01908 mAig_Manager_t * manager; 01909 01910 01911 if(state2 == bAig_Zero) 01912 return 1; 01913 if(state1 == bAig_One) 01914 return 1; 01915 if(state1 == bAig_Zero && state2 != bAig_Zero) 01916 return 0; 01917 if(state1 != bAig_One && state2 == bAig_One) 01918 return 0; 01919 01920 01921 manager = Ntk_NetworkReadMAigManager(network); 01922 01923 if(pm->verbosity>=1) 01924 fprintf(vis_stdout,"Test convergence:\n"); 01925 PureSat_ResetCoi(cm); 01926 if(pm->verbosity>=1){ 01927 fprintf(vis_stdout,"after reset COI\n"); 01928 nodes_in_coi = PureSat_CountNodesInCoi(cm); 01929 fprintf(vis_stdout,"There are %d node in COI\n",nodes_in_coi); 01930 } 01931 tmp1 = cm->obj; 01932 tmp2 = cm->auxObj; 01933 tmp3 = cm->assertion; 01934 tmp4 = cm->assertArray; 01935 01936 tmp5 = cm->unitLits; 01937 tmp6 = cm->pureLits; 01938 tmp7 = cm->nonobjUnitLitArray; 01939 cm->obj = 0; 01940 cm->auxObj = 0; 01941 cm->assertion = 0; 01942 cm->unitLits = 0; 01943 cm->pureLits = 0; 01944 cm->nonobjUnitLitArray = 0; 01945 cm->assertArray = sat_ArrayAlloc(1); 01946 sat_ArrayInsert(cm->assertArray,SATnot(state1)); 01947 sat_ArrayInsert(cm->assertArray,state2); 01948 01949 sat_MarkTransitiveFaninForArray(cm, cm->assertArray, CoiMask); 01950 01951 if(pm->verbosity>=1){ 01952 fprintf(vis_stdout,"after add new init states:\n"); 01953 nodes_in_coi = PureSat_CountNodesInCoi(cm); 01954 fprintf(vis_stdout,"There are %d node in COI\n",nodes_in_coi); 01955 } 01956 cm->option->coreGeneration = 0; 01957 cm->status = 0; 01958 cm->option->AbRf = 0; 01959 sat_Main(cm); 01960 cm->option->AbRf = 1; 01961 if(manager->NodesArray!=cm->nodesArray) 01962 /*cm->nodesArray may be reallocated*/ 01963 manager->NodesArray = cm->nodesArray; 01964 sat_ArrayFree(cm->assertArray); 01965 manager->assertArray = tmp4; 01966 cm->obj = tmp1; 01967 cm->auxObj = tmp2; 01968 cm->assertion = tmp3; 01969 cm->assertArray = tmp4; 01970 01971 cm->unitLits = tmp5; 01972 cm->pureLits = tmp6; 01973 cm->nonobjUnitLitArray = tmp7; 01974 cm->option->coreGeneration = 1; 01975 status = cm->status; 01976 if(cm->currentDecision!=-1) 01977 sat_Backtrack(cm,-1); 01978 cm->status = 0; 01979 01980 if(status == SAT_UNSAT) 01981 /*state2 contains state1, reach convergence*/ 01982 return 1; 01983 else 01984 return 0; 01985 } 01986 01999 satManager_t * PureSat_SatManagerAlloc(bAig_Manager_t *manager, 02000 PureSat_Manager_t *pm, 02001 bAigEdge_t object, 02002 array_t *auxObjectArray) 02003 { 02004 satManager_t * cm; 02005 satOption_t *option; 02006 int i,size; 02007 bAigEdge_t tv; 02008 02009 cm = ALLOC(satManager_t, 1); 02010 memset(cm, 0, sizeof(satManager_t)); 02011 cm->nodesArraySize = manager->nodesArraySize; 02012 cm->initNodesArraySize = manager->nodesArraySize; 02013 cm->maxNodesArraySize = manager->maxNodesArraySize; 02014 cm->nodesArray = manager->NodesArray; 02015 02016 cm->HashTable = manager->HashTable; 02017 cm->literals = manager->literals; 02018 02019 cm->initNumVariables = (manager->nodesArraySize/bAigNodeSize)-1; 02020 cm->initNumClauses = 0; 02021 cm->initNumLiterals = 0; 02022 cm->comment = ALLOC(char, 2); 02023 cm->comment[0] = ' '; 02024 cm->comment[1] = '\0'; 02025 cm->stdErr = vis_stderr; 02026 cm->stdOut = vis_stdout; 02027 cm->status = 0; 02028 cm->orderedVariableArray = 0; 02029 cm->unitLits = sat_ArrayAlloc(16); 02030 cm->pureLits = sat_ArrayAlloc(16); 02031 cm->option = 0; 02032 cm->each = 0; 02033 cm->decisionHead = 0; 02034 cm->variableArray = 0; 02035 cm->queue = 0; 02036 cm->BDDQueue = 0; 02037 cm->unusedAigQueue = 0; 02038 02039 cm->ipm = manager->ipm; 02040 cm->assertArray = manager->assertArray; 02041 cm->assertArray2 = manager->assertArray2; 02042 cm->InitState = manager->InitState; 02043 cm->CoiAssertArray = manager->CoiAssertArray; 02044 cm->EqArray = manager->EqArray; 02045 02046 if(auxObjectArray) { 02047 cm->auxObj = sat_ArrayAlloc(auxObjectArray->num+1); 02048 size = auxObjectArray->num; 02049 for(i=0; i<size; i++) { 02050 tv = array_fetch(bAigEdge_t, auxObjectArray, i); 02051 if(tv == 1) continue; 02052 else if(tv == 0) { 02053 cm->status = SAT_UNSAT; 02054 break; 02055 } 02056 sat_ArrayInsert(cm->auxObj, tv); 02057 } 02058 } 02059 if(object == 0) cm->status = SAT_UNSAT; 02060 else if(object == 1) cm->status = SAT_SAT; 02061 02062 02063 if(cm->status == 0) { 02064 if(object!=-1){ 02065 cm->obj = sat_ArrayAlloc(1); 02066 sat_ArrayInsert(cm->obj, object); 02067 } 02068 /* initialize option*/ 02069 option = sat_InitOption(); 02070 02071 option->coreGeneration = 1; 02072 option->ForceFinish = 1; 02073 02074 option->clauseDeletionHeuristic = 0; 02075 option->includeLevelZeroLiteral = 1; 02076 option->minimizeConflictClause = 0; 02077 option->IP = 1; 02078 option->RT = 1; 02079 option->verbose = pm->verbosity; 02080 02081 cm->anteTable = st_init_table(st_numcmp,st_numhash); 02082 cm->RTreeTable = st_init_table(st_ptrcmp,st_ptrhash); 02083 02084 cm->option = option; 02085 cm->each = sat_InitStatistics(); 02086 02087 BmcRestoreAssertion(manager,cm); 02088 02089 /* value reset..*/ 02090 sat_CleanDatabase(cm); 02091 02092 /* set cone of influence*/ 02093 sat_SetConeOfInfluence(cm); 02094 sat_AllocLiteralsDB(cm); 02095 } 02096 return cm; 02097 } 02098 02099 02111 satManager_t * PureSat_SatManagerAlloc_WOCOI(mAig_Manager_t *manager, 02112 PureSat_Manager_t *pm, 02113 bAigEdge_t object, 02114 array_t *auxObjectArray) 02115 { 02116 satManager_t * cm; 02117 satOption_t *option; 02118 int i,size; 02119 bAigEdge_t tv; 02120 02121 cm = ALLOC(satManager_t, 1); 02122 memset(cm, 0, sizeof(satManager_t)); 02123 cm->nodesArraySize = manager->nodesArraySize; 02124 cm->initNodesArraySize = manager->nodesArraySize; 02125 cm->maxNodesArraySize = manager->maxNodesArraySize; 02126 cm->nodesArray = manager->NodesArray; 02127 02128 cm->HashTable = manager->HashTable; 02129 cm->literals = manager->literals; 02130 02131 cm->initNumVariables = (manager->nodesArraySize/bAigNodeSize)-1; 02132 cm->initNumClauses = 0; 02133 cm->initNumLiterals = 0; 02134 cm->comment = ALLOC(char, 2); 02135 cm->comment[0] = ' '; 02136 cm->comment[1] = '\0'; 02137 cm->stdErr = vis_stderr; 02138 cm->stdOut = vis_stdout; 02139 cm->status = 0; 02140 cm->orderedVariableArray = 0; 02141 cm->unitLits = sat_ArrayAlloc(16); 02142 cm->pureLits = sat_ArrayAlloc(16); 02143 cm->option = 0; 02144 cm->each = 0; 02145 cm->decisionHead = 0; 02146 cm->variableArray = 0; 02147 cm->queue = 0; 02148 cm->BDDQueue = 0; 02149 cm->unusedAigQueue = 0; 02150 02151 cm->ipm = manager->ipm; 02152 cm->assertArray = manager->assertArray; 02153 cm->assertArray2 = manager->assertArray2; 02154 cm->InitState = manager->InitState; 02155 cm->CoiAssertArray = manager->CoiAssertArray; 02156 cm->EqArray = manager->EqArray; 02157 02158 if(auxObjectArray) { 02159 cm->auxObj = sat_ArrayAlloc(auxObjectArray->num+1); 02160 size = auxObjectArray->num; 02161 for(i=0; i<size; i++) { 02162 tv = array_fetch(bAigEdge_t, auxObjectArray, i); 02163 if(tv == 1) continue; 02164 else if(tv == 0) { 02165 cm->status = SAT_UNSAT; 02166 break; 02167 } 02168 sat_ArrayInsert(cm->auxObj, tv); 02169 } 02170 } 02171 if(object == 0) cm->status = SAT_UNSAT; 02172 else if(object == 1) cm->status = SAT_SAT; 02173 02174 02175 if(cm->status == 0) { 02176 if(object!=-1){ 02177 cm->obj = sat_ArrayAlloc(1); 02178 sat_ArrayInsert(cm->obj, object); 02179 } 02180 02181 option = sat_InitOption(); 02182 option->ForceFinish = 1; 02183 02184 option->coreGeneration = 1; 02185 option->clauseDeletionHeuristic = 0; 02186 option->includeLevelZeroLiteral = 1; 02187 option->minimizeConflictClause = 0; 02188 option->IP = 0; 02189 option->RT = 1; 02190 option->verbose = pm->verbosity; 02191 02192 cm->anteTable = st_init_table(st_numcmp,st_numhash); 02193 cm->RTreeTable = st_init_table(st_ptrcmp,st_ptrhash); 02194 02195 cm->option = option; 02196 cm->each = sat_InitStatistics(); 02197 02198 BmcRestoreAssertion(manager,cm); 02199 02200 sat_CleanDatabase(cm); 02201 02202 /* WOCOI: NO set cone of influence*/ 02203 sat_AllocLiteralsDB(cm); 02204 } 02205 return cm; 02206 } 02207 02221 void PureSat_SatFreeManager(satManager_t*cm) 02222 { 02223 satVariable_t var; 02224 satLevel_t *d; 02225 int i; 02226 02227 02228 if(cm->option->coreGeneration){ 02229 st_free_table(cm->anteTable); 02230 st_free_table(cm->RTreeTable); 02231 02232 cm->anteTable=0; 02233 cm->RTreeTable=0; 02234 } 02235 02236 /*timeframe, timeframeWOI,HashTable can't be freed*/ 02237 02238 if(cm->option) sat_FreeOption(cm->option); 02239 if(cm->total) sat_FreeStatistics(cm->total); 02240 if(cm->each) sat_FreeStatistics(cm->each); 02241 02242 if(cm->literals) sat_FreeLiteralsDB(cm->literals); 02243 02244 cm->option=0; 02245 cm->total=0; 02246 cm->each=0; 02247 cm->literals=0; 02248 02249 if(cm->decisionHead) { 02250 for(i=0; i<cm->decisionHeadSize; i++) { 02251 d = &(cm->decisionHead[i]); 02252 if(d->implied) 02253 sat_ArrayFree(d->implied); 02254 if(d->satisfied) 02255 sat_ArrayFree(d->satisfied); 02256 } 02257 free(cm->decisionHead); 02258 cm->decisionHead = 0; 02259 cm->decisionHeadSize = 0; 02260 } 02261 02262 if(cm->queue) sat_FreeQueue(cm->queue); 02263 if(cm->BDDQueue) sat_FreeQueue(cm->BDDQueue); 02264 if(cm->unusedAigQueue)sat_FreeQueue(cm->unusedAigQueue); 02265 cm->queue = 0; 02266 cm->BDDQueue = 0; 02267 cm->unusedAigQueue = 0; 02268 02269 if(cm->auxObj) sat_ArrayFree(cm->auxObj); 02270 if(cm->obj) sat_ArrayFree(cm->obj); 02271 if(cm->unitLits) sat_ArrayFree(cm->unitLits); 02272 if(cm->pureLits) sat_ArrayFree(cm->pureLits); 02273 if(cm->assertion) sat_ArrayFree(cm->assertion); 02274 if(cm->auxArray) sat_ArrayFree(cm->auxArray); 02275 if(cm->nonobjUnitLitArray) sat_ArrayFree(cm->nonobjUnitLitArray); 02276 if(cm->objUnitLitArray) sat_ArrayFree(cm->objUnitLitArray); 02277 if(cm->orderedVariableArray) sat_ArrayFree(cm->orderedVariableArray); 02278 if(cm->savedConflictClauses) sat_ArrayFree(cm->savedConflictClauses); 02279 02280 cm->auxObj = 0; 02281 cm->obj = 0; 02282 cm->unitLits = 0; 02283 cm->pureLits = 0; 02284 cm->assertion = 0; 02285 cm->auxArray = 0; 02286 cm->nonobjUnitLitArray = 0; 02287 cm->objUnitLitArray = 0; 02288 cm->orderedVariableArray = 0; 02289 02290 if(cm->variableArray) { 02291 for(i=0; i<cm->initNumVariables; i++) { 02292 var = cm->variableArray[i]; 02293 if(var.wl[0]) { 02294 sat_ArrayFree(var.wl[0]); 02295 var.wl[0] = 0; 02296 } 02297 if(var.wl[1]) { 02298 sat_ArrayFree(var.wl[1]); 02299 var.wl[1] = 0; 02300 } 02301 } 02302 free(cm->variableArray); 02303 cm->variableArray = 0; 02304 } 02305 02306 if(cm->comment) free(cm->comment); 02307 cm->comment=0; 02308 02309 FREE(cm); 02310 } 02311 02325 void PureSat_PrintAigStatus(mAig_Manager_t *manager) 02326 { 02327 (void) fprintf(vis_stdout,"Maximum number of nodes: %ld\n", 02328 manager->maxNodesArraySize/bAigNodeSize); 02329 (void) fprintf(vis_stdout,"Current number of nodes: %ld\n", 02330 manager->nodesArraySize/bAigNodeSize); 02331 fprintf(vis_stdout,"Current Max Node Index: %ld\n\n", 02332 manager->nodesArraySize); 02333 } 02334 02347 void PureSat_MarkGlobalVar(bAig_Manager_t *manager, 02348 int length) 02349 { 02350 bAigTimeFrame_t * tf = manager->timeframeWOI; 02351 bAigEdge_t * li,* bli,node; 02352 int i; 02353 02354 li = tf->latchInputs[length]; 02355 bli = tf->blatchInputs[length]; 02356 02357 for(i=0; i<tf->nLatches; i++){ 02358 node = bAig_NonInvertedEdge(li[i]); 02359 manager->NodesArray[node+bAigFlags] |= IsGlobalVarMask; 02360 } 02361 02362 for(i=0; i<tf->nbLatches; i++){ 02363 node = bAig_NonInvertedEdge(bli[i]); 02364 manager->NodesArray[node+bAigFlags] |= IsGlobalVarMask; 02365 } 02366 } 02367 02380 void PureSat_UnMarkGlobalVar(bAig_Manager_t *manager, 02381 int length) 02382 { 02383 bAigTimeFrame_t * tf = manager->timeframeWOI; 02384 bAigEdge_t * li,* bli,node; 02385 int i; 02386 02387 li = tf->latchInputs[length]; 02388 bli = tf->blatchInputs[length]; 02389 02390 for(i=0; i<tf->nLatches; i++){ 02391 node = bAig_NonInvertedEdge(li[i]); 02392 manager->NodesArray[node+bAigFlags] &= ResetGlobalVarMask; 02393 } 02394 02395 for(i=0; i<tf->nbLatches; i++){ 02396 node = bAig_NonInvertedEdge(bli[i]); 02397 manager->NodesArray[node+bAigFlags] &= ResetGlobalVarMask; 02398 } 02399 } 02400 02401 02414 void PureSat_MarkGlobalVar_AbRf(bAig_Manager_t *manager, 02415 int length) 02416 { 02417 bAigTimeFrame_t * tf = manager->timeframeWOI; 02418 bAigEdge_t * li,* bli,node; 02419 int i; 02420 02421 02422 li = tf->latchInputs[length]; 02423 bli = tf->blatchInputs[length]; 02424 02425 for(i=0; i<tf->nLatches; i++){ 02426 node = bAig_NonInvertedEdge(li[i]); 02427 if(flags(node)&VisibleVarMask) 02428 manager->NodesArray[node+bAigFlags] |= IsGlobalVarMask; 02429 } 02430 02431 for(i=0; i<tf->nbLatches; i++){ 02432 node = bAig_NonInvertedEdge(bli[i]); 02433 if(flags(node)&VisibleVarMask) 02434 manager->NodesArray[node+bAigFlags] |= IsGlobalVarMask; 02435 } 02436 02437 } 02438 02439 02452 void PuresatMarkVisibleVarWithVPGV(Ntk_Network_t *network, 02453 array_t * visibleArray, 02454 PureSat_Manager_t *pm, 02455 int from, 02456 int to) 02457 { 02458 02459 mAig_Manager_t * manager = Ntk_NetworkReadMAigManager(network); 02460 st_table * node2MvfAigTable =(st_table *) Ntk_NetworkReadApplInfo(network, 02461 MVFAIG_NETWORK_APPL_KEY); 02462 MvfAig_Function_t *mvfAig; 02463 bAigTimeFrame_t * tf = manager->timeframeWOI; 02464 mAigMvar_t lmVar; 02465 mAigBvar_t bVar; 02466 array_t *bVarList,*mVarList; 02467 int i,j,k,lmAigId,index,index1; 02468 char * name; 02469 Ntk_Node_t * latch; 02470 bAigEdge_t node,v, *li, *bli; 02471 02472 bVarList = mAigReadBinVarList(manager); 02473 mVarList = mAigReadMulVarList(manager); 02474 02475 /*Although some SV in tf 0 are not marked as visiblevar, 02476 //they actually visible since all SV of tf 0 are visible*/ 02477 if(from<0) 02478 from=0; 02479 if(to>pm->Length+1) 02480 to=pm->Length+1; 02481 02482 /*clean VPGV mask*/ 02483 li = tf->latchInputs[1]; 02484 bli = tf->blatchInputs[1]; 02485 for(j=0;j<tf->nLatches;j++) 02486 flags(li[j])&=ResetVPGVMask; 02487 for(j=0;j<tf->nbLatches;j++) 02488 flags(bli[j])&=ResetVPGVMask; 02489 02490 for(i=from;i<=to;i++){ 02491 li = tf->latchInputs[i]; 02492 bli = tf->blatchInputs[i]; 02493 arrayForEachItem(char *,visibleArray,k,name){ 02494 int retVal; 02495 latch = Ntk_NetworkFindNodeByName(network,name); 02496 st_lookup(node2MvfAigTable,latch,&mvfAig); 02497 for(j=0;j<mvfAig->num;j++){ 02498 v = bAig_GetCanonical(manager,MvfAig_FunctionReadComponent(mvfAig,j)); 02499 if(v==bAig_Zero||v==bAig_One) 02500 continue; 02501 retVal = st_lookup(tf->li2index,(char*)v,&index); 02502 assert(retVal); 02503 if(li[index]==bAig_Zero||li[index]==bAig_One) 02504 continue; 02505 node = bAig_NonInvertedEdge(li[index]); 02506 manager->NodesArray[node+bAigFlags] |= VisibleVarMask; 02507 /*marking PGV*/ 02508 if(i==1){ 02509 if(!st_lookup(pm->vertexTable,name,NIL(char*))){ 02510 flags(node) |= VPGVMask; 02511 02512 } 02513 } 02514 } 02515 02516 02517 lmAigId = Ntk_NodeReadMAigId(latch); 02518 lmVar = array_fetch(mAigMvar_t, mVarList,lmAigId); 02519 for(j=0,index1=lmVar.bVars;j<lmVar.encodeLength;j++,index1++){ 02520 int retVal; 02521 bVar = array_fetch(mAigBvar_t,bVarList,index1); 02522 if(bVar.node==bAig_Zero||bVar.node==bAig_One) 02523 continue; 02524 retVal = st_lookup(tf->bli2index,(char*)bVar.node,&index); 02525 assert(retVal); 02526 if(bli[index]==bAig_Zero||bli[index]==bAig_One) 02527 continue; 02528 node = bAig_NonInvertedEdge(bli[index]); 02529 manager->NodesArray[node+bAigFlags] |= VisibleVarMask; 02530 /*marking PGV*/ 02531 if(i==1){ 02532 if(!st_lookup(pm->vertexTable,name,NIL(char*))) 02533 flags(node) |= VPGVMask; 02534 } 02535 } 02536 } 02537 } 02538 return; 02539 02540 } 02541 02542 02555 void PuresatMarkVisibleVar(Ntk_Network_t *network, 02556 array_t * visibleArray, 02557 PureSat_Manager_t *pm, 02558 int from, 02559 int to) 02560 { 02561 02562 mAig_Manager_t * manager = Ntk_NetworkReadMAigManager(network); 02563 st_table * node2MvfAigTable =(st_table *) Ntk_NetworkReadApplInfo(network, 02564 MVFAIG_NETWORK_APPL_KEY); 02565 MvfAig_Function_t *mvfAig; 02566 bAigTimeFrame_t * tf = manager->timeframeWOI; 02567 mAigMvar_t lmVar; 02568 mAigBvar_t bVar; 02569 array_t *bVarList,*mVarList; 02570 int i,j,k,lmAigId,index,index1; 02571 char * name; 02572 Ntk_Node_t * latch; 02573 bAigEdge_t node,v, *li, *bli; 02574 02575 bVarList = mAigReadBinVarList(manager); 02576 mVarList = mAigReadMulVarList(manager); 02577 02578 02579 if(from<0) 02580 from=0; 02581 if(to>pm->Length+1) 02582 to=pm->Length+1; 02583 02584 for(i=from;i<=to;i++){ 02585 li = tf->latchInputs[i]; 02586 bli = tf->blatchInputs[i]; 02587 arrayForEachItem(char *,visibleArray,k,name){ 02588 latch = Ntk_NetworkFindNodeByName(network,name); 02589 st_lookup(node2MvfAigTable,latch,&mvfAig); 02590 /*multi val var*/ 02591 for(j=0;j<mvfAig->num;j++){ 02592 int retVal; 02593 v = bAig_GetCanonical(manager,MvfAig_FunctionReadComponent(mvfAig,j)); 02594 if(v==bAig_Zero||v==bAig_One) 02595 continue; 02596 retVal = st_lookup(tf->li2index,(char*)v,&index); 02597 assert(retVal); 02598 if(li[index]==bAig_Zero||li[index]==bAig_One) 02599 continue; 02600 node = bAig_NonInvertedEdge(li[index]); 02601 manager->NodesArray[node+bAigFlags] |= VisibleVarMask; 02602 } 02603 02604 /*binary var*/ 02605 lmAigId = Ntk_NodeReadMAigId(latch); 02606 lmVar = array_fetch(mAigMvar_t, mVarList,lmAigId); 02607 for(j=0,index1=lmVar.bVars;j<lmVar.encodeLength;j++,index1++){ 02608 int retVal; 02609 bVar = array_fetch(mAigBvar_t,bVarList,index1); 02610 if(bVar.node==bAig_Zero||bVar.node==bAig_One) 02611 continue; 02612 retVal = st_lookup(tf->bli2index,(char*)bVar.node,&index); 02613 assert(retVal); 02614 if(bli[index]==bAig_Zero||bli[index]==bAig_One) 02615 continue; 02616 node = bAig_NonInvertedEdge(bli[index]); 02617 manager->NodesArray[node+bAigFlags] |= VisibleVarMask; 02618 } 02619 }// arrayForEachItem(char *,visibleArray,k,name) 02620 } 02621 02622 return; 02623 02624 } 02625 02626 02639 bAigEdge_t PureSat_MapIPRecur(mAig_Manager_t *manager, 02640 bAigEdge_t node, 02641 st_table * tmpTable) 02642 { 02643 bAigEdge_t v,result,left,right; 02644 int isInverted; 02645 02646 #if DBG 02647 assert(node!=bAig_NULL); 02648 #endif 02649 if(node == bAig_One || node == bAig_Zero){ 02650 return node; 02651 } 02652 02653 if(st_lookup(tmpTable,(char *)bAig_NonInvertedEdge(node),&v)){ 02654 if(bAig_IsInverted(node)) 02655 result = bAig_Not(v); 02656 else 02657 result = v; 02658 02659 return result; 02660 } 02661 02662 left = PureSat_MapIPRecur(manager,leftChild(node),tmpTable); 02663 right = PureSat_MapIPRecur(manager,rightChild(node),tmpTable); 02664 02665 v = PureSat_And(manager,left,right); 02666 isInverted = bAig_IsInverted(node); 02667 result = isInverted ? bAig_Not(v) : v; 02668 st_insert(tmpTable,(char *)bAig_NonInvertedEdge(node),(char *)v); 02669 02670 //fprintf(vis_stdout,"return %d->%d\n",node,result); 02671 return result; 02672 } 02673 02674 02675 02688 bAigEdge_t PureSat_MapIP(mAig_Manager_t *manager, 02689 bAigEdge_t node, 02690 int from, 02691 int to) 02692 { 02693 bAigTimeFrame_t *tf = manager->timeframeWOI; 02694 st_table *tmpTable = st_init_table(st_numcmp,st_numhash); 02695 bAigEdge_t * L1,*L0,result,v1,v0; 02696 int i; 02697 02698 if(node==bAig_One||node==bAig_Zero) 02699 return node; 02700 02701 L1 = tf->latchInputs[from]; 02702 L0 = tf->latchInputs[to]; 02703 for(i=0;i<tf->nLatches;i++){ 02704 v1 = L1[i]; 02705 v0 = L0[i]; 02706 if(SATisInverted(v1)){ 02707 v1 = SATnot(v1); 02708 v0 = SATnot(v0); 02709 } 02710 st_insert(tmpTable,(char*)v1,(char*)v0); 02711 02712 } 02713 L1 = tf->blatchInputs[from]; 02714 L0 = tf->blatchInputs[to]; 02715 for(i=0;i<tf->nbLatches;i++){ 02716 v1 = L1[i]; 02717 v0 = L0[i]; 02718 if(SATisInverted(v1)){ 02719 v1 = SATnot(v1); 02720 v0 = SATnot(v0); 02721 } 02722 st_insert(tmpTable,(char*)v1,(char*)v0); 02723 02724 } 02725 02726 manager->class_ = to; 02727 result = PureSat_MapIPRecur(manager,node,tmpTable); 02728 02729 st_free_table(tmpTable); 02730 02731 return result; 02732 } 02733 02734 02748 void PureSatProcessDummy(bAig_Manager_t *manager, 02749 satManager_t *cm, 02750 RTnode_t RTnode) 02751 { 02752 int i; 02753 bAigEdge_t *lp,node; 02754 RTManager_t *rm = cm->rm; 02755 02756 if(RT_flag(RTnode)&RT_VisitedMask){ 02757 return; 02758 } 02759 RT_flag(RTnode) |= RT_VisitedMask; 02760 02761 if(RT_pivot(RTnode)==0){ /*leaf*/ 02762 #if DBG 02763 assert(RT_oriClsIdx(RTnode)==0); 02764 #endif 02765 if(RT_oriClsIdx(RTnode)) 02766 lp = (long*)SATfirstLit(RT_oriClsIdx(RTnode)); 02767 else 02768 02769 lp = RT_formula(RTnode) + cm->rm->fArray; 02770 for(i=0;i<RT_fSize(RTnode);i++,lp++){ 02771 assert(*lp>0);/* not processed yet*/ 02772 if(RT_oriClsIdx(RTnode))/*is CNF*/ 02773 node = SATgetNode(*lp); 02774 else /*is AIG*/ 02775 node = *lp; 02776 node = SATnormalNode(node); 02777 if(node>=manager->nodesArraySize){ 02778 #if DBG 02779 assert(flags(node)&DummyMask); 02780 #endif 02781 *lp = DUMMY; 02782 } 02783 } 02784 } /*leaf*/ 02785 02786 /*not leaf*/ 02787 else{ 02788 if(RT_pivot(RTnode)>=manager->nodesArraySize){ 02789 int class_ = bAig_Class(RT_pivot(RTnode)); 02790 RT_pivot(RTnode) = DUMMY+class_; 02791 } 02792 PureSatProcessDummy(manager,cm,RT_left(RTnode)); 02793 PureSatProcessDummy(manager,cm,RT_right(RTnode)); 02794 } 02795 02796 return ; 02797 02798 } 02799 02800 02814 bAigEdge_t 02815 PureSat_FindNodeByName( 02816 bAig_Manager_t *manager, 02817 nameType_t *name, 02818 int bound) 02819 { 02820 02821 bAigEdge_t node; 02822 02823 if (!st_lookup(manager->SymbolTableArray[bound], name, &node)){ 02824 node = bAig_NULL; 02825 } 02826 02827 return bAig_GetCanonical(manager, node); 02828 } 02829 02830 02843 bAigEdge_t 02844 PureSatCreatebAigOfPropFormula( 02845 Ntk_Network_t *network, 02846 bAig_Manager_t *manager, 02847 int bound, 02848 Ctlsp_Formula_t *ltl, 02849 int withInitialState) 02850 { 02851 int index; 02852 bAigEdge_t result, left, right, *li; 02853 bAigTimeFrame_t *timeframe; 02854 02855 if (ltl == NIL(Ctlsp_Formula_t)) return bAig_NULL; 02856 if (ltl->type == Ctlsp_TRUE_c) return bAig_One; 02857 if (ltl->type == Ctlsp_FALSE_c) return bAig_Zero; 02858 02859 assert(Ctlsp_isPropositionalFormula(ltl)); 02860 02861 if(withInitialState) timeframe = manager->timeframe; 02862 else timeframe = manager->timeframeWOI; 02863 02864 if (ltl->type == Ctlsp_ID_c){ 02865 char *nodeNameString = Ctlsp_FormulaReadVariableName(ltl); 02866 char *nodeValueString = Ctlsp_FormulaReadValueName(ltl); 02867 Ntk_Node_t *node = Ntk_NetworkFindNodeByName(network, nodeNameString); 02868 02869 Var_Variable_t *nodeVar; 02870 int nodeValue; 02871 02872 MvfAig_Function_t *tmpMvfAig; 02873 st_table *nodeToMvfAigTable; /* maps each node to its mvfAig */ 02874 02875 if (node == NIL(Ntk_Node_t)) { 02876 char *nameKey; 02877 char tmpName[100]; 02878 02879 sprintf(tmpName, "%s_%d", nodeNameString, bound); 02880 nameKey = util_strsav(tmpName); 02881 02882 result = PureSat_FindNodeByName(manager, nameKey,bound); 02883 if(result == bAig_NULL){ 02884 result = PureSat_CreateVarNode(manager, nameKey); 02885 } else { 02886 02887 FREE(nameKey); 02888 } 02889 return result; 02890 } 02891 02892 nodeToMvfAigTable = (st_table *) Ntk_NetworkReadApplInfo(network, MVFAIG_NETWORK_APPL_KEY); 02893 assert(nodeToMvfAigTable != NIL(st_table)); 02894 02895 tmpMvfAig = Bmc_ReadMvfAig(node, nodeToMvfAigTable); 02896 if (tmpMvfAig == NIL(MvfAig_Function_t)){ 02897 tmpMvfAig = Bmc_NodeBuildMVF(network, node); 02898 array_free(tmpMvfAig); 02899 tmpMvfAig = Bmc_ReadMvfAig(node, nodeToMvfAigTable); 02900 } 02901 02902 nodeVar = Ntk_NodeReadVariable(node); 02903 if (Var_VariableTestIsSymbolic(nodeVar)) { 02904 nodeValue = Var_VariableReadIndexFromSymbolicValue(nodeVar, nodeValueString); 02905 if ( nodeValue == -1 ) { 02906 (void) fprintf(vis_stderr, "Value specified in RHS is not in domain of variable\n"); 02907 (void) fprintf(vis_stderr,"%s = %s\n", nodeNameString, nodeValueString); 02908 return bAig_NULL; 02909 } 02910 } 02911 else { 02912 int check; 02913 check = StringCheckIsInteger(nodeValueString, &nodeValue); 02914 if( check == 0 ) { 02915 (void) fprintf(vis_stderr,"Illegal value in the RHS\n"); 02916 (void) fprintf(vis_stderr,"%s = %s\n", nodeNameString, nodeValueString); 02917 return bAig_NULL; 02918 } 02919 if( check == 1 ) { 02920 (void) fprintf(vis_stderr,"Value in the RHS is out of range of int\n"); 02921 (void) fprintf(vis_stderr,"%s = %s", nodeNameString, nodeValueString); 02922 return bAig_NULL; 02923 } 02924 if ( !(Var_VariableTestIsValueInRange(nodeVar, nodeValue))) { 02925 (void) fprintf(vis_stderr,"Value specified in RHS is not in domain of variable\n"); 02926 (void) fprintf(vis_stderr,"%s = %s\n", nodeNameString, nodeValueString); 02927 return bAig_NULL; 02928 02929 } 02930 } 02931 result = MvfAig_FunctionReadComponent(tmpMvfAig, nodeValue); 02932 result = bAig_GetCanonical(manager, result); 02933 if(st_lookup(timeframe->li2index, (char *)result, &index)) { 02934 li = timeframe->latchInputs[bound]; 02935 result = bAig_GetCanonical(manager, li[index]); 02936 } 02937 else if(st_lookup(timeframe->o2index, (char *)result, &index)) { 02938 li = timeframe->outputs[bound]; 02939 result = bAig_GetCanonical(manager, li[index]); 02940 02941 } 02942 else if(st_lookup(timeframe->i2index, (char *)result, &index)) { 02943 li = timeframe->internals[bound]; 02944 result = bAig_GetCanonical(manager, li[index]); 02945 02946 } 02947 return result; 02948 } 02949 02950 left = PureSatCreatebAigOfPropFormula(network, manager, bound, ltl->left, withInitialState); 02951 if (left == bAig_NULL){ 02952 return bAig_NULL; 02953 } 02954 right = PureSatCreatebAigOfPropFormula(network, manager, bound, ltl->right, withInitialState); 02955 if (right == bAig_NULL && ltl->type ==Ctlsp_NOT_c ){ 02956 return bAig_Not(left); 02957 } 02958 else if(right == bAig_NULL) { 02959 return bAig_NULL; 02960 } 02961 02962 switch(ltl->type) { 02963 02964 case Ctlsp_OR_c: 02965 result = PureSat_Or(manager, left, right); 02966 break; 02967 case Ctlsp_AND_c: 02968 result = PureSat_And(manager, left, right); 02969 break; 02970 case Ctlsp_THEN_c: 02971 result = PureSat_Then(manager, left, right); 02972 break; 02973 case Ctlsp_EQ_c: 02974 result = PureSat_Eq(manager, left, right); 02975 break; 02976 case Ctlsp_XOR_c: 02977 result = PureSat_Xor(manager, left, right); 02978 break; 02979 default: 02980 fail("Unexpected type"); 02981 } 02982 return result; 02983 } /* BmcCirCUsCreatebAigOfPropFormula */ 02984 02985 02986 02987 03002 void PureSatMarkObj(bAig_Manager_t * manager, 03003 long from, 03004 long to) 03005 { 03006 long v; 03007 03008 for(v=from;v<=to;v+=bAigNodeSize) 03009 flags(v)|=ObjMask; 03010 } 03011 03012 03013 03027 boolean PureSat_ConcretTest(Ntk_Network_t *network, 03028 PureSat_Manager_t *pm, 03029 array_t *sufArray, 03030 bAigEdge_t property, 03031 array_t *previousResultArray, 03032 int Con, 03033 int satStat, 03034 int inc) 03035 { 03036 mAig_Manager_t * manager = Ntk_NetworkReadMAigManager(network); 03037 int status,i,nodes_in_coi=0; 03038 satManager_t *cm; 03039 char *name; 03040 double t1,t2; 03041 satArray_t *saved; 03042 st_table * SufAbsNameTable = st_init_table(strcmp,st_strhash); 03043 bAigEdge_t from,*lp; 03044 03045 arrayForEachItem(char *,sufArray,i,name){ 03046 st_insert(SufAbsNameTable,name,(char*)0); 03047 } 03048 03049 manager->assertArray = sat_ArrayAlloc(1); 03050 sat_ArrayInsert(manager->assertArray,manager->InitState); 03051 cm = PureSat_SatManagerAlloc_WOCOI(manager,pm,property,previousResultArray); 03052 03053 cm->option->coreGeneration = 0; 03054 cm->option->RT = 0; 03055 cm->option->AbRf = 1; 03056 if(inc){ 03057 cm->option->incTraceObjective = 1; 03058 cm->savedConflictClauses = pm->savedConCls; 03059 pm->savedConCls = 0; 03060 } 03061 t1 = util_cpu_ctime(); 03062 PureSat_CleanMask(manager,ResetVisibleVarMask); 03063 PuresatMarkVisibleVar(network,sufArray,pm,0,pm->Length+1); 03064 if(!Con){ 03065 from = manager->nodesArraySize; 03066 PureSatSetCOI(network,pm,cm,SufAbsNameTable,0,pm->Length,pm->Length); 03067 PureSatKillPseudoGV(network,pm,SufAbsNameTable,1,pm->Length); 03068 if(inc){ 03069 PureSatMarkObj(manager,from,manager->nodesArraySize-bAigNodeSize); 03070 } 03071 PureSat_ResetManager(manager,cm,0); 03072 PureSatProcessFanout(cm); 03073 } 03074 else{ 03075 sat_MarkTransitiveFaninForNode(cm,property,CoiMask); 03076 sat_MarkTransitiveFaninForNode(cm,manager->InitState,CoiMask); 03077 cm->option->AbRf = 0; 03078 } 03079 t2 = util_cpu_ctime(); 03080 pm->tPro += t2-t1; 03081 if(pm->verbosity>=2) 03082 fprintf(vis_stdout,"process time:%g,total:%g\n", 03083 (double)((t2-t1)/1000.0),pm->tPro/1000); 03084 if(pm->verbosity>=1){ 03085 nodes_in_coi = PureSat_CountNodesInCoi(cm); 03086 fprintf(vis_stdout,"There are %d node in COI\n",nodes_in_coi); 03087 } 03088 st_free_table(SufAbsNameTable); 03089 manager->assertArray2 = cm->assertArray2; 03090 sat_Main(cm); 03091 if(satStat) 03092 sat_ReportStatistics(cm,cm->each); 03093 cm->option->AbRf = 1; 03094 manager->NodesArray = cm->nodesArray; 03095 t1 = util_cpu_ctime(); 03096 if(!Con){ 03097 PureSatRecoverFanout(cm,pm); 03098 PureSat_RestoreAigForDummyNode(manager,pm->oldPos); 03099 PureSat_CleanMask(manager,ResetVisited3Mask); 03100 } 03101 /*record conflict*/ 03102 if(inc && cm->savedConflictClauses ){ 03103 if(!Con){ 03104 int num=0; 03105 saved = cm->savedConflictClauses; 03106 pm->savedConCls = sat_ArrayAlloc(1); 03107 for(i=0, lp=saved->space; i<saved->num; i++, lp++){ 03108 sat_ArrayInsert(pm->savedConCls,*lp); 03109 if(*lp<0) 03110 num++; 03111 } 03112 assert(num%2==0); 03113 if(pm->verbosity>=2) 03114 fprintf(vis_stdout,"record %d ConCls for incremental concretization\n",num/2); 03115 } 03116 else 03117 pm->savedConCls = 0; 03118 sat_ArrayFree(cm->savedConflictClauses); 03119 cm->savedConflictClauses = 0; 03120 } 03121 t2 = util_cpu_ctime(); 03122 pm->tPro += t2-t1; 03123 if(pm->verbosity>=2) 03124 fprintf(vis_stdout,"process time:%g,total:%g\n", 03125 (double)((t2-t1)/1000.0),pm->tPro/1000); 03126 sat_ArrayFree(manager->assertArray); 03127 status = cm->status; 03128 cm->option->coreGeneration = 1; 03129 PureSat_SatFreeManager(cm); 03130 if(status == SAT_SAT){ 03131 if(pm->verbosity>=1) 03132 fprintf(vis_stdout,"CEX exist\n"); 03133 return FALSE; /* cex exists*/ 03134 } 03135 else{ 03136 if(pm->verbosity>=1) 03137 fprintf(vis_stdout,"no CEX\n"); 03138 return TRUE; /* no cex*/ 03139 } 03140 03141 } 03142 03143 03144 03159 boolean PureSat_ConcretTest_Core(Ntk_Network_t *network, 03160 PureSat_Manager_t *pm, 03161 array_t *sufArray, 03162 bAigEdge_t property, 03163 array_t *previousResultArray, 03164 st_table * junkTable) 03165 { 03166 mAig_Manager_t * manager = Ntk_NetworkReadMAigManager(network); 03167 int status,i,nodes_in_coi=0; 03168 satManager_t *cm; 03169 char *name; 03170 double t1,t2; 03171 st_table * SufAbsNameTable = st_init_table(strcmp,st_strhash); 03172 array_t * tmpRef1; 03173 st_table *refTable = st_init_table(strcmp,st_strhash); 03174 03175 arrayForEachItem(char *,sufArray,i,name){ 03176 st_insert(SufAbsNameTable,name,(char*)0); 03177 } 03178 03179 manager->assertArray = sat_ArrayAlloc(1); 03180 sat_ArrayInsert(manager->assertArray,manager->InitState); 03181 cm = PureSat_SatManagerAlloc_WOCOI(manager,pm,property,previousResultArray); 03182 cm->option->coreGeneration = 1; 03183 cm->option->AbRf = 1; 03184 cm->option->IP = 1; 03185 t1 = util_cpu_ctime(); 03186 PureSat_CleanMask(manager,ResetVisibleVarMask); 03187 PuresatMarkVisibleVarWithVPGV(network,sufArray,pm,0,pm->Length+1); 03188 03189 PureSatSetCOI(network,pm,cm,SufAbsNameTable,0,pm->Length,pm->Length); 03190 PureSatKillPseudoGV(network,pm,SufAbsNameTable,1,pm->Length); 03191 PureSat_ResetManager(manager,cm,0); 03192 PureSatProcessFanout(cm); 03193 03194 t2 = util_cpu_ctime(); 03195 pm->tPro += t2-t1; 03196 if(pm->verbosity>=2) 03197 fprintf(vis_stdout,"process time:%g,total:%g\n", 03198 (double)((t2-t1)/1000.0),pm->tPro/1000); 03199 if(pm->verbosity>=1){ 03200 nodes_in_coi = PureSat_CountNodesInCoi(cm); 03201 fprintf(vis_stdout,"There are %d node in COI\n",nodes_in_coi); 03202 } 03203 manager->assertArray2 = cm->assertArray2; 03204 sat_Main(cm); 03205 manager->NodesArray = cm->nodesArray; 03206 t1 = util_cpu_ctime(); 03207 PureSatRecoverFanout(cm,pm); 03208 PureSat_RestoreAigForDummyNode(manager,pm->oldPos); 03209 PureSat_CleanMask(manager,ResetVisited3Mask); 03210 if(cm->status==SAT_UNSAT){ 03211 PureSatProcessDummy(manager,cm,cm->rm->root); 03212 ResetRTree(cm->rm); 03213 } 03214 t2 = util_cpu_ctime(); 03215 pm->tPro += t2-t1; 03216 if(pm->verbosity>=2) 03217 fprintf(vis_stdout,"process time:%g,total:%g\n", 03218 (double)((t2-t1)/1000.0),pm->tPro/1000); 03219 03220 if(cm->status==SAT_UNSAT){ 03221 tmpRef1 = PureSat_GetSufAbsFromCore(network,cm,pm,property,SufAbsNameTable); 03222 03223 arrayForEachItem(char*,tmpRef1,i,name) 03224 st_insert(refTable,name,(char*)0); 03225 03226 arrayForEachItem(char*,sufArray,i,name){ 03227 if(!st_lookup(refTable,name,NIL(char*))&& 03228 !st_lookup(pm->vertexTable,name,NIL(char*))){ 03229 if(pm->verbosity>=2) 03230 fprintf(vis_stdout,"%s can be gotten rid of\n",name); 03231 st_insert(junkTable,name,(char*)0); 03232 } 03233 } 03234 array_free(tmpRef1); 03235 } 03236 03237 st_free_table(SufAbsNameTable); 03238 st_free_table(refTable); 03239 RT_Free(cm->rm); 03240 sat_ArrayFree(manager->assertArray); 03241 status = cm->status; 03242 cm->option->coreGeneration = 1; 03243 PureSat_SatFreeManager(cm); 03244 if(status == SAT_SAT){ 03245 if(pm->verbosity>=1) 03246 fprintf(vis_stdout,"CEX exist\n"); 03247 return FALSE; // cex exists 03248 } 03249 else{ 03250 if(pm->verbosity>=1) 03251 fprintf(vis_stdout,"no CEX\n"); 03252 return TRUE; // no cex 03253 } 03254 03255 } 03256 03257 03271 void PureSatGenerateRingForNode(Ntk_Network_t *network, 03272 PureSat_Manager_t *pm, 03273 Ntk_Node_t * node1, 03274 array_t * ringArray, 03275 int *dfs) 03276 { 03277 Ntk_Node_t *node; 03278 char *name; 03279 int i; 03280 03281 if(PureSatNodeReadColor(node1) == dfsBlack_c) 03282 return; 03283 PureSatNodeSetColor(node1,dfsBlack_c); 03284 if(Ntk_NodeTestIsLatch(node1)){ 03285 name = Ntk_NodeReadName(node1); 03286 st_insert(pm->node2dfsTable,name,(char*)(long)(*dfs)); 03287 array_insert_last(char *,ringArray,name); 03288 return; 03289 } 03290 03291 Ntk_NodeForEachFanin(node1,i,node){ 03292 PureSatGenerateRingForNode(network,pm,node,ringArray, 03293 dfs); 03294 } 03295 return; 03296 } 03297 03298 03311 array_t * PureSatGenerateRing(Ntk_Network_t *network, 03312 PureSat_Manager_t *pm, 03313 array_t * coreArray, 03314 int * dfs) 03315 { 03316 array_t * ringArray = array_alloc(char *,0); 03317 int i,j; 03318 char *name; 03319 Ntk_Node_t *node1,*node; 03320 03321 arrayForEachItem(char *,coreArray,i,name){ 03322 node1 = Ntk_NetworkFindNodeByName(network,name); 03323 Ntk_NodeForEachFanin(node1,j,node){ 03324 PureSatGenerateRingForNode(network,pm,node, 03325 ringArray,dfs); 03326 } 03327 } 03328 return ringArray; 03329 } 03330 03331 03344 void PureSatGenerateDfs(Ntk_Network_t *network, 03345 PureSat_Manager_t *pm, 03346 array_t * vertexArray) 03347 { 03348 03349 int dfs = 1,i,ct=0; 03350 char *name; 03351 Ntk_Node_t *node; 03352 array_t * ringArray = array_alloc(char *,0); 03353 array_t * coreArray; 03354 lsGen gen; 03355 st_generator * stgen; 03356 03357 Ntk_NetworkForEachNode( network, gen, node ) { 03358 PureSatNodeSetColor( node, dfsWhite_c ); 03359 } 03360 03361 arrayForEachItem(char *,vertexArray,i,name){ 03362 st_insert(pm->node2dfsTable,name,(char*)(long)dfs); 03363 node = Ntk_NetworkFindNodeByName(network,name); 03364 PureSatNodeSetColor(node,dfsBlack_c); 03365 ct++; 03366 } 03367 03368 coreArray = array_dup(vertexArray); 03369 03370 while(coreArray->num>0){ 03371 dfs++; 03372 ringArray = PureSatGenerateRing(network,pm,coreArray, 03373 &dfs); 03374 arrayForEachItem(char*,ringArray,i,name){ 03375 st_insert(pm->node2dfsTable,name,(char*)(long)dfs); 03376 03377 ct++; 03378 } 03379 array_free(coreArray); 03380 coreArray = ringArray; 03381 } 03382 03383 st_foreach_item(pm->CoiTable,stgen,&node,NIL(char*)){ 03384 name = Ntk_NodeReadName(node); 03385 if(!st_lookup(pm->node2dfsTable,name,NIL(char*))){ 03386 st_insert(pm->node2dfsTable,name,(char*)LARGEDFS); 03387 if(pm->verbosity>=2) 03388 fprintf(vis_stdout,"%s LARGEDFS is inserted into node2dfsTable\n",name); 03389 } 03390 } 03391 03392 return; 03393 03394 } 03395 03409 array_t * PureSatComputeOrder_2(Ntk_Network_t *network, 03410 PureSat_Manager_t *pm, 03411 array_t * vertexArray, 03412 array_t * invisibleArray, 03413 int * sccArray, 03414 int * NumInSecondLevel) 03415 { 03416 03417 array_t * RCArray; 03418 03419 PureSatGenerateDfs(network,pm,vertexArray); 03420 RCArray = PureSatGenerateRCArray_2(network,pm,invisibleArray, 03421 NumInSecondLevel); 03422 03423 return RCArray; 03424 } 03425 03426 03427 03441 void PureSatAddIdenLatchToAbs(Ntk_Network_t *network, 03442 PureSat_Manager_t *pm, 03443 array_t *nameArray) 03444 { 03445 int i; 03446 st_generator * stgen; 03447 st_table* table; 03448 char *name,*name1; 03449 st_table *table1 = st_init_table(st_ptrcmp,st_ptrhash); 03450 array_t * tmpArray = array_alloc(char*,0); 03451 03452 st_foreach_item(pm->vertexTable,stgen,&name,NIL(char*)) 03453 st_insert(table1,name,(char*)0); 03454 arrayForEachItem(char*,nameArray,i,name) 03455 st_insert(table1,name,(char*)0); 03456 03457 arrayForEachItem(char*,nameArray,i,name){ 03458 03459 if(st_lookup(pm->IdenLatchTable,name,&table)){ 03460 st_foreach_item(table,stgen,&name1,NIL(char*)){ 03461 if(!st_lookup(table1,name1,NIL(char*))){ 03462 st_insert(table1,name1,(char*)0); 03463 array_insert_last(char*,tmpArray,name1); 03464 } 03465 } 03466 } 03467 } 03468 03469 arrayForEachItem(char*,tmpArray,i,name){ 03470 array_insert_last(char*,nameArray,name); 03471 if(pm->verbosity>=2) 03472 fprintf(vis_stdout,"add %s to refineArray\n",name); 03473 } 03474 03475 array_free(tmpArray); 03476 st_free_table(table1); 03477 } 03478 03479 03491 void 03492 PureSatCreateInitAbsByAIG(bAig_Manager_t *manager, 03493 PureSat_Manager_t *pm, 03494 bAigEdge_t node, 03495 st_table * tmpTable) 03496 { 03497 bAigTimeFrame_t * tf = manager->timeframeWOI; 03498 char * name; 03499 st_table * table; 03500 st_generator * stgen; 03501 03502 if(node==bAig_NULL) 03503 return; 03504 03505 node = bAig_NonInvertedEdge(node); 03506 03507 if(flags(node)&VisitedMask) 03508 return; 03509 03510 flags(node) |= VisitedMask; 03511 03512 03513 if(flags(node)&StateBitMask){ 03514 if(!st_lookup(tf->MultiLatchTable,(char*)node,&table)){ 03515 int retVal = st_lookup(tf->idx2name,(char*)node,&name); 03516 assert(retVal); 03517 if(!st_lookup(tmpTable,name,NIL(char*))){ 03518 st_insert(tmpTable,name,(char*)0); 03519 03520 } 03521 } 03522 else{ 03523 st_foreach_item(table,stgen,&name,NIL(char*)){ 03524 if(!st_lookup(tmpTable,name,NIL(char*))){ 03525 st_insert(tmpTable,name,(char*)0); 03526 03527 } 03528 } 03529 } 03530 } 03531 03532 if(flags(node)&StateBitMask) 03533 return; 03534 03535 PureSatCreateInitAbsByAIG(manager,pm,leftChild(node),tmpTable); 03536 PureSatCreateInitAbsByAIG(manager,pm,rightChild(node),tmpTable); 03537 } 03538 03539 03553 void 03554 PureSat_GetLatchForNode(bAig_Manager_t *manager, 03555 PureSat_Manager_t *pm, 03556 bAigEdge_t node, 03557 array_t * nameArray, 03558 st_table *tmpTable, 03559 int cut) 03560 { 03561 bAigTimeFrame_t * tf = manager->timeframeWOI; 03562 char * name; 03563 st_table * table; 03564 st_generator * stgen; 03565 03566 if(node==bAig_NULL) 03567 return; 03568 03569 node = bAig_NonInvertedEdge(node); 03570 03571 if(flags(node)&VisitedMask) 03572 return; 03573 03574 flags(node) |= VisitedMask; 03575 03576 03577 if(flags(node)&StateBitMask){ 03578 if(!st_lookup(tf->MultiLatchTable,(char*)node,&table)){ 03579 int retVal = st_lookup(tf->idx2name,(char*)node,&name); 03580 assert(retVal); 03581 if(!st_lookup(tmpTable,name,NIL(char*))){ 03582 st_insert(tmpTable,name,(char*)0); 03583 array_insert_last(char *,nameArray,name); 03584 if(pm->verbosity>=2) 03585 fprintf(vis_stdout,"insert %s\n",name); 03586 } 03587 } 03588 else{ 03589 st_foreach_item(table,stgen,&name,NIL(char*)){ 03590 if(!st_lookup(tmpTable,name,NIL(char*))){ 03591 st_insert(tmpTable,name,(char*)0); 03592 array_insert_last(char *,nameArray,name); 03593 if(pm->verbosity>=2) 03594 fprintf(vis_stdout,"insert %s\n",name); 03595 } 03596 } 03597 } 03598 } 03599 03600 if(cut==2){ 03601 if(flags(node)&Visited2Mask) 03602 return; 03603 } 03604 else{ 03605 if(cut==1){ 03606 if(flags(node)&Visited3Mask) 03607 return; 03608 } 03609 else{ 03610 fprintf(vis_stdout,"wrong cut\n"); 03611 exit(0); 03612 } 03613 } 03614 03615 PureSat_GetLatchForNode(manager,pm,leftChild(node),nameArray,tmpTable,cut); 03616 PureSat_GetLatchForNode(manager,pm,rightChild(node),nameArray,tmpTable,cut); 03617 } 03618 03619 03632 st_table * PureSatGetAigCoi(Ntk_Network_t *network, 03633 PureSat_Manager_t *pm, 03634 bAigEdge_t property) 03635 { 03636 bAig_Manager_t *manager; 03637 st_table * node2MvfAigTable,*tmpTable; 03638 array_t * nameArray,*nameArray1; 03639 bAigTimeFrame_t *tf; 03640 char * name; 03641 Ntk_Node_t *latch; 03642 MvfAig_Function_t *mvfAig; 03643 mAigMvar_t lmVar; 03644 mAigBvar_t bVar; 03645 array_t *bVarList,*mVarList; 03646 int i,j,lmAigId; 03647 long index,index1; 03648 bAigEdge_t v, *li, *bli; 03649 03650 manager = Ntk_NetworkReadMAigManager(network); 03651 if (manager == NIL(mAig_Manager_t)) { 03652 (void) fprintf(vis_stdout, 03653 "** bmc error: run build_partition_maigs command first\n"); 03654 exit(0);; 03655 } 03656 node2MvfAigTable =(st_table *) Ntk_NetworkReadApplInfo(network, 03657 MVFAIG_NETWORK_APPL_KEY); 03658 tf = manager->timeframeWOI; 03659 03660 bVarList = mAigReadBinVarList(manager); 03661 mVarList = mAigReadMulVarList(manager); 03662 03663 assert(manager->timeframeWOI->currentTimeframe>=2); 03664 PureSat_CleanMask(manager,ResetVisitedMask); 03665 PureSat_CleanMask(manager,ResetVisited2Mask); 03666 PureSat_CleanMask(manager,ResetVisited3Mask); 03667 li = tf->latchInputs[1]; 03668 for(i=0;i<tf->nLatches;i++) 03669 flags(li[i])|=Visited3Mask; 03670 li = tf->blatchInputs[1]; 03671 for(i=0;i<tf->nbLatches;i++) 03672 flags(li[i])|=Visited3Mask; 03673 li = tf->latchInputs[2]; 03674 for(i=0;i<tf->nLatches;i++) 03675 flags(li[i])|=Visited2Mask; 03676 li = tf->blatchInputs[2]; 03677 for(i=0;i<tf->nbLatches;i++) 03678 flags(li[i])|=Visited2Mask; 03679 03680 nameArray = array_alloc(char *,0); 03681 tmpTable = st_init_table(st_ptrcmp,st_ptrhash); 03682 PureSat_GetLatchForNode(manager,pm,property,nameArray,tmpTable,2); 03683 PureSat_CleanMask(manager,ResetVisitedMask); 03684 03685 03686 li = tf->latchInputs[2]; 03687 bli = tf->blatchInputs[2]; 03688 while(nameArray->num>0){ 03689 nameArray1 = nameArray; 03690 nameArray = array_alloc(char *,0); 03691 arrayForEachItem(char*,nameArray1,i,name){ 03692 latch = Ntk_NetworkFindNodeByName(network,name); 03693 st_lookup(node2MvfAigTable,latch,&mvfAig); 03694 for(j=0;j<mvfAig->num;j++){ 03695 int retVal; 03696 v = bAig_GetCanonical(manager,MvfAig_FunctionReadComponent(mvfAig,j)); 03697 if(v==bAig_Zero||v==bAig_One) 03698 continue; 03699 retVal = st_lookup(tf->li2index,(char*)v,&index); 03700 assert(retVal); 03701 if(li[index]==bAig_Zero||li[index]==bAig_One) 03702 continue; 03703 PureSat_GetLatchForNode(manager,pm,li[index],nameArray,tmpTable,1); 03704 } 03705 03706 03707 lmAigId = Ntk_NodeReadMAigId(latch); 03708 lmVar = array_fetch(mAigMvar_t, mVarList,lmAigId); 03709 for(j=0,index1=lmVar.bVars;j<lmVar.encodeLength;j++,index1++){ 03710 int retVal; 03711 bVar = array_fetch(mAigBvar_t,bVarList,index1); 03712 if(bVar.node==bAig_Zero||bVar.node==bAig_One) 03713 continue; 03714 retVal = st_lookup(tf->bli2index,(char*)bVar.node,&index); 03715 assert(retVal); 03716 if(bli[index]==bAig_Zero||bli[index]==bAig_One) 03717 continue; 03718 PureSat_GetLatchForNode(manager,pm,bli[index],nameArray,tmpTable,1); 03719 } 03720 } 03721 03722 array_free(nameArray1); 03723 } 03724 03725 array_free(nameArray); 03726 PureSat_CleanMask(manager,ResetVisitedMask); 03727 PureSat_CleanMask(manager,ResetVisited2Mask); 03728 PureSat_CleanMask(manager,ResetVisited3Mask); 03729 03730 return tmpTable; 03731 } 03732 03733 03748 void PureSatPreProcLatch(Ntk_Network_t *network, 03749 PureSat_Manager_t *pm) 03750 { 03751 st_generator * stgen; 03752 bAig_Manager_t * manager = Ntk_NetworkReadMAigManager(network); 03753 st_table * node2MvfAigTable =(st_table *) Ntk_NetworkReadApplInfo(network, 03754 MVFAIG_NETWORK_APPL_KEY); 03755 bAigTimeFrame_t * tf = manager->timeframeWOI; 03756 mAigMvar_t lmVar; 03757 mAigBvar_t bVar; 03758 array_t *bVarList,*mVarList; 03759 int j,lmAigId,id,index1; 03760 char * name; 03761 Ntk_Node_t * latch; 03762 bAigEdge_t v, **li, **bli; 03763 MvfAig_Function_t *mvfAig; 03764 03765 bVarList = mAigReadBinVarList(manager); 03766 mVarList = mAigReadMulVarList(manager); 03767 li = tf->latchInputs; 03768 bli = tf->blatchInputs; 03769 03770 st_foreach_item(pm->CoiTable,stgen,&latch,NIL(char*)){ 03771 int checkbin=1; 03772 st_lookup(node2MvfAigTable,latch,&mvfAig); 03773 for(j=0;j<mvfAig->num;j++){ 03774 int retVal; 03775 v = bAig_GetCanonical(manager,MvfAig_FunctionReadComponent(mvfAig,j)); 03776 if(v==bAig_Zero||v==bAig_One) 03777 continue; 03778 retVal = st_lookup(tf->li2index,(char*)v,&id); 03779 assert(retVal); 03780 if(li[0][id]==li[1][id]&&li[1][id]==li[2][id]){ 03781 name = Ntk_NodeReadName(latch); 03782 st_insert(pm->vertexTable,name,(char*)0); 03783 if(pm->verbosity>=2) 03784 fprintf(vis_stdout,"preproc: add %s to abs\n",name); 03785 checkbin = 0; 03786 break; 03787 } 03788 } 03789 if(checkbin){ 03790 lmAigId = Ntk_NodeReadMAigId(latch); 03791 lmVar = array_fetch(mAigMvar_t, mVarList,lmAigId); 03792 for(j=0,index1=lmVar.bVars;j<lmVar.encodeLength;j++,index1++){ 03793 int retVal; 03794 bVar = array_fetch(mAigBvar_t,bVarList,index1); 03795 if(bVar.node==bAig_Zero||bVar.node==bAig_One) 03796 continue; 03797 retVal = st_lookup(tf->bli2index,(char*)bVar.node,&id); 03798 assert(retVal); 03799 if(bli[0][id]==bli[1][id]&&bli[1][id]==bli[2][id]){ 03800 name = Ntk_NodeReadName(latch); 03801 st_insert(pm->vertexTable,name,(char*)0); 03802 if(pm->verbosity>=2) 03803 fprintf(vis_stdout,"preproc BINARY: add %s to abs\n",name); 03804 break; 03805 } 03806 } 03807 } 03808 } 03809 03810 } 03811 03812 03825 void PureSatGetIndenticalLatch(Ntk_Network_t *network, 03826 PureSat_Manager_t *pm) 03827 { 03828 bAig_Manager_t *manager = Ntk_NetworkReadMAigManager(network); 03829 bAigTimeFrame_t * tf = manager->timeframeWOI; 03830 bAigEdge_t *li=tf->latchInputs[2],*bli = tf->blatchInputs[2]; 03831 int i; 03832 bAigEdge_t v; 03833 st_table *table; 03834 st_generator *stgen,*stgen1; 03835 char *name,*name1; 03836 st_table *table2,*table1=st_init_table(st_ptrcmp,st_ptrhash); 03837 03838 pm->IdenLatchTable = st_init_table(st_ptrcmp,st_ptrhash); 03839 03840 for(i=0;i<tf->nLatches;i++){ 03841 v=bAig_NonInvertedEdge(li[i]); 03842 if(!st_lookup(table1,(char*)v,NIL(char*))){ 03843 if(st_lookup(tf->MultiLatchTable,(char*)v,&table)){ 03844 int init=0; 03845 st_foreach_item(table,stgen,&name,NIL(char*)){ 03846 if(!st_lookup(pm->IdenLatchTable,name,&table2)){ 03847 st_insert(pm->IdenLatchTable,name,table); 03848 if(pm->verbosity>=2) 03849 fprintf(vis_stdout,"%s and ",name); 03850 init = 1; 03851 } 03852 /*insert everything in table 2 into table 03853 name is already in another group, put everything of current group 03854 into that group*/ 03855 else{ 03856 st_foreach_item(table,stgen1,&name1,NIL(char*)){ 03857 st_insert(table2,name1,(char*)0); 03858 st_insert(pm->IdenLatchTable,name1,table2); 03859 if(pm->verbosity>=2) 03860 fprintf(vis_stdout,"%s and ",name1); 03861 } 03862 if(pm->verbosity>=2) 03863 fprintf(vis_stdout,"are the same\n"); 03864 break; 03865 } 03866 } 03867 if(init){ 03868 if(pm->verbosity>=2) 03869 fprintf(vis_stdout,"are the same\n"); 03870 } 03871 } 03872 st_insert(table1,(char*)v,(char*)0); 03873 } 03874 } 03875 03876 03877 for(i=0;i<tf->nbLatches;i++){ 03878 v=bAig_NonInvertedEdge(bli[i]); 03879 if(!st_lookup(table1,(char*)v,NIL(char*))){ 03880 if(st_lookup(tf->MultiLatchTable,(char*)v,&table)){ 03881 int init=0; 03882 st_foreach_item(table,stgen,&name,NIL(char*)){ 03883 03884 if(!st_lookup(pm->IdenLatchTable,name,table2)){ 03885 st_insert(pm->IdenLatchTable,name,table); 03886 if(pm->verbosity>=2) 03887 fprintf(vis_stdout,"%s and ",name); 03888 init = 1; 03889 } 03890 /*insert everything in table 2 into table 03891 name is already in another group, put everything of current group 03892 into that group*/ 03893 else{ 03894 st_foreach_item(table,stgen1,&name1,NIL(char*)){ 03895 03896 st_insert(table2,name1,(char*)0); 03897 st_insert(pm->IdenLatchTable,name1,table2); 03898 if(pm->verbosity>=2) 03899 fprintf(vis_stdout,"%s and ",name1); 03900 } 03901 if(pm->verbosity>=2) 03902 fprintf(vis_stdout,"are the same\n"); 03903 break; 03904 } 03905 } 03906 if(init){ 03907 if(pm->verbosity>=2) 03908 fprintf(vis_stdout,"are the same\n"); 03909 } 03910 } 03911 st_insert(table1,(char*)v,(char*)0); 03912 } 03913 } 03914 03915 st_free_table(table1); 03916 }