From cb294bbebc107f670c81bbd164e2c71976f7e68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Wed, 28 Aug 2024 16:17:11 +0200 Subject: [PATCH 1/2] Save cell mapping as new 'M' AIGER extension --- src/aig/gia/giaAiger.c | 12 +++++ src/aig/gia/giaAigerExt.c | 98 +++++++++++++++++++++++++++++++++++++++ src/aig/gia/giaIf.c | 2 +- 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/src/aig/gia/giaAiger.c b/src/aig/gia/giaAiger.c index de94c46022..9c6ca89922 100644 --- a/src/aig/gia/giaAiger.c +++ b/src/aig/gia/giaAiger.c @@ -1464,6 +1464,18 @@ void Gia_AigerWriteS( Gia_Man_t * pInit, char * pFileName, int fWriteSymbols, in Vec_StrFree( vStrExt ); if ( fVerbose ) printf( "Finished writing extension \"m\".\n" ); } + // write cell mapping + if ( Gia_ManHasCellMapping(p) ) + { + extern Vec_Str_t * Gia_AigerWriteCellMappingDoc( Gia_Man_t * p ); + fprintf( pFile, "M" ); + vStrExt = Gia_AigerWriteCellMappingDoc( p ); + Gia_FileWriteBufferSize( pFile, Vec_StrSize(vStrExt) ); + fwrite( Vec_StrArray(vStrExt), 1, Vec_StrSize(vStrExt), pFile ); + Vec_StrFree( vStrExt ); + if ( fVerbose ) printf( "Finished writing extension \"M\".\n" ); + + } // write placement if ( p->pPlacement ) { diff --git a/src/aig/gia/giaAigerExt.c b/src/aig/gia/giaAigerExt.c index 50c3588d94..aa12598e6f 100644 --- a/src/aig/gia/giaAigerExt.c +++ b/src/aig/gia/giaAigerExt.c @@ -19,6 +19,9 @@ ***********************************************************************/ #include "gia.h" +#include "misc/st/st.h" +#include "map/mio/mio.h" +#include "map/mio/mioInt.h" ABC_NAMESPACE_IMPL_START @@ -288,6 +291,101 @@ Vec_Str_t * Gia_AigerWriteMappingDoc( Gia_Man_t * p ) return Vec_StrAllocArray( (char *)pBuffer, 4*nSize ); } +int Gia_AigerWriteCellMappingInstance( Gia_Man_t * p, unsigned char * pBuffer, int nSize2, int i ) +{ + int k, iFan; + if ( !Gia_ObjIsCellInv(p, i) ) { + Gia_AigerWriteInt( pBuffer + nSize2, Gia_ObjCellId(p, i) ); nSize2 += 4; + Gia_AigerWriteInt( pBuffer + nSize2, i ); nSize2 += 4; + Gia_CellForEachFanin( p, i, iFan, k ) + { + Gia_AigerWriteInt( pBuffer + nSize2, iFan ); + nSize2 += 4; + } + } else { + Gia_AigerWriteInt( pBuffer + nSize2, 3 ); nSize2 += 4; + Gia_AigerWriteInt( pBuffer + nSize2, i ); nSize2 += 4; + Gia_AigerWriteInt( pBuffer + nSize2, Abc_LitNot(i) ); nSize2 += 4; + } + + return nSize2; +} + +Vec_Str_t * Gia_AigerWriteCellMappingDoc( Gia_Man_t * p ) +{ + unsigned char * pBuffer; + int i, iFan, nCells = 0, nInstances = 0, nSize = 8, nSize2 = 0; + Mio_Cell2_t * pCells = Mio_CollectRootsNewDefault2( 6, &nCells, 0 ); + assert( pCells ); + + for (int i = 0; i < nCells; i++) + { + Mio_Gate_t *pGate = pCells[i].pMioGate; + Mio_Pin_t *pPin; + nSize += strlen(Mio_GateReadName(pGate)) + 1; + nSize += strlen(Mio_GateReadOutName(pGate)) + 1 + 4; + Mio_GateForEachPin( pGate, pPin ) + nSize += strlen(Mio_PinReadName(pPin)) + 1; + } + + Gia_ManForEachCell( p, i ) + { + assert ( !Gia_ObjIsCellBuf(p, i) ); // not implemented + nInstances++; + if ( Gia_ObjIsCellInv(p, i) ) + nSize += 12; + else + nSize += Gia_ObjCellSize(p, i) * 4 + 8; + } + + pBuffer = ABC_ALLOC( unsigned char, nSize ); + Gia_AigerWriteInt( pBuffer + nSize2, nCells ); nSize2 += 4; + Gia_AigerWriteInt( pBuffer + nSize2, nInstances ); nSize2 += 4; + + for (int i = 0; i < nCells; i++) + { + int nPins = 0; + Mio_Gate_t *pGate = pCells[i].pMioGate; + Mio_Pin_t *pPin; + + strcpy(pBuffer + nSize2, Mio_GateReadName(pGate)); + nSize2 += strlen(Mio_GateReadName(pGate)) + 1; + strcpy(pBuffer + nSize2, Mio_GateReadOutName(pGate)); + nSize2 += strlen(Mio_GateReadOutName(pGate)) + 1; + + Mio_GateForEachPin( pGate, pPin ) + nPins++; + Gia_AigerWriteInt( pBuffer + nSize2, nPins ); nSize2 += 4; + + Mio_GateForEachPin( pGate, pPin ) + { + strcpy(pBuffer + nSize2, Mio_PinReadName(pPin)); + nSize2 += strlen(Mio_PinReadName(pPin)) + 1; + } + } + + Gia_ManForEachCell( p, i ) + { + if ( Gia_ObjIsCellBuf(p, i) ) + continue; + + if ( Gia_ObjIsCellInv(p, i) && !Abc_LitIsCompl(i) ) { + // swap the order so that the inverter is after the driver + // of the inverter's input + nSize2 = Gia_AigerWriteCellMappingInstance(p, pBuffer, nSize2, Abc_LitNot(i) ); + nSize2 = Gia_AigerWriteCellMappingInstance(p, pBuffer, nSize2, i ); + i += 1; + continue; + } + + nSize2 = Gia_AigerWriteCellMappingInstance(p, pBuffer, nSize2, i ); + } + + assert( nSize2 == nSize ); + ABC_FREE( pCells ); + return Vec_StrAllocArray( (char *)pBuffer, nSize ); +} + /**Function************************************************************* Synopsis [Read/write packing information.] diff --git a/src/aig/gia/giaIf.c b/src/aig/gia/giaIf.c index 1ffca1789d..c08a91ecd1 100644 --- a/src/aig/gia/giaIf.c +++ b/src/aig/gia/giaIf.c @@ -2208,7 +2208,7 @@ void Gia_ManMappingVerify( Gia_Man_t * p ) continue; if ( !Gia_ObjIsLut(p, Gia_ObjId(p, pFanin)) ) { - Abc_Print( -1, "Gia_ManMappingVerify: CO driver %d does not have mapping.\n", Gia_ObjId(p, pFanin) ); + Abc_Print( -1, "Gia_ManMappingVerify: Buffer driver %d does not have mapping.\n", Gia_ObjId(p, pFanin) ); Result = 0; continue; } From 786a39a294cdd4fa3610bbc1acef7c3f28c3bdd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Povi=C5=A1er?= Date: Wed, 28 Aug 2024 22:09:34 +0200 Subject: [PATCH 2/2] Make casts explicit --- src/aig/gia/giaAigerExt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/aig/gia/giaAigerExt.c b/src/aig/gia/giaAigerExt.c index aa12598e6f..d149b0a5e9 100644 --- a/src/aig/gia/giaAigerExt.c +++ b/src/aig/gia/giaAigerExt.c @@ -320,7 +320,7 @@ Vec_Str_t * Gia_AigerWriteCellMappingDoc( Gia_Man_t * p ) for (int i = 0; i < nCells; i++) { - Mio_Gate_t *pGate = pCells[i].pMioGate; + Mio_Gate_t *pGate = (Mio_Gate_t *) pCells[i].pMioGate; Mio_Pin_t *pPin; nSize += strlen(Mio_GateReadName(pGate)) + 1; nSize += strlen(Mio_GateReadOutName(pGate)) + 1 + 4; @@ -345,12 +345,12 @@ Vec_Str_t * Gia_AigerWriteCellMappingDoc( Gia_Man_t * p ) for (int i = 0; i < nCells; i++) { int nPins = 0; - Mio_Gate_t *pGate = pCells[i].pMioGate; + Mio_Gate_t *pGate = (Mio_Gate_t *) pCells[i].pMioGate; Mio_Pin_t *pPin; - strcpy(pBuffer + nSize2, Mio_GateReadName(pGate)); + strcpy((char *) pBuffer + nSize2, Mio_GateReadName(pGate)); nSize2 += strlen(Mio_GateReadName(pGate)) + 1; - strcpy(pBuffer + nSize2, Mio_GateReadOutName(pGate)); + strcpy((char *) pBuffer + nSize2, Mio_GateReadOutName(pGate)); nSize2 += strlen(Mio_GateReadOutName(pGate)) + 1; Mio_GateForEachPin( pGate, pPin ) @@ -359,7 +359,7 @@ Vec_Str_t * Gia_AigerWriteCellMappingDoc( Gia_Man_t * p ) Mio_GateForEachPin( pGate, pPin ) { - strcpy(pBuffer + nSize2, Mio_PinReadName(pPin)); + strcpy((char *) pBuffer + nSize2, Mio_PinReadName(pPin)); nSize2 += strlen(Mio_PinReadName(pPin)) + 1; } }