Commit 6da21b8b by Alan Mishchenko

Experiments with SAT-based cube enumeration.

parent ddc522a0
......@@ -1583,6 +1583,10 @@ SOURCE=.\src\sat\bmc\bmcFault.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\bmc\bmcFx.c
# End Source File
# Begin Source File
SOURCE=.\src\sat\bmc\bmcICheck.c
# End Source File
# Begin Source File
......
......@@ -426,6 +426,39 @@ Gia_Man_t * Gia_ManDupOrderAiger( Gia_Man_t * p )
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManDupOnsetOffset( Gia_Man_t * p )
{
Gia_Man_t * pNew;
Gia_Obj_t * pObj;
int i;
pNew = Gia_ManStart( Gia_ManObjNum(p) );
pNew->pName = Abc_UtilStrsav( p->pName );
pNew->pSpec = Abc_UtilStrsav( p->pSpec );
Gia_ManConst0(p)->Value = 0;
Gia_ManForEachCi( p, pObj, i )
pObj->Value = Gia_ManAppendCi(pNew);
Gia_ManForEachAnd( p, pObj, i )
pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
Gia_ManForEachCo( p, pObj, i )
{
pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
pObj->Value = Gia_ManAppendCo( pNew, Abc_LitNot(Gia_ObjFanin0Copy(pObj)) );
}
Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
return pNew;
}
/**Function*************************************************************
Synopsis [Duplicates AIG while putting first PIs, then nodes, then POs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_Man_t * Gia_ManDupLastPis( Gia_Man_t * p, int nLastPis )
{
Gia_Man_t * pNew;
......
......@@ -346,9 +346,9 @@ Cnf_Dat_t * Mf_ManDeriveCnf( Mf_Man_t * p, int fCnfObjIds, int fAddOrCla )
Gia_ManForEachAndReverseId( p->pGia, Id )
if ( Mf_ObjMapRefNum(p, Id) )
Vec_IntWriteEntry( vCnfIds, Id, Id ), iVar++;
Vec_IntWriteEntry( vCnfIds, 0, 0 );
Gia_ManForEachCiId( p->pGia, Id, i )
Vec_IntWriteEntry( vCnfIds, Id, Id );
Vec_IntWriteEntry( vCnfIds, 0, 0 );
assert( iVar == nVars );
}
else
......@@ -358,9 +358,9 @@ Cnf_Dat_t * Mf_ManDeriveCnf( Mf_Man_t * p, int fCnfObjIds, int fAddOrCla )
Gia_ManForEachAndReverseId( p->pGia, Id )
if ( Mf_ObjMapRefNum(p, Id) )
Vec_IntWriteEntry( vCnfIds, Id, iVar++ );
Vec_IntWriteEntry( vCnfIds, 0, iVar++ );
Gia_ManForEachCiId( p->pGia, Id, i )
Vec_IntWriteEntry( vCnfIds, Id, iVar++ );
Vec_IntWriteEntry( vCnfIds, 0, iVar++ );
assert( iVar == nVars );
}
// generate CNF
......
......@@ -75,7 +75,7 @@ int Gia_ManSatEnum( Gia_Man_t * pGia, int nConfLimit, int nTimeOut, int fVerbose
abctime clkStart = Abc_Clock();
pCnf = Mf_ManGenerateCnf( pGia, 8, 0, 1, 0 );
pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 );
iParVarBeg = pCnf->nVars - Gia_ManPiNum(pGia) - 1;
iParVarBeg = pCnf->nVars - Gia_ManPiNum(pGia);// - 1;
Cnf_DataFree( pCnf );
// iterate through the SAT assignment
vLits = Vec_IntAlloc( Gia_ManPiNum(pGia) );
......@@ -180,7 +180,7 @@ Qbf_Man_t * Gia_QbfAlloc( Gia_Man_t * pGia, int nPars, int fVerbose )
p->nPars = nPars;
p->nVars = Gia_ManPiNum(pGia) - nPars;
p->fVerbose = fVerbose;
p->iParVarBeg = pCnf->nVars - Gia_ManPiNum(pGia) - 1;
p->iParVarBeg = pCnf->nVars - Gia_ManPiNum(pGia);// - 1;
p->pSatVer = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 );
p->pSatSyn = sat_solver_new();
p->vValues = Vec_IntAlloc( Gia_ManPiNum(pGia) );
......@@ -280,7 +280,7 @@ Gia_Man_t * Gia_QbfCofactor( Gia_Man_t * p, int nPars, Vec_Int_t * vValues, Vec_
int Gia_QbfAddCofactor( Qbf_Man_t * p, Gia_Man_t * pCof )
{
Cnf_Dat_t * pCnf = Mf_ManGenerateCnf( pCof, 8, 0, 1, 0 );
int i, iFirstVar = sat_solver_nvars(p->pSatSyn) + pCnf->nVars - Gia_ManPiNum(pCof) - 1;
int i, iFirstVar = sat_solver_nvars(p->pSatSyn) + pCnf->nVars - Gia_ManPiNum(pCof);// - 1;
pCnf->pMan = NULL;
Cnf_DataLift( pCnf, sat_solver_nvars(p->pSatSyn) );
for ( i = 0; i < pCnf->nClauses; i++ )
......
......@@ -437,6 +437,7 @@ static int Abc_CommandAbc9ICheck ( Abc_Frame_t * pAbc, int argc, cha
static int Abc_CommandAbc9SatTest ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9FFTest ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Qbf ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9SatFx ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Inse ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Maxi ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAbc9Bmci ( Abc_Frame_t * pAbc, int argc, char ** argv );
......@@ -1043,6 +1044,7 @@ void Abc_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "ABC9", "&sattest", Abc_CommandAbc9SatTest, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&fftest", Abc_CommandAbc9FFTest, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&qbf", Abc_CommandAbc9Qbf, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&satfx", Abc_CommandAbc9SatFx, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&inse", Abc_CommandAbc9Inse, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&maxi", Abc_CommandAbc9Maxi, 0 );
Cmd_CommandAdd( pAbc, "ABC9", "&bmci", Abc_CommandAbc9Bmci, 0 );
......@@ -36545,6 +36547,72 @@ usage:
SeeAlso []
***********************************************************************/
int Abc_CommandAbc9SatFx( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern int Bmc_FxCompute( Gia_Man_t * p );
extern int Bmc_FxComputeOne( Gia_Man_t * p );
int c, nFrames = 1000, fDec = 0, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "Fdvh" ) ) != EOF )
{
switch ( c )
{
case 'F':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-F\" should be followed by an integer.\n" );
goto usage;
}
nFrames = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nFrames < 0 )
goto usage;
break;
case 'd':
fDec ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( pAbc->pGia == NULL )
{
Abc_Print( -1, "Abc_CommandAbc9SatFx(): There is no AIG.\n" );
return 0;
}
if ( fDec )
Bmc_FxComputeOne( pAbc->pGia );
else
Bmc_FxCompute( pAbc->pGia );
return 0;
usage:
Abc_Print( -2, "usage: &satfx [-F num] [-dvh]\n" );
Abc_Print( -2, "\t performs SAT based shared logic extraction\n" );
Abc_Print( -2, "\t-F num : the number of timeframes [default = %d]\n", nFrames );
Abc_Print( -2, "\t-d : toggles decomposing the first output [default = %s]\n", fDec? "yes": "no" );
Abc_Print( -2, "\t-v : toggles 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_CommandAbc9Inse( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Vec_Int_t * Gia_ManInseTest( Gia_Man_t * p, Vec_Int_t * vInit, int nFrames, int nWords, int nTimeOut, int fSim, int fVerbose );
......@@ -54,10 +54,11 @@ void * If_ManSatBuildXY( int nLutSize )
sat_solver_setnvars( p, nVars );
for ( m = 0; m < nMintsF; m++ )
sat_solver_add_mux( p,
iVarM + m,
iVarP0 + m % nMintsL,
iVarP1 + 2 * (m / nMintsL) + 1,
iVarP1 + 2 * (m / nMintsL),
iVarM + m );
0, 0, 0, 0 );
return p;
}
void * If_ManSatBuildXYZ( int nLutSize )
......@@ -73,13 +74,13 @@ void * If_ManSatBuildXYZ( int nLutSize )
sat_solver_setnvars( p, nVars );
for ( m = 0; m < nMintsF; m++ )
sat_solver_add_mux41( p,
iVarM + m,
iVarP0 + m % nMintsL,
iVarP1 + (m >> nLutSize) % nMintsL,
iVarP2 + 4 * (m >> (2 * nLutSize)) + 0,
iVarP2 + 4 * (m >> (2 * nLutSize)) + 1,
iVarP2 + 4 * (m >> (2 * nLutSize)) + 2,
iVarP2 + 4 * (m >> (2 * nLutSize)) + 3,
iVarM + m );
iVarP2 + 4 * (m >> (2 * nLutSize)) + 3 );
return p;
}
void If_ManSatUnbuild( void * p )
......
......@@ -138,7 +138,6 @@ static inline Cnf_Dat_t * Cnf_DeriveGiaRemapped( Gia_Man_t * p )
int Bmc_EcoSolve( sat_solver * pSat, int Root, Vec_Int_t * vVars )
{
int nBTLimit = 1000000;
Vec_Int_t * vValues = Vec_IntAlloc( Vec_IntSize(vVars) );
Vec_Int_t * vLits = Vec_IntAlloc( Vec_IntSize(vVars) );
int status, i, Div, iVar, nFinal, * pFinal, nIter = 0, RetValue = 0;
int pLits[2], nVars = sat_solver_nvars( pSat );
......@@ -154,10 +153,6 @@ int Bmc_EcoSolve( sat_solver * pSat, int Root, Vec_Int_t * vVars )
if ( status == l_False )
{ RetValue = 1; break; }
assert( status == l_True );
// remember variable values
Vec_IntClear( vValues );
Vec_IntForEachEntry( vVars, iVar, i )
Vec_IntPush( vValues, sat_solver_var_value(pSat, iVar) );
// collect divisor literals
Vec_IntClear( vLits );
Vec_IntPush( vLits, Abc_LitNot(pLits[0]) ); // F = 0
......@@ -189,7 +184,6 @@ int Bmc_EcoSolve( sat_solver * pSat, int Root, Vec_Int_t * vVars )
nIter++;
}
// assert( status == l_True );
Vec_IntFree( vValues );
Vec_IntFree( vLits );
return RetValue;
}
......
......@@ -374,53 +374,53 @@ static inline int sat_solver_add_xor( sat_solver * pSat, int iVarA, int iVarB, i
assert( Cid );
return 4;
}
static inline int sat_solver_add_mux( sat_solver * pSat, int iVarC, int iVarT, int iVarE, int iVarZ )
static inline int sat_solver_add_mux( sat_solver * pSat, int iVarZ, int iVarC, int iVarT, int iVarE, int iComplC, int iComplT, int iComplE, int iComplZ )
{
lit Lits[3];
int Cid;
assert( iVarC >= 0 && iVarT >= 0 && iVarE >= 0 && iVarZ >= 0 );
Lits[0] = toLitCond( iVarC, 1 );
Lits[1] = toLitCond( iVarT, 1 );
Lits[0] = toLitCond( iVarC, 1 ^ iComplC );
Lits[1] = toLitCond( iVarT, 1 ^ iComplT );
Lits[2] = toLitCond( iVarZ, 0 );
Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
assert( Cid );
Lits[0] = toLitCond( iVarC, 1 );
Lits[1] = toLitCond( iVarT, 0 );
Lits[2] = toLitCond( iVarZ, 1 );
Lits[0] = toLitCond( iVarC, 1 ^ iComplC );
Lits[1] = toLitCond( iVarT, 0 ^ iComplT );
Lits[2] = toLitCond( iVarZ, 1 ^ iComplZ );
Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
assert( Cid );
Lits[0] = toLitCond( iVarC, 0 );
Lits[1] = toLitCond( iVarE, 1 );
Lits[2] = toLitCond( iVarZ, 0 );
Lits[0] = toLitCond( iVarC, 0 ^ iComplC );
Lits[1] = toLitCond( iVarE, 1 ^ iComplE );
Lits[2] = toLitCond( iVarZ, 0 ^ iComplZ );
Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
assert( Cid );
Lits[0] = toLitCond( iVarC, 0 );
Lits[1] = toLitCond( iVarE, 0 );
Lits[2] = toLitCond( iVarZ, 1 );
Lits[0] = toLitCond( iVarC, 0 ^ iComplC );
Lits[1] = toLitCond( iVarE, 0 ^ iComplE );
Lits[2] = toLitCond( iVarZ, 1 ^ iComplZ );
Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
assert( Cid );
if ( iVarT == iVarE )
return 4;
Lits[0] = toLitCond( iVarT, 0 );
Lits[1] = toLitCond( iVarE, 0 );
Lits[2] = toLitCond( iVarZ, 1 );
Lits[0] = toLitCond( iVarT, 0 ^ iComplT );
Lits[1] = toLitCond( iVarE, 0 ^ iComplE );
Lits[2] = toLitCond( iVarZ, 1 ^ iComplZ );
Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
assert( Cid );
Lits[0] = toLitCond( iVarT, 1 );
Lits[1] = toLitCond( iVarE, 1 );
Lits[2] = toLitCond( iVarZ, 0 );
Lits[0] = toLitCond( iVarT, 1 ^ iComplT );
Lits[1] = toLitCond( iVarE, 1 ^ iComplE );
Lits[2] = toLitCond( iVarZ, 0 ^ iComplZ );
Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
assert( Cid );
return 6;
}
static inline int sat_solver_add_mux41( sat_solver * pSat, int iVarC0, int iVarC1, int iVarD0, int iVarD1, int iVarD2, int iVarD3, int iVarZ )
static inline int sat_solver_add_mux41( sat_solver * pSat, int iVarZ, int iVarC0, int iVarC1, int iVarD0, int iVarD1, int iVarD2, int iVarD3 )
{
lit Lits[4];
int Cid;
......
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