ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
dec.h
Go to the documentation of this file.
1
20
21#ifndef ABC__opt__dec__dec_h
22#define ABC__opt__dec__dec_h
23
24
28
32
33
34
36
37
41
42typedef struct Dec_Edge_t_ Dec_Edge_t;
44{
45 unsigned fCompl : 1; // the complemented bit
46 unsigned Node : 30; // the decomposition node pointed by the edge
47};
48
49typedef struct Dec_Node_t_ Dec_Node_t;
51{
52 Dec_Edge_t eEdge0; // the left child of the node
53 Dec_Edge_t eEdge1; // the right child of the node
54 // other info
55 union { int iFunc; // the literal of the node (AIG)
56 void * pFunc; }; // the function of the node (BDD or AIG)
57 unsigned Level : 14; // the level of this node in the global AIG
58 // printing info
59 unsigned fNodeOr : 1; // marks the original OR node
60 unsigned fCompl0 : 1; // marks the original complemented edge
61 unsigned fCompl1 : 1; // marks the original complemented edge
62 // latch info
63 unsigned nLat0 : 5; // the number of latches on the first edge
64 unsigned nLat1 : 5; // the number of latches on the second edge
65 unsigned nLat2 : 5; // the number of latches on the output edge
66};
67
70{
71 int fConst; // marks the constant 1 graph
72 int nLeaves; // the number of leaves
73 int nSize; // the number of nodes (including the leaves)
74 int nCap; // the number of allocated nodes
75 Dec_Node_t * pNodes; // the array of leaves and internal nodes
76 Dec_Edge_t eRoot; // the pointer to the topmost node
77};
78
79typedef struct Dec_Man_t_ Dec_Man_t;
81{
82 void * pMvcMem; // memory manager for MVC cover (used for factoring)
83 Vec_Int_t * vCubes; // storage for cubes
84 Vec_Int_t * vLits; // storage for literals
85 // precomputation information about 4-variable functions
86 unsigned short * puCanons; // canonical forms
87 char * pPhases; // canonical phases
88 char * pPerms; // canonical permutations
89 unsigned char * pMap; // mapping of functions into class numbers
90};
91
92
96
97// iterator through the leaves
98#define Dec_GraphForEachLeaf( pGraph, pLeaf, i ) \
99 for ( i = 0; (i < (pGraph)->nLeaves) && (((pLeaf) = Dec_GraphNode(pGraph, i)), 1); i++ )
100// iterator through the internal nodes
101#define Dec_GraphForEachNode( pGraph, pAnd, i ) \
102 for ( i = (pGraph)->nLeaves; (i < (pGraph)->nSize) && (((pAnd) = Dec_GraphNode(pGraph, i)), 1); i++ )
103
107
108/*=== decAbc.c ========================================================*/
109/*=== decFactor.c ========================================================*/
110extern Dec_Graph_t * Dec_Factor( char * pSop );
111/*=== decMan.c ========================================================*/
112extern Dec_Man_t * Dec_ManStart();
113extern void Dec_ManStop( Dec_Man_t * p );
114/*=== decPrint.c ========================================================*/
115extern void Dec_GraphPrint( FILE * pFile, Dec_Graph_t * pGraph, char * pNamesIn[], char * pNameOut );
116/*=== decUtil.c ========================================================*/
117extern unsigned Dec_GraphDeriveTruth( Dec_Graph_t * pGraph );
118
122
134static inline Dec_Edge_t Dec_EdgeCreate( int Node, int fCompl )
135{
136 Dec_Edge_t eEdge = { (unsigned)fCompl, (unsigned)Node };
137 return eEdge;
138}
139
151static inline unsigned Dec_EdgeToInt( Dec_Edge_t eEdge )
152{
153 return (eEdge.Node << 1) | eEdge.fCompl;
154}
155
167static inline Dec_Edge_t Dec_IntToEdge( unsigned Edge )
168{
169 return Dec_EdgeCreate( Edge >> 1, Edge & 1 );
170}
171
183static inline unsigned Dec_EdgeToInt_( Dec_Edge_t m ) { union { Dec_Edge_t x; unsigned y; } v; v.x = m; return v.y; }
184/*
185static inline unsigned Dec_EdgeToInt_( Dec_Edge_t eEdge )
186{
187 return *(unsigned *)&eEdge;
188}
189*/
190
202static inline Dec_Edge_t Dec_IntToEdge_( unsigned m ) { union { Dec_Edge_t x; unsigned y; } v; v.y = m; return v.x; }
203/*
204static inline Dec_Edge_t Dec_IntToEdge_( unsigned Edge )
205{
206 return *(Dec_Edge_t *)&Edge;
207}
208*/
209
221static inline Dec_Graph_t * Dec_GraphCreate( int nLeaves )
222{
223 Dec_Graph_t * pGraph;
224 pGraph = ABC_ALLOC( Dec_Graph_t, 1 );
225 memset( pGraph, 0, sizeof(Dec_Graph_t) );
226 pGraph->nLeaves = nLeaves;
227 pGraph->nSize = nLeaves;
228 pGraph->nCap = 2 * nLeaves + 50;
229 pGraph->pNodes = ABC_ALLOC( Dec_Node_t, pGraph->nCap );
230 memset( pGraph->pNodes, 0, sizeof(Dec_Node_t) * pGraph->nSize );
231 return pGraph;
232}
233
245static inline Dec_Graph_t * Dec_GraphCreateConst0()
246{
247 Dec_Graph_t * pGraph;
248 pGraph = ABC_ALLOC( Dec_Graph_t, 1 );
249 memset( pGraph, 0, sizeof(Dec_Graph_t) );
250 pGraph->fConst = 1;
251 pGraph->eRoot.fCompl = 1;
252 return pGraph;
253}
254
266static inline Dec_Graph_t * Dec_GraphCreateConst1()
267{
268 Dec_Graph_t * pGraph;
269 pGraph = ABC_ALLOC( Dec_Graph_t, 1 );
270 memset( pGraph, 0, sizeof(Dec_Graph_t) );
271 pGraph->fConst = 1;
272 return pGraph;
273}
274
286static inline Dec_Graph_t * Dec_GraphCreateLeaf( int iLeaf, int nLeaves, int fCompl )
287{
288 Dec_Graph_t * pGraph;
289 assert( 0 <= iLeaf && iLeaf < nLeaves );
290 pGraph = Dec_GraphCreate( nLeaves );
291 pGraph->eRoot.Node = iLeaf;
292 pGraph->eRoot.fCompl = fCompl;
293 return pGraph;
294}
295
307static inline void Dec_GraphFree( Dec_Graph_t * pGraph )
308{
309 ABC_FREE( pGraph->pNodes );
310 ABC_FREE( pGraph );
311}
312
324static inline int Dec_GraphIsConst( Dec_Graph_t * pGraph )
325{
326 return pGraph->fConst;
327}
328
340static inline int Dec_GraphIsConst0( Dec_Graph_t * pGraph )
341{
342 return pGraph->fConst && pGraph->eRoot.fCompl;
343}
344
356static inline int Dec_GraphIsConst1( Dec_Graph_t * pGraph )
357{
358 return pGraph->fConst && !pGraph->eRoot.fCompl;
359}
360
372static inline int Dec_GraphIsComplement( Dec_Graph_t * pGraph )
373{
374 return pGraph->eRoot.fCompl;
375}
376
388static inline void Dec_GraphComplement( Dec_Graph_t * pGraph )
389{
390 pGraph->eRoot.fCompl ^= 1;
391}
392
393
405static inline int Dec_GraphLeaveNum( Dec_Graph_t * pGraph )
406{
407 return pGraph->nLeaves;
408}
409
421static inline int Dec_GraphNodeNum( Dec_Graph_t * pGraph )
422{
423 return pGraph->nSize - pGraph->nLeaves;
424}
425
437static inline Dec_Node_t * Dec_GraphNode( Dec_Graph_t * pGraph, int i )
438{
439 return pGraph->pNodes + i;
440}
441
453static inline Dec_Node_t * Dec_GraphNodeLast( Dec_Graph_t * pGraph )
454{
455 return pGraph->pNodes + pGraph->nSize - 1;
456}
457
469static inline int Dec_GraphNodeInt( Dec_Graph_t * pGraph, Dec_Node_t * pNode )
470{
471 return pNode - pGraph->pNodes;
472}
473
485static inline int Dec_GraphIsVar( Dec_Graph_t * pGraph )
486{
487 return pGraph->eRoot.Node < (unsigned)pGraph->nLeaves;
488}
489
501static inline int Dec_GraphNodeIsVar( Dec_Graph_t * pGraph, Dec_Node_t * pNode )
502{
503 return Dec_GraphNodeInt(pGraph,pNode) < pGraph->nLeaves;
504}
505
517static inline Dec_Node_t * Dec_GraphVar( Dec_Graph_t * pGraph )
518{
519 assert( Dec_GraphIsVar( pGraph ) );
520 return Dec_GraphNode( pGraph, pGraph->eRoot.Node );
521}
522
534static inline int Dec_GraphVarInt( Dec_Graph_t * pGraph )
535{
536 assert( Dec_GraphIsVar( pGraph ) );
537 return Dec_GraphNodeInt( pGraph, Dec_GraphVar(pGraph) );
538}
539
551static inline void Dec_GraphSetRoot( Dec_Graph_t * pGraph, Dec_Edge_t eRoot )
552{
553 pGraph->eRoot = eRoot;
554}
555
567static inline Dec_Node_t * Dec_GraphAppendNode( Dec_Graph_t * pGraph )
568{
569 Dec_Node_t * pNode;
570 if ( pGraph->nSize == pGraph->nCap )
571 {
572 pGraph->pNodes = ABC_REALLOC( Dec_Node_t, pGraph->pNodes, 2 * pGraph->nCap );
573 pGraph->nCap = 2 * pGraph->nCap;
574 }
575 pNode = pGraph->pNodes + pGraph->nSize++;
576 memset( pNode, 0, sizeof(Dec_Node_t) );
577 return pNode;
578}
579
591static inline Dec_Edge_t Dec_GraphAddNodeAnd( Dec_Graph_t * pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1 )
592{
593 Dec_Node_t * pNode;
594 // get the new node
595 pNode = Dec_GraphAppendNode( pGraph );
596 // set the inputs and other info
597 pNode->eEdge0 = eEdge0;
598 pNode->eEdge1 = eEdge1;
599 pNode->fCompl0 = eEdge0.fCompl;
600 pNode->fCompl1 = eEdge1.fCompl;
601 return Dec_EdgeCreate( pGraph->nSize - 1, 0 );
602}
603
615static inline Dec_Edge_t Dec_GraphAddNodeOr( Dec_Graph_t * pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1 )
616{
617 Dec_Node_t * pNode;
618 // get the new node
619 pNode = Dec_GraphAppendNode( pGraph );
620 // set the inputs and other info
621 pNode->eEdge0 = eEdge0;
622 pNode->eEdge1 = eEdge1;
623 pNode->fCompl0 = eEdge0.fCompl;
624 pNode->fCompl1 = eEdge1.fCompl;
625 // make adjustments for the OR gate
626 pNode->fNodeOr = 1;
627 pNode->eEdge0.fCompl = !pNode->eEdge0.fCompl;
628 pNode->eEdge1.fCompl = !pNode->eEdge1.fCompl;
629 return Dec_EdgeCreate( pGraph->nSize - 1, 1 );
630}
631
643static inline Dec_Edge_t Dec_GraphAddNodeXor( Dec_Graph_t * pGraph, Dec_Edge_t eEdge0, Dec_Edge_t eEdge1, int Type )
644{
645 Dec_Edge_t eNode0, eNode1, eNode;
646 if ( Type == 0 )
647 {
648 // derive the first AND
649 eEdge0.fCompl ^= 1;
650 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
651 eEdge0.fCompl ^= 1;
652 // derive the second AND
653 eEdge1.fCompl ^= 1;
654 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
655 // derive the final OR
656 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
657 }
658 else
659 {
660 // derive the first AND
661 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
662 // derive the second AND
663 eEdge0.fCompl ^= 1;
664 eEdge1.fCompl ^= 1;
665 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 );
666 // derive the final OR
667 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
668 eNode.fCompl ^= 1;
669 }
670 return eNode;
671}
672
684static inline Dec_Edge_t Dec_GraphAddNodeMux( Dec_Graph_t * pGraph, Dec_Edge_t eEdgeC, Dec_Edge_t eEdgeT, Dec_Edge_t eEdgeE, int Type )
685{
686 Dec_Edge_t eNode0, eNode1, eNode;
687 if ( Type == 0 )
688 {
689 // derive the first AND
690 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeT );
691 // derive the second AND
692 eEdgeC.fCompl ^= 1;
693 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeE );
694 // derive the final OR
695 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
696 }
697 else
698 {
699 // complement the arguments
700 eEdgeT.fCompl ^= 1;
701 eEdgeE.fCompl ^= 1;
702 // derive the first AND
703 eNode0 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeT );
704 // derive the second AND
705 eEdgeC.fCompl ^= 1;
706 eNode1 = Dec_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeE );
707 // derive the final OR
708 eNode = Dec_GraphAddNodeOr( pGraph, eNode0, eNode1 );
709 eNode.fCompl ^= 1;
710 }
711 return eNode;
712}
713
714
715
717
718
719
720#endif
721
725
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct Dec_Man_t_ Dec_Man_t
Definition dec.h:79
struct Dec_Node_t_ Dec_Node_t
Definition dec.h:49
Dec_Man_t * Dec_ManStart()
DECLARATIONS ///.
Definition decMan.c:45
unsigned Dec_GraphDeriveTruth(Dec_Graph_t *pGraph)
DECLARATIONS ///.
Definition decUtil.c:102
typedefABC_NAMESPACE_HEADER_START struct Dec_Edge_t_ Dec_Edge_t
INCLUDES ///.
Definition dec.h:42
void Dec_ManStop(Dec_Man_t *p)
Definition decMan.c:70
void Dec_GraphPrint(FILE *pFile, Dec_Graph_t *pGraph, char *pNamesIn[], char *pNameOut)
FUNCTION DEFINITIONS ///.
Definition decPrint.c:49
Dec_Graph_t * Dec_Factor(char *pSop)
FUNCTION DECLARATIONS ///.
Definition decFactor.c:58
struct Dec_Graph_t_ Dec_Graph_t
Definition dec.h:68
Cube * p
Definition exorList.c:222
unsigned fCompl
Definition dec.h:45
unsigned Node
Definition dec.h:46
Dec_Node_t * pNodes
Definition dec.h:75
int nCap
Definition dec.h:74
int fConst
Definition dec.h:71
int nLeaves
Definition dec.h:72
int nSize
Definition dec.h:73
Dec_Edge_t eRoot
Definition dec.h:76
Vec_Int_t * vCubes
Definition dec.h:83
char * pPerms
Definition dec.h:88
char * pPhases
Definition dec.h:87
void * pMvcMem
Definition dec.h:82
unsigned char * pMap
Definition dec.h:89
Vec_Int_t * vLits
Definition dec.h:84
unsigned short * puCanons
Definition dec.h:86
unsigned fCompl1
Definition dec.h:61
Dec_Edge_t eEdge1
Definition dec.h:53
void * pFunc
Definition dec.h:56
unsigned nLat0
Definition dec.h:63
unsigned fNodeOr
Definition dec.h:59
int iFunc
Definition dec.h:55
unsigned nLat1
Definition dec.h:64
unsigned Level
Definition dec.h:57
Dec_Edge_t eEdge0
Definition dec.h:52
unsigned fCompl0
Definition dec.h:60
unsigned nLat2
Definition dec.h:65
#define assert(ex)
Definition util_old.h:213
char * memset()