ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cswInt.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "aig/aig/aig.h"
#include "opt/dar/dar.h"
#include "bool/kit/kit.h"
#include "csw.h"
Include dependency graph for cswInt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Csw_Cut_t_
 
struct  Csw_Man_t_
 

Macros

#define Csw_ObjForEachCut(p, pObj, pCut, i)
 MACRO DEFINITIONS ///.
 
#define Csw_CutForEachLeaf(p, pCut, pLeaf, i)
 

Typedefs

typedef typedefABC_NAMESPACE_HEADER_START struct Csw_Man_t_ Csw_Man_t
 INCLUDES ///.
 
typedef struct Csw_Cut_t_ Csw_Cut_t
 

Functions

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)
 
Csw_Man_tCsw_ManStart (Aig_Man_t *pMan, int nCutsMax, int nLeafMax, int fVerbose)
 DECLARATIONS ///.
 
void Csw_ManStop (Csw_Man_t *p)
 
int Csw_TableCountCuts (Csw_Man_t *p)
 
void Csw_TableCutInsert (Csw_Man_t *p, Csw_Cut_t *pCut)
 
Aig_Obj_tCsw_TableCutLookup (Csw_Man_t *p, Csw_Cut_t *pCut)
 

Macro Definition Documentation

◆ Csw_CutForEachLeaf

#define Csw_CutForEachLeaf ( p,
pCut,
pLeaf,
i )
Value:
for ( i = 0; (i < (int)(pCut)->nFanins) && ((pLeaf) = Aig_ManObj(p, (pCut)->pFanins[i])); i++ )
Cube * p
Definition exorList.c:222

Definition at line 131 of file cswInt.h.

131#define Csw_CutForEachLeaf( p, pCut, pLeaf, i ) \
132 for ( i = 0; (i < (int)(pCut)->nFanins) && ((pLeaf) = Aig_ManObj(p, (pCut)->pFanins[i])); i++ )

◆ Csw_ObjForEachCut

#define Csw_ObjForEachCut ( p,
pObj,
pCut,
i )
Value:
for ( i = 0, pCut = Csw_ObjCuts(p, pObj); i < p->nCutsMax; i++, pCut = Csw_CutNext(pCut) )

MACRO DEFINITIONS ///.

ITERATORS ///

Definition at line 128 of file cswInt.h.

128#define Csw_ObjForEachCut( p, pObj, pCut, i ) \
129 for ( i = 0, pCut = Csw_ObjCuts(p, pObj); i < p->nCutsMax; i++, pCut = Csw_CutNext(pCut) )

Typedef Documentation

◆ Csw_Cut_t

typedef struct Csw_Cut_t_ Csw_Cut_t

Definition at line 53 of file cswInt.h.

◆ Csw_Man_t

typedef typedefABC_NAMESPACE_HEADER_START struct Csw_Man_t_ Csw_Man_t

INCLUDES ///.

CFile****************************************************************

FileName [cswInt.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Cut sweeping.]

Synopsis [External declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - July 11, 2007.]

Revision [

Id
cswInt.h,v 1.00 2007/07/11 00:00:00 alanmi Exp

] PARAMETERS /// BASIC TYPES ///

Definition at line 52 of file cswInt.h.

Function Documentation

◆ Csw_ManStart()

Csw_Man_t * Csw_ManStart ( Aig_Man_t * pMan,
int nCutsMax,
int nLeafMax,
int fVerbose )
extern

DECLARATIONS ///.

CFile****************************************************************

FileName [cswMan.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Cut sweeping.]

Synopsis []

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - July 11, 2007.]

Revision [

Id
cswMan.c,v 1.00 2007/07/11 00:00:00 alanmi Exp

] FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Starts the cut sweeping manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file cswMan.c.

