From d9a08eb44b99c65b30e4516673f915bdc9cb9279 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Wed, 15 May 2024 21:41:29 -0700 Subject: [PATCH] New command &window to extract windows from an AIG. --- src/aig/gia/giaDup.c | 78 +++++++++++++++++++++++++++++++++++++++++++- src/base/abci/abc.c | 67 +++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 1 deletion(-) diff --git a/src/aig/gia/giaDup.c b/src/aig/gia/giaDup.c index b0db86dff..35bc54394 100644 --- a/src/aig/gia/giaDup.c +++ b/src/aig/gia/giaDup.c @@ -5873,7 +5873,7 @@ Gia_Man_t * Gia_ManDupOdc( Gia_Man_t * p, int iObj, int fVerbose ) Gia_ManForEachCo( p, pObj, i ) if ( Gia_ObjIsTravIdCurrent(p, pObj) ) iRes = Gia_ManHashOr( pNew, iRes, Gia_ManHashXor(pNew, pObj->Value, Gia_ObjFanin0Copy(pObj)) ); - Gia_ManAppendCo( pNew, iRes ); + Gia_ManAppendCo( pNew, Abc_LitNot(iRes) ); Vec_IntFree( vRoots ); Vec_IntFree( vNodes ); Vec_IntFree( vSupp ); @@ -5882,6 +5882,82 @@ Gia_Man_t * Gia_ManDupOdc( Gia_Man_t * p, int iObj, int fVerbose ) return pNew; } +/**Function************************************************************* + + Synopsis [Mark nodes supported by the cut.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Int_t * Gia_ManMarkSupported( Gia_Man_t * p, Vec_Int_t * vObjs ) +{ + Gia_Obj_t * pObj; int i; + Vec_Int_t * vInner = Vec_IntAlloc( 100 ); + Gia_ManIncrementTravId(p); + Gia_ManForEachObjVec( vObjs, p, pObj, i ) + Gia_ObjSetTravIdCurrent(p, pObj); + Vec_IntAppend( vInner, vObjs ); + Gia_ManForEachAnd( p, pObj, i ) { + if ( Gia_ObjIsTravIdCurrent(p, pObj) ) + continue; + if ( !Gia_ObjIsTravIdCurrent(p, Gia_ObjFanin0(pObj)) || !Gia_ObjIsTravIdCurrent(p, Gia_ObjFanin1(pObj)) ) + continue; + Gia_ObjSetTravIdCurrent(p, pObj); + Vec_IntPush( vInner, Gia_ObjId(p, pObj) ); + } + return vInner; +} +Vec_Int_t * Gia_ManMarkPointed( Gia_Man_t * p, Vec_Int_t * vCut, Vec_Int_t * vInner ) +{ + Gia_Obj_t * pObj; int i; + Vec_Int_t * vOuts = Vec_IntAlloc( 100 ); + Gia_ManForEachObjVec( vCut, p, pObj, i ) + Gia_ObjSetTravIdPrevious(p, pObj); + Gia_ManForEachAnd( p, pObj, i ) { + if ( Gia_ObjIsTravIdCurrent(p, pObj) ) + continue; + if ( Gia_ObjIsTravIdCurrent(p, Gia_ObjFanin0(pObj)) ) { + Gia_ObjSetTravIdPrevious(p, Gia_ObjFanin0(pObj)); + Vec_IntPush( vOuts, Gia_ObjFaninId0p(p, pObj) ); + } + if ( Gia_ObjIsTravIdCurrent(p, Gia_ObjFanin1(pObj)) ) { + Gia_ObjSetTravIdPrevious(p, Gia_ObjFanin1(pObj)); + Vec_IntPush( vOuts, Gia_ObjFaninId1p(p, pObj) ); + } + } + Gia_ManForEachCo( p, pObj, i ) { + if ( Gia_ObjIsTravIdCurrent(p, Gia_ObjFanin0(pObj)) ) { + Gia_ObjSetTravIdPrevious(p, Gia_ObjFanin0(pObj)); + Vec_IntPush( vOuts, Gia_ObjFaninId0p(p, pObj) ); + } + } + Vec_IntSort( vOuts, 0 ); + return vOuts; +} +Gia_Man_t * Gia_ManDupWindow( Gia_Man_t * p, Vec_Int_t * vCut ) +{ + Gia_Obj_t * pObj; int i; + Vec_Int_t * vInner = Gia_ManMarkSupported( p, vCut ); + Vec_Int_t * vOuts = Gia_ManMarkPointed( p, vCut, vInner ); + Gia_Man_t * pNew = Gia_ManStart( 100 ); + pNew->pName = Abc_UtilStrsav( "win" ); + Gia_ManConst0(p)->Value = 0; + Gia_ManForEachObjVec( vCut, p, pObj, i ) + pObj->Value = Gia_ManAppendCi( pNew ); + Gia_ManForEachObjVecStart( vInner, p, pObj, i, Vec_IntSize(vCut) ) + pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); + Gia_ManForEachObjVec( vOuts, p, pObj, i ) + pObj->Value = Gia_ManAppendCo( pNew, pObj->Value ); + printf( "Derived window with %d inputs, %d internal nodes, and %d outputs: ", Vec_IntSize(vCut), Vec_IntSize(vInner), Vec_IntSize(vOuts) ); + Vec_IntFree( vInner ); + Vec_IntFree( vOuts ); + return pNew; +} + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 49c88ef5e..353609973 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -608,6 +608,7 @@ static int Abc_CommandAbc9StrEco ( Abc_Frame_t * pAbc, int argc, cha static int Abc_CommandAbc9GenCex ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandAbc9Odc ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandAbc9GenRel ( Abc_Frame_t * pAbc, int argc, char ** argv ); +static int Abc_CommandAbc9Window ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandAbc9Test ( Abc_Frame_t * pAbc, int argc, char ** argv ); @@ -1398,6 +1399,7 @@ void Abc_Init( Abc_Frame_t * pAbc ) Cmd_CommandAdd( pAbc, "ABC9", "&gencex", Abc_CommandAbc9GenCex, 0 ); Cmd_CommandAdd( pAbc, "ABC9", "&odc", Abc_CommandAbc9Odc, 0 ); Cmd_CommandAdd( pAbc, "ABC9", "&genrel", Abc_CommandAbc9GenRel, 0 ); + Cmd_CommandAdd( pAbc, "ABC9", "&window", Abc_CommandAbc9Window, 0 ); Cmd_CommandAdd( pAbc, "ABC9", "&test", Abc_CommandAbc9Test, 0 ); { @@ -53111,6 +53113,71 @@ usage: Abc_Print( -2, "\t : the output file name (extended PLA format)\n"); return 1; } + + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Abc_CommandAbc9Window( Abc_Frame_t * pAbc, int argc, char ** argv ) +{ + extern Gia_Man_t * Gia_ManDupWindow( Gia_Man_t * p, Vec_Int_t * vCut ); + Gia_Man_t * pNew = NULL; + Vec_Int_t * vCut = NULL; + int c, fVerbose = 0; + Extra_UtilGetoptReset(); + while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) + { + switch ( c ) + { + case 'v': + fVerbose ^= 1; + break; + case 'h': + goto usage; + default: + goto usage; + } + } + if ( pAbc->pGia == NULL ) + { + Abc_Print( -1, "Abc_CommandAbc9Window(): There is no AIG.\n" ); + return 0; + } + if ( argc == globalUtilOptind ) + { + Abc_Print( -1, "Abc_CommandAbc9Window(): Node IDs should be given on the command line.\n" ); + return 0; + } + if ( argc-globalUtilOptind < 1 ) + { + Abc_Print( -1, "Abc_CommandAbc9Window(): The window should have at least one support variable.\n" ); + return 0; + } + vCut = Vec_IntAlloc( 100 ); + for ( c = globalUtilOptind; c < argc; c++ ) + Vec_IntPush( vCut, atoi(argv[c]) ); + pNew = Gia_ManDupWindow( pAbc->pGia, vCut ); + Abc_FrameUpdateGia( pAbc, pNew ); + Vec_IntFree( vCut ); + return 0; + +usage: + Abc_Print( -2, "usage: &window [-vh] ... \n" ); + Abc_Print( -2, "\t generates window supported by the given nodes\n" ); + Abc_Print( -2, "\t-v : toggles printing verbose information [default = %d]\n", fVerbose ? "yes": "no" ); + Abc_Print( -2, "\t-h : print the command usage\n"); + Abc_Print( -2, "\t : the list of input nodes\n"); + return 1; +} + /**Function************************************************************* Synopsis []