abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
kitHop.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [kitHop.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Computation kit.]
8 
9  Synopsis [Procedures involving AIGs.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - Dec 6, 2006.]
16 
17  Revision [$Id: kitHop.c,v 1.00 2006/12/06 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "kit.h"
22 #include "aig/hop/hop.h"
23 #include "aig/gia/gia.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Transforms the decomposition graph into the AIG.]
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
47 int Kit_GraphToGiaInternal( Gia_Man_t * pMan, Kit_Graph_t * pGraph, int fHash )
48 {
49  Kit_Node_t * pNode = NULL;
50  int i, pAnd0, pAnd1;
51  // check for constant function
52  if ( Kit_GraphIsConst(pGraph) )
53  return Abc_LitNotCond( 1, Kit_GraphIsComplement(pGraph) );
54  // check for a literal
55  if ( Kit_GraphIsVar(pGraph) )
56  return Abc_LitNotCond( Kit_GraphVar(pGraph)->iFunc, Kit_GraphIsComplement(pGraph) );
57  // build the AIG nodes corresponding to the AND gates of the graph
58  Kit_GraphForEachNode( pGraph, pNode, i )
59  {
60  pAnd0 = Abc_LitNotCond( Kit_GraphNode(pGraph, pNode->eEdge0.Node)->iFunc, pNode->eEdge0.fCompl );
61  pAnd1 = Abc_LitNotCond( Kit_GraphNode(pGraph, pNode->eEdge1.Node)->iFunc, pNode->eEdge1.fCompl );
62  if ( fHash )
63  pNode->iFunc = Gia_ManHashAnd( pMan, pAnd0, pAnd1 );
64  else
65  pNode->iFunc = Gia_ManAppendAnd( pMan, pAnd0, pAnd1 );
66  }
67  // complement the result if necessary
68  return Abc_LitNotCond( pNode->iFunc, Kit_GraphIsComplement(pGraph) );
69 }
70 int Kit_GraphToGia( Gia_Man_t * pMan, Kit_Graph_t * pGraph, Vec_Int_t * vLeaves, int fHash )
71 {
72  Kit_Node_t * pNode = NULL;
73  int i;
74  // collect the fanins
75  Kit_GraphForEachLeaf( pGraph, pNode, i )
76  pNode->iFunc = vLeaves ? Vec_IntEntry(vLeaves, i) : Gia_Obj2Lit(pMan, Gia_ManPi(pMan, i));
77  // perform strashing
78  return Kit_GraphToGiaInternal( pMan, pGraph, fHash );
79 }
80 int Kit_TruthToGia( Gia_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory, Vec_Int_t * vLeaves, int fHash )
81 {
82  int iLit;
83  Kit_Graph_t * pGraph;
84  // transform truth table into the decomposition tree
85  if ( vMemory == NULL )
86  {
87  vMemory = Vec_IntAlloc( 0 );
88  pGraph = Kit_TruthToGraph( pTruth, nVars, vMemory );
89  Vec_IntFree( vMemory );
90  }
91  else
92  pGraph = Kit_TruthToGraph( pTruth, nVars, vMemory );
93  if ( pGraph == NULL )
94  {
95  printf( "Kit_TruthToGia(): Converting truth table to AIG has failed for function:\n" );
96  Kit_DsdPrintFromTruth( pTruth, nVars ); printf( "\n" );
97  }
98  // derive the AIG for the decomposition tree
99  iLit = Kit_GraphToGia( pMan, pGraph, vLeaves, fHash );
100  Kit_GraphFree( pGraph );
101  return iLit;
102 }
103 
104 /**Function*************************************************************
105 
106  Synopsis [Transforms the decomposition graph into the AIG.]
107 
108  Description []
109 
110  SideEffects []
111 
112  SeeAlso []
113 
114 ***********************************************************************/
116 {
117  Kit_Node_t * pNode = NULL;
118  Hop_Obj_t * pAnd0, * pAnd1;
119  int i;
120  // check for constant function
121  if ( Kit_GraphIsConst(pGraph) )
122  return Hop_NotCond( Hop_ManConst1(pMan), Kit_GraphIsComplement(pGraph) );
123  // check for a literal
124  if ( Kit_GraphIsVar(pGraph) )
125  return Hop_NotCond( (Hop_Obj_t *)Kit_GraphVar(pGraph)->pFunc, Kit_GraphIsComplement(pGraph) );
126  // build the AIG nodes corresponding to the AND gates of the graph
127  Kit_GraphForEachNode( pGraph, pNode, i )
128  {
129  pAnd0 = Hop_NotCond( (Hop_Obj_t *)Kit_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
130  pAnd1 = Hop_NotCond( (Hop_Obj_t *)Kit_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
131  pNode->pFunc = Hop_And( pMan, pAnd0, pAnd1 );
132  }
133  // complement the result if necessary
134  return Hop_NotCond( (Hop_Obj_t *)pNode->pFunc, Kit_GraphIsComplement(pGraph) );
135 }
137 {
138  Kit_Node_t * pNode = NULL;
139  int i;
140  // collect the fanins
141  Kit_GraphForEachLeaf( pGraph, pNode, i )
142  pNode->pFunc = Hop_IthVar( pMan, i );
143  // perform strashing
144  return Kit_GraphToHopInternal( pMan, pGraph );
145 }
146 Hop_Obj_t * Kit_TruthToHop( Hop_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory )
147 {
148  Hop_Obj_t * pObj;
149  Kit_Graph_t * pGraph;
150  // transform truth table into the decomposition tree
151  if ( vMemory == NULL )
152  {
153  vMemory = Vec_IntAlloc( 0 );
154  pGraph = Kit_TruthToGraph( pTruth, nVars, vMemory );
155  Vec_IntFree( vMemory );
156  }
157  else
158  pGraph = Kit_TruthToGraph( pTruth, nVars, vMemory );
159  if ( pGraph == NULL )
160  {
161  printf( "Kit_TruthToHop(): Converting truth table to AIG has failed for function:\n" );
162  Kit_DsdPrintFromTruth( pTruth, nVars ); printf( "\n" );
163  }
164  // derive the AIG for the decomposition tree
165  pObj = Kit_GraphToHop( pMan, pGraph );
166  Kit_GraphFree( pGraph );
167  return pObj;
168 }
169 
170 /**Function*************************************************************
171 
172  Synopsis [Strashes one logic node using its SOP.]
173 
174  Description []
175 
176  SideEffects []
177 
178  SeeAlso []
179 
180 ***********************************************************************/
181 Hop_Obj_t * Kit_CoverToHop( Hop_Man_t * pMan, Vec_Int_t * vCover, int nVars, Vec_Int_t * vMemory )
182 {
183  Kit_Graph_t * pGraph;
184  Hop_Obj_t * pFunc;
185  // perform factoring
186  Vec_IntClear( vMemory );
187  pGraph = Kit_SopFactor( vCover, 0, nVars, vMemory );
188  // convert graph to the AIG
189  pFunc = Kit_GraphToHop( pMan, pGraph );
190  Kit_GraphFree( pGraph );
191  return pFunc;
192 }
193 
194 ////////////////////////////////////////////////////////////////////////
195 /// END OF FILE ///
196 ////////////////////////////////////////////////////////////////////////
197 
198 
200 
int Kit_TruthToGia(Gia_Man_t *pMan, unsigned *pTruth, int nVars, Vec_Int_t *vMemory, Vec_Int_t *vLeaves, int fHash)
DECLARATIONS ///.
Definition: kitHop.c:80
static int Gia_ManAppendAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: gia.h:592
Kit_Edge_t eEdge0
Definition: kit.h:69
static Hop_Obj_t * Hop_ManConst1(Hop_Man_t *p)
Definition: hop.h:132
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition: hopOper.c:104
Hop_Obj_t * Kit_GraphToHopInternal(Hop_Man_t *pMan, Kit_Graph_t *pGraph)
Definition: kitHop.c:115
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static Kit_Node_t * Kit_GraphNode(Kit_Graph_t *pGraph, int i)
Definition: kit.h:211
Kit_Edge_t eEdge1
Definition: kit.h:70
static int Kit_GraphIsComplement(Kit_Graph_t *pGraph)
Definition: kit.h:205
static int Kit_GraphIsVar(Kit_Graph_t *pGraph)
Definition: kit.h:206
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
Definition: kitDsd.c:490
#define Kit_GraphForEachLeaf(pGraph, pLeaf, i)
Definition: kit.h:502
void * pFunc
Definition: kit.h:73
Definition: hop.h:65
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
Hop_Obj_t * Kit_TruthToHop(Hop_Man_t *pMan, unsigned *pTruth, int nVars, Vec_Int_t *vMemory)
Definition: kitHop.c:146
static int Kit_GraphIsConst(Kit_Graph_t *pGraph)
Definition: kit.h:202
Hop_Obj_t * Kit_GraphToHop(Hop_Man_t *pMan, Kit_Graph_t *pGraph)
Definition: kitHop.c:136
static Gia_Obj_t * Gia_ManPi(Gia_Man_t *p, int v)
Definition: gia.h:405
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
unsigned fCompl
Definition: kit.h:62
void Kit_GraphFree(Kit_Graph_t *pGraph)
Definition: kitGraph.c:131
int Kit_GraphToGia(Gia_Man_t *pMan, Kit_Graph_t *pGraph, Vec_Int_t *vLeaves, int fHash)
Definition: kitHop.c:70
#define Kit_GraphForEachNode(pGraph, pAnd, i)
Definition: kit.h:504
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
unsigned Node
Definition: kit.h:63
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
ABC_NAMESPACE_IMPL_START int Kit_GraphToGiaInternal(Gia_Man_t *pMan, Kit_Graph_t *pGraph, int fHash)
DECLARATIONS ///.
Definition: kitHop.c:47
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static Hop_Obj_t * Hop_NotCond(Hop_Obj_t *p, int c)
Definition: hop.h:128
Definition: gia.h:95
Hop_Obj_t * Kit_CoverToHop(Hop_Man_t *pMan, Vec_Int_t *vCover, int nVars, Vec_Int_t *vMemory)
Definition: kitHop.c:181
static Kit_Node_t * Kit_GraphVar(Kit_Graph_t *pGraph)
Definition: kit.h:215
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
int iFunc
Definition: kit.h:72
Kit_Graph_t * Kit_TruthToGraph(unsigned *pTruth, int nVars, Vec_Int_t *vMemory)
Definition: kitGraph.c:355
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition: hopOper.c:63
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition: giaHash.c:572
static int Gia_Obj2Lit(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:433
Kit_Graph_t * Kit_SopFactor(Vec_Int_t *vCover, int fCompl, int nVars, Vec_Int_t *vMemory)
FUNCTION DEFINITIONS ///.
Definition: kitFactor.c:55