ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cswCut.c File Reference
#include "cswInt.h"
Include dependency graph for cswCut.c:

Go to the source code of this file.

Functions

unsigned * Csw_CutComputeTruth (Csw_Man_t *p, Csw_Cut_t *pCut, Csw_Cut_t *pCut0, Csw_Cut_t *pCut1, int fCompl0, int fCompl1)
 
int Csw_CutSupportMinimize (Csw_Man_t *p, Csw_Cut_t *pCut)
 
int Csw_CutFilter (Csw_Man_t *p, Aig_Obj_t *pObj, Csw_Cut_t *pCut)
 
int Csw_CutMerge (Csw_Man_t *p, Csw_Cut_t *pCut0, Csw_Cut_t *pCut1, Csw_Cut_t *pCut)
 
Aig_Obj_tCsw_ObjTwoVarCut (Csw_Man_t *p, Csw_Cut_t *pCut)
 
Csw_Cut_tCsw_ObjPrepareCuts (Csw_Man_t *p, Aig_Obj_t *pObj, int fTriv)
 FUNCTION DECLARATIONS ///.
 
Aig_Obj_tCsw_ObjSweep (Csw_Man_t *p, Aig_Obj_t *pObj, int fTriv)
 

Function Documentation

◆ Csw_CutComputeTruth()

unsigned * Csw_CutComputeTruth ( Csw_Man_t * p,
Csw_Cut_t * pCut,
Csw_Cut_t * pCut0,
Csw_Cut_t * pCut1,
int fCompl0,
int fCompl1 )

Function*************************************************************

Synopsis [Performs truth table computation.]

Description []

SideEffects []

SeeAlso []

Definition at line 149 of file cswCut.c.

150{
151 // permute the first table
152 if ( fCompl0 )
153 Kit_TruthNot( p->puTemp[0], Csw_CutTruth(pCut0), p->nLeafMax );
154 else
155 Kit_TruthCopy( p->puTemp[0], Csw_CutTruth(pCut0), p->nLeafMax );
156 Kit_TruthStretch( p->puTemp[2], p->puTemp[0], pCut0->nFanins, p->nLeafMax, Cut_TruthPhase(pCut, pCut0), 0 );
157 // permute the second table
158 if ( fCompl1 )
159 Kit_TruthNot( p->puTemp[1], Csw_CutTruth(pCut1), p->nLeafMax );
160 else
161 Kit_TruthCopy( p->puTemp[1], Csw_CutTruth(pCut1), p->nLeafMax );
162 Kit_TruthStretch( p->puTemp[3], p->puTemp[1], pCut1->nFanins, p->nLeafMax, Cut_TruthPhase(pCut, pCut1), 0 );
163 // produce the resulting table
164 Kit_TruthAnd( Csw_CutTruth(pCut), p->puTemp[2], p->puTemp[3], p->nLeafMax );
165// assert( pCut->nFanins >= Kit_TruthSupportSize( Csw_CutTruth(pCut), p->nLeafMax ) );
166 return Csw_CutTruth(pCut);
167}
Cube * p
Definition exorList.c:222
void Kit_TruthStretch(unsigned *pOut, unsigned *pIn, int nVars, int nVarsAll, unsigned Phase, int fReturnIn)
Definition kitTruth.c:166
char nFanins
Definition cswInt.h:65
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Csw_CutFilter()

int Csw_CutFilter ( Csw_Man_t * p,
Aig_Obj_t * pObj,
Csw_Cut_t * pCut )

Function*************************************************************

Synopsis [Returns 1 if the cut is contained.]

Description []

SideEffects []

SeeAlso []

Definition at line 243 of file cswCut.c.

244{
245 Csw_Cut_t * pTemp;
246 int i;
247 // go through the cuts of the node
248 Csw_ObjForEachCut( p, pObj, pTemp, i )
249 {
250 if ( pTemp->nFanins < 2 )
251 continue;
252 if ( pTemp == pCut )
253 continue;
254 if ( pTemp->nFanins > pCut->nFanins )
255 {
256 // skip the non-contained cuts
257 if ( (pTemp->uSign & pCut->uSign) != pCut->uSign )
258 continue;
259 // check containment seriously
260 if ( Csw_CutCheckDominance( pCut, pTemp ) )
261 {
262 // remove contained cut
263 pTemp->nFanins = 0;
264 }
265 }
266 else
267 {
268 // skip the non-contained cuts
269 if ( (pTemp->uSign & pCut->uSign) != pTemp->uSign )
270 continue;
271 // check containment seriously
272 if ( Csw_CutCheckDominance( pTemp, pCut ) )
273 {
274 // remove the given
275 pCut->nFanins = 0;
276 return 1;
277 }
278 }
279 }
280 return 0;
281}
struct Csw_Cut_t_ Csw_Cut_t
Definition cswInt.h:53
#define Csw_ObjForEachCut(p, pObj, pCut, i)
MACRO DEFINITIONS ///.
Definition cswInt.h:128
unsigned uSign
Definition cswInt.h:61
Here is the caller graph for this function:

