Commit c7bc6b63 by Alan Mishchenko

Experiments with simulation-based engines.

parent a4518e6f
......@@ -205,9 +205,11 @@ struct Gia_Man_t_
int fBuiltInSim;
int iPatsPi;
int nSimWords;
int nSimWordsT;
int iPastPiMax;
int nSimWordsMax;
Vec_Wrd_t * vSims;
Vec_Wrd_t * vSimsT;
Vec_Wrd_t * vSimsPi;
Vec_Wrd_t * vSimsPo;
Vec_Int_t * vClassOld;
......
......@@ -96,6 +96,7 @@ void Gia_ManStop( Gia_Man_t * p )
Vec_IntFreeP( &p->vClassNew );
Vec_IntFreeP( &p->vClassOld );
Vec_WrdFreeP( &p->vSims );
Vec_WrdFreeP( &p->vSimsT );
Vec_WrdFreeP( &p->vSimsPi );
Vec_WrdFreeP( &p->vSimsPo );
Vec_IntFreeP( &p->vTimeStamps );
......
......@@ -496,33 +496,16 @@ unsigned Extra_ReadBinary( char * Buffer )
***********************************************************************/
void Extra_PrintBinary( FILE * pFile, unsigned Sign[], int nBits )
{
int Remainder, nWords;
int w, i;
Remainder = (nBits%(sizeof(unsigned)*8));
nWords = (nBits/(sizeof(unsigned)*8)) + (Remainder>0);
for ( w = nWords-1; w >= 0; w-- )
for ( i = ((w == nWords-1 && Remainder)? Remainder-1: 31); i >= 0; i-- )
fprintf( pFile, "%c", '0' + (int)((Sign[w] & (1<<i)) > 0) );
// fprintf( pFile, "\n" );
int i;
for ( i = nBits-1; i >= 0; i-- )
fprintf( pFile, "%c", '0' + Abc_InfoHasBit(Sign, i) );
// fprintf( pFile, "\n" );
}
void Extra_PrintBinary2( FILE * pFile, unsigned Sign[], int nBits )
{
int Remainder, nWords;
int w, i;
Remainder = (nBits%(sizeof(unsigned)*8));
nWords = (nBits/(sizeof(unsigned)*8)) + (Remainder>0);
for ( w = 0; w < nWords; w++ )
{
int Limit = w == nWords-1 ? Remainder : 32;
for ( i = 0; i < Limit; i++ )
fprintf( pFile, "%c", '0' + (int)((Sign[w] & (1<<i)) > 0) );
}
int i;
for ( i = 0; i < nBits; i++ )
fprintf( pFile, "%c", '0' + Abc_InfoHasBit(Sign, i) );
// fprintf( pFile, "\n" );
}
......
......@@ -2594,6 +2594,19 @@ static inline void Extra_Transpose64Simple( word A[64], word B[64] )
if ( (A[i] >> k) & 1 )
B[k] |= ((word)1 << (63-i));
}
static inline void Extra_BitMatrixTransposeSimple( Vec_Wrd_t * vSimsIn, int nWordsIn, Vec_Wrd_t * vSimsOut, int nWordsOut )
{
int i, k;
assert( Vec_WrdSize(vSimsIn) == nWordsIn * nWordsOut * 64 );
assert( Vec_WrdSize(vSimsIn) == Vec_WrdSize(vSimsOut) );
assert( Vec_WrdSize(vSimsIn) % nWordsIn == 0 );
assert( Vec_WrdSize(vSimsOut) % nWordsOut == 0 );
Vec_WrdFill( vSimsOut, Vec_WrdSize(vSimsOut), 0 );
for ( i = 0; i < 64*nWordsOut; i++ )
for ( k = 0; k < 64*nWordsIn; k++ )
if ( Abc_InfoHasBit( (unsigned *)Vec_WrdEntryP(vSimsIn, i*nWordsIn), k ) )
Abc_InfoSetBit( (unsigned *)Vec_WrdEntryP(vSimsOut, k*nWordsOut), i );
}
void Extra_Transpose32( unsigned a[32] )
{
int j, k;
......@@ -2642,13 +2655,13 @@ void Extra_BitMatrixTransposeP( Vec_Wrd_t * vSimsIn, int nWordsIn, Vec_Wrd_t * v
assert( Vec_WrdSize(vSimsIn) == Vec_WrdSize(vSimsOut) );
assert( Vec_WrdSize(vSimsIn) / nWordsIn == 64 * nWordsOut );
assert( Vec_WrdSize(vSimsOut) / nWordsOut == 64 * nWordsIn );
for ( y = 0; y < nWordsIn; y++ )
for ( x = 0; x < nWordsOut; x++ )
for ( y = 0; y < nWordsIn; y++ )
{
for ( i = 0; i < 64; i++ )
{
pM[i] = Vec_WrdEntryP( vSimsOut, (64*y+i)*nWordsOut + x );
pM[i][0] = Vec_WrdEntry ( vSimsIn, (64*x+i)*nWordsIn + y );
pM[i] = Vec_WrdEntryP( vSimsOut, (64*y+63-i)*nWordsOut + x );
pM[i][0] = Vec_WrdEntry ( vSimsIn, (64*x+63-i)*nWordsIn + y );
}
Extra_Transpose64p( pM );
}
......@@ -2657,8 +2670,8 @@ void Extra_BitMatrixTransposePP( Vec_Ptr_t * vSimsIn, int nWordsIn, Vec_Wrd_t *
{
word * pM[64]; int i, y, x;
assert( Vec_WrdSize(vSimsOut) / nWordsOut == 64 * nWordsIn );
for ( y = 0; y < nWordsIn; y++ )
for ( x = 0; x < nWordsOut; x++ )
for ( y = 0; y < nWordsIn; y++ )
{
for ( i = 0; i < 64; i++ )
{
......@@ -2668,51 +2681,51 @@ void Extra_BitMatrixTransposePP( Vec_Ptr_t * vSimsIn, int nWordsIn, Vec_Wrd_t *
Extra_Transpose64p( pM );
}
}
void Extra_BitMatrixTransposeTest()
{
int nWordsIn = 1;
int nWordsOut = 2;
int i, k, nItems = 64 * nWordsIn * nWordsOut;
Vec_Wrd_t * vSimsIn = Vec_WrdStart( nItems );
Vec_Wrd_t * vSimsOut = Vec_WrdStart( nItems );
Abc_RandomW(1);
for ( i = 0; i < nItems; i++ )
Vec_WrdWriteEntry( vSimsIn, i, Abc_RandomW(0) );
Extra_BitMatrixTransposeP( vSimsIn, nWordsIn, vSimsOut, nWordsOut );
nItems = Vec_WrdSize(vSimsIn) / nWordsIn;
for ( i = 0; i < nItems; i++ )
void Extra_BitMatrixShow( Vec_Wrd_t * vSims, int nWords )
{
int i, k, nBits = Vec_WrdSize(vSims) / nWords;
for ( i = 0; i < nBits; i++ )
{
if ( i%64 == 0 )
Abc_Print( 1, "\n" );
for ( k = 0; k < nWordsIn; k++ )
for ( k = 0; k < nWords; k++ )
{
Extra_PrintBinary( stdout, (unsigned *)Vec_WrdEntryP(vSimsIn, i*nWordsIn+k), 64 );
Extra_PrintBinary2( stdout, (unsigned *)Vec_WrdEntryP(vSims, i*nWords+k), 64 );
Abc_Print( 1, " " );
}
Abc_Print( 1, "\n" );
}
Abc_Print( 1, "\n" );
}
void Extra_BitMatrixTransposeTest()
{
abctime clk = Abc_Clock();
nItems = Vec_WrdSize(vSimsOut) / nWordsOut;
for ( i = 0; i < nItems; i++ )
{
if ( i%64 == 0 )
Abc_Print( 1, "\n" );
for ( k = 0; k < nWordsOut; k++ )
{
Extra_PrintBinary( stdout, (unsigned *)Vec_WrdEntryP(vSimsOut, i*nWordsOut+k), 64 );
Abc_Print( 1, " " );
}
Abc_Print( 1, "\n" );
}
Abc_Print( 1, "\n" );
int nWordsIn = 100;
int nWordsOut = 200;
int nItems = 64 * nWordsIn * nWordsOut;
Vec_Wrd_t * vSimsIn = Vec_WrdStartRandom( nItems );
Vec_Wrd_t * vSimsOut = Vec_WrdStart( nItems );
Vec_Wrd_t * vSimsOut2 = Vec_WrdStart( nItems );
Extra_BitMatrixTransposeP ( vSimsIn, nWordsIn, vSimsOut, nWordsOut );
Extra_BitMatrixTransposeSimple( vSimsIn, nWordsIn, vSimsOut2, nWordsOut );
if ( memcmp( Vec_WrdArray(vSimsOut), Vec_WrdArray(vSimsOut2), sizeof(word)*Vec_WrdSize(vSimsOut) ) )
printf( "Verification failed.\n" );
else
printf( "Verification succeeded.\n" );
//Extra_BitMatrixShow( vSimsIn, nWordsIn );
//Extra_BitMatrixShow( vSimsOut, nWordsOut );
//Extra_BitMatrixShow( vSimsOut2, nWordsOut );
Vec_WrdFree( vSimsIn );
Vec_WrdFree( vSimsOut );
Vec_WrdFree( vSimsOut2 );
Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
}
////////////////////////////////////////////////////////////////////////
......
......@@ -1842,6 +1842,16 @@ static inline int Abc_TtCountOnesVecXor( word * x, word * y, int nWords )
Count += Abc_TtCountOnes( x[w] ^ y[w] );
return Count;
}
static inline int Abc_TtAndXorSum( word * pOut, word * pIn1, word * pIn2, int nWords )
{
int w, Count = 0;
for ( w = 0; w < nWords; w++ )
{
pOut[w] &= pIn1[w] ^ pIn2[w];
Count += Abc_TtCountOnes( pOut[w] );
}
return Count;
}
/**Function*************************************************************
......
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