ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
decAbc.c
Go to the documentation of this file.
1
18
19#include "base/abc/abc.h"
20#include "aig/ivy/ivy.h"
21#include "dec.h"
22
24
25
29
33
47{
48 Abc_Obj_t * pAnd0, * pAnd1;
49 Dec_Node_t * pNode = NULL; // Suppress "might be used uninitialized"
50 int i;
51 // check for constant function
52 if ( Dec_GraphIsConst(pGraph) )
53 return Abc_ObjNotCond( Abc_AigConst1(pNtk), Dec_GraphIsComplement(pGraph) );
54 // check for a literal
55 if ( Dec_GraphIsVar(pGraph) )
56 return Abc_ObjNotCond( (Abc_Obj_t *)Dec_GraphVar(pGraph)->pFunc, Dec_GraphIsComplement(pGraph) );
57 // build the AIG nodes corresponding to the AND gates of the graph
58 Dec_GraphForEachNode( pGraph, pNode, i )
59 {
60 pAnd0 = Abc_ObjNotCond( (Abc_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
61 pAnd1 = Abc_ObjNotCond( (Abc_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
62 pNode->pFunc = Abc_AigAnd( (Abc_Aig_t *)pNtk->pManFunc, pAnd0, pAnd1 );
63 }
64 // complement the result if necessary
65 return Abc_ObjNotCond( (Abc_Obj_t *)pNode->pFunc, Dec_GraphIsComplement(pGraph) );
66}
67
79Abc_Obj_t * Dec_SopToAig( Abc_Ntk_t * pNtk, char * pSop, Vec_Ptr_t * vFaninAigs )
80{
81 Abc_Obj_t * pFunc;
82 Dec_Graph_t * pFForm;
83 Dec_Node_t * pNode;
84 int i;
85 pFForm = Dec_Factor( pSop );
86 Dec_GraphForEachLeaf( pFForm, pNode, i )
87 pNode->pFunc = Vec_PtrEntry( vFaninAigs, i );
88 pFunc = Dec_GraphToNetwork( pNtk, pFForm );
89 Dec_GraphFree( pFForm );
90 return pFunc;
91}
92
104Abc_Obj_t * Dec_GraphToAig( Abc_Ntk_t * pNtk, Dec_Graph_t * pFForm, Vec_Ptr_t * vFaninAigs )
105{
106 Abc_Obj_t * pFunc;
107 Dec_Node_t * pNode;
108 int i;
109 Dec_GraphForEachLeaf( pFForm, pNode, i )
110 pNode->pFunc = Vec_PtrEntry( vFaninAigs, i );
111 pFunc = Dec_GraphToNetwork( pNtk, pFForm );
112 return pFunc;
113}
114
128{
129 Abc_Obj_t * pAnd, * pAnd0, * pAnd1;
130 Dec_Node_t * pNode = NULL; // Suppress "might be used uninitialized"
131 int i;
132 // check for constant function
133 if ( Dec_GraphIsConst(pGraph) )
134 return Abc_ObjNotCond( Abc_AigConst1(pNtk), Dec_GraphIsComplement(pGraph) );
135 // check for a literal
136 if ( Dec_GraphIsVar(pGraph) )
137 return Abc_ObjNotCond( (Abc_Obj_t *)Dec_GraphVar(pGraph)->pFunc, Dec_GraphIsComplement(pGraph) );
138 // build the AIG nodes corresponding to the AND gates of the graph
139 Dec_GraphForEachNode( pGraph, pNode, i )
140 {
141 pAnd0 = Abc_ObjNotCond( (Abc_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
142 pAnd1 = Abc_ObjNotCond( (Abc_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
143// pNode->pFunc = Abc_AigAnd( (Abc_Aig_t *)pNtk->pManFunc, pAnd0, pAnd1 );
144 pAnd = Abc_NtkCreateNode( pNtk );
145 Abc_ObjAddFanin( pAnd, pAnd0 );
146 Abc_ObjAddFanin( pAnd, pAnd1 );
147 pNode->pFunc = pAnd;
148 }
149 // complement the result if necessary
150 return Abc_ObjNotCond( (Abc_Obj_t *)pNode->pFunc, Dec_GraphIsComplement(pGraph) );
151}
152
167int Dec_GraphToNetworkCount( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int NodeMax, int LevelMax )
168{
169 Abc_Aig_t * pMan = (Abc_Aig_t *)pRoot->pNtk->pManFunc;
170 Dec_Node_t * pNode, * pNode0, * pNode1;
171 Abc_Obj_t * pAnd, * pAnd0, * pAnd1;
172 int i, Counter, LevelNew, LevelOld;
173 // check for constant function or a literal
174 if ( Dec_GraphIsConst(pGraph) || Dec_GraphIsVar(pGraph) )
175 return 0;
176 // set the levels of the leaves
177 Dec_GraphForEachLeaf( pGraph, pNode, i )
178 pNode->Level = Abc_ObjRegular((Abc_Obj_t *)pNode->pFunc)->Level;
179 // compute the AIG size after adding the internal nodes
180 Counter = 0;
181 Dec_GraphForEachNode( pGraph, pNode, i )
182 {
183 // get the children of this node
184 pNode0 = Dec_GraphNode( pGraph, pNode->eEdge0.Node );
185 pNode1 = Dec_GraphNode( pGraph, pNode->eEdge1.Node );
186 // get the AIG nodes corresponding to the children
187 pAnd0 = (Abc_Obj_t *)pNode0->pFunc;
188 pAnd1 = (Abc_Obj_t *)pNode1->pFunc;
189 if ( pAnd0 && pAnd1 )
190 {
191 // if they are both present, find the resulting node
192 pAnd0 = Abc_ObjNotCond( pAnd0, pNode->eEdge0.fCompl );
193 pAnd1 = Abc_ObjNotCond( pAnd1, pNode->eEdge1.fCompl );
194 pAnd = Abc_AigAndLookup( pMan, pAnd0, pAnd1 );
195 // return -1 if the node is the same as the original root
196 if ( Abc_ObjRegular(pAnd) == pRoot )
197 return -1;
198 }
199 else
200 pAnd = NULL;
201 // count the number of added nodes
202 if ( pAnd == NULL || Abc_NodeIsTravIdCurrent(Abc_ObjRegular(pAnd)) )
203 {
204 if ( ++Counter > NodeMax )
205 return -1;
206 }
207 // count the number of new levels
208 LevelNew = 1 + Abc_MaxInt( pNode0->Level, pNode1->Level );
209 if ( pAnd )
210 {
211 if ( Abc_ObjRegular(pAnd) == Abc_AigConst1(pRoot->pNtk) )
212 LevelNew = 0;
213 else if ( Abc_ObjRegular(pAnd) == Abc_ObjRegular(pAnd0) )
214 LevelNew = (int)Abc_ObjRegular(pAnd0)->Level;
215 else if ( Abc_ObjRegular(pAnd) == Abc_ObjRegular(pAnd1) )
216 LevelNew = (int)Abc_ObjRegular(pAnd1)->Level;
217 LevelOld = (int)Abc_ObjRegular(pAnd)->Level;
218// assert( LevelNew == LevelOld );
219 }
220 if ( LevelNew > LevelMax )
221 return -1;
222 pNode->pFunc = pAnd;
223 pNode->Level = LevelNew;
224 }
225 return Counter;
226}
227
228
240int Dec_GraphUpdateNetwork( Abc_Obj_t * pRoot, Dec_Graph_t * pGraph, int fUpdateLevel, int nGain )
241{
242 extern Abc_Obj_t * Dec_GraphToNetwork( Abc_Ntk_t * pNtk, Dec_Graph_t * pGraph );
243 Abc_Obj_t * pRootNew;
244 Abc_Ntk_t * pNtk = pRoot->pNtk;
245 int nNodesNew, nNodesOld, RetValue;
246 nNodesOld = Abc_NtkNodeNum(pNtk);
247 // create the new structure of nodes
248 pRootNew = Dec_GraphToNetwork( pNtk, pGraph );
249 // remove the old nodes
250 RetValue = Abc_AigReplace( (Abc_Aig_t *)pNtk->pManFunc, pRoot, pRootNew, fUpdateLevel );
251 // compare the gains
252 nNodesNew = Abc_NtkNodeNum(pNtk);
253 //assert( nGain <= nNodesOld - nNodesNew );
254 return RetValue;
255}
256
257
270{
271 Dec_Node_t * pNode = NULL; // Suppress "might be used uninitialized"
272 Hop_Obj_t * pAnd0, * pAnd1;
273 int i;
274 // check for constant function
275 if ( Dec_GraphIsConst(pGraph) )
276 return Hop_NotCond( Hop_ManConst1(pMan), Dec_GraphIsComplement(pGraph) );
277 // check for a literal
278 if ( Dec_GraphIsVar(pGraph) )
279 return Hop_NotCond( (Hop_Obj_t *)Dec_GraphVar(pGraph)->pFunc, Dec_GraphIsComplement(pGraph) );
280 // build the AIG nodes corresponding to the AND gates of the graph
281 Dec_GraphForEachNode( pGraph, pNode, i )
282 {
283 pAnd0 = Hop_NotCond( (Hop_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
284 pAnd1 = Hop_NotCond( (Hop_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
285 pNode->pFunc = Hop_And( pMan, pAnd0, pAnd1 );
286 }
287 // complement the result if necessary
288 return Hop_NotCond( (Hop_Obj_t *)pNode->pFunc, Dec_GraphIsComplement(pGraph) );
289}
290
302Hop_Obj_t * Dec_GraphFactorSop( Hop_Man_t * pMan, char * pSop )
303{
304 Hop_Obj_t * pFunc;
305 Dec_Graph_t * pFForm;
306 Dec_Node_t * pNode;
307 int i;
308 // perform factoring
309 pFForm = Dec_Factor( pSop );
310 // collect the fanins
311 Dec_GraphForEachLeaf( pFForm, pNode, i )
312 pNode->pFunc = Hop_IthVar( pMan, i );
313 // perform strashing
314 pFunc = Dec_GraphToNetworkAig( pMan, pFForm );
315 Dec_GraphFree( pFForm );
316 return pFunc;
317}
318
331{
332 Dec_Node_t * pNode = NULL; // Suppress "might be used uninitialized"
333 Ivy_Obj_t * pAnd0, * pAnd1;
334 int i;
335 // check for constant function
336 if ( Dec_GraphIsConst(pGraph) )
337 return Ivy_NotCond( Ivy_ManConst1(pMan), Dec_GraphIsComplement(pGraph) );
338 // check for a literal
339 if ( Dec_GraphIsVar(pGraph) )
340 return Ivy_NotCond( (Ivy_Obj_t *)Dec_GraphVar(pGraph)->pFunc, Dec_GraphIsComplement(pGraph) );
341 // build the AIG nodes corresponding to the AND gates of the graph
342 Dec_GraphForEachNode( pGraph, pNode, i )
343 {
344 pAnd0 = Ivy_NotCond( (Ivy_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl );
345 pAnd1 = Ivy_NotCond( (Ivy_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl );
346 pNode->pFunc = Ivy_And( pMan, pAnd0, pAnd1 );
347 }
348 // complement the result if necessary
349 return Ivy_NotCond( (Ivy_Obj_t *)pNode->pFunc, Dec_GraphIsComplement(pGraph) );
350}
351
352
356
357
359
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
struct Abc_Aig_t_ Abc_Aig_t
Definition abc.h:117
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL Abc_Obj_t * Abc_AigAndLookup(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition abcAig.c:403
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition abcAig.c:700
ABC_DLL int Abc_AigReplace(Abc_Aig_t *pMan, Abc_Obj_t *pOld, Abc_Obj_t *pNew, int fUpdateLevel)
Definition abcAig.c:850
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition abcAig.c:683
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
int Dec_GraphToNetworkCount(Abc_Obj_t *pRoot, Dec_Graph_t *pGraph, int NodeMax, int LevelMax)
Definition decAbc.c:167
Ivy_Obj_t * Dec_GraphToNetworkIvy(Ivy_Man_t *pMan, Dec_Graph_t *pGraph)
Definition decAbc.c:330
Hop_Obj_t * Dec_GraphFactorSop(Hop_Man_t *pMan, char *pSop)
Definition decAbc.c:302
Hop_Obj_t * Dec_GraphToNetworkAig(Hop_Man_t *pMan, Dec_Graph_t *pGraph)
Definition decAbc.c:269
int Dec_GraphUpdateNetwork(Abc_Obj_t *pRoot, Dec_Graph_t *pGraph, int fUpdateLevel, int nGain)
Definition decAbc.c:240
Abc_Obj_t * Dec_GraphToAig(Abc_Ntk_t *pNtk, Dec_Graph_t *pFForm, Vec_Ptr_t *vFaninAigs)
Definition decAbc.c:104
Abc_Obj_t * Dec_GraphToNetworkNoStrash(Abc_Ntk_t *pNtk, Dec_Graph_t *pGraph)
Definition decAbc.c:127
Abc_Obj_t * Dec_SopToAig(Abc_Ntk_t *pNtk, char *pSop, Vec_Ptr_t *vFaninAigs)
Definition decAbc.c:79
ABC_NAMESPACE_IMPL_START Abc_Obj_t * Dec_GraphToNetwork(Abc_Ntk_t *pNtk, Dec_Graph_t *pGraph)
DECLARATIONS ///.
Definition decAbc.c:46
struct Dec_Node_t_ Dec_Node_t
Definition dec.h:49
#define Dec_GraphForEachLeaf(pGraph, pLeaf, i)
ITERATORS ///.
Definition dec.h:98
#define Dec_GraphForEachNode(pGraph, pAnd, i)
Definition dec.h:101
Dec_Graph_t * Dec_Factor(char *pSop)
FUNCTION DECLARATIONS ///.
Definition decFactor.c:58
struct Dec_Graph_t_ Dec_Graph_t
Definition dec.h:68
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
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
Definition hopOper.c:104
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition ivy.h:46
struct Ivy_Obj_t_ Ivy_Obj_t
Definition ivy.h:47
Ivy_Obj_t * Ivy_And(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1)
Definition ivyOper.c:84
void * pManFunc
Definition abc.h:191
Abc_Ntk_t * pNtk
Definition abc.h:130
Dec_Edge_t eEdge1
Definition dec.h:53
void * pFunc
Definition dec.h:56
unsigned Level
Definition dec.h:57
Dec_Edge_t eEdge0
Definition dec.h:52
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42