◆ Csw_CutMerge()

int Csw_CutMerge ( Csw_Man_t * p,
Csw_Cut_t * pCut0,
Csw_Cut_t * pCut1,
Csw_Cut_t * pCut )

Function*************************************************************

Synopsis [Prepares the object for FPGA mapping.]

Description []

SideEffects []

SeeAlso []

Definition at line 380 of file cswCut.c.

381{
382 assert( p->nLeafMax > 0 );
383 // merge the nodes
384 if ( pCut0->nFanins < pCut1->nFanins )
385 {
386 if ( !Csw_CutMergeOrdered( p, pCut1, pCut0, pCut ) )
387 return 0;
388 }
389 else
390 {
391 if ( !Csw_CutMergeOrdered( p, pCut0, pCut1, pCut ) )
392 return 0;
393 }
394 pCut->uSign = pCut0->uSign | pCut1->uSign;
395 return 1;
396}
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ Csw_CutSupportMinimize()

int Csw_CutSupportMinimize ( Csw_Man_t * p,
Csw_Cut_t * pCut )

Function*************************************************************

Synopsis [Performs support minimization for the truth table.]

Description []

SideEffects []

SeeAlso []

Definition at line 180 of file cswCut.c.

181{
182 unsigned * pTruth;
183 int uSupp, nFansNew, i, k;
184 // get truth table
185 pTruth = Csw_CutTruth( pCut );
186 // get support
187 uSupp = Kit_TruthSupport( pTruth, p->nLeafMax );
188 // get the new support size
189 nFansNew = Kit_WordCountOnes( uSupp );
190 // check if there are redundant variables
191 if ( nFansNew == pCut->nFanins )
192 return nFansNew;
193 assert( nFansNew < pCut->nFanins );
194 // minimize support
195 Kit_TruthShrink( p->puTemp[0], pTruth, nFansNew, p->nLeafMax, uSupp, 1 );
196 for ( i = k = 0; i < pCut->nFanins; i++ )
197 if ( uSupp & (1 << i) )
198 pCut->pFanins[k++] = pCut->pFanins[i];
199 assert( k == nFansNew );
200 pCut->nFanins = nFansNew;
201// assert( nFansNew == Kit_TruthSupportSize( pTruth, p->nLeafMax ) );
202//Extra_PrintBinary( stdout, pTruth, (1<<p->nLeafMax) ); printf( "\n" );
203 return nFansNew;
204}
unsigned Kit_TruthSupport(unsigned *pTruth, int nVars)
Definition kitTruth.c:346
void Kit_TruthShrink(unsigned *pOut, unsigned *pIn, int nVars, int nVarsAll, unsigned Phase, int fReturnIn)
Definition kitTruth.c:200
int pFanins[0]
Definition cswInt.h:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Csw_ObjPrepareCuts()

Csw_Cut_t * Csw_ObjPrepareCuts ( Csw_Man_t * p,
Aig_Obj_t * pObj,
int fTriv )

FUNCTION DECLARATIONS ///.

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 453 of file cswCut.c.

454{
455 Csw_Cut_t * pCutSet, * pCut;
456 int i;
457 // create the cutset of the node
458 pCutSet = (Csw_Cut_t *)Aig_MmFixedEntryFetch( p->pMemCuts );
459 Csw_ObjSetCuts( p, pObj, pCutSet );
460 Csw_ObjForEachCut( p, pObj, pCut, i )
461 {
462 pCut->nFanins = 0;
463 pCut->iNode = pObj->Id;
464 pCut->nCutSize = p->nCutSize;
465 pCut->nLeafMax = p->nLeafMax;
466 }
467 // add unit cut if needed
468 if ( fTriv )
469 {
470 pCut = pCutSet;
471 pCut->Cost = 0;
472 pCut->iNode = pObj->Id;
473 pCut->nFanins = 1;
474 pCut->pFanins[0] = pObj->Id;
475 pCut->uSign = Aig_ObjCutSign( pObj->Id );
476 memset( Csw_CutTruth(pCut), 0xAA, sizeof(unsigned) * p->nTruthWords );
477 }
478 return pCutSet;
479}
char * Aig_MmFixedEntryFetch(Aig_MmFixed_t *p)
Definition aigMem.c:161
int Id
Definition aig.h:85
short nCutSize
Definition cswInt.h:63
char nLeafMax
Definition cswInt.h:64
int iNode
Definition cswInt.h:62
int Cost
Definition cswInt.h:59
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Csw_ObjSweep()

