00001
00021 #ifndef __DEC_H__
00022 #define __DEC_H__
00023
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027
00031
00035
00039
00040 typedef struct Dec_Edge_t_ Dec_Edge_t;
00041 struct Dec_Edge_t_
00042 {
00043 unsigned fCompl : 1;
00044 unsigned Node : 30;
00045 };
00046
00047 typedef struct Dec_Node_t_ Dec_Node_t;
00048 struct Dec_Node_t_
00049 {
00050 Dec_Edge_t eEdge0;
00051 Dec_Edge_t eEdge1;
00052
00053 void * pFunc;
00054 unsigned Level : 14;
00055
00056 unsigned fNodeOr : 1;
00057 unsigned fCompl0 : 1;
00058 unsigned fCompl1 : 1;
00059
00060 unsigned nLat0 : 5;
00061 unsigned nLat1 : 5;
00062 unsigned nLat2 : 5;
00063 };
00064
00065 typedef struct Dec_Graph_t_ Dec_Graph_t;
00066 struct Dec_Graph_t_
00067 {
00068 int fConst;
00069 int nLeaves;
00070 int nSize;
00071 int nCap;
00072 Dec_Node_t * pNodes;
00073 Dec_Edge_t eRoot;
00074 };
00075
00076 typedef struct Dec_Man_t_ Dec_Man_t;
00077 struct Dec_Man_t_
00078 {
00079 void * pMvcMem;
00080 Vec_Int_t * vCubes;
00081 Vec_Int_t * vLits;
00082
00083 unsigned short * puCanons;
00084 char * pPhases;
00085 char * pPerms;
00086 unsigned char * pMap;
00087 };
00088
00089
00093
00094
00095 #define Dec_GraphForEachLeaf( pGraph, pLeaf, i ) \
00096 for ( i = 0; (i < (pGraph)->nLeaves) && (((pLeaf) = Dec_GraphNode(pGraph, i)), 1); i++ )
00097
00098 #define Dec_GraphForEachNode( pGraph, pAnd, i ) \
00099 for ( i = (pGraph)->nLeaves; (i < (pGraph)->nSize) && (((pAnd) = Dec_GraphNode(pGraph, i)), 1); i++ )
00100
00104
00105
00106 extern Abc_Obj_t * Dec_GraphToNetwork( Abc_Ntk_t * pNtk, Dec_Graph_t * pGraph );
00107 extern Abc_Obj_t * Dec_GraphToNetworkNoStrash( Abc_Ntk_t * pNtk, Dec_Graph_t * pGraph );
00108 extern int Dec_GraphToNetworkCount( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int NodeMax, int LevelMax );
00109 extern void Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, bool fUpdateLevel, int nGain );
00110
00111 extern Dec_Graph_t * Dec_Factor( char * pSop );
00112
00113 extern Dec_Man_t * Dec_ManStart();
00114 extern void Dec_ManStop( Dec_Man_t * p );
00115
00116 extern void Dec_GraphPrint( FILE * pFile, Dec_Graph_t * pGraph, char * pNamesIn[], char * pNameOut );
00117
00118 extern DdNode * Dec_GraphDeriveBdd( DdManager * dd, Dec_Graph_t * pGraph );
00119 extern unsigned Dec_GraphDeriveTruth( Dec_Graph_t * pGraph );
00120
00124
00136 static inline Dec_Edge_t Dec_EdgeCreate( int Node, int fCompl )
00137 {
00138 Dec_Edge_t eEdge = { fCompl, Node };
00139 return eEdge;
00140 }
00141
00153 static inline unsigned Dec_EdgeToInt( Dec_Edge_t eEdge )
00154 {
00155 return (eEdge.Node << 1) | eEdge.fCompl;
00156 }
00157
00169 static inline Dec_Edge_t Dec_IntToEdge( unsigned Edge )
00170 {
00171 return Dec_EdgeCreate( Edge >> 1, Edge & 1 );
00172 }
00173
00185 static inline unsigned Dec_EdgeToInt_( Dec_Edge_t eEdge )
00186 {
00187 return *(unsigned *)&eEdge;
00188 }
00189
00201 static inline Dec_Edge_t Dec_IntToEdge_( unsigned Edge )
00202 {
00203 return *(Dec_Edge_t *)&Edge;
00204 }
00205
00217 static inline Dec_Graph_t * Dec_GraphCreate( int nLeaves )
00218 {
00219 Dec_Graph_t * pGraph;
00220 pGraph = ALLOC( Dec_Graph_t, 1 );
00221 memset( pGraph, 0, sizeof(Dec_Graph_t) );
00222 pGraph->nLeaves = nLeaves;
00223 pGraph->nSize = nLeaves;
00224 pGraph->nCap = 2 * nLeaves + 50;
00225 pGraph->pNodes = ALLOC( Dec_Node_t, pGraph->nCap );
00226 memset( pGraph->pNodes, 0, sizeof(Dec_Node_t) * pGraph->nSize );
00227 return pGraph;
00228 }
00229
00241 static inline Dec_Graph_t * Dec_GraphCreateConst0()
00242 {
00243 Dec_Graph_t * pGraph;
00244 pGraph = ALLOC( Dec_Graph_t, 1 );
00245 memset( pGraph, 0, sizeof(Dec_Graph_t) );
00246 pGraph->fConst = 1;
00247 pGraph->eRoot.fCompl = 1;
00248 return pGraph;
00249 }
00250
00262 static inline Dec_Graph_t * Dec_GraphCreateConst1()
00263 {
00264 Dec_Graph_t * pGraph;
00265 pGraph = ALLOC( Dec_Graph_t, 1 );
00266 memset( pGraph, 0, sizeof(Dec_Graph_t) );
00267 pGraph->fConst = 1;
00268 return pGraph;
00269 }
00270
00282 static inline Dec_Graph_t * Dec_GraphCreateLeaf( int iLeaf, int nLeaves, int fCompl )
00283 {
00284 Dec_Graph_t * pGraph;
00285 assert( 0 <= iLeaf && iLeaf < nLeaves );
00286 pGraph = Dec_GraphCreate( nLeaves );
00287 pGraph->eRoot.Node = iLeaf;
00288 pGraph->eRoot.fCompl = fCompl;
00289 return pGraph;
00290 }
00291
00303 static inline void Dec_GraphFree( Dec_Graph_t * pGraph )
00304 {
00305 FREE( pGraph->pNodes );
00306 free( pGraph );
00307 }
00308
00320 static inline bool Dec_GraphIsConst( Dec_Graph_t * pGraph )
00321 {
00322 return pGraph->fConst;
00323 }
00324
00336 static inline bool Dec_GraphIsConst0( Dec_Graph_t * pGraph )
00337 {
00338 return pGraph->fConst && pGraph->eRoot.fCompl;
00339 }
00340
00352 static inline bool Dec_GraphIsConst1( Dec_Graph_t * pGraph )
00353 {
00354 return pGraph->fConst && !pGraph->eRoot.fCompl;
00355 }
00356
00368 static inline bool Dec_GraphIsComplement( Dec_Graph_t * pGraph )
00369 {
00370 return pGraph->eRoot.fCompl;
00371 }
00372
00384 static inline void Dec_GraphComplement( Dec_Graph_t * pGraph )
00385 {
00386 pGraph->eRoot.fCompl ^= 1;
00387 }
00388
00389
00401 static inline int Dec_GraphLeaveNum( Dec_Graph_t * pGraph )
00402 {
00403 return pGraph->nLeaves;
00404 }
00405
00417 static inline int Dec_GraphNodeNum( Dec_Graph_t * pGraph )
00418 {
00419 return pGraph->nSize - pGraph->nLeaves;
00420 }
00421
00433 static inline Dec_Node_t * Dec_GraphNode( Dec_Graph_t * pGraph, int i )
00434 {
00435 return pGraph->pNodes + i;
00436 }
00437
00449 static inline Dec_Node_t * Dec_GraphNodeLast( Dec_Graph_t * pGraph )
00450 {
00451 return pGraph->pNodes + pGraph->nSize - 1;
00452 }
00453
00465 static inline int Dec_GraphNodeInt( Dec_Graph_t * pGraph, Dec_Node_t * pNode )
00466 {
00467 return pNode - pGraph->pNodes;
00468 }
00469
00481 static inline bool Dec_GraphIsVar( Dec_Graph_t * pGraph )
00482 {
00483 return pGraph->eRoot.Node < (unsigned)pGraph->nLeaves;
00484 }
00485
00497 static inline bool Dec_GraphNodeIsVar( Dec_Graph_t * pGraph, Dec_Node_t * pNode )
00498 {
00499 return Dec_GraphNodeInt(pGraph,pNode) < pGraph->nLeaves;
00500 }
00501
00513 static inline Dec_Node_t * Dec_GraphVar( Dec_Graph_t * pGraph )
00514 {
00515 assert( Dec_GraphIsVar( pGraph ) );
00516 return Dec_GraphNode( pGraph, pGraph->eRoot.Node );
00517 }
00518
00530 static inline int Dec_GraphVarInt( Dec_Graph_t * pGraph )
00531 {
00532 assert( Dec_GraphIsVar( pGraph ) );
00533 return Dec_GraphNodeInt( pGraph, Dec_GraphVar(pGraph) );
00534 }
00535
00547 static inline void Dec_GraphSetRoot( Dec_Graph_t * pGraph, Dec_Edge_t eRoot )
00548 {
00549 pGraph->eRoot = eRoot;
00550 }
00551
00563 static inline Dec_Node_t * Dec_GraphAppendNode( Dec_Graph_t * pGraph )
00564 {
00565 Dec_Node_t * pNode;
00566 if ( pGraph->nSize == pGraph->nCap )
00567 {
00568 pGraph->pNodes = REALLOC( Dec_Node_t, pGraph->pNodes, 2 * pGraph->nCap );
00569 pGraph->nCap = 2 * pGraph->nCap;
00570 }
00571 pNode = pGraph->pNodes + pGraph->nSize++;
00572 memset( pNode, 0, sizeof(Dec_Node_t) );
00573 return pNode;
00574 }
00575
00587 static inline Dec_Edge_t Dec_GraphAddNodeAnd( Dec_Graph_t * pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1 )
00588 {
00589 Dec_Node_t * pNode;
00590
00591 pNode = Dec_GraphAppendNode( pGraph );
00592
00593 pNode->eEdge0 = eEdge0;
00594 pNode->eEdge1 = eEdge1;
00595 pNode->fCompl0 = eEdge0.fCompl;
00596 pNode->fCompl1 = eEdge1.fCompl;
00597 return Dec_EdgeCreate( pGraph->nSize - 1, 0 );
00598 }
00599
00611 static inline Dec_Edge_t Dec_GraphAddNodeOr( Dec_Graph_t * pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1 )
00612 {
00613 Dec_Node_t * pNode;
00614
00615 pNode = Dec_GraphAppendNode( pGraph );
00616
00617 pNode->eEdge0 = eEdge0;
00618 pNode->eEdge1 = eEdge1;
00619 pNode->fCompl0 = eEdge0.fCompl;
00620 pNode->fCompl1 = eEdge1.fCompl;
00621
00622 pNode->fNodeOr = 1;
00623 pNode->eEdge0.fCompl = !pNode->eEdge0.fCompl;
00624 pNode->eEdge1.fCompl = !pNode->eEdge1.fCompl;
00625 return Dec_EdgeCreate( pGraph->nSize - 1, 1 );
00626 }
00627
00639 static inline Dec_Edge_t Dec_GraphAddNodeXor( Dec_Graph_t * pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1, int Type )
00640 {
00641 Dec_Edge_t eNode0, eNode1, eNode;
00642 if ( Type == 0 )
00643 {
00644
00645 eEdge0.fCompl ^= 1;
00646 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
00647 eEdge0.fCompl ^= 1;
00648
00649 eEdge1.fCompl ^= 1;
00650 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
00651
00652 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
00653 }
00654 else
00655 {
00656
00657 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
00658
00659 eEdge0.fCompl ^= 1;
00660 eEdge1.fCompl ^= 1;
00661 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
00662
00663 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
00664 eNode.fCompl ^= 1;
00665 }
00666 return eNode;
00667 }
00668
00680 static inline Dec_Edge_t Dec_GraphAddNodeMux( Dec_Graph_t * pGraph, Dec_Edge_t eEdgeC, Dec_Edge_t eEdgeT, Dec_Edge_t eEdgeE, int Type )
00681 {
00682 Dec_Edge_t eNode0, eNode1, eNode;
00683 if ( Type == 0 )
00684 {
00685
00686 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeT );
00687
00688 eEdgeC.fCompl ^= 1;
00689 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeE );
00690
00691 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
00692 }
00693 else
00694 {
00695
00696 eEdgeT.fCompl ^= 1;
00697 eEdgeE.fCompl ^= 1;
00698
00699 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeT );
00700
00701 eEdgeC.fCompl ^= 1;
00702 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeE );
00703
00704 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
00705 eNode.fCompl ^= 1;
00706 }
00707 return eNode;
00708 }
00709
00710 #ifdef __cplusplus
00711 }
00712 #endif
00713
00714 #endif
00715
00719