mirror of https://github.com/YosysHQ/abc.git
Detecting full-adder chains and putting them into white boxes.
This commit is contained in:
parent
153e888794
commit
372a348c90
|
|
@ -3815,6 +3815,10 @@ SOURCE=.\src\aig\gia\giaEra2.c
|
|||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\src\aig\gia\giaFadds.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\src\aig\gia\giaFalse.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
|
|
|||
|
|
@ -719,6 +719,13 @@ static inline int Gia_ManAppendMux( Gia_Man_t * p, int iCtrl, int iData1, int iD
|
|||
int iTemp1 = Gia_ManAppendAnd( p, iCtrl, iData1 );
|
||||
return Abc_LitNotCond( Gia_ManAppendAnd( p, Abc_LitNot(iTemp0), Abc_LitNot(iTemp1) ), 1 );
|
||||
}
|
||||
static inline int Gia_ManAppendMaj( Gia_Man_t * p, int iData0, int iData1, int iData2 )
|
||||
{
|
||||
int iTemp0 = Gia_ManAppendOr( p, iData1, iData2 );
|
||||
int iTemp1 = Gia_ManAppendAnd( p, iData0, iTemp0 );
|
||||
int iTemp2 = Gia_ManAppendAnd( p, iData1, iData2 );
|
||||
return Gia_ManAppendOr( p, iTemp1, iTemp2 );
|
||||
}
|
||||
static inline int Gia_ManAppendXor( Gia_Man_t * p, int iLit0, int iLit1 )
|
||||
{
|
||||
return Gia_ManAppendMux( p, iLit0, Abc_LitNot(iLit1), iLit1 );
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
***********************************************************************/
|
||||
|
||||
#include "gia.h"
|
||||
#include "misc/vec/vecWec.h"
|
||||
#include "misc/tim/tim.h"
|
||||
|
||||
ABC_NAMESPACE_IMPL_START
|
||||
|
||||
|
|
@ -27,14 +29,63 @@ ABC_NAMESPACE_IMPL_START
|
|||
/// DECLARATIONS ///
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define Dtc_ForEachCut( pList, pCut, i ) for ( i = 0, pCut = pList + 1; i < pList[0]; i++, pCut += pCut[0] + 1 )
|
||||
#define Dtc_ForEachFadd( vFadds, i ) for ( i = 0; i < Vec_IntSize(vFadds)/5; i++ )
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/// FUNCTION DEFINITIONS ///
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
Synopsis [Derive GIA with boxes containing adder-chains.]
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
void Gia_ManIllustrateBoxes( Gia_Man_t * p )
|
||||
{
|
||||
Tim_Man_t * pManTime = (Tim_Man_t *)p->pManTime;
|
||||
int nBoxes = Tim_ManBoxNum( pManTime );
|
||||
int i, k, curCi, curCo, nBoxIns, nBoxOuts;
|
||||
Gia_Obj_t * pObj;
|
||||
// walk through the boxes
|
||||
curCi = Tim_ManPiNum(pManTime);
|
||||
curCo = 0;
|
||||
for ( i = 0; i < Tim_ManBoxNum(pManTime); i++ )
|
||||
{
|
||||
nBoxIns = Tim_ManBoxInputNum(pManTime, i);
|
||||
nBoxOuts = Tim_ManBoxOutputNum(pManTime, i);
|
||||
printf( "Box %4d [%d x %d] : ", i, nBoxIns, nBoxOuts );
|
||||
printf( "Input obj IDs = " );
|
||||
for ( k = 0; k < nBoxIns; k++ )
|
||||
{
|
||||
pObj = Gia_ManCo( p, curCo + k );
|
||||
printf( "%d ", Gia_ObjId(p, pObj) );
|
||||
}
|
||||
printf( " Output obj IDs = " );
|
||||
for ( k = 0; k < nBoxOuts; k++ )
|
||||
{
|
||||
pObj = Gia_ManCi( p, curCi + k );
|
||||
printf( "%d ", Gia_ObjId(p, pObj) );
|
||||
}
|
||||
curCo += nBoxIns;
|
||||
curCi += nBoxOuts;
|
||||
printf( "\n" );
|
||||
}
|
||||
curCo += Tim_ManPoNum(pManTime);
|
||||
// verify counts
|
||||
assert( curCi == Gia_ManCiNum(p) );
|
||||
assert( curCo == Gia_ManCoNum(p) );
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Detecting FADDs in the AIG.]
|
||||
|
||||
Description []
|
||||
|
||||
|
|
@ -43,7 +94,6 @@ ABC_NAMESPACE_IMPL_START
|
|||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
#define Dtc_ForEachCut( pList, pCut, i ) for ( i = 0, pCut = pList + 1; i < pList[0]; i++, pCut += pCut[0] + 1 )
|
||||
int Dtc_ManCutMergeOne( int * pCut0, int * pCut1, int * pCut )
|
||||
{
|
||||
int i, k;
|
||||
|
|
@ -108,21 +158,20 @@ void Dtc_ObjCleanTruth_rec( Gia_Obj_t * pObj )
|
|||
Dtc_ObjCleanTruth_rec( Gia_ObjFanin0(pObj) );
|
||||
Dtc_ObjCleanTruth_rec( Gia_ObjFanin1(pObj) );
|
||||
}
|
||||
int Dtc_ObjComputeTruth( Gia_Man_t * p, int iObj, int * pCut )
|
||||
int Dtc_ObjComputeTruth( Gia_Man_t * p, int iObj, int * pCut, int * pTruth )
|
||||
{
|
||||
unsigned Truth, Truths[3] = { 0xAA, 0xCC, 0xF0 }; int i;
|
||||
for ( i = 1; i <= pCut[0]; i++ )
|
||||
Gia_ManObj(p, pCut[i])->Value = Truths[i-1];
|
||||
Truth = 0xFF & Dtc_ObjComputeTruth_rec( Gia_ManObj(p, iObj) );
|
||||
Dtc_ObjCleanTruth_rec( Gia_ManObj(p, iObj) );
|
||||
if ( Truth == 0x69 || Truth == 0x96 )
|
||||
if ( pTruth )
|
||||
*pTruth = Truth;
|
||||
if ( Truth == 0x96 || Truth == 0x69 )
|
||||
return 1;
|
||||
if ( Truth == 0x8E || Truth == 0x4D || Truth == 0x2B || Truth == 0xE8 ||
|
||||
Truth == 0x71 || Truth == 0xB2 || Truth == 0xD4 || Truth == 0x17 )
|
||||
{
|
||||
// printf( "%2x ", Truth );
|
||||
if ( Truth == 0xE8 || Truth == 0xD4 || Truth == 0xB2 || Truth == 0x71 ||
|
||||
Truth == 0x17 || Truth == 0x2B || Truth == 0x4D || Truth == 0x8E )
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
void Dtc_ManCutMerge( Gia_Man_t * p, int iObj, int * pList0, int * pList1, Vec_Int_t * vCuts, Vec_Int_t * vCutsXor, Vec_Int_t * vCutsMaj )
|
||||
|
|
@ -143,7 +192,7 @@ void Dtc_ManCutMerge( Gia_Man_t * p, int iObj, int * pList0, int * pList1, Vec_I
|
|||
Vec_IntPush( vCuts, pCut[c] );
|
||||
if ( pCut[0] != 3 )
|
||||
continue;
|
||||
Type = Dtc_ObjComputeTruth( p, iObj, pCut );
|
||||
Type = Dtc_ObjComputeTruth( p, iObj, pCut, NULL );
|
||||
if ( Type == 0 )
|
||||
continue;
|
||||
vTemp = Type == 1 ? vCutsXor : vCutsMaj;
|
||||
|
|
@ -152,7 +201,7 @@ void Dtc_ManCutMerge( Gia_Man_t * p, int iObj, int * pList0, int * pList1, Vec_I
|
|||
Vec_IntPush( vTemp, iObj );
|
||||
}
|
||||
}
|
||||
void Dtc_ManComputeCuts( Gia_Man_t * p, Vec_Int_t ** pvCutsXor, Vec_Int_t ** pvCutsMaj )
|
||||
void Dtc_ManComputeCuts( Gia_Man_t * p, Vec_Int_t ** pvCutsXor, Vec_Int_t ** pvCutsMaj, int fVerbose )
|
||||
{
|
||||
Gia_Obj_t * pObj;
|
||||
int * pList0, * pList1, i, nCuts = 0;
|
||||
|
|
@ -178,23 +227,14 @@ void Dtc_ManComputeCuts( Gia_Man_t * p, Vec_Int_t ** pvCutsXor, Vec_Int_t ** pvC
|
|||
Vec_IntAppend( vCuts, vTemp );
|
||||
nCuts += Vec_IntSize( vTemp );
|
||||
}
|
||||
printf( "Nodes = %d. Cuts = %d. Cuts/Node = %.2f. Ints/Node = %.2f.\n",
|
||||
Gia_ManAndNum(p), nCuts, 1.0*nCuts/Gia_ManAndNum(p), 1.0*Vec_IntSize(vCuts)/Gia_ManAndNum(p) );
|
||||
if ( fVerbose )
|
||||
printf( "Nodes = %d. Cuts = %d. Cuts/Node = %.2f. Ints/Node = %.2f.\n",
|
||||
Gia_ManAndNum(p), nCuts, 1.0*nCuts/Gia_ManAndNum(p), 1.0*Vec_IntSize(vCuts)/Gia_ManAndNum(p) );
|
||||
Vec_IntFree( vTemp );
|
||||
Vec_IntFree( vCuts );
|
||||
*pvCutsXor = vCutsXor;
|
||||
*pvCutsMaj = vCutsMaj;
|
||||
}
|
||||
int Dtc_ManCompare( int * pCut0, int * pCut1 )
|
||||
{
|
||||
if ( pCut0[0] < pCut1[0] ) return -1;
|
||||
if ( pCut0[0] > pCut1[0] ) return 1;
|
||||
if ( pCut0[1] < pCut1[1] ) return -1;
|
||||
if ( pCut0[1] > pCut1[1] ) return 1;
|
||||
if ( pCut0[2] < pCut1[2] ) return -1;
|
||||
if ( pCut0[2] > pCut1[2] ) return 1;
|
||||
return 0;
|
||||
}
|
||||
Vec_Int_t * Dtc_ManFindCommonCuts( Gia_Man_t * p, Vec_Int_t * vCutsXor, Vec_Int_t * vCutsMaj )
|
||||
{
|
||||
int * pCuts0 = Vec_IntArray(vCutsXor);
|
||||
|
|
@ -222,13 +262,13 @@ Vec_Int_t * Dtc_ManFindCommonCuts( Gia_Man_t * p, Vec_Int_t * vCutsXor, Vec_Int_
|
|||
else if ( pCuts0[i] > pCuts1[i] )
|
||||
pCuts1 += 4;
|
||||
}
|
||||
assert( Vec_IntSize(vFadds) % 5 == 0 );
|
||||
return vFadds;
|
||||
}
|
||||
void Dtc_ManPrintFadds( Vec_Int_t * vFadds )
|
||||
{
|
||||
int i, nObjs = Vec_IntSize(vFadds)/5;
|
||||
assert( Vec_IntSize(vFadds) % 5 == 0 );
|
||||
for ( i = 0; i < nObjs; i++ )
|
||||
int i;
|
||||
Dtc_ForEachFadd( vFadds, i )
|
||||
{
|
||||
printf( "%6d : ", i );
|
||||
printf( "%6d ", Vec_IntEntry(vFadds, 5*i+0) );
|
||||
|
|
@ -240,34 +280,42 @@ void Dtc_ManPrintFadds( Vec_Int_t * vFadds )
|
|||
printf( "\n" );
|
||||
}
|
||||
}
|
||||
void Dtc_ManSortChains( Gia_Man_t * p, Vec_Int_t * vFadds )
|
||||
int Dtc_ManCompare( int * pCut0, int * pCut1 )
|
||||
{
|
||||
Vec_Int_t * vMap = Vec_IntStartFull( Gia_ManObjNum(p) );
|
||||
int i, iFadd, Count = 0, nObjs = Vec_IntSize(vFadds)/5;
|
||||
assert( Vec_IntSize(vFadds) % 5 == 0 );
|
||||
for ( i = 0; i < nObjs; i++ )
|
||||
Vec_IntWriteEntry( vMap, Vec_IntEntry(vFadds, 5*i+4), i );
|
||||
for ( i = 0; i < nObjs; i++ )
|
||||
{
|
||||
int fFound = 0;
|
||||
if ( (iFadd = Vec_IntEntry( vMap, Vec_IntEntry(vFadds, 5*i+0) )) >= 0 )
|
||||
printf( "%d -> %d\n", iFadd, i ), fFound++;
|
||||
if ( (iFadd = Vec_IntEntry( vMap, Vec_IntEntry(vFadds, 5*i+1) )) >= 0 )
|
||||
printf( "%d -> %d\n", iFadd, i ), fFound++;
|
||||
if ( (iFadd = Vec_IntEntry( vMap, Vec_IntEntry(vFadds, 5*i+2) )) >= 0 )
|
||||
printf( "%d -> %d\n", iFadd, i ), fFound++;
|
||||
if ( !fFound )
|
||||
printf( "\n" );
|
||||
if ( fFound > 1 )
|
||||
Count++;
|
||||
}
|
||||
// printf( "%d \n", Count );
|
||||
Vec_IntFree( vMap );
|
||||
if ( pCut0[0] < pCut1[0] ) return -1;
|
||||
if ( pCut0[0] > pCut1[0] ) return 1;
|
||||
if ( pCut0[1] < pCut1[1] ) return -1;
|
||||
if ( pCut0[1] > pCut1[1] ) return 1;
|
||||
if ( pCut0[2] < pCut1[2] ) return -1;
|
||||
if ( pCut0[2] > pCut1[2] ) return 1;
|
||||
return 0;
|
||||
}
|
||||
int Dtc_ManCompare2( int * pCut0, int * pCut1 )
|
||||
{
|
||||
if ( pCut0[4] < pCut1[4] ) return -1;
|
||||
if ( pCut0[4] > pCut1[4] ) return 1;
|
||||
return 0;
|
||||
}
|
||||
// returns array of 5-tuples containing inputs/sum/cout of each full adder
|
||||
Vec_Int_t * Gia_ManDetectFullAdders( Gia_Man_t * p, int fVerbose )
|
||||
{
|
||||
Vec_Int_t * vCutsXor, * vCutsMaj, * vFadds;
|
||||
Dtc_ManComputeCuts( p, &vCutsXor, &vCutsMaj, fVerbose );
|
||||
qsort( Vec_IntArray(vCutsXor), Vec_IntSize(vCutsXor)/4, 16, (int (*)(const void *, const void *))Dtc_ManCompare );
|
||||
qsort( Vec_IntArray(vCutsMaj), Vec_IntSize(vCutsMaj)/4, 16, (int (*)(const void *, const void *))Dtc_ManCompare );
|
||||
vFadds = Dtc_ManFindCommonCuts( p, vCutsXor, vCutsMaj );
|
||||
qsort( Vec_IntArray(vFadds), Vec_IntSize(vFadds)/5, 20, (int (*)(const void *, const void *))Dtc_ManCompare2 );
|
||||
if ( fVerbose )
|
||||
printf( "XOR3 cuts = %d. MAJ cuts = %d. Fadds = %d.\n", Vec_IntSize(vCutsXor)/4, Vec_IntSize(vCutsMaj)/4, Vec_IntSize(vFadds)/5 );
|
||||
//Dtc_ManPrintFadds( vFadds );
|
||||
Vec_IntFree( vCutsXor );
|
||||
Vec_IntFree( vCutsMaj );
|
||||
return vFadds;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
Synopsis [Map each MAJ into the topmost MAJ of its chain.]
|
||||
|
||||
Description []
|
||||
|
||||
|
|
@ -276,19 +324,399 @@ void Dtc_ManSortChains( Gia_Man_t * p, Vec_Int_t * vFadds )
|
|||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
void Gia_ManDetectCarryChains( Gia_Man_t * p )
|
||||
// maps MAJ nodes into FADD indexes
|
||||
Vec_Int_t * Gia_ManCreateMap( Gia_Man_t * p, Vec_Int_t * vFadds )
|
||||
{
|
||||
Vec_Int_t * vCutsXor, * vCutsMaj, * vFadds;
|
||||
Dtc_ManComputeCuts( p, &vCutsXor, &vCutsMaj );
|
||||
qsort( Vec_IntArray(vCutsXor), Vec_IntSize(vCutsXor)/4, 16, (int (*)(const void *, const void *))Dtc_ManCompare );
|
||||
qsort( Vec_IntArray(vCutsMaj), Vec_IntSize(vCutsMaj)/4, 16, (int (*)(const void *, const void *))Dtc_ManCompare );
|
||||
vFadds = Dtc_ManFindCommonCuts( p, vCutsXor, vCutsMaj );
|
||||
printf( "XOR3 cuts = %d. MAJ cuts = %d. Fadds = %d.\n", Vec_IntSize(vCutsXor)/4, Vec_IntSize(vCutsMaj)/4, Vec_IntSize(vFadds)/5 );
|
||||
// Dtc_ManPrintFadds( vFadds );
|
||||
Dtc_ManSortChains( p, vFadds );
|
||||
Vec_IntFree( vCutsXor );
|
||||
Vec_IntFree( vCutsMaj );
|
||||
Vec_Int_t * vMap = Vec_IntStartFull( Gia_ManObjNum(p) ); int i;
|
||||
Dtc_ForEachFadd( vFadds, i )
|
||||
Vec_IntWriteEntry( vMap, Vec_IntEntry(vFadds, 5*i+4), i );
|
||||
return vMap;
|
||||
}
|
||||
// find chain length (for each MAJ, how many FADDs are rooted in its first input)
|
||||
int Gia_ManFindChains_rec( Gia_Man_t * p, int iMaj, Vec_Int_t * vFadds, Vec_Int_t * vMap, Vec_Int_t * vLength )
|
||||
{
|
||||
assert( Vec_IntEntry(vMap, iMaj) >= 0 ); // MAJ
|
||||
if ( Vec_IntEntry(vLength, iMaj) >= 0 )
|
||||
return Vec_IntEntry(vLength, iMaj);
|
||||
assert( Gia_ObjIsAnd(Gia_ManObj(p, iMaj)) );
|
||||
{
|
||||
int iFadd = Vec_IntEntry( vMap, iMaj );
|
||||
int iXor0 = Vec_IntEntry( vFadds, 5*iFadd+0 );
|
||||
int iXor1 = Vec_IntEntry( vFadds, 5*iFadd+1 );
|
||||
int iXor2 = Vec_IntEntry( vFadds, 5*iFadd+2 );
|
||||
int iLen0 = Vec_IntEntry( vMap, iXor0 ) == -1 ? 0 : Gia_ManFindChains_rec( p, iXor0, vFadds, vMap, vLength );
|
||||
int iLen1 = Vec_IntEntry( vMap, iXor1 ) == -1 ? 0 : Gia_ManFindChains_rec( p, iXor1, vFadds, vMap, vLength );
|
||||
int iLen2 = Vec_IntEntry( vMap, iXor2 ) == -1 ? 0 : Gia_ManFindChains_rec( p, iXor2, vFadds, vMap, vLength );
|
||||
int iLen = Abc_MaxInt( iLen0, Abc_MaxInt(iLen1, iLen2) );
|
||||
if ( iLen0 < iLen )
|
||||
{
|
||||
if ( iLen == iLen1 )
|
||||
{
|
||||
ABC_SWAP( int, Vec_IntArray(vFadds)[5*iFadd+0], Vec_IntArray(vFadds)[5*iFadd+1] );
|
||||
}
|
||||
else if ( iLen == iLen2 )
|
||||
{
|
||||
ABC_SWAP( int, Vec_IntArray(vFadds)[5*iFadd+0], Vec_IntArray(vFadds)[5*iFadd+2] );
|
||||
}
|
||||
}
|
||||
Vec_IntWriteEntry( vLength, iMaj, iLen + 1 );
|
||||
return iLen + 1;
|
||||
}
|
||||
}
|
||||
// for each FADD find the longest chain and reorder its inputs
|
||||
void Gia_ManFindChains( Gia_Man_t * p, Vec_Int_t * vFadds, Vec_Int_t * vMap )
|
||||
{
|
||||
int i;
|
||||
// for each FADD find the longest chain rooted in it
|
||||
Vec_Int_t * vLength = Vec_IntStartFull( Gia_ManObjNum(p) );
|
||||
Dtc_ForEachFadd( vFadds, i )
|
||||
Gia_ManFindChains_rec( p, Vec_IntEntry(vFadds, 5*i+4), vFadds, vMap, vLength );
|
||||
Vec_IntFree( vLength );
|
||||
}
|
||||
// collect one carry-chain
|
||||
void Gia_ManCollectOneChain( Gia_Man_t * p, Vec_Int_t * vFadds, int iFaddTop, Vec_Int_t * vMap, Vec_Int_t * vChain )
|
||||
{
|
||||
int iFadd;
|
||||
Vec_IntClear( vChain );
|
||||
for ( iFadd = iFaddTop; iFadd >= 0 &&
|
||||
!Gia_ObjIsTravIdCurrentId(p, Vec_IntEntry(vFadds, 5*iFadd+3)) &&
|
||||
!Gia_ObjIsTravIdCurrentId(p, Vec_IntEntry(vFadds, 5*iFadd+4));
|
||||
iFadd = Vec_IntEntry(vMap, Vec_IntEntry(vFadds, 5*iFadd+0)) )
|
||||
{
|
||||
Vec_IntPush( vChain, iFadd );
|
||||
}
|
||||
Vec_IntReverseOrder( vChain );
|
||||
}
|
||||
void Gia_ManMarkWithTravId_rec( Gia_Man_t * p, int Id )
|
||||
{
|
||||
Gia_Obj_t * pObj;
|
||||
if ( Gia_ObjIsTravIdCurrentId(p, Id) )
|
||||
return;
|
||||
Gia_ObjSetTravIdCurrentId(p, Id);
|
||||
pObj = Gia_ManObj( p, Id );
|
||||
if ( Gia_ObjIsAnd(pObj) )
|
||||
Gia_ManMarkWithTravId_rec( p, Gia_ObjFaninId0(pObj, Id) );
|
||||
if ( Gia_ObjIsAnd(pObj) )
|
||||
Gia_ManMarkWithTravId_rec( p, Gia_ObjFaninId1(pObj, Id) );
|
||||
}
|
||||
// returns mapping of each MAJ into the topmost elements of its chain
|
||||
Vec_Wec_t * Gia_ManCollectTopmost( Gia_Man_t * p, Vec_Int_t * vFadds, Vec_Int_t * vMap, int nFaddMin )
|
||||
{
|
||||
int i, j, iFadd;
|
||||
Vec_Int_t * vChain = Vec_IntAlloc( 100 );
|
||||
Vec_Wec_t * vChains = Vec_WecAlloc( Vec_IntSize(vFadds)/5 );
|
||||
// erase elements appearing as FADD inputs
|
||||
Vec_Bit_t * vMarksTop = Vec_BitStart( Vec_IntSize(vFadds)/5 );
|
||||
Dtc_ForEachFadd( vFadds, i )
|
||||
if ( (iFadd = Vec_IntEntry(vMap, Vec_IntEntry(vFadds, 5*i+0))) >= 0 )
|
||||
Vec_BitWriteEntry( vMarksTop, iFadd, 1 );
|
||||
// compress the remaining ones
|
||||
Gia_ManIncrementTravId( p );
|
||||
Dtc_ForEachFadd( vFadds, i )
|
||||
{
|
||||
if ( Vec_BitEntry(vMarksTop, i) )
|
||||
continue;
|
||||
Gia_ManCollectOneChain( p, vFadds, i, vMap, vChain );
|
||||
if ( Vec_IntSize(vChain) < nFaddMin )
|
||||
continue;
|
||||
Vec_IntAppend( Vec_WecPushLevel(vChains), vChain );
|
||||
Vec_IntForEachEntry( vChain, iFadd, j )
|
||||
{
|
||||
assert( !Gia_ObjIsTravIdCurrentId(p, Vec_IntEntry(vFadds, 5*iFadd+3)) );
|
||||
assert( !Gia_ObjIsTravIdCurrentId(p, Vec_IntEntry(vFadds, 5*iFadd+4)) );
|
||||
Gia_ManMarkWithTravId_rec( p, Vec_IntEntry(vFadds, 5*iFadd+3) );
|
||||
Gia_ManMarkWithTravId_rec( p, Vec_IntEntry(vFadds, 5*iFadd+4) );
|
||||
}
|
||||
}
|
||||
// cleanup
|
||||
Vec_BitFree( vMarksTop );
|
||||
Vec_IntFree( vChain );
|
||||
return vChains;
|
||||
}
|
||||
// prints chains beginning in majority nodes contained in vTops
|
||||
void Gia_ManPrintChains( Gia_Man_t * p, Vec_Int_t * vFadds, Vec_Int_t * vMap, Vec_Wec_t * vChains )
|
||||
{
|
||||
Vec_Int_t * vChain;
|
||||
int i, k, iFadd, Count = 0;
|
||||
Vec_WecForEachLevel( vChains, vChain, i )
|
||||
{
|
||||
Count += Vec_IntSize(vChain);
|
||||
if ( i < 10 )
|
||||
{
|
||||
printf( "Chain %4d : %4d ", i, Vec_IntSize(vChain) );
|
||||
Vec_IntForEachEntry( vChain, iFadd, k )
|
||||
{
|
||||
printf( "%d(%d) ", iFadd, Vec_IntEntry(vFadds, 5*iFadd+4) );
|
||||
if ( k != Vec_IntSize(vChain) - 1 )
|
||||
printf( "-> " );
|
||||
if ( k > 6 )
|
||||
{
|
||||
printf( "..." );
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf( "\n" );
|
||||
}
|
||||
else if ( i == 10 )
|
||||
printf( "...\n" );
|
||||
|
||||
}
|
||||
printf( "Total chains = %d. Total full-adders = %d.\n", Vec_WecSize(vChains), Count );
|
||||
}
|
||||
// map SUM bits and topmost MAJ into topmost FADD number
|
||||
Vec_Int_t * Gia_ManFindMapping( Gia_Man_t * p, Vec_Int_t * vFadds, Vec_Int_t * vMap, Vec_Wec_t * vChains )
|
||||
{
|
||||
Vec_Int_t * vChain;
|
||||
int i, k, iFadd;
|
||||
Vec_Int_t * vMap2Chain = Vec_IntStartFull( Gia_ManObjNum(p) );
|
||||
Vec_WecForEachLevel( vChains, vChain, i )
|
||||
{
|
||||
Vec_IntForEachEntry( vChain, iFadd, k )
|
||||
{
|
||||
//printf( "Chain %d: setting SUM %d (obj %d)\n", i, k, Vec_IntEntry(vFadds, 5*iFadd+3) );
|
||||
assert( Vec_IntEntry(vMap2Chain, Vec_IntEntry(vFadds, 5*iFadd+3)) == -1 );
|
||||
Vec_IntWriteEntry( vMap2Chain, Vec_IntEntry(vFadds, 5*iFadd+3), i );
|
||||
}
|
||||
//printf( "Chain %d: setting CARRY (obj %d)\n", i, Vec_IntEntry(vFadds, 5*iFadd+4) );
|
||||
assert( Vec_IntEntry(vMap2Chain, Vec_IntEntry(vFadds, 5*iFadd+4)) == -1 );
|
||||
Vec_IntWriteEntry( vMap2Chain, Vec_IntEntry(vFadds, 5*iFadd+4), i );
|
||||
}
|
||||
return vMap2Chain;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Derive GIA with boxes containing adder-chains.]
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
Vec_Int_t * Gia_ManCollectTruthTables( Gia_Man_t * p, Vec_Int_t * vFadds )
|
||||
{
|
||||
int i, k, Type, Truth, pCut[4] = {3};
|
||||
Vec_Int_t * vTruths = Vec_IntAlloc( 2*Vec_IntSize(vFadds)/5 );
|
||||
Gia_ManCleanValue( p );
|
||||
Dtc_ForEachFadd( vFadds, i )
|
||||
{
|
||||
for ( k = 0; k < 3; k++ )
|
||||
pCut[k+1] = Vec_IntEntry( vFadds, 5*i+k );
|
||||
Type = Dtc_ObjComputeTruth( p, Vec_IntEntry(vFadds, 5*i+3), pCut, &Truth );
|
||||
assert( Type == 1 );
|
||||
Vec_IntPush( vTruths, Truth );
|
||||
Type = Dtc_ObjComputeTruth( p, Vec_IntEntry(vFadds, 5*i+4), pCut, &Truth );
|
||||
assert( Type == 2 );
|
||||
Vec_IntPush( vTruths, Truth );
|
||||
}
|
||||
return vTruths;
|
||||
}
|
||||
float * Gia_ManGenerateDelayTableFloat( int nIns, int nOuts )
|
||||
{
|
||||
int i, Total = nIns * nOuts;
|
||||
float * pDelayTable = ABC_ALLOC( float, Total + 3 );
|
||||
pDelayTable[0] = 0;
|
||||
pDelayTable[1] = nIns;
|
||||
pDelayTable[2] = nOuts;
|
||||
for ( i = 0; i < Total; i++ )
|
||||
pDelayTable[i+3] = 1;
|
||||
pDelayTable[i+3 - nIns] = -ABC_INFINITY;
|
||||
return pDelayTable;
|
||||
}
|
||||
Tim_Man_t * Gia_ManGenerateTim( int nPis, int nPos, int nBoxes, int nIns, int nOuts )
|
||||
{
|
||||
Tim_Man_t * pMan;
|
||||
int i, curPi, curPo;
|
||||
Vec_Ptr_t * vDelayTables = Vec_PtrAlloc( 1 );
|
||||
Vec_PtrPush( vDelayTables, Gia_ManGenerateDelayTableFloat(nIns, nOuts) );
|
||||
pMan = Tim_ManStart( nPis + nOuts * nBoxes, nPos + nIns * nBoxes );
|
||||
Tim_ManSetDelayTables( pMan, vDelayTables );
|
||||
curPi = nPis;
|
||||
curPo = 0;
|
||||
for ( i = 0; i < nBoxes; i++ )
|
||||
{
|
||||
Tim_ManCreateBox( pMan, curPo, nIns, curPi, nOuts, 0 );
|
||||
curPi += nOuts;
|
||||
curPo += nIns;
|
||||
}
|
||||
curPo += nPos;
|
||||
assert( curPi == Tim_ManCiNum(pMan) );
|
||||
assert( curPo == Tim_ManCoNum(pMan) );
|
||||
//Tim_ManPrint( pMan );
|
||||
return pMan;
|
||||
}
|
||||
Gia_Man_t * Gia_ManGenerateExtraAig( int nBoxes, int nIns, int nOuts )
|
||||
{
|
||||
Gia_Man_t * pNew = Gia_ManStart( nBoxes * 20 );
|
||||
int i, k, pInLits[16], pOutLits[16];
|
||||
assert( nIns < 16 && nOuts < 16 );
|
||||
for ( i = 0; i < nIns; i++ )
|
||||
pInLits[i] = Gia_ManAppendCi( pNew );
|
||||
pOutLits[0] = Gia_ManAppendXor( pNew, Gia_ManAppendXor(pNew, pInLits[0], pInLits[1]), pInLits[2] );
|
||||
pOutLits[1] = Gia_ManAppendMaj( pNew, pInLits[0], pInLits[1], pInLits[2] );
|
||||
for ( i = 0; i < nBoxes; i++ )
|
||||
for ( k = 0; k < nOuts; k++ )
|
||||
Gia_ManAppendCo( pNew, pOutLits[k] );
|
||||
return pNew;
|
||||
}
|
||||
void Gia_ManDupFadd( Gia_Man_t * pNew, Gia_Man_t * p, Vec_Int_t * vChain, Vec_Int_t * vFadds, Vec_Int_t * vMap, Vec_Wec_t * vChains, Vec_Int_t * vMap2Chain, Vec_Int_t * vTruths )
|
||||
{
|
||||
extern void Gia_ManDupWithFaddBoxes_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vFadds, Vec_Int_t * vMap, Vec_Wec_t * vChains, Vec_Int_t * vMap2Chain, Vec_Int_t * vTruths );
|
||||
int i, k, iFadd, iCiLit, pLits[3];
|
||||
Gia_Obj_t * pObj;
|
||||
// construct FADD inputs
|
||||
Vec_IntForEachEntry( vChain, iFadd, i )
|
||||
for ( k = 0; k < 3; k++ )
|
||||
{
|
||||
if ( i && !k ) continue;
|
||||
pObj = Gia_ManObj( p, Vec_IntEntry(vFadds, 5*iFadd+k) );
|
||||
Gia_ManDupWithFaddBoxes_rec( pNew, p, pObj, vFadds, vMap, vChains, vMap2Chain, vTruths );
|
||||
}
|
||||
// construct boxes
|
||||
iCiLit = 0;
|
||||
Vec_IntForEachEntry( vChain, iFadd, i )
|
||||
{
|
||||
int iXorTruth = Vec_IntEntry( vTruths, 2*iFadd+0 );
|
||||
int iMajTruth = Vec_IntEntry( vTruths, 2*iFadd+1 );
|
||||
for ( k = 0; k < 3; k++ )
|
||||
{
|
||||
pObj = Gia_ManObj( p, Vec_IntEntry(vFadds, 5*iFadd+k) );
|
||||
pLits[k] = (!k && iCiLit) ? iCiLit : pObj->Value;
|
||||
assert( pLits[k] >= 0 );
|
||||
}
|
||||
// normalize truth table
|
||||
// if ( Truth == 0xE8 || Truth == 0xD4 || Truth == 0xB2 || Truth == 0x71 ||
|
||||
// Truth == 0x17 || Truth == 0x2B || Truth == 0x4D || Truth == 0x8E )
|
||||
if ( iMajTruth == 0x4D )
|
||||
pLits[0] = Abc_LitNot(pLits[0]), iMajTruth = 0x8E, iXorTruth = 0xFF & ~iXorTruth;
|
||||
else if ( iMajTruth == 0xD4 )
|
||||
pLits[0] = Abc_LitNot(pLits[0]), iMajTruth = 0xE8, iXorTruth = 0xFF & ~iXorTruth;
|
||||
else if ( iMajTruth == 0x2B )
|
||||
pLits[1] = Abc_LitNot(pLits[1]), iMajTruth = 0x8E, iXorTruth = 0xFF & ~iXorTruth;
|
||||
else if ( iMajTruth == 0xB2 )
|
||||
pLits[1] = Abc_LitNot(pLits[1]), iMajTruth = 0xE8, iXorTruth = 0xFF & ~iXorTruth;
|
||||
if ( iMajTruth == 0x8E )
|
||||
pLits[2] = Abc_LitNot(pLits[2]), iMajTruth = 0xE8, iXorTruth = 0xFF & ~iXorTruth;
|
||||
else if ( iMajTruth == 0x71 )
|
||||
pLits[2] = Abc_LitNot(pLits[2]), iMajTruth = 0x17, iXorTruth = 0xFF & ~iXorTruth;
|
||||
else assert( iMajTruth == 0xE8 || iMajTruth == 0x17 );
|
||||
// normalize carry-in
|
||||
if ( Abc_LitIsCompl(pLits[0]) )
|
||||
{
|
||||
for ( k = 0; k < 3; k++ )
|
||||
pLits[k] = Abc_LitNot(pLits[k]);
|
||||
iXorTruth = 0xFF & ~iXorTruth;
|
||||
iMajTruth = 0xFF & ~iMajTruth;
|
||||
}
|
||||
// add COs
|
||||
assert( !Abc_LitIsCompl(pLits[0]) );
|
||||
for ( k = 0; k < 3; k++ )
|
||||
Gia_ManAppendCo( pNew, pLits[k] );
|
||||
// create CI
|
||||
assert( iXorTruth == 0x96 || iXorTruth == 0x69 );
|
||||
pObj = Gia_ManObj( p, Vec_IntEntry(vFadds, 5*iFadd+3) );
|
||||
pObj->Value = Abc_LitNotCond( Gia_ManAppendCi(pNew), (int)(iXorTruth == 0x69) );
|
||||
// create CI
|
||||
assert( iMajTruth == 0xE8 || iMajTruth == 0x17 );
|
||||
iCiLit = Abc_LitNotCond( Gia_ManAppendCi(pNew), (int)(iMajTruth == 0x17) );
|
||||
}
|
||||
// assign carry out
|
||||
assert( iFadd == Vec_IntEntryLast(vChain) );
|
||||
pObj = Gia_ManObj( p, Vec_IntEntry(vFadds, 5*iFadd+4) );
|
||||
pObj->Value = iCiLit;
|
||||
}
|
||||
void Gia_ManDupWithFaddBoxes_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vFadds, Vec_Int_t * vMap, Vec_Wec_t * vChains, Vec_Int_t * vMap2Chain, Vec_Int_t * vTruths )
|
||||
{
|
||||
int iChain;
|
||||
if ( ~pObj->Value )
|
||||
return;
|
||||
assert( Gia_ObjIsAnd(pObj) );
|
||||
iChain = Vec_IntEntry( vMap2Chain, Gia_ObjId(p, pObj) );
|
||||
/*
|
||||
assert( iChain == -1 );
|
||||
if ( iChain >= 0 )
|
||||
{
|
||||
Gia_ManDupFadd( pNew, p, Vec_WecEntry(vChains, iChain), vFadds, vMap, vChains, vMap2Chain, vTruths );
|
||||
assert( ~pObj->Value );
|
||||
return;
|
||||
}
|
||||
*/
|
||||
Gia_ManDupWithFaddBoxes_rec( pNew, p, Gia_ObjFanin0(pObj), vFadds, vMap, vChains, vMap2Chain, vTruths );
|
||||
Gia_ManDupWithFaddBoxes_rec( pNew, p, Gia_ObjFanin1(pObj), vFadds, vMap, vChains, vMap2Chain, vTruths );
|
||||
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
|
||||
}
|
||||
Gia_Man_t * Gia_ManDupWithFaddBoxes( Gia_Man_t * p, int nFaddMin, int fVerbose )
|
||||
{
|
||||
Gia_Man_t * pNew, * pTemp;
|
||||
Vec_Int_t * vFadds, * vMap, * vMap2Chain, * vTruths, * vChain;
|
||||
Vec_Wec_t * vChains;
|
||||
Gia_Obj_t * pObj;
|
||||
int i, nBoxes;
|
||||
|
||||
// detect FADDs
|
||||
vFadds = Gia_ManDetectFullAdders( p, fVerbose );
|
||||
assert( Vec_IntSize(vFadds) % 5 == 0 );
|
||||
// map MAJ into its FADD
|
||||
vMap = Gia_ManCreateMap( p, vFadds );
|
||||
// for each FADD, find the longest chain and reorder its inputs
|
||||
Gia_ManFindChains( p, vFadds, vMap );
|
||||
// returns the set of topmost MAJ nodes
|
||||
vChains = Gia_ManCollectTopmost( p, vFadds, vMap, nFaddMin );
|
||||
if ( fVerbose )
|
||||
Gia_ManPrintChains( p, vFadds, vMap, vChains );
|
||||
if ( Vec_WecSize(vChains) == 0 )
|
||||
{
|
||||
Vec_IntFree( vFadds );
|
||||
Vec_IntFree( vMap );
|
||||
Vec_WecFree( vChains );
|
||||
return Gia_ManDup( p );
|
||||
}
|
||||
// returns mapping of each MAJ into the topmost elements of its chain
|
||||
vMap2Chain = Gia_ManFindMapping( p, vFadds, vMap, vChains );
|
||||
// compute truth tables for FADDs
|
||||
vTruths = Gia_ManCollectTruthTables( p, vFadds );
|
||||
|
||||
// duplicate
|
||||
Gia_ManFillValue( p );
|
||||
pNew = Gia_ManStart( Gia_ManObjNum(p) );
|
||||
pNew->pName = Abc_UtilStrsav( p->pName );
|
||||
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
|
||||
Gia_ManConst0(p)->Value = 0;
|
||||
Gia_ManForEachCi( p, pObj, i )
|
||||
pObj->Value = Gia_ManAppendCi( pNew );
|
||||
Vec_WecForEachLevel( vChains, vChain, i )
|
||||
Gia_ManDupFadd( pNew, p, vChain, vFadds, vMap, vChains, vMap2Chain, vTruths );
|
||||
Gia_ManForEachCo( p, pObj, i )
|
||||
Gia_ManDupWithFaddBoxes_rec( pNew, p, Gia_ObjFanin0(pObj), vFadds, vMap, vChains, vMap2Chain, vTruths );
|
||||
Gia_ManForEachCo( p, pObj, i )
|
||||
Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
|
||||
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
|
||||
assert( !Gia_ManHasDangling(pNew) );
|
||||
|
||||
// cleanup
|
||||
Vec_IntFree( vFadds );
|
||||
Vec_IntFree( vMap );
|
||||
Vec_WecFree( vChains );
|
||||
Vec_IntFree( vMap2Chain );
|
||||
Vec_IntFree( vTruths );
|
||||
|
||||
// normalize
|
||||
pNew = Gia_ManDupNormalize( pTemp = pNew );
|
||||
Gia_ManStop( pTemp );
|
||||
|
||||
// other information
|
||||
nBoxes = (Gia_ManCiNum(pNew) - Gia_ManCiNum(p)) / 2;
|
||||
assert( nBoxes == (Gia_ManCoNum(pNew) - Gia_ManCoNum(p)) / 3 );
|
||||
pNew->pManTime = Gia_ManGenerateTim( Gia_ManCiNum(p), Gia_ManCoNum(p), nBoxes, 3, 2 );
|
||||
pNew->pAigExtra = Gia_ManGenerateExtraAig( nBoxes, 3, 2 );
|
||||
|
||||
//pNew = Gia_ManDupCollapse( pTemp = pNew, pNew->pAigExtra, NULL );
|
||||
//Gia_ManStop( pTemp );
|
||||
|
||||
//Gia_ManIllustrateBoxes( pNew );
|
||||
return pNew;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ Vec_Int_t * Gia_ManOrderWithBoxes( Gia_Man_t * p )
|
|||
// include primary inputs
|
||||
for ( i = 0; i < Tim_ManPiNum(pManTime); i++ )
|
||||
{
|
||||
pObj = Gia_ManPi( p, i );
|
||||
pObj = Gia_ManCi( p, i );
|
||||
Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
|
||||
Gia_ObjSetTravIdCurrent( p, pObj );
|
||||
assert( Gia_ObjId(p, pObj) == i+1 );
|
||||
|
|
@ -130,7 +130,7 @@ Vec_Int_t * Gia_ManOrderWithBoxes( Gia_Man_t * p )
|
|||
// add internal nodes
|
||||
for ( k = 0; k < Tim_ManBoxInputNum(pManTime, i); k++ )
|
||||
{
|
||||
pObj = Gia_ManPo( p, curCo + k );
|
||||
pObj = Gia_ManCo( p, curCo + k );
|
||||
if ( Gia_ManOrderWithBoxes_rec( p, Gia_ObjFanin0(pObj), vNodes ) )
|
||||
{
|
||||
int iCiNum = p->iData2;
|
||||
|
|
@ -151,14 +151,14 @@ Vec_Int_t * Gia_ManOrderWithBoxes( Gia_Man_t * p )
|
|||
// add POs corresponding to box inputs
|
||||
for ( k = 0; k < Tim_ManBoxInputNum(pManTime, i); k++ )
|
||||
{
|
||||
pObj = Gia_ManPo( p, curCo + k );
|
||||
pObj = Gia_ManCo( p, curCo + k );
|
||||
Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
|
||||
}
|
||||
curCo += Tim_ManBoxInputNum(pManTime, i);
|
||||
// add PIs corresponding to box outputs
|
||||
for ( k = 0; k < Tim_ManBoxOutputNum(pManTime, i); k++ )
|
||||
{
|
||||
pObj = Gia_ManPi( p, curCi + k );
|
||||
pObj = Gia_ManCi( p, curCi + k );
|
||||
Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
|
||||
Gia_ObjSetTravIdCurrent( p, pObj );
|
||||
}
|
||||
|
|
@ -167,19 +167,19 @@ Vec_Int_t * Gia_ManOrderWithBoxes( Gia_Man_t * p )
|
|||
// add remaining nodes
|
||||
for ( i = Tim_ManCoNum(pManTime) - Tim_ManPoNum(pManTime); i < Tim_ManCoNum(pManTime); i++ )
|
||||
{
|
||||
pObj = Gia_ManPo( p, i );
|
||||
pObj = Gia_ManCo( p, i );
|
||||
Gia_ManOrderWithBoxes_rec( p, Gia_ObjFanin0(pObj), vNodes );
|
||||
}
|
||||
// add POs
|
||||
for ( i = Tim_ManCoNum(pManTime) - Tim_ManPoNum(pManTime); i < Tim_ManCoNum(pManTime); i++ )
|
||||
{
|
||||
pObj = Gia_ManPo( p, i );
|
||||
pObj = Gia_ManCo( p, i );
|
||||
Vec_IntPush( vNodes, Gia_ObjId(p, pObj) );
|
||||
}
|
||||
curCo += Tim_ManPoNum(pManTime);
|
||||
// verify counts
|
||||
assert( curCi == Gia_ManPiNum(p) );
|
||||
assert( curCo == Gia_ManPoNum(p) );
|
||||
assert( curCi == Gia_ManCiNum(p) );
|
||||
assert( curCo == Gia_ManCoNum(p) );
|
||||
assert( Vec_IntSize(vNodes) == Gia_ManObjNum(p) );
|
||||
return vNodes;
|
||||
}
|
||||
|
|
@ -292,8 +292,8 @@ Gia_Man_t * Gia_ManDupCollapse( Gia_Man_t * p, Gia_Man_t * pBoxes, Vec_Int_t * v
|
|||
Gia_Man_t * pNew, * pTemp;
|
||||
Gia_Obj_t * pObj, * pObjBox;
|
||||
int i, k, curCi, curCo;
|
||||
assert( Gia_ManRegNum(p) == 0 );
|
||||
assert( Gia_ManPiNum(p) == Tim_ManPiNum(pManTime) + Gia_ManPoNum(pBoxes) );
|
||||
//assert( Gia_ManRegNum(p) == 0 );
|
||||
assert( Gia_ManCiNum(p) == Tim_ManPiNum(pManTime) + Gia_ManCoNum(pBoxes) );
|
||||
pNew = Gia_ManStart( Gia_ManObjNum(p) );
|
||||
pNew->pName = Abc_UtilStrsav( p->pName );
|
||||
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
|
||||
|
|
@ -307,7 +307,7 @@ Gia_Man_t * Gia_ManDupCollapse( Gia_Man_t * p, Gia_Man_t * pBoxes, Vec_Int_t * v
|
|||
Gia_ObjSetTravIdCurrent( p, Gia_ManConst0(p) );
|
||||
for ( i = 0; i < Tim_ManPiNum(pManTime); i++ )
|
||||
{
|
||||
pObj = Gia_ManPi( p, i );
|
||||
pObj = Gia_ManCi( p, i );
|
||||
pObj->Value = Gia_ManAppendCi(pNew);
|
||||
Gia_ObjSetTravIdCurrent( p, pObj );
|
||||
}
|
||||
|
|
@ -326,13 +326,13 @@ Gia_Man_t * Gia_ManDupCollapse( Gia_Man_t * p, Gia_Man_t * pBoxes, Vec_Int_t * v
|
|||
int fSkip = (vBoxPres != NULL && !Vec_IntEntry(vBoxPres, i));
|
||||
for ( k = 0; k < Tim_ManBoxInputNum(pManTime, i); k++ )
|
||||
{
|
||||
pObj = Gia_ManPo( p, curCo + k );
|
||||
pObj = Gia_ManCo( p, curCo + k );
|
||||
Gia_ManDupCollapse_rec( p, Gia_ObjFanin0(pObj), pNew );
|
||||
pObj->Value = fSkip ? -1 : Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
|
||||
}
|
||||
for ( k = 0; k < Tim_ManBoxOutputNum(pManTime, i); k++ )
|
||||
{
|
||||
pObj = Gia_ManPi( p, curCi + k );
|
||||
pObj = Gia_ManCi( p, curCi + k );
|
||||
pObj->Value = fSkip ? 0 : Gia_ManAppendCi(pNew);
|
||||
Gia_ObjSetTravIdCurrent( p, pObj );
|
||||
}
|
||||
|
|
@ -342,20 +342,20 @@ Gia_Man_t * Gia_ManDupCollapse( Gia_Man_t * p, Gia_Man_t * pBoxes, Vec_Int_t * v
|
|||
for ( k = 0; k < Tim_ManBoxInputNum(pManTime, i); k++ )
|
||||
{
|
||||
// build logic
|
||||
pObj = Gia_ManPo( p, curCo + k );
|
||||
pObj = Gia_ManCo( p, curCo + k );
|
||||
Gia_ManDupCollapse_rec( p, Gia_ObjFanin0(pObj), pNew );
|
||||
// transfer to the PI
|
||||
pObjBox = Gia_ManPi( pBoxes, k );
|
||||
pObjBox = Gia_ManCi( pBoxes, k );
|
||||
pObjBox->Value = Gia_ObjFanin0Copy(pObj);
|
||||
Gia_ObjSetTravIdCurrent( pBoxes, pObjBox );
|
||||
}
|
||||
for ( k = 0; k < Tim_ManBoxOutputNum(pManTime, i); k++ )
|
||||
{
|
||||
// build logic
|
||||
pObjBox = Gia_ManPo( pBoxes, curCi - Tim_ManPiNum(pManTime) + k );
|
||||
pObjBox = Gia_ManCo( pBoxes, curCi - Tim_ManPiNum(pManTime) + k );
|
||||
Gia_ManDupCollapse_rec( pBoxes, Gia_ObjFanin0(pObjBox), pNew );
|
||||
// transfer to the PI
|
||||
pObj = Gia_ManPi( p, curCi + k );
|
||||
pObj = Gia_ManCi( p, curCi + k );
|
||||
pObj->Value = Gia_ObjFanin0Copy(pObjBox);
|
||||
Gia_ObjSetTravIdCurrent( p, pObj );
|
||||
}
|
||||
|
|
@ -366,21 +366,21 @@ Gia_Man_t * Gia_ManDupCollapse( Gia_Man_t * p, Gia_Man_t * pBoxes, Vec_Int_t * v
|
|||
// add remaining nodes
|
||||
for ( i = Tim_ManCoNum(pManTime) - Tim_ManPoNum(pManTime); i < Tim_ManCoNum(pManTime); i++ )
|
||||
{
|
||||
pObj = Gia_ManPo( p, i );
|
||||
pObj = Gia_ManCo( p, i );
|
||||
Gia_ManDupCollapse_rec( p, Gia_ObjFanin0(pObj), pNew );
|
||||
pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
|
||||
}
|
||||
curCo += Tim_ManPoNum(pManTime);
|
||||
// verify counts
|
||||
assert( curCi == Gia_ManPiNum(p) );
|
||||
assert( curCo == Gia_ManPoNum(p) );
|
||||
assert( curCi == Gia_ManCiNum(p) );
|
||||
assert( curCo == Gia_ManCoNum(p) );
|
||||
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
|
||||
Gia_ManHashStop( pNew );
|
||||
pNew = Gia_ManCleanup( pTemp = pNew );
|
||||
Gia_ManCleanupRemap( p, pTemp );
|
||||
Gia_ManStop( pTemp );
|
||||
assert( Tim_ManPoNum(pManTime) == Gia_ManPoNum(pNew) );
|
||||
assert( Tim_ManPiNum(pManTime) == Gia_ManPiNum(pNew) );
|
||||
assert( Tim_ManPoNum(pManTime) == Gia_ManCoNum(pNew) );
|
||||
assert( Tim_ManPiNum(pManTime) == Gia_ManCiNum(pNew) );
|
||||
return pNew;
|
||||
}
|
||||
|
||||
|
|
@ -426,7 +426,7 @@ int Gia_ManLevelWithBoxes( Gia_Man_t * p )
|
|||
Gia_ObjSetTravIdCurrent( p, Gia_ManConst0(p) );
|
||||
for ( i = 0; i < Tim_ManPiNum(pManTime); i++ )
|
||||
{
|
||||
pObj = Gia_ManPi( p, i );
|
||||
pObj = Gia_ManCi( p, i );
|
||||
Gia_ObjSetLevel( p, pObj, Tim_ManGetCiArrival(pManTime, i) / nAnd2Delay );
|
||||
Gia_ObjSetTravIdCurrent( p, pObj );
|
||||
}
|
||||
|
|
@ -441,7 +441,7 @@ int Gia_ManLevelWithBoxes( Gia_Man_t * p )
|
|||
// compute level for TFI of box inputs
|
||||
for ( k = 0; k < nBoxInputs; k++ )
|
||||
{
|
||||
pObj = Gia_ManPo( p, curCo + k );
|
||||
pObj = Gia_ManCo( p, curCo + k );
|
||||
if ( Gia_ManLevelWithBoxes_rec( p, Gia_ObjFanin0(pObj) ) )
|
||||
{
|
||||
printf( "Boxes are not in a topological order. Switching to level computation without boxes.\n" );
|
||||
|
|
@ -453,12 +453,12 @@ int Gia_ManLevelWithBoxes( Gia_Man_t * p )
|
|||
// compute level for box outputs
|
||||
for ( k = 0; k < nBoxOutputs; k++ )
|
||||
{
|
||||
pObj = Gia_ManPi( p, curCi + k );
|
||||
pObj = Gia_ManCi( p, curCi + k );
|
||||
Gia_ObjSetTravIdCurrent( p, pObj );
|
||||
// evaluate delay of this output
|
||||
LevelMax = 0;
|
||||
assert( nBoxInputs == (int)pDelayTable[1] );
|
||||
for ( j = 0; j < nBoxInputs && (pObjIn = Gia_ManPo(p, curCo + j)); j++ )
|
||||
for ( j = 0; j < nBoxInputs && (pObjIn = Gia_ManCo(p, curCo + j)); j++ )
|
||||
if ( (int)pDelayTable[3+k*nBoxInputs+j] != -ABC_INFINITY )
|
||||
LevelMax = Abc_MaxInt( LevelMax, Gia_ObjLevel(p, pObjIn) + ((int)pDelayTable[3+k*nBoxInputs+j] / nAnd2Delay) );
|
||||
// set box output level
|
||||
|
|
@ -471,15 +471,15 @@ int Gia_ManLevelWithBoxes( Gia_Man_t * p )
|
|||
p->nLevels = 0;
|
||||
for ( i = Tim_ManCoNum(pManTime) - Tim_ManPoNum(pManTime); i < Tim_ManCoNum(pManTime); i++ )
|
||||
{
|
||||
pObj = Gia_ManPo( p, i );
|
||||
pObj = Gia_ManCo( p, i );
|
||||
Gia_ManLevelWithBoxes_rec( p, Gia_ObjFanin0(pObj) );
|
||||
Gia_ObjSetCoLevel( p, pObj );
|
||||
p->nLevels = Abc_MaxInt( p->nLevels, Gia_ObjLevel(p, pObj) );
|
||||
}
|
||||
curCo += Tim_ManPoNum(pManTime);
|
||||
// verify counts
|
||||
assert( curCi == Gia_ManPiNum(p) );
|
||||
assert( curCo == Gia_ManPoNum(p) );
|
||||
assert( curCi == Gia_ManCiNum(p) );
|
||||
assert( curCo == Gia_ManCoNum(p) );
|
||||
// printf( "Max level is %d.\n", p->nLevels );
|
||||
return p->nLevels;
|
||||
}
|
||||
|
|
@ -528,7 +528,7 @@ int Gia_ManLutLevelWithBoxes( Gia_Man_t * p )
|
|||
Gia_ObjSetTravIdCurrent( p, Gia_ManConst0(p) );
|
||||
for ( i = 0; i < Tim_ManPiNum(pManTime); i++ )
|
||||
{
|
||||
pObj = Gia_ManPi( p, i );
|
||||
pObj = Gia_ManCi( p, i );
|
||||
// Gia_ObjSetLevel( p, pObj, Tim_ManGetCiArrival(pManTime, i) / nAnd2Delay );
|
||||
Gia_ObjSetLevel( p, pObj, 0 );
|
||||
Gia_ObjSetTravIdCurrent( p, pObj );
|
||||
|
|
@ -544,7 +544,7 @@ int Gia_ManLutLevelWithBoxes( Gia_Man_t * p )
|
|||
// compute level for TFI of box inputs
|
||||
for ( k = 0; k < nBoxInputs; k++ )
|
||||
{
|
||||
pObj = Gia_ManPo( p, curCo + k );
|
||||
pObj = Gia_ManCo( p, curCo + k );
|
||||
if ( Gia_ManLutLevelWithBoxes_rec( p, Gia_ObjFanin0(pObj) ) )
|
||||
{
|
||||
printf( "Boxes are not in a topological order. Switching to level computation without boxes.\n" );
|
||||
|
|
@ -556,12 +556,12 @@ int Gia_ManLutLevelWithBoxes( Gia_Man_t * p )
|
|||
// compute level for box outputs
|
||||
for ( k = 0; k < nBoxOutputs; k++ )
|
||||
{
|
||||
pObj = Gia_ManPi( p, curCi + k );
|
||||
pObj = Gia_ManCi( p, curCi + k );
|
||||
Gia_ObjSetTravIdCurrent( p, pObj );
|
||||
// evaluate delay of this output
|
||||
LevelMax = 0;
|
||||
assert( nBoxInputs == (int)pDelayTable[1] );
|
||||
for ( j = 0; j < nBoxInputs && (pObjIn = Gia_ManPo(p, curCo + j)); j++ )
|
||||
for ( j = 0; j < nBoxInputs && (pObjIn = Gia_ManCo(p, curCo + j)); j++ )
|
||||
if ( (int)pDelayTable[3+k*nBoxInputs+j] != -ABC_INFINITY )
|
||||
// LevelMax = Abc_MaxInt( LevelMax, Gia_ObjLevel(p, pObjIn) + ((int)pDelayTable[3+k*nBoxInputs+j] / nAnd2Delay) );
|
||||
LevelMax = Abc_MaxInt( LevelMax, Gia_ObjLevel(p, pObjIn) + 1 );
|
||||
|
|
@ -575,15 +575,15 @@ int Gia_ManLutLevelWithBoxes( Gia_Man_t * p )
|
|||
p->nLevels = 0;
|
||||
for ( i = Tim_ManCoNum(pManTime) - Tim_ManPoNum(pManTime); i < Tim_ManCoNum(pManTime); i++ )
|
||||
{
|
||||
pObj = Gia_ManPo( p, i );
|
||||
pObj = Gia_ManCo( p, i );
|
||||
Gia_ManLutLevelWithBoxes_rec( p, Gia_ObjFanin0(pObj) );
|
||||
Gia_ObjSetCoLevel( p, pObj );
|
||||
p->nLevels = Abc_MaxInt( p->nLevels, Gia_ObjLevel(p, pObj) );
|
||||
}
|
||||
curCo += Tim_ManPoNum(pManTime);
|
||||
// verify counts
|
||||
assert( curCi == Gia_ManPiNum(p) );
|
||||
assert( curCo == Gia_ManPoNum(p) );
|
||||
assert( curCi == Gia_ManCiNum(p) );
|
||||
assert( curCo == Gia_ManCoNum(p) );
|
||||
// printf( "Max level is %d.\n", p->nLevels );
|
||||
return p->nLevels;
|
||||
}
|
||||
|
|
@ -714,14 +714,14 @@ Gia_Man_t * Gia_ManUpdateExtraAig( void * pTime, Gia_Man_t * p, Vec_Int_t * vBox
|
|||
Vec_Int_t * vOutPres = Vec_IntAlloc( 100 );
|
||||
int i, k, curPo = 0;
|
||||
assert( Vec_IntSize(vBoxPres) == Tim_ManBoxNum(pManTime) );
|
||||
assert( Gia_ManPoNum(p) == Tim_ManCiNum(pManTime) - Tim_ManPiNum(pManTime) );
|
||||
assert( Gia_ManCoNum(p) == Tim_ManCiNum(pManTime) - Tim_ManPiNum(pManTime) );
|
||||
for ( i = 0; i < Tim_ManBoxNum(pManTime); i++ )
|
||||
{
|
||||
for ( k = 0; k < Tim_ManBoxOutputNum(pManTime, i); k++ )
|
||||
Vec_IntPush( vOutPres, Vec_IntEntry(vBoxPres, i) );
|
||||
curPo += Tim_ManBoxOutputNum(pManTime, i);
|
||||
}
|
||||
assert( curPo == Gia_ManPoNum(p) );
|
||||
assert( curPo == Gia_ManCoNum(p) );
|
||||
// if ( Vec_IntSize(vOutPres) > 0 )
|
||||
pNew = Gia_ManDupOutputVec( p, vOutPres );
|
||||
Vec_IntFree( vOutPres );
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ SRC += src/aig/gia/giaAig.c \
|
|||
src/aig/gia/giaEquiv.c \
|
||||
src/aig/gia/giaEra.c \
|
||||
src/aig/gia/giaEra2.c \
|
||||
src/aig/gia/giaFadds.c \
|
||||
src/aig/gia/giaFalse.c \
|
||||
src/aig/gia/giaFanout.c \
|
||||
src/aig/gia/giaForce.c \
|
||||
|
|
|
|||
|
|
@ -439,6 +439,7 @@ static int Abc_CommandAbc9Maxi ( Abc_Frame_t * pAbc, int argc, cha
|
|||
static int Abc_CommandAbc9Bmci ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
static int Abc_CommandAbc9PoXsim ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
static int Abc_CommandAbc9Demiter ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
static int Abc_CommandAbc9Fadds ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
//static int Abc_CommandAbc9PoPart2 ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
//static int Abc_CommandAbc9CexCut ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
//static int Abc_CommandAbc9CexMerge ( Abc_Frame_t * pAbc, int argc, char ** argv );
|
||||
|
|
@ -1040,6 +1041,7 @@ void Abc_Init( Abc_Frame_t * pAbc )
|
|||
Cmd_CommandAdd( pAbc, "ABC9", "&bmci", Abc_CommandAbc9Bmci, 0 );
|
||||
Cmd_CommandAdd( pAbc, "ABC9", "&poxsim", Abc_CommandAbc9PoXsim, 0 );
|
||||
Cmd_CommandAdd( pAbc, "ABC9", "&demiter", Abc_CommandAbc9Demiter, 0 );
|
||||
Cmd_CommandAdd( pAbc, "ABC9", "&fadds", Abc_CommandAbc9Fadds, 0 );
|
||||
// Cmd_CommandAdd( pAbc, "ABC9", "&popart2", Abc_CommandAbc9PoPart2, 0 );
|
||||
// Cmd_CommandAdd( pAbc, "ABC9", "&cexcut", Abc_CommandAbc9CexCut, 0 );
|
||||
// Cmd_CommandAdd( pAbc, "ABC9", "&cexmerge", Abc_CommandAbc9CexMerge, 0 );
|
||||
|
|
@ -36546,6 +36548,64 @@ usage:
|
|||
return 1;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
int Abc_CommandAbc9Fadds( Abc_Frame_t * pAbc, int argc, char ** argv )
|
||||
{
|
||||
extern Gia_Man_t * Gia_ManDupWithFaddBoxes( Gia_Man_t * p, int nFaddMin, int fVerbose );
|
||||
Gia_Man_t * pTemp;
|
||||
int c, nFaddMin = 3, fVerbose = 0;
|
||||
Extra_UtilGetoptReset();
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case 'N':
|
||||
if ( globalUtilOptind >= argc )
|
||||
{
|
||||
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
|
||||
goto usage;
|
||||
}
|
||||
nFaddMin = atoi(argv[globalUtilOptind]);
|
||||
globalUtilOptind++;
|
||||
if ( nFaddMin < 0 )
|
||||
goto usage;
|
||||
break;
|
||||
case 'v':
|
||||
fVerbose ^= 1;
|
||||
break;
|
||||
case 'h':
|
||||
goto usage;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
if ( pAbc->pGia == NULL )
|
||||
{
|
||||
Abc_Print( -1, "Abc_CommandAbc9Fadds(): There is no AIG.\n" );
|
||||
return 0;
|
||||
}
|
||||
pTemp = Gia_ManDupWithFaddBoxes( pAbc->pGia, nFaddMin, fVerbose );
|
||||
Abc_FrameUpdateGia( pAbc, pTemp );
|
||||
return 0;
|
||||
usage:
|
||||
Abc_Print( -2, "usage: &fadds [-N num] [-vh]\n" );
|
||||
Abc_Print( -2, "\t detects full-adder chains and puts them into white boxes\n" );
|
||||
Abc_Print( -2, "\t-N num : the minimum length of full-adder chain to box [default = %d]\n", nFaddMin );
|
||||
Abc_Print( -2, "\t-v : toggles printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
|
||||
Abc_Print( -2, "\t-h : print the command usage\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
|
|
|
|||
Loading…
Reference in New Issue