Aig_Obj_t * Csw_ObjSweep ( Csw_Man_t * p,
Aig_Obj_t * pObj,
int fTriv )

Function*************************************************************

Synopsis [Derives cuts for one node and sweeps this node.]

Description []

SideEffects []

SeeAlso []

Definition at line 492 of file cswCut.c.

493{
494 int fUseResub = 1;
495 Csw_Cut_t * pCut0, * pCut1, * pCut, * pCutSet;
496 Aig_Obj_t * pFanin0 = Aig_ObjFanin0(pObj);
497 Aig_Obj_t * pFanin1 = Aig_ObjFanin1(pObj);
498 Aig_Obj_t * pObjNew;
499 unsigned * pTruth;
500 int i, k, nVars, nFanins, iVar;
501 abctime clk;
502
503 assert( !Aig_IsComplement(pObj) );
504 if ( !Aig_ObjIsNode(pObj) )
505 return pObj;
506 if ( Csw_ObjCuts(p, pObj) )
507 return pObj;
508 // the node is not processed yet
509 assert( Csw_ObjCuts(p, pObj) == NULL );
510 assert( Aig_ObjIsNode(pObj) );
511
512 // set up the first cut
513 pCutSet = Csw_ObjPrepareCuts( p, pObj, fTriv );
514
515 // compute pair-wise cut combinations while checking table
516 Csw_ObjForEachCut( p, pFanin0, pCut0, i )
517 if ( pCut0->nFanins > 0 )
518 Csw_ObjForEachCut( p, pFanin1, pCut1, k )
519 if ( pCut1->nFanins > 0 )
520 {
521 // make sure K-feasible cut exists
522 if ( Kit_WordCountOnes(pCut0->uSign | pCut1->uSign) > p->nLeafMax )
523 continue;
524 // get the next cut of this node
525 pCut = Csw_CutFindFree( p, pObj );
526clk = Abc_Clock();
527 // assemble the new cut
528 if ( !Csw_CutMerge( p, pCut0, pCut1, pCut ) )
529 {
530 assert( pCut->nFanins == 0 );
531 continue;
532 }
533 // check containment
534 if ( Csw_CutFilter( p, pObj, pCut ) )
535 {
536 assert( pCut->nFanins == 0 );
537 continue;
538 }
539 // create its truth table
540 pTruth = Csw_CutComputeTruth( p, pCut, pCut0, pCut1, Aig_ObjFaninC0(pObj), Aig_ObjFaninC1(pObj) );
541 // support minimize the truth table
542 nFanins = pCut->nFanins;
543// nVars = Csw_CutSupportMinimize( p, pCut ); // leads to quality degradation
544 nVars = Kit_TruthSupportSize( pTruth, p->nLeafMax );
545p->timeCuts += Abc_Clock() - clk;
546
547 // check for trivial truth tables
548 if ( nVars == 0 )
549 {
550 p->nNodesTriv0++;
551 return Aig_NotCond( Aig_ManConst1(p->pManRes), !(pTruth[0] & 1) );
552 }
553 if ( nVars == 1 )
554 {
555 p->nNodesTriv1++;
556 iVar = Kit_WordFindFirstBit( Kit_TruthSupport(pTruth, p->nLeafMax) );
557 assert( iVar < pCut->nFanins );
558 return Aig_NotCond( Aig_ManObj(p->pManRes, pCut->pFanins[iVar]), (pTruth[0] & 1) );
559 }
560 if ( nVars == 2 && nFanins > 2 && fUseResub )
561 {
562 if ( (pObjNew = Csw_ObjTwoVarCut( p, pCut )) )
563 {
564 p->nNodesTriv2++;
565 return pObjNew;
566 }
567 }
568
569 // check if an equivalent node with the same cut exists
570clk = Abc_Clock();
571 pObjNew = pCut->nFanins > 2 ? Csw_TableCutLookup( p, pCut ) : NULL;
572p->timeHash += Abc_Clock() - clk;
573 if ( pObjNew )
574 {
575 p->nNodesCuts++;
576 return pObjNew;
577 }
578
579 // assign the cost
580 pCut->Cost = Csw_CutFindCost( p, pCut );
581 assert( pCut->nFanins > 0 );
582 assert( pCut->Cost > 0 );
583 }
584 p->nNodesTried++;
585
586 // load the resulting cuts into the table
587clk = Abc_Clock();
588 Csw_ObjForEachCut( p, pObj, pCut, i )
589 {
590 if ( pCut->nFanins > 2 )
591 {
592 assert( pCut->Cost > 0 );
593 Csw_TableCutInsert( p, pCut );
594 }
595 }
596p->timeHash += Abc_Clock() - clk;
597
598 // return the node if could not replace it
599 return pObj;
600}
ABC_INT64_T abctime
Definition abc_global.h:332
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
Csw_Cut_t * Csw_ObjPrepareCuts(Csw_Man_t *p, Aig_Obj_t *pObj, int fTriv)
FUNCTION DECLARATIONS ///.
Definition cswCut.c:453
int Csw_CutFilter(Csw_Man_t *p, Aig_Obj_t *pObj, Csw_Cut_t *pCut)
Definition cswCut.c:243
unsigned * Csw_CutComputeTruth(Csw_Man_t *p, Csw_Cut_t *pCut, Csw_Cut_t *pCut0, Csw_Cut_t *pCut1, int fCompl0, int fCompl1)
Definition cswCut.c:149
Aig_Obj_t * Csw_ObjTwoVarCut(Csw_Man_t *p, Csw_Cut_t *pCut)
Definition cswCut.c:409
int Csw_CutMerge(Csw_Man_t *p, Csw_Cut_t *pCut0, Csw_Cut_t *pCut1, Csw_Cut_t *pCut)
Definition cswCut.c:380
void Csw_TableCutInsert(Csw_Man_t *p, Csw_Cut_t *pCut)
Definition cswTable.c:103
Aig_Obj_t * Csw_TableCutLookup(Csw_Man_t *p, Csw_Cut_t *pCut)
Definition cswTable.c:121
int Kit_TruthSupportSize(unsigned *pTruth, int nVars)
Definition kitTruth.c:327
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Csw_ObjTwoVarCut()

Aig_Obj_t * Csw_ObjTwoVarCut ( Csw_Man_t * p,
Csw_Cut_t * pCut )

Function*************************************************************

Synopsis [Consider cut with more than 2 fanins having 2 true variables.]

Description []

SideEffects []

SeeAlso []

Definition at line 409 of file cswCut.c.

410{
411 Aig_Obj_t * pRes, * pIn0, * pIn1;
412 int nVars, uTruth, fCompl = 0;
413 assert( pCut->nFanins > 2 );
414 // minimize support of this cut
415 nVars = Csw_CutSupportMinimize( p, pCut );
416 assert( nVars == 2 );
417 // get the fanins
418 pIn0 = Aig_ManObj( p->pManRes, pCut->pFanins[0] );
419 pIn1 = Aig_ManObj( p->pManRes, pCut->pFanins[1] );
420 // derive the truth table
421 uTruth = 0xF & *Csw_CutTruth(pCut);
422 if ( uTruth == 14 || uTruth == 13 || uTruth == 11 || uTruth == 7 )
423 {
424 uTruth = 0xF & ~uTruth;
425 fCompl = 1;
426 }
427 // compute the result
428 pRes = NULL;
429 if ( uTruth == 1 ) // 0001 // 1110 14
430 pRes = Aig_And( p->pManRes, Aig_Not(pIn0), Aig_Not(pIn1) );
431 if ( uTruth == 2 ) // 0010 // 1101 13
432 pRes = Aig_And( p->pManRes, pIn0 , Aig_Not(pIn1) );
433 if ( uTruth == 4 ) // 0100 // 1011 11
434 pRes = Aig_And( p->pManRes, Aig_Not(pIn0), pIn1 );
435 if ( uTruth == 8 ) // 1000 // 0111 7
436 pRes = Aig_And( p->pManRes, pIn0 , pIn1 );
437 if ( pRes )
438 pRes = Aig_NotCond( pRes, fCompl );
439 return pRes;
440}
Aig_Obj_t * Aig_And(Aig_Man_t *p, Aig_Obj_t *p0, Aig_Obj_t *p1)
Definition aigOper.c:104
int Csw_CutSupportMinimize(Csw_Man_t *p, Csw_Cut_t *pCut)
Definition cswCut.c:180
Here is the call graph for this function:
Here is the caller graph for this function: