Commit a162b1f4 by Alan Mishchenko

Experimental simulation commands.

parent 62180f35
......@@ -1246,11 +1246,17 @@ void Gia_ManSimOneBit( Gia_Man_t * p, Vec_Int_t * vValues )
Gia_ManForEachCo( p, pObj, k )
pObj->fMark0 = Gia_ObjFanin0(pObj)->fMark0 ^ Gia_ObjFaninC0(pObj);
Gia_ManForEachCo( p, pObj, k )
Gia_ManForEachCi( p, pObj, k )
printf( "%d", k % 10 );
printf( "\n" );
Gia_ManForEachCi( p, pObj, k )
printf( "%d", Vec_IntEntry(vValues, k) );
printf( "\n" );
Gia_ManForEachCo( p, pObj, k )
printf( "%d", k % 10 );
printf( "\n" );
Gia_ManForEachCo( p, pObj, k )
printf( "%d", pObj->fMark0 );
printf( "\n" );
printf( "\n" );
......@@ -1309,6 +1315,66 @@ void Gia_ManSimOneBitTest2( Gia_Man_t * p )
Vec_IntFree( vValues );
}
void Gia_ManSimOneBitTest3( Gia_Man_t * p )
{
Vec_Int_t * vValues = Vec_IntStart( Gia_ManCiNum(p) );
Vec_IntWriteEntry( vValues, 0, 1 );
Gia_ManSimOneBit( p, vValues );
Vec_IntFill( vValues, Vec_IntSize(vValues), 0 );
Vec_IntWriteEntry( vValues, 0, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p)/2, 1 );
Gia_ManSimOneBit( p, vValues );
Vec_IntFill( vValues, Vec_IntSize(vValues), 0 );
Vec_IntWriteEntry( vValues, 0, 1 );
Vec_IntWriteEntry( vValues, 1, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p)/2+2, 1 );
Gia_ManSimOneBit( p, vValues );
Vec_IntFill( vValues, Vec_IntSize(vValues), 0 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p)/2-1, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p) -1, 1 );
Gia_ManSimOneBit( p, vValues );
Vec_IntFill( vValues, Vec_IntSize(vValues), 0 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p)/2-1, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p)/2-2, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p) -1, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p) -2, 1 );
Gia_ManSimOneBit( p, vValues );
Vec_IntFill( vValues, Vec_IntSize(vValues), 0 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p)/2-2, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p) -2, 1 );
Gia_ManSimOneBit( p, vValues );
Vec_IntFill( vValues, Vec_IntSize(vValues), 0 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p)/2-1, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p)/2-2, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p)/2-3, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p) -1, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p) -2, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p) -3, 1 );
Gia_ManSimOneBit( p, vValues );
Vec_IntFill( vValues, Vec_IntSize(vValues), 0 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p)/2-2, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p)/2-3, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p) -2, 1 );
Vec_IntWriteEntry( vValues, Gia_ManCiNum(p) -3, 1 );
Gia_ManSimOneBit( p, vValues );
Vec_IntFill( vValues, Vec_IntSize(vValues), 0 );
Vec_IntFill( vValues, Vec_IntSize(vValues), 1 );
Gia_ManSimOneBit( p, vValues );
Vec_IntFill( vValues, Vec_IntSize(vValues), 0 );
Vec_IntFree( vValues );
}
void Gia_ManSimOneBitTest( Gia_Man_t * p )
{
Vec_Int_t * vValues = Vec_IntStart( Gia_ManCiNum(p) );
......
......@@ -2348,6 +2348,55 @@ void Gia_ManSimGen( Gia_Man_t * pGia )
fclose( pFile );
}
/**Function*************************************************************
Synopsis [Trying vectorized simulation.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManSimTwo( Gia_Man_t * p0, Gia_Man_t * p1, int nWords, int nRounds, int fVerbose )
{
Vec_Wrd_t * vSim0, * vSim1, * vSim2;
abctime clk = Abc_Clock();
int n, i, RetValue = 1;
printf( "Simulating %d round with %d machine words.\n", nRounds, nWords );
Abc_RandomW(0);
for ( n = 0; RetValue && n < nRounds; n++ )
{
vSim0 = Vec_WrdStartRandom( Gia_ManCiNum(p0) * nWords );
p0->vSimsPi = vSim0;
p1->vSimsPi = vSim0;
vSim1 = Gia_ManSimPatSim( p0 );
vSim2 = Gia_ManSimPatSim( p1 );
for ( i = 0; i < Gia_ManCoNum(p0); i++ )
{
word * pSim1 = Vec_WrdEntryP(vSim1, Gia_ObjId(p0, Gia_ManCo(p0, i))*nWords);
word * pSim2 = Vec_WrdEntryP(vSim2, Gia_ObjId(p1, Gia_ManCo(p1, i))*nWords);
if ( memcmp(pSim1, pSim2, sizeof(word)*nWords) )
{
printf( "Output %d failed simulation at round %d. ", i, n );
RetValue = 0;
break;
}
}
Vec_WrdFree( vSim1 );
Vec_WrdFree( vSim2 );
Vec_WrdFree( vSim0 );
p0->vSimsPi = NULL;
p1->vSimsPi = NULL;
}
if ( RetValue == 1 )
printf( "Simulation did not detect a bug. " );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
return RetValue;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
......
......@@ -415,6 +415,7 @@ static int Abc_CommandAbc9Cof ( Abc_Frame_t * pAbc, int argc, cha
static int Abc_CommandAbc9Trim ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Dfs ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Sim ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Sim2 ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Sim3 ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9MLGen ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9MLTest ( Abc_Frame_t * pAbc, int argc, char ** argv );
......@@ -1149,6 +1150,7 @@ void Abc_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "ABC9", "&trim", Abc_CommandAbc9Trim, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&dfs", Abc_CommandAbc9Dfs, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&sim", Abc_CommandAbc9Sim, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&sim2", Abc_CommandAbc9Sim2, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&sim3", Abc_CommandAbc9Sim3, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&mlgen", Abc_CommandAbc9MLGen, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&mltest", Abc_CommandAbc9MLTest, 0 );
......@@ -32880,6 +32882,184 @@ usage:
SeeAlso []
***********************************************************************/
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 );
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;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "WRNTvh" ) ) != EOF )
{
switch ( c )
{
case 'W':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-W\" should be followed by an integer.\n" );
goto usage;
}
nWords = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nWords < 0 )
goto usage;
break;
case 'R':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-R\" should be followed by an integer.\n" );
goto usage;
}
nRounds = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nRounds < 0 )
goto usage;
break;
case 'N':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
goto usage;
}
RandSeed = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( RandSeed < 0 )
goto usage;
break;
case 'T':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-T\" should be followed by an integer.\n" );
goto usage;
}
TimeLimit = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( TimeLimit < 0 )
goto usage;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
pArgvNew = argv + globalUtilOptind;
nArgcNew = argc - globalUtilOptind;
if ( nArgcNew > 2 )
{
Abc_Print( -1, "Abc_CommandAbc9Cec(): Wrong number of command-line arguments.\n" );
return 1;
}
if ( nArgcNew == 2 )
{
char * pFileNames[2] = { pArgvNew[0], pArgvNew[1] }, * pTemp;
int n;
for ( n = 0; n < 2; n++ )
{
// fix the wrong symbol
for ( pTemp = pFileNames[n]; *pTemp; pTemp++ )
if ( *pTemp == '>' )
*pTemp = '\\';
if ( (pFile = fopen( pFileNames[n], "r" )) == NULL )
{
Abc_Print( -1, "Cannot open input file \"%s\". ", pFileNames[n] );
if ( (pFileNames[n] = Extra_FileGetSimilarName( pFileNames[n], ".aig", NULL, NULL, NULL, NULL )) )
Abc_Print( 1, "Did you mean \"%s\"?", pFileNames[n] );
Abc_Print( 1, "\n" );
return 1;
}
fclose( pFile );
pGias[n] = Gia_AigerRead( pFileNames[n], 0, 0, 0 );
if ( pGias[n] == NULL )
{
Abc_Print( -1, "Reading AIGER from file \"%s\" has failed.\n", pFileNames[n] );
return 0;
}
}
}
else
{
char * FileName, * pTemp;
if ( pAbc->pGia == NULL )
{
Abc_Print( -1, "Abc_CommandAbc9Cec(): There is no current AIG.\n" );
return 1;
}
pGias[0] = pAbc->pGia;
if ( nArgcNew == 1 )
FileName = pArgvNew[0];
else
{
assert( nArgcNew == 0 );
if ( pAbc->pGia->pSpec == NULL )
{
Abc_Print( -1, "File name is not given on the command line.\n" );
return 1;
}
FileName = pAbc->pGia->pSpec;
}
// fix the wrong symbol
for ( pTemp = FileName; *pTemp; pTemp++ )
if ( *pTemp == '>' )
*pTemp = '\\';
if ( (pFile = fopen( FileName, "r" )) == NULL )
{
Abc_Print( -1, "Cannot open input file \"%s\". ", FileName );
if ( (FileName = Extra_FileGetSimilarName( FileName, ".aig", NULL, NULL, NULL, NULL )) )
Abc_Print( 1, "Did you mean \"%s\"?", FileName );
Abc_Print( 1, "\n" );
return 1;
}
fclose( pFile );
pGias[1] = Gia_AigerRead( FileName, 0, 0, 0 );
if ( pGias[1] == NULL )
{
Abc_Print( -1, "Reading AIGER has failed.\n" );
return 0;
}
}
if ( Gia_ManCiNum(pGias[0]) != Gia_ManCiNum(pGias[1]) )
{
Abc_Print( -1, "The number of CIs does not match.\n" );
return 1;
}
if ( Gia_ManCoNum(pGias[0]) != Gia_ManCoNum(pGias[1]) )
{
Abc_Print( -1, "The number of COs does not match.\n" );
return 1;
}
RetValue = Gia_ManSimTwo( pGias[0], pGias[1], nWords, nRounds, fVerbose );
if ( pGias[0] != pAbc->pGia )
Gia_ManStopP( &pGias[0] );
Gia_ManStopP( &pGias[1] );
return 0;
usage:
Abc_Print( -2, "usage: &sim2 [-WRNT num] [-vh] <file1.aig> <file2.aig>\n" );
Abc_Print( -2, "\t performs random of two circuits\n" );
Abc_Print( -2, "\t-W num : the number of words to simulate [default = %d]\n", nWords );
Abc_Print( -2, "\t-R num : the number of simulation rounds [default = %d]\n", nRounds );
Abc_Print( -2, "\t-N num : random number seed (1 <= num <= 1000) [default = %d]\n", RandSeed );
Abc_Print( -2, "\t-T num : approximate runtime limit in seconds [default = %d]\n", TimeLimit );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_CommandAbc9Sim3( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern int Ssw_RarSimulateGia( Gia_Man_t * p, Ssw_RarPars_t * pPars );
......@@ -345,11 +345,12 @@ void Wlc_BlastFullAdder( Gia_Man_t * pNew, int a, int b, int c, int * pc, int *
if ( fCompl )
*ps = Abc_LitNot(*ps), *pc = Abc_LitNot(*pc);
}
void Wlc_BlastAdder( Gia_Man_t * pNew, int * pAdd0, int * pAdd1, int nBits, int Carry ) // result is in pAdd0
int Wlc_BlastAdder( Gia_Man_t * pNew, int * pAdd0, int * pAdd1, int nBits, int Carry ) // result is in pAdd0
{
int b;
for ( b = 0; b < nBits; b++ )
Wlc_BlastFullAdder( pNew, pAdd0[b], pAdd1[b], Carry, &Carry, &pAdd0[b] );
return Carry;
}
void Wlc_BlastSubtract( Gia_Man_t * pNew, int * pAdd0, int * pAdd1, int nBits, int Carry ) // result is in pAdd0
{
......@@ -1022,7 +1023,7 @@ void Wlc_BlastReduceMatrix2( Gia_Man_t * pNew, Vec_Wec_t * vProds, Vec_Int_t * v
}
void Wlc_BlastMultiplier3( Gia_Man_t * pNew, int * pArgA, int * pArgB, int nArgA, int nArgB, Vec_Int_t * vRes, int fSigned, int fCla )
void Wlc_BlastMultiplier3( Gia_Man_t * pNew, int * pArgA, int * pArgB, int nArgA, int nArgB, Vec_Int_t * vRes, int fSigned, int fCla, Vec_Wec_t ** pvProds )
{
Vec_Wec_t * vProds = Vec_WecStart( nArgA + nArgB );
Vec_Wec_t * vLevels = Vec_WecStart( nArgA + nArgB );
......@@ -1043,7 +1044,10 @@ void Wlc_BlastMultiplier3( Gia_Man_t * pNew, int * pArgA, int * pArgB, int nArgA
Vec_WecPush( vLevels, nArgA+nArgB-1, 0 );
}
Wlc_BlastReduceMatrix( pNew, vProds, vLevels, vRes, fSigned, fCla );
if ( pvProds )
*pvProds = Vec_WecDup(vProds);
else
Wlc_BlastReduceMatrix( pNew, vProds, vLevels, vRes, fSigned, fCla );
// Wlc_BlastReduceMatrix2( pNew, vProds, vRes, fSigned, fCla );
Vec_WecFree( vProds );
......@@ -1086,7 +1090,7 @@ void Wlc_BlastDecoder( Gia_Man_t * pNew, int * pNum, int nNum, Vec_Int_t * vTmp,
Vec_IntPush( vRes, iMint );
}
}
void Wlc_BlastBooth( Gia_Man_t * pNew, int * pArgA, int * pArgB, int nArgA, int nArgB, Vec_Int_t * vRes, int fSigned, int fCla )
void Wlc_BlastBooth( Gia_Man_t * pNew, int * pArgA, int * pArgB, int nArgA, int nArgB, Vec_Int_t * vRes, int fSigned, int fCla, Vec_Wec_t ** pvProds )
{
Vec_Wec_t * vProds = Vec_WecStart( nArgA + nArgB + 3 );
Vec_Wec_t * vLevels = Vec_WecStart( nArgA + nArgB + 3 );
......@@ -1159,9 +1163,11 @@ void Wlc_BlastBooth( Gia_Man_t * pNew, int * pArgA, int * pArgB, int nArgA, int
//Vec_WecPrint( vProds, 0 );
//Wlc_BlastPrintMatrix( pNew, vProds, 1 );
//printf( "Cutoff ID for partial products = %d.\n", Gia_ManObjNum(pNew) );
Wlc_BlastReduceMatrix( pNew, vProds, vLevels, vRes, fSigned, fCla );
// Wlc_BlastReduceMatrix2( pNew, vProds, vRes, fSigned, fCla );
if ( pvProds )
*pvProds = Vec_WecDup(vProds);
else
Wlc_BlastReduceMatrix( pNew, vProds, vLevels, vRes, fSigned, fCla );
// Wlc_BlastReduceMatrix2( pNew, vProds, vRes, fSigned, fCla );
Vec_WecFree( vProds );
Vec_WecFree( vLevels );
Vec_IntFree( vArgB );
......@@ -1792,9 +1798,9 @@ Gia_Man_t * Wlc_NtkBitBlast( Wlc_Ntk_t * p, Wlc_BstPar_t * pParIn )
if ( Wlc_NtkCountConstBits(pArg0, nRangeMax) < Wlc_NtkCountConstBits(pArg1, nRangeMax) )
ABC_SWAP( int *, pArg0, pArg1 );
if ( pPar->fBooth )
Wlc_BlastBooth( pNew, pArg0, pArg1, nRange0, nRange1, vRes, fSigned, pPar->fCla );
Wlc_BlastBooth( pNew, pArg0, pArg1, nRange0, nRange1, vRes, fSigned, pPar->fCla, NULL );
else if ( pPar->fCla )
Wlc_BlastMultiplier3( pNew, pArg0, pArg1, nRange0, nRange1, vRes, Wlc_ObjIsSignedFanin01(p, pObj), pPar->fCla );
Wlc_BlastMultiplier3( pNew, pArg0, pArg1, nRange0, nRange1, vRes, Wlc_ObjIsSignedFanin01(p, pObj), pPar->fCla, NULL );
else
Wlc_BlastMultiplier( pNew, pArg0, pArg1, nRangeMax, nRangeMax, vTemp2, vRes, fSigned );
if ( nRange > Vec_IntSize(vRes) )
......
......@@ -422,7 +422,7 @@ static inline Vec_Wec_t * Vec_WecDup( Vec_Wec_t * p )
Vec_Wec_t * vNew;
Vec_Int_t * vVec;
int i, k, Entry;
vNew = Vec_WecAlloc( Vec_WecSize(p) );
vNew = Vec_WecStart( Vec_WecSize(p) );
Vec_WecForEachLevel( p, vVec, i )
Vec_IntForEachEntry( vVec, Entry, k )
Vec_WecPush( vNew, i, Entry );
......
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