mirror of https://github.com/YosysHQ/abc.git
Improvements to BMS.
This commit is contained in:
parent
db1daf7b8a
commit
ea3836ea5d
|
|
@ -65,7 +65,9 @@ struct Ses_Man_t_
|
||||||
int nSpecWords; /* number of words for function */
|
int nSpecWords; /* number of words for function */
|
||||||
int nRows; /* number of rows in the specification (without 0) */
|
int nRows; /* number of rows in the specification (without 0) */
|
||||||
int nMaxDepth; /* maximum depth (-1 if depth is not constrained) */
|
int nMaxDepth; /* maximum depth (-1 if depth is not constrained) */
|
||||||
|
int nMaxDepthTmp; /* temporary copy to modify nMaxDepth temporarily */
|
||||||
int * pArrTimeProfile; /* arrival times of inputs (NULL if arrival times are ignored) */
|
int * pArrTimeProfile; /* arrival times of inputs (NULL if arrival times are ignored) */
|
||||||
|
int pArrTimeProfileTmp[8]; /* temporary copy to modify pArrTimeProfile temporarily */
|
||||||
int nArrTimeDelta; /* delta to the original arrival times (arrival times are normalized to have 0 as minimum element) */
|
int nArrTimeDelta; /* delta to the original arrival times (arrival times are normalized to have 0 as minimum element) */
|
||||||
int nArrTimeMax; /* maximum normalized arrival time */
|
int nArrTimeMax; /* maximum normalized arrival time */
|
||||||
int nBTLimit; /* conflict limit */
|
int nBTLimit; /* conflict limit */
|
||||||
|
|
@ -76,6 +78,7 @@ struct Ses_Man_t_
|
||||||
int fSatVerbose; /* be verbose about SAT solving */
|
int fSatVerbose; /* be verbose about SAT solving */
|
||||||
|
|
||||||
int nGates; /* number of gates */
|
int nGates; /* number of gates */
|
||||||
|
int fDecStructure; /* set to 1 or higher if nSpecFunc = 1 and f = x_i OP g(X \ {x_i}), otherwise 0 (determined when solving) */
|
||||||
|
|
||||||
int nSimVars; /* number of simulation vars x(i, t) */
|
int nSimVars; /* number of simulation vars x(i, t) */
|
||||||
int nOutputVars; /* number of output variables g(h, i) */
|
int nOutputVars; /* number of output variables g(h, i) */
|
||||||
|
|
@ -322,6 +325,60 @@ static inline void Ses_StorePrintDebugEntry( Ses_Store_t * pStore, word * pTruth
|
||||||
fprintf( pStore->pDebugEntries, "\"\n" );
|
fprintf( pStore->pDebugEntries, "\"\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Abc_ExactNormalizeArrivalTimesForNetwork( int nVars, int * pArrTimeProfile, char * pSol )
|
||||||
|
{
|
||||||
|
int nGates, i, j, k, nMax;
|
||||||
|
Vec_Int_t * vLevels;
|
||||||
|
|
||||||
|
nGates = pSol[ABC_EXACT_SOL_NGATES];
|
||||||
|
|
||||||
|
/* printf( "NORMALIZE\n" ); */
|
||||||
|
/* printf( " #vars = %d\n", nVars ); */
|
||||||
|
/* printf( " #gates = %d\n", nGates ); */
|
||||||
|
|
||||||
|
vLevels = Vec_IntAllocArrayCopy( pArrTimeProfile, nVars );
|
||||||
|
|
||||||
|
/* compute level of each gate based on arrival time profile (to compute depth) */
|
||||||
|
for ( i = 0; i < nGates; ++i )
|
||||||
|
{
|
||||||
|
j = pSol[3 + i * 4 + 2];
|
||||||
|
k = pSol[3 + i * 4 + 3];
|
||||||
|
|
||||||
|
Vec_IntPush( vLevels, Abc_MaxInt( Vec_IntEntry( vLevels, j ), Vec_IntEntry( vLevels, k ) ) + 1 );
|
||||||
|
|
||||||
|
/* printf( " gate %d = (%d,%d)\n", nVars + i, j, k ); */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Vec_IntPrint( vLevels ); */
|
||||||
|
|
||||||
|
/* reset all levels except for the last one */
|
||||||
|
for ( i = 0; i < nVars + nGates - 1; ++i )
|
||||||
|
Vec_IntSetEntry( vLevels, i, Vec_IntEntry( vLevels, nVars + nGates - 1 ) );
|
||||||
|
|
||||||
|
/* Vec_IntPrint( vLevels ); */
|
||||||
|
|
||||||
|
/* compute levels from top to bottom */
|
||||||
|
for ( i = nGates - 1; i >= 0; --i )
|
||||||
|
{
|
||||||
|
j = pSol[3 + i * 4 + 2];
|
||||||
|
k = pSol[3 + i * 4 + 3];
|
||||||
|
|
||||||
|
Vec_IntSetEntry( vLevels, j, Abc_MinInt( Vec_IntEntry( vLevels, j ), Vec_IntEntry( vLevels, nVars + i ) - 1 ) );
|
||||||
|
Vec_IntSetEntry( vLevels, k, Abc_MinInt( Vec_IntEntry( vLevels, k ), Vec_IntEntry( vLevels, nVars + i ) - 1 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Vec_IntPrint( vLevels ); */
|
||||||
|
|
||||||
|
/* normalize arrival times */
|
||||||
|
Abc_NormalizeArrivalTimes( Vec_IntArray( vLevels ), nVars, &nMax );
|
||||||
|
memcpy( pArrTimeProfile, Vec_IntArray( vLevels ), sizeof(int) * nVars );
|
||||||
|
|
||||||
|
/* printf( " nMax = %d\n", nMax ); */
|
||||||
|
/* Vec_IntPrint( vLevels ); */
|
||||||
|
|
||||||
|
Vec_IntFree( vLevels );
|
||||||
|
}
|
||||||
|
|
||||||
// pArrTimeProfile is normalized
|
// pArrTimeProfile is normalized
|
||||||
// returns 1 if and only if a new TimesEntry has been created
|
// returns 1 if and only if a new TimesEntry has been created
|
||||||
int Ses_StoreAddEntry( Ses_Store_t * pStore, word * pTruth, int nVars, int * pArrTimeProfile, char * pSol, int fResLimit )
|
int Ses_StoreAddEntry( Ses_Store_t * pStore, word * pTruth, int nVars, int * pArrTimeProfile, char * pSol, int fResLimit )
|
||||||
|
|
@ -330,6 +387,9 @@ int Ses_StoreAddEntry( Ses_Store_t * pStore, word * pTruth, int nVars, int * pAr
|
||||||
Ses_TruthEntry_t * pTEntry;
|
Ses_TruthEntry_t * pTEntry;
|
||||||
Ses_TimesEntry_t * pTiEntry;
|
Ses_TimesEntry_t * pTiEntry;
|
||||||
|
|
||||||
|
if ( pSol )
|
||||||
|
Abc_ExactNormalizeArrivalTimesForNetwork( nVars, pArrTimeProfile, pSol );
|
||||||
|
|
||||||
key = Ses_StoreTableHash( pTruth, nVars );
|
key = Ses_StoreTableHash( pTruth, nVars );
|
||||||
pTEntry = pStore->pEntries[key];
|
pTEntry = pStore->pEntries[key];
|
||||||
|
|
||||||
|
|
@ -417,7 +477,7 @@ int Ses_StoreAddEntry( Ses_Store_t * pStore, word * pTruth, int nVars, int * pAr
|
||||||
|
|
||||||
// pArrTimeProfile is normalized
|
// pArrTimeProfile is normalized
|
||||||
// returns 1 if entry was in store, pSol may still be 0 if it couldn't be computed
|
// returns 1 if entry was in store, pSol may still be 0 if it couldn't be computed
|
||||||
int Ses_StoreGetEntry( Ses_Store_t * pStore, word * pTruth, int nVars, int * pArrTimeProfile, char ** pSol )
|
int Ses_StoreGetEntrySimple( Ses_Store_t * pStore, word * pTruth, int nVars, int * pArrTimeProfile, char ** pSol )
|
||||||
{
|
{
|
||||||
int key;
|
int key;
|
||||||
Ses_TruthEntry_t * pTEntry;
|
Ses_TruthEntry_t * pTEntry;
|
||||||
|
|
@ -457,6 +517,57 @@ int Ses_StoreGetEntry( Ses_Store_t * pStore, word * pTruth, int nVars, int * pAr
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Ses_StoreGetEntry( Ses_Store_t * pStore, word * pTruth, int nVars, int * pArrTimeProfile, char ** pSol )
|
||||||
|
{
|
||||||
|
int key;
|
||||||
|
Ses_TruthEntry_t * pTEntry;
|
||||||
|
Ses_TimesEntry_t * pTiEntry;
|
||||||
|
int pTimes[8];
|
||||||
|
|
||||||
|
key = Ses_StoreTableHash( pTruth, nVars );
|
||||||
|
pTEntry = pStore->pEntries[key];
|
||||||
|
|
||||||
|
/* find truth table entry */
|
||||||
|
while ( pTEntry )
|
||||||
|
{
|
||||||
|
if ( Ses_StoreTruthEqual( pTEntry, pTruth, nVars ) )
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
pTEntry = pTEntry->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* no entry found? */
|
||||||
|
if ( !pTEntry )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* find times entry */
|
||||||
|
pTiEntry = pTEntry->head;
|
||||||
|
while ( pTiEntry )
|
||||||
|
{
|
||||||
|
/* found after normalization wrt. to network */
|
||||||
|
if ( pTiEntry->pNetwork )
|
||||||
|
{
|
||||||
|
memcpy( pTimes, pArrTimeProfile, sizeof(int) * nVars );
|
||||||
|
Abc_ExactNormalizeArrivalTimesForNetwork( nVars, pTimes, pTiEntry->pNetwork );
|
||||||
|
|
||||||
|
if ( Ses_StoreTimesEqual( pTimes, pTiEntry->pArrTimeProfile, nVars ) )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* found for non synthesized network */
|
||||||
|
else if ( Ses_StoreTimesEqual( pArrTimeProfile, pTiEntry->pArrTimeProfile, nVars ) )
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
pTiEntry = pTiEntry->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* no entry found? */
|
||||||
|
if ( !pTiEntry )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
*pSol = pTiEntry->pNetwork;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void Ses_StoreWrite( Ses_Store_t * pStore, const char * pFilename, int fSynthImp, int fSynthRL, int fUnsynthImp, int fUnsynthRL )
|
static void Ses_StoreWrite( Ses_Store_t * pStore, const char * pFilename, int fSynthImp, int fSynthRL, int fUnsynthImp, int fUnsynthRL )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -763,7 +874,7 @@ static int Ses_ManCreateClauses( Ses_Man_t * pSes )
|
||||||
{
|
{
|
||||||
extern int Extra_TruthVarsSymm( unsigned * pTruth, int nVars, int iVar0, int iVar1 );
|
extern int Extra_TruthVarsSymm( unsigned * pTruth, int nVars, int iVar0, int iVar1 );
|
||||||
|
|
||||||
int h, i, j, k, t, ii, jj, kk, p, q, d;
|
int h, i, j, k, t, ii, jj, kk, p, q;
|
||||||
int pLits[3];
|
int pLits[3];
|
||||||
Vec_Int_t * vLits = Vec_IntAlloc( 0u );
|
Vec_Int_t * vLits = Vec_IntAlloc( 0u );
|
||||||
|
|
||||||
|
|
@ -834,6 +945,29 @@ static int Ses_ManCreateClauses( Ses_Man_t * pSes )
|
||||||
sat_solver_addclause( pSes->pSat, Vec_IntArray( vLits ), Vec_IntArray( vLits ) + jj );
|
sat_solver_addclause( pSes->pSat, Vec_IntArray( vLits ), Vec_IntArray( vLits ) + jj );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* gate decomposition (makes it worse) */
|
||||||
|
/* if ( fDecVariable >= 0 && pSes->nGates >= 2 ) */
|
||||||
|
/* { */
|
||||||
|
/* pLits[0] = Abc_Var2Lit( Ses_ManSelectVar( pSes, pSes->nGates - 1, fDecVariable, pSes->nSpecVars + pSes->nGates - 2 ), 0 ); */
|
||||||
|
/* if ( !sat_solver_addclause( pSes->pSat, pLits, pLits + 1 ) ) */
|
||||||
|
/* { */
|
||||||
|
/* Vec_IntFree( vLits ); */
|
||||||
|
/* return 0; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
/* for ( k = 1; k < pSes->nSpecVars + pSes->nGates - 1; ++k ) */
|
||||||
|
/* for ( j = 0; j < k; ++j ) */
|
||||||
|
/* if ( j != fDecVariable || k != pSes->nSpecVars + pSes->nGates - 2 ) */
|
||||||
|
/* { */
|
||||||
|
/* pLits[0] = Abc_Var2Lit( Ses_ManSelectVar( pSes, pSes->nGates - 1, j, k ), 1 ); */
|
||||||
|
/* if ( !sat_solver_addclause( pSes->pSat, pLits, pLits + 1 ) ) */
|
||||||
|
/* { */
|
||||||
|
/* Vec_IntFree( vLits ); */
|
||||||
|
/* return 0; */
|
||||||
|
/* } */
|
||||||
|
/* } */
|
||||||
|
/* } */
|
||||||
|
|
||||||
/* only AIG */
|
/* only AIG */
|
||||||
if ( pSes->fMakeAIG )
|
if ( pSes->fMakeAIG )
|
||||||
{
|
{
|
||||||
|
|
@ -922,9 +1056,14 @@ static int Ses_ManCreateClauses( Ses_Man_t * pSes )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* DEPTH clauses */
|
return 1;
|
||||||
if ( pSes->nMaxDepth >= 0 )
|
}
|
||||||
|
|
||||||
|
static int Ses_ManCreateDepthClauses( Ses_Man_t * pSes )
|
||||||
{
|
{
|
||||||
|
int i, j, k, jj, kk, d, h;
|
||||||
|
int pLits[3];
|
||||||
|
|
||||||
for ( i = 0; i < pSes->nGates; ++i )
|
for ( i = 0; i < pSes->nGates; ++i )
|
||||||
{
|
{
|
||||||
/* propagate depths from children */
|
/* propagate depths from children */
|
||||||
|
|
@ -992,7 +1131,6 @@ static int Ses_ManCreateClauses( Ses_Man_t * pSes )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -1099,6 +1237,7 @@ static char * Ses_ManExtractSolution( Ses_Man_t * pSes )
|
||||||
printf( " and operands %d and %d", j, k );
|
printf( " and operands %d and %d", j, k );
|
||||||
*p++ = j;
|
*p++ = j;
|
||||||
*p++ = k;
|
*p++ = k;
|
||||||
|
k = pSes->nSpecVars + i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1155,7 +1294,7 @@ static char * Ses_ManExtractSolution( Ses_Man_t * pSes )
|
||||||
}
|
}
|
||||||
*p++ = d;
|
*p++ = d;
|
||||||
if ( pSes->pArrTimeProfile && pSes->fExtractVerbose )
|
if ( pSes->pArrTimeProfile && pSes->fExtractVerbose )
|
||||||
printf( "output %d points to %d and has normalized delay %d (nArrTimeDelta = %d)\n", h, i, d, pSes->nArrTimeDelta );
|
printf( "output %d points to gate %d and has normalized delay %d (nArrTimeDelta = %d)\n", h, pSes->nSpecVars + i, d, pSes->nArrTimeDelta );
|
||||||
for ( l = 0; l < pSes->nSpecVars; ++l )
|
for ( l = 0; l < pSes->nSpecVars; ++l )
|
||||||
{
|
{
|
||||||
d = ( pSes->nMaxDepth != -1 ) ? pPerm[i * pSes->nSpecVars + l] : 0;
|
d = ( pSes->nMaxDepth != -1 ) ? pPerm[i * pSes->nSpecVars + l] : 0;
|
||||||
|
|
@ -1396,16 +1535,14 @@ static inline void Ses_ManPrintVars( Ses_Man_t * pSes )
|
||||||
Synopsis [Synthesis algorithm.]
|
Synopsis [Synthesis algorithm.]
|
||||||
|
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
static int Ses_ManFindMinimumSize( Ses_Man_t * pSes )
|
// returns 0, if current max depth and arrival times are not consistent
|
||||||
|
static int Ses_CheckDepthConsistency( Ses_Man_t * pSes )
|
||||||
{
|
{
|
||||||
int nGates = 0, f, i, l, mask = ~0;
|
int l, i, mask = ~0;
|
||||||
int fAndDecStructure = 0; /* network must be f = AND(x_i, g) or f = AND(!x_i, g) structure */
|
|
||||||
int fMaxGatesLevel2 = 1;
|
int fMaxGatesLevel2 = 1;
|
||||||
abctime timeStart;
|
|
||||||
|
|
||||||
/* do the arrival times allow for a network? */
|
pSes->fDecStructure = 0;
|
||||||
if ( pSes->nMaxDepth != -1 )
|
|
||||||
{
|
|
||||||
for ( l = 0; l < pSes->nSpecVars; ++l )
|
for ( l = 0; l < pSes->nSpecVars; ++l )
|
||||||
{
|
{
|
||||||
if ( pSes->pArrTimeProfile[l] >= pSes->nMaxDepth )
|
if ( pSes->pArrTimeProfile[l] >= pSes->nMaxDepth )
|
||||||
|
|
@ -1416,22 +1553,24 @@ static int Ses_ManFindMinimumSize( Ses_Man_t * pSes )
|
||||||
}
|
}
|
||||||
else if ( pSes->nSpecFunc == 1 && pSes->fMakeAIG && pSes->pArrTimeProfile[l] + 1 == pSes->nMaxDepth )
|
else if ( pSes->nSpecFunc == 1 && pSes->fMakeAIG && pSes->pArrTimeProfile[l] + 1 == pSes->nMaxDepth )
|
||||||
{
|
{
|
||||||
if ( ( fAndDecStructure == 1 && pSes->nSpecVars > 2 ) || fAndDecStructure == 2 )
|
if ( ( pSes->fDecStructure == 1 && pSes->nSpecVars > 2 ) || pSes->fDecStructure == 2 )
|
||||||
{
|
{
|
||||||
if ( pSes->fVeryVerbose )
|
if ( pSes->fVeryVerbose )
|
||||||
printf( "give up due to impossible decomposition (depth = %d, input = %d, arrival time = %d)", pSes->nMaxDepth, l, pSes->pArrTimeProfile[l] );
|
printf( "give up due to impossible decomposition (depth = %d, input = %d, arrival time = %d)", pSes->nMaxDepth, l, pSes->pArrTimeProfile[l] );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fAndDecStructure++;
|
pSes->fDecStructure++;
|
||||||
|
|
||||||
if ( pSes->nSpecVars < 6u )
|
if ( pSes->nSpecVars < 6u )
|
||||||
mask = ( 1 << pSes->nSpecVars ) - 1u;
|
mask = Abc_Tt6Mask( 1u << pSes->nSpecVars );
|
||||||
|
|
||||||
/* A subset B <=> A and B = A */
|
/* A subset B <=> A and B = A */
|
||||||
for ( i = 0; i < pSes->nSpecWords; ++i )
|
for ( i = 0; i < pSes->nSpecWords; ++i )
|
||||||
if ( ( ( s_Truths8[(l << 2) + i] & pSes->pSpec[i] & mask ) != ( pSes->pSpec[i] & mask ) ) &&
|
if ( ( ( s_Truths8[(l << 2) + i] & pSes->pSpec[i] & mask ) != ( pSes->pSpec[i] & mask ) ) &&
|
||||||
( ( ~( s_Truths8[(l << 2) + i] ) & pSes->pSpec[i] & mask ) != ( pSes->pSpec[i] & mask ) ) )
|
( ( ~( s_Truths8[(l << 2) + i] ) & pSes->pSpec[i] & mask ) != ( pSes->pSpec[i] & mask ) ) &&
|
||||||
|
( ( ( s_Truths8[(l << 2) + i] | pSes->pSpec[i] ) & mask ) != ( pSes->pSpec[i] & mask ) ) &&
|
||||||
|
( ( ( ~( s_Truths8[(l << 2) + i] ) | pSes->pSpec[i] ) & mask ) != ( pSes->pSpec[i] & mask ) ) )
|
||||||
{
|
{
|
||||||
if ( pSes->fVeryVerbose )
|
if ( pSes->fVeryVerbose )
|
||||||
printf( "give up due to impossible decomposition (depth = %d, input = %d, arrival time = %d)", pSes->nMaxDepth, l, pSes->pArrTimeProfile[l] );
|
printf( "give up due to impossible decomposition (depth = %d, input = %d, arrival time = %d)", pSes->nMaxDepth, l, pSes->pArrTimeProfile[l] );
|
||||||
|
|
@ -1441,7 +1580,7 @@ static int Ses_ManFindMinimumSize( Ses_Man_t * pSes )
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if depth's match with structure at second level from top */
|
/* check if depth's match with structure at second level from top */
|
||||||
if ( fAndDecStructure )
|
if ( pSes->fDecStructure )
|
||||||
fMaxGatesLevel2 = ( pSes->nSpecVars == 3 ) ? 2 : 1;
|
fMaxGatesLevel2 = ( pSes->nSpecVars == 3 ) ? 2 : 1;
|
||||||
else
|
else
|
||||||
fMaxGatesLevel2 = ( pSes->nSpecVars == 4 ) ? 4 : 3;
|
fMaxGatesLevel2 = ( pSes->nSpecVars == 4 ) ? 4 : 3;
|
||||||
|
|
@ -1455,15 +1594,27 @@ static int Ses_ManFindMinimumSize( Ses_Man_t * pSes )
|
||||||
printf( "give up due to impossible decomposition at second level (depth = %d, input = %d, arrival time = %d)", pSes->nMaxDepth, l, pSes->pArrTimeProfile[l] );
|
printf( "give up due to impossible decomposition at second level (depth = %d, input = %d, arrival time = %d)", pSes->nMaxDepth, l, pSes->pArrTimeProfile[l] );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check if depth's match with structure at third level from top */
|
||||||
|
if ( pSes->nSpecVars > 4 && pSes->fDecStructure && i == 1 ) /* we have f = AND(x_i, AND(x_j, g)) (x_i and x_j may be complemented) */
|
||||||
|
{
|
||||||
|
i = 0;
|
||||||
|
for ( l = 0; l < pSes->nSpecVars; ++l )
|
||||||
|
if ( pSes->pArrTimeProfile[l] + 3 == pSes->nMaxDepth )
|
||||||
|
if ( ++i > 1 )
|
||||||
|
{
|
||||||
|
if ( pSes->fVeryVerbose )
|
||||||
|
printf( "give up due to impossible decomposition at third level (depth = %d, input = %d, arrival time = %d)", pSes->nMaxDepth, l, pSes->pArrTimeProfile[l] );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* store whether call was unsuccessful due to resource limit and not due to impossible constraint */
|
return 1;
|
||||||
pSes->fHitResLimit = 0;
|
}
|
||||||
|
|
||||||
while ( true )
|
// returns 0, if current max depth and #gates are not consistent
|
||||||
|
static int Ses_CheckGatesConsistency( Ses_Man_t * pSes, int nGates )
|
||||||
{
|
{
|
||||||
++nGates;
|
|
||||||
|
|
||||||
/* give up if number of gates is impossible for given depth */
|
/* give up if number of gates is impossible for given depth */
|
||||||
if ( pSes->nMaxDepth != -1 && nGates >= (1 << pSes->nMaxDepth ) )
|
if ( pSes->nMaxDepth != -1 && nGates >= (1 << pSes->nMaxDepth ) )
|
||||||
{
|
{
|
||||||
|
|
@ -1472,7 +1623,7 @@ static int Ses_ManFindMinimumSize( Ses_Man_t * pSes )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( fAndDecStructure && nGates >= ( 1 << ( pSes->nMaxDepth - 1 ) ) + 1 )
|
if ( pSes->fDecStructure && nGates >= ( 1 << ( pSes->nMaxDepth - 1 ) ) + 1 )
|
||||||
{
|
{
|
||||||
if ( pSes->fVeryVerbose )
|
if ( pSes->fVeryVerbose )
|
||||||
printf( "give up due to impossible depth in AND-dec structure (depth = %d, gates = %d)", pSes->nMaxDepth, nGates );
|
printf( "give up due to impossible depth in AND-dec structure (depth = %d, gates = %d)", pSes->nMaxDepth, nGates );
|
||||||
|
|
@ -1487,23 +1638,112 @@ static int Ses_ManFindMinimumSize( Ses_Man_t * pSes )
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Abc_ExactCopyDepthAndArrivalTimes( int nVars, int nDepthFrom, int * nDepthTo, int * pTimesFrom, int * pTimesTo )
|
||||||
|
{
|
||||||
|
int l;
|
||||||
|
|
||||||
|
*nDepthTo = nDepthFrom;
|
||||||
|
for ( l = 0; l < nVars; ++l )
|
||||||
|
pTimesTo[l] = pTimesFrom[l];
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Ses_ManStoreDepthAndArrivalTimes( Ses_Man_t * pSes )
|
||||||
|
{
|
||||||
|
if ( pSes->nMaxDepth == -1 ) return;
|
||||||
|
Abc_ExactCopyDepthAndArrivalTimes( pSes->nSpecVars, pSes->nMaxDepth, &pSes->nMaxDepthTmp, pSes->pArrTimeProfile, pSes->pArrTimeProfileTmp );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Ses_ManRestoreDepthAndArrivalTimes( Ses_Man_t * pSes )
|
||||||
|
{
|
||||||
|
if ( pSes->nMaxDepth == -1 ) return;
|
||||||
|
Abc_ExactCopyDepthAndArrivalTimes( pSes->nSpecVars, pSes->nMaxDepthTmp, &pSes->nMaxDepth, pSes->pArrTimeProfileTmp, pSes->pArrTimeProfile );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Abc_ExactAdjustDepthAndArrivalTimes( int nVars, int nGates, int nDepthFrom, int * nDepthTo, int * pTimesFrom, int * pTimesTo, int nTimesMax )
|
||||||
|
{
|
||||||
|
int l;
|
||||||
|
|
||||||
|
*nDepthTo = Abc_MinInt( nDepthFrom, nGates );
|
||||||
|
for ( l = 0; l < nVars; ++l )
|
||||||
|
pTimesTo[l] = Abc_MinInt( pTimesFrom[l], Abc_MaxInt( 0, nGates - 1 - nTimesMax + pTimesFrom[l] ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Ses_AdjustDepthAndArrivalTimes( Ses_Man_t * pSes, int nGates )
|
||||||
|
{
|
||||||
|
Abc_ExactAdjustDepthAndArrivalTimes( pSes->nSpecVars, nGates, pSes->nMaxDepthTmp, &pSes->nMaxDepth, pSes->pArrTimeProfileTmp, pSes->pArrTimeProfile, pSes->nArrTimeMax - 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Ses_ManFindMinimumSize( Ses_Man_t * pSes )
|
||||||
|
{
|
||||||
|
int nGates = 0, f, fRes, fSat;
|
||||||
|
abctime timeStart;
|
||||||
|
|
||||||
|
/* store whether call was unsuccessful due to resource limit and not due to impossible constraint */
|
||||||
|
pSes->fHitResLimit = 0;
|
||||||
|
|
||||||
|
/* do the arrival times allow for a network? */
|
||||||
|
if ( pSes->nMaxDepth != -1 && !Ses_CheckDepthConsistency( pSes ) )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
//Ses_ManStoreDepthAndArrivalTimes( pSes );
|
||||||
|
|
||||||
|
while ( true )
|
||||||
|
{
|
||||||
|
++nGates;
|
||||||
|
|
||||||
|
//Ses_AdjustDepthAndArrivalTimes( pSes, nGates );
|
||||||
|
|
||||||
|
/* do #gates and max depth allow for a network? */
|
||||||
|
if ( !Ses_CheckGatesConsistency( pSes, nGates ) )
|
||||||
|
{
|
||||||
|
fRes = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* solve */
|
||||||
timeStart = Abc_Clock();
|
timeStart = Abc_Clock();
|
||||||
Ses_ManCreateVars( pSes, nGates );
|
Ses_ManCreateVars( pSes, nGates );
|
||||||
|
f = Ses_ManCreateDepthClauses( pSes );
|
||||||
|
pSes->timeInstance += ( Abc_Clock() - timeStart );
|
||||||
|
if ( !f ) continue; /* proven UNSAT while creating clauses */
|
||||||
|
|
||||||
|
/* first solve */
|
||||||
|
fSat = Ses_ManSolve( pSes );
|
||||||
|
if ( fSat == 0 )
|
||||||
|
continue; /* UNSAT, continue with next # of gates */
|
||||||
|
else if ( fSat == 2 )
|
||||||
|
{
|
||||||
|
pSes->fHitResLimit = 1;
|
||||||
|
fRes = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
timeStart = Abc_Clock();
|
||||||
f = Ses_ManCreateClauses( pSes );
|
f = Ses_ManCreateClauses( pSes );
|
||||||
pSes->timeInstance += ( Abc_Clock() - timeStart );
|
pSes->timeInstance += ( Abc_Clock() - timeStart );
|
||||||
if ( !f )
|
if ( !f ) continue; /* proven UNSAT while creating clauses */
|
||||||
continue; /* proven UNSAT while creating clauses */
|
|
||||||
|
|
||||||
switch ( Ses_ManSolve( pSes ) )
|
fSat = Ses_ManSolve( pSes );
|
||||||
|
if ( fSat == 1 )
|
||||||
{
|
{
|
||||||
case 1: return 1; /* SAT */
|
fRes = 1;
|
||||||
case 2:
|
break;
|
||||||
pSes->fHitResLimit = 1;
|
|
||||||
return 0; /* resource limit */
|
|
||||||
}
|
}
|
||||||
|
else if ( fSat == 2 )
|
||||||
|
{
|
||||||
|
pSes->fHitResLimit = 1;
|
||||||
|
fRes = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
/* UNSAT => continue */
|
||||||
|
}
|
||||||
|
|
||||||
|
//Ses_ManRestoreDepthAndArrivalTimes( pSes );
|
||||||
|
return fRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Function*************************************************************
|
/**Function*************************************************************
|
||||||
|
|
@ -1567,6 +1807,7 @@ Gia_Man_t * Gia_ManFindExact( word * pTruth, int nVars, int nFunc, int nMaxDepth
|
||||||
|
|
||||||
pSes = Ses_ManAlloc( pTruth, nVars, nFunc, nMaxDepth, pArrTimeProfile, 1, nBTLimit, fVerbose );
|
pSes = Ses_ManAlloc( pTruth, nVars, nFunc, nMaxDepth, pArrTimeProfile, 1, nBTLimit, fVerbose );
|
||||||
pSes->fVeryVerbose = 1;
|
pSes->fVeryVerbose = 1;
|
||||||
|
pSes->fExtractVerbose = 1;
|
||||||
pSes->fSatVerbose = 1;
|
pSes->fSatVerbose = 1;
|
||||||
if ( fVerbose )
|
if ( fVerbose )
|
||||||
Ses_ManPrintFuncs( pSes );
|
Ses_ManPrintFuncs( pSes );
|
||||||
|
|
@ -1814,7 +2055,7 @@ void Abc_ExactStats()
|
||||||
// the area cost should not exceed 2048, if the cut is implementable; otherwise, it should be ABC_INFINITY
|
// the area cost should not exceed 2048, if the cut is implementable; otherwise, it should be ABC_INFINITY
|
||||||
int Abc_ExactDelayCost( word * pTruth, int nVars, int * pArrTimeProfile, char * pPerm, int * Cost, int AigLevel )
|
int Abc_ExactDelayCost( word * pTruth, int nVars, int * pArrTimeProfile, char * pPerm, int * Cost, int AigLevel )
|
||||||
{
|
{
|
||||||
int i, nMaxArrival, l;
|
int i, nMaxArrival, nDelta, l;
|
||||||
Ses_Man_t * pSes = NULL;
|
Ses_Man_t * pSes = NULL;
|
||||||
char * pSol = NULL, * p;
|
char * pSol = NULL, * p;
|
||||||
int pNormalArrTime[8];
|
int pNormalArrTime[8];
|
||||||
|
|
@ -1864,7 +2105,7 @@ int Abc_ExactDelayCost( word * pTruth, int nVars, int * pArrTimeProfile, char *
|
||||||
for ( l = 0; l < nVars; ++l )
|
for ( l = 0; l < nVars; ++l )
|
||||||
pNormalArrTime[l] = pArrTimeProfile[l];
|
pNormalArrTime[l] = pArrTimeProfile[l];
|
||||||
|
|
||||||
Abc_NormalizeArrivalTimes( pNormalArrTime, nVars, &nMaxArrival );
|
nDelta = Abc_NormalizeArrivalTimes( pNormalArrTime, nVars, &nMaxArrival );
|
||||||
|
|
||||||
if ( s_pSesStore->fVeryVerbose )
|
if ( s_pSesStore->fVeryVerbose )
|
||||||
{
|
{
|
||||||
|
|
@ -1893,7 +2134,7 @@ int Abc_ExactDelayCost( word * pTruth, int nVars, int * pArrTimeProfile, char *
|
||||||
nMaxDepth = Abc_MaxInt( nMaxDepth, pNormalArrTime[i] );
|
nMaxDepth = Abc_MaxInt( nMaxDepth, pNormalArrTime[i] );
|
||||||
nMaxDepth += nVars + 1;
|
nMaxDepth += nVars + 1;
|
||||||
if ( AigLevel != -1 )
|
if ( AigLevel != -1 )
|
||||||
nMaxDepth = Abc_MinInt( AigLevel, nMaxDepth + nVars + 1 );
|
nMaxDepth = Abc_MinInt( AigLevel - nDelta, nMaxDepth + nVars + 1 );
|
||||||
|
|
||||||
timeStartExact = Abc_Clock();
|
timeStartExact = Abc_Clock();
|
||||||
|
|
||||||
|
|
@ -2015,7 +2256,7 @@ Abc_Obj_t * Abc_ExactBuildNode( word * pTruth, int nVars, int * pArrTimeProfile,
|
||||||
for ( i = 0; i < nVars; ++i )
|
for ( i = 0; i < nVars; ++i )
|
||||||
pNormalArrTime[i] = pArrTimeProfile[i];
|
pNormalArrTime[i] = pArrTimeProfile[i];
|
||||||
Abc_NormalizeArrivalTimes( pNormalArrTime, nVars, &nMaxArrival );
|
Abc_NormalizeArrivalTimes( pNormalArrTime, nVars, &nMaxArrival );
|
||||||
Ses_StoreGetEntry( s_pSesStore, pTruth, nVars, pNormalArrTime, &pSol );
|
assert( Ses_StoreGetEntry( s_pSesStore, pTruth, nVars, pNormalArrTime, &pSol ) );
|
||||||
if ( !pSol )
|
if ( !pSol )
|
||||||
{
|
{
|
||||||
s_pSesStore->timeTotal += ( Abc_Clock() - timeStart );
|
s_pSesStore->timeTotal += ( Abc_Clock() - timeStart );
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue