Skip to content

Commit 0e4a080

Browse files
committed
Enabling "if" to dump the cut and truth table info.
1 parent 192c161 commit 0e4a080

File tree

4 files changed

+147
-1
lines changed

4 files changed

+147
-1
lines changed

src/map/if/if.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ struct If_Man_t_
285285
int pDumpIns[16];
286286
Vec_Str_t * vMarks;
287287
Vec_Int_t * vVisited2;
288+
Vec_Int_t * vCuts;
289+
Vec_Int_t * vCutCosts;
288290

289291
// timing manager
290292
Tim_Man_t * pManTim;

src/map/if/ifCore.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ int If_ManPerformMappingComb( If_Man_t * p )
154154
// area oriented mapping
155155
for ( i = 0; i < p->pPars->nAreaIters; i++ )
156156
{
157+
if ( p->pPars->fDumpFile && p->pPars->nLutSize <= 6 && i == p->pPars->nAreaIters-1 ) {
158+
p->vCuts = Vec_IntAlloc( 1 << 20 );
159+
p->vCutCosts = Vec_IntAlloc( 1 << 16 );
160+
}
157161
If_ManPerformMappingRound( p, p->pPars->nCutsMax, 2, 0, 0, "Area" );
158162
if ( p->pPars->fExpRed )
159163
If_ManImproveMapping( p );

src/map/if/ifMan.c

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,121 @@ void If_ManRestart( If_Man_t * p )
199199
p->nObjs[IF_CI] = p->nObjs[IF_CO] = p->nObjs[IF_AND] = 0;
200200
}
201201