46{
47 Csw_Man_t * p;
48 Aig_Obj_t * pObj;
49 int i;
50 assert( nCutsMax >= 2 );
51 assert( nLeafMax <= 16 );
52 // allocate the fraiging manager
53 p = ABC_ALLOC( Csw_Man_t, 1 );
54 memset( p, 0, sizeof(Csw_Man_t) );
55 p->nCutsMax = nCutsMax;
56 p->nLeafMax = nLeafMax;
57 p->fVerbose = fVerbose;
58 p->pManAig = pMan;
59 // create the new manager
60 p->pManRes = Aig_ManStartFrom( pMan );
61 assert( Aig_ManCiNum(p->pManAig) == Aig_ManCiNum(p->pManRes) );
62 // allocate room for cuts and equivalent nodes
63 p->pnRefs = ABC_ALLOC( int, Aig_ManObjNumMax(pMan) );
64 p->pEquiv = ABC_ALLOC( Aig_Obj_t *, Aig_ManObjNumMax(pMan) );
65 p->pCuts = ABC_ALLOC( Csw_Cut_t *, Aig_ManObjNumMax(pMan) );
66 memset( p->pCuts, 0, sizeof(Aig_Obj_t *) * Aig_ManObjNumMax(pMan) );
67 memset( p->pnRefs, 0, sizeof(int) * Aig_ManObjNumMax(pMan) );
68 // allocate memory manager
69 p->nTruthWords = Abc_TruthWordNum(nLeafMax);
70 p->nCutSize = sizeof(Csw_Cut_t) + sizeof(int) * nLeafMax + sizeof(unsigned) * p->nTruthWords;
71 p->pMemCuts = Aig_MmFixedStart( p->nCutSize * p->nCutsMax, 512 );
72 // allocate hash table for cuts
73 p->nTableSize = Abc_PrimeCudd( Aig_ManNodeNum(pMan) * p->nCutsMax / 2 );
74 p->pTable = ABC_ALLOC( Csw_Cut_t *, p->nTableSize );
75 memset( p->pTable, 0, sizeof(Aig_Obj_t *) * p->nTableSize );
76 // set the pointers to the available fraig nodes
77 Csw_ObjSetEquiv( p, Aig_ManConst1(p->pManAig), Aig_ManConst1(p->pManRes) );
78 Aig_ManForEachCi( p->pManAig, pObj, i )
79 Csw_ObjSetEquiv( p, pObj, Aig_ManCi(p->pManRes, i) );
80 // room for temporary truth tables
81 p->puTemp[0] = ABC_ALLOC( unsigned, 4 * p->nTruthWords );
82 p->puTemp[1] = p->puTemp[0] + p->nTruthWords;
83 p->puTemp[2] = p->puTemp[1] + p->nTruthWords;
84 p->puTemp[3] = p->puTemp[2] + p->nTruthWords;
85 return p;
86}
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define Aig_ManForEachCi(p, pObj, i)
ITERATORS ///.
Definition aig.h:393
Aig_Man_t * Aig_ManStartFrom(Aig_Man_t *p)
Definition aigMan.c:92
struct Aig_Obj_t_ Aig_Obj_t
Definition aig.h:51
Aig_MmFixed_t * Aig_MmFixedStart(int nEntrySize, int nEntriesMax)
FUNCTION DEFINITIONS ///.
Definition aigMem.c:96
struct Csw_Cut_t_ Csw_Cut_t
Definition cswInt.h:53
typedefABC_NAMESPACE_HEADER_START struct Csw_Man_t_ Csw_Man_t
INCLUDES ///.
Definition cswInt.h:52
#define assert(ex)
Definition util_old.h:213
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Csw_ManStop()

void Csw_ManStop ( Csw_Man_t * p)
extern

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

Synopsis [Stops the fraiging manager.]

Description []

SideEffects []

SeeAlso []

Definition at line 99 of file cswMan.c.

100{
101 if ( p->fVerbose )
102 {
103 int nNodesBeg = Aig_ManNodeNum(p->pManAig);
104 int nNodesEnd = Aig_ManNodeNum(p->pManRes);
105 printf( "Beg = %7d. End = %7d. (%6.2f %%) Try = %7d. Cuts = %8d.\n",
106 nNodesBeg, nNodesEnd, 100.0*(nNodesBeg-nNodesEnd)/nNodesBeg,
107 p->nNodesTried, Csw_TableCountCuts( p ) );
108 printf( "Triv0 = %6d. Triv1 = %6d. Triv2 = %6d. Cut-replace = %6d.\n",
109 p->nNodesTriv0, p->nNodesTriv1, p->nNodesTriv2, p->nNodesCuts );
110 ABC_PRTP( "Cuts ", p->timeCuts, p->timeTotal );
111 ABC_PRTP( "Hashing ", p->timeHash, p->timeTotal );
112 ABC_PRTP( "Other ", p->timeOther, p->timeTotal );
113 ABC_PRTP( "TOTAL ", p->timeTotal, p->timeTotal );
114 }
115 ABC_FREE( p->puTemp[0] );
116 Aig_MmFixedStop( p->pMemCuts, 0 );
117 ABC_FREE( p->pnRefs );
118 ABC_FREE( p->pEquiv );
119 ABC_FREE( p->pCuts );
120 ABC_FREE( p->pTable );
121 ABC_FREE( p );
122}
#define ABC_PRTP(a, t, T)
Definition abc_global.h:258
#define ABC_FREE(obj)
Definition abc_global.h:267
void Aig_MmFixedStop(Aig_MmFixed_t *p, int fVerbose)
Definition aigMem.c:132
int Csw_TableCountCuts(Csw_Man_t *p)
Definition cswTable.c:82
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 )
extern

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
#define Csw_ObjForEachCut(p, pObj, pCut, i)
MACRO DEFINITIONS ///.
Definition cswInt.h:128
int Id
Definition aig.h:85
unsigned uSign
Definition cswInt.h:61
int pFanins[0]
Definition cswInt.h:66
short nCutSize
Definition cswInt.h:63
char nLeafMax
Definition cswInt.h:64
char nFanins
Definition cswInt.h:65
int iNode
Definition cswInt.h:62
int Cost
Definition cswInt.h:59
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 )
extern

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
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
unsigned Kit_TruthSupport(unsigned *pTruth, int nVars)
Definition kitTruth.c:346
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_TableCountCuts()

