ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
amapGraph.c
Go to the documentation of this file.
1
20
21#include "amapInt.h"
22
24
25
29
33
46{
47 Amap_Obj_t * pObj;
48 pObj = (Amap_Obj_t *)Aig_MmFixedEntryFetch( p->pMemObj );
49 memset( pObj, 0, sizeof(Amap_Obj_t) );
50 pObj->nFouts[0] = 1; // needed for flow to work in the first pass
51 pObj->Id = Vec_PtrSize(p->vObjs);
52 Vec_PtrPush( p->vObjs, pObj );
53 return pObj;
54}
55
68{
69 Amap_Obj_t * pObj;
70 pObj = Amap_ManSetupObj( p );
71 pObj->Type = AMAP_OBJ_CONST1;
72 pObj->fPhase = 1;
73 p->nObjs[AMAP_OBJ_CONST1]++;
74 return pObj;
75}
76
89{
90 Amap_Obj_t * pObj;
91 pObj = Amap_ManSetupObj( p );
92 pObj->Type = AMAP_OBJ_PI;
93 pObj->IdPio = Vec_PtrSize( p->vPis );
94 Vec_PtrPush( p->vPis, pObj );
95 p->nObjs[AMAP_OBJ_PI]++;
96 return pObj;
97}
98
111{
112 Amap_Obj_t * pObj;
113 pObj = Amap_ManSetupObj( p );
114 pObj->IdPio = Vec_PtrSize( p->vPos );
115 Vec_PtrPush( p->vPos, pObj );
116 pObj->Type = AMAP_OBJ_PO;
117 pObj->Fan[0] = Amap_ObjToLit(pFan0); Amap_Regular(pFan0)->nRefs++;
118 pObj->Level = Amap_Regular(pFan0)->Level;
119 if ( p->nLevelMax < (int)pObj->Level )
120 p->nLevelMax = (int)pObj->Level;
121 assert( p->nLevelMax < 4094 ); // 2^12-2
122 p->nObjs[AMAP_OBJ_PO]++;
123 return pObj;
124}
125
138{
139 Amap_Obj_t * pObj;
140 pObj = Amap_ManSetupObj( p );
141 pObj->Type = AMAP_OBJ_AND;
142 pObj->Fan[0] = Amap_ObjToLit(pFan0); Amap_Regular(pFan0)->nRefs++;
143 pObj->Fan[1] = Amap_ObjToLit(pFan1); Amap_Regular(pFan1)->nRefs++;
144 assert( Abc_Lit2Var(pObj->Fan[0]) != Abc_Lit2Var(pObj->Fan[1]) );
145 pObj->fPhase = Amap_ObjPhaseReal(pFan0) & Amap_ObjPhaseReal(pFan1);
146 pObj->Level = 1 + Abc_MaxInt( Amap_Regular(pFan0)->Level, Amap_Regular(pFan1)->Level );
147 if ( p->nLevelMax < (int)pObj->Level )
148 p->nLevelMax = (int)pObj->Level;
149 assert( p->nLevelMax < 4094 ); // 2^12-2
150 p->nObjs[AMAP_OBJ_AND]++;
151 return pObj;
152}
153
166{
167 Amap_Obj_t * pObj;
168 pObj = Amap_ManSetupObj( p );
169 pObj->Type = AMAP_OBJ_XOR;
170 pObj->Fan[0] = Amap_ObjToLit(pFan0); Amap_Regular(pFan0)->nRefs++;
171 pObj->Fan[1] = Amap_ObjToLit(pFan1); Amap_Regular(pFan1)->nRefs++;
172 pObj->fPhase = Amap_ObjPhaseReal(pFan0) ^ Amap_ObjPhaseReal(pFan1);
173 pObj->Level = 2 + Abc_MaxInt( Amap_Regular(pFan0)->Level, Amap_Regular(pFan1)->Level );
174 if ( p->nLevelMax < (int)pObj->Level )
175 p->nLevelMax = (int)pObj->Level;
176 assert( p->nLevelMax < 4094 ); // 2^12-2
177 p->nObjs[AMAP_OBJ_XOR]++;
178 return pObj;
179}
180
193{
194 Amap_Obj_t * pObj;
195 pObj = Amap_ManSetupObj( p );
196 pObj->Type = AMAP_OBJ_MUX;
197 pObj->Fan[0] = Amap_ObjToLit(pFan0); Amap_Regular(pFan0)->nRefs++;
198 pObj->Fan[1] = Amap_ObjToLit(pFan1); Amap_Regular(pFan1)->nRefs++;
199 pObj->Fan[2] = Amap_ObjToLit(pFanC); Amap_Regular(pFanC)->nRefs++;
200 pObj->fPhase = (Amap_ObjPhaseReal(pFan1) & Amap_ObjPhaseReal(pFanC)) |
201 (Amap_ObjPhaseReal(pFan0) & ~Amap_ObjPhaseReal(pFanC));
202 pObj->Level = Abc_MaxInt( Amap_Regular(pFan0)->Level, Amap_Regular(pFan1)->Level );
203 pObj->Level = 2 + Abc_MaxInt( pObj->Level, Amap_Regular(pFanC)->Level );
204 if ( p->nLevelMax < (int)pObj->Level )
205 p->nLevelMax = (int)pObj->Level;
206 assert( p->nLevelMax < 4094 ); // 2^12-2
207 p->nObjs[AMAP_OBJ_MUX]++;
208 return pObj;
209}
210
223{
224 Amap_Obj_t * pTemp;
225 // mark the node as a representative if its class
226// assert( pObj->fRepr == 0 );
227 pObj->fRepr = 1;
228 // update the level of this node (needed for correct required time computation)
229 for ( pTemp = pObj; pTemp; pTemp = Amap_ObjChoice(p, pTemp) )
230 {
231 pObj->Level = Abc_MaxInt( pObj->Level, pTemp->Level );
232// pTemp->nVisits++; pTemp->nVisitsCopy++;
233 }
234 // mark the largest level
235 if ( p->nLevelMax < (int)pObj->Level )
236 p->nLevelMax = (int)pObj->Level;
237 assert( p->nLevelMax < 4094 ); // 2^12-2
238}
239
251void Amap_ManCreateXorChoices( Amap_Man_t * p, Amap_Obj_t * pFan0, Amap_Obj_t * pFan1, Amap_Obj_t * pChoices[] )
252{
253 pChoices[0] = Amap_ManCreateXor( p, pFan0, pFan1 );
254 pChoices[1] = Amap_ManCreateXor( p, Amap_Not(pFan0), pFan1 );
255 pChoices[2] = Amap_ManCreateXor( p, pFan0, Amap_Not(pFan1) );
256 pChoices[3] = Amap_ManCreateXor( p, Amap_Not(pFan0), Amap_Not(pFan1) );
257}
258
270void Amap_ManCreateMuxChoices( Amap_Man_t * p, Amap_Obj_t * pFan0, Amap_Obj_t * pFan1, Amap_Obj_t * pFanC, Amap_Obj_t * pChoices[] )
271{
272 pChoices[0] = Amap_ManCreateMux( p, pFan0, pFan1, pFanC );
273 pChoices[1] = Amap_ManCreateMux( p, Amap_Not(pFan0), Amap_Not(pFan1), pFanC );
274 pChoices[2] = Amap_ManCreateMux( p, pFan1, pFan0, Amap_Not(pFanC) );
275 pChoices[3] = Amap_ManCreateMux( p, Amap_Not(pFan1), Amap_Not(pFan0), Amap_Not(pFanC) );
276}
277
289static inline Amap_Obj_t * Amap_AndToObj( Aig_Obj_t * pObj )
290{
291 return Amap_NotCond( (Amap_Obj_t *)Aig_Regular(pObj)->pData, Aig_IsComplement(pObj) );
292}
293
306{
307 if ( pObj->Equiv == 0 )
308 return pObj;
309 return Amap_ManGetLast_rec( p, Amap_ObjChoice(p, pObj) );
310}
311
324{
325 Vec_Ptr_t * vNodes;
326 Amap_Obj_t * pChoices[4];
327 Aig_Obj_t * pObj, * pFanin, * pPrev, * pFan0, * pFan1, * pFanC;
328 int i, fChoices;
329 if ( pAig->pEquivs )
330 vNodes = Aig_ManDfsChoices( pAig );
331 else
332 vNodes = Aig_ManDfs( pAig, 1 );
333 p->pConst1 = Amap_ManCreateConst1( p );
334 // print warning about excessive memory usage
335 if ( p->pPars->fVerbose )
336 {
337 if ( 1.0 * Aig_ManObjNum(pAig) * sizeof(Amap_Obj_t) / (1<<30) > 0.1 )
338 printf( "Warning: Mapper allocates %.3f GB for subject graph with %d objects.\n",
339 1.0 * Aig_ManObjNum(pAig) * sizeof(Amap_Obj_t) / (1<<30), Aig_ManObjNum(pAig) );
340 }
341 // create PIs and remember them in the old nodes
342 Aig_ManCleanData(pAig);
343 Aig_ManConst1(pAig)->pData = Amap_ManConst1( p );
344 Aig_ManForEachCi( pAig, pObj, i )
345 pObj->pData = Amap_ManCreatePi( p );
346 // load the AIG into the mapper
347 Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pObj, i )
348 {
349 fChoices = 0;
350 if ( p->fUseXor && Aig_ObjRecognizeExor(pObj, &pFan0, &pFan1 ) )
351 {
352 Amap_ManCreateXorChoices( p, Amap_AndToObj(pFan0), Amap_AndToObj(pFan1), pChoices );
353 fChoices = 1;
354 }
355 else if ( p->fUseMux && Aig_ObjIsMuxType(pObj) )
356 {
357 pFanC = Aig_ObjRecognizeMux( pObj, &pFan1, &pFan0 );
358 Amap_ManCreateMuxChoices( p, Amap_AndToObj(pFan0), Amap_AndToObj(pFan1), Amap_AndToObj(pFanC), pChoices );
359 fChoices = 1;
360 }
361 pObj->pData = Amap_ManCreateAnd( p, (Amap_Obj_t *)Aig_ObjChild0Copy(pObj), (Amap_Obj_t *)Aig_ObjChild1Copy(pObj) );
362 if ( fChoices )
363 {
364 p->nChoicesAdded++;
365 Amap_ObjSetChoice( (Amap_Obj_t *)pObj->pData, pChoices[0] );
366 Amap_ObjSetChoice( pChoices[0], pChoices[1] );
367 Amap_ObjSetChoice( pChoices[1], pChoices[2] );
368 Amap_ObjSetChoice( pChoices[2], pChoices[3] );
370 }
371 if ( Aig_ObjIsChoice( pAig, pObj ) )
372 {
373// assert( !fChoices );
374 p->nChoicesGiven++;
375 for ( pPrev = pObj, pFanin = Aig_ObjEquiv(pAig, pObj); pFanin; pPrev = pFanin, pFanin = Aig_ObjEquiv(pAig, pFanin) )
376 {
377 ((Amap_Obj_t *)pFanin->pData)->fRepr = 0;
378 Amap_ObjSetChoice( Amap_ManGetLast_rec(p, (Amap_Obj_t *)pPrev->pData),
379 (Amap_Obj_t *)pFanin->pData );
380 }
382 }
383 }
384 Vec_PtrFree( vNodes );
385 // set the primary outputs without copying the phase
386 Aig_ManForEachCo( pAig, pObj, i )
387 pObj->pData = Amap_ManCreatePo( p, (Amap_Obj_t *)Aig_ObjChild0Copy(pObj) );
388 if ( p->pPars->fVerbose )
389 printf( "Performing mapping with %d given and %d created choices.\n",
390 p->nChoicesGiven, p->nChoicesAdded );
391}
392
396
397
399
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Aig_Obj_t * Aig_ObjRecognizeMux(Aig_Obj_t *pObj, Aig_Obj_t **ppObjT, Aig_Obj_t **ppObjE)
Definition aigUtil.c:387
Vec_Ptr_t * Aig_ManDfsChoices(Aig_Man_t *p)
Definition aigDfs.c:405
int Aig_ObjRecognizeExor(Aig_Obj_t *pObj, Aig_Obj_t **ppFan0, Aig_Obj_t **ppFan1)
Definition aigUtil.c:343
char * Aig_MmFixedEntryFetch(Aig_MmFixed_t *p)
Definition aigMem.c:161
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition aig.h:393
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
#define Aig_ManForEachCo(p, pObj, i)
Definition aig.h:398
Vec_Ptr_t * Aig_ManDfs(Aig_Man_t *p, int fNodesOnly)
Definition aigDfs.c:145
int Aig_ObjIsMuxType(Aig_Obj_t *pObj)
Definition aigUtil.c:307
void Aig_ManCleanData(Aig_Man_t *p)
Definition aigUtil.c:205
void Amap_ManCreateMuxChoices(Amap_Man_t *p, Amap_Obj_t *pFan0, Amap_Obj_t *pFan1, Amap_Obj_t *pFanC, Amap_Obj_t *pChoices[])
Definition amapGraph.c:270
Amap_Obj_t * Amap_ManCreatePo(Amap_Man_t *p, Amap_Obj_t *pFan0)
Definition amapGraph.c:110
Amap_Obj_t * Amap_ManCreateMux(Amap_Man_t *p, Amap_Obj_t *pFan0, Amap_Obj_t *pFan1, Amap_Obj_t *pFanC)
Definition amapGraph.c:192
void Amap_ManCreate(Amap_Man_t *p, Aig_Man_t *pAig)
Definition amapGraph.c:323
void Amap_ManCreateXorChoices(Amap_Man_t *p, Amap_Obj_t *pFan0, Amap_Obj_t *pFan1, Amap_Obj_t *pChoices[])
Definition amapGraph.c:251
void Amap_ManCreateChoice(Amap_Man_t *p, Amap_Obj_t *pObj)
Definition amapGraph.c:222
Amap_Obj_t * Amap_ManCreatePi(Amap_Man_t *p)
FUNCTION DECLARATIONS ///.
Definition amapGraph.c:88
Amap_Obj_t * Amap_ManCreateXor(Amap_Man_t *p, Amap_Obj_t *pFan0, Amap_Obj_t *pFan1)
Definition amapGraph.c:165
Amap_Obj_t * Amap_ManCreateConst1(Amap_Man_t *p)
Definition amapGraph.c:67
Amap_Obj_t * Amap_ManCreateAnd(Amap_Man_t *p, Amap_Obj_t *pFan0, Amap_Obj_t *pFan1)
Definition amapGraph.c:137
Amap_Obj_t * Amap_ManGetLast_rec(Amap_Man_t *p, Amap_Obj_t *pObj)
Definition amapGraph.c:305
ABC_NAMESPACE_IMPL_START Amap_Obj_t * Amap_ManSetupObj(Amap_Man_t *p)
DECLARATIONS ///.
Definition amapGraph.c:45
struct Amap_Obj_t_ Amap_Obj_t
Definition amapInt.h:71
@ AMAP_OBJ_XOR
Definition amapInt.h:56
@ AMAP_OBJ_AND
Definition amapInt.h:55
@ AMAP_OBJ_CONST1
Definition amapInt.h:52
@ AMAP_OBJ_PO
Definition amapInt.h:54
@ AMAP_OBJ_PI
Definition amapInt.h:53
@ AMAP_OBJ_MUX
Definition amapInt.h:57
struct Amap_Man_t_ Amap_Man_t
Definition amapInt.h:70
Cube * p
Definition exorList.c:222
void * pData
Definition aig.h:87
unsigned Type
Definition amapInt.h:201
unsigned fRepr
Definition amapInt.h:205
int Fan[3]
Definition amapInt.h:211
void * pData
Definition amapInt.h:213
int nFouts[2]
Definition amapInt.h:218
unsigned Id
Definition amapInt.h:202
unsigned Level
Definition amapInt.h:207
unsigned IdPio
Definition amapInt.h:203
unsigned fPhase
Definition amapInt.h:204
#define assert(ex)
Definition util_old.h:213
char * memset()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55