202+
/**Function*************************************************************
203+
204+
Synopsis []
205+
206+
Description []
207+
208+
SideEffects []
209+
210+
SeeAlso []
211+
212+
***********************************************************************/
213+
void If_ManSimpleSort( int * pArray, int nSize )
214+
{
215+
int temp, i, j, best_i;
216+
for ( i = 0; i < nSize-1; i++ ) {
217+
best_i = i;
218+
for ( j = i+1; j < nSize; j++ )
219+
if ( pArray[j] < pArray[best_i] )
220+
best_i = j;
221+
temp = pArray[i];
222+
pArray[i] = pArray[best_i];
223+
pArray[best_i] = temp;
224+
}
225+
}
226+
void If_ManDumpCut( If_Cut_t * pCut, int nLutSize, Vec_Int_t * vCuts )
227+
{
228+
int i;
229+
for ( i = 0; i < pCut->nLeaves; i++ )
230+
Vec_IntPush( vCuts, pCut->pLeaves[i] );
231+
for ( ; i < nLutSize; i++ )
232+
Vec_IntPush( vCuts, 0 );
233+
}
234+
void If_ManDumpCutsAndCost( If_Man_t * p, If_Obj_t * pObj, Vec_Int_t * vCuts, Vec_Int_t * vCutCosts )
235+
{
236+
If_Cut_t * pCut; int k, nCuts = 0;
237+
while ( nCuts < p->pPars->nCutsMax ) {
238+
If_ObjForEachCut( pObj, pCut, k ) {
239+
If_ManDumpCut( pCut, p->pPars->nLutSize, vCuts );
240+
Vec_IntPush( vCutCosts, (int)pCut->Area );
241+
if ( ++nCuts == p->pPars->nCutsMax )
242+
break;
243+
}
244+
}
245+
}
246+
void If_ManDumpCutsAndCostAdd( int Obj, int nCutsMax, int nLutSize, Vec_Int_t * vCopy, Vec_Int_t * vCuts, Vec_Int_t * vCutCosts, Vec_Int_t * vCutsOut, Vec_Int_t * vCutCostsOut )
247+
{
248+
int i, * pCuts = Vec_IntEntryP( vCuts, Obj * nCutsMax * nLutSize );
249+
for ( i = 0; i < nCutsMax * nLutSize; i++ )
250+
pCuts[i] = Vec_IntEntry(vCopy, pCuts[i]);
251+
for ( i = 0; i < nCutsMax; i++ )
252+
If_ManSimpleSort( pCuts + i*nLutSize, nLutSize );
253+
for ( i = 0; i < nCutsMax * nLutSize; i++ )
254+
Vec_IntPush( vCutsOut, pCuts[i] );
255+
for ( i = 0; i < nCutsMax; i++ )
256+
Vec_IntPush( vCutCostsOut, Vec_IntEntry( vCutCosts, Obj * nCutsMax + i ) );
257+
}
258+
int If_ManDumpData( If_Man_t * p, FILE * pFile )
259+
{
260+
Vec_Int_t * vCopy = Vec_IntStartFull( If_ManObjNum(p) );
261+
Vec_Int_t * vCopy2 = Vec_IntAlloc( If_ManObjNum(p) );
262+
Vec_Int_t * vLevelLims = Vec_IntAlloc( p->nLevelMax + 1 );
263+
Vec_Int_t * vCuts = Vec_IntAlloc( 1 << 20 );
264+
Vec_Int_t * vFanins = Vec_IntAlloc( If_ManCoNum(p) );
265+
Vec_Int_t * vCutCosts = Vec_IntAlloc( 1 << 16 );
266+
Vec_Int_t * vLevel; If_Obj_t * pObj;
267+
int i, k, Obj, nObjs = 0, nBytes = 0;
268+
Vec_Wec_t * vLevels = Vec_WecStart( p->nLevelMax );
269+
If_ManForEachNode( p, pObj, i )
270+
Vec_WecPush( vLevels, pObj->Level, i );
271+
Vec_IntWriteEntry( vCopy, 0, nObjs++ );
272+
If_ManForEachCi( p, pObj, i )
273+
Vec_IntWriteEntry( vCopy, pObj->Id, nObjs++ );
274+
Vec_WecForEachLevelStart( vLevels, vLevel, i, 1 )
275+
Vec_IntForEachEntry( vLevel, Obj, k ) {
276+
Vec_IntWriteEntry( vCopy, Obj, nObjs++ );
277+
Vec_IntPush( vCopy2, Obj - 1 - If_ManCiNum(p) );
278+
}
279+
assert( Vec_IntSize(vCopy2) == If_ManAndNum(p) );
280+
assert( nObjs == 1 + If_ManCiNum(p) + If_ManAndNum(p) );
281+
nObjs = If_ManCiNum(p) + 1;
282+
Vec_WecForEachLevelStart( vLevels, vLevel, i, 1 ) {
283+
Vec_IntPush( vLevelLims, nObjs );
284+
nObjs += Vec_IntSize(vLevel);
285+
}
286+
Vec_IntPush( vLevelLims, nObjs );
287+
assert( Vec_IntSize(vLevelLims) == p->nLevelMax + 1 );
288+
Vec_IntForEachEntry( vCopy2, Obj, i )
289+
If_ManDumpCutsAndCostAdd( Obj, p->pPars->nCutsMax, p->pPars->nLutSize, vCopy, p->vCuts, p->vCutCosts, vCuts, vCutCosts );
290+
assert( Vec_IntSize(vCuts) == If_ManAndNum(p) * p->pPars->nCutsMax * p->pPars->nLutSize );
291+
assert( Vec_IntSize(vCutCosts) == If_ManAndNum(p) * p->pPars->nCutsMax );
292+
If_ManForEachCo( p, pObj, i )
293+
Vec_IntPush( vFanins, Vec_IntEntry(vCopy, pObj->pFanin0->Id) );
294+
nBytes += fwrite( Vec_IntArray(vCuts), 1, sizeof(int)*Vec_IntSize(vCuts), pFile );
295+
nBytes += fwrite( Vec_IntArray(vFanins), 1, sizeof(int)*Vec_IntSize(vFanins), pFile );
296+
nBytes += fwrite( Vec_IntArray(vLevelLims), 1, sizeof(int)*Vec_IntSize(vLevelLims), pFile );
297+
nBytes += fwrite( Vec_IntArray(vCutCosts), 1, sizeof(int)*Vec_IntSize(vCutCosts), pFile );
298+
if ( 0 ) {
299+
Vec_WecPrint( vLevels, 0 );
300+
Vec_IntPrint( vCopy );
301+
Vec_IntPrint( vCopy2 );
302+
Vec_IntPrint( vLevelLims );
303+
Vec_IntPrint( vCuts );
304+
Vec_IntPrint( vFanins );
305+
Vec_IntPrint( vCutCosts );
306+
}
307+
Vec_WecFree( vLevels );
308+
Vec_IntFree( vCopy );
309+
Vec_IntFree( vCopy2 );
310+
Vec_IntFree( vLevelLims );
311+
Vec_IntFree( vCuts );
312+
Vec_IntFree( vFanins );
313+
Vec_IntFree( vCutCosts );
314+
return nBytes;
315+
}
316+
202317
/**Function*************************************************************
203318
204319
Synopsis []
@@ -212,7 +327,26 @@ void If_ManRestart( If_Man_t * p )
212327
***********************************************************************/
213328
void If_ManStop( If_Man_t * p )
214329
{
215-
if ( p->pPars->fDumpFile && p->pPars->fTruth )
330+
if ( p->pPars->fDumpFile && p->pPars->nLutSize <= 6 )
331+
{
332+
char pFileName[1000] = {0};
333+
// "I15_O20_L32_N256_C16_K6__name.bin"
334+
char * pName = Extra_FileNameGeneric(Extra_FileNameWithoutPath(p->pName));
335+
sprintf( pFileName, "I%d_O%d_L%d_N%d_C%d_K%d__%s.bin", If_ManCiNum(p), If_ManCoNum(p), p->nLevelMax, If_ManAndNum(p), p->pPars->nCutsMax, p->pPars->nLutSize, pName );
336+
ABC_FREE( pName );
337+
FILE * pFile = fopen( pFileName, "wb" );
338+
if ( pFile == NULL )
339+
printf( "Cannot open file \"%s\" for writing.\n", pFileName );
340+
else {
341+
int nBytes = If_ManDumpData( p, pFile );
342+
int nBytes2 = sizeof(int) * (If_ManAndNum(p) * p->pPars->nCutsMax * p->pPars->nLutSize + If_ManCoNum(p) + p->nLevelMax + 1);
343+
nBytes2 += sizeof(int) * (If_ManAndNum(p) * p->pPars->nCutsMax);
344+
assert( nBytes == nBytes2 );
345+
fclose( pFile );
346+
printf( "Finished writing cut information into file \"%s\" (%.3f MB).\n", pFileName, 1.0 * nBytes / (1<<20) );
347+
}
348+
}
349+
else if ( p->pPars->fDumpFile && p->pPars->fTruth )
216350
{
217351
char pFileName[1000] = {0}, pBuffer[100];
218352
int nUnique = 0, nChunks = 0, nChunkSize = 1 << 10, nBytes = 0;
@@ -314,6 +448,8 @@ void If_ManStop( If_Man_t * p )
314448
Vec_PtrFreeP( &p->vVisited );
315449
Vec_StrFreeP( &p->vMarks );
316450
Vec_IntFreeP( &p->vVisited2 );
451+
Vec_IntFreeP( &p->vCuts );
452+
Vec_IntFreeP( &p->vCutCosts );
317453
if ( p->vPairHash )
318454
Hash_IntManStop( p->vPairHash );
319455
for ( i = 6; i <= Abc_MaxInt(6,p->pPars->nLutSize); i++ )

src/map/if/ifMap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ void If_ObjPerformMappingAnd( If_Man_t * p, If_Obj_t * pObj, int Mode, int fPrep
503503
if ( p->pPars->pFuncUser )
504504
If_ObjForEachCut( pObj, pCut, i )
505505
p->pPars->pFuncUser( p, pObj, pCut );
506+
if ( p->vCuts ) {
507+
extern void If_ManDumpCutsAndCost( If_Man_t * p, If_Obj_t * pObj, Vec_Int_t * vCuts, Vec_Int_t * vCutCosts );
508+
If_ManDumpCutsAndCost( p, pObj, p->vCuts, p->vCutCosts );
509+
}
506510
// free the cuts
507511
If_ManDerefNodeCutSet( p, pObj );
508512
}

0 commit comments

Comments
 (0)