ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ifMap.c
Go to the documentation of this file.
1
20
21#include "if.h"
22#include "misc/extra/extra.h"
23
25
29
30extern char * Dau_DsdMerge( char * pDsd0i, int * pPerm0, char * pDsd1i, int * pPerm1, int fCompl0, int fCompl1, int nVars );
31extern int If_CutDelayRecCost3( If_Man_t* p, If_Cut_t* pCut, If_Obj_t * pObj );
32extern int Abc_ExactDelayCost( word * pTruth, int nVars, int * pArrTimeProfile, char * pPerm, int * Cost, int AigLevel );
33
37
51{
52 int Delay0, Delay1;
53 if ( pObj->fVisit )
54 return pObj->iCopy;
55 if ( If_ObjIsCi(pObj) || If_ObjIsConst1(pObj) )
56 return -1;
57 // store the node in the structure by level
58 assert( If_ObjIsAnd(pObj) );
59 pObj->fVisit = 1;
60 Vec_PtrPush( vVisited, pObj );
61 Delay0 = If_ManCutAigDelay_rec( p, pObj->pFanin0, vVisited );
62 Delay1 = If_ManCutAigDelay_rec( p, pObj->pFanin1, vVisited );
63 pObj->iCopy = (Delay0 >= 0 && Delay1 >= 0) ? 1 + Abc_MaxInt(Delay0, Delay1) : -1;
64 return pObj->iCopy;
65}
67{
68 If_Obj_t * pLeaf;
69 int i, Delay;
70 Vec_PtrClear( p->vVisited );
71 If_CutForEachLeaf( p, pCut, pLeaf, i )
72 {
73 assert( pLeaf->fVisit == 0 );
74 pLeaf->fVisit = 1;
75 Vec_PtrPush( p->vVisited, pLeaf );
76 pLeaf->iCopy = If_ObjCutBest(pLeaf)->Delay;
77 }
78 Delay = If_ManCutAigDelay_rec( p, pObj, p->vVisited );
79 Vec_PtrForEachEntry( If_Obj_t *, p->vVisited, pLeaf, i )
80 pLeaf->fVisit = 0;
81// assert( Delay <= (int)pObj->Level );
82 return Delay;
83}
84
96static inline int If_WordCountOnes( unsigned uWord )
97{
98 uWord = (uWord & 0x55555555) + ((uWord>>1) & 0x55555555);
99 uWord = (uWord & 0x33333333) + ((uWord>>2) & 0x33333333);
100 uWord = (uWord & 0x0F0F0F0F) + ((uWord>>4) & 0x0F0F0F0F);
101 uWord = (uWord & 0x00FF00FF) + ((uWord>>8) & 0x00FF00FF);
102 return (uWord & 0x0000FFFF) + (uWord>>16);
103}
104
116float If_CutDelaySpecial( If_Man_t * p, If_Cut_t * pCut, int fCarry )
117{
118 static float Pin2Pin[2][3] = { {1.0, 1.0, 1.0}, {1.0, 1.0, 0.0} };
119 If_Obj_t * pLeaf;
120 float DelayCur, Delay = -IF_FLOAT_LARGE;
121 int i;
122 assert( pCut->nLeaves <= 3 );
123 If_CutForEachLeaf( p, pCut, pLeaf, i )
124 {
125 DelayCur = If_ObjCutBest(pLeaf)->Delay;
126 Delay = IF_MAX( Delay, Pin2Pin[fCarry][i] + DelayCur );
127 }
128 return Delay;
129}
130
144{
145 int i;
146 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
147 p->pArrTimeProfile[i] = (int)If_ObjCutBest(If_CutLeaf(p, pCut, i))->Delay;
148 return p->pArrTimeProfile;
149}
150
162void If_ObjPerformMappingAnd( If_Man_t * p, If_Obj_t * pObj, int Mode, int fPreprocess, int fFirst )
163{
164 If_Set_t * pCutSet;
165 If_Cut_t * pCut0, * pCut1, * pCut;
166 If_Cut_t * pCut0R, * pCut1R;
167 int fFunc0R, fFunc1R;
168 int i, k, v, iCutDsd, fChange;
169 int fSave0 = p->pPars->fDelayOpt || p->pPars->fDelayOptLut || p->pPars->fDsdBalance || p->pPars->fUserRecLib || p->pPars->fUserSesLib || p->pPars->fUserLutDec || p->pPars->fUserLut2D ||
170 p->pPars->fUseDsdTune || p->pPars->fUseCofVars || p->pPars->fUseAndVars || p->pPars->fUse34Spec || p->pPars->pLutStruct || p->pPars->pFuncCell2 || p->pPars->fUseCheck1 || p->pPars->fUseCheck2;
171 int fUseAndCut = (p->pPars->nAndDelay > 0) || (p->pPars->nAndArea > 0);
172 assert( !If_ObjIsAnd(pObj->pFanin0) || pObj->pFanin0->pCutSet->nCuts > 0 );
173 assert( !If_ObjIsAnd(pObj->pFanin1) || pObj->pFanin1->pCutSet->nCuts > 0 );
174
175 // prepare
176 if ( Mode == 0 )
177 pObj->EstRefs = (float)pObj->nRefs;
178 else if ( Mode == 1 )
179 pObj->EstRefs = (float)((2.0 * pObj->EstRefs + pObj->nRefs) / 3.0);
180 // deref the selected cut
181 if ( Mode && pObj->nRefs > 0 )
182 If_CutAreaDeref( p, If_ObjCutBest(pObj) );
183
184 // prepare the cutset
185 pCutSet = If_ManSetupNodeCutSet( p, pObj );
186
187 // get the current assigned best cut
188 pCut = If_ObjCutBest(pObj);
189 if ( !fFirst )
190 {
191 // recompute the parameters of the best cut
192 if ( p->pPars->fDelayOpt )
193 pCut->Delay = If_CutSopBalanceEval( p, pCut, NULL );
194 else if ( p->pPars->fDsdBalance )
195 pCut->Delay = If_CutDsdBalanceEval( p, pCut, NULL );
196 else if ( p->pPars->fUserRecLib )
197 pCut->Delay = If_CutDelayRecCost3( p, pCut, pObj );
198 else if ( p->pPars->fUserSesLib )
199 {
200 int Cost = 0;
201 pCut->fUser = 1;
202 pCut->Delay = (float)Abc_ExactDelayCost( If_CutTruthW(p, pCut), If_CutLeaveNum(pCut), If_CutArrTimeProfile(p, pCut), If_CutPerm(pCut), &Cost, If_ManCutAigDelay(p, pObj, pCut) );
203 if ( Cost == ABC_INFINITY )
204 {
205 for ( v = 0; v < If_CutLeaveNum(pCut); v++ )
206 If_CutPerm(pCut)[v] = IF_BIG_CHAR;
207 pCut->Cost = IF_COST_MAX;
208 pCut->fUseless = 1;
209 }
210 }
211 else if ( p->pPars->fUserLutDec || p->pPars->fUserLut2D )
212 {
213 pCut->Delay = If_LutDecReEval( p, pCut );
214 }
215 else if ( p->pPars->fDelayOptLut )
216 pCut->Delay = If_CutLutBalanceEval( p, pCut );
217 else if( p->pPars->nGateSize > 0 )
218 pCut->Delay = If_CutDelaySop( p, pCut );
219 else
220 pCut->Delay = If_CutDelay( p, pObj, pCut );
221 assert( pCut->Delay != -1 );
222// assert( pCut->Delay <= pObj->Required + p->fEpsilon );
223 if ( pCut->Delay > pObj->Required + 2*p->fEpsilon )
224 Abc_Print( 1, "If_ObjPerformMappingAnd(): Warning! Node with ID %d has delay (%f) exceeding the required times (%f).\n",
225 pObj->Id, pCut->Delay, pObj->Required + p->fEpsilon );
226 pCut->Area = (Mode == 2)? If_CutAreaDerefed( p, pCut ) : If_CutAreaFlow( p, pCut );
227 if ( p->pPars->fEdge )
228 pCut->Edge = (Mode == 2)? If_CutEdgeDerefed( p, pCut ) : If_CutEdgeFlow( p, pCut );
229 if ( p->pPars->fPower )
230 pCut->Power = (Mode == 2)? If_CutPowerDerefed( p, pCut, pObj ) : If_CutPowerFlow( p, pCut, pObj );
231 // save the best cut from the previous iteration
232 if ( !fPreprocess || pCut->nLeaves <= 1 )
233 If_CutCopy( p, pCutSet->ppCuts[pCutSet->nCuts++], pCut );
234 }
235
236 // generate cuts
237 If_ObjForEachCut( pObj->pFanin0, pCut0, i )
238 If_ObjForEachCut( pObj->pFanin1, pCut1, k )
239 {
240 // get the next free cut
241 assert( pCutSet->nCuts <= pCutSet->nCutsMax );
242 pCut = pCutSet->ppCuts[pCutSet->nCuts];
243 // make sure K-feasible cut exists
244 if ( If_WordCountOnes(pCut0->uSign | pCut1->uSign) > p->pPars->nLutSize )
245 continue;
246
247 pCut0R = pCut0;
248 pCut1R = pCut1;
249 fFunc0R = pCut0->iCutFunc ^ pCut0->fCompl ^ pObj->fCompl0;
250 fFunc1R = pCut1->iCutFunc ^ pCut1->fCompl ^ pObj->fCompl1;
251 if ( !p->pPars->fUseTtPerm || pCut0->nLeaves > pCut1->nLeaves || (pCut0->nLeaves == pCut1->nLeaves && fFunc0R > fFunc1R) )
252 {
253 }
254 else
255 {
256 ABC_SWAP( If_Cut_t *, pCut0R, pCut1R );
257 ABC_SWAP( int, fFunc0R, fFunc1R );
258 }
259
260 // merge the cuts
261 if ( p->pPars->fUseTtPerm )
262 {
263 if ( !If_CutMerge( p, pCut0R, pCut1R, pCut ) )
264 continue;
265 }
266 else
267 {
268 if ( !If_CutMergeOrdered( p, pCut0, pCut1, pCut ) )
269 continue;
270 }
271 if ( p->pPars->fUserLutDec && !fFirst && pCut->nLeaves > p->pPars->nLutDecSize )
272 continue;
273 if ( pObj->fSpec && pCut->nLeaves == (unsigned)p->pPars->nLutSize )
274 continue;
275 p->nCutsMerged++;
276 p->nCutsTotal++;
277 // check if this cut is contained in any of the available cuts
278 if ( !p->pPars->fSkipCutFilter && If_CutFilter( pCutSet, pCut, fSave0 ) )
279 continue;
280 // check if the cut is a special AND-gate cut
281 pCut->fAndCut = fUseAndCut && pCut->nLeaves == 2 && pCut->pLeaves[0] == pObj->pFanin0->Id && pCut->pLeaves[1] == pObj->pFanin1->Id;
282 //assert( pCut->nLeaves != 2 || pCut->pLeaves[0] < pCut->pLeaves[1] );
283 //assert( pCut->nLeaves != 2 || pObj->pFanin0->Id < pObj->pFanin1->Id );
284 // compute the truth table
285 pCut->iCutFunc = -1;
286 pCut->fCompl = 0;
287 if ( p->pPars->fTruth )
288 {
289// int nShared = pCut0->nLeaves + pCut1->nLeaves - pCut->nLeaves;
290 abctime clk = 0;
291 if ( p->pPars->fVerbose )
292 clk = Abc_Clock();
293 if ( p->pPars->fUseTtPerm )
294 fChange = If_CutComputeTruthPerm( p, pCut, pCut0R, pCut1R, fFunc0R, fFunc1R );
295 else
296 fChange = If_CutComputeTruth( p, pCut, pCut0, pCut1, pObj->fCompl0, pObj->fCompl1 );
297 if ( p->pPars->fVerbose )
298 p->timeCache[4] += Abc_Clock() - clk;
299 if ( !p->pPars->fSkipCutFilter && fChange && If_CutFilter( pCutSet, pCut, fSave0 ) )
300 continue;
301 if ( p->pPars->fLut6Filter && pCut->nLeaves == 6 && !If_CutCheckTruth6(p, pCut) )
302 continue;
303 if ( p->pPars->fUseDsd )
304 {
305 extern void If_ManCacheRecord( If_Man_t * p, int iDsd0, int iDsd1, int nShared, int iDsd );
306 int truthId = Abc_Lit2Var(pCut->iCutFunc);
307 if ( truthId >= Vec_IntSize(p->vTtDsds[pCut->nLeaves]) || Vec_IntEntry(p->vTtDsds[pCut->nLeaves], truthId) == -1 )
308 {
309 while ( truthId >= Vec_IntSize(p->vTtDsds[pCut->nLeaves]) )
310 {
311 Vec_IntPush( p->vTtDsds[pCut->nLeaves], -1 );
312 for ( v = 0; v < Abc_MaxInt(6, pCut->nLeaves); v++ )
313 Vec_StrPush( p->vTtPerms[pCut->nLeaves], IF_BIG_CHAR );
314 }
315 iCutDsd = If_DsdManCompute( p->pIfDsdMan, If_CutTruthWR(p, pCut), pCut->nLeaves, (unsigned char *)If_CutDsdPerm(p, pCut), p->pPars->pLutStruct );
316 Vec_IntWriteEntry( p->vTtDsds[pCut->nLeaves], truthId, iCutDsd );
317 }
318 assert( If_DsdManSuppSize(p->pIfDsdMan, If_CutDsdLit(p, pCut)) == (int)pCut->nLeaves );
319 //If_ManCacheRecord( p, If_CutDsdLit(p, pCut0), If_CutDsdLit(p, pCut1), nShared, If_CutDsdLit(p, pCut) );
320 }
321 // run user functions
322 pCut->fUseless = 0;
323 if ( p->pPars->pFuncCell || p->pPars->pFuncCell2 )
324 {
325 assert( p->pPars->fUseTtPerm == 0 );
326 assert( pCut->nLimit >= 4 && pCut->nLimit <= 16 );
327 if ( p->pPars->fUseDsd )
328 pCut->fUseless = If_DsdManCheckDec( p->pIfDsdMan, If_CutDsdLit(p, pCut) );
329 else if ( p->pPars->pFuncCell2 )
330 pCut->fUseless = !p->pPars->pFuncCell2( p, (word *)If_CutTruthW(p, pCut), pCut->nLeaves, NULL, NULL );
331 else
332 pCut->fUseless = !p->pPars->pFuncCell( p, If_CutTruth(p, pCut), Abc_MaxInt(6, pCut->nLeaves), pCut->nLeaves, p->pPars->pLutStruct );
333 p->nCutsUselessAll += pCut->fUseless;
334 p->nCutsUseless[pCut->nLeaves] += pCut->fUseless;
335 p->nCutsCountAll++;
336 p->nCutsCount[pCut->nLeaves]++;
337 // skip 5-input cuts, which cannot be decomposed
338 if ( (p->pPars->fEnableCheck75 || p->pPars->fEnableCheck75u) && pCut->nLeaves == 5 && pCut->nLimit == 5 )
339 {
340 extern int If_CluCheckDecInAny( word t, int nVars );
341 extern int If_CluCheckDecOut( word t, int nVars );
342 unsigned TruthU = *If_CutTruth(p, pCut);
343 word Truth = (((word)TruthU << 32) | (word)TruthU);
344 p->nCuts5++;
345 if ( If_CluCheckDecInAny( Truth, 5 ) )
346 p->nCuts5a++;
347 else
348 continue;
349 }
350 else if ( p->pPars->fVerbose && pCut->nLeaves == 5 )
351 {
352 extern int If_CluCheckDecInAny( word t, int nVars );
353 extern int If_CluCheckDecOut( word t, int nVars );
354 unsigned TruthU = *If_CutTruth(p, pCut);
355 word Truth = (((word)TruthU << 32) | (word)TruthU);
356 p->nCuts5++;
357 if ( If_CluCheckDecInAny( Truth, 5 ) || If_CluCheckDecOut( Truth, 5 ) )
358 p->nCuts5a++;
359 }
360 }
361 else if ( p->pPars->fUseDsdTune )
362 {
363 pCut->fUseless = If_DsdManReadMark( p->pIfDsdMan, If_CutDsdLit(p, pCut) );
364 p->nCutsUselessAll += pCut->fUseless;
365 p->nCutsUseless[pCut->nLeaves] += pCut->fUseless;
366 p->nCutsCountAll++;
367 p->nCutsCount[pCut->nLeaves]++;
368 }
369 else if ( p->pPars->fUse34Spec )
370 {
371 assert( pCut->nLeaves <= 4 );
372 if ( pCut->nLeaves == 4 && !Abc_Tt4Check( (int)(0xFFFF & *If_CutTruth(p, pCut)) ) )
373 pCut->fUseless = 1;
374 }
375 else
376 {
377 if ( p->pPars->fUseAndVars )
378 {
379 int iDecMask = -1, truthId = Abc_Lit2Var(pCut->iCutFunc);
380 assert( p->pPars->nLutSize <= 13 );
381 if ( truthId >= Vec_IntSize(p->vTtDecs[pCut->nLeaves]) || Vec_IntEntry(p->vTtDecs[pCut->nLeaves], truthId) == -1 )
382 {
383 while ( truthId >= Vec_IntSize(p->vTtDecs[pCut->nLeaves]) )
384 Vec_IntPush( p->vTtDecs[pCut->nLeaves], -1 );
385 if ( (int)pCut->nLeaves > p->pPars->nLutSize / 2 && (int)pCut->nLeaves <= 2 * (p->pPars->nLutSize / 2) )
386 iDecMask = Abc_TtProcessBiDec( If_CutTruthWR(p, pCut), (int)pCut->nLeaves, p->pPars->nLutSize / 2 );
387 else
388 iDecMask = 0;
389 Vec_IntWriteEntry( p->vTtDecs[pCut->nLeaves], truthId, iDecMask );
390 }
391 iDecMask = Vec_IntEntry(p->vTtDecs[pCut->nLeaves], truthId);
392 assert( iDecMask >= 0 );
393 pCut->fUseless = (int)(iDecMask == 0 && (int)pCut->nLeaves > p->pPars->nLutSize / 2);
394 p->nCutsUselessAll += pCut->fUseless;
395 p->nCutsUseless[pCut->nLeaves] += pCut->fUseless;
396 p->nCutsCountAll++;
397 p->nCutsCount[pCut->nLeaves]++;
398 }
399 if ( p->pPars->fUseCofVars && (!p->pPars->fUseAndVars || pCut->fUseless) )
400 {
401 int iCofVar = -1, truthId = Abc_Lit2Var(pCut->iCutFunc);
402 if ( truthId >= Vec_StrSize(p->vTtVars[pCut->nLeaves]) || Vec_StrEntry(p->vTtVars[pCut->nLeaves], truthId) == (char)-1 )
403 {
404 while ( truthId >= Vec_StrSize(p->vTtVars[pCut->nLeaves]) )
405 Vec_StrPush( p->vTtVars[pCut->nLeaves], (char)-1 );
406 iCofVar = Abc_TtCheckCondDep( If_CutTruthWR(p, pCut), pCut->nLeaves, p->pPars->nLutSize / 2 );
407 Vec_StrWriteEntry( p->vTtVars[pCut->nLeaves], truthId, (char)iCofVar );
408 }
409 iCofVar = Vec_StrEntry(p->vTtVars[pCut->nLeaves], truthId);
410 assert( iCofVar >= 0 && iCofVar <= (int)pCut->nLeaves );
411 pCut->fUseless = (int)(iCofVar == (int)pCut->nLeaves && pCut->nLeaves > 0);
412 p->nCutsUselessAll += pCut->fUseless;
413 p->nCutsUseless[pCut->nLeaves] += pCut->fUseless;
414 p->nCutsCountAll++;
415 p->nCutsCount[pCut->nLeaves]++;
416 }
417 }
418 }
419
420 // compute the application-specific cost and depth
421 pCut->fUser = (p->pPars->pFuncCost != NULL);
422 pCut->Cost = p->pPars->pFuncCost? p->pPars->pFuncCost(p, pCut) : 0;
423 if ( pCut->Cost == IF_COST_MAX )
424 continue;
425 // check if the cut satisfies the required times
426 if ( p->pPars->fDelayOpt )
427 pCut->Delay = If_CutSopBalanceEval( p, pCut, NULL );
428 else if ( p->pPars->fDsdBalance )
429 pCut->Delay = If_CutDsdBalanceEval( p, pCut, NULL );
430 else if ( p->pPars->fUserRecLib )
431 pCut->Delay = If_CutDelayRecCost3( p, pCut, pObj );
432 else if ( p->pPars->fUserLutDec )
433 {
434 pCut->Delay = If_LutDecEval( p, pCut, pObj, Mode == 0, fFirst );
435 pCut->fUseless = pCut->Delay == ABC_INFINITY;
436 }
437 else if ( p->pPars->fUserLut2D )
438 {
439 pCut->Delay = If_Lut2DecEval( p, pCut, pObj, Mode == 0, fFirst );
440 pCut->fUseless = pCut->Delay == ABC_INFINITY;
441 }
442 else if ( p->pPars->fUserSesLib )
443 {
444 int Cost = 0;
445 pCut->fUser = 1;
446 pCut->Delay = (float)Abc_ExactDelayCost( If_CutTruthW(p, pCut), If_CutLeaveNum(pCut), If_CutArrTimeProfile(p, pCut), If_CutPerm(pCut), &Cost, If_ManCutAigDelay(p, pObj, pCut) );
447 if ( Cost == ABC_INFINITY )
448 {
449 for ( v = 0; v < If_CutLeaveNum(pCut); v++ )
450 If_CutPerm(pCut)[v] = IF_BIG_CHAR;
451 pCut->Cost = IF_COST_MAX;
452 pCut->fUseless = 1;
453 }
454 }
455 else if ( p->pPars->fDelayOptLut )
456 pCut->Delay = If_CutLutBalanceEval( p, pCut );
457 else if( p->pPars->nGateSize > 0 )
458 pCut->Delay = If_CutDelaySop( p, pCut );
459 else
460 pCut->Delay = If_CutDelay( p, pObj, pCut );
461 if ( pCut->Delay == -1 )
462 continue;
463 if ( Mode && pCut->Delay > pObj->Required + p->fEpsilon && pCutSet->nCuts > 0 )
464 continue;
465 // compute area of the cut (this area may depend on the application specific cost)
466 pCut->Area = (Mode == 2)? If_CutAreaDerefed( p, pCut ) : If_CutAreaFlow( p, pCut );
467 if ( p->pPars->fEdge )
468 pCut->Edge = (Mode == 2)? If_CutEdgeDerefed( p, pCut ) : If_CutEdgeFlow( p, pCut );
469 if ( p->pPars->fPower )
470 pCut->Power = (Mode == 2)? If_CutPowerDerefed( p, pCut, pObj ) : If_CutPowerFlow( p, pCut, pObj );
471// pCut->AveRefs = (Mode == 0)? (float)0.0 : If_CutAverageRefs( p, pCut );
472 // insert the cut into storage
473 If_CutSort( p, pCutSet, pCut );
474// If_CutTraverse( p, pObj, pCut );
475 }
476 assert( pCutSet->nCuts > 0 );
477// If_CutVerifyCuts( pCutSet, !p->pPars->fUseTtPerm );
478
479 // update the best cut
480 if ( !fPreprocess || pCutSet->ppCuts[0]->Delay <= pObj->Required + p->fEpsilon )
481 {
482 If_CutCopy( p, If_ObjCutBest(pObj), pCutSet->ppCuts[0] );
483 if ( p->pPars->fUserRecLib || p->pPars->fUserSesLib )
484 assert(If_ObjCutBest(pObj)->Cost < IF_COST_MAX && If_ObjCutBest(pObj)->Delay < ABC_INFINITY);
485 }
486 // add the trivial cut to the set
487 if ( !pObj->fSkipCut && If_ObjCutBest(pObj)->nLeaves > 1 )
488 {
489 If_ManSetupCutTriv( p, pCutSet->ppCuts[pCutSet->nCuts++], pObj->Id );
490 assert( pCutSet->nCuts <= pCutSet->nCutsMax+1 );
491 }
492// if ( If_ObjCutBest(pObj)->nLeaves == 0 )
493// p->nBestCutSmall[0]++;
494// else if ( If_ObjCutBest(pObj)->nLeaves == 1 )
495// p->nBestCutSmall[1]++;
496
497 // ref the selected cut
498 if ( Mode && pObj->nRefs > 0 )
499 If_CutAreaRef( p, If_ObjCutBest(pObj) );
500 if ( If_ObjCutBest(pObj)->fUseless )
501 Abc_Print( 1, "The best cut is useless.\n" );
502 // call the user specified function for each cut
503 if ( p->pPars->pFuncUser )
504 If_ObjForEachCut( pObj, pCut, i )
505 p->pPars->pFuncUser( p, pObj, pCut );
506 // free the cuts
507 If_ManDerefNodeCutSet( p, pObj );
508}
509
521void If_ObjPerformMappingChoice( If_Man_t * p, If_Obj_t * pObj, int Mode, int fPreprocess )
522{
523 If_Set_t * pCutSet;
524 If_Obj_t * pTemp;
525 If_Cut_t * pCutTemp, * pCut;
526 int i, fSave0 = p->pPars->fDelayOpt || p->pPars->fDelayOptLut || p->pPars->fDsdBalance || p->pPars->fUserRecLib || p->pPars->fUserSesLib || p->pPars->fUse34Spec || p->pPars->fUserLutDec || p->pPars->fUserLut2D;
527 assert( pObj->pEquiv != NULL );
528
529 // prepare
530 if ( Mode && pObj->nRefs > 0 )
531 If_CutAreaDeref( p, If_ObjCutBest(pObj) );
532
533 // remove elementary cuts
534 for ( pTemp = pObj; pTemp; pTemp = pTemp->pEquiv )
535 if ( pTemp != pObj || pTemp->pCutSet->nCuts > 1 )
536 pTemp->pCutSet->nCuts--;
537
538 // update the cutset of the node
539 pCutSet = pObj->pCutSet;
540
541 // generate cuts
542 for ( pTemp = pObj->pEquiv; pTemp; pTemp = pTemp->pEquiv )
543 {
544 if ( pTemp->pCutSet->nCuts == 0 )
545 continue;
546 // go through the cuts of this node
547 If_ObjForEachCut( pTemp, pCutTemp, i )
548 {
549 if ( pCutTemp->fUseless )
550 continue;
551 // get the next free cut
552 assert( pCutSet->nCuts <= pCutSet->nCutsMax );
553 pCut = pCutSet->ppCuts[pCutSet->nCuts];
554 // copy the cut into storage
555 If_CutCopy( p, pCut, pCutTemp );
556 // check if this cut is contained in any of the available cuts
557 if ( If_CutFilter( pCutSet, pCut, fSave0 ) )
558 continue;
559 // check if the cut satisfies the required times
560// assert( pCut->Delay == If_CutDelay( p, pTemp, pCut ) );
561 if ( Mode && pCut->Delay > pObj->Required + p->fEpsilon && pCutSet->nCuts > 0 )
562 continue;
563 // set the phase attribute
564 pCut->fCompl = pObj->fPhase ^ pTemp->fPhase;
565 // compute area of the cut (this area may depend on the application specific cost)
566 pCut->Area = (Mode == 2)? If_CutAreaDerefed( p, pCut ) : If_CutAreaFlow( p, pCut );
567 if ( p->pPars->fEdge )
568 pCut->Edge = (Mode == 2)? If_CutEdgeDerefed( p, pCut ) : If_CutEdgeFlow( p, pCut );
569 if ( p->pPars->fPower )
570 pCut->Power = (Mode == 2)? If_CutPowerDerefed( p, pCut, pObj ) : If_CutPowerFlow( p, pCut, pObj );
571// pCut->AveRefs = (Mode == 0)? (float)0.0 : If_CutAverageRefs( p, pCut );
572 // insert the cut into storage
573 If_CutSort( p, pCutSet, pCut );
574 }
575 }
576 assert( pCutSet->nCuts > 0 );
577
578 // update the best cut
579 if ( !fPreprocess || pCutSet->ppCuts[0]->Delay <= pObj->Required + p->fEpsilon )
580 If_CutCopy( p, If_ObjCutBest(pObj), pCutSet->ppCuts[0] );
581 // add the trivial cut to the set
582 if ( !pObj->fSkipCut && If_ObjCutBest(pObj)->nLeaves > 1 )
583 {
584 If_ManSetupCutTriv( p, pCutSet->ppCuts[pCutSet->nCuts++], pObj->Id );
585 assert( pCutSet->nCuts <= pCutSet->nCutsMax+1 );
586 }
587
588 // ref the selected cut
589 if ( Mode && pObj->nRefs > 0 )
590 If_CutAreaRef( p, If_ObjCutBest(pObj) );
591 // free the cuts
592 If_ManDerefChoiceCutSet( p, pObj );
593}
594
606int If_ManPerformMappingRound( If_Man_t * p, int nCutsUsed, int Mode, int fPreprocess, int fFirst, char * pLabel )
607{
608 ProgressBar * pProgress = NULL;
609 If_Obj_t * pObj;
610 int i;
611 abctime clk = Abc_Clock();
612 float arrTime;
613 assert( Mode >= 0 && Mode <= 2 );
614 p->nBestCutSmall[0] = p->nBestCutSmall[1] = 0;
615 // set the sorting function
616 if ( Mode || p->pPars->fArea ) // area
617 p->SortMode = 1;
618 else if ( p->pPars->fFancy )
619 p->SortMode = 2;
620 else
621 p->SortMode = 0;
622 // set the cut number
623 p->nCutsUsed = nCutsUsed;
624 p->nCutsMerged = 0;
625 // make sure the visit counters are all zero
626 If_ManForEachNode( p, pObj, i )
627 assert( pObj->nVisits == pObj->nVisitsCopy );
628 // map the internal nodes
629 if ( p->pManTim != NULL )
630 {
631 Tim_ManIncrementTravId( p->pManTim );
632 If_ManForEachObj( p, pObj, i )
633 {
634 if ( If_ObjIsAnd(pObj) )
635 {
636 If_ObjPerformMappingAnd( p, pObj, Mode, fPreprocess, fFirst );
637 if ( pObj->fRepr )
638 If_ObjPerformMappingChoice( p, pObj, Mode, fPreprocess );
639 }
640 else if ( If_ObjIsCi(pObj) )
641 {
642//Abc_Print( 1, "processing CI %d\n", pObj->Id );
643 arrTime = Tim_ManGetCiArrival( p->pManTim, pObj->IdPio );
644 If_ObjSetArrTime( pObj, arrTime );
645 }
646 else if ( If_ObjIsCo(pObj) )
647 {
648 arrTime = If_ObjArrTime( If_ObjFanin0(pObj) );
649 Tim_ManSetCoArrival( p->pManTim, pObj->IdPio, arrTime );
650 }
651 else if ( If_ObjIsConst1(pObj) )
652 {
653 arrTime = -IF_INFINITY;
654 If_ObjSetArrTime( pObj, arrTime );
655 }
656 else
657 assert( 0 );
658 }
659// Tim_ManPrint( p->pManTim );
660 }
661 else
662 {
663 pProgress = Extra_ProgressBarStart( stdout, If_ManObjNum(p) );
664 If_ManForEachNode( p, pObj, i )
665 {
666 Extra_ProgressBarUpdate( pProgress, i, pLabel );
667 If_ObjPerformMappingAnd( p, pObj, Mode, fPreprocess, fFirst );
668 if ( pObj->fRepr )
669 If_ObjPerformMappingChoice( p, pObj, Mode, fPreprocess );
670 }
671 }
672 Extra_ProgressBarStop( pProgress );
673 // make sure the visit counters are all zero
674 If_ManForEachNode( p, pObj, i )
675 assert( pObj->nVisits == 0 );
676 // compute required times and stats
678// Tim_ManPrint( p->pManTim );
679 if ( p->pPars->fVerbose )
680 {
681 char Symb = fPreprocess? 'P' : ((Mode == 0)? 'D' : ((Mode == 1)? 'F' : 'A'));
682 Abc_Print( 1, "%c: Del = %7.2f. Ar = %9.1f. Edge = %8d. ",
683 Symb, p->RequiredGlo, p->AreaGlo, p->nNets );
684 if ( p->dPower )
685 Abc_Print( 1, "Switch = %7.2f. ", p->dPower );
686 Abc_Print( 1, "Cut = %8d. ", p->nCutsMerged );
687 Abc_PrintTime( 1, "T", Abc_Clock() - clk );
688// Abc_Print( 1, "Max number of cuts = %d. Average number of cuts = %5.2f.\n",
689// p->nCutsMax, 1.0 * p->nCutsMerged / If_ManAndNum(p) );
690 }
691 return 1;
692}
693
694
698
699
701
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
Cube * p
Definition exorList.c:222
void Extra_ProgressBarStop(ProgressBar *p)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
ABC_NAMESPACE_IMPL_START void If_ManCacheRecord(If_Man_t *p, int iDsd0, int iDsd1, int nShared, int iDsd)
DECLARATIONS ///.
Definition ifCache.c:45
int If_CluCheckDecInAny(word t, int nVars)
Definition ifDec16.c:1767
int If_CluCheckDecOut(word t, int nVars)
Definition ifDec16.c:1840
int If_ManCutAigDelay_rec(If_Man_t *p, If_Obj_t *pObj, Vec_Ptr_t *vVisited)
FUNCTION DEFINITIONS ///.
Definition ifMap.c:50
float If_CutDelaySpecial(If_Man_t *p, If_Cut_t *pCut, int fCarry)
Definition ifMap.c:116
void If_ObjPerformMappingAnd(If_Man_t *p, If_Obj_t *pObj, int Mode, int fPreprocess, int fFirst)
Definition ifMap.c:162
int Abc_ExactDelayCost(word *pTruth, int nVars, int *pArrTimeProfile, char *pPerm, int *Cost, int AigLevel)
Definition abcExact.c:2716
void If_ObjPerformMappingChoice(If_Man_t *p, If_Obj_t *pObj, int Mode, int fPreprocess)
Definition ifMap.c:521
ABC_NAMESPACE_IMPL_START char * Dau_DsdMerge(char *pDsd0i, int *pPerm0, char *pDsd1i, int *pPerm1, int fCompl0, int fCompl1, int nVars)
DECLARATIONS ///.
Definition dauMerge.c:587
int * If_CutArrTimeProfile(If_Man_t *p, If_Cut_t *pCut)
Definition ifMap.c:143
int If_ManCutAigDelay(If_Man_t *p, If_Obj_t *pObj, If_Cut_t *pCut)
Definition ifMap.c:66
int If_ManPerformMappingRound(If_Man_t *p, int nCutsUsed, int Mode, int fPreprocess, int fFirst, char *pLabel)
Definition ifMap.c:606
int If_CutDelayRecCost3(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pObj)
Definition abcRec3.c:1004
int If_CutMerge(If_Man_t *p, If_Cut_t *pCut0, If_Cut_t *pCut1, If_Cut_t *pCut)
Definition ifCut.c:364
#define If_ManForEachObj(p, pObj, i)
Definition if.h:491
float If_CutAreaDeref(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1056
int If_CutComputeTruthPerm(If_Man_t *p, If_Cut_t *pCut, If_Cut_t *pCut0, If_Cut_t *pCut1, int fCompl0, int fCompl1)
Definition ifTruth.c:269
void If_ManSetupCutTriv(If_Man_t *p, If_Cut_t *pCut, int ObjId)
Definition ifMan.c:517
float If_CutPowerFlow(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pRoot)
Definition ifCut.c:1003
float If_CutEdgeDerefed(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1211
float If_CutDelay(If_Man_t *p, If_Obj_t *pObj, If_Cut_t *pCut)
Definition ifTime.c:91
float If_CutEdgeFlow(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:965
int If_CutFilter(If_Set_t *pCutSet, If_Cut_t *pCut, int fSaveCut0)
Definition ifCut.c:146
struct If_Cut_t_ If_Cut_t
Definition if.h:80
float If_CutAreaRef(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1083
If_Set_t * If_ManSetupNodeCutSet(If_Man_t *p, If_Obj_t *pObj)
Definition ifMan.c:597
int If_DsdManSuppSize(If_DsdMan_t *p, int iDsd)
Definition ifDsd.c:197
float If_CutAreaFlow(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:927
void If_ManDerefChoiceCutSet(If_Man_t *p, If_Obj_t *pObj)
Definition ifMan.c:663
#define IF_COST_MAX
Definition if.h:59
int If_CutLutBalanceEval(If_Man_t *p, If_Cut_t *pCut)
Definition ifDelay.c:369
int If_DsdManCompute(If_DsdMan_t *p, word *pTruth, int nLeaves, unsigned char *pPerm, char *pLutStruct)
Definition ifDsd.c:2063
int If_CutDsdBalanceEval(If_Man_t *p, If_Cut_t *pCut, Vec_Int_t *vAig)
Definition ifDsd.c:2322
int If_CutDelaySop(If_Man_t *p, If_Cut_t *pCut)
Definition ifDelay.c:64
#define IF_BIG_CHAR
Definition if.h:61
int If_LutDecReEval(If_Man_t *p, If_Cut_t *pCut)
Definition ifDelay.c:597
#define IF_FLOAT_LARGE
Definition if.h:469
struct If_Set_t_ If_Set_t
Definition if.h:81
#define If_CutForEachLeaf(p, pCut, pLeaf, i)
Definition if.h:503
void If_ManComputeRequired(If_Man_t *p)
Definition ifTime.c:313
#define IF_MAX(a, b)
Definition if.h:466
int If_DsdManReadMark(If_DsdMan_t *p, int iDsd)
Definition ifDsd.c:205
int If_Lut2DecEval(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pObj, int optDelay, int fFirst)
Definition ifDelay.c:508
void If_CutSort(If_Man_t *p, If_Set_t *pCutSet, If_Cut_t *pCut)
Definition ifCut.c:746
int If_CutCheckTruth6(If_Man_t *p, If_Cut_t *pCut)
Definition ifTruth.c:396
#define If_ObjForEachCut(pObj, pCut, i)
Definition if.h:500
struct If_Man_t_ If_Man_t
BASIC TYPES ///.
Definition if.h:77
void If_ManDerefNodeCutSet(If_Man_t *p, If_Obj_t *pObj)
Definition ifMan.c:620
#define If_ManForEachNode(p, pObj, i)
Definition if.h:497
float If_CutAreaDerefed(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1110
int If_CutSopBalanceEval(If_Man_t *p, If_Cut_t *pCut, Vec_Int_t *vAig)
Definition ifDelay.c:248
int If_CutMergeOrdered(If_Man_t *p, If_Cut_t *pCut0, If_Cut_t *pCut1, If_Cut_t *pCut)
Definition ifCut.c:290
struct If_Obj_t_ If_Obj_t
Definition if.h:79
#define IF_INFINITY
Definition if.h:57
float If_CutPowerDerefed(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pRoot)
Definition ifCut.c:1314
int If_CutComputeTruth(If_Man_t *p, If_Cut_t *pCut, If_Cut_t *pCut0, If_Cut_t *pCut1, int fCompl0, int fCompl1)
Definition ifTruth.c:99
int If_LutDecEval(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pObj, int optDelay, int fFirst)
Definition ifDelay.c:415
int If_DsdManCheckDec(If_DsdMan_t *p, int iDsd)
Definition ifDsd.c:201
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
float Power
Definition if.h:305
unsigned Cost
Definition if.h:310
int pLeaves[0]
Definition if.h:318
unsigned nLeaves
Definition if.h:316
float Delay
Definition if.h:306
unsigned nLimit
Definition if.h:315
unsigned fAndCut
Definition if.h:314
unsigned fUseless
Definition if.h:313
unsigned fCompl
Definition if.h:311
unsigned uSign
Definition if.h:309
float Area
Definition if.h:303
int iCutFunc
Definition if.h:307
unsigned fUser
Definition if.h:312
float Edge
Definition if.h:304
int nRefs
Definition if.h:346
unsigned fPhase
Definition if.h:336
float EstRefs
Definition if.h:352
int IdPio
Definition if.h:345
If_Obj_t * pFanin1
Definition if.h:350
int iCopy
Definition if.h:357
unsigned fVisit
Definition if.h:339
If_Obj_t * pFanin0
Definition if.h:349
int nVisits
Definition if.h:347
unsigned fRepr
Definition if.h:337
unsigned fCompl1
Definition if.h:335
unsigned fSkipCut
Definition if.h:342
unsigned fSpec
Definition if.h:340
int nVisitsCopy
Definition if.h:348
If_Set_t * pCutSet
Definition if.h:360
unsigned fCompl0
Definition if.h:334
float Required
Definition if.h:353
int Id
Definition if.h:344
If_Obj_t * pEquiv
Definition if.h:351
If_Cut_t ** ppCuts
Definition if.h:327
short nCutsMax
Definition if.h:324
short nCuts
Definition if.h:325
void Tim_ManSetCoArrival(Tim_Man_t *p, int iCo, float Delay)
Definition timTime.c:116
void Tim_ManIncrementTravId(Tim_Man_t *p)
DECLARATIONS ///.
Definition timTrav.c:44
float Tim_ManGetCiArrival(Tim_Man_t *p, int iCi)
Definition timTime.c:174
#define assert(ex)
Definition util_old.h:213
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