119 #define Bbl_ManForEachObj_int( p, pObj, h ) \
120 for ( h = 0; (h < p->nSize) && (pObj = Bbl_VecObj(p,h)); h += Bbl_ObjSize(pObj) )
121 #define Bbl_ManForEachFnc_int( p, pObj, h ) \
122 for ( h = 0; (h < p->nSize) && (pObj = Bbl_VecFnc(p,h)); h += Bbl_FncSize(pObj) )
123 #define Bbl_ObjForEachFanin_int( pObj, pFanin, i ) \
124 for ( i = 0; (i < (int)pObj->nFanins) && (pFanin = Bbl_ObjFanin(pObj,i)); i++ )
126 #define BBLIF_ALLOC(type, num) ((type *) malloc(sizeof(type) * (num)))
127 #define BBLIF_CALLOC(type, num) ((type *) calloc((num), sizeof(type)))
128 #define BBLIF_FALLOC(type, num) ((type *) memset(malloc(sizeof(type) * (num)), 0xff, sizeof(type) * (num)))
129 #define BBLIF_FREE(obj) ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
130 #define BBLIF_REALLOC(type, obj, num) \
131 ((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (num))) : \
132 ((type *) malloc(sizeof(type) * (num))))
153 if ( nCap > 0 && nCap < 16 )
157 p->pArray = p->nCap?
BBLIF_ALLOC(
int, p->nCap ) : NULL;
177 memset( p->pArray, 0,
sizeof(
int) * nSize );
198 for ( i = 0; i < nSize; i++ )
270 assert( i >= 0 && i < p->nSize );
287 assert( i >= 0 && i < p->nSize );
288 p->pArray[i] = Entry;
304 assert( i >= 0 && i < p->nSize );
305 p->pArray[i] += Addition;
322 return p->pArray[p->nSize-1];
338 if ( p->nCap >= nCapMin )
360 for ( i = 0; i < nSize; i++ )
379 if ( p->nSize >= nSize )
381 if ( nSize > 2 * p->nCap )
383 else if ( nSize > p->nCap )
385 for ( i = p->nSize; i < nSize; i++ )
437 assert( p->nSize >= nSizeNew );
470 if ( p->nSize == p->nCap )
477 p->pArray[p->nSize++] = Entry;
499 if ( nCap > 0 && nCap < 16 )
563 fwrite( &p->
nSize,
sizeof(
int), 1, pFile );
564 fwrite( p->
pArray,
sizeof(
char), p->
nSize, pFile );
581 char * pStr = *ppStr;
583 p->
nSize = *(
int *)pStr;
584 p->
pArray = pStr +
sizeof(int);
585 *ppStr = pStr +
sizeof(int) + p->
nSize *
sizeof(
char);
641 pFile = fopen( pFileName,
"r" );
644 printf(
"Bbl_ManFileSize(): The file is unavailable (absent or open).\n" );
648 nFileSize = ftell( pFile );
671 pFile = fopen( pFileName,
"rb" );
673 RetValue = fread( pContents, nFileSize, 1, pFile );
694 pFile = fopen( pFileName,
"wb" );
753 int h, nFuncs = 0, nNodes = 0, nObjs = 0;
758 printf(
"Total objects = %7d. Total nodes = %7d. Unique functions = %7d.\n", nObjs, nNodes, nFuncs );
812 nLength = pName? 4 * ((
strlen(pName) + 1) / 4 + 1) : 0;
843 for ( i = 0; i < nCubes-1; i++ )
846 for (j = i+1; j < nCubes; j++)
847 if (
memcmp( pCubes[j], pCubes[best_i], nVars ) < 0 )
849 pTemp = pCubes[i]; pCubes[i] = pCubes[best_i]; pCubes[best_i] = pTemp;
866 char ** pCubes, * pSopNew;
867 int c, Length, nCubes;
869 assert( Length % (nVars + 3) == 0 );
870 nCubes = Length / (nVars + 3);
874 memcpy( pSopNew, pSop, Length + 1 );
878 for ( c = 0; c < nCubes; c++ )
879 pCubes[c] = pSop + c * (nVars + 3);
883 for ( c = 0; c < nCubes; c++ )
884 memcpy( pSopNew + c * (nVars + 3), pCubes[c], nVars + 3 );
886 pSopNew[nCubes * (nVars + 3)] = 0;
925 int h, Length =
strlen(pSop) + 1;
926 int nWords = (Length / 4 + (Length % 4 > 0));
927 if ( nVars > 16 ) nVars = 16;
928 if ( nCubes > 16 ) nCubes = 16;
931 for ( h = p->
SopMap[nVars][nCubes]; h; h = pEnt->
iNext )
935 assert( nVars == 16 || nCubes == 16 || pFnc->
nWords == nWords );
958 int iFunc, Length =
strlen(pSop) + 1;
959 int nWords = Length / 4 + (Length % 4 > 0);
968 pFnc->
pWords[nWords-1] = 0;
993 printf(
"Attempting to create a combinational input with %d fanins (should be 0).\n", nFanins );
998 printf(
"Attempting to create a combinational output with %d fanins (should be 1).\n", nFanins );
1030 printf(
"Bbl_ManAddFanin(): Cannot add fanin of the combinational input (Id = %d).\n", ObjId );
1036 printf(
"Bbl_ManAddFanin(): Cannot add fanout of the combinational output (Id = %d).\n", FaninId );
1040 if ( iFanin >= (
int)pObj->
nFanins )
1042 printf(
"Bbl_ManAddFanin(): Trying to add more fanins to object (Id = %d) than declared (%d).\n", ObjId, pObj->
nFanins );
1047 pObj->
pFanins[iFanin] = (
char *)pObj - (
char *)pFanin;
1065 int h, RetValue = 1;
1069 RetValue = 0, printf(
"Bbl_ManCheck(): Node %d does not have function specified.\n", pObj->
Id );
1071 RetValue = 0, printf(
"Bbl_ManCheck(): CI with %d has function specified.\n", pObj->
Id );
1073 RetValue = 0, printf(
"Bbl_ManCheck(): CO with %d has function specified.\n", pObj->
Id );
1075 RetValue = 0, printf(
"Bbl_ManCheck(): Object %d has less fanins (%d) than declared (%d).\n",
1167 return (
Bbl_Obj_t *)(pNext < pEdge ? pNext : NULL);
1202 if ( pFanin == pPrev )
1222 pFile = fopen( pFileName,
"w" );
1223 fprintf( pFile,
"# Test file written by Bbl_ManDumpBlif() in ABC.\n" );
1229 fprintf( pFile,
".inputs %d\n",
Bbl_ObjId(pObj) );
1231 fprintf( pFile,
".outputs %d\n",
Bbl_ObjId(pObj) );
1234 fprintf( pFile,
".names" );
1236 fprintf( pFile,
" %d",
Bbl_ObjId(pFanin) );
1237 fprintf( pFile,
" %d\n",
Bbl_ObjId(pObj) );
1247 fprintf( pFile,
".names" );
1249 fprintf( pFile,
" %d",
Bbl_ObjId(pFanin) );
1250 fprintf( pFile,
" %d\n",
Bbl_ObjId(pObj) );
1251 fprintf( pFile,
"1 1\n" );
1253 fprintf( pFile,
".end\n" );
1275 char * pResult, * pTemp;
1276 int nMints, nOnes, b, v;
1277 assert( nVars >= 0 && nVars <= 16 );
1278 nMints = (1 << nVars);
1281 for ( b = 0; b < nMints; b++ )
1282 nOnes += ((pTruth[b>>5] >> (b&31)) & 1);
1284 if ( nOnes == 0 || nOnes == nMints )
1287 for ( v = 0; v < nVars; v++ )
1290 *pTemp++ = nOnes?
'1' :
'0';
1293 assert( pTemp - pResult == nVars + 4 );
1296 pResult = pTemp =
BBLIF_ALLOC(
char, nOnes * (nVars + 3) + 1 );
1297 for ( b = 0; b < nMints; b++ )
1299 if ( ((pTruth[b>>5] >> (b&31)) & 1) == 0 )
1301 for ( v = 0; v < nVars; v++ )
1302 *pTemp++ = ((b >> v) & 1)?
'1' :
'0';
1308 assert( pTemp - pResult == nOnes * (nVars + 3) + 1 );
1325 unsigned Masks[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 };
1327 nWords = (nVars <= 5 ? 1 : (1 << (nVars - 5)));
1328 for ( i = 0; i < nVars; i++ )
1332 for ( k = 0; k <
nWords; k++ )
1333 pVars[i][k] = Masks[i];
1337 for ( k = 0; k <
nWords; k++ )
1338 if ( k & (1 << (i-5)) )
1339 pVars[i][k] = ~(unsigned)0;
1364 unsigned * pTruth, * pCube, * pVars[16];
1365 int nWords = nVars <= 5 ? 1 : (1 << (nVars - 5));
1366 int v, c, w, nCubes, fCompl = 0;
1369 if (
strlen(pSop) % (nVars + 3) != 0 )
1371 printf(
"Bbl_ManSopToTruth(): SOP is represented incorrectly.\n" );
1376 pVars[0] =
BBLIF_ALLOC(
unsigned, nWords * (nVars+1) );
1377 for ( v = 1; v < nVars; v++ )
1378 pVars[v] = pVars[v-1] + nWords;
1379 pCube = pVars[v-1] +
nWords;
1382 memset( pTruth, 0,
sizeof(
unsigned) * nWords );
1383 nCubes =
strlen(pSop) / (nVars + 3);
1384 for ( c = 0; c < nCubes; c++ )
1386 fCompl = (pSop[nVars+1] ==
'0');
1387 memset( pCube, 0xff,
sizeof(
unsigned) * nWords );
1389 for ( v = 0; v < nVars; v++ )
1390 if ( pSop[v] ==
'1' )
1391 for ( w = 0; w <
nWords; w++ )
1392 pCube[w] &= pVars[v][w];
1393 else if ( pSop[v] ==
'0' )
1394 for ( w = 0; w <
nWords; w++ )
1395 pCube[w] &= ~pVars[v][w];
1397 for ( w = 0; w <
nWords; w++ )
1398 pTruth[w] |= pCube[w];
1400 pSop += (nVars + 3);
1404 for ( w = 0; w <
nWords; w++ )
1405 pTruth[w] = ~pTruth[w];
1428 printf(
"Old SOP:\n%s\n", pSop );
1429 printf(
"New SOP:\n%s\n", pSopNew );
static char * Bbl_ManSop(Bbl_Man_t *p, int h)
#define Bbl_ManForEachFnc_int(p, pObj, h)
static Bbl_Obj_t * Bbl_ObjFanin(Bbl_Obj_t *pObj, int i)
void Bbl_ManAddFanin(Bbl_Man_t *p, int ObjId, int FaninId)
int Bbl_ObjIsInput(Bbl_Obj_t *p)
char * Bbl_ManTruthToSop(unsigned *pTruth, int nVars)
Bbl_Man_t * Bbl_ManStart(char *pName)
MACRO DEFINITIONS ///.
#define BBLIF_ALLOC(type, num)
void Bbl_ManPrintStats(Bbl_Man_t *p)
static void Vec_IntFillExtra(Vec_Int_t *p, int nSize, int Fill)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
char * Bbl_ManName(Bbl_Man_t *p)
Bbl_Obj_t * Bbl_ManObjNext(Bbl_Man_t *p, Bbl_Obj_t *pObj)
static Vec_Int_t * Vec_IntAllocArray(int *pArray, int nSize)
static Bbl_Fnc_t * Bbl_VecFnc(Vec_Str_t *p, int h)
static Bbl_Obj_t * Bbl_ManObj(Bbl_Man_t *p, int Id)
static Bbl_Obj_t * Bbl_VecObj(Vec_Str_t *p, int h)
static int Bbl_FncSize(Bbl_Fnc_t *pFnc)
int Bbl_ObjId(Bbl_Obj_t *p)
int Bbl_ObjIdOriginal(Bbl_Man_t *pMan, Bbl_Obj_t *p)
int Bbl_ObjIsLut(Bbl_Obj_t *p)
static void Vec_IntSetEntry(Vec_Int_t *p, int i, int Entry)
static int Vec_IntGetEntry(Vec_Int_t *p, int i)
struct Bbl_Obj_t_ Bbl_Obj_t
static Vec_Str_t * Vec_StrAlloc(int nCap)
#define Bbl_ObjForEachFanin_int(pObj, pFanin, i)
static Vec_Int_t * Vec_IntStartNatural(int nSize)
static int Bbl_ObjFaninNum(Bbl_Obj_t *pObj)
int Bbl_ObjFaninNumber(Bbl_Obj_t *p)
unsigned * Bbl_ManSopToTruth(char *pSop, int nVars)
int Bbl_ManSopCheckUnique(Bbl_Man_t *p, char *pSop, int nVars, int nCubes, int iFunc)
#define BBLIF_REALLOC(type, obj, num)
Bbl_Obj_t * Bbl_ManObjFirst(Bbl_Man_t *p)
int Bbl_ManCheck(Bbl_Man_t *p)
static void Bbl_ManSopToTruthElem(int nVars, unsigned **pVars)
static void Vec_IntGrow(Vec_Int_t *p, int nCapMin)
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
static Vec_Int_t * Vec_IntStart(int nSize)
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
int Bbl_ManSaveSop(Bbl_Man_t *p, char *pSop, int nVars)
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
static void Vec_StrFree(Vec_Str_t *p)
#define Bbl_ManForEachObj(p, pObj)
Bbl_Obj_t * Bbl_ObjFaninFirst(Bbl_Obj_t *p)
static int Vec_IntEntry(Vec_Int_t *p, int i)
#define ABC_NAMESPACE_IMPL_END
static void Vec_IntFill(Vec_Int_t *p, int nSize, int Fill)
Bbl_Man_t * Bbl_ManReadBinaryBlif(char *pFileName)
void Bbl_ManDumpBlif(Bbl_Man_t *p, char *pFileName)
int Bbl_ManFileSize(char *pFileName)
Bbl_Obj_t * Bbl_ObjFaninNext(Bbl_Obj_t *p, Bbl_Obj_t *pPrev)
static void Vec_IntPush(Vec_Int_t *p, int Entry)
char * Bbl_ManSortSop(char *pSop, int nVars)
#define Bbl_ManForEachObj_int(p, pObj, h)
static int Bbl_ObjIsNode(Bbl_Obj_t *pObj)
#define ABC_NAMESPACE_IMPL_START
static int Vec_StrSize(Vec_Str_t *p)
static int Vec_IntEntryLast(Vec_Int_t *p)
struct Bbl_Fnc_t_ Bbl_Fnc_t
Vec_Str_t * Vec_StrRead(char **ppStr)
static int Vec_IntSize(Vec_Int_t *p)
static int Bbl_ObjSize(Bbl_Obj_t *pObj)
static void Vec_IntShrink(Vec_Int_t *p, int nSizeNew)
static int Bbl_ObjIsCo(Bbl_Obj_t *pObj)
int Bbl_ObjIsMarked(Bbl_Obj_t *p)
void Vec_StrWrite(FILE *pFile, Vec_Str_t *p)
#define Bbl_ObjForEachFanin(pObj, pFanin)
char * Bbl_ManFileRead(char *pFileName)
static void Vec_IntFree(Vec_Int_t *p)
static void Vec_IntClear(Vec_Int_t *p)
void Bbl_ManTestTruth(char *pSop, int nVars)
void Bbl_ManDumpBinaryBlif(Bbl_Man_t *p, char *pFileName)
int Bbl_ManCreateEntry(Bbl_Man_t *p, int iFunc, int iNext)
static int Bbl_ObjIsCi(Bbl_Obj_t *pObj)
char * Vec_StrFetch(Vec_Str_t *p, int nBytes)
static Vec_Str_t * Vec_StrAllocArray(char *pArray, int nSize)
int Bbl_ObjIsOutput(Bbl_Obj_t *p)
void Bbl_ManSortCubes(char **pCubes, int nCubes, int nVars)
void Bbl_ManStop(Bbl_Man_t *p)
int Bbl_ManFncSize(Bbl_Man_t *p)
void Bbl_ManCreateObject(Bbl_Man_t *p, Bbl_Type_t Type, int ObjId, int nFanins, char *pSop)
char * Bbl_ObjSop(Bbl_Man_t *pMan, Bbl_Obj_t *p)
static Bbl_Ent_t * Bbl_VecEnt(Vec_Str_t *p, int h)
int Bbl_ObjFncHandle(Bbl_Obj_t *p)
void Bbl_ObjMark(Bbl_Obj_t *p)