Commit 3b77f2d1 by Alan Mishchenko

Added permute/unpermute.

parent 51134ab8
......@@ -210,6 +210,7 @@ struct Abc_Ntk_t_
void * pHaig; // history AIG
float * pLutTimes; // arrivals/requireds/slacks using LUT-delay model
Vec_Ptr_t * vOnehots; // names of one-hot-encoded registers
Vec_Int_t * vObjPerm; // permutation saved
// node attributes
Vec_Ptr_t * vAttrs; // managers of various node attributes (node functionality, global BDDs, etc)
};
......@@ -707,6 +708,8 @@ extern ABC_DLL Abc_Ntk_t * Abc_NtkCreateWithNode( char * pSop );
extern ABC_DLL void Abc_NtkDelete( Abc_Ntk_t * pNtk );
extern ABC_DLL void Abc_NtkFixNonDrivenNets( Abc_Ntk_t * pNtk );
extern ABC_DLL void Abc_NtkMakeComb( Abc_Ntk_t * pNtk, int fRemoveLatches );
extern ABC_DLL void Abc_NtkPermute( Abc_Ntk_t * pNtk, int fInputs, int fOutputs, int fFlops );
extern ABC_DLL void Abc_NtkUnpermute( Abc_Ntk_t * pNtk );
/*=== abcObj.c ==========================================================*/
extern ABC_DLL Abc_Obj_t * Abc_ObjAlloc( Abc_Ntk_t * pNtk, Abc_ObjType_t Type );
extern ABC_DLL void Abc_ObjRecycle( Abc_Obj_t * pObj );
......
......@@ -132,6 +132,8 @@ Abc_Ntk_t * Abc_NtkStartFrom( Abc_Ntk_t * pNtk, Abc_NtkType_t Type, Abc_NtkFunc_
pNtkNew->vOnehots = (Vec_Ptr_t *)Vec_VecDupInt( (Vec_Vec_t *)pNtk->vOnehots );
if ( pNtk->pSeqModel )
pNtkNew->pSeqModel = Abc_CexDup( pNtk->pSeqModel, Abc_NtkLatchNum(pNtk) );
if ( pNtk->vObjPerm )
pNtkNew->vObjPerm = Vec_IntDup( pNtk->vObjPerm );
// check that the CI/CO/latches are copied correctly
assert( Abc_NtkCiNum(pNtk) == Abc_NtkCiNum(pNtkNew) );
assert( Abc_NtkCoNum(pNtk) == Abc_NtkCoNum(pNtkNew) );
......@@ -180,6 +182,8 @@ Abc_Ntk_t * Abc_NtkStartFromNoLatches( Abc_Ntk_t * pNtk, Abc_NtkType_t Type, Abc
continue;
Abc_NtkDupBox(pNtkNew, pObj, 1);
}
if ( pNtk->vObjPerm )
pNtkNew->vObjPerm = Vec_IntDup( pNtk->vObjPerm );
// transfer the names
// Abc_NtkTrasferNamesNoLatches( pNtk, pNtkNew );
Abc_ManTimeDup( pNtk, pNtkNew );
......@@ -1038,6 +1042,7 @@ void Abc_NtkDelete( Abc_Ntk_t * pNtk )
if ( pNtk->vOnehots )
Vec_VecFree( (Vec_Vec_t *)pNtk->vOnehots );
Vec_PtrFreeP( &pNtk->vLtlProperties );
Vec_IntFreeP( &pNtk->vObjPerm );
ABC_FREE( pNtk );
}
......@@ -1532,6 +1537,169 @@ void Abc_NtkRemovePo( Abc_Ntk_t * pNtk, int iOutput )
Abc_NtkDeleteObj( pObj );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_NtkPermute( Abc_Ntk_t * pNtk, int fInputs, int fOutputs, int fFlops )
{
Abc_Obj_t * pTemp;
Vec_Int_t * vInputs, * vOutputs, * vFlops, * vTemp;
int i, k, Entry;
// start permutation arrays
vInputs = Vec_IntStartNatural( Abc_NtkPiNum(pNtk) );
vOutputs = Vec_IntStartNatural( Abc_NtkPoNum(pNtk) );
vFlops = Vec_IntStartNatural( Abc_NtkLatchNum(pNtk) );
// permute inputs
if ( fInputs )
for ( i = 0; i < Abc_NtkPiNum(pNtk); i++ )
{
k = rand() % Abc_NtkPiNum(pNtk);
// swap indexes
Entry = Vec_IntEntry( vInputs, i );
Vec_IntWriteEntry( vInputs, i, Vec_IntEntry(vInputs, k) );
Vec_IntWriteEntry( vInputs, k, Entry );
// swap PIs
pTemp = Vec_PtrEntry( pNtk->vPis, i );
Vec_PtrWriteEntry( pNtk->vPis, i, Vec_PtrEntry(pNtk->vPis, k) );
Vec_PtrWriteEntry( pNtk->vPis, k, pTemp );
// swap CIs
pTemp = Vec_PtrEntry( pNtk->vCis, i );
Vec_PtrWriteEntry( pNtk->vCis, i, Vec_PtrEntry(pNtk->vCis, k) );
Vec_PtrWriteEntry( pNtk->vCis, k, pTemp );
//printf( "Swapping PIs %d and %d.\n", i, k );
}
// permute outputs
if ( fOutputs )
for ( i = 0; i < Abc_NtkPoNum(pNtk); i++ )
{
k = rand() % Abc_NtkPoNum(pNtk);
// swap indexes
Entry = Vec_IntEntry( vOutputs, i );
Vec_IntWriteEntry( vOutputs, i, Vec_IntEntry(vOutputs, k) );
Vec_IntWriteEntry( vOutputs, k, Entry );
// swap POs
pTemp = Vec_PtrEntry( pNtk->vPos, i );
Vec_PtrWriteEntry( pNtk->vPos, i, Vec_PtrEntry(pNtk->vPos, k) );
Vec_PtrWriteEntry( pNtk->vPos, k, pTemp );
// swap COs
pTemp = Vec_PtrEntry( pNtk->vCos, i );
Vec_PtrWriteEntry( pNtk->vCos, i, Vec_PtrEntry(pNtk->vCos, k) );
Vec_PtrWriteEntry( pNtk->vCos, k, pTemp );
//printf( "Swapping POs %d and %d.\n", i, k );
}
// permute flops
assert( Abc_NtkBoxNum(pNtk) == Abc_NtkLatchNum(pNtk) );
if ( fFlops )
for ( i = 0; i < Abc_NtkLatchNum(pNtk); i++ )
{
k = rand() % Abc_NtkLatchNum(pNtk);
// swap indexes
Entry = Vec_IntEntry( vFlops, i );
Vec_IntWriteEntry( vFlops, i, Vec_IntEntry(vFlops, k) );
Vec_IntWriteEntry( vFlops, k, Entry );
// swap flops
pTemp = Vec_PtrEntry( pNtk->vBoxes, i );
Vec_PtrWriteEntry( pNtk->vBoxes, i, Vec_PtrEntry(pNtk->vBoxes, k) );
Vec_PtrWriteEntry( pNtk->vBoxes, k, pTemp );
// swap CIs
pTemp = Vec_PtrEntry( pNtk->vCis, Abc_NtkPiNum(pNtk)+i );
Vec_PtrWriteEntry( pNtk->vCis, Abc_NtkPiNum(pNtk)+i, Vec_PtrEntry(pNtk->vCis, Abc_NtkPiNum(pNtk)+k) );
Vec_PtrWriteEntry( pNtk->vCis, Abc_NtkPiNum(pNtk)+k, pTemp );
// swap COs
pTemp = Vec_PtrEntry( pNtk->vCos, Abc_NtkPoNum(pNtk)+i );
Vec_PtrWriteEntry( pNtk->vCos, Abc_NtkPoNum(pNtk)+i, Vec_PtrEntry(pNtk->vCos, Abc_NtkPoNum(pNtk)+k) );
Vec_PtrWriteEntry( pNtk->vCos, Abc_NtkPoNum(pNtk)+k, pTemp );
//printf( "Swapping flops %d and %d.\n", i, k );
}
// invert arrays
vInputs = Vec_IntInvert( vTemp = vInputs, -1 );
Vec_IntFree( vTemp );
vOutputs = Vec_IntInvert( vTemp = vOutputs, -1 );
Vec_IntFree( vTemp );
vFlops = Vec_IntInvert( vTemp = vFlops, -1 );
Vec_IntFree( vTemp );
// pack the results into the output array
Vec_IntFreeP( &pNtk->vObjPerm );
pNtk->vObjPerm = Vec_IntAlloc( Abc_NtkPiNum(pNtk) + Abc_NtkPoNum(pNtk) + Abc_NtkLatchNum(pNtk) );
Vec_IntForEachEntry( vInputs, Entry, i )
Vec_IntPush( pNtk->vObjPerm, Entry );
Vec_IntForEachEntry( vOutputs, Entry, i )
Vec_IntPush( pNtk->vObjPerm, Entry );
Vec_IntForEachEntry( vFlops, Entry, i )
Vec_IntPush( pNtk->vObjPerm, Entry );
// cleanup
Vec_IntFree( vInputs );
Vec_IntFree( vOutputs );
Vec_IntFree( vFlops );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_NtkUnpermute( Abc_Ntk_t * pNtk )
{
Vec_Ptr_t * vTemp, * vTemp2, * vLatch;
int i, * pInputs, * pOutputs, * pFlops;
if ( pNtk->vObjPerm == NULL )
{
printf( "Abc_NtkUnpermute(): Initial permutation is not available.\n" );
return;
}
assert( Abc_NtkBoxNum(pNtk) == Abc_NtkLatchNum(pNtk) );
// get reverve permutation
pInputs = Vec_IntArray( pNtk->vObjPerm );
pOutputs = pInputs + Abc_NtkPiNum(pNtk);
pFlops = pOutputs + Abc_NtkPoNum(pNtk);
// create new PI array
vTemp = Vec_PtrAlloc( Abc_NtkPiNum(pNtk) );
for ( i = 0; i < Abc_NtkPiNum(pNtk); i++ )
Vec_PtrPush( vTemp, Abc_NtkPi(pNtk, pInputs[i]) );
Vec_PtrFreeP( &pNtk->vPis );
pNtk->vPis = vTemp;
// create new PO array
vTemp = Vec_PtrAlloc( Abc_NtkPoNum(pNtk) );
for ( i = 0; i < Abc_NtkPoNum(pNtk); i++ )
Vec_PtrPush( vTemp, Abc_NtkPo(pNtk, pOutputs[i]) );
Vec_PtrFreeP( &pNtk->vPos );
pNtk->vPos = vTemp;
// create new CI/CO arrays
vTemp = Vec_PtrDup( pNtk->vPis );
vTemp2 = Vec_PtrDup( pNtk->vPos );
vLatch = Vec_PtrAlloc( Abc_NtkLatchNum(pNtk) );
for ( i = 0; i < Abc_NtkLatchNum(pNtk); i++ )
{
//printf( "Setting flop %d to be %d.\n", i, pFlops[i] );
Vec_PtrPush( vTemp, Abc_NtkCi(pNtk, Abc_NtkPiNum(pNtk) + pFlops[i]) );
Vec_PtrPush( vTemp2, Abc_NtkCo(pNtk, Abc_NtkPoNum(pNtk) + pFlops[i]) );
Vec_PtrPush( vLatch, Abc_NtkBox(pNtk, pFlops[i]) );
}
Vec_PtrFreeP( &pNtk->vCis );
Vec_PtrFreeP( &pNtk->vCos );
Vec_PtrFreeP( &pNtk->vBoxes );
pNtk->vCis = vTemp;
pNtk->vCos = vTemp2;
pNtk->vBoxes = vLatch;
// cleanup
Vec_IntFreeP( &pNtk->vObjPerm );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
......
......@@ -279,6 +279,8 @@ static int Abc_CommandBm ( Abc_Frame_t * pAbc, int argc, cha
static int Abc_CommandTestCex ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandPdr ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandReconcile ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandPermute ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandUnpermute ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandTraceStart ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandTraceCheck ( Abc_Frame_t * pAbc, int argc, char ** argv );
......@@ -701,6 +703,8 @@ void Abc_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "Verification", "testcex", Abc_CommandTestCex, 0 );
Cmd_CommandAdd( pAbc, "Verification", "pdr", Abc_CommandPdr, 0 );
Cmd_CommandAdd( pAbc, "Verification", "reconcile", Abc_CommandReconcile, 1 );
Cmd_CommandAdd( pAbc, "Verification", "permute", Abc_CommandPermute, 1 );
Cmd_CommandAdd( pAbc, "Verification", "unpermute", Abc_CommandUnpermute, 1 );
Cmd_CommandAdd( pAbc, "ABC8", "*r", Abc_CommandAbc8Read, 0 );
......@@ -20375,6 +20379,118 @@ usage:
SeeAlso []
***********************************************************************/
int Abc_CommandPermute( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Abc_Ntk_t * pNtk = pAbc->pNtkCur, * pNtkRes = NULL;
int fInputs = 1;
int fOutputs = 1;
int c, fFlops = 1;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "iofh" ) ) != EOF )
{
switch ( c )
{
case 'i':
fInputs ^= 1;
break;
case 'o':
fOutputs ^= 1;
break;
case 'f':
fFlops ^= 1;
break;
case 'h':
goto usage;
default:
Abc_Print( -2, "Unknown switch.\n");
goto usage;
}
}
if ( pNtk == NULL )
{
Abc_Print( -1, "Empty network.\n" );
return 1;
}
pNtkRes = Abc_NtkDup( pNtk );
if ( pNtkRes == NULL )
{
Abc_Print( -1, "Command \"permute\" has failed.\n" );
return 1;
}
Abc_NtkPermute( pNtkRes, fInputs, fOutputs, fFlops );
Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
return 0;
usage:
Abc_Print( -2, "usage: permute [-iofh]\n" );
Abc_Print( -2, "\t performs random permutation of inputs/outputs/flops\n" );
Abc_Print( -2, "\t-i : toggle permuting primary inputs [default = %s]\n", fInputs? "yes": "no" );
Abc_Print( -2, "\t-o : toggle permuting primary inputs [default = %s]\n", fOutputs? "yes": "no" );
Abc_Print( -2, "\t-f : toggle permuting primary inputs [default = %s]\n", fFlops? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_CommandUnpermute( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Abc_Ntk_t * pNtk = pAbc->pNtkCur, * pNtkRes = NULL;
int c;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
{
switch ( c )
{
case 'h':
goto usage;
default:
Abc_Print( -2, "Unknown switch.\n");
goto usage;
}
}
if ( pNtk == NULL )
{
Abc_Print( -1, "Empty network.\n" );
return 1;
}
pNtkRes = Abc_NtkDup( pNtk );
if ( pNtkRes == NULL )
{
Abc_Print( -1, "Command \"unpermute\" has failed.\n" );
return 1;
}
Abc_NtkUnpermute( pNtkRes );
Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
return 0;
usage:
Abc_Print( -2, "usage: unpermute [-h]\n" );
Abc_Print( -2, "\t restores inputs/outputs/flops before the last permutation\n" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_CommandTraceStart( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment