void Dar_BalanceUniqify( Aig_Obj_t * pObj, Vec_Ptr_t * vNodes, int fExor ) { Aig_Obj_t * pTemp, * pTempNext; int i, k; // sort the nodes by their literal Vec_PtrSort( vNodes, (int (*)())Dar_ObjCompareLits ); // remove duplicates k = 0; Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pTemp, i ) { if ( i + 1 == Vec_PtrSize(vNodes) ) { Vec_PtrWriteEntry( vNodes, k++, pTemp ); break; } pTempNext = (Aig_Obj_t *)Vec_PtrEntry( vNodes, i+1 ); if ( !fExor && pTemp == Aig_Not(pTempNext) ) // pos_lit & neg_lit = 0 { Vec_PtrClear( vNodes ); return; } if ( pTemp != pTempNext ) // save if different Vec_PtrWriteEntry( vNodes, k++, pTemp ); else if ( fExor ) // in case of XOR, remove identical i++; } Vec_PtrShrink( vNodes, k ); // check that there is no duplicates pTemp = (Aig_Obj_t *)Vec_PtrEntry( vNodes, 0 ); Vec_PtrForEachEntryStart( Aig_Obj_t *, vNodes, pTempNext, i, 1 ) { assert( pTemp != pTempNext ); pTemp = pTempNext; } }
/**Function************************************************************* Synopsis [Builds implication supergate.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Aig_Obj_t * Dar_BalanceBuildSuperTop( Aig_Man_t * p, Vec_Ptr_t * vSuper, Aig_Type_t Type, int fUpdateLevel, int nLutSize ) { Vec_Ptr_t * vSubset; Aig_Obj_t * pObj; int i, nBaseSizeAll, nBaseSize; assert( vSuper->nSize > 1 ); // sort the new nodes by level in the decreasing order Vec_PtrSort( vSuper, (int (*)(void))Aig_NodeCompareLevelsDecrease ); // add one LUT at a time while ( Vec_PtrSize(vSuper) > 1 ) { // isolate the group of nodes with nLutSize inputs nBaseSizeAll = 0; vSubset = Vec_PtrAlloc( nLutSize ); Vec_PtrForEachEntryReverse( Aig_Obj_t *, vSuper, pObj, i ) { nBaseSize = Aig_BaseSize( p, pObj, nLutSize ); if ( nBaseSizeAll + nBaseSize > nLutSize && Vec_PtrSize(vSubset) > 1 ) break; nBaseSizeAll += nBaseSize; Vec_PtrPush( vSubset, pObj ); } // remove them from vSuper Vec_PtrShrink( vSuper, Vec_PtrSize(vSuper) - Vec_PtrSize(vSubset) ); // create the new supergate pObj = Dar_BalanceBuildSuper( p, vSubset, Type, fUpdateLevel ); Vec_PtrFree( vSubset ); // add the new output Dar_BalancePushUniqueOrderByLevel( vSuper, pObj, Type == AIG_OBJ_EXOR ); }
/**Function************************************************************* Synopsis [Removes decomposed nodes from the array of fanins.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Lpk_DecomposeClean( Vec_Ptr_t * vLeaves, int nLeavesOld ) { Lpk_Fun_t * pFunc; int i; Vec_PtrForEachEntryStart( Lpk_Fun_t *, vLeaves, pFunc, i, nLeavesOld ) Lpk_FunFree( pFunc ); Vec_PtrShrink( vLeaves, nLeavesOld ); }
/**Function************************************************************* Synopsis [Computes and adds all single-cube divisors to storage.] Description [This procedure should be called once when the matrix is already contructed before the process of logic extraction begins..] SideEffects [] SeeAlso [] ***********************************************************************/ void Fxu_MatrixComputeSingles( Fxu_Matrix * p, int fUse0, int nSingleMax ) { Fxu_Var * pVar; Vec_Ptr_t * vSingles; int i, k; // set the weight limit p->nWeightLimit = 1 - fUse0; // iterate through columns in the matrix and collect single-cube divisors vSingles = Vec_PtrAlloc( 10000 ); Fxu_MatrixForEachVariable( p, pVar ) Fxu_MatrixComputeSinglesOneCollect( p, pVar, vSingles ); p->nSingleTotal = Vec_PtrSize(vSingles) / 3; // check if divisors should be filtered if ( Vec_PtrSize(vSingles) > nSingleMax ) { int * pWeigtCounts, nDivCount, Weight, i, c;; assert( Vec_PtrSize(vSingles) % 3 == 0 ); // count how many divisors have the given weight pWeigtCounts = ABC_ALLOC( int, 1000 ); memset( pWeigtCounts, 0, sizeof(int) * 1000 ); for ( i = 2; i < Vec_PtrSize(vSingles); i += 3 ) { Weight = (int)(ABC_PTRUINT_T)Vec_PtrEntry(vSingles, i); if ( Weight >= 999 ) pWeigtCounts[999]++; else pWeigtCounts[Weight]++; } // select the bound on the weight (above this bound, singles will be included) nDivCount = 0; for ( c = 999; c >= 0; c-- ) { nDivCount += pWeigtCounts[c]; if ( nDivCount >= nSingleMax ) break; } ABC_FREE( pWeigtCounts ); // collect singles with the given costs k = 0; for ( i = 2; i < Vec_PtrSize(vSingles); i += 3 ) { Weight = (int)(ABC_PTRUINT_T)Vec_PtrEntry(vSingles, i); if ( Weight < c ) continue; Vec_PtrWriteEntry( vSingles, k++, Vec_PtrEntry(vSingles, i-2) ); Vec_PtrWriteEntry( vSingles, k++, Vec_PtrEntry(vSingles, i-1) ); Vec_PtrWriteEntry( vSingles, k++, Vec_PtrEntry(vSingles, i) ); if ( k/3 == nSingleMax ) break; } Vec_PtrShrink( vSingles, k ); // adjust the weight limit p->nWeightLimit = c; }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Io_ReadBlifReorderFormalNames( Vec_Ptr_t * vTokens, Mio_Gate_t * pGate ) { Mio_Pin_t * pGatePin; char * pName, * pNamePin; int i, k, nSize, Length; nSize = Vec_PtrSize(vTokens); if ( nSize - 3 != Mio_GateReadInputs(pGate) ) return 0; // check if the names are in order for ( pGatePin = Mio_GateReadPins(pGate), i = 0; pGatePin; pGatePin = Mio_PinReadNext(pGatePin), i++ ) { pNamePin = Mio_PinReadName(pGatePin); Length = strlen(pNamePin); pName = (char *)Vec_PtrEntry(vTokens, i+2); if ( !strncmp( pNamePin, pName, Length ) && pName[Length] == '=' ) continue; break; } if ( i == nSize - 3 ) return 1; // reorder the pins for ( pGatePin = Mio_GateReadPins(pGate), i = 0; pGatePin; pGatePin = Mio_PinReadNext(pGatePin), i++ ) { pNamePin = Mio_PinReadName(pGatePin); Length = strlen(pNamePin); for ( k = 2; k < nSize; k++ ) { pName = (char *)Vec_PtrEntry(vTokens, k); if ( !strncmp( pNamePin, pName, Length ) && pName[Length] == '=' ) { Vec_PtrPush( vTokens, pName ); break; } } } pNamePin = Mio_GateReadOutName(pGate); Length = strlen(pNamePin); for ( k = 2; k < nSize; k++ ) { pName = (char *)Vec_PtrEntry(vTokens, k); if ( !strncmp( pNamePin, pName, Length ) && pName[Length] == '=' ) { Vec_PtrPush( vTokens, pName ); break; } } if ( Vec_PtrSize(vTokens) - nSize != nSize - 2 ) return 0; Vec_PtrForEachEntryStart( char *, vTokens, pName, k, nSize ) Vec_PtrWriteEntry( vTokens, k - nSize + 2, pName ); Vec_PtrShrink( vTokens, nSize ); return 1; }
/**Function************************************************************* Synopsis [Implements the function.] Description [Returns the node implementing this function.] SideEffects [] SeeAlso [] ***********************************************************************/ Abc_Obj_t * Lpk_Implement( Lpk_Man_t * pMan, Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, int nLeavesOld ) { Abc_Obj_t * pFanin, * pRes; int i; assert( nLeavesOld < Vec_PtrSize(vLeaves) ); // mark implemented nodes Vec_PtrForEachEntryStop( Abc_Obj_t *, vLeaves, pFanin, i, nLeavesOld ) Vec_PtrWriteEntry( vLeaves, i, Abc_ObjNot(pFanin) ); // recursively construct starting from the first entry pRes = Lpk_Implement_rec( pMan, pNtk, vLeaves, (Lpk_Fun_t *)Vec_PtrEntry( vLeaves, nLeavesOld ) ); Vec_PtrShrink( vLeaves, nLeavesOld ); return pRes; }