47static word s_Truths8[32] = {
58static word s_Truths8Neg[32] = {
69static int Abc_TtIsSubsetWithMask(
word * pSmall,
word * pLarge,
word * pMask,
int nWords )
72 for ( w = 0; w <
nWords; ++w )
73 if ( ( pSmall[w] & pLarge[w] & pMask[w] ) != ( pSmall[w] & pMask[w] ) )
78static int Abc_TtCofsOppositeWithMask(
word * pTruth,
word * pMask,
int nWords,
int iVar )
82 int w, Shift = ( 1 << iVar );
83 for ( w = 0; w <
nWords; ++w )
84 if ( ( ( pTruth[w] << Shift ) & s_Truths6[iVar] & pMask[w] ) != ( ~pTruth[w] & s_Truths6[iVar] & pMask[w] ) )
90 int w, Step = ( 1 << ( iVar - 6 ) );
91 word *
p = pTruth, * m = pMask, * pLimit = pTruth +
nWords;
92 for ( ;
p < pLimit;
p += 2 * Step, m += 2 * Step )
93 for ( w = 0; w < Step; ++w )
94 if ( (
p[w] & m[w] ) != ( ~
p[w + Step] & m[w + Step] ) )
102static int Abc_TtIsTopDecomposable(
word * pTruth,
word * pMask,
int nWords,
int iVar )
106 if ( Abc_TtIsSubsetWithMask( pTruth, &s_Truths8[iVar << 2], pMask,
nWords ) )
return 1;
107 if ( Abc_TtIsSubsetWithMask( pTruth, &s_Truths8Neg[iVar << 2], pMask,
nWords ) )
return 2;
108 if ( Abc_TtIsSubsetWithMask( &s_Truths8[iVar << 2], pTruth, pMask,
nWords ) )
return 3;
109 if ( Abc_TtIsSubsetWithMask( &s_Truths8Neg[iVar << 2], pTruth, pMask,
nWords ) )
return 4;
110 if ( Abc_TtCofsOppositeWithMask( pTruth, pMask,
nWords, iVar ) )
return 5;
117static int Abc_TtIsStairDecomposable(
word * pTruth,
int nWords,
int * pVars,
int nSize,
int * pStairFunc )
123 Abc_TtCopy( pCopy, pTruth,
nWords, 0 );
126 for ( i = 0; i < nSize; ++i )
128 d = Abc_TtIsTopDecomposable( pCopy, pMask,
nWords, pVars[i] );
138 Abc_TtAnd( pMask, pMask, &s_Truths8[pVars[i] << 2],
nWords, 0 );
142 Abc_TtAnd( pMask, pMask, &s_Truths8Neg[pVars[i] << 2],
nWords, 0 );
145 Abc_TtXor( pCopy, pCopy, &s_Truths8[pVars[i] << 2],
nWords, 0 );
159static inline void Abc_DebugPrint(
const char* str,
int fCond )
168static inline void Abc_DebugPrintInt(
const char* fmt,
int n,
int fCond )
177static inline void Abc_DebugPrintIntInt(
const char* fmt,
int n1,
int n2,
int fCond )
181 printf( fmt, n1, n2 );
186static inline void Abc_DebugErase(
int n,
int fCond )
191 for ( i = 0; i < n; ++i )
203#define ABC_EXACT_SOL_NVARS 0
204#define ABC_EXACT_SOL_NFUNC 1
205#define ABC_EXACT_SOL_NGATES 2
207#define ANSI_COLOR_RED "\x1b[31m"
208#define ANSI_COLOR_GREEN "\x1b[32m"
209#define ANSI_COLOR_YELLOW "\x1b[33m"
210#define ANSI_COLOR_BLUE "\x1b[34m"
211#define ANSI_COLOR_MAGENTA "\x1b[35m"
212#define ANSI_COLOR_CYAN "\x1b[36m"
213#define ANSI_COLOR_RESET "\x1b[0m"
311#define SES_STORE_TABLE_SIZE 1024
361static int Abc_NormalizeArrivalTimes(
int * pArrTimeProfile,
int nVars,
int * maxNormalized )
363 int *
p = pArrTimeProfile, * pEnd = pArrTimeProfile + nVars;
375 if ( *
p > *maxNormalized )
385static inline Ses_Store_t * Ses_StoreAlloc(
int nBTLimit,
int fMakeAIG,
int fVerbose )
398static inline void Ses_StoreClean(
Ses_Store_t * pStore )
411 pTiEntry = pTEntry->
head;
415 pTiEntry2 = pTiEntry;
416 pTiEntry = pTiEntry->
next;
420 pTEntry = pTEntry->
next;
432static inline int Ses_StoreTableHash(
word * pTruth,
int nVars )
434 static int s_Primes[4] = { 1291, 1699, 1999, 2357 };
437 for ( i = 0; i < Abc_TtWordNum( nVars ); ++i )
438 uHash ^= pTruth[i] * s_Primes[i & 0xf];
446 if ( pEntry->
nVars != nVars )
449 for ( i = 0; i < Abc_TtWordNum( nVars ); ++i )
450 if ( pEntry->
pTruth[i] != pTruth[i] )
458 pEntry->
nVars = nVars;
459 for ( i = 0; i < Abc_TtWordNum( nVars ); ++i )
460 pEntry->
pTruth[i] = pTruthSrc[i];
463static inline int Ses_StoreTimesEqual(
int * pTimes1,
int * pTimes2,
int nVars )
466 for ( i = 0; i < nVars; ++i )
467 if ( pTimes1[i] != pTimes2[i] )
472static inline void Ses_StoreTimesCopy(
int * pTimesDest,
int * pTimesSrc,
int nVars )
475 for ( i = 0; i < nVars; ++i )
476 pTimesDest[i] = pTimesSrc[i];
484 Abc_TtPrintHexRev( stdout, pEntry->
pTruth, pEntry->
nVars );
485 printf(
", n = %d", pEntry->
nVars );
486 printf(
", arrival =" );
487 for ( i = 0; i < pEntry->
nVars; ++i )
492static inline void Ses_StorePrintDebugEntry(
Ses_Store_t * pStore,
word * pTruth,
int nVars,
int * pNormalArrTime,
int nMaxDepth,
char * pSol,
int nStartGates )
497 if ( s_pSesStore->fMakeAIG ) fprintf( pStore->
pDebugEntries,
" -a" );
498 fprintf( pStore->
pDebugEntries,
" -S %d -D %d -A", nStartGates + 1, nMaxDepth );
499 for ( l = 0; l < nVars; ++l )
500 fprintf( pStore->
pDebugEntries,
"%c%d", ( l == 0 ?
' ' :
',' ), pNormalArrTime[l] );
510static void Abc_ExactNormalizeArrivalTimesForNetwork(
int nVars,
int * pArrTimeProfile,
char * pSol )
512 int nGates, i, j, k, nMax;
521 vLevels = Vec_IntAllocArrayCopy( pArrTimeProfile, nVars );
524 for ( i = 0; i < nGates; ++i )
526 j = pSol[3 + i * 4 + 2];
527 k = pSol[3 + i * 4 + 3];
529 Vec_IntPush( vLevels, Abc_MaxInt( Vec_IntEntry( vLevels, j ), Vec_IntEntry( vLevels, k ) ) + 1 );
537 for ( i = 0; i < nVars + nGates - 1; ++i )
538 Vec_IntSetEntry( vLevels, i, Vec_IntEntry( vLevels, nVars + nGates - 1 ) );
543 for ( i = nGates - 1; i >= 0; --i )
545 j = pSol[3 + i * 4 + 2];
546 k = pSol[3 + i * 4 + 3];
548 Vec_IntSetEntry( vLevels, j, Abc_MinInt( Vec_IntEntry( vLevels, j ), Vec_IntEntry( vLevels, nVars + i ) - 1 ) );
549 Vec_IntSetEntry( vLevels, k, Abc_MinInt( Vec_IntEntry( vLevels, k ), Vec_IntEntry( vLevels, nVars + i ) - 1 ) );
555 Abc_NormalizeArrivalTimes( Vec_IntArray( vLevels ), nVars, &nMax );
556 memcpy( pArrTimeProfile, Vec_IntArray( vLevels ),
sizeof(
int) * nVars );
561 Vec_IntFree( vLevels );
564static void Ses_StoreWrite(
Ses_Store_t * pStore,
const char * pFilename,
int fSynthImp,
int fSynthRL,
int fUnsynthImp,
int fUnsynthRL )
568 unsigned long nEntries = 0;
573 pFile = fopen( pFilename,
"wb" );
576 printf(
"cannot open file \"%s\" for writing\n", pFilename );
584 fwrite( &nEntries,
sizeof(
unsigned long ), 1, pFile );
593 pTiEntry = pTEntry->
head;
596 if ( !fSynthImp && pTiEntry->
pNetwork && !pTiEntry->
fResLimit ) { pTiEntry = pTiEntry->
next;
continue; }
597 if ( !fSynthRL && pTiEntry->
pNetwork && pTiEntry->
fResLimit ) { pTiEntry = pTiEntry->
next;
continue; }
598 if ( !fUnsynthImp && !pTiEntry->
pNetwork && !pTiEntry->
fResLimit ) { pTiEntry = pTiEntry->
next;
continue; }
599 if ( !fUnsynthRL && !pTiEntry->
pNetwork && pTiEntry->
fResLimit ) { pTiEntry = pTiEntry->
next;
continue; }
601 fwrite( pTEntry->
pTruth,
sizeof(
word ), 4, pFile );
602 fwrite( &pTEntry->
nVars,
sizeof(
int ), 1, pFile );
604 fwrite( &pTiEntry->
fResLimit,
sizeof(
int ), 1, pFile );
612 fwrite( &zero,
sizeof(
char ), 1, pFile );
613 fwrite( &zero,
sizeof(
char ), 1, pFile );
614 fwrite( &zero,
sizeof(
char ), 1, pFile );
617 pTiEntry = pTiEntry->
next;
619 pTEntry = pTEntry->
next;
636 Abc_ExactNormalizeArrivalTimesForNetwork( nVars, pArrTimeProfile, pSol );
638 key = Ses_StoreTableHash( pTruth, nVars );
644 if ( Ses_StoreTruthEqual( pTEntry, pTruth, nVars ) )
647 pTEntry = pTEntry->
next;
654 Ses_StoreTruthCopy( pTEntry, pTruth, nVars );
660 pTiEntry = pTEntry->
head;
663 if ( Ses_StoreTimesEqual( pArrTimeProfile, pTiEntry->
pArrTimeProfile, nVars ) )
666 pTiEntry = pTiEntry->
next;
673 Ses_StoreTimesCopy( pTiEntry->
pArrTimeProfile, pArrTimeProfile, nVars );
677 pTEntry->
head = pTiEntry;
721 Ses_StoreWrite( pStore, pStore->
szDBName, 1, 0, 0, 0 );
734 key = Ses_StoreTableHash( pTruth, nVars );
740 if ( Ses_StoreTruthEqual( pTEntry, pTruth, nVars ) )
743 pTEntry = pTEntry->
next;
751 pTiEntry = pTEntry->
head;
754 if ( Ses_StoreTimesEqual( pArrTimeProfile, pTiEntry->
pArrTimeProfile, nVars ) )
757 pTiEntry = pTiEntry->
next;
775 key = Ses_StoreTableHash( pTruth, nVars );
781 if ( Ses_StoreTruthEqual( pTEntry, pTruth, nVars ) )
784 pTEntry = pTEntry->
next;
792 pTiEntry = pTEntry->
head;
798 memcpy( pTimes, pArrTimeProfile,
sizeof(
int) * nVars );
799 Abc_ExactNormalizeArrivalTimesForNetwork( nVars, pTimes, pTiEntry->
pNetwork );
805 else if ( Ses_StoreTimesEqual( pArrTimeProfile, pTiEntry->
pArrTimeProfile, nVars ) )
808 pTiEntry = pTiEntry->
next;
819static void Ses_StoreRead(
Ses_Store_t * pStore,
const char * pFilename,
int fSynthImp,
int fSynthRL,
int fUnsynthImp,
int fUnsynthRL )
822 unsigned long nEntries;
824 int nVars, fResLimit;
825 int pArrTimeProfile[8];
833 printf(
"cannot read from database when szDBName is set" );
837 pFile = fopen( pFilename,
"rb" );
840 printf(
"cannot open file \"%s\" for reading\n", pFilename );
844 value = fread( &nEntries,
sizeof(
unsigned long ), 1, pFile );
846 for ( i = 0; i < (int)nEntries; ++i )
848 value = fread( pTruth,
sizeof(
word ), 4, pFile );
849 value = fread( &nVars,
sizeof(
int ), 1, pFile );
850 value = fread( pArrTimeProfile,
sizeof(
int ), 8, pFile );
851 value = fread( &fResLimit,
sizeof(
int ), 1, pFile );
852 value = fread( pHeader,
sizeof(
char ), 3, pFile );
854 if ( pHeader[0] ==
'\0' )
859 pNetwork[0] = pHeader[0];
860 pNetwork[1] = pHeader[1];
861 pNetwork[2] = pHeader[2];
866 if ( !fSynthImp && pNetwork && !fResLimit )
continue;
867 if ( !fSynthRL && pNetwork && fResLimit )
continue;
868 if ( !fUnsynthImp && !pNetwork && !fResLimit )
continue;
869 if ( !fUnsynthRL && !pNetwork && fResLimit )
continue;
871 Ses_StoreAddEntry( pStore, pTruth, nVars, pArrTimeProfile, pNetwork, fResLimit );
876 printf(
"read %lu entries from file\n", (
long)nEntries );
880static inline void Ses_ManComputeTopDec(
Ses_Man_t * pSes )
888 if ( Abc_TtIsTopDecomposable( pSes->
pSpec, pMask, pSes->
nSpecWords, l ) )
892static inline Ses_Man_t * Ses_ManAlloc(
word * pTruth,
int nVars,
int nFunc,
int nMaxDepth,
int * pArrTimeProfile,
int fMakeAIG,
int nBTLimit,
int fVerbose )
899 for ( h = 0; h < nFunc; ++h )
900 if ( pTruth[h << 2] & 1 )
902 for ( i = 0; i < 4; ++i )
903 pTruth[(h << 2) + i] = ~pTruth[(h << 2) + i];
904 p->bSpecInv |= ( 1 << h );
907 p->nSpecVars = nVars;
908 p->nSpecFunc = nFunc;
909 p->nSpecWords = Abc_TtWordNum( nVars );
910 p->nRows = ( 1 << nVars ) - 1;
911 p->nMaxDepth = nMaxDepth;
912 p->pArrTimeProfile = nMaxDepth >= 0 ? pArrTimeProfile : NULL;
913 if (
p->pArrTimeProfile )
914 p->nArrTimeDelta = Abc_NormalizeArrivalTimes(
p->pArrTimeProfile, nVars, &
p->nArrTimeMax );
916 p->nArrTimeDelta =
p->nArrTimeMax = 0;
917 p->fMakeAIG = fMakeAIG;
918 p->nBTLimit = nBTLimit;
919 p->fVerbose = fVerbose;
921 p->fExtractVerbose = 0;
923 p->vPolar = Vec_IntAlloc( 100 );
924 p->vAssump = Vec_IntAlloc( 10 );
925 p->vStairDecVars = Vec_IntAlloc( nVars );
926 p->nRandRowAssigns = 2 * nVars;
927 p->fKeepRowAssigns = 0;
929 if (
p->nSpecFunc == 1 )
930 Ses_ManComputeTopDec(
p );
937static inline void Ses_ManCleanLight(
Ses_Man_t * pSes )
942 for ( i = 0; i < 4; ++i )
943 pSes->
pSpec[(h << 2) + i] = ~( pSes->
pSpec[(h << 2) + i] );
949 Vec_IntFree( pSes->
vPolar );
956static inline void Ses_ManClean(
Ses_Man_t * pSes )
960 Ses_ManCleanLight( pSes );
968static inline int Ses_ManSimVar(
Ses_Man_t * pSes,
int i,
int t )
970 assert( i < pSes->nGates );
971 assert( t < pSes->nRows );
976static inline int Ses_ManOutputVar(
Ses_Man_t * pSes,
int h,
int i )
978 assert( h < pSes->nSpecFunc );
979 assert( i < pSes->nGates );
984static inline int Ses_ManGateVar(
Ses_Man_t * pSes,
int i,
int p,
int q )
986 assert( i < pSes->nGates );
994static inline int Ses_ManSelectVar(
Ses_Man_t * pSes,
int i,
int j,
int k )
999 assert( i < pSes->nGates );
1000 assert( k < pSes->nSpecVars + i );
1004 for ( a = pSes->
nSpecVars; a < pSes->nSpecVars + i; ++a )
1005 offset += a * ( a - 1 ) / 2;
1007 return offset + ( -j * ( 1 + j - 2 * ( pSes->
nSpecVars + i ) ) ) / 2 + ( k - j - 1 );
1010static inline int Ses_ManDepthVar(
Ses_Man_t * pSes,
int i,
int j )
1012 assert( i < pSes->nGates );
1013 assert( j <= pSes->nArrTimeMax + i );
1023static word * Ses_ManDeriveTruth(
Ses_Man_t * pSes,
char * pSol,
int fInvert )
1027 word * pTruth = NULL, * pTruth0, * pTruth1;
1034 for ( i = 0; i < nGates; ++i )
1044 pTruth = &pSes->
pTtObjs[i << 2];
1048 pTruth[w] |= ~pTruth0[w] & pTruth1[w];
1049 if ( ( f >> 1 ) & 1 )
1051 pTruth[w] |= pTruth0[w] & ~pTruth1[w];
1052 if ( ( f >> 2 ) & 1 )
1054 pTruth[w] |= pTruth0[w] & pTruth1[w];
1057 assert( Abc_Lit2Var( *
p ) == nGates - 1 );
1058 if ( fInvert && Abc_LitIsCompl( *
p ) )
1069static void Ses_ManCreateVars(
Ses_Man_t * pSes,
int nGates )
1075 printf(
"create variables for network with %d functions over %d variables and %d/%d gates\n", pSes->
nSpecFunc, pSes->
nSpecVars, nGates, pSes->
nMaxGates );
1083 for ( i = pSes->
nSpecVars; i < pSes->nSpecVars + nGates; ++i )
1118static inline void Ses_ManGateCannotHaveChild(
Ses_Man_t * pSes,
int i,
int j )
1122 for ( k = 0; k < j; ++k )
1123 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManSelectVar( pSes, i, k, j ), 1 ) );
1124 for ( k = j + 1; k < pSes->
nSpecVars + i; ++k )
1125 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManSelectVar( pSes, i, j, k ), 1 ) );
1128static inline void Ses_ManCreateMainClause(
Ses_Man_t * pSes,
int t,
int i,
int j,
int k,
int a,
int b,
int c )
1130 int pLits[5], ctr = 0;
1132 pLits[ctr++] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i, j, k ), 1 );
1133 pLits[ctr++] = Abc_Var2Lit( Ses_ManSimVar( pSes, i, t ), a );
1135 if ( j < pSes->nSpecVars )
1137 if ( ( ( ( t + 1 ) & ( 1 << j ) ) ? 1 : 0 ) != b )
1141 pLits[ctr++] = Abc_Var2Lit( Ses_ManSimVar( pSes, j - pSes->
nSpecVars, t ), b );
1143 if ( k < pSes->nSpecVars )
1145 if ( ( ( ( t + 1 ) & ( 1 << k ) ) ? 1 : 0 ) != c )
1149 pLits[ctr++] = Abc_Var2Lit( Ses_ManSimVar( pSes, k - pSes->
nSpecVars, t ), c );
1151 if ( b > 0 || c > 0 )
1152 pLits[ctr++] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, b, c ), 1 - a );
1157static int inline Ses_ManCreateTruthTableClause(
Ses_Man_t * pSes,
int t )
1162 for ( i = 0; i < pSes->
nGates; ++i )
1165 for ( j = 0; j < pSes->
nSpecVars + i; ++j )
1166 for ( k = j + 1; k < pSes->
nSpecVars + i; ++k )
1168 Ses_ManCreateMainClause( pSes, t, i, j, k, 0, 0, 1 );
1169 Ses_ManCreateMainClause( pSes, t, i, j, k, 0, 1, 0 );
1170 Ses_ManCreateMainClause( pSes, t, i, j, k, 0, 1, 1 );
1171 Ses_ManCreateMainClause( pSes, t, i, j, k, 1, 0, 0 );
1172 Ses_ManCreateMainClause( pSes, t, i, j, k, 1, 0, 1 );
1173 Ses_ManCreateMainClause( pSes, t, i, j, k, 1, 1, 0 );
1174 Ses_ManCreateMainClause( pSes, t, i, j, k, 1, 1, 1 );
1181 pLits[0] = Abc_Var2Lit( Ses_ManOutputVar( pSes, h, i ), 1 );
1182 pLits[1] = Abc_Var2Lit( Ses_ManSimVar( pSes, i, t ), 1 - Abc_TtGetBit( &pSes->
pSpec[h << 2], t + 1 ) );
1189 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManSimVar( pSes, pSes->
nGates - 1, t ), 1 - Abc_TtGetBit( pSes->
pSpec, t + 1 ) ) );
1194static int Ses_ManCreateClauses(
Ses_Man_t * pSes )
1198 int h, i, j, k, t, ii, jj, kk, iii,
p, q;
1202 for ( t = 0; t < pSes->
nRows; ++t )
1204 if ( Abc_TtGetBit( pSes->
pTtValues, t ) )
1205 if ( !Ses_ManCreateTruthTableClause( pSes, t ) )
1212 for ( i = 0; i < pSes->
nGates - 1; ++i )
1213 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManOutputVar( pSes, 0, i ), 1 ) );
1214 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManOutputVar( pSes, 0, pSes->
nGates - 1 ), 0 ) );
1216 vLits = Vec_IntAlloc( 0u );
1220 vLits = Vec_IntAlloc( 0u );
1225 Vec_IntGrowResize( vLits, pSes->
nGates );
1226 for ( i = 0; i < pSes->
nGates; ++i )
1227 Vec_IntSetEntry( vLits, i, Abc_Var2Lit( Ses_ManOutputVar( pSes, h, i ), 0 ) );
1233 for ( i = 0; i < pSes->
nGates; ++i )
1235 Vec_IntGrowResize( vLits, ( ( pSes->
nSpecVars + i ) * ( pSes->
nSpecVars + i - 1 ) ) / 2 );
1237 for ( j = 0; j < pSes->
nSpecVars + i; ++j )
1238 for ( k = j + 1; k < pSes->
nSpecVars + i; ++k )
1239 Vec_IntSetEntry( vLits, jj++, Abc_Var2Lit( Ses_ManSelectVar( pSes, i, j, k ), 0 ) );
1269 for ( i = 0; i < pSes->
nGates; ++i )
1272 pLits[0] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 0, 1 ), 1 );
1273 pLits[1] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 0 ), 1 );
1274 pLits[2] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 1 ), 0 );
1277 pLits[0] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 0, 1 ), 1 );
1278 pLits[1] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 0 ), 0 );
1279 pLits[2] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 1 ), 1 );
1282 pLits[0] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 0, 1 ), 0 );
1283 pLits[1] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 0 ), 1 );
1284 pLits[2] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 1 ), 1 );
1292 for ( i = 0; i < pSes->
nGates; ++i )
1294 pLits[0] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 0, 1 ), 0 );
1295 pLits[1] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 0 ), 0 );
1296 pLits[2] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 1 ), 0 );
1299 pLits[0] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 0, 1 ), 1 );
1300 pLits[1] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 0 ), 0 );
1301 pLits[2] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 1 ), 1 );
1304 pLits[0] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 0, 1 ), 0 );
1305 pLits[1] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 0 ), 1 );
1306 pLits[2] = Abc_Var2Lit( Ses_ManGateVar( pSes, i, 1, 1 ), 1 );
1310 for ( i = 0; i < pSes->
nGates; ++i )
1311 for ( k = 1; k < pSes->
nSpecVars + i; ++k )
1312 for ( j = 0; j < k; ++j )
1314 pLits[0] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i, j, k ), 1 );
1316 for ( kk = 1; kk < pSes->
nSpecVars + i; ++kk )
1317 for ( jj = 0; jj < kk; ++jj )
1319 if ( k == kk && j == jj )
continue;
1320 pLits[1] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i, jj, kk ), 1 );
1322 if ( pLits[0] < pLits[1] )
1348 if ( pSes->
nGates - 2 - i < j )
1352 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManSelectVar( pSes, pSes->
nGates - 1 - i, j, pSes->
nSpecVars + pSes->
nGates - 2 - i ), 0 ) );
1359 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManGateVar( pSes, pSes->
nGates - 1 - i, 0, 1 ), 1 ) );
1365 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManGateVar( pSes, pSes->
nGates - 1 - i, 1, 0 ), 1 ) );
1366 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManGateVar( pSes, pSes->
nGates - 1 - i, 1, 1 ), 1 ) );
1370 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManGateVar( pSes, pSes->
nGates - 1 - i, 1, 0 ), 0 ) );
1371 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManGateVar( pSes, pSes->
nGates - 1 - i, 1, 1 ), 0 ) );
1379 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManGateVar( pSes, pSes->
nGates - 1 - i, 0, 1 ), 0 ) );
1380 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManGateVar( pSes, pSes->
nGates - 1 - i, 1, 0 ), 0 ) );
1381 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManGateVar( pSes, pSes->
nGates - 1 - i, 1, 1 ), 1 ) );
1392 for ( i = 0; i < pSes->
nGates; ++i )
1396 Vec_IntSetEntry( vLits, jj++, Abc_Var2Lit( Ses_ManOutputVar( pSes, h, i ), 0 ) );
1397 for ( ii = i + 1; ii < pSes->
nGates; ++ii )
1399 for ( j = 0; j < pSes->
nSpecVars + i; ++j )
1400 Vec_IntSetEntry( vLits, jj++, Abc_Var2Lit( Ses_ManSelectVar( pSes, ii, j, pSes->
nSpecVars + i ), 0 ) );
1401 for ( j = pSes->
nSpecVars + i + 1; j < pSes->nSpecVars + ii; ++j )
1402 Vec_IntSetEntry( vLits, jj++, Abc_Var2Lit( Ses_ManSelectVar( pSes, ii, pSes->
nSpecVars + i, j ), 0 ) );
1406 Vec_IntFree( vLits );
1410 for ( i = 0; i < pSes->
nGates - 1; ++i )
1411 for ( ii = i + 1; ii < pSes->
nGates; ++ii )
1412 for ( k = 1; k < pSes->
nSpecVars + i; ++k )
1413 for ( j = 0; j < k; ++j )
1415 pLits[0] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i, j, k ), 1 );
1416 pLits[1] = Abc_Var2Lit( Ses_ManSelectVar( pSes, ii, j, pSes->
nSpecVars + i ), 1 );
1419 pLits[1] = Abc_Var2Lit( Ses_ManSelectVar( pSes, ii, k, pSes->
nSpecVars + i ), 1 );
1423 for ( i = 0; i < pSes->
nGates - 2; ++i )
1424 for ( ii = i + 1; ii < pSes->
nGates - 1; ++ii )
1425 for ( iii = ii + 1; iii < pSes->
nGates; ++iii )
1426 for ( k = 1; k < pSes->
nSpecVars + i; ++k )
1427 for ( j = 0; j < k; ++j )
1429 pLits[0] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i, j, k ), 1 );
1430 pLits[1] = Abc_Var2Lit( Ses_ManSelectVar( pSes, ii, j, k ), 1 );
1431 pLits[2] = Abc_Var2Lit( Ses_ManSelectVar( pSes, iii, i, ii ), 1 );
1436 for ( i = 0; i < pSes->
nGates - 1; ++i )
1438 for ( k = 2; k < pSes->
nSpecVars + i; ++k )
1440 for ( j = 1; j < k; ++j )
1441 for ( jj = 0; jj < j; ++jj )
1443 pLits[0] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i, j, k ), 1 );
1444 pLits[1] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i + 1, jj, k ), 1 );
1448 for ( j = 0; j < k; ++j )
1449 for ( kk = 1; kk < k; ++kk )
1450 for ( jj = 0; jj < kk; ++jj )
1452 pLits[0] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i, j, k ), 1 );
1453 pLits[1] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i + 1, jj, kk ), 1 );
1462 for (
p = 0;
p < q; ++
p )
1467 printf(
"variables %d and %d are symmetric\n",
p, q );
1468 for ( i = 0; i < pSes->
nGates; ++i )
1469 for ( j = 0; j < q; ++j )
1471 if ( j ==
p )
continue;
1473 vLits = Vec_IntAlloc( 0 );
1474 Vec_IntPush( vLits, Abc_Var2Lit( Ses_ManSelectVar( pSes, i, j, q ), 1 ) );
1475 for ( ii = 0; ii < i; ++ii )
1476 for ( kk = 1; kk < pSes->
nSpecVars + ii; ++kk )
1477 for ( jj = 0; jj < kk; ++jj )
1478 if ( jj ==
p || kk ==
p )
1479 Vec_IntPush( vLits, Abc_Var2Lit( Ses_ManSelectVar( pSes, ii, jj, kk ), 0 ) );
1481 Vec_IntFree( vLits );
1488static int Ses_ManCreateDepthClauses(
Ses_Man_t * pSes )
1490 int i, j, k, jj, kk, d, h;
1493 for ( i = 0; i < pSes->
nGates; ++i )
1496 for ( k = 1; k < i; ++k )
1497 for ( j = 0; j < k; ++j )
1499 pLits[0] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i, pSes->
nSpecVars + j, pSes->
nSpecVars + k ), 1 );
1502 pLits[1] = Abc_Var2Lit( Ses_ManDepthVar( pSes, j, jj ), 1 );
1503 pLits[2] = Abc_Var2Lit( Ses_ManDepthVar( pSes, i, jj + 1 ), 0 );
1508 for ( k = 0; k < i; ++k )
1509 for ( j = 0; j < pSes->
nSpecVars + k; ++j )
1511 pLits[0] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i, j, pSes->
nSpecVars + k ), 1 );
1514 pLits[1] = Abc_Var2Lit( Ses_ManDepthVar( pSes, k, kk ), 1 );
1515 pLits[2] = Abc_Var2Lit( Ses_ManDepthVar( pSes, i, kk + 1 ), 0 );
1523 for ( k = 1; k < pSes->
nSpecVars + i; ++k )
1530 pLits[0] = Abc_Var2Lit( Ses_ManSelectVar( pSes, i, j, k ), 1 );
1531 pLits[1] = Abc_Var2Lit( Ses_ManDepthVar( pSes, i, d ), 0 );
1537 Vec_IntPush( pSes->
vAssump, Abc_Var2Lit( Ses_ManDepthVar( pSes, i, 0 ), 0 ) );
1542 pLits[0] = Abc_Var2Lit( Ses_ManDepthVar( pSes, i, j ), 1 );
1543 pLits[1] = Abc_Var2Lit( Ses_ManDepthVar( pSes, i, j - 1 ), 0 );
1551 pLits[0] = Abc_Var2Lit( Ses_ManOutputVar( pSes, h, i ), 1 );
1552 pLits[1] = Abc_Var2Lit( Ses_ManDepthVar( pSes, i, pSes->
nMaxDepth ), 1 );
1566static inline double Sat_Wrd2Dbl(
word w ) {
return (
double)(unsigned)(w&0x3FFFFFFF) + (double)(1<<30)*(unsigned)(w>>30); }
1568static inline int Ses_ManSolve(
Ses_Man_t * pSes )
1579 timeStart = Abc_Clock();
1581 timeDelta = Abc_Clock() - timeStart;
1584 printf(
" RE: %2d ST: %4.f CO: %7.0f DE: %6.0f PR: %6.0f\n",
1613 printf(
"resource limit reached\n" );
1639static char * Ses_ManExtractSolution(
Ses_Man_t * pSes )
1641 int nSol, h, i, j, k, l, aj, ak, d, nOp;
1656 for ( i = 0; i < pSes->
nGates; ++i )
1658 nOp = sat_solver_var_value( pSes->
pSat, Ses_ManGateVar( pSes, i, 0, 1 ) );
1659 nOp |= sat_solver_var_value( pSes->
pSat, Ses_ManGateVar( pSes, i, 1, 0 ) ) << 1;
1660 nOp |= sat_solver_var_value( pSes->
pSat, Ses_ManGateVar( pSes, i, 1, 1 ) ) << 2;
1666 printf(
"add gate %d with operation %d", pSes->
nSpecVars + i, nOp );
1668 for ( k = 0; k < pSes->
nSpecVars + i; ++k )
1669 for ( j = 0; j < k; ++j )
1670 if ( sat_solver_var_value( pSes->
pSat, Ses_ManSelectVar( pSes, i, j, k ) ) )
1673 printf(
" and operands %d and %d", j, k );
1684 printf(
" and depth vector " );
1686 printf(
"%d", sat_solver_var_value( pSes->
pSat, Ses_ManDepthVar( pSes, i, j ) ) );
1696 for ( i = 0; i < pSes->
nGates; ++i )
1699 j = pSol[3 + i * 4 + 2];
1700 k = pSol[3 + i * 4 + 3];
1708 if ( aj == 0 && ak == 0 )
1709 pPerm[i * pSes->
nSpecVars + l] = ( l == j || l == k ) ? 1 : 0;
1711 pPerm[i * pSes->
nSpecVars + l] = Abc_MaxInt( aj, ak ) + 1;
1718 for ( i = 0; i < pSes->
nGates; ++i )
1719 if ( sat_solver_var_value( pSes->
pSat, Ses_ManOutputVar( pSes, h, i ) ) )
1721 *
p++ = Abc_Var2Lit( i, ( pSes->
bSpecInv >> h ) & 1 );
1729 d = Abc_MaxInt( d, pPerm[i * pSes->
nSpecVars + l] );
1733 printf(
"output %d points to gate %d and has normalized delay %d (nArrTimeDelta = %d)\n", h, pSes->
nSpecVars + i, d, pSes->
nArrTimeDelta );
1738 printf(
" pin-to-pin arrival time from input %d is %d (pArrTimeProfile = %d)\n", l, d, pSes->
pArrTimeProfile[l] );
1748 assert( (
p - pSol ) == nSol );
1757static Abc_Ntk_t * Ses_ManExtractNtk(
char const * pSol )
1770 pGateTruth[3] =
'0';
1771 pGateTruth[4] =
'\0';
1775 Vec_PtrPush( pNtk->
vObjs, NULL );
1778 pObj = Abc_NtkCreatePi( pNtk );
1780 Vec_PtrPush( pGates, pObj );
1787 pGateTruth[2] =
'0' + ( *
p & 1 );
1788 pGateTruth[1] =
'0' + ( ( *
p >> 1 ) & 1 );
1789 pGateTruth[0] =
'0' + ( ( *
p >> 2 ) & 1 );
1796 pObj = Abc_NtkCreateNode( pNtk );
1798 Vec_PtrPush( pGates, pObj );
1808 pObj = Abc_NtkCreatePo( pNtk );
1810 if ( Abc_LitIsCompl( *
p ) )
1818 Vec_PtrFree( pGates );
1821 printf(
"Ses_ManExtractSolution(): Network check has failed.\n" );
1826static Gia_Man_t * Ses_ManExtractGia(
char const * pSol )
1833 int nObj, nChild1, nChild2, fChild1Comp, fChild2Comp;
1846 nObj = Gia_ManAppendCi( pGia );
1847 Vec_IntPush( pGates, nObj );
1856 nChild1 = Vec_IntEntry( pGates,
p[2] );
1857 nChild2 = Vec_IntEntry( pGates,
p[3] );
1858 fChild1Comp = fChild2Comp = 0;
1862 nChild1 = Abc_LitNot( nChild1 );
1865 if ( ( *
p >> 1 ) & 1 )
1867 nChild2 = Abc_LitNot( nChild2 );
1870 nObj = Gia_ManAppendAnd( pGia, nChild1, nChild2 );
1871 if ( fChild1Comp && fChild2Comp )
1874 nObj = Abc_LitNot( nObj );
1877 Vec_IntPush( pGates, nObj );
1887 if ( Abc_LitIsCompl( *
p ) )
1888 nObj = Abc_LitNot( nObj );
1889 Gia_ManAppendCo( pGia, nObj );
1895 Vec_IntFree( pGates );
1905static void Ses_ManPrintRuntime(
Ses_Man_t * pSes )
1907 printf(
"Runtime breakdown:\n" );
1916static inline void Ses_ManPrintFuncs(
Ses_Man_t * pSes )
1920 printf(
"find optimum circuit for %d %d-variable functions:\n", pSes->
nSpecFunc, pSes->
nSpecVars );
1923 printf(
" func %d: ", h + 1 );
1924 Abc_TtPrintHexRev( stdout, &pSes->
pSpec[h << 2], pSes->
nSpecVars );
1930 printf(
" max depth = %d\n", pSes->
nMaxDepth );
1933 printf(
" arrival times =" );
1941static inline void Ses_ManPrintVars(
Ses_Man_t * pSes )
1943 int h, i, j, k,
p, q, t;
1945 for ( i = 0; i < pSes->
nGates; ++i )
1946 for ( t = 0; t < pSes->
nRows; ++t )
1947 printf(
"x(%d, %d) : %d\n", i, t, Ses_ManSimVar( pSes, i, t ) );
1950 for ( i = 0; i < pSes->
nGates; ++i )
1951 printf(
"h(%d, %d) : %d\n", h, i, Ses_ManOutputVar( pSes, h, i ) );
1953 for ( i = 0; i < pSes->
nGates; ++i )
1954 for (
p = 0;
p <= 1; ++
p )
1955 for ( q = 0; q <= 1; ++ q)
1957 if (
p == 0 && q == 0 ) {
continue; }
1958 printf(
"f(%d, %d, %d) : %d\n", i,
p, q, Ses_ManGateVar( pSes, i,
p, q ) );
1961 for ( i = 0; i < pSes->
nGates; ++i )
1962 for ( j = 0; j < pSes->
nSpecVars + i; ++j )
1963 for ( k = j + 1; k < pSes->
nSpecVars + i; ++k )
1964 printf(
"s(%d, %d, %d) : %d\n", i, j, k, Ses_ManSelectVar( pSes, i, j, k ) );
1967 for ( i = 0; i < pSes->
nGates; ++i )
1968 for ( j = 0; j <= i; ++j )
1969 printf(
"d(%d, %d) : %d\n", i, j, Ses_ManDepthVar( pSes, i, j ) );
1978static void Ses_ManComputeMaxGates(
Ses_Man_t * pSes )
2004static int Ses_CheckDepthConsistency(
Ses_Man_t * pSes )
2006 int l, i, fAdded, nLevel;
2007 int fMaxGatesLevel2 = 1;
2017 printf(
"give up due to impossible arrival time (depth = %d, input = %d, arrival time = %d)", pSes->
nMaxDepth, l, pSes->
pArrTimeProfile[l] );
2025 printf(
"give up due to impossible decomposition (depth = %d, input = %d, arrival time = %d)", pSes->
nMaxDepth, l, pSes->
pArrTimeProfile[l] );
2032 if ( !( ( pSes->
pDecVars >> l ) & 1 ) )
2035 printf(
"give up due to impossible decomposition (depth = %d, input = %d, arrival time = %d)", pSes->
nMaxDepth, l, pSes->
pArrTimeProfile[l] );
2055 if ( fAdded > 1 || ( nLevel + 1 < pSes->
nSpecVars ) )
2058 printf(
"give up due to impossible decomposition at level %d", nLevel );
2069 if ( !fAdded )
break;
2077 printf(
"give up due to impossible stair decomposition at level %d: ", nLevel );
2086 fMaxGatesLevel2 = ( pSes->
nSpecVars == 3 ) ? 2 : 1;
2088 fMaxGatesLevel2 = ( pSes->
nSpecVars == 4 ) ? 4 : 3;
2093 if ( ++i > fMaxGatesLevel2 )
2096 printf(
"give up due to impossible decomposition at second level (depth = %d, input = %d, arrival time = %d)", pSes->
nMaxDepth, l, pSes->
pArrTimeProfile[l] );
2109 printf(
"give up due to impossible decomposition at third level (depth = %d, input = %d, arrival time = %d)", pSes->
nMaxDepth, l, pSes->
pArrTimeProfile[l] );
2118static int Ses_CheckGatesConsistency(
Ses_Man_t * pSes,
int nGates )
2124 printf(
"give up due to impossible depth (depth = %d, gates = %d)", pSes->
nMaxDepth, nGates );
2132 printf(
"give up due to impossible depth and arrival times (depth = %d, gates = %d)", pSes->
nMaxDepth, nGates );
2139 printf(
"give up due to impossible depth in AND-dec structure (depth = %d, gates = %d)", pSes->
nMaxDepth, nGates );
2144 if ( nGates >= ( 1 << pSes->
nSpecVars ) )
2147 printf(
"give up due to impossible number of gates" );
2154static void Abc_ExactCopyDepthAndArrivalTimes(
int nVars,
int nDepthFrom,
int * nDepthTo,
int * pTimesFrom,
int * pTimesTo )
2158 *nDepthTo = nDepthFrom;
2159 for ( l = 0; l < nVars; ++l )
2160 pTimesTo[l] = pTimesFrom[l];
2163static void Ses_ManStoreDepthAndArrivalTimes(
Ses_Man_t * pSes )
2169static void Ses_ManRestoreDepthAndArrivalTimes(
Ses_Man_t * pSes )
2175static void Abc_ExactAdjustDepthAndArrivalTimes(
int nVars,
int nGates,
int nDepthFrom,
int * nDepthTo,
int * pTimesFrom,
int * pTimesTo,
int nTimesMax )
2179 *nDepthTo = Abc_MinInt( nDepthFrom, nGates );
2180 for ( l = 0; l < nVars; ++l )
2181 pTimesTo[l] = Abc_MinInt( pTimesFrom[l], Abc_MaxInt( 0, nGates - 1 - nTimesMax + pTimesFrom[l] ) );
2184static void Ses_AdjustDepthAndArrivalTimes(
Ses_Man_t * pSes,
int nGates )
2190static int Ses_ManFindNetworkExact(
Ses_Man_t * pSes,
int nGates )
2196 timeStart = Abc_Clock();
2197 Vec_IntClear( pSes->
vPolar );
2198 Vec_IntClear( pSes->
vAssump );
2199 Ses_ManCreateVars( pSes, nGates );
2203 f = Ses_ManCreateDepthClauses( pSes );
2208 sat_solver_set_polarity( pSes->
pSat, Vec_IntArray( pSes->
vPolar ), Vec_IntSize( pSes->
vPolar ) );
2211 fSat = Ses_ManSolve( pSes );
2214 else if ( fSat == 2 )
2220 timeStart = Abc_Clock();
2221 f = Ses_ManCreateClauses( pSes );
2225 fSat = Ses_ManSolve( pSes );
2228 else if ( fSat == 2 )
2239static int Ses_ManFindNetworkExactCEGAR(
Ses_Man_t * pSes,
int nGates,
char ** pSol )
2241 int fRes, iMint, fSat, i;
2249 if ( !Ses_CheckGatesConsistency( pSes, nGates ) )
2255 fRes = Ses_ManFindNetworkExact( pSes, nGates );
2256 if ( fRes != 1 )
return fRes;
2260 *pSol = Ses_ManExtractSolution( pSes );
2261 Abc_TtXor( pTruth, Ses_ManDeriveTruth( pSes, *pSol, 0 ), pSes->
pSpec, pSes->
nSpecWords, 0 );
2262 iMint = Abc_TtFindFirstBit( pTruth, pSes->
nSpecVars );
2264 if ( iMint == -1 || (pSes->
nSpecVars < 6 && iMint > pSes->
nRows) )
2272 Abc_TtSetBit( pSes->
pTtValues, iMint - 1 );
2273 if ( !Ses_ManCreateTruthTableClause( pSes, iMint - 1 ) )
2276 if ( ( fSat = Ses_ManSolve( pSes ) ) == 1 )
continue;
2278 return ( fSat == 2 ) ? 0 : 2;
2283static char * Ses_ManFindMinimumSizeBottomUp(
Ses_Man_t * pSes )
2295 nGates = Abc_MaxInt( nGates, Vec_IntSize( pSes->
vStairDecVars ) - 1 );
2307 fRes = Ses_ManFindNetworkExactCEGAR( pSes, nGates, &pSol );
2314 else if ( fRes == 1 || fRes == 3 )
2323static char * Ses_ManFindMinimumSizeTopDown(
Ses_Man_t * pSes,
int nMinGates )
2326 char * pSol = NULL, * pSol2 = NULL;
2334 fRes = Ses_ManFindNetworkExactCEGAR( pSes, nGates, &pSol2 );
2341 else if ( fRes == 2 || fRes == 3 )
2346 if ( nGates == nMinGates )
2357static char * Ses_ManFindMinimumSize(
Ses_Man_t * pSes )
2369 printf(
"try with %d gates\n", i );
2373 fRes = Ses_ManFindNetworkExact( pSes, i++ );
2374 if ( fRes == 2 )
continue;
2375 if ( fRes == 0 )
break;
2377 pSol = Ses_ManExtractSolution( pSes );
2387 if ( !Ses_CheckDepthConsistency( pSes ) )
2389 Ses_ManComputeMaxGates( pSes );
2392 pSol = Ses_ManFindMinimumSizeBottomUp( pSes );
2395 return Ses_ManFindMinimumSizeTopDown( pSes, pSes->
nGates + 1 );
2422 assert( nVars >= 2 && nVars <= 8 );
2424 timeStart = Abc_Clock();
2426 pSes = Ses_ManAlloc( pTruth, nVars, nFunc, nMaxDepth, pArrTimeProfile, 0, nBTLimit, fVerbose );
2431 Ses_ManPrintFuncs( pSes );
2433 if ( ( pSol = Ses_ManFindMinimumSize( pSes ) ) != NULL )
2435 pNtk = Ses_ManExtractNtk( pSol );
2439 pSes->
timeTotal = Abc_Clock() - timeStart;
2442 Ses_ManPrintRuntime( pSes );
2445 Ses_ManClean( pSes );
2458 assert( nVars >= 2 && nVars <= 8 );
2460 timeStart = Abc_Clock();
2462 pSes = Ses_ManAlloc( pTruth, nVars, nFunc, nMaxDepth, pArrTimeProfile, 1, nBTLimit, fVerbose );
2469 Ses_ManPrintFuncs( pSes );
2471 if ( ( pSol = Ses_ManFindMinimumSize( pSes ) ) != NULL )
2473 pGia = Ses_ManExtractGia( pSol );
2477 pSes->
timeTotal = Abc_Clock() - timeStart;
2480 Ses_ManPrintRuntime( pSes );
2483 Ses_ManClean( pSes );
2513 word pTruth[4] = {0xcafe, 0, 0, 0};
2514 Abc_Ntk_t * pNtk, * pNtk2, * pNtk3, * pNtk4;
2515 int pArrTimeProfile[4] = {6, 2, 8, 5};
2523 assert( Abc_NtkNodeNum( pNtk2 ) == 6 );
2533 pNtk4 =
Abc_NtkFindExact( pTruth, 4, 1, 9, pArrTimeProfile, 50000, 0, fVerbose );
2549 word pTruth[4] = {0xcafe, 0, 0, 0};
2551 Gia_Man_t * pGia, * pGia2, * pGia3, * pGia4, * pMiter;
2553 int pArrTimeProfile[4] = {6, 2, 8, 5};
2573 pGia4 =
Gia_ManFindExact( pTruth, 4, 1, 9, pArrTimeProfile, 50000, 0, fVerbose );
2607 return s_pSesStore != NULL;
2616void Abc_ExactStart(
int nBTLimit,
int fMakeAIG,
int fVerbose,
int fVeryVerbose,
const char * pFilename )
2620 s_pSesStore = Ses_StoreAlloc( nBTLimit, fMakeAIG, fVerbose );
2621 s_pSesStore->fVeryVerbose = fVeryVerbose;
2624 Ses_StoreRead( s_pSesStore, pFilename, 1, 0, 0, 0 );
2627 strcpy( s_pSesStore->szDBName, pFilename );
2629 if ( s_pSesStore->fVeryVerbose )
2631 s_pSesStore->pDebugEntries = fopen(
"bms.debug",
"w" );
2635 printf(
"BMS manager already started\n" );
2643 Ses_StoreWrite( s_pSesStore, pFilename, 1, 0, 0, 0 );
2644 if ( s_pSesStore->pDebugEntries )
2645 fclose( s_pSesStore->pDebugEntries );
2646 Ses_StoreClean( s_pSesStore );
2649 printf(
"BMS manager has not been started\n" );
2658 printf(
"BMS manager has not been started\n" );
2662 printf(
"-------------------------------------------------------------------------------------------------------------------------------\n" );
2663 printf(
" 0 1 2 3 4 5 6 7 8 total\n" );
2664 printf(
"-------------------------------------------------------------------------------------------------------------------------------\n" );
2665 printf(
"number of considered cuts :" );
2666 for ( i = 0; i < 9; ++i )
2667 printf(
"%10lu", s_pSesStore->pCutCount[i] );
2668 printf(
"%10lu\n", s_pSesStore->nCutCount );
2669 printf(
" - trivial :" );
2670 for ( i = 0; i < 9; ++i )
2671 printf(
"%10lu", s_pSesStore->pSynthesizedTrivial[i] );
2672 printf(
"%10lu\n", s_pSesStore->nSynthesizedTrivial );
2673 printf(
" - synth (imp) :" );
2674 for ( i = 0; i < 9; ++i )
2675 printf(
"%10lu", s_pSesStore->pSynthesizedImp[i] );
2676 printf(
"%10lu\n", s_pSesStore->nSynthesizedImp );
2677 printf(
" - synth (res) :" );
2678 for ( i = 0; i < 9; ++i )
2679 printf(
"%10lu", s_pSesStore->pSynthesizedRL[i] );
2680 printf(
"%10lu\n", s_pSesStore->nSynthesizedRL );
2681 printf(
" - not synth (imp) :" );
2682 for ( i = 0; i < 9; ++i )
2683 printf(
"%10lu", s_pSesStore->pUnsynthesizedImp[i] );
2684 printf(
"%10lu\n", s_pSesStore->nUnsynthesizedImp );
2685 printf(
" - not synth (res) :" );
2686 for ( i = 0; i < 9; ++i )
2687 printf(
"%10lu", s_pSesStore->pUnsynthesizedRL[i] );
2688 printf(
"%10lu\n", s_pSesStore->nUnsynthesizedRL );
2689 printf(
" - cache hits :" );
2690 for ( i = 0; i < 9; ++i )
2691 printf(
"%10lu", s_pSesStore->pCacheHits[i] );
2692 printf(
"%10lu\n", s_pSesStore->nCacheHits );
2693 printf(
"-------------------------------------------------------------------------------------------------------------------------------\n" );
2694 printf(
"number of entries : %d\n", s_pSesStore->nEntriesCount );
2695 printf(
"number of valid entries : %d\n", s_pSesStore->nValidEntriesCount );
2696 printf(
"number of invalid entries : %d\n", s_pSesStore->nEntriesCount - s_pSesStore->nValidEntriesCount );
2697 printf(
"-------------------------------------------------------------------------------------------------------------------------------\n" );
2698 printf(
"number of SAT calls : %lu\n", s_pSesStore->nSatCalls );
2699 printf(
"number of UNSAT calls : %lu\n", s_pSesStore->nUnsatCalls );
2700 printf(
"number of UNDEF calls : %lu\n", s_pSesStore->nUndefCalls );
2702 printf(
"-------------------------------------------------------------------------------------------------------------------------------\n" );
2703 printf(
"Runtime breakdown:\n" );
2704 ABC_PRTP(
"Exact ", s_pSesStore->timeExact, s_pSesStore->timeTotal );
2705 ABC_PRTP(
" Sat ", s_pSesStore->timeSat, s_pSesStore->timeTotal );
2706 ABC_PRTP(
" Sat ", s_pSesStore->timeSatSat, s_pSesStore->timeTotal );
2707 ABC_PRTP(
" Unsat ", s_pSesStore->timeSatUnsat, s_pSesStore->timeTotal );
2708 ABC_PRTP(
" Undef ", s_pSesStore->timeSatUndef, s_pSesStore->timeTotal );
2709 ABC_PRTP(
" Instance", s_pSesStore->timeInstance, s_pSesStore->timeTotal );
2710 ABC_PRTP(
"Other ", s_pSesStore->timeTotal - s_pSesStore->timeExact, s_pSesStore->timeTotal );
2711 ABC_PRTP(
"ALL ", s_pSesStore->timeTotal, s_pSesStore->timeTotal );
2718 int i, nMaxArrival, nDelta, l;
2720 char * pSol = NULL, * pSol2 = NULL, *
p;
2721 int pNormalArrTime[8];
2723 abctime timeStart = Abc_Clock(), timeStartExact;
2726 if ( nVars < 0 || nVars > 8 )
2728 printf(
"invalid truth table size %d\n", nVars );
2733 s_pSesStore->nCutCount++;
2734 s_pSesStore->pCutCount[nVars]++;
2738 s_pSesStore->nSynthesizedTrivial++;
2739 s_pSesStore->pSynthesizedTrivial[0]++;
2742 s_pSesStore->timeTotal += ( Abc_Clock() - timeStart );
2748 s_pSesStore->nSynthesizedTrivial++;
2749 s_pSesStore->pSynthesizedTrivial[1]++;
2753 s_pSesStore->timeTotal += ( Abc_Clock() - timeStart );
2754 return pArrTimeProfile[0];
2757 for ( l = 0; l < nVars; ++l )
2758 pNormalArrTime[l] = pArrTimeProfile[l];
2760 nDelta = Abc_NormalizeArrivalTimes( pNormalArrTime, nVars, &nMaxArrival );
2766 s_pSesStore->nCacheHits++;
2767 s_pSesStore->pCacheHits[nVars]++;
2771 if ( s_pSesStore->fVeryVerbose )
2774 Abc_TtPrintHexRev( stdout, pTruth, nVars );
2776 printf(
" [%d", pNormalArrTime[0] );
2777 for ( l = 1; l < nVars; ++l )
2778 printf(
" %d", pNormalArrTime[l] );
2779 printf(
"]@%d:", AigLevel );
2783 nMaxDepth = pNormalArrTime[0];
2784 for ( i = 1; i < nVars; ++i )
2785 nMaxDepth = Abc_MaxInt( nMaxDepth, pNormalArrTime[i] );
2786 nMaxDepth += nVars + 1;
2787 if ( AigLevel != -1 )
2788 nMaxDepth = Abc_MinInt( AigLevel - nDelta, nMaxDepth + nVars + 1 );
2790 timeStartExact = Abc_Clock();
2792 pSes = Ses_ManAlloc( pTruth, nVars, 1 , nMaxDepth, pNormalArrTime, s_pSesStore->fMakeAIG, s_pSesStore->nBTLimit, s_pSesStore->fVerbose );
2794 pSes->
pSat = s_pSesStore->pSat;
2799 if ( s_pSesStore->fVeryVerbose )
2805 if ( ( pSol2 = Ses_ManFindMinimumSize( pSes ) ) != NULL )
2807 if ( s_pSesStore->fVeryVerbose )
2809 if ( pSes->
nMaxDepth >= 10 ) printf(
"\b" );
2819 if ( s_pSesStore->fVeryVerbose )
2821 if ( pSes->
nMaxDepth >= 10 ) printf(
"\b" );
2828 if ( s_pSesStore->fVeryVerbose )
2832 if ( s_pSesStore->pDebugEntries && pSes->
fHitResLimit )
2833 Ses_StorePrintDebugEntry( s_pSesStore, pTruth, nVars, pNormalArrTime, pSes->
nMaxDepth, pSol, nVars - 2 );
2835 pSes->
timeTotal = Abc_Clock() - timeStartExact;
2838 s_pSesStore->nSatCalls += pSes->
nSatCalls;
2842 s_pSesStore->timeSat += pSes->
timeSat;
2847 s_pSesStore->timeExact += pSes->
timeTotal;
2851 Ses_ManCleanLight( pSes );
2854 Ses_StoreAddEntry( s_pSesStore, pTruth, nVars, pNormalArrTime, pSol, fResLimit );
2862 for ( l = 0; l < nVars; ++l )
2869 for ( l = 0; l < nVars; ++l )
2872 Delay2 = Abc_MaxInt( Delay2, pArrTimeProfile[l] + pPerm[l] );
2881 s_pSesStore->timeTotal += ( Abc_Clock() - timeStart );
2888 s_pSesStore->timeTotal += ( Abc_Clock() - timeStart );
2897 int i, j, nMaxArrival;
2898 int pNormalArrTime[8];
2904 abctime timeStart = Abc_Clock();
2908 s_pSesStore->timeTotal += ( Abc_Clock() - timeStart );
2913 s_pSesStore->timeTotal += ( Abc_Clock() - timeStart );
2917 for ( i = 0; i < nVars; ++i )
2918 pNormalArrTime[i] = pArrTimeProfile[i];
2919 Abc_NormalizeArrivalTimes( pNormalArrTime, nVars, &nMaxArrival );
2923 s_pSesStore->timeTotal += ( Abc_Clock() - timeStart );
2931 pGateTruth[3] =
'0';
2932 pGateTruth[4] =
'\0';
2935 for ( i = 0; i < nVars; ++i )
2938 Vec_PtrPush( pGates, pFanins[i] );
2945 pGateTruth[2] =
'0' + ( *
p & 1 );
2946 pGateTruth[1] =
'0' + ( ( *
p >> 1 ) & 1 );
2947 pGateTruth[0] =
'0' + ( ( *
p >> 2 ) & 1 );
2955 for ( j = 0; j < 4; ++j )
2956 pGateTruth[j] = ( pGateTruth[j] ==
'0' ) ?
'1' :
'0';
2959 pObj = Abc_NtkCreateNode( pNtk );
2962 Vec_PtrPush( pGates, pObj );
2970 pObj = (
Abc_Obj_t *)Vec_PtrEntry( pGates, nVars + Abc_Lit2Var( *
p ) );
2972 Vec_PtrFree( pGates );
2974 s_pSesStore->timeTotal += ( Abc_Clock() - timeStart );
2981 word pTruth[4] = {0xcafe, 0, 0, 0};
2982 int pArrTimeProfile[4] = {6, 2, 8, 5};
2986 char pPerm[4] = {0};
2994 Vec_PtrPush( pNtk->
vObjs, NULL );
2995 for ( i = 0; i < 4; ++i )
2997 pFanins[i] = Abc_NtkCreatePi( pNtk );
3010 (*pArrTimeProfile)++;
3012 (*pArrTimeProfile)--;
#define ABC_EXACT_SOL_NGATES
Abc_Ntk_t * Abc_NtkFromTruthTable(word *pTruth, int nVars)
Abc_Ntk_t * Abc_NtkFindExact(word *pTruth, int nVars, int nFunc, int nMaxDepth, int *pArrTimeProfile, int nBTLimit, int nStartGates, int fVerbose)
int Abc_ExactDelayCost(word *pTruth, int nVars, int *pArrTimeProfile, char *pPerm, int *Cost, int AigLevel)
void Abc_ExactStoreTest(int fVerbose)
#define ANSI_COLOR_YELLOW
struct Ses_TruthEntry_t_ Ses_TruthEntry_t
Gia_Man_t * Gia_ManFindExact(word *pTruth, int nVars, int nFunc, int nMaxDepth, int *pArrTimeProfile, int nBTLimit, int nStartGates, int fVerbose)
Abc_Obj_t * Abc_ExactBuildNode(word *pTruth, int nVars, int *pArrTimeProfile, Abc_Obj_t **pFanins, Abc_Ntk_t *pNtk)
void Abc_ExactTestSingleOutput(int fVerbose)
struct Ses_Store_t_ Ses_Store_t
void Abc_ExactStop(const char *pFilename)
void Abc_ExactStart(int nBTLimit, int fMakeAIG, int fVerbose, int fVeryVerbose, const char *pFilename)
int Ses_StoreGetEntry(Ses_Store_t *pStore, word *pTruth, int nVars, int *pArrTimeProfile, char **pSol)
#define ABC_EXACT_SOL_NVARS
void Abc_ExactTestSingleOutputAIG(int fVerbose)
int Ses_StoreAddEntry(Ses_Store_t *pStore, word *pTruth, int nVars, int *pArrTimeProfile, char *pSol, int fResLimit)
void Abc_ExactTest(int fVerbose)
struct Ses_Man_t_ Ses_Man_t
#define ABC_EXACT_SOL_NFUNC
int Ses_StoreGetEntrySimple(Ses_Store_t *pStore, word *pTruth, int nVars, int *pArrTimeProfile, char **pSol)
#define SES_STORE_TABLE_SIZE
struct Ses_TimesEntry_t_ Ses_TimesEntry_t
void Abc_NtkCecSat(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int nConfLimit, int nInsLimit)
FUNCTION DEFINITIONS ///.
struct Abc_Obj_t_ Abc_Obj_t
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeBuf(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
ABC_DLL char * Abc_SopFromTruthBin(char *pTruth)
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
ABC_DLL void Abc_NodeFreeNames(Vec_Ptr_t *vNames)
ABC_DLL Gia_Man_t * Abc_NtkAigToGia(Abc_Ntk_t *p, int fGiaSimple)
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
ABC_DLL char * Abc_SopCreateFromTruth(Mem_Flex_t *pMan, int nVars, unsigned *pTruth)
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_NtkToAig(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
ABC_DLL Vec_Ptr_t * Abc_NodeGetFakeNames(int nNames)
ABC_DLL char * Abc_SopRegister(Mem_Flex_t *pMan, const char *pName)
DECLARATIONS ///.
ABC_DLL void Abc_NtkShortNames(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Ntk_t * Abc_NtkCreateWithNode(char *pSop)
#define ABC_PRTP(a, t, T)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_CALLOC(type, num)
#define ABC_CONST(number)
PARAMETERS ///.
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
ABC_NAMESPACE_IMPL_START typedef signed char value
#define sat_solver_addclause
void Cec_ManCecSetDefaultParams(Cec_ParCec_t *p)
struct Cec_ParCec_t_ Cec_ParCec_t
int Cec_ManVerify(Gia_Man_t *p, Cec_ParCec_t *pPars)
MACRO DEFINITIONS ///.
void Gia_ManStop(Gia_Man_t *p)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
struct Gia_Man_t_ Gia_Man_t
Gia_Man_t * Gia_ManMiter(Gia_Man_t *pAig0, Gia_Man_t *pAig1, int nInsDup, int fDualOut, int fSeq, int fImplic, int fVerbose)
unsigned __int64 word
DECLARATIONS ///.
Mem_Flex_t * Mem_FlexStart()
void Mem_FlexStop(Mem_Flex_t *p, int fVerbose)
struct Mem_Flex_t_ Mem_Flex_t
sat_solver * sat_solver_new(void)
void sat_solver_restart(sat_solver *s)
int sat_solver_nclauses(sat_solver *s)
void sat_solver_setnvars(sat_solver *s, int n)
int sat_solver_nvars(sat_solver *s)
void sat_solver_delete(sat_solver *s)
int pArrTimeProfileTmp[8]
Vec_Int_t * vStairDecVars
unsigned long nSynthesizedRL
unsigned long pUnsynthesizedRL[9]
unsigned long nSynthesizedImp
unsigned long pSynthesizedImp[9]
unsigned long nUnsatCalls
unsigned long pSynthesizedTrivial[9]
unsigned long pSynthesizedRL[9]
unsigned long pUnsynthesizedImp[9]
Ses_TruthEntry_t * pEntries[SES_STORE_TABLE_SIZE]
unsigned long pCacheHits[9]
unsigned long nUndefCalls
unsigned long nSynthesizedTrivial
unsigned long pCutCount[9]
unsigned long nUnsynthesizedImp
unsigned long nUnsynthesizedRL
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.