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
00108
00120 static inline Dec_Edge_t Dec_EdgeCreate( int Node, int fCompl )
00121 {
00122 Dec_Edge_t eEdge = { fCompl, Node };
00123 return eEdge;
00124 }
00125
00137 static inline unsigned Dec_EdgeToInt( Dec_Edge_t eEdge )
00138 {
00139 return (eEdge.Node << 1) | eEdge.fCompl;
00140 }
00141
00153 static inline Dec_Edge_t Dec_IntToEdge( unsigned Edge )
00154 {
00155 return Dec_EdgeCreate( Edge >> 1, Edge & 1 );
00156 }
00157
00169 static inline unsigned Dec_EdgeToInt_( Dec_Edge_t eEdge )
00170 {
00171 return *(unsigned *)&eEdge;
00172 }
00173
00185 static inline Dec_Edge_t Dec_IntToEdge_( unsigned Edge )
00186 {
00187 return *(Dec_Edge_t *)&Edge;
00188 }
00189
00201 static inline Dec_Graph_t * Dec_GraphCreate( int nLeaves )
00202 {
00203 Dec_Graph_t * pGraph;
00204 pGraph = ALLOC( Dec_Graph_t, 1 );
00205 memset( pGraph, 0, sizeof(Dec_Graph_t) );
00206 pGraph->nLeaves = nLeaves;
00207 pGraph->nSize = nLeaves;
00208 pGraph->nCap = 2 * nLeaves + 50;
00209 pGraph->pNodes = ALLOC( Dec_Node_t, pGraph->nCap );
00210 memset( pGraph->pNodes, 0, sizeof(Dec_Node_t) * pGraph->nSize );
00211 return pGraph;
00212 }
00213
00225 static inline Dec_Graph_t * Dec_GraphCreateConst0()
00226 {
00227 Dec_Graph_t * pGraph;
00228 pGraph = ALLOC( Dec_Graph_t, 1 );
00229 memset( pGraph, 0, sizeof(Dec_Graph_t) );
00230 pGraph->fConst = 1;
00231 pGraph->eRoot.fCompl = 1;
00232 return pGraph;
00233 }
00234
00246 static inline Dec_Graph_t * Dec_GraphCreateConst1()
00247 {
00248 Dec_Graph_t * pGraph;
00249 pGraph = ALLOC( Dec_Graph_t, 1 );
00250 memset( pGraph, 0, sizeof(Dec_Graph_t) );
00251 pGraph->fConst = 1;
00252 return pGraph;
00253 }
00254
00266 static inline Dec_Graph_t * Dec_GraphCreateLeaf( int iLeaf, int nLeaves, int fCompl )
00267 {
00268 Dec_Graph_t * pGraph;
00269 assert( 0 <= iLeaf && iLeaf < nLeaves );
00270 pGraph = Dec_GraphCreate( nLeaves );
00271 pGraph->eRoot.Node = iLeaf;
00272 pGraph->eRoot.fCompl = fCompl;
00273 return pGraph;
00274 }
00275
00287 static inline void Dec_GraphFree( Dec_Graph_t * pGraph )
00288 {
00289 FREE( pGraph->pNodes );
00290 free( pGraph );
00291 }
00292
00304 static inline int Dec_GraphIsConst( Dec_Graph_t * pGraph )
00305 {
00306 return pGraph->fConst;
00307 }
00308
00320 static inline int Dec_GraphIsConst0( Dec_Graph_t * pGraph )
00321 {
00322 return pGraph->fConst && pGraph->eRoot.fCompl;
00323 }
00324
00336 static inline int Dec_GraphIsConst1( Dec_Graph_t * pGraph )
00337 {
00338 return pGraph->fConst && !pGraph->eRoot.fCompl;
00339 }
00340
00352 static inline int Dec_GraphIsComplement( Dec_Graph_t * pGraph )
00353 {
00354 return pGraph->eRoot.fCompl;
00355 }
00356
00368 static inline void Dec_GraphComplement( Dec_Graph_t * pGraph )
00369 {
00370 pGraph->eRoot.fCompl ^= 1;
00371 }
00372
00373
00385 static inline int Dec_GraphLeaveNum( Dec_Graph_t * pGraph )
00386 {
00387 return pGraph->nLeaves;
00388 }
00389
00401 static inline int Dec_GraphNodeNum( Dec_Graph_t * pGraph )
00402 {
00403 return pGraph->nSize - pGraph->nLeaves;
00404 }
00405
00417 static inline Dec_Node_t * Dec_GraphNode( Dec_Graph_t * pGraph, int i )
00418 {
00419 return pGraph->pNodes + i;
00420 }
00421
00433 static inline Dec_Node_t * Dec_GraphNodeLast( Dec_Graph_t * pGraph )
00434 {
00435 return pGraph->pNodes + pGraph->nSize - 1;
00436 }
00437
00449 static inline int Dec_GraphNodeInt( Dec_Graph_t * pGraph, Dec_Node_t * pNode )
00450 {
00451 return pNode - pGraph->pNodes;
00452 }
00453
00465 static inline int Dec_GraphIsVar( Dec_Graph_t * pGraph )
00466 {
00467 return pGraph->eRoot.Node < (unsigned)pGraph->nLeaves;
00468 }
00469
00481 static inline int Dec_GraphNodeIsVar( Dec_Graph_t * pGraph, Dec_Node_t * pNode )
00482 {
00483 return Dec_GraphNodeInt(pGraph,pNode) < pGraph->nLeaves;
00484 }
00485
00497 static inline Dec_Node_t * Dec_GraphVar( Dec_Graph_t * pGraph )
00498 {
00499 assert( Dec_GraphIsVar( pGraph ) );
00500 return Dec_GraphNode( pGraph, pGraph->eRoot.Node );
00501 }
00502
00514 static inline int Dec_GraphVarInt( Dec_Graph_t * pGraph )
00515 {
00516 assert( Dec_GraphIsVar( pGraph ) );
00517 return Dec_GraphNodeInt( pGraph, Dec_GraphVar(pGraph) );
00518 }
00519
00531 static inline void Dec_GraphSetRoot( Dec_Graph_t * pGraph, Dec_Edge_t eRoot )
00532 {
00533 pGraph->eRoot = eRoot;
00534 }
00535
00547 static inline Dec_Node_t * Dec_GraphAppendNode( Dec_Graph_t * pGraph )
00548 {
00549 Dec_Node_t * pNode;
00550 if ( pGraph->nSize == pGraph->nCap )
00551 {
00552 pGraph->pNodes = REALLOC( Dec_Node_t, pGraph->pNodes, 2 * pGraph->nCap );
00553 pGraph->nCap = 2 * pGraph->nCap;
00554 }
00555 pNode = pGraph->pNodes + pGraph->nSize++;
00556 memset( pNode, 0, sizeof(Dec_Node_t) );
00557 return pNode;
00558 }
00559
00571 static inline Dec_Edge_t Dec_GraphAddNodeAnd( Dec_Graph_t * pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1 )
00572 {
00573 Dec_Node_t * pNode;
00574
00575 pNode = Dec_GraphAppendNode( pGraph );
00576
00577 pNode->eEdge0 = eEdge0;
00578 pNode->eEdge1 = eEdge1;
00579 pNode->fCompl0 = eEdge0.fCompl;
00580 pNode->fCompl1 = eEdge1.fCompl;
00581 return Dec_EdgeCreate( pGraph->nSize - 1, 0 );
00582 }
00583
00595 static inline Dec_Edge_t Dec_GraphAddNodeOr( Dec_Graph_t * pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1 )
00596 {
00597 Dec_Node_t * pNode;
00598
00599 pNode = Dec_GraphAppendNode( pGraph );
00600
00601 pNode->eEdge0 = eEdge0;
00602 pNode->eEdge1 = eEdge1;
00603 pNode->fCompl0 = eEdge0.fCompl;
00604 pNode->fCompl1 = eEdge1.fCompl;
00605
00606 pNode->fNodeOr = 1;
00607 pNode->eEdge0.fCompl = !pNode->eEdge0.fCompl;
00608 pNode->eEdge1.fCompl = !pNode->eEdge1.fCompl;
00609 return Dec_EdgeCreate( pGraph->nSize - 1, 1 );
00610 }
00611
00623 static inline Dec_Edge_t Dec_GraphAddNodeXor( Dec_Graph_t * pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1, int Type )
00624 {
00625 Dec_Edge_t eNode0, eNode1, eNode;
00626 if ( Type == 0 )
00627 {
00628
00629 eEdge0.fCompl ^= 1;
00630 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
00631 eEdge0.fCompl ^= 1;
00632
00633 eEdge1.fCompl ^= 1;
00634 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
00635
00636 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
00637 }
00638 else
00639 {
00640
00641 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
00642
00643 eEdge0.fCompl ^= 1;
00644 eEdge1.fCompl ^= 1;
00645 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
00646
00647 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
00648 eNode.fCompl ^= 1;
00649 }
00650 return eNode;
00651 }
00652
00664 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 )
00665 {
00666 Dec_Edge_t eNode0, eNode1, eNode;
00667 if ( Type == 0 )
00668 {
00669
00670 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeT );
00671
00672 eEdgeC.fCompl ^= 1;
00673 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeE );
00674
00675 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
00676 }
00677 else
00678 {
00679
00680 eEdgeT.fCompl ^= 1;
00681 eEdgeE.fCompl ^= 1;
00682
00683 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeT );
00684
00685 eEdgeC.fCompl ^= 1;
00686 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeE );
00687
00688 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
00689 eNode.fCompl ^= 1;
00690 }
00691 return eNode;
00692 }
00693
00694 #ifdef __cplusplus
00695 }
00696 #endif
00697
00698 #endif
00699
00703