int Csw_TableCountCuts ( Csw_Man_t * p)
extern

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

Synopsis [Returns the total number of cuts in the table.]

Description []

SideEffects []

SeeAlso []

Definition at line 82 of file cswTable.c.

83{
84 Csw_Cut_t * pEnt;
85 int i, Counter = 0;
86 for ( i = 0; i < p->nTableSize; i++ )
87 for ( pEnt = p->pTable[i]; pEnt; pEnt = pEnt->pNext )
88 Counter++;
89 return Counter;
90}
Csw_Cut_t * pNext
Definition cswInt.h:58
Here is the caller graph for this function:

◆ Csw_TableCutInsert()

void Csw_TableCutInsert ( Csw_Man_t * p,
Csw_Cut_t * pCut )
extern

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

Synopsis [Adds the cut to the hash table.]

Description []

SideEffects []

SeeAlso []

Definition at line 103 of file cswTable.c.

104{
105 int iEntry = Csw_CutHash(pCut) % p->nTableSize;
106 pCut->pNext = p->pTable[iEntry];
107 p->pTable[iEntry] = pCut;
108}
ABC_NAMESPACE_IMPL_START unsigned Csw_CutHash(Csw_Cut_t *pCut)
DECLARATIONS ///.
Definition cswTable.c:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Csw_TableCutLookup()

Aig_Obj_t * Csw_TableCutLookup ( Csw_Man_t * p,
Csw_Cut_t * pCut )
extern

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

Synopsis [Returns an equivalent node if it exists.]

Description []

SideEffects []

SeeAlso []

Definition at line 121 of file cswTable.c.

122{
123 Aig_Obj_t * pRes = NULL;
124 Csw_Cut_t * pEnt;
125 unsigned * pTruthNew, * pTruthOld;
126 int iEntry = Csw_CutHash(pCut) % p->nTableSize;
127 for ( pEnt = p->pTable[iEntry]; pEnt; pEnt = pEnt->pNext )
128 {
129 if ( pEnt->nFanins != pCut->nFanins )
130 continue;
131 if ( pEnt->uSign != pCut->uSign )
132 continue;
133 if ( memcmp( pEnt->pFanins, pCut->pFanins, sizeof(int) * pCut->nFanins ) )
134 continue;
135 pTruthOld = Csw_CutTruth(pEnt);
136 pTruthNew = Csw_CutTruth(pCut);
137 if ( (pTruthOld[0] & 1) == (pTruthNew[0] & 1) )
138 {
139 if ( Kit_TruthIsEqual( pTruthOld, pTruthNew, pCut->nFanins ) )
140 {
141 pRes = Aig_ManObj( p->pManRes, pEnt->iNode );
142 assert( pRes->fPhase == Aig_ManObj( p->pManRes, pCut->iNode )->fPhase );
143 break;
144 }
145 }
146 else
147 {
148 if ( Kit_TruthIsOpposite( pTruthOld, pTruthNew, pCut->nFanins ) )
149 {
150 pRes = Aig_Not( Aig_ManObj( p->pManRes, pEnt->iNode ) );
151 assert( Aig_Regular(pRes)->fPhase != Aig_ManObj( p->pManRes, pCut->iNode )->fPhase );
152 break;
153 }
154 }
155 }
156 return pRes;
157}
unsigned int fPhase
Definition aig.h:78
int memcmp()
Here is the call graph for this function:
Here is the caller graph for this function: