Experimental simulation commands.

This commit is contained in:
Alan Mishchenko 2021-07-25 14:11:34 -07:00
parent 62180f3576
commit a162b1f47a
6 changed files with 579 additions and 71 deletions

View File

@ -1246,10 +1246,16 @@ 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_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" );
@ -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) );

View File

@ -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 ///
////////////////////////////////////////////////////////////////////////

View 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 );
@ -32869,6 +32871,184 @@ usage:
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
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 []

View File

@ -397,102 +397,309 @@ Gia_Man_t * Wlc_ManGenAdder( int nBits )
SeeAlso []
***********************************************************************/
void Wlc_BuildOne32( Gia_Man_t * p, int * pLitIn, int * pLitOut )
{
Wlc_BlastFullAdder( p, pLitIn[0], pLitIn[1], pLitIn[2], &pLitIn[5], &pLitOut[0] );
Wlc_BlastFullAdder( p, pLitIn[3], pLitIn[4], pLitIn[5], &pLitOut[2], &pLitOut[1] );
}
void Wlc_BuildOne51( Gia_Man_t * p, int * pLitIn, int * pLitOut )
{
int Lit00, Lit01, Lit11;
Wlc_BlastFullAdder( p, pLitIn[0], pLitIn[1], pLitIn[2], &Lit01, &Lit00 );
Wlc_BlastFullAdder( p, pLitIn[3], pLitIn[4], Lit00, &Lit11, &pLitOut[0] );
Wlc_BlastFullAdder( p, pLitIn[5], Lit01, Lit11, &pLitOut[2], &pLitOut[1] );
}
void Wlc_BuildOne6( Gia_Man_t * p, int * pLitIn, int Const1, int * pLitOut )
{
int Lit00, Lit01, Lit10, Lit11, Lit12;
Wlc_BlastFullAdder( p, pLitIn[0], pLitIn[1], pLitIn[2], &Lit01, &Lit00 );
Wlc_BlastFullAdder( p, pLitIn[3], pLitIn[4], pLitIn[5], &Lit11, &Lit10 );
Wlc_BlastFullAdder( p, Lit00, Lit10, Const1, &Lit12, &pLitOut[0] );
Wlc_BlastFullAdder( p, Lit01, Lit11, Lit12, &pLitOut[2],&pLitOut[1] );
}
Vec_Wec_t * Wlc_ManGenTree_iter( Gia_Man_t * p, Vec_Wec_t * vBits, int * pCounter )
{
Vec_Wec_t * vBitsNew = Vec_WecStart( Vec_WecSize(vBits) ); int i, k, Count = 0;
Vec_Wec_t * vBitsNew = Vec_WecStart( Vec_WecSize(vBits) );
int i, k, pLitsIn[16], pLitsOut[16], Count = 0, fSimple = Vec_WecMaxLevelSize(vBits) <= 3;
for ( i = 0; i < Vec_WecSize(vBits)-1; i++ )
{
Vec_Int_t * vBits0 = Vec_WecEntry(vBits, i);
Vec_Int_t * vBits1 = Vec_WecEntry(vBits, i+1);
if ( i == 0 )
if ( fSimple )
{
int s = 0;
assert( Vec_IntSize(vBits0) <= 3 );
for ( k = 0; Vec_IntSize(vBits0) > 0; k++ )
pLitsIn[k] = Vec_IntPop( vBits0 );
for ( ; k < 3; k++ )
pLitsIn[k] = 0;
assert( k == 3 );
Wlc_BlastFullAdder( p, pLitsIn[0], pLitsIn[1], pLitsIn[2], &pLitsOut[1], &pLitsOut[0] );
Vec_WecPush( vBitsNew, i+0, pLitsOut[0] );
Vec_WecPush( vBitsNew, i+1, pLitsOut[1] );
Count += 2;
continue;
}
while ( Vec_IntSize(vBits0) >= 6 )
{
for ( k = 0; k < 6; k++ )
Vec_IntPop( vBits0 );
Vec_WecPush( vBitsNew, i+0, 0 );
Vec_WecPush( vBitsNew, i+1, 0 );
Vec_WecPush( vBitsNew, i+2, 0 );
pLitsIn[k] = Vec_IntPop( vBits0 );
assert( k == 6 );
Wlc_BuildOne6( p, pLitsIn, 0, pLitsOut );
Vec_WecPush( vBitsNew, i+0, pLitsOut[0] );
Vec_WecPush( vBitsNew, i+1, pLitsOut[1] );
Vec_WecPush( vBitsNew, i+2, pLitsOut[2] );
Count += 3;
}
if ( Vec_IntSize(vBits0) == 4 || Vec_IntSize(vBits0) == 5 )
if ( Vec_IntSize(vBits0) == 5 && Vec_IntSize(vBits1) > 0 )
{
Vec_IntClear( vBits0 );
if ( Vec_IntSize(vBits1) > 0 )
Vec_IntPop( vBits1 );
Vec_WecPush( vBitsNew, i+0, 0 );
Vec_WecPush( vBitsNew, i+1, 0 );
Vec_WecPush( vBitsNew, i+2, 0 );
for ( k = 0; Vec_IntSize(vBits0) > 0; k++ )
pLitsIn[k] = Vec_IntPop( vBits0 );
pLitsIn[k++] = Vec_IntPop( vBits1 );
assert( k == 6 );
Wlc_BuildOne51( p, pLitsIn, pLitsOut );
Vec_WecPush( vBitsNew, i+0, pLitsOut[0] );
Vec_WecPush( vBitsNew, i+1, pLitsOut[1] );
Vec_WecPush( vBitsNew, i+2, pLitsOut[2] );
Count += 3;
}
//if ( (Vec_IntSize(vBits0) == 2 && Vec_IntSize(vBits1) > 1) || (Vec_IntSize(vBits0) == 3 && Vec_IntSize(vBits1) > 0) )
if ( Vec_IntSize(vBits0) == 3 && Vec_IntSize(vBits1) > 0 )
if ( Vec_IntSize(vBits0) == 5 && Vec_IntSize(vBits1) == 0 )
{
Vec_IntClear( vBits0 );
Vec_IntPop( vBits1 );
if ( Vec_IntSize(vBits1) > 0 )
Vec_IntPop( vBits1 );
if ( Vec_IntSize(vBits1) > 0 )
Vec_IntPop( vBits1 );
Vec_WecPush( vBitsNew, i+0, 0 );
Vec_WecPush( vBitsNew, i+1, 0 );
Vec_WecPush( vBitsNew, i+2, 0 );
for ( k = 0; Vec_IntSize(vBits0) > 0; k++ )
pLitsIn[k] = Vec_IntPop( vBits0 );
pLitsIn[k++] = 0;
assert( k == 6 );
Wlc_BuildOne6( p, pLitsIn, 0, pLitsOut );
Vec_WecPush( vBitsNew, i+0, pLitsOut[0] );
Vec_WecPush( vBitsNew, i+1, pLitsOut[1] );
Vec_WecPush( vBitsNew, i+2, pLitsOut[2] );
Count += 3;
}
if ( Vec_IntSize(vBits0) == 3 && Vec_IntSize(vBits1) == 0 )
if ( Vec_IntSize(vBits0) == 4 && Vec_IntSize(vBits1) > 0 )
{
for ( k = 0; Vec_IntSize(vBits0) > 0; k++ )
pLitsIn[k] = Vec_IntPop( vBits0 );
pLitsIn[k++] = 0;
pLitsIn[k++] = Vec_IntPop( vBits1 );
assert( k == 6 );
Wlc_BuildOne51( p, pLitsIn, pLitsOut );
Vec_WecPush( vBitsNew, i+0, pLitsOut[0] );
Vec_WecPush( vBitsNew, i+1, pLitsOut[1] );
Vec_WecPush( vBitsNew, i+2, pLitsOut[2] );
Count += 3;
}
if ( Vec_IntSize(vBits0) == 3 && Vec_IntSize(vBits1) >= 2 )
{
for ( k = 0; Vec_IntSize(vBits0) > 0; k++ )
pLitsIn[k] = Vec_IntPop( vBits0 );
pLitsIn[k++] = Vec_IntPop( vBits1 );
pLitsIn[k++] = Vec_IntPop( vBits1 );
assert( k == 5 );
Wlc_BuildOne32( p, pLitsIn, pLitsOut );
Vec_WecPush( vBitsNew, i+0, pLitsOut[0] );
Vec_WecPush( vBitsNew, i+1, pLitsOut[1] );
Vec_WecPush( vBitsNew, i+2, pLitsOut[2] );
Count += 3;
}
if ( Vec_IntSize(vBits0) >= 3 )
{
for ( k = 0; k < 3; k++ )
pLitsIn[k] = Vec_IntPop( vBits0 );
assert( k == 3 );
Wlc_BlastFullAdder( p, pLitsIn[0], pLitsIn[1], pLitsIn[2], &pLitsOut[1], &pLitsOut[0] );
Vec_WecPush( vBitsNew, i+0, pLitsOut[0] );
Vec_WecPush( vBitsNew, i+1, pLitsOut[1] );
Count += 2;
}
/*
if ( Vec_IntSize(vBits0) == 2 )
{
Vec_IntClear( vBits0 );
Vec_WecPush( vBitsNew, i+0, 0 );
Vec_WecPush( vBitsNew, i+1, 0 );
Count += 2;
}
/*
if ( Vec_IntSize(vBits0) == 1 && Vec_IntSize(vBits1) > 2 )
{
Vec_IntClear( vBits0 );
Vec_IntPop( vBits1 );
Vec_IntPop( vBits1 );
Vec_IntPop( vBits1 );
Vec_WecPush( vBitsNew, i+0, 0 );
Vec_WecPush( vBitsNew, i+1, 0 );
Vec_WecPush( vBitsNew, i+2, 0 );
}
*/
for ( k = 0; k < Vec_IntSize(vBits0); k++ )
Vec_WecPush( vBitsNew, i, 0 );
Vec_IntClear( vBits0 );
for ( k = 0; Vec_IntSize(vBits0) > 0; k++ )
Vec_WecPush( vBitsNew, i, Vec_IntPop(vBits0) );
}
if ( pCounter )
*pCounter += Count;
*pCounter = Count;
return vBitsNew;
}
Gia_Man_t * Wlc_ManGenTree( int nBits )
void Wlc_ManGenTreeOne( Gia_Man_t * pNew, Vec_Wec_t * vBits0, int fMult, int fVerbose )
{
Gia_Man_t * pTemp, * pNew; int i, iLit, Counter = 0;
Vec_Int_t * vOuts = Vec_IntAlloc( 1000 ), * vLits = Vec_IntAlloc( 1000 );
Vec_Wec_t * vTemp, * vBits = Vec_WecStart( 14 ); // Abc_Base2Log(nBits)+3 );
pNew = Gia_ManStart( 1000 );
pNew->pName = Abc_UtilStrsav( "tree" );
for ( i = 0; i < nBits; i++ )
// Vec_WecPush( vBits, 0, Gia_ManAppendCi(pNew) );
Vec_WecPush( vBits, 0, 0 );
Vec_WecPrint( vBits, 0 );
Gia_ManHashAlloc( pNew );
for ( i = 0; i < 10; i++ )
extern int Wlc_BlastAdder( Gia_Man_t * pNew, int * pAdd0, int * pAdd1, int nBits, int Carry ); // result is in pAdd0
Vec_Wec_t * vTemp, * vBits = Vec_WecDup( vBits0 );
Vec_Int_t * vOuts = Vec_IntAlloc( 1000 ), * vOuts2;
Vec_Int_t * vLits0 = Vec_IntAlloc( 1000 );
Vec_Int_t * vLits1 = Vec_IntAlloc( 1000 );
int i, iLit, nBitsAll = 0, CounterAll = 0, Counter = 1;
for ( i = 0; Counter && i < 1000; i++ )
{
if ( fVerbose ) printf( "LEVEL %d\n", i );
if ( fVerbose ) Vec_WecPrint( vBits, 0 );
if ( Vec_WecMaxLevelSize(vBits) <= 2 )
break;
vBits = Wlc_ManGenTree_iter( pNew, vTemp = vBits, &Counter );
Vec_WecFree( vTemp );
printf( "LEVEL %d\n", i+1 );
Vec_WecPrint( vBits, 0 );
CounterAll += Counter;
}
printf( "Counter = %d.\n", Counter );
Gia_ManHashStop( pNew );
Vec_IntForEachEntry( vOuts, iLit, i )
Gia_ManAppendCo( pNew, iLit );
Vec_IntFree( vLits );
printf( "Total count = %d.\n", CounterAll );
if ( !fMult )
{
int Carry;
/*
Vec_WecForEachLevel( vBits, vOuts2, i )
{
if ( i == 10 )
break;
if ( i == 0 )
{
assert( Vec_IntSize(vOuts2) == 1 );
Vec_IntPush( vOuts, Vec_IntPop(vOuts2) );
continue;
}
assert( Vec_IntSize(vOuts2) == 1 || Vec_IntSize(vOuts2) == 2 );
Vec_IntPush( vLits0, Vec_IntPop(vOuts2) );
if ( Vec_IntSize(vOuts2) == 1 )
Vec_IntPush( vLits1, Vec_IntPop(vOuts2) );
else
{
Vec_IntPush( vLits1, 0 );
}
}
assert( Vec_IntSize(vLits0) == 9 );
assert( Vec_IntSize(vLits1) == 9 );
*/
Vec_WecForEachLevel( vBits, vOuts2, i )
{
if ( Vec_IntSize(vOuts2) == 0 )
break;
assert( Vec_IntSize(vOuts2) == 1 || Vec_IntSize(vOuts2) == 2 );
Vec_IntPush( vLits0, Vec_IntPop(vOuts2) );
if ( Vec_IntSize(vOuts2) == 1 )
Vec_IntPush( vLits1, Vec_IntPop(vOuts2) );
else
Vec_IntPush( vLits1, 0 );
}
printf( "The adder size is %d.\n", Vec_IntSize(vLits0) );
Vec_IntShrink( vLits0, 11 );
Vec_IntShrink( vLits1, 11 );
// vOuts2 = Wlc_ManGenAdder_rec( pNew, 9, Vec_IntArray(vLits0), Vec_IntArray(vLits1), 0, 3 );
// Vec_IntAppend( vOuts, vOuts2 );
// Vec_IntFree( vOuts2 );
Carry = Wlc_BlastAdder( pNew, Vec_IntArray(vLits0), Vec_IntArray(vLits1), 11, 0 );
Vec_IntAppend( vOuts, vLits0 );
Vec_IntPush( vOuts, Carry );
Gia_ManAppendCo( pNew, Vec_IntEntry(vOuts, 11) );
}
else
{
Vec_WecForEachLevel( vBits, vOuts2, i )
{
if ( Vec_IntSize(vOuts2) == 0 )
break;
assert( Vec_IntSize(vOuts2) == 1 || Vec_IntSize(vOuts2) == 2 );
Vec_IntPush( vLits0, Vec_IntPop(vOuts2) );
if ( Vec_IntSize(vOuts2) == 1 )
Vec_IntPush( vLits1, Vec_IntPop(vOuts2) );
else
Vec_IntPush( vLits1, 0 );
}
printf( "The adder size is %d.\n", Vec_IntSize(vLits0) );
Vec_IntShrink( vLits0, Gia_ManCiNum(pNew)+1 ); // mult
Vec_IntShrink( vLits1, Gia_ManCiNum(pNew)+1 ); // mult
for ( nBitsAll = 3; nBitsAll < Vec_IntSize(vLits0); nBitsAll *= 3 )
;
for ( i = Vec_IntSize(vLits0); i < nBitsAll; i++ )
{
Vec_IntPush( vLits0, 0 );
Vec_IntPush( vLits1, 0 );
}
assert( Vec_IntSize(vLits0) == nBitsAll );
assert( Vec_IntSize(vLits1) == nBitsAll );
vOuts2 = Wlc_ManGenAdder_rec( pNew, nBitsAll, Vec_IntArray(vLits0), Vec_IntArray(vLits1), 0, 3 );
Vec_IntAppend( vOuts, vOuts2 );
Vec_IntFree( vOuts2 );
//Carry = Wlc_BlastAdder( pNew, Vec_IntArray(vLits0), Vec_IntArray(vLits1), nBitsAll, 0 );
//Vec_IntAppend( vOuts, vLits0 );
//Vec_IntPush( vOuts, Carry );
Vec_IntShrink( vOuts, Gia_ManCiNum(pNew) ); // mult
//Vec_IntShrink( vOuts, Gia_ManCiNum(pNew)/2 );
Vec_IntForEachEntry( vOuts, iLit, i )
Gia_ManAppendCo( pNew, iLit );
}
Vec_IntFree( vOuts );
Vec_IntFree( vLits0 );
Vec_IntFree( vLits1 );
Vec_WecFree( vBits );
}
Gia_Man_t * Wlc_ManGenTree( int nInputs, int Value, int nBits, int fVerbose )
{
Gia_Man_t * pTemp, * pNew; int i, Counter = 0;
Vec_Wec_t * vBits = Vec_WecStart( nBits+2 );
for ( i = 0; i < nBits+2; i++ )
Vec_WecPush( vBits, i, (Value >> i) & 1 );
pNew = Gia_ManStart( 1000 );
pNew->pName = Abc_UtilStrsav( "tree" );
for ( i = 0; i < nInputs; i++ )
Vec_WecPush( vBits, 0, Gia_ManAppendCi(pNew) );
Gia_ManHashAlloc( pNew );
Wlc_ManGenTreeOne( pNew, vBits, 0, fVerbose );
Gia_ManHashStop( pNew );
Vec_WecFree( vBits );
pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManStop( pTemp );
return pNew;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Wlc_ManGenProd( int nInputs, int fVerbose )
{
extern 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 );
extern 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_Int_t * vIns = Vec_IntAlloc( 2*nInputs );
Gia_Man_t * pTemp, * pNew;
Vec_Wec_t * vProds; int i;
pNew = Gia_ManStart( 1000 );
pNew->pName = Abc_UtilStrsav( "tree" );
for ( i = 0; i < 2*nInputs; i++ )
Vec_IntPush( vIns, Gia_ManAppendCi(pNew) );
//for ( i = 0; i < nInputs; i++ )
// Vec_IntPush( vIns, Gia_ManAppendCi(pNew) );
//for ( i = 0; i < nInputs; i++ )
// Vec_IntPush( vIns, Vec_IntEntry(vIns, i) );
Gia_ManHashAlloc( pNew );
Wlc_BlastBooth( pNew, Vec_IntArray(vIns), Vec_IntArray(vIns)+nInputs, nInputs, nInputs, NULL, 0, 0, &vProds );
//Wlc_BlastMultiplier3( pNew, Vec_IntArray(vIns), Vec_IntArray(vIns)+nInputs, nInputs, nInputs, NULL, 0, 0, &vProds );
//Vec_WecPrint( vProds, 0 );
Wlc_ManGenTreeOne( pNew, vProds, 1, fVerbose );
Gia_ManHashStop( pNew );
Vec_WecFree( vProds );
Vec_IntFree( vIns );
pNew = Gia_ManCleanup( pTemp = pNew );
Gia_ManStop( pTemp );
return pNew;

View File

@ -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) )

View File

@ -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 );