Enabling support for reading AIGs with XOR gates.

This commit is contained in:
Alan Mishchenko 2022-06-05 18:27:40 -07:00
parent aebf1e7b9c
commit 617eb759ae
3 changed files with 92 additions and 5 deletions

View File

@ -147,6 +147,73 @@ Gia_Man_t * Gia_ManDupMuxes( Gia_Man_t * p, int Limit )
return pNew;
}
/**Function*************************************************************
Synopsis [Creates AIG with XORs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManCreateXors( Gia_Man_t * p )
{
Gia_Man_t * pNew; Gia_Obj_t * pObj, * pFan0, * pFan1;
Vec_Int_t * vRefs = Vec_IntStart( Gia_ManObjNum(p) );
int i, iLit0, iLit1, nXors = 0, nObjs = 0;
Gia_ManForEachObj( p, pObj, i )
pObj->fMark0 = 0;
Gia_ManForEachAnd( p, pObj, i )
{
if ( Gia_ObjRecognizeExor(pObj, &pFan0, &pFan1) )
{
Vec_IntAddToEntry( vRefs, Gia_ObjId(p, Gia_Regular(pFan0)), 1 );
Vec_IntAddToEntry( vRefs, Gia_ObjId(p, Gia_Regular(pFan1)), 1 );
pObj->fMark0 = 1;
nXors++;
}
else
{
Vec_IntAddToEntry( vRefs, Gia_ObjFaninId0(pObj, i), 1 );
Vec_IntAddToEntry( vRefs, Gia_ObjFaninId1(pObj, i), 1 );
}
}
Gia_ManForEachCo( p, pObj, i )
Vec_IntAddToEntry( vRefs, Gia_ObjFaninId0p(p, pObj), 1 );
Gia_ManForEachAnd( p, pObj, i )
nObjs += Vec_IntEntry(vRefs, i) > 0;
pNew = Gia_ManStart( 1 + Gia_ManCiNum(p) + Gia_ManCoNum(p) + nObjs );
pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManConst0(p)->Value = 0;
Gia_ManForEachObj1( p, pObj, i )
{
if ( Gia_ObjIsCi(pObj) )
pObj->Value = Gia_ManAppendCi( pNew );
else if ( Gia_ObjIsCo(pObj) )
pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
else if ( Gia_ObjIsBuf(pObj) )
pObj->Value = Gia_ManAppendBuf( pNew, Gia_ObjFanin0Copy(pObj) );
else if ( pObj->fMark0 )
{
Gia_ObjRecognizeExor(pObj, &pFan0, &pFan1);
iLit0 = Abc_LitNotCond( Gia_Regular(pFan0)->Value, Gia_IsComplement(pFan0) );
iLit1 = Abc_LitNotCond( Gia_Regular(pFan1)->Value, Gia_IsComplement(pFan1) );
pObj->Value = Gia_ManAppendXorReal( pNew, iLit0, iLit1 );
}
else if ( Vec_IntEntry(vRefs, i) > 0 )
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
}
assert( pNew->nObjs == pNew->nObjsAlloc );
pNew->pMuxes = ABC_CALLOC( unsigned, pNew->nObjs );
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
Vec_IntFree( vRefs );
//printf( "Created %d XORs.\n", nXors );
return pNew;
}
/**Function*************************************************************
Synopsis [Derives GIA without MUXes.]

View File

@ -2485,15 +2485,21 @@ void Gia_ManSimGen( Gia_Man_t * pGia )
SeeAlso []
***********************************************************************/
int Gia_ManSimTwo( Gia_Man_t * p0, Gia_Man_t * p1, int nWords, int nRounds, int fVerbose )
int Gia_ManSimTwo( Gia_Man_t * p0, Gia_Man_t * p1, int nWords, int nRounds, int TimeLimit, int fVerbose )
{
Vec_Wrd_t * vSim0, * vSim1, * vSim2;
abctime clk = Abc_Clock();
int n, i, RetValue = 1;
int TimeStop = TimeLimit ? TimeLimit * CLOCKS_PER_SEC + Abc_Clock() : 0; // in CPU ticks
printf( "Simulating %d round with %d machine words.\n", nRounds, nWords );
Abc_RandomW(0);
for ( n = 0; RetValue && n < nRounds; n++ )
{
if ( TimeStop && Abc_Clock() > TimeStop )
{
printf( "Computation timed out after %d seconds and %d rounds.\n", TimeLimit, n );
break;
}
vSim0 = Vec_WrdStartRandom( Gia_ManCiNum(p0) * nWords );
p0->vSimsPi = vSim0;
p1->vSimsPi = vSim0;

View File

@ -30138,6 +30138,7 @@ int Abc_CommandAbc9Read( Abc_Frame_t * pAbc, int argc, char ** argv )
extern void Abc3_ReadShowHie( char * pFileName, int fFlat );
extern Gia_Man_t * Gia_MiniAigSuperDerive( char * pFileName, int fVerbose );
extern Gia_Man_t * Gia_FileSimpleRead( char * pFileName, int fNames, char * pFileW );
extern Gia_Man_t * Gia_ManCreateXors( Gia_Man_t * p );
Gia_Man_t * pAig = NULL;
FILE * pFile;
char ** pArgvNew;
@ -30150,8 +30151,9 @@ int Abc_CommandAbc9Read( Abc_Frame_t * pAbc, int argc, char ** argv )
int fGiaSimple = 0;
int fSkipStrash = 0;
int fNewReader = 0;
int fDetectXors = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "csmnlpvh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "csxmnlpvh" ) ) != EOF )
{
switch ( c )
{
@ -30161,6 +30163,9 @@ int Abc_CommandAbc9Read( Abc_Frame_t * pAbc, int argc, char ** argv )
case 's':
fSkipStrash ^= 1;
break;
case 'x':
fDetectXors ^= 1;
break;
case 'm':
fMiniAig ^= 1;
break;
@ -30215,16 +30220,25 @@ int Abc_CommandAbc9Read( Abc_Frame_t * pAbc, int argc, char ** argv )
// else if ( Extra_FileIsType( FileName, ".v", NULL, NULL ) )
// Abc3_ReadShowHie( FileName, fSkipStrash );
else
{
pAig = Gia_AigerRead( FileName, fGiaSimple, fSkipStrash, 0 );
if ( fDetectXors )
{
Gia_Man_t * pTemp;
pAig = Gia_ManCreateXors( pTemp = pAig );
Gia_ManStop( pTemp );
}
}
if ( pAig )
Abc_FrameUpdateGia( pAbc, pAig );
return 0;
usage:
Abc_Print( -2, "usage: &r [-csmnlvh] <file>\n" );
Abc_Print( -2, "usage: &r [-csxmnlvh] <file>\n" );
Abc_Print( -2, "\t reads the current AIG from the AIGER file\n" );
Abc_Print( -2, "\t-c : toggles reading simple AIG [default = %s]\n", fGiaSimple? "yes": "no" );
Abc_Print( -2, "\t-s : toggles structural hashing while reading [default = %s]\n", !fSkipStrash? "yes": "no" );
Abc_Print( -2, "\t-x : toggles detecting XORs while reading [default = %s]\n", fDetectXors? "yes": "no" );
Abc_Print( -2, "\t-m : toggles reading MiniAIG rather than AIGER file [default = %s]\n", fMiniAig? "yes": "no" );
Abc_Print( -2, "\t-n : toggles reading MiniAIG as a set of supergates [default = %s]\n", fMiniAig2? "yes": "no" );
Abc_Print( -2, "\t-l : toggles reading MiniLUT rather than AIGER file [default = %s]\n", fMiniLut? "yes": "no" );
@ -32979,7 +32993,7 @@ usage:
***********************************************************************/
int Abc_CommandAbc9Sim2( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern int Gia_ManSimTwo( Gia_Man_t * p0, Gia_Man_t * p1, int nWords, int nRounds, int fVerbose );
extern int Gia_ManSimTwo( Gia_Man_t * p0, Gia_Man_t * p1, int nWords, int nRounds, int TimeLimit, int fVerbose );
Gia_Man_t * pGias[2]; FILE * pFile;
char ** pArgvNew; int nArgcNew;
int c, RetValue = 0, fVerbose = 0, nWords = 16, nRounds = 10, RandSeed = 1, TimeLimit = 0;
@ -33126,7 +33140,7 @@ int Abc_CommandAbc9Sim2( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "The number of COs does not match.\n" );
return 1;
}
RetValue = Gia_ManSimTwo( pGias[0], pGias[1], nWords, nRounds, fVerbose );
RetValue = Gia_ManSimTwo( pGias[0], pGias[1], nWords, nRounds, TimeLimit, fVerbose );
if ( pGias[0] != pAbc->pGia )
Gia_ManStopP( &pGias[0] );
Gia_ManStopP( &pGias[1] );