ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
nwkMap.c
Go to the documentation of this file.
1
20
21#include "nwk.h"
22#include "map/if/if.h"
23
25
26
30
34
47{
48// extern void * Abc_FrameReadLibLut();
49 // set defaults
50 memset( pPars, 0, sizeof(If_Par_t) );
51 // user-controlable paramters
52// pPars->nLutSize = -1;
53 pPars->nLutSize = 6;
54 pPars->nCutsMax = 8;
55 pPars->nFlowIters = 1;
56 pPars->nAreaIters = 2;
57 pPars->DelayTarget = -1;
58 pPars->Epsilon = (float)0.005;
59 pPars->fPreprocess = 1;
60 pPars->fArea = 0;
61 pPars->fFancy = 0;
62 pPars->fExpRed = 1;
63 pPars->fLatchPaths = 0;
64 pPars->fEdge = 1;
65 pPars->fPower = 0;
66 pPars->fCutMin = 0;
67 pPars->fVerbose = 0;
68 // internal parameters
69 pPars->fTruth = 0;
70 pPars->nLatchesCi = 0;
71 pPars->nLatchesCo = 0;
72 pPars->fLiftLeaves = 0;
73// pPars->pLutLib = Abc_FrameReadLibLut();
74 pPars->pLutLib = NULL;
75 pPars->pTimesArr = NULL;
76 pPars->pTimesArr = NULL;
77 pPars->pFuncCost = NULL;
78/*
79 if ( pPars->nLutSize == -1 )
80 {
81 if ( pPars->pLutLib == NULL )
82 {
83 printf( "The LUT library is not given.\n" );
84 return;
85 }
86 // get LUT size from the library
87 pPars->nLutSize = pPars->pLutLib->LutMax;
88 }
89*/
90}
91
104{
105 extern Vec_Int_t * Saig_ManComputeSwitchProbs( Aig_Man_t * p, int nFrames, int nPref, int fProbOne );
106 Vec_Int_t * vSwitching = NULL, * vSwitching2 = NULL;
107 float * pSwitching = NULL, * pSwitching2 = NULL;
108 If_Man_t * pIfMan;
109 If_Obj_t * pIfObj = NULL;
110 Aig_Obj_t * pNode, * pFanin, * pPrev;
111 int i;
112 abctime clk = Abc_Clock();
113 // set the number of registers (switch activity will be combinational)
114 Aig_ManSetRegNum( p, 0 );
115 if ( pPars->fPower )
116 {
117 vSwitching = Saig_ManComputeSwitchProbs( p, 48, 16, 0 );
118 if ( pPars->fVerbose )
119 {
120 ABC_PRT( "Computing switching activity", Abc_Clock() - clk );
121 }
122 pSwitching = (float *)vSwitching->pArray;
123 vSwitching2 = Vec_IntStart( Aig_ManObjNumMax(p) );
124 pSwitching2 = (float *)vSwitching2->pArray;
125 }
126 // start the mapping manager and set its parameters
127 pIfMan = If_ManStart( pPars );
128 pIfMan->vSwitching = vSwitching2;
129 // load the AIG into the mapper
130 Aig_ManForEachObj( p, pNode, i )
131 {
132 if ( Aig_ObjIsAnd(pNode) )
133 {
134 pIfObj = If_ManCreateAnd( pIfMan,
135 If_NotCond( (If_Obj_t *)Aig_ObjFanin0(pNode)->pData, Aig_ObjFaninC0(pNode) ),
136 If_NotCond( (If_Obj_t *)Aig_ObjFanin1(pNode)->pData, Aig_ObjFaninC1(pNode) ) );
137// printf( "no%d=%d\n ", If_ObjId(pIfObj), If_ObjLevel(pIfObj) );
138 }
139 else if ( Aig_ObjIsCi(pNode) )
140 {
141 pIfObj = If_ManCreateCi( pIfMan );
142 If_ObjSetLevel( pIfObj, Aig_ObjLevel(pNode) );
143// printf( "pi%d=%d\n ", If_ObjId(pIfObj), If_ObjLevel(pIfObj) );
144 if ( pIfMan->nLevelMax < (int)pIfObj->Level )
145 pIfMan->nLevelMax = (int)pIfObj->Level;
146 }
147 else if ( Aig_ObjIsCo(pNode) )
148 {
149 pIfObj = If_ManCreateCo( pIfMan, If_NotCond( (If_Obj_t *)Aig_ObjFanin0(pNode)->pData, Aig_ObjFaninC0(pNode) ) );
150// printf( "po%d=%d\n ", If_ObjId(pIfObj), If_ObjLevel(pIfObj) );
151 }
152 else if ( Aig_ObjIsConst1(pNode) )
153 pIfObj = If_ManConst1( pIfMan );
154 else // add the node to the mapper
155 assert( 0 );
156 // save the result
157 assert( Vec_PtrEntry(vAigToIf, i) == NULL );
158 Vec_PtrWriteEntry( vAigToIf, i, pIfObj );
159 pNode->pData = pIfObj;
160 if ( vSwitching2 )
161 pSwitching2[pIfObj->Id] = pSwitching[pNode->Id];
162 // set up the choice node
163 if ( Aig_ObjIsChoice( p, pNode ) )
164 {
165 for ( pPrev = pNode, pFanin = Aig_ObjEquiv(p, pNode); pFanin; pPrev = pFanin, pFanin = Aig_ObjEquiv(p, pFanin) )
166 If_ObjSetChoice( (If_Obj_t *)pPrev->pData, (If_Obj_t *)pFanin->pData );
167 If_ManCreateChoice( pIfMan, (If_Obj_t *)pNode->pData );
168 }
169// assert( If_ObjLevel(pIfObj) == Aig_ObjLevel(pNode) );
170 }
171 if ( vSwitching )
172 Vec_IntFree( vSwitching );
173 return pIfMan;
174}
175
176
188Hop_Obj_t * Nwk_NodeIfToHop2_rec( Hop_Man_t * pHopMan, If_Man_t * pIfMan, If_Obj_t * pIfObj, Vec_Ptr_t * vVisited )
189{
190 If_Cut_t * pCut;
191 If_Obj_t * pTemp;
192 Hop_Obj_t * gFunc, * gFunc0, * gFunc1;
193 // get the best cut
194 pCut = If_ObjCutBest(pIfObj);
195 // if the cut is visited, return the result
196 if ( If_CutData(pCut) )
197 return (Hop_Obj_t *)If_CutData(pCut);
198 // mark the node as visited
199 Vec_PtrPush( vVisited, pCut );
200 // insert the worst case
201 If_CutSetData( pCut, (void *)1 );
202 // skip in case of primary input
203 if ( If_ObjIsCi(pIfObj) )
204 return (Hop_Obj_t *)If_CutData(pCut);
205 // compute the functions of the children
206 for ( pTemp = pIfObj; pTemp; pTemp = pTemp->pEquiv )
207 {
208 gFunc0 = Nwk_NodeIfToHop2_rec( pHopMan, pIfMan, pTemp->pFanin0, vVisited );
209 if ( gFunc0 == (void *)1 )
210 continue;
211 gFunc1 = Nwk_NodeIfToHop2_rec( pHopMan, pIfMan, pTemp->pFanin1, vVisited );
212 if ( gFunc1 == (void *)1 )
213 continue;
214 // both branches are solved
215 gFunc = Hop_And( pHopMan, Hop_NotCond(gFunc0, pTemp->fCompl0), Hop_NotCond(gFunc1, pTemp->fCompl1) );
216 if ( pTemp->fPhase != pIfObj->fPhase )
217 gFunc = Hop_Not(gFunc);
218 If_CutSetData( pCut, gFunc );
219 break;
220 }
221 return (Hop_Obj_t *)If_CutData(pCut);
222}
223
235Hop_Obj_t * Nwk_NodeIfToHop( Hop_Man_t * pHopMan, If_Man_t * pIfMan, If_Obj_t * pIfObj )
236{
237 If_Cut_t * pCut;
238 Hop_Obj_t * gFunc;
239 If_Obj_t * pLeaf;
240 int i;
241 // get the best cut
242 pCut = If_ObjCutBest(pIfObj);
243 assert( pCut->nLeaves > 1 );
244 // set the leaf variables
245 If_CutForEachLeaf( pIfMan, pCut, pLeaf, i )
246 If_CutSetData( If_ObjCutBest(pLeaf), Hop_IthVar(pHopMan, i) );
247 // recursively compute the function while collecting visited cuts
248 Vec_PtrClear( pIfMan->vTemp );
249 gFunc = Nwk_NodeIfToHop2_rec( pHopMan, pIfMan, pIfObj, pIfMan->vTemp );
250 if ( gFunc == (void *)1 )
251 {
252 printf( "Nwk_NodeIfToHop(): Computing local AIG has failed.\n" );
253 return NULL;
254 }
255// printf( "%d ", Vec_PtrSize(p->vTemp) );
256 // clean the cuts
257 If_CutForEachLeaf( pIfMan, pCut, pLeaf, i )
258 If_CutSetData( If_ObjCutBest(pLeaf), NULL );
259 Vec_PtrForEachEntry( If_Cut_t *, pIfMan->vTemp, pCut, i )
260 If_CutSetData( pCut, NULL );
261 return gFunc;
262}
263
276{
277 Vec_Ptr_t * vIfToAig;
278 Nwk_Man_t * pNtk;
279 Nwk_Obj_t * pObjNew = NULL;
280 Aig_Obj_t * pObj, * pObjRepr;
281 If_Obj_t * pIfObj = NULL;
282 If_Cut_t * pCutBest;
283 int i, k, nLeaves, * ppLeaves;
284 assert( Aig_ManCiNum(p) == If_ManCiNum(pIfMan) );
285 assert( Aig_ManCoNum(p) == If_ManCoNum(pIfMan) );
286 assert( Aig_ManNodeNum(p) == If_ManAndNum(pIfMan) );
288 If_ManCleanCutData( pIfMan );
289 // create mapping of IF to AIG
290 vIfToAig = Vec_PtrStart( If_ManObjNum(pIfMan) );
291 Aig_ManForEachObj( p, pObj, i )
292 {
293 pIfObj = (If_Obj_t *)Vec_PtrEntry( vAigToIf, i );
294 Vec_PtrWriteEntry( vIfToAig, pIfObj->Id, pObj );
295 }
296 // construct the network
297 pNtk = Nwk_ManAlloc();
298 pNtk->pName = Abc_UtilStrsav( p->pName );
299 pNtk->pSpec = Abc_UtilStrsav( p->pSpec );
300// pNtk->nLatches = Aig_ManRegNum(p);
301// pNtk->nTruePis = Nwk_ManCiNum(pNtk) - pNtk->nLatches;
302// pNtk->nTruePos = Nwk_ManCoNum(pNtk) - pNtk->nLatches;
303 Aig_ManForEachObj( p, pObj, i )
304 {
305 pIfObj = (If_Obj_t *)Vec_PtrEntry( vAigToIf, i );
306 if ( pIfObj->nRefs == 0 && !If_ObjIsTerm(pIfObj) )
307 continue;
308 if ( Aig_ObjIsNode(pObj) )
309 {
310 pCutBest = If_ObjCutBest( pIfObj );
311 nLeaves = If_CutLeaveNum( pCutBest );
312 ppLeaves = If_CutLeaves( pCutBest );
313 // create node
314 pObjNew = Nwk_ManCreateNode( pNtk, nLeaves, pIfObj->nRefs );
315 for ( k = 0; k < nLeaves; k++ )
316 {
317 pObjRepr = (Aig_Obj_t *)Vec_PtrEntry( vIfToAig, ppLeaves[k] );
318 Nwk_ObjAddFanin( pObjNew, (Nwk_Obj_t *)pObjRepr->pData );
319 }
320 // get the functionality
321 pObjNew->pFunc = Nwk_NodeIfToHop( pNtk->pManHop, pIfMan, pIfObj );
322 }
323 else if ( Aig_ObjIsCi(pObj) )
324 pObjNew = Nwk_ManCreateCi( pNtk, pIfObj->nRefs );
325 else if ( Aig_ObjIsCo(pObj) )
326 {
327 pObjNew = Nwk_ManCreateCo( pNtk );
328 pObjNew->fInvert = Aig_ObjFaninC0(pObj);
329 Nwk_ObjAddFanin( pObjNew, (Nwk_Obj_t *)Aig_ObjFanin0(pObj)->pData );
330//printf( "%d ", pObjNew->Id );
331 }
332 else if ( Aig_ObjIsConst1(pObj) )
333 {
334 pObjNew = Nwk_ManCreateNode( pNtk, 0, pIfObj->nRefs );
335 pObjNew->pFunc = Hop_ManConst1( pNtk->pManHop );
336 }
337 else
338 assert( 0 );
339 pObj->pData = pObjNew;
340 }
341//printf( "\n" );
342 Vec_PtrFree( vIfToAig );
343 pNtk->pManTime = Tim_ManDup( pIfMan->pManTim, 0 );
344 Nwk_ManMinimumBase( pNtk, 0 );
345 assert( Nwk_ManCheck( pNtk ) );
346 return pNtk;
347}
348
361{
362 Nwk_Man_t * pNtk;
363 If_Man_t * pIfMan;
364 Vec_Ptr_t * vAigToIf;
365 // set the arrival times
366 pPars->pTimesArr = ABC_ALLOC( float, Aig_ManCiNum(p) );
367 memset( pPars->pTimesArr, 0, sizeof(float) * Aig_ManCiNum(p) );
368 // translate into the mapper
369 vAigToIf = Vec_PtrStart( Aig_ManObjNumMax(p) );
370 pIfMan = Nwk_ManToIf( p, pPars, vAigToIf );
371 if ( pIfMan == NULL )
372 return NULL;
373 pIfMan->pManTim = Tim_ManDup( pManTime, 0 );
374 pIfMan->pPars->fCutMin = 0; // is not compatible with deriving result
375 if ( !If_ManPerformMapping( pIfMan ) )
376 {
377 If_ManStop( pIfMan );
378 return NULL;
379 }
380 // transform the result of mapping into the new network
381 pNtk = Nwk_ManFromIf( pIfMan, p, vAigToIf );
382 if ( pPars->fBidec && pPars->nLutSize <= 8 )
383 Nwk_ManBidecResyn( pNtk, 0 );
384 If_ManStop( pIfMan );
385 Vec_PtrFree( vAigToIf );
386 return pNtk;
387}
388
389
393
394
396
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_ManSetRegNum(Aig_Man_t *p, int nRegs)
Definition aigMan.c:438
#define Aig_ManForEachObj(p, pObj, i)
Definition aig.h:403
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
void Aig_ManCleanData(Aig_Man_t *p)
Definition aigUtil.c:205
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
Vec_Int_t * Saig_ManComputeSwitchProbs(Aig_Man_t *pAig, int nFrames, int nPref, int fProbOne)
Definition giaSwitch.c:711
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
void If_ManCleanCutData(If_Man_t *p)
Definition ifUtil.c:64
void If_ManCreateChoice(If_Man_t *p, If_Obj_t *pRepr)
Definition ifMan.c:460
If_Obj_t * If_ManCreateCo(If_Man_t *p, If_Obj_t *pDriver)
Definition ifMan.c:356
struct If_Par_t_ If_Par_t
Definition if.h:78
struct If_Cut_t_ If_Cut_t
Definition if.h:80
If_Obj_t * If_ManCreateAnd(If_Man_t *p, If_Obj_t *pFan0, If_Obj_t *pFan1)
Definition ifMan.c:384
#define If_CutForEachLeaf(p, pCut, pLeaf, i)
Definition if.h:503
void If_ManStop(If_Man_t *p)
Definition ifMan.c:212
int If_ManPerformMapping(If_Man_t *p)
Definition ifCore.c:82
struct If_Man_t_ If_Man_t
BASIC TYPES ///.
Definition if.h:77
If_Man_t * If_ManStart(If_Par_t *pPars)
FUNCTION DEFINITIONS ///.
Definition ifMan.c:50
If_Obj_t * If_ManCreateCi(If_Man_t *p)
Definition ifMan.c:334
struct If_Obj_t_ If_Obj_t
Definition if.h:79
ABC_DLL int Nwk_ManCheck(Nwk_Man_t *p)
DECLARATIONS ///.
Definition nwkCheck.c:45
struct Nwk_Man_t_ Nwk_Man_t
Definition ntlnwk.h:41
ABC_DLL void Nwk_ManBidecResyn(Nwk_Man_t *p, int fVerbose)
Definition nwkBidec.c:129
If_Man_t * Nwk_ManToIf(Aig_Man_t *p, If_Par_t *pPars, Vec_Ptr_t *vAigToIf)
Definition nwkMap.c:103
Hop_Obj_t * Nwk_NodeIfToHop2_rec(Hop_Man_t *pHopMan, If_Man_t *pIfMan, If_Obj_t *pIfObj, Vec_Ptr_t *vVisited)
Definition nwkMap.c:188
Nwk_Man_t * Nwk_ManFromIf(If_Man_t *pIfMan, Aig_Man_t *p, Vec_Ptr_t *vAigToIf)
Definition nwkMap.c:275
Nwk_Man_t * Nwk_MappingIf(Aig_Man_t *p, Tim_Man_t *pManTime, If_Par_t *pPars)
Definition nwkMap.c:360
ABC_NAMESPACE_IMPL_START void Nwk_ManSetIfParsDefault(If_Par_t *pPars)
DECLARATIONS ///.
Definition nwkMap.c:46
Hop_Obj_t * Nwk_NodeIfToHop(Hop_Man_t *pHopMan, If_Man_t *pIfMan, If_Obj_t *pIfObj)
Definition nwkMap.c:235
ABC_DLL Nwk_Obj_t * Nwk_ManCreateNode(Nwk_Man_t *pMan, int nFanins, int nFanouts)
Definition nwkObj.c:134
ABC_DLL Nwk_Obj_t * Nwk_ManCreateCi(Nwk_Man_t *pMan, int nFanouts)
Definition nwkObj.c:70
ABC_DLL Nwk_Obj_t * Nwk_ManCreateCo(Nwk_Man_t *pMan)
Definition nwkObj.c:92
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition nwk.h:49
ABC_DLL Nwk_Man_t * Nwk_ManAlloc()
DECLARATIONS ///.
Definition nwkMan.c:45
ABC_DLL void Nwk_ObjAddFanin(Nwk_Obj_t *pObj, Nwk_Obj_t *pFanin)
Definition nwkFanio.c:165
ABC_DLL void Nwk_ManMinimumBase(Nwk_Man_t *pNtk, int fVerbose)
Definition nwkUtil.c:563
int Id
Definition aig.h:85
void * pData
Definition aig.h:87
unsigned nLeaves
Definition if.h:316
int nLevelMax
Definition if.h:211
If_Par_t * pPars
Definition if.h:201
Vec_Int_t * vSwitching
Definition if.h:225
Vec_Ptr_t * vTemp
Definition if.h:208
Tim_Man_t * pManTim
Definition if.h:289
int nRefs
Definition if.h:346
unsigned fPhase
Definition if.h:336
If_Obj_t * pFanin1
Definition if.h:350
If_Obj_t * pFanin0
Definition if.h:349
unsigned Level
Definition if.h:343
unsigned fCompl1
Definition if.h:335
unsigned fCompl0
Definition if.h:334
int Id
Definition if.h:344
If_Obj_t * pEquiv
Definition if.h:351
float * pTimesArr
Definition if.h:176
int fLatchPaths
Definition if.h:121
float Epsilon
Definition if.h:111
int fTruth
Definition if.h:160
int fPower
Definition if.h:124
int nLutSize
Definition if.h:104
int fExpRed
Definition if.h:120
int nLatchesCo
Definition if.h:167
int fEdge
Definition if.h:123
int nFlowIters
Definition if.h:106
int nAreaIters
Definition if.h:107
int fLiftLeaves
Definition if.h:170
int fBidec
Definition if.h:131
int nCutsMax
Definition if.h:105
int fVerbose
Definition if.h:152
float DelayTarget
Definition if.h:110
int fCutMin
Definition if.h:125
int fPreprocess
Definition if.h:117
If_LibLut_t * pLutLib
Definition if.h:175
int nLatchesCi
Definition if.h:166
int fFancy
Definition if.h:119
int(* pFuncCost)(If_Man_t *, If_Cut_t *)
Definition if.h:178
int fArea
Definition if.h:118
Tim_Man_t * pManTime
Definition nwk.h:74
char * pName
Definition nwk.h:64
Hop_Man_t * pManHop
Definition nwk.h:73
char * pSpec
Definition nwk.h:65
typedefABC_NAMESPACE_HEADER_START struct Tim_Man_t_ Tim_Man_t
INCLUDES ///.
Definition tim.h:92
Tim_Man_t * Tim_ManDup(Tim_Man_t *p, int fUnitDelay)
Definition timMan.c:86
#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