ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcNtbdd.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "aig/saig/saig.h"
23
24#ifdef ABC_USE_CUDD
25#include "bdd/extrab/extraBdd.h"
26#endif
27
29
30
34
35#ifdef ABC_USE_CUDD
36
37 int Abc_NtkBddToMuxesPerformGlo( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkNew, int Limit, int fReorder, int fUseAdd );
38static void Abc_NtkBddToMuxesPerform( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkNew );
39static Abc_Obj_t * Abc_NodeBddToMuxes( Abc_Obj_t * pNodeOld, Abc_Ntk_t * pNtkNew );
40static Abc_Obj_t * Abc_NodeBddToMuxes_rec( DdManager * dd, DdNode * bFunc, Abc_Ntk_t * pNtkNew, st__table * tBdd2Node );
41static DdNode * Abc_NodeGlobalBdds_rec( DdManager * dd, Abc_Obj_t * pNode, int nBddSizeMax, int fDropInternal, ProgressBar * pProgress, int * pCounter, int fVerbose );
42
46
63Abc_Ntk_t * Abc_NtkDeriveFromBdd( void * dd0, void * bFunc, char * pNamePo, Vec_Ptr_t * vNamesPi )
64{
65 DdManager * dd = (DdManager *)dd0;
66 Abc_Ntk_t * pNtk;
67 Vec_Ptr_t * vNamesPiFake = NULL;
68 Abc_Obj_t * pNode, * pNodePi, * pNodePo;
69 DdNode * bSupp, * bTemp;
70 char * pName;
71 int i;
72
73 // supply fake names if real names are not given
74 if ( pNamePo == NULL )
75 pNamePo = "F";
76 if ( vNamesPi == NULL )
77 {
78 vNamesPiFake = Abc_NodeGetFakeNames( dd->size );
79 vNamesPi = vNamesPiFake;
80 }
81
82 // make sure BDD depends on the variables whose index
83 // does not exceed the size of the array with PI names
84 bSupp = Cudd_Support( dd, (DdNode *)bFunc ); Cudd_Ref( bSupp );
85 for ( bTemp = bSupp; bTemp != Cudd_ReadOne(dd); bTemp = cuddT(bTemp) )
86 if ( (int)Cudd_NodeReadIndex(bTemp) >= Vec_PtrSize(vNamesPi) )
87 break;
88 Cudd_RecursiveDeref( dd, bSupp );
89 if ( bTemp != Cudd_ReadOne(dd) )
90 return NULL;
91
92 // start the network
94 pNtk->pName = Extra_UtilStrsav(pNamePo);
95 // make sure the new manager has enough inputs
96 Cudd_bddIthVar( (DdManager *)pNtk->pManFunc, Vec_PtrSize(vNamesPi) );
97 // add the PIs corresponding to the names
98 Vec_PtrForEachEntry( char *, vNamesPi, pName, i )
99 Abc_ObjAssignName( Abc_NtkCreatePi(pNtk), pName, NULL );
100 // create the node
101 pNode = Abc_NtkCreateNode( pNtk );
102 pNode->pData = (DdNode *)Cudd_bddTransfer( dd, (DdManager *)pNtk->pManFunc, (DdNode *)bFunc ); Cudd_Ref((DdNode *)pNode->pData);
103 Abc_NtkForEachPi( pNtk, pNodePi, i )
104 Abc_ObjAddFanin( pNode, pNodePi );
105 // create the only PO
106 pNodePo = Abc_NtkCreatePo( pNtk );
107 Abc_ObjAddFanin( pNodePo, pNode );
108 Abc_ObjAssignName( pNodePo, pNamePo, NULL );
109 // make the network minimum base
110 Abc_NtkMinimumBase( pNtk );
111 if ( vNamesPiFake )
112 Abc_NodeFreeNames( vNamesPiFake );
113 if ( !Abc_NtkCheck( pNtk ) )
114 fprintf( stdout, "Abc_NtkDeriveFromBdd(): Network check has failed.\n" );
115 return pNtk;
116}
117
118
119
132Abc_Ntk_t * Abc_NtkBddToMuxes( Abc_Ntk_t * pNtk, int fGlobal, int Limit, int fUseAdd )
133{
134 Abc_Ntk_t * pNtkNew;
135 pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_SOP );
136 if ( fGlobal )
137 {
138 if ( !Abc_NtkBddToMuxesPerformGlo( pNtk, pNtkNew, Limit, 0, fUseAdd ) )
139 {
140 Abc_NtkDelete( pNtkNew );
141 return NULL;
142 }
143 }
144 else
145 {
146 Abc_NtkBddToMuxesPerform( pNtk, pNtkNew );
147 Abc_NtkFinalize( pNtk, pNtkNew );
148 }
149 // make sure everything is okay
150 if ( !Abc_NtkCheck( pNtkNew ) )
151 {
152 printf( "Abc_NtkBddToMuxes: The network check has failed.\n" );
153 Abc_NtkDelete( pNtkNew );
154 return NULL;
155 }
156 return pNtkNew;
157}
158
170void Abc_NtkBddToMuxesPerform( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkNew )
171{
172 ProgressBar * pProgress;
173 Abc_Obj_t * pNode, * pNodeNew;
174 Vec_Ptr_t * vNodes;
175 int i;
176 assert( Abc_NtkIsBddLogic(pNtk) );
177 // perform conversion in the topological order
178 vNodes = Abc_NtkDfs( pNtk, 0 );
179 pProgress = Extra_ProgressBarStart( stdout, vNodes->nSize );
180 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
181 {
182 Extra_ProgressBarUpdate( pProgress, i, NULL );
183 // convert one node
184 assert( Abc_ObjIsNode(pNode) );
185 pNodeNew = Abc_NodeBddToMuxes( pNode, pNtkNew );
186 // mark the old node with the new one
187 assert( pNode->pCopy == NULL );
188 pNode->pCopy = pNodeNew;
189 }
190 Vec_PtrFree( vNodes );
191 Extra_ProgressBarStop( pProgress );
192}
193
205Abc_Obj_t * Abc_NodeBddToMuxes( Abc_Obj_t * pNodeOld, Abc_Ntk_t * pNtkNew )
206{
207 DdManager * dd = (DdManager *)pNodeOld->pNtk->pManFunc;
208 DdNode * bFunc = (DdNode *)pNodeOld->pData;
209 Abc_Obj_t * pFaninOld, * pNodeNew;
210 st__table * tBdd2Node;
211 int i;
212 // create the table mapping BDD nodes into the ABC nodes
213 tBdd2Node = st__init_table( st__ptrcmp, st__ptrhash );
214 // add the constant and the elementary vars
215 Abc_ObjForEachFanin( pNodeOld, pFaninOld, i )
216 st__insert( tBdd2Node, (char *)Cudd_bddIthVar(dd, i), (char *)pFaninOld->pCopy );
217 // create the new nodes recursively
218 pNodeNew = Abc_NodeBddToMuxes_rec( dd, Cudd_Regular(bFunc), pNtkNew, tBdd2Node );
219 st__free_table( tBdd2Node );
220 if ( Cudd_IsComplement(bFunc) )
221 pNodeNew = Abc_NtkCreateNodeInv( pNtkNew, pNodeNew );
222 return pNodeNew;
223}
224
236Abc_Obj_t * Abc_NodeBddToMuxes_rec( DdManager * dd, DdNode * bFunc, Abc_Ntk_t * pNtkNew, st__table * tBdd2Node )
237{
238 Abc_Obj_t * pNodeNew, * pNodeNew0, * pNodeNew1, * pNodeNewC;
239 assert( !Cudd_IsComplement(bFunc) );
240 //assert( b1 == a1 );
241 if ( bFunc == a1 )
242 return Abc_NtkCreateNodeConst1(pNtkNew);
243 if ( bFunc == a0 )
244 return Abc_NtkCreateNodeConst0(pNtkNew);
245 if ( st__lookup( tBdd2Node, (char *)bFunc, (char **)&pNodeNew ) )
246 return pNodeNew;
247 // solve for the children nodes
248 pNodeNew0 = Abc_NodeBddToMuxes_rec( dd, Cudd_Regular(cuddE(bFunc)), pNtkNew, tBdd2Node );
249 if ( Cudd_IsComplement(cuddE(bFunc)) )
250 pNodeNew0 = Abc_NtkCreateNodeInv( pNtkNew, pNodeNew0 );
251 pNodeNew1 = Abc_NodeBddToMuxes_rec( dd, cuddT(bFunc), pNtkNew, tBdd2Node );
252 if ( ! st__lookup( tBdd2Node, (char *)Cudd_bddIthVar(dd, bFunc->index), (char **)&pNodeNewC ) )
253 assert( 0 );
254 // create the MUX node
255 pNodeNew = Abc_NtkCreateNodeMux( pNtkNew, pNodeNewC, pNodeNew1, pNodeNew0 );
256 st__insert( tBdd2Node, (char *)bFunc, (char *)pNodeNew );
257 return pNodeNew;
258}
259
271int Abc_NtkBddToMuxesPerformGlo( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkNew, int Limit, int fReorder, int fUseAdd )
272{
273 DdManager * dd;
274 Vec_Ptr_t * vAdds = fUseAdd ? Vec_PtrAlloc(100) : NULL;
275 Abc_Obj_t * pObj, * pObjNew; int i;
276 st__table * tBdd2Node;
277 assert( Abc_NtkIsStrash(pNtk) );
278 dd = (DdManager *)Abc_NtkBuildGlobalBdds( pNtk, Limit, 1, fReorder, 0, 0 );
279 if ( dd == NULL )
280 {
281 printf( "Construction of global BDDs has failed.\n" );
282 return 0;
283 }
284 //printf( "Shared BDD size = %6d nodes.\n", Cudd_ReadKeys(dd) - Cudd_ReadDead(dd) );
285
286 tBdd2Node = st__init_table( st__ptrcmp, st__ptrhash );
287 Abc_NtkForEachCi( pNtkNew, pObjNew, i )
288 st__insert( tBdd2Node, (char *)Cudd_bddIthVar(dd, i), (char *)pObjNew );
289
290 // complement the global functions
291 Abc_NtkForEachCo( pNtk, pObj, i )
292 {
293 DdNode * bFunc = (DdNode *)Abc_ObjGlobalBdd(pObj);
294 if ( fUseAdd )
295 {
296 DdNode * aFunc = Cudd_BddToAdd( dd, bFunc ); Cudd_Ref( aFunc );
297 pObjNew = Abc_NodeBddToMuxes_rec( dd, aFunc, pNtkNew, tBdd2Node );
298 Vec_PtrPush( vAdds, aFunc );
299 }
300 else
301 {
302 pObjNew = Abc_NodeBddToMuxes_rec( dd, Cudd_Regular(bFunc), pNtkNew, tBdd2Node );
303 if ( Cudd_IsComplement(bFunc) )
304 pObjNew = Abc_NtkCreateNodeInv( pNtkNew, pObjNew );
305 }
306 Abc_ObjAddFanin( pObj->pCopy, pObjNew );
307 }
308
309 // cleanup
310 st__free_table( tBdd2Node );
311 Abc_NtkFreeGlobalBdds( pNtk, 0 );
312 if ( vAdds )
313 {
314 DdNode * aTemp;
315 Vec_PtrForEachEntry( DdNode *, vAdds, aTemp, i )
316 Cudd_RecursiveDeref( dd, aTemp );
317 Vec_PtrFree( vAdds );
318 }
319 Extra_StopManager( dd );
320 Abc_NtkCleanCopy( pNtk );
321 return 1;
322}
323
335void * Abc_NtkBuildGlobalBdds( Abc_Ntk_t * pNtk, int nBddSizeMax, int fDropInternal, int fReorder, int fReverse, int fVerbose )
336{
337 ProgressBar * pProgress;
338 Abc_Obj_t * pObj, * pFanin;
339 Vec_Att_t * pAttMan;
340 DdManager * dd;
341 DdNode * bFunc;
342 int i, k, Counter;
343
344 // remove dangling nodes
346
347 // start the manager
348 assert( Abc_NtkGlobalBdd(pNtk) == NULL );
349 dd = Cudd_Init( Abc_NtkCiNum(pNtk), 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
350 pAttMan = Vec_AttAlloc( Abc_NtkObjNumMax(pNtk) + 1, dd, (void (*)(void*))Extra_StopManager, NULL, (void (*)(void*,void*))Cudd_RecursiveDeref );
351 Vec_PtrWriteEntry( pNtk->vAttrs, VEC_ATTR_GLOBAL_BDD, pAttMan );
352
353 // set reordering
354 if ( fReorder )
355 Cudd_AutodynEnable( dd, CUDD_REORDER_SYMM_SIFT );
356
357 // assign the constant node BDD
358 pObj = Abc_AigConst1(pNtk);
359 if ( Abc_ObjFanoutNum(pObj) > 0 )
360 {
361 bFunc = dd->one;
362 Abc_ObjSetGlobalBdd( pObj, bFunc ); Cudd_Ref( bFunc );
363 }
364 // set the elementary variables
365 Abc_NtkForEachCi( pNtk, pObj, i )
366 if ( Abc_ObjFanoutNum(pObj) > 0 )
367 {
368 bFunc = fReverse ? dd->vars[Abc_NtkCiNum(pNtk) - 1 - i] : dd->vars[i];
369 Abc_ObjSetGlobalBdd( pObj, bFunc ); Cudd_Ref( bFunc );
370 }
371
372 // collect the global functions of the COs
373 Counter = 0;
374 // construct the BDDs
375 pProgress = Extra_ProgressBarStart( stdout, Abc_NtkNodeNum(pNtk) );
376 Abc_NtkForEachCo( pNtk, pObj, i )
377 {
378 bFunc = Abc_NodeGlobalBdds_rec( dd, Abc_ObjFanin0(pObj), nBddSizeMax, fDropInternal, pProgress, &Counter, fVerbose );
379 if ( bFunc == NULL )
380 {
381 if ( fVerbose )
382 printf( "Constructing global BDDs is aborted.\n" );
383 Abc_NtkFreeGlobalBdds( pNtk, 0 );
384 Cudd_Quit( dd );
385
386 // reset references
387 Abc_NtkForEachObj( pNtk, pObj, i )
388 if ( !Abc_ObjIsBox(pObj) && !Abc_ObjIsBi(pObj) )
389 pObj->vFanouts.nSize = 0;
390 Abc_NtkForEachObj( pNtk, pObj, i )
391 if ( !Abc_ObjIsBox(pObj) && !Abc_ObjIsBo(pObj) )
392 Abc_ObjForEachFanin( pObj, pFanin, k )
393 pFanin->vFanouts.nSize++;
394 return NULL;
395 }
396 bFunc = Cudd_NotCond( bFunc, (int)Abc_ObjFaninC0(pObj) ); Cudd_Ref( bFunc );
397 Abc_ObjSetGlobalBdd( pObj, bFunc );
398 }
399 Extra_ProgressBarStop( pProgress );
400
401/*
402 // derefence the intermediate BDDs
403 Abc_NtkForEachNode( pNtk, pObj, i )
404 if ( pObj->pCopy )
405 {
406 Cudd_RecursiveDeref( dd, (DdNode *)pObj->pCopy );
407 pObj->pCopy = NULL;
408 }
409*/
410/*
411 // make sure all nodes are derefed
412 Abc_NtkForEachObj( pNtk, pObj, i )
413 {
414 if ( pObj->pCopy != NULL )
415 printf( "Abc_NtkBuildGlobalBdds() error: Node %d has BDD assigned\n", pObj->Id );
416 if ( pObj->vFanouts.nSize > 0 )
417 printf( "Abc_NtkBuildGlobalBdds() error: Node %d has refs assigned\n", pObj->Id );
418 }
419*/
420 // reset references
421 Abc_NtkForEachObj( pNtk, pObj, i )
422 if ( !Abc_ObjIsBox(pObj) && !Abc_ObjIsBi(pObj) )
423 pObj->vFanouts.nSize = 0;
424 Abc_NtkForEachObj( pNtk, pObj, i )
425 if ( !Abc_ObjIsBox(pObj) && !Abc_ObjIsBo(pObj) )
426 Abc_ObjForEachFanin( pObj, pFanin, k )
427 pFanin->vFanouts.nSize++;
428
429 // reorder one more time
430 if ( fReorder )
431 {
432 Cudd_ReduceHeap( dd, CUDD_REORDER_SYMM_SIFT, 1 );
433// Cudd_ReduceHeap( dd, CUDD_REORDER_SYMM_SIFT, 1 );
434 Cudd_AutodynDisable( dd );
435 }
436 if ( fVerbose )
437 Cudd_PrintInfo( dd, stdout );
438 return dd;
439}
440
452DdNode * Abc_NodeGlobalBdds_rec( DdManager * dd, Abc_Obj_t * pNode, int nBddSizeMax, int fDropInternal, ProgressBar * pProgress, int * pCounter, int fVerbose )
453{
454 DdNode * bFunc, * bFunc0, * bFunc1, * bFuncC;
455 int fDetectMuxes = 0;
456 assert( !Abc_ObjIsComplement(pNode) );
457 if ( Cudd_ReadKeys(dd)-Cudd_ReadDead(dd) > (unsigned)nBddSizeMax )
458 {
459 Extra_ProgressBarStop( pProgress );
460 if ( fVerbose )
461 printf( "The number of live nodes reached %d.\n", nBddSizeMax );
462 fflush( stdout );
463 return NULL;
464 }
465 // if the result is available return
466 if ( Abc_ObjGlobalBdd(pNode) == NULL )
467 {
468 Abc_Obj_t * pNodeC, * pNode0, * pNode1;
469 pNode0 = Abc_ObjFanin0(pNode);
470 pNode1 = Abc_ObjFanin1(pNode);
471 // check for the special case when it is MUX/EXOR
472 if ( fDetectMuxes &&
473 Abc_ObjGlobalBdd(pNode0) == NULL && Abc_ObjGlobalBdd(pNode1) == NULL &&
474 Abc_ObjIsNode(pNode0) && Abc_ObjFanoutNum(pNode0) == 1 &&
475 Abc_ObjIsNode(pNode1) && Abc_ObjFanoutNum(pNode1) == 1 &&
476 Abc_NodeIsMuxType(pNode) )
477 {
478 // deref the fanins
479 pNode0->vFanouts.nSize--;
480 pNode1->vFanouts.nSize--;
481 // recognize the MUX
482 pNodeC = Abc_NodeRecognizeMux( pNode, &pNode1, &pNode0 );
483 assert( Abc_ObjFanoutNum(pNodeC) > 1 );
484 // dereference the control once (the second time it will be derefed when BDDs are computed)
485 pNodeC->vFanouts.nSize--;
486
487 // compute the result for all branches
488 bFuncC = Abc_NodeGlobalBdds_rec( dd, pNodeC, nBddSizeMax, fDropInternal, pProgress, pCounter, fVerbose );
489 if ( bFuncC == NULL )
490 return NULL;
491 Cudd_Ref( bFuncC );
492 bFunc0 = Abc_NodeGlobalBdds_rec( dd, Abc_ObjRegular(pNode0), nBddSizeMax, fDropInternal, pProgress, pCounter, fVerbose );
493 if ( bFunc0 == NULL )
494 return NULL;
495 Cudd_Ref( bFunc0 );
496 bFunc1 = Abc_NodeGlobalBdds_rec( dd, Abc_ObjRegular(pNode1), nBddSizeMax, fDropInternal, pProgress, pCounter, fVerbose );
497 if ( bFunc1 == NULL )
498 return NULL;
499 Cudd_Ref( bFunc1 );
500
501 // complement the branch BDDs
502 bFunc0 = Cudd_NotCond( bFunc0, (int)Abc_ObjIsComplement(pNode0) );
503 bFunc1 = Cudd_NotCond( bFunc1, (int)Abc_ObjIsComplement(pNode1) );
504 // get the final result
505 bFunc = Cudd_bddIte( dd, bFuncC, bFunc1, bFunc0 ); Cudd_Ref( bFunc );
506 Cudd_RecursiveDeref( dd, bFunc0 );
507 Cudd_RecursiveDeref( dd, bFunc1 );
508 Cudd_RecursiveDeref( dd, bFuncC );
509 // add the number of used nodes
510 (*pCounter) += 3;
511 }
512 else
513 {
514 // compute the result for both branches
515 bFunc0 = Abc_NodeGlobalBdds_rec( dd, Abc_ObjFanin(pNode,0), nBddSizeMax, fDropInternal, pProgress, pCounter, fVerbose );
516 if ( bFunc0 == NULL )
517 return NULL;
518 Cudd_Ref( bFunc0 );
519 bFunc1 = Abc_NodeGlobalBdds_rec( dd, Abc_ObjFanin(pNode,1), nBddSizeMax, fDropInternal, pProgress, pCounter, fVerbose );
520 if ( bFunc1 == NULL )
521 return NULL;
522 Cudd_Ref( bFunc1 );
523 bFunc0 = Cudd_NotCond( bFunc0, (int)Abc_ObjFaninC0(pNode) );
524 bFunc1 = Cudd_NotCond( bFunc1, (int)Abc_ObjFaninC1(pNode) );
525 // get the final result
526 bFunc = Cudd_bddAndLimit( dd, bFunc0, bFunc1, nBddSizeMax );
527 if ( bFunc == NULL )
528 return NULL;
529 Cudd_Ref( bFunc );
530 Cudd_RecursiveDeref( dd, bFunc0 );
531 Cudd_RecursiveDeref( dd, bFunc1 );
532 // add the number of used nodes
533 (*pCounter)++;
534 }
535 // set the result
536 assert( Abc_ObjGlobalBdd(pNode) == NULL );
537 Abc_ObjSetGlobalBdd( pNode, bFunc );
538 // increment the progress bar
539 if ( pProgress )
540 Extra_ProgressBarUpdate( pProgress, *pCounter, NULL );
541 }
542 // prepare the return value
543 bFunc = (DdNode *)Abc_ObjGlobalBdd(pNode);
544 // dereference BDD at the node
545 if ( --pNode->vFanouts.nSize == 0 && fDropInternal )
546 {
547 Cudd_Deref( bFunc );
548 Abc_ObjSetGlobalBdd( pNode, NULL );
549 }
550 return bFunc;
551}
552
564void * Abc_NtkFreeGlobalBdds( Abc_Ntk_t * pNtk, int fFreeMan )
565{
566 return Abc_NtkAttrFree( pNtk, VEC_ATTR_GLOBAL_BDD, fFreeMan );
567}
568
581{
582 Vec_Ptr_t * vFuncsGlob;
583 Abc_Obj_t * pObj;
584 int RetValue, i;
585 // complement the global functions
586 vFuncsGlob = Vec_PtrAlloc( Abc_NtkCoNum(pNtk) );
587 Abc_NtkForEachCo( pNtk, pObj, i )
588 Vec_PtrPush( vFuncsGlob, Abc_ObjGlobalBdd(pObj) );
589 RetValue = Cudd_SharingSize( (DdNode **)Vec_PtrArray(vFuncsGlob), Vec_PtrSize(vFuncsGlob) );
590 Vec_PtrFree( vFuncsGlob );
591 return RetValue;
592}
593
605double Abc_NtkSpacePercentage( Abc_Obj_t * pNode )
606{
607 /*
608 Vec_Ptr_t * vNodes;
609 Abc_Obj_t * pObj, * pNodeR;
610 DdManager * dd;
611 DdNode * bFunc;
612 double Result;
613 int i;
614 pNodeR = Abc_ObjRegular(pNode);
615 assert( Abc_NtkIsStrash(pNodeR->pNtk) );
616 Abc_NtkCleanCopy( pNodeR->pNtk );
617 // get the CIs in the support of the node
618 vNodes = Abc_NtkNodeSupport( pNodeR->pNtk, &pNodeR, 1 );
619 // start the manager
620 dd = Cudd_Init( Vec_PtrSize(vNodes), 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
621 Cudd_AutodynEnable( dd, CUDD_REORDER_SYMM_SIFT );
622 // assign elementary BDDs for the CIs
623 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
624 pObj->pCopy = (Abc_Obj_t *)dd->vars[i];
625 // build the BDD of the cone
626 bFunc = Abc_NodeGlobalBdds_rec( dd, pNodeR, 10000000, 1, NULL, NULL, 1 ); Cudd_Ref( bFunc );
627 bFunc = Cudd_NotCond( bFunc, pNode != pNodeR );
628 // count minterms
629 Result = Cudd_CountMinterm( dd, bFunc, dd->size );
630 // get the percentagle
631 Result *= 100.0;
632 for ( i = 0; i < dd->size; i++ )
633 Result /= 2;
634 // clean up
635 Cudd_Quit( dd );
636 Vec_PtrFree( vNodes );
637 return Result;
638 */
639 return 0.0;
640}
641
642
643
644
656void Abc_NtkBddImplicationTest()
657{
658 DdManager * dd;
659 DdNode * bImp, * bSum, * bTemp;
660 int nVars = 200;
661 int nImps = 200;
662 int i;
663 abctime clk;
664clk = Abc_Clock();
665 dd = Cudd_Init( nVars, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
666 Cudd_AutodynEnable( dd, CUDD_REORDER_SIFT );
667 bSum = b0; Cudd_Ref( bSum );
668 for ( i = 0; i < nImps; i++ )
669 {
670 printf( "." );
671 bImp = Cudd_bddAnd( dd, dd->vars[rand()%nVars], dd->vars[rand()%nVars] ); Cudd_Ref( bImp );
672 bSum = Cudd_bddOr( dd, bTemp = bSum, bImp ); Cudd_Ref( bSum );
673 Cudd_RecursiveDeref( dd, bTemp );
674 Cudd_RecursiveDeref( dd, bImp );
675 }
676 printf( "The BDD before = %d.\n", Cudd_DagSize(bSum) );
677 Cudd_ReduceHeap( dd, CUDD_REORDER_SIFT, 1 );
678 printf( "The BDD after = %d.\n", Cudd_DagSize(bSum) );
679ABC_PRT( "Time", Abc_Clock() - clk );
680 Cudd_RecursiveDeref( dd, bSum );
681 Cudd_Quit( dd );
682}
683
684#else
685
686double Abc_NtkSpacePercentage( Abc_Obj_t * pNode ) { return 0.0; }
687Abc_Ntk_t * Abc_NtkBddToMuxes( Abc_Ntk_t * pNtk, int fGlobal, int Limit, int fUseAdd ) { return NULL; }
688
689
690#endif
691
695
696
698
Abc_Ntk_t * Abc_NtkBddToMuxes(Abc_Ntk_t *pNtk, int fGlobal, int Limit, int fUseAdd)
Definition abcNtbdd.c:687
ABC_NAMESPACE_IMPL_START double Abc_NtkSpacePercentage(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNtbdd.c:686
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL void * Abc_NtkAttrFree(Abc_Ntk_t *pNtk, int Attr, int fFreeMan)
DECLARATIONS ///.
Definition abcUtil.c:55
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition abcNtk.c:53
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
Definition abcObj.c:643
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
Definition abcDfs.c:82
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
Definition abcObj.c:612
ABC_DLL void Abc_NodeFreeNames(Vec_Ptr_t *vNames)
Definition abcNames.c:264
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
ABC_DLL Abc_Ntk_t * Abc_NtkDeriveFromBdd(void *dd, void *bFunc, char *pNamePo, Vec_Ptr_t *vNamesPi)
struct Abc_Aig_t_ Abc_Aig_t
Definition abc.h:117
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
Definition abcNames.c:69
ABC_DLL void Abc_NtkFinalize(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew)
Definition abcNtk.c:355
@ ABC_NTK_LOGIC
Definition abc.h:57
ABC_DLL void * Abc_NtkFreeGlobalBdds(Abc_Ntk_t *pNtk, int fFreeMan)
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
Definition abcAig.c:194
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeMux(Abc_Ntk_t *pNtk, Abc_Obj_t *pNodeC, Abc_Obj_t *pNode1, Abc_Obj_t *pNode0)
Definition abcObj.c:834
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition abcObj.c:674
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
ABC_DLL void * Abc_NtkBuildGlobalBdds(Abc_Ntk_t *pNtk, int fBddSizeMax, int fDropInternal, int fReorder, int fReverse, int fVerbose)
ABC_DLL int Abc_NtkMinimumBase(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition abcMinBase.c:892
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
@ ABC_FUNC_SOP
Definition abc.h:65
@ ABC_FUNC_BDD
Definition abc.h:66
ABC_DLL Vec_Ptr_t * Abc_NodeGetFakeNames(int nNames)
Definition abcNames.c:228
ABC_DLL int Abc_NodeIsMuxType(Abc_Obj_t *pNode)
Definition abcUtil.c:1342
ABC_DLL Abc_Obj_t * Abc_NodeRecognizeMux(Abc_Obj_t *pNode, Abc_Obj_t **ppNodeT, Abc_Obj_t **ppNodeE)
Definition abcUtil.c:1430
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
Definition abcNtk.c:157
ABC_DLL int Abc_NtkSizeOfGlobalBdds(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition abcAig.c:683
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define b0
Definition bbrImage.c:96
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
void Extra_StopManager(DdManager *dd)
#define a0
Definition extraBdd.h:79
#define a1
Definition extraBdd.h:80
void Extra_ProgressBarStop(ProgressBar *p)
char * Extra_UtilStrsav(const char *s)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
int st__ptrhash(const char *, int)
Definition st.c:467
int st__ptrcmp(const char *, const char *)
Definition st.c:479
int st__lookup(st__table *table, const char *key, char **value)
Definition st.c:114
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition st.c:72
int st__insert(st__table *table, const char *key, char *value)
Definition st.c:171
void st__free_table(st__table *table)
Definition st.c:81
Vec_Ptr_t * vAttrs
Definition abc.h:214
char * pName
Definition abc.h:158
void * pManFunc
Definition abc.h:191
void * pData
Definition abc.h:145
Abc_Ntk_t * pNtk
Definition abc.h:130
Vec_Int_t vFanouts
Definition abc.h:144
Abc_Obj_t * pCopy
Definition abc.h:148
Definition st.h:52
#define assert(ex)
Definition util_old.h:213
@ VEC_ATTR_GLOBAL_BDD
Definition vecAtt.h:47
struct Vec_Att_t_ Vec_Att_t
BASIC TYPES ///.
Definition vecAtt.h:62
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55