From 76bed2055cc171109a86bf56c6da00aa4d251a30 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Sat, 8 May 2021 20:10:44 -0700 Subject: Updating LUT synthesis code. --- src/aig/gia/giaGen.c | 30 +++++++++++ src/aig/gia/giaMinLut.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++ src/base/abci/abc.c | 5 +- src/misc/vec/vecWrd.h | 57 +++++++++++++++++++++ 4 files changed, 220 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/aig/gia/giaGen.c b/src/aig/gia/giaGen.c index 3c0d2235..3c813d5c 100644 --- a/src/aig/gia/giaGen.c +++ b/src/aig/gia/giaGen.c @@ -195,6 +195,36 @@ int Gia_ManSimulateWordsInit( Gia_Man_t * p, Vec_Wrd_t * vSimsIn ) return 1; } +Vec_Wrd_t * Gia_ManSimulateWordsOut( Gia_Man_t * p, Vec_Wrd_t * vSimsIn ) +{ + Gia_Obj_t * pObj; int i, Id; + int nWords = Vec_WrdSize(vSimsIn) / Gia_ManCiNum(p); + Vec_Wrd_t * vSimsOut = Vec_WrdStart( nWords * Gia_ManCoNum(p) ); + assert( Vec_WrdSize(vSimsIn) == nWords * Gia_ManCiNum(p) ); + // allocate simulation info for one timeframe + Vec_WrdFreeP( &p->vSims ); + p->vSims = Vec_WrdStart( Gia_ManObjNum(p) * nWords ); + p->nSimWords = nWords; + // set input sim info + Gia_ManForEachCiId( p, Id, i ) + memcpy( Vec_WrdEntryP(p->vSims, Id*nWords), Vec_WrdEntryP(vSimsIn, i*nWords), sizeof(word)*nWords ); + // perform simulation + Gia_ManForEachObj1( p, pObj, i ) + { + if ( Gia_ObjIsAnd(pObj) ) + Gia_ManObjSimAnd( p, i ); + else if ( Gia_ObjIsCi(pObj) ) + continue; + else if ( Gia_ObjIsCo(pObj) ) + Gia_ManObjSimPo( p, i ); + else assert( 0 ); + } + // set output sim info + Gia_ManForEachCoId( p, Id, i ) + memcpy( Vec_WrdEntryP(vSimsOut, i*nWords), Vec_WrdEntryP(p->vSims, Id*nWords), sizeof(word)*nWords ); + return vSimsOut; +} + /**Function************************************************************* Synopsis [Dump data files.] diff --git a/src/aig/gia/giaMinLut.c b/src/aig/gia/giaMinLut.c index 660b3c8f..7d0ac8e1 100644 --- a/src/aig/gia/giaMinLut.c +++ b/src/aig/gia/giaMinLut.c @@ -40,6 +40,136 @@ ABC_NAMESPACE_IMPL_START /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Vec_WrdReadText( char * pFileName, Vec_Wrd_t ** pvSimI, Vec_Wrd_t ** pvSimO, int nIns, int nOuts ) +{ + int i, nSize, iLine, nLines, nWords; + char pLine[1000]; + Vec_Wrd_t * vSimI, * vSimO; + FILE * pFile = fopen( pFileName, "rb" ); + if ( pFile == NULL ) + { + printf( "Cannot open file \"%s\" for reading.\n", pFileName ); + return; + } + fseek( pFile, 0, SEEK_END ); + nSize = ftell( pFile ); + if ( nSize % (nIns + nOuts + 1) > 0 ) + { + printf( "Cannot read file with simulation data that is not aligned at 8 bytes (remainder = %d).\n", nSize % (nIns + nOuts + 1) ); + fclose( pFile ); + return; + } + rewind( pFile ); + nLines = nSize / (nIns + nOuts + 1); + nWords = (nLines + 63)/64; + vSimI = Vec_WrdStart( nIns *nWords ); + vSimO = Vec_WrdStart( nOuts*nWords ); + for ( iLine = 0; fgets( pLine, 1000, pFile ); iLine++ ) + { + for ( i = 0; i < nIns; i++ ) + if ( pLine[i] == '1' ) + Abc_TtXorBit( Vec_WrdArray(vSimI) + i*nWords, iLine ); + else assert( pLine[i] == '0' ); + for ( i = 0; i < nOuts; i++ ) + if ( pLine[nIns+i] == '1' ) + Abc_TtXorBit( Vec_WrdArray(vSimO) + i*nWords, iLine ); + else assert( pLine[nIns+i] == '0' ); + } + fclose( pFile ); + *pvSimI = vSimI; + *pvSimO = vSimO; + printf( "Read %d words of simulation data for %d inputs and %d outputs.\n", nWords, nIns, nOuts ); +} +void Gia_ManSimInfoTransform( int fSmall ) +{ + int nIns = fSmall ? 32 : 64; + int nOuts = fSmall ? 10 : 35; + char * pFileName = fSmall ? "io_s.txt" : "io_l.txt"; + Vec_Wrd_t * vSimI, * vSimO; + Vec_WrdReadText( pFileName, &vSimI, &vSimO, nIns, nOuts ); + Vec_WrdDumpBin( Extra_FileNameGenericAppend(pFileName, ".simi"), vSimI, 1 ); + Vec_WrdDumpBin( Extra_FileNameGenericAppend(pFileName, ".simo"), vSimO, 1 ); + Vec_WrdFree( vSimI ); + Vec_WrdFree( vSimO ); +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Gia_ManSimInfoTry( Gia_Man_t * p, Vec_Wrd_t * vSimI, Vec_Wrd_t * vSimO ) +{ + extern Vec_Wrd_t * Gia_ManSimulateWordsOut( Gia_Man_t * p, Vec_Wrd_t * vSimsIn ); + Vec_Wrd_t * vSimsOut = Gia_ManSimulateWordsOut( p, vSimI ); + word * pSim0 = Vec_WrdArray(p->vSims); + int i, Count, nWords = Vec_WrdSize(vSimO) / Gia_ManCoNum(p); + Gia_Obj_t * pObj; + assert( Vec_WrdSize(vSimI) / Gia_ManCiNum(p) == nWords ); + assert( Vec_WrdSize(vSimI) % Gia_ManCiNum(p) == 0 ); + assert( Vec_WrdSize(vSimO) % Gia_ManCoNum(p) == 0 ); + Abc_TtClear( pSim0, nWords ); + Gia_ManForEachCo( p, pObj, i ) + { + word * pSimImpl = Vec_WrdEntryP( vSimsOut, i * nWords ); + word * pSimGold = Vec_WrdEntryP( vSimO, i * nWords ); + Abc_TtOrXor( pSim0, pSimImpl, pSimGold, nWords ); + } + Count = Abc_TtCountOnesVec( pSim0, nWords ); + printf( "Number of failed patterns is %d (out of %d). The first one is %d\n", + Count, 64*nWords, Abc_TtFindFirstBit2(pSim0, nWords) ); + Vec_WrdFreeP( &p->vSims ); + Vec_WrdFreeP( &vSimsOut ); + p->nSimWords = -1; + return Count; +} +void Gia_ManSimInfoTryTest( Gia_Man_t * p, int fSmall ) +{ + abctime clk = Abc_Clock(); + int nIns = fSmall ? 32 : 64; + int nOuts = fSmall ? 10 : 35; + char * pFileNameI = fSmall ? "s.simi" : "l.simi"; + char * pFileNameO = fSmall ? "s.simo" : "l.simo"; + Vec_Wrd_t * vSimI = Vec_WrdReadBin( pFileNameI, 1 ); + Vec_Wrd_t * vSimO = Vec_WrdReadBin( pFileNameO, 1 ); + Gia_ManSimInfoTry( p, vSimI, vSimO ); + Vec_WrdFree( vSimI ); + Vec_WrdFree( vSimO ); + Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Gia_ManSimInfoPassTest( Gia_Man_t * p, int fSmall ) +{ +} + /**Function************************************************************* Synopsis [] diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index f1e09980..15a4857b 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -48456,6 +48456,7 @@ usage: ***********************************************************************/ int Abc_CommandAbc9Test( Abc_Frame_t * pAbc, int argc, char ** argv ) { + extern void Gia_ManSimInfoTryTest( Gia_Man_t * p, int fSmall ); extern void Gia_RsbEnumerateWindows( Gia_Man_t * p, int nInputsMax, int nLevelsMax ); extern int Gia_ManSumTotalOfSupportSizes( Gia_Man_t * p ); int c, fVerbose = 0; @@ -48519,8 +48520,8 @@ int Abc_CommandAbc9Test( Abc_Frame_t * pAbc, int argc, char ** argv ) // return 1; // } // Abc_FrameUpdateGia( pAbc, Abc_Procedure(pAbc->pGia) ); -// Gia_ManTryResub( pAbc->pGia ); - printf( "AIG in \"%s\" has the sum of output support sizes equal to %d.\n", pAbc->pGia->pSpec, Gia_ManSumTotalOfSupportSizes(pAbc->pGia) ); + Gia_ManSimInfoTryTest( pAbc->pGia, fSwitch ); +// printf( "AIG in \"%s\" has the sum of output support sizes equal to %d.\n", pAbc->pGia->pSpec, Gia_ManSumTotalOfSupportSizes(pAbc->pGia) ); return 0; usage: Abc_Print( -2, "usage: &test [-FW num] [-svh]\n" ); diff --git a/src/misc/vec/vecWrd.h b/src/misc/vec/vecWrd.h index 663b7a88..9fa82f2d 100644 --- a/src/misc/vec/vecWrd.h +++ b/src/misc/vec/vecWrd.h @@ -1330,6 +1330,63 @@ static inline Vec_Wrd_t * Vec_WrdReadHex( char * pFileName, int * pnWords, int f return p; } +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline void Vec_WrdDumpBin( char * pFileName, Vec_Wrd_t * p, int fVerbose ) +{ + int RetValue; + FILE * pFile = fopen( pFileName, "wb" ); + if ( pFile == NULL ) + { + printf( "Cannot open file \"%s\" for writing.\n", pFileName ); + return; + } + RetValue = fwrite( Vec_WrdArray(p), 1, 8*Vec_WrdSize(p), pFile ); + fclose( pFile ); + if ( RetValue != 8*Vec_WrdSize(p) ) + printf( "Error reading data from file.\n" ); + if ( fVerbose ) + printf( "Written %d words of simulation data into file \"%s\".\n", Vec_WrdSize(p), pFileName ); +} +static inline Vec_Wrd_t * Vec_WrdReadBin( char * pFileName, int fVerbose ) +{ + Vec_Wrd_t * p = NULL; int nSize, RetValue; + FILE * pFile = fopen( pFileName, "rb" ); + if ( pFile == NULL ) + { + printf( "Cannot open file \"%s\" for reading.\n", pFileName ); + return NULL; + } + fseek( pFile, 0, SEEK_END ); + nSize = ftell( pFile ); + if ( nSize % 8 > 0 ) + { + printf( "Cannot read file with simulation data that is not aligned at 8 bytes (remainder = %d).\n", nSize % 8 ); + fclose( pFile ); + return NULL; + } + else + { + rewind( pFile ); + p = Vec_WrdStart( nSize/8 ); + RetValue = fread( Vec_WrdArray(p), 1, nSize, pFile ); + fclose( pFile ); + if ( RetValue != nSize ) + printf( "Error reading data from file.\n" ); + if ( fVerbose ) + printf( "Read %d words of simulation data from file \"%s\".\n", nSize/8, pFileName ); + return p; + } +} ABC_NAMESPACE_HEADER_END -- cgit v1.2.3