Commit 0ae0744e authored by Alan Mishchenko's avatar Alan Mishchenko

Experimental resubstitution.

parent a8bd59bd
......@@ -1558,8 +1558,7 @@ extern void Gia_ManIncrSimSet( Gia_Man_t * p, Vec_Int_t * vObjLit
extern int Gia_ManIncrSimCheckOver( Gia_Man_t * p, int iLit0, int iLit1 );
extern int Gia_ManIncrSimCheckEqual( Gia_Man_t * p, int iLit0, int iLit1 );
/*=== giaSimBase.c ============================================================*/
extern Vec_Wrd_t * Gia_ManSimPatRead( char * pFileName, int * pnWords );
extern void Gia_ManSimPatWrite( char * pFileName, Vec_Wrd_t * vSimsIn, int nWords );
extern Vec_Wrd_t * Gia_ManSimPatSim( Gia_Man_t * p );
/*=== giaSpeedup.c ============================================================*/
extern float Gia_ManDelayTraceLut( Gia_Man_t * p );
extern float Gia_ManDelayTraceLutPrint( Gia_Man_t * p, int fVerbose );
......@@ -1685,6 +1684,7 @@ extern int Gia_ObjRecognizeExor( Gia_Obj_t * pObj, Gia_Obj_t **
extern Gia_Obj_t * Gia_ObjRecognizeMux( Gia_Obj_t * pNode, Gia_Obj_t ** ppNodeT, Gia_Obj_t ** ppNodeE );
extern int Gia_ObjRecognizeMuxLits( Gia_Man_t * p, Gia_Obj_t * pNode, int * iLitT, int * iLitE );
extern int Gia_NodeMffcSize( Gia_Man_t * p, Gia_Obj_t * pNode );
extern int Gia_NodeMffcSizeMark( Gia_Man_t * p, Gia_Obj_t * pNode );
extern int Gia_NodeMffcSizeSupp( Gia_Man_t * p, Gia_Obj_t * pNode, Vec_Int_t * vSupp );
extern int Gia_ManHasDangling( Gia_Man_t * p );
extern int Gia_ManMarkDangling( Gia_Man_t * p );
......
This diff is collapsed.
......@@ -306,89 +306,6 @@ Gia_Man_t * Gia_ManSimPatGenMiter( Gia_Man_t * p, Vec_Wrd_t * vSims )
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManSimPatWriteOne( FILE * pFile, word * pSim, int nWords )
{
int k, Digit, nDigits = nWords*16;
for ( k = 0; k < nDigits; k++ )
{
Digit = (int)((pSim[k/16] >> ((k%16) * 4)) & 15);
if ( Digit < 10 )
fprintf( pFile, "%d", Digit );
else
fprintf( pFile, "%c", 'A' + Digit-10 );
}
fprintf( pFile, "\n" );
}
void Gia_ManSimPatWrite( char * pFileName, Vec_Wrd_t * vSimsIn, int nWords )
{
int i, nNodes = Vec_WrdSize(vSimsIn) / nWords;
FILE * pFile = fopen( pFileName, "wb" );
if ( pFile == NULL )
{
printf( "Cannot open file \"%s\" for writing.\n", pFileName );
return;
}
assert( Vec_WrdSize(vSimsIn) % nWords == 0 );
for ( i = 0; i < nNodes; i++ )
Gia_ManSimPatWriteOne( pFile, Vec_WrdEntryP(vSimsIn, i*nWords), nWords );
fclose( pFile );
printf( "Written %d words of simulation data for %d objects into file \"%s\".\n", nWords, Vec_WrdSize(vSimsIn)/nWords, pFileName );
}
int Gia_ManSimPatReadOne( char c )
{
int Digit = 0;
if ( c >= '0' && c <= '9' )
Digit = c - '0';
else if ( c >= 'A' && c <= 'F' )
Digit = c - 'A' + 10;
else if ( c >= 'a' && c <= 'f' )
Digit = c - 'a' + 10;
else assert( 0 );
assert( Digit >= 0 && Digit < 16 );
return Digit;
}
Vec_Wrd_t * Gia_ManSimPatRead( char * pFileName, int * pnWords )
{
Vec_Wrd_t * vSimsIn = NULL;
int c, nWords = -1, nChars = 0; word Num = 0;
FILE * pFile = fopen( pFileName, "rb" );
if ( pFile == NULL )
{
printf( "Cannot open file \"%s\" for reading.\n", pFileName );
return NULL;
}
vSimsIn = Vec_WrdAlloc( 1000 );
while ( (c = fgetc(pFile)) != EOF )
{
if ( c == '\n' && nWords == -1 )
nWords = Vec_WrdSize(vSimsIn);
if ( c == '\n' || c == '\r' || c == '\t' || c == ' ' )
continue;
Num |= (word)Gia_ManSimPatReadOne((char)c) << (nChars * 4);
if ( ++nChars < 16 )
continue;
Vec_WrdPush( vSimsIn, Num );
nChars = 0;
Num = 0;
}
assert( Vec_WrdSize(vSimsIn) % nWords == 0 );
fclose( pFile );
printf( "Read %d words of simulation data for %d objects.\n", nWords, Vec_WrdSize(vSimsIn)/nWords );
if ( pnWords )
*pnWords = nWords;
return vSimsIn;
}
/**Function*************************************************************
......
......@@ -1101,19 +1101,20 @@ int Gia_NodeDeref_rec( Gia_Man_t * p, Gia_Obj_t * pNode )
SeeAlso []
***********************************************************************/
int Gia_NodeRef_rec( Gia_Man_t * p, Gia_Obj_t * pNode )
int Gia_NodeRef_rec( Gia_Man_t * p, Gia_Obj_t * pNode, int fMark )
{
Gia_Obj_t * pFanin;
int Counter = 0;
if ( Gia_ObjIsCi(pNode) )
return 0;
assert( Gia_ObjIsAnd(pNode) );
if ( fMark ) Gia_ObjSetTravIdCurrent(p, pNode);
pFanin = Gia_ObjFanin0(pNode);
if ( Gia_ObjRefInc(p, pFanin) == 0 )
Counter += Gia_NodeRef_rec( p, pFanin );
Counter += Gia_NodeRef_rec( p, pFanin, fMark );
pFanin = Gia_ObjFanin1(pNode);
if ( Gia_ObjRefInc(p, pFanin) == 0 )
Counter += Gia_NodeRef_rec( p, pFanin );
Counter += Gia_NodeRef_rec( p, pFanin, fMark );
return Counter + 1;
}
......@@ -1152,7 +1153,19 @@ int Gia_NodeMffcSize( Gia_Man_t * p, Gia_Obj_t * pNode )
assert( !Gia_IsComplement(pNode) );
assert( Gia_ObjIsCand(pNode) );
ConeSize1 = Gia_NodeDeref_rec( p, pNode );
ConeSize2 = Gia_NodeRef_rec( p, pNode );
ConeSize2 = Gia_NodeRef_rec( p, pNode, 0 );
assert( ConeSize1 == ConeSize2 );
assert( ConeSize1 >= 0 );
return ConeSize1;
}
int Gia_NodeMffcSizeMark( Gia_Man_t * p, Gia_Obj_t * pNode )
{
int ConeSize1, ConeSize2;
assert( !Gia_IsComplement(pNode) );
assert( Gia_ObjIsCand(pNode) );
ConeSize1 = Gia_NodeDeref_rec( p, pNode );
Gia_ManIncrementTravId( p );
ConeSize2 = Gia_NodeRef_rec( p, pNode, 1 );
assert( ConeSize1 == ConeSize2 );
assert( ConeSize1 >= 0 );
return ConeSize1;
......@@ -1193,7 +1206,7 @@ int Gia_NodeMffcSizeSupp( Gia_Man_t * p, Gia_Obj_t * pNode, Vec_Int_t * vSupp )
ConeSize1 = Gia_NodeDeref_rec( p, pNode );
Gia_NodeCollect_rec( p, Gia_ObjFanin0(pNode), vSupp );
Gia_NodeCollect_rec( p, Gia_ObjFanin1(pNode), vSupp );
ConeSize2 = Gia_NodeRef_rec( p, pNode );
ConeSize2 = Gia_NodeRef_rec( p, pNode, 0 );
assert( ConeSize1 == ConeSize2 );
assert( ConeSize1 >= 0 );
return ConeSize1;
......
......@@ -32892,7 +32892,7 @@ int Abc_CommandAbc9ReadSim( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( fOutputs )
{
Vec_WrdFreeP( &pAbc->pGia->vSimsPo );
pAbc->pGia->vSimsPo = Gia_ManSimPatRead( pArgvNew[0], NULL );
pAbc->pGia->vSimsPo = Vec_WrdReadHex( pArgvNew[0], NULL, 1 );
if ( Vec_WrdSize(pAbc->pGia->vSimsPo) % Gia_ManCoNum(pAbc->pGia) != 0 )
{
Vec_WrdFreeP( &pAbc->pGia->vSimsPo );
......@@ -32906,7 +32906,7 @@ int Abc_CommandAbc9ReadSim( Abc_Frame_t * pAbc, int argc, char ** argv )
else
{
Vec_WrdFreeP( &pAbc->pGia->vSimsPi );
pAbc->pGia->vSimsPi = Gia_ManSimPatRead( pArgvNew[0], NULL );
pAbc->pGia->vSimsPi = Vec_WrdReadHex( pArgvNew[0], NULL, 1 );
if ( Vec_WrdSize(pAbc->pGia->vSimsPi) % Gia_ManCiNum(pAbc->pGia) != 0 )
{
Vec_WrdFreeP( &pAbc->pGia->vSimsPi );
......@@ -32988,12 +32988,12 @@ int Abc_CommandAbc9WriteSim( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( fOutputs )
{
assert( Vec_WrdSize(pAbc->pGia->vSimsPo) % Gia_ManCoNum(pAbc->pGia) == 0 );
Gia_ManSimPatWrite( pArgvNew[0], pAbc->pGia->vSimsPo, Vec_WrdSize(pAbc->pGia->vSimsPo) / Gia_ManCoNum(pAbc->pGia) );
Vec_WrdDumpHex( pArgvNew[0], pAbc->pGia->vSimsPo, Vec_WrdSize(pAbc->pGia->vSimsPo) / Gia_ManCoNum(pAbc->pGia), 1 );
}
else
{
assert( Vec_WrdSize(pAbc->pGia->vSimsPi) % Gia_ManCiNum(pAbc->pGia) == 0 );
Gia_ManSimPatWrite( pArgvNew[0], pAbc->pGia->vSimsPi, Vec_WrdSize(pAbc->pGia->vSimsPi) / Gia_ManCiNum(pAbc->pGia) );
Vec_WrdDumpHex( pArgvNew[0], pAbc->pGia->vSimsPi, Vec_WrdSize(pAbc->pGia->vSimsPi) / Gia_ManCiNum(pAbc->pGia), 1 );
}
return 0;
......@@ -47938,7 +47938,7 @@ int Abc_CommandAbc9Test( Abc_Frame_t * pAbc, int argc, char ** argv )
// return 1;
// }
// Abc_FrameUpdateGia( pAbc, Abc_Procedure(pAbc->pGia) );
// Gia_SimQualityTest( pAbc->pGia );
// Gia_ManTryResub( pAbc->pGia );
return 0;
usage:
Abc_Print( -2, "usage: &test [-FW num] [-svh]\n" );
......@@ -63,6 +63,8 @@ struct Vec_Int_t_
for ( i = Vec_IntSize(vVec) - 1; (i >= 0) && (((pEntry) = Vec_IntEntry(vVec, i)), 1); i-- )
#define Vec_IntForEachEntryTwo( vVec1, vVec2, Entry1, Entry2, i ) \
for ( i = 0; (i < Vec_IntSize(vVec1)) && (((Entry1) = Vec_IntEntry(vVec1, i)), 1) && (((Entry2) = Vec_IntEntry(vVec2, i)), 1); i++ )
#define Vec_IntForEachEntryTwoStart( vVec1, vVec2, Entry1, Entry2, i, Start ) \
for ( i = Start; (i < Vec_IntSize(vVec1)) && (((Entry1) = Vec_IntEntry(vVec1, i)), 1) && (((Entry2) = Vec_IntEntry(vVec2, i)), 1); i++ )
#define Vec_IntForEachEntryDouble( vVec, Entry1, Entry2, i ) \
for ( i = 0; (i+1 < Vec_IntSize(vVec)) && (((Entry1) = Vec_IntEntry(vVec, i)), 1) && (((Entry2) = Vec_IntEntry(vVec, i+1)), 1); i += 2 )
#define Vec_IntForEachEntryDoubleStart( vVec, Entry1, Entry2, i, Start ) \
......
......@@ -167,6 +167,32 @@ static inline Vec_Wrd_t * Vec_WrdStartRandom( int nSize )
vSims->pArray[i] = Abc_RandomW(0);
return vSims;
}
static inline Vec_Wrd_t * Vec_WrdStartTruthTables( int nVars )
{
Vec_Wrd_t * p;
unsigned Masks[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 };
int i, k, nWords;
nWords = nVars <= 6 ? 1 : (1 << (nVars - 6));
p = Vec_WrdStart( nWords * nVars );
for ( i = 0; i < nVars; i++ )
{
unsigned * pTruth = (unsigned *)(p->pArray + nWords * i);
if ( i < 5 )
{
for ( k = 0; k < 2*nWords; k++ )
pTruth[k] = Masks[i];
}
else
{
for ( k = 0; k < 2*nWords; k++ )
if ( k & (1 << (i-5)) )
pTruth[k] = ~(unsigned)0;
else
pTruth[k] = 0;
}
}
return p;
}
/**Function*************************************************************
......@@ -1201,6 +1227,99 @@ static inline void Vec_WrdAppend( Vec_Wrd_t * vVec1, Vec_Wrd_t * vVec2 )
Vec_WrdPush( vVec1, Entry );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void Gia_ManSimPatWriteOne( FILE * pFile, word * pSim, int nWords )
{
int k, Digit, nDigits = nWords*16;
for ( k = 0; k < nDigits; k++ )
{
Digit = (int)((pSim[k/16] >> ((k%16) * 4)) & 15);
if ( Digit < 10 )
fprintf( pFile, "%d", Digit );
else
fprintf( pFile, "%c", 'A' + Digit-10 );
}
fprintf( pFile, "\n" );
}
static inline void Vec_WrdPrintHex( Vec_Wrd_t * p, int nWords )
{
int i, nNodes = Vec_WrdSize(p) / nWords;
assert( Vec_WrdSize(p) % nWords == 0 );
for ( i = 0; i < nNodes; i++ )
Gia_ManSimPatWriteOne( stdout, Vec_WrdEntryP(p, i*nWords), nWords );
}
static inline void Vec_WrdDumpHex( char * pFileName, Vec_Wrd_t * p, int nWords, int fVerbose )
{
int i, nNodes = Vec_WrdSize(p) / nWords;
FILE * pFile = fopen( pFileName, "wb" );
if ( pFile == NULL )
{
printf( "Cannot open file \"%s\" for writing.\n", pFileName );
return;
}
assert( Vec_WrdSize(p) % nWords == 0 );
for ( i = 0; i < nNodes; i++ )
Gia_ManSimPatWriteOne( pFile, Vec_WrdEntryP(p, i*nWords), nWords );
fclose( pFile );
if ( fVerbose )
printf( "Written %d words of simulation data for %d objects into file \"%s\".\n", nWords, Vec_WrdSize(p)/nWords, pFileName );
}
static inline int Vec_WrdReadHexOne( char c )
{
int Digit = 0;
if ( c >= '0' && c <= '9' )
Digit = c - '0';
else if ( c >= 'A' && c <= 'F' )
Digit = c - 'A' + 10;
else if ( c >= 'a' && c <= 'f' )
Digit = c - 'a' + 10;
else assert( 0 );
assert( Digit >= 0 && Digit < 16 );
return Digit;
}
static inline Vec_Wrd_t * Vec_WrdReadHex( char * pFileName, int * pnWords, int fVerbose )
{
Vec_Wrd_t * p = NULL;
int c, nWords = -1, nChars = 0; word Num = 0;
FILE * pFile = fopen( pFileName, "rb" );
if ( pFile == NULL )
{
printf( "Cannot open file \"%s\" for reading.\n", pFileName );
return NULL;
}
p = Vec_WrdAlloc( 1000 );
while ( (c = fgetc(pFile)) != EOF )
{
if ( c == '\n' && nWords == -1 )
nWords = Vec_WrdSize(p);
if ( c == '\n' || c == '\r' || c == '\t' || c == ' ' )
continue;
Num |= (word)Vec_WrdReadHexOne((char)c) << (nChars * 4);
if ( ++nChars < 16 )
continue;
Vec_WrdPush( p, Num );
nChars = 0;
Num = 0;
}
assert( Vec_WrdSize(p) % nWords == 0 );
fclose( pFile );
if ( pnWords )
*pnWords = nWords;
if ( fVerbose )
printf( "Read %d words of simulation data for %d objects.\n", nWords, Vec_WrdSize(p)/nWords );
return p;
}
ABC_NAMESPACE_HEADER_END
......
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