/**Function************************************************************* Synopsis [Expands cubes against the offset given as an AIG.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Abc_ObjExpandCubesTry( Vec_Str_t * vSop, sat_solver * pSat, Vec_Int_t * vVars ) { extern int Bmc_CollapseExpandRound( sat_solver * pSat, sat_solver * pSatOn, Vec_Int_t * vLits, Vec_Int_t * vNums, Vec_Int_t * vTemp, int nBTLimit, int fCanon, int fOnOffSetLit ); char * pCube, * pSop = Vec_StrArray(vSop); int nCubes = Abc_SopGetCubeNum(pSop); int nVars = Abc_SopGetVarNum(pSop); Vec_Int_t * vLits = Vec_IntAlloc( nVars ); Vec_Int_t * vTemp = Vec_IntAlloc( nVars ); assert( nVars == Vec_IntSize(vVars) ); assert( Vec_StrSize(vSop) == nCubes * (nVars + 3) + 1 ); Bmc_SopForEachCube( pSop, nVars, pCube ) { int k, Entry; // collect literals and clean cube Vec_IntFill( vLits, nVars, -1 ); for ( k = 0; k < nVars; k++ ) { if ( pCube[k] == '-' ) continue; Vec_IntWriteEntry( vLits, k, Abc_Var2Lit(Vec_IntEntry(vVars, k), pCube[k] == '0') ); pCube[k] = '-'; } // expand cube Bmc_CollapseExpandRound( pSat, NULL, vLits, NULL, vTemp, 0, 0, -1 ); // insert literals Vec_IntForEachEntry( vLits, Entry, k ) if ( Entry != -1 ) pCube[k] = '1' - Abc_LitIsCompl(Entry); }
/**Function************************************************************* Synopsis [Converts SOP in ABC into SOP representation in Espresso.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ pset_family Abc_SopToEspresso( char * pSop ) { char * pCube; pset_family Cover; pset set; int nCubes, nVars, Value, v; if ( pSop == NULL ) return NULL; nVars = Abc_SopGetVarNum(pSop); nCubes = Abc_SopGetCubeNum(pSop); assert( cube.size == 2 * nVars ); if ( Abc_SopIsConst0(pSop) ) { Cover = sf_new(0, cube.size); return Cover; } if ( Abc_SopIsConst1(pSop) ) { Cover = sf_new(1, cube.size); set = GETSET(Cover, Cover->count++); set_copy( set, cube.fullset ); return Cover; } // create the cover Cover = sf_new(nCubes, cube.size); // fill in the cubes Abc_SopForEachCube( pSop, nVars, pCube ) { set = GETSET(Cover, Cover->count++); set_copy( set, cube.fullset ); Abc_CubeForEachVar( pCube, Value, v ) { if ( Value == '0' ) set_remove(set, 2*v+1); else if ( Value == '1' ) set_remove(set, 2*v); } }
/**Function************************************************************* Synopsis [Computes the results of simulating one node.] Description [Assumes that fanins have pCopy set to the input values.] SideEffects [] SeeAlso [] ***********************************************************************/ int Abc_ObjSopSimulate( Abc_Obj_t * pObj ) { char * pCube, * pSop = (char *)pObj->pData; int nVars, Value, v, ResOr, ResAnd, ResVar; assert( pSop && !Abc_SopIsExorType(pSop) ); // simulate the SOP of the node ResOr = 0; nVars = Abc_SopGetVarNum(pSop); Abc_SopForEachCube( pSop, nVars, pCube ) { ResAnd = 1; Abc_CubeForEachVar( pCube, Value, v ) { if ( Value == '0' ) ResVar = 1 ^ ((int)(ABC_PTRUINT_T)Abc_ObjFanin(pObj, v)->pCopy); else if ( Value == '1' ) ResVar = (int)(ABC_PTRUINT_T)Abc_ObjFanin(pObj, v)->pCopy; else continue; ResAnd &= ResVar; } ResOr |= ResAnd; }
/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Io_ReadBlifNetworkNames( Io_ReadBlif_t * p, Vec_Ptr_t ** pvTokens ) { Vec_Ptr_t * vTokens = *pvTokens; Abc_Ntk_t * pNtk = p->pNtkCur; Abc_Obj_t * pNode; char * pToken, Char, ** ppNames; int nFanins, nNames; // create a new node and add it to the network if ( vTokens->nSize < 2 ) { p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0); sprintf( p->sError, "The .names line has less than two tokens." ); Io_ReadBlifPrintErrorMessage( p ); return 1; } // create the node ppNames = (char **)vTokens->pArray + 1; nNames = vTokens->nSize - 2; pNode = Io_ReadCreateNode( pNtk, ppNames[nNames], ppNames, nNames ); // derive the functionality of the node p->vCubes->nSize = 0; nFanins = vTokens->nSize - 2; if ( nFanins == 0 ) { while ( (vTokens = Io_ReadBlifGetTokens(p)) ) { pToken = (char *)vTokens->pArray[0]; if ( pToken[0] == '.' ) break; // read the cube if ( vTokens->nSize != 1 ) { p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0); sprintf( p->sError, "The number of tokens in the constant cube is wrong." ); Io_ReadBlifPrintErrorMessage( p ); return 1; } // create the cube Char = ((char *)vTokens->pArray[0])[0]; Vec_StrPush( p->vCubes, ' ' ); Vec_StrPush( p->vCubes, Char ); Vec_StrPush( p->vCubes, '\n' ); } } else { while ( (vTokens = Io_ReadBlifGetTokens(p)) ) { pToken = (char *)vTokens->pArray[0]; if ( pToken[0] == '.' ) break; // read the cube if ( vTokens->nSize != 2 ) { p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0); sprintf( p->sError, "The number of tokens in the cube is wrong." ); Io_ReadBlifPrintErrorMessage( p ); return 1; } // create the cube Vec_StrPrintStr( p->vCubes, (char *)vTokens->pArray[0] ); // check the char Char = ((char *)vTokens->pArray[1])[0]; if ( Char != '0' && Char != '1' && Char != 'x' && Char != 'n' ) { p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0); sprintf( p->sError, "The output character in the constant cube is wrong." ); Io_ReadBlifPrintErrorMessage( p ); return 1; } Vec_StrPush( p->vCubes, ' ' ); Vec_StrPush( p->vCubes, Char ); Vec_StrPush( p->vCubes, '\n' ); } } // if there is nothing there if ( p->vCubes->nSize == 0 ) { // create an empty cube Vec_StrPush( p->vCubes, ' ' ); Vec_StrPush( p->vCubes, '0' ); Vec_StrPush( p->vCubes, '\n' ); } Vec_StrPush( p->vCubes, 0 ); // set the pointer to the functionality of the node Abc_ObjSetData( pNode, Abc_SopRegister((Mem_Flex_t *)pNtk->pManFunc, p->vCubes->pArray) ); // check the size if ( Abc_ObjFaninNum(pNode) != Abc_SopGetVarNum((char *)Abc_ObjData(pNode)) ) { p->LineCur = Extra_FileReaderGetLineNumber(p->pReader, 0); sprintf( p->sError, "The number of fanins (%d) of node %s is different from SOP size (%d).", Abc_ObjFaninNum(pNode), Abc_ObjName(Abc_ObjFanout(pNode,0)), Abc_SopGetVarNum((char *)Abc_ObjData(pNode)) ); Io_ReadBlifPrintErrorMessage( p ); return 1; } // return the last array of tokens *pvTokens = vTokens; return 0; }
ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [Reorder fanins of the network.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void Abc_NtkOrderFaninsById( Abc_Ntk_t * pNtk ) { Vec_Int_t * vOrder; Vec_Str_t * vStore; Abc_Obj_t * pNode; char * pSop, * pSopNew; char * pCube, * pCubeNew; int nVars, i, v, * pOrder; assert( Abc_NtkHasSop(pNtk) ); vOrder = Vec_IntAlloc( 100 ); vStore = Vec_StrAlloc( 100 ); Abc_NtkForEachNode( pNtk, pNode, i ) { pSop = (char *)pNode->pData; nVars = Abc_SopGetVarNum(pSop); assert( nVars == Abc_ObjFaninNum(pNode) ); Vec_IntClear( vOrder ); for ( v = 0; v < nVars; v++ ) Vec_IntPush( vOrder, v ); pOrder = Vec_IntArray(vOrder); Vec_IntSelectSortCost( pOrder, nVars, &pNode->vFanins ); // copy the cover Vec_StrGrow( vStore, Abc_SopGetCubeNum(pSop) * (nVars + 3) + 1 ); memcpy( Vec_StrArray(vStore), pSop, Abc_SopGetCubeNum(pSop) * (nVars + 3) + 1 ); pSopNew = pCubeNew = pSop; pSop = Vec_StrArray(vStore); // generate permuted one Abc_SopForEachCube( pSop, nVars, pCube ) { for ( v = 0; v < nVars; v++ ) pCubeNew[v] = '-'; for ( v = 0; v < nVars; v++ ) if ( pCube[pOrder[v]] == '0' ) pCubeNew[v] = '0'; else if ( pCube[pOrder[v]] == '1' ) pCubeNew[v] = '1'; pCubeNew += nVars + 3; } pNode->pData = pSopNew; Vec_IntSort( &pNode->vFanins, 0 ); // Vec_IntPrint( vOrder ); }