69static inline Res6_Man_t * Res6_ManStart(
int nIns,
int nNodes,
int nOuts,
int nPats )
74 p->nDivs = 1 + nIns + nNodes;
78 p->nWords =(nPats + 63)/64;
79 Vec_WrdFill( &
p->vIns, 2*
p->nDivsA*
p->nWords, 0 );
80 Vec_WrdFill( &
p->vOuts, (1 << nOuts)*
p->nWords, 0 );
83 for ( i = 0; i < 2*
p->nDivsA; i++ )
84 p->ppLits[i] = Vec_WrdEntryP( &
p->vIns, i*
p->nWords );
85 for ( i = 0; i < (1 << nOuts); i++ )
86 p->ppSets[i] = Vec_WrdEntryP( &
p->vOuts, i*
p->nWords );
87 Abc_TtFill(
p->ppLits[1],
p->nWords );
88 Vec_IntGrow( &
p->vSol, 2*
MAX_NODE+nOuts );
89 Vec_IntGrow( &
p->vSolBest, 2*
MAX_NODE+nOuts );
90 Vec_IntGrow( &
p->vTempBest, 2*
MAX_NODE+nOuts );
95 Vec_WrdErase( &
p->vIns );
96 Vec_WrdErase( &
p->vOuts );
97 Vec_IntErase( &
p->vSol );
98 Vec_IntErase( &
p->vSolBest );
99 Vec_IntErase( &
p->vTempBest );
100 Vec_IntErase( &
p->vSupp );
121 Res6_Man_t *
p = pData ? Res6_ManStart( 0, pData->nIns, pData->nOuts, pData->nPats ) : NULL;
122 if (
p == NULL )
return NULL;
123 assert( pData->nSimWords ==
p->nWords );
124 for ( i = 1; i <
p->nDivs; i++ )
125 for ( n = 0; n < 2; n++ )
126 Abc_TtCopy(
p->ppLits[2*i+n], Vec_WrdEntryP(pData->vSimsIn, (i-1)*pData->nSimWords), pData->nSimWords, n );
127 for ( i = 0; i < (1 <<
p->nOuts); i++ )
128 Abc_TtCopy(
p->ppSets[i], Vec_WrdEntryP(pData->vSimsOut, i*pData->nSimWords), pData->nSimWords, 0 );
131 Vec_IntPush( &
p->vSupp, 1+n );
134 Vec_IntPush( &
p->vSol, n );
135 Vec_IntPush( &
p->vSol, Vec_IntEntryLast(&
p->vSol) );
137 Abc_RDataStop( pData );
155 FILE * pFile = fopen( pFileName,
"rb" );
157 printf(
"Cannot open input file \"%s\".\n", pFileName );
160 int i, k, nIns, nNodes, nOuts, nPats;
161 char Temp[100], Buffer[100];
162 char * pLine = fgets( Buffer, 100, pFile );
165 printf(
"Cannot read the header line of input file \"%s\".\n", pFileName );
168 if ( 5 != sscanf(pLine,
"%s %d %d %d %d", Temp, &nIns, &nNodes, &nOuts, &nPats) )
170 printf(
"Cannot read the parameters from the header of input file \"%s\".\n", pFileName );
173 p = Res6_ManStart( nIns, nNodes, nOuts, nPats );
175 for ( i = 1; i <
p->nDivs; i++ )
177 char * pNext = fgets( pLine, nPats + 100, pFile );
180 printf(
"Cannot read line %d of input file \"%s\".\n", i, pFileName );
186 for ( k = 0; k <
p->nPats; k++ )
187 if ( pNext[k] ==
'0' )
188 Abc_TtSetBit(
p->ppLits[2*i+1], k );
189 else if ( pNext[k] ==
'1' )
190 Abc_TtSetBit(
p->ppLits[2*i], k );
192 for ( i = 0; i < (1 <<
p->nOuts); i++ )
194 char * pNext = fgets( pLine, nPats + 100, pFile );
197 printf(
"Cannot read line %d of input file \"%s\".\n", i, pFileName );
203 for ( k = 0; k <
p->nPats; k++ )
204 if ( pNext[k] ==
'1' )
205 Abc_TtSetBit(
p->ppSets[i], k );
214 FILE * pFile = fopen( pFileName,
"wb" );
216 printf(
"Cannot open output file \"%s\".\n", pFileName );
220 fprintf( pFile,
"resyn %d %d %d %d\n",
p->nIns,
p->nDivs -
p->nIns - 1,
p->nOuts,
p->nPats );
221 for ( i = 1; i <
p->nDivs; i++, fputc(
'\n', pFile) )
222 for ( k = 0; k <
p->nPats; k++ )
223 if ( Abc_TtGetBit(
p->ppLits[2*i+1], k) )
225 else if ( Abc_TtGetBit(
p->ppLits[2*i], k) )
229 for ( i = 0; i < (1 <<
p->nOuts); i++, fputc(
'\n', pFile) )
230 for ( k = 0; k <
p->nPats; k++ )
231 fputc(
'0' + Abc_TtGetBit(
p->ppSets[i], k), pFile );
237 int i, nInputs = (
p->nIns &&
p->nIns < 6) ?
p->nIns : 6;
238 printf(
"Problem: In = %d Div = %d Out = %d Pat = %d\n",
p->nIns,
p->nDivs -
p->nIns - 1,
p->nOuts,
p->nPats );
241 printf(
"%02d : %s\n", 0,
"const0" );
242 printf(
"%02d : %s\n", 1,
"const1" );
243 for ( i = 1; i <
p->nDivs; i++ )
247 *
p->ppLits[2*i+0] = Abc_Tt6Stretch( *
p->ppLits[2*i+0], nInputs );
248 *
p->ppLits[2*i+1] = Abc_Tt6Stretch( *
p->ppLits[2*i+1], nInputs );
253 for ( i = 0; i < (1 <<
p->nOuts); i++ )
256 *
p->ppSets[i] = Abc_Tt6Stretch( *
p->ppSets[i], nInputs );
260static inline Vec_Int_t * Res6_ManReadSol(
char * pFileName )
263 FILE * pFile = fopen( pFileName,
"rb" );
265 printf(
"Cannot open input file \"%s\".\n", pFileName );
268 while ( fgetc(pFile) !=
'\n' );
269 vRes = Vec_IntAlloc( 10 );
270 while ( fscanf(pFile,
"%d", &Num) == 1 )
271 Vec_IntPush( vRes, Num );
276static inline void Res6_ManWriteSol(
char * pFileName,
Vec_Int_t *
p )
278 FILE * pFile = fopen( pFileName,
"wb" );
280 printf(
"Cannot open output file \"%s\".\n", pFileName );
285 fprintf( pFile,
"%d ", iLit );
301static inline int Res6_LitSign(
int iLit )
303 return Abc_LitIsCompl(iLit) ?
'~' :
' ';
305static inline int Res6_LitChar(
int iLit,
int nDivs )
307 return Abc_Lit2Var(iLit) < nDivs ? (nDivs < 28 ?
'a'+Abc_Lit2Var(iLit)-1 :
'd') :
'x';
309static inline void Res6_LitPrint(
int iLit,
int nDivs )
312 printf(
"%d", iLit );
315 printf(
"%c%c", Res6_LitSign(iLit), Res6_LitChar(iLit, nDivs) );
316 if ( Abc_Lit2Var(iLit) >= nDivs || nDivs >= 28 )
317 printf(
"%d", Abc_Lit2Var(iLit) );
325 if ( iLit >= 2 && iLit < 2*nDivs )
326 Vec_IntPushUnique( vSupp, Abc_Lit2Var(iLit) );
335 for ( k = 0; k < 64*
nWords; k++ )
336 if ( Abc_TtGetBit(ppLits[2*iObj+1], k) )
338 else if ( Abc_TtGetBit(ppLits[2*iObj], k) )
344 for ( k = 0; k < 64*
nWords; k++ )
347 if ( Abc_TtGetBit(ppLits[2*iObj+1], k) )
349 else if ( Abc_TtGetBit(ppLits[2*iObj+0], k) )
357 Vec_IntFree( vSupp );
362 int Res = Vec_IntSize(vSupp);
363 Vec_IntFree( vSupp );
368 int iNode, nNodes = Vec_IntSize(vSol)/2-1;
369 assert( Vec_IntSize(vSol) % 2 == 0 );
370 printf(
"Solution: In = %d Div = %d Node = %d Out = %d\n",
Res6_FindSupportSize(vSol, nDivs), nDivs-1, nNodes, 1 );
371 for ( iNode = 0; iNode <= nNodes; iNode++ )
373 int * pLits = Vec_IntEntryP( vSol, 2*iNode );
374 printf(
"x%-2d = ", nDivs + iNode );
375 Res6_LitPrint( pLits[0], nDivs );
376 if ( pLits[0] != pLits[1] )
378 printf(
" %c ", pLits[0] < pLits[1] ?
'&' :
'^' );
379 Res6_LitPrint( pLits[1], nDivs );
393 for ( w = 0; w <
p->nWords; w++ )
394 Cost += Abc_TtCountOnes( (
p->ppLits[iDiv][w] &
p->ppSets[0][w]) | (
p->ppLits[iDiv^1][w] &
p->ppSets[1][w]) );
400 for ( d = 0; d < 2*
p->nDivs; d++ )
403 printf(
"Div = %d Cost = %d\n", d, Cost );
404 if ( CostBest >= Cost )
405 CostBest = Cost, dBest = d;
414 assert( Vec_IntSize(vSol) % 2 == 0 );
419 Abc_TtXor(
p->ppLits[2*
p->nDivs+i+0],
p->ppLits[iLit0],
p->ppLits[iLit1],
p->nWords, 0 );
420 Abc_TtXor(
p->ppLits[2*
p->nDivs+i+1],
p->ppLits[iLit0],
p->ppLits[iLit1],
p->nWords, 1 );
424 Abc_TtAnd(
p->ppLits[2*
p->nDivs+i+0],
p->ppLits[iLit0],
p->ppLits[iLit1],
p->nWords, 0 );
425 Abc_TtOr (
p->ppLits[2*
p->nDivs+i+1],
p->ppLits[iLit0^1],
p->ppLits[iLit1^1],
p->nWords );
450 printf(
"Verification successful.\n" );
452 printf(
"Verification FAILED with %d errors on %d patterns.\n", Cost,
p->nPats );
456 char FileNameSol[1000];
458 strcpy( FileNameSol, pFileNameSol );
461 strcpy( FileNameSol, pFileNameRes );
466 Vec_Int_t * vSol = Res6_ManReadSol( FileNameSol );
468 if (
p == NULL || vSol == NULL )
495 int i, n, iObj, iLit0, iLit1, iOffset = 2*(1+Vec_IntSize(&
p->vSupp));
496 assert( Vec_IntSize(vSol) % 2 == 0 );
498 for ( n = 0; n < 2; n++ )
499 Abc_TtCopy(
p->ppLits[2*(1+i)+n],
p->ppLits[2*iObj+n],
p->nWords, 0 );
504 Abc_TtXor(
p->ppLits[iOffset+i+0],
p->ppLits[iLit0],
p->ppLits[iLit1],
p->nWords, 0 );
505 Abc_TtXor(
p->ppLits[iOffset+i+1],
p->ppLits[iLit0],
p->ppLits[iLit1],
p->nWords, 1 );
509 Abc_TtAnd(
p->ppLits[iOffset+i+0],
p->ppLits[iLit0],
p->ppLits[iLit1],
p->nWords, 0 );
510 Abc_TtOr (
p->ppLits[iOffset+i+1],
p->ppLits[iLit0^1],
p->ppLits[iLit1^1],
p->nWords );
519 printf(
"Verification successful.\n" );
521 printf(
"Verification FAILED with %d errors on %d patterns.\n", Cost,
p->nPats );
525 int iNode, nNodes = Vec_IntSize(vSol)/2-1;
526 assert( Vec_IntSize(vSol) % 2 == 0 );
527 printf(
"Solution: In = %d Div = %d Node = %d Out = %d\n", nSuppSize, nDivs-1, nNodes, 1 );
528 for ( iNode = 0; iNode <= nNodes; iNode++ )
530 int * pLits = Vec_IntEntryP( vSol, 2*iNode );
531 printf(
"x%-2d = ", 1+nSuppSize+iNode );
532 Res6_LitPrint( pLits[0], 1+nSuppSize );
533 if ( pLits[0] != pLits[1] )
535 printf(
" %c ", pLits[0] < pLits[1] ?
'&' :
'^' );
536 Res6_LitPrint( pLits[1], 1+nSuppSize );
544 if (
p == NULL )
return;
#define ABC_ALLOC(type, num)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
int Res6_FindBestDiv(Res6_Man_t *p, int *pCost)
Vec_Int_t * Res6_FindSupport(Vec_Int_t *vSol, int nDivs)
int Res6_FindBestEval(Res6_Man_t *p, Vec_Int_t *vSol, int Start)
#define MAX_NODE
DECLARATIONS ///.
void Res6_ManResubCheckPla(char *pFileName, int fVerbose)
int Res6_FindSupportSize(Vec_Int_t *vSol, int nDivs)
Res6_Man_t * Res6_ManRead(char *pFileName)
void Res6_ManResubCheck(char *pFileNameRes, char *pFileNameSol, int fVerbose)
int Res6_FindGetCost(Res6_Man_t *p, int iDiv)
void Res6_PrintSuppSims(Vec_Int_t *vSol, word **ppLits, int nWords, int nDivs)
void Res6_ManPrintProblem(Res6_Man_t *p, int fVerbose)
void Res6_ManResubVerifyPla(Res6_Man_t *p, Vec_Int_t *vSol)
Res6_Man_t * Res6_ManReadPla(char *pFileName)
void Dau_DsdPrintFromTruth2(word *pTruth, int nVarsInit)
int Res6_FindBestEvalPla(Res6_Man_t *p, Vec_Int_t *vSol)
void Res6_ManResubVerify(Res6_Man_t *p, Vec_Int_t *vSol)
void Res6_PrintSolutionPla(Vec_Int_t *vSol, int nSuppSize, int nDivs)
void Res6_ManWrite(char *pFileName, Res6_Man_t *p)
struct Res6_Man_t_ Res6_Man_t
void Res6_PrintSolution(Vec_Int_t *vSol, int nDivs)
typedefABC_NAMESPACE_HEADER_START struct Abc_RData_t_ Abc_RData_t
INCLUDES ///.
unsigned __int64 word
DECLARATIONS ///.
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryDoubleStart(vVec, Entry1, Entry2, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.