51 char * pSop, * pSopNew;
52 char * pCube, * pCubeNew;
53 int nVars, i, v, * pOrder;
54 assert( Abc_NtkHasSop(pNtk) );
55 vOrder = Vec_IntAlloc( 100 );
56 vStore = Vec_StrAlloc( 100 );
59 pSop = (
char *)pNode->
pData;
61 assert( nVars == Abc_ObjFaninNum(pNode) );
62 Vec_IntClear( vOrder );
63 for ( v = 0; v < nVars; v++ )
64 Vec_IntPush( vOrder, v );
65 pOrder = Vec_IntArray(vOrder);
66 Vec_IntSelectSortCost( pOrder, nVars, &pNode->
vFanins );
70 pSopNew = pCubeNew = pSop;
71 pSop = Vec_StrArray(vStore);
75 for ( v = 0; v < nVars; v++ )
77 for ( v = 0; v < nVars; v++ )
78 if ( pCube[pOrder[v]] ==
'0' )
80 else if ( pCube[pOrder[v]] ==
'1' )
82 pCubeNew += nVars + 3;
84 pNode->
pData = pSopNew;
85 Vec_IntSort( &pNode->
vFanins, 0 );
88 Vec_IntFree( vOrder );
89 Vec_StrFree( vStore );
108 Vec_PtrClear( vCubes );
110 Vec_PtrPush( vCubes, pCube );
112 Vec_StrClear( vStore );
113 for ( v = 0; v < nVars; v++ )
116 Vec_StrPush( vStore, pCube[v] );
117 Vec_StrPush( vStore,
'\0' );
120 nCubes = Vec_PtrSize( vCubes );
121 Vec_PtrClear( vCubes );
122 for ( v = 0; v < nVars; v++ )
123 Vec_PtrPush( vCubes, Vec_StrEntryP(vStore, v*(nCubes+1)) );
125static inline void Vec_StrSelectSortCost(
char ** pArray,
int nSize,
Vec_Int_t * vPerm )
127 int i, j, best_i, * pPerm;
128 Vec_IntClear( vPerm );
129 for ( i = 0; i < nSize; i++ )
130 Vec_IntPush( vPerm, i );
131 pPerm = Vec_IntArray( vPerm );
132 for ( i = 0; i < nSize-1; i++ )
135 for ( j = i+1; j < nSize; j++ )
136 if (
strcmp(pArray[j], pArray[best_i]) < 0 )
138 ABC_SWAP(
char *, pArray[i], pArray[best_i] );
139 ABC_SWAP(
int, pPerm[i], pPerm[best_i] );
150 char * pSop, * pSopNew;
151 char * pCube, * pCubeNew;
152 int nVars, i, v, * pOrder;
153 assert( Abc_NtkHasSop(pNtk) );
154 vOrder = Vec_IntAlloc( 100 );
155 vStore = Vec_StrAlloc( 100 );
156 vCubes = Vec_PtrAlloc( 100 );
157 vCounts = Vec_IntAlloc( 100 );
158 vFanins = Vec_IntAlloc( 100 );
161 pSop = (
char *)pNode->
pData;
163 assert( nVars == Abc_ObjFaninNum(pNode) );
167 Vec_StrSelectSortCost( (
char **)Vec_PtrArray(vCubes), nVars, vOrder );
168 pOrder = Vec_IntArray(vOrder);
172 pSopNew = pCubeNew = pSop;
173 pSop = Vec_StrArray(vStore);
177 for ( v = 0; v < nVars; v++ )
179 for ( v = 0; v < nVars; v++ )
180 if ( pCube[pOrder[v]] ==
'0' )
182 else if ( pCube[pOrder[v]] ==
'1' )
184 pCubeNew += nVars + 3;
186 pNode->
pData = pSopNew;
188 Vec_IntClear( vFanins );
189 for ( v = 0; v < nVars; v++ )
190 Vec_IntPush( vFanins, Abc_ObjFaninId( pNode, pOrder[v] ) );
191 Vec_IntClear( &pNode->
vFanins );
192 Vec_IntAppend( &pNode->
vFanins, vFanins );
194 Vec_IntFree( vFanins );
195 Vec_IntFree( vCounts );
196 Vec_IntFree( vOrder );
197 Vec_StrFree( vStore );
198 Vec_PtrFree( vCubes );
213static inline void Vec_StrSelectSortCost2(
char ** pArray,
int nSize,
Vec_Int_t * vCounts,
Vec_Int_t * vPerm )
215 int i, j, best_i, * pPerm;
216 Vec_IntClear( vPerm );
217 for ( i = 0; i < nSize; i++ )
218 Vec_IntPush( vPerm, i );
219 pPerm = Vec_IntArray( vPerm );
220 for ( i = 0; i < nSize-1; i++ )
223 for ( j = i+1; j < nSize; j++ )
224 if ( Vec_IntEntry(vCounts, pPerm[j]) < Vec_IntEntry(vCounts, pPerm[best_i]) ||
225 (Vec_IntEntry(vCounts, pPerm[j]) == Vec_IntEntry(vCounts, pPerm[best_i]) &&
strcmp(pArray[j], pArray[best_i]) < 0) )
227 ABC_SWAP(
char *, pArray[i], pArray[best_i] );
228 ABC_SWAP(
int, pPerm[i], pPerm[best_i] );
239 char * pSop, * pSopNew;
240 char * pCube, * pCubeNew;
241 int nVars, i, v, * pOrder;
242 assert( Abc_NtkHasSop(pNtk) );
243 vOrder = Vec_IntAlloc( 100 );
244 vStore = Vec_StrAlloc( 100 );
245 vCubes = Vec_PtrAlloc( 100 );
246 vCounts = Vec_IntAlloc( 100 );
247 vFanins = Vec_IntAlloc( 100 );
250 pSop = (
char *)pNode->
pData;
252 assert( nVars == Abc_ObjFaninNum(pNode) );
254 Vec_IntFill( vCounts, nVars, 0 );
256 for ( v = 0; v < nVars; v++ )
257 if ( pCube[v] !=
'-' )
258 Vec_IntAddToEntry( vCounts, v, 1 );
263 Vec_StrSelectSortCost2( (
char **)Vec_PtrArray(vCubes), nVars, vCounts, vOrder );
264 pOrder = Vec_IntArray(vOrder);
276 pSopNew = pCubeNew = pSop;
277 pSop = Vec_StrArray(vStore);
281 for ( v = 0; v < nVars; v++ )
283 for ( v = 0; v < nVars; v++ )
284 if ( pCube[pOrder[v]] ==
'0' )
286 else if ( pCube[pOrder[v]] ==
'1' )
288 pCubeNew += nVars + 3;
290 pNode->
pData = pSopNew;
292 Vec_IntClear( vFanins );
293 for ( v = 0; v < nVars; v++ )
294 Vec_IntPush( vFanins, Abc_ObjFaninId( pNode, pOrder[v] ) );
295 Vec_IntClear( &pNode->
vFanins );
296 Vec_IntAppend( &pNode->
vFanins, vFanins );
298 Vec_IntFree( vFanins );
299 Vec_IntFree( vCounts );
300 Vec_IntFree( vOrder );
301 Vec_StrFree( vStore );
302 Vec_PtrFree( vCubes );
314 char * pSop, * pSopNew;
315 char * pCube, * pCubeNew;
316 int nVars, i, v, iCube, * pOrder;
317 assert( Abc_NtkHasSop(pNtk) );
318 vStore = Vec_StrAlloc( 100 );
319 vOrder = Vec_IntAlloc( 100 );
320 vCounts = Vec_IntAlloc( 100 );
321 vFanins = Vec_IntAlloc( 100 );
322 vCubeNum = Vec_IntAlloc( 100 );
325 pSop = (
char *)pNode->
pData;
327 assert( nVars == Abc_ObjFaninNum(pNode) );
329 Vec_IntFill( vCounts, nVars, 0 );
330 Vec_IntFill( vCubeNum, nVars, 0 );
334 for ( v = 0; v < nVars; v++ )
335 if ( pCube[v] !=
'-' )
337 Vec_IntAddToEntry( vCounts, v, 1 );
338 Vec_IntWriteEntry( vCubeNum, v, iCube );
343 for ( v = 0; v < nVars; v++ )
344 if ( Vec_IntEntry(vCounts, v) == 1 )
345 Vec_IntWriteEntry( vCounts, v, Vec_IntEntry(vCubeNum, v) );
349 Vec_IntClear( vOrder );
350 for ( v = 0; v < nVars; v++ )
351 Vec_IntPush( vOrder, v );
352 pOrder = Vec_IntArray(vOrder);
353 Vec_IntSelectSortCost( pOrder, nVars, vCounts );
357 pSopNew = pCubeNew = pSop;
358 pSop = Vec_StrArray(vStore);
362 for ( v = 0; v < nVars; v++ )
364 for ( v = 0; v < nVars; v++ )
365 if ( pCube[pOrder[v]] ==
'0' )
367 else if ( pCube[pOrder[v]] ==
'1' )
369 pCubeNew += nVars + 3;
371 pNode->
pData = pSopNew;
373 Vec_IntClear( vFanins );
374 for ( v = 0; v < nVars; v++ )
375 Vec_IntPush( vFanins, Abc_ObjFaninId( pNode, pOrder[v] ) );
376 Vec_IntClear( &pNode->
vFanins );
377 Vec_IntAppend( &pNode->
vFanins, vFanins );
379 Vec_IntFree( vCubeNum );
380 Vec_IntFree( vFanins );
381 Vec_IntFree( vCounts );
382 Vec_IntFree( vOrder );
383 Vec_StrFree( vStore );
400 int CutPoint, nVars = Abc_ObjFaninNum(pNode);
415 CutPoint = (nCubes / 2) * (nVars + 3);
416 ((
char *)pNode1->
pData)[CutPoint] = 0;
417 pNode2->
pData = (
char *)pNode2->
pData + CutPoint;
422 int nObjOld = Abc_NtkObjNumMax(pNtk);
424 assert( Abc_NtkHasSop(pNtk) );
430 if ( (Abc_ObjFaninNum(pNode) > nFaninsMax && nCubes > 1) || nCubes > nCubesMax )
448 return strcmp( *pp1, *pp2 );
454 int i, nNum1 = 0, nNum2 = 0;
455 for ( i = 0; pStr1[i]; i++ )
457 nNum1 += (pStr1[i] !=
'-');
458 nNum2 += (pStr2[i] !=
'-');
464 return strcmp( *pp1, *pp2 );
468 char * pCube, * pPivot;
469 char * pSop = (
char *)pNode->
pData;
470 int i, nVars = Abc_ObjFaninNum(pNode);
471 Vec_PtrClear( vCubes );
474 assert( pCube[nVars] ==
' ' );
476 Vec_PtrPush( vCubes, pCube );
482 Vec_StrGrow( vStore, Vec_PtrSize(vCubes) * (nVars + 3) );
483 pPivot = Vec_StrArray( vStore );
486 assert( pCube[nVars] == 0 );
488 memcpy( pPivot, pCube, (
size_t)(nVars + 3) );
491 memcpy( pSop, Vec_StrArray(vStore), (
size_t)(Vec_PtrSize(vCubes) * (nVars + 3)) );
499 assert( Abc_NtkHasSop(pNtk) );
500 vCubes = Vec_PtrAlloc( 1000 );
501 vStore = Vec_StrAlloc( 1000 );
504 Vec_StrFree( vStore );
505 Vec_PtrFree( vCubes );
540static inline int Abc_CubeContain(
char * pCube1,
char * pCube2,
int nVars )
542 int v, fCont12 = 1, fCont21 = 1;
543 for ( v = 0; v < nVars; v++ )
545 if ( pCube1[v] == pCube2[v] )
547 if ( pCube1[v] ==
'-' )
549 else if ( pCube2[v] ==
'-' )
553 if ( !fCont12 && !fCont21 )
556 assert( fCont21 || fCont12 );
557 return (fCont21 << 1) | fCont12;
561 char * pSop = (
char *)pNode->
pData;
562 char * pCube, * pCube2, * pSopNew;
563 int nVars = Abc_ObjFaninNum(pNode);
564 int Status, nCount = 0;
567 if ( pCube[0] ==
'z' || pCube2[0] ==
'z' )
569 Status = Abc_CubeContain( pCube, pCube2, nVars );
570 nCount += (int)(Status > 0);
573 else if ( Status & 2 )
579 pSopNew = (
char *)pNode->
pData;
582 if ( pCube[0] ==
'z' )
584 memcpy( pSopNew, pCube, (
size_t)(nVars + 3) );
585 pSopNew += nVars + 3;
592 char * pSop = (
char *)pNode->
pData;
593 char * pCube, * pCube2;
594 int i, nVars = Abc_ObjFaninNum(pNode);
598 int Counter = 0, iDiff = -1;
599 for ( i = 0; i < nVars; i++ )
600 if ( pCube[i] != pCube2[i] )
601 Counter++, iDiff = i;
602 if ( Counter == 1 && ((pCube[iDiff] ==
'0' && pCube2[iDiff] ==
'1') || (pCube[iDiff] ==
'1' && pCube2[iDiff] ==
'0')) )
603 pCube[iDiff] = pCube2[iDiff] =
'-';
608 char * pSop = (
char *)pNode->
pData;
609 char * pCube, * pCube2;
610 int i, nVars = Abc_ObjFaninNum(pNode);
615 if ( pCube == pCube2 )
617 for ( i = 0; i < nVars; i++ )
618 if ( pCube[i] != pCube2[i] )
626 for ( i = 0; fChanges; i++ )
638 assert( Abc_NtkHasSop(pNtk) );
642 Abc_Print( 0,
"%d nodes were made dist1-cube-free and/or single-cube-containment-free.\n", Counter );
void Abc_NtkSopTranspose(char *pSop, int nVars, Vec_Ptr_t *vCubes, Vec_Str_t *vStore)
void Abc_NtkOrderFaninsByLitCount(Abc_Ntk_t *pNtk)
int Abc_NtkMakeLegit(Abc_Ntk_t *pNtk)
void Abc_NodeSplitLarge(Abc_Obj_t *pNode)
int Abc_NodeMakeSCCFree(Abc_Obj_t *pNode)
void Abc_NodeCheckDist1Free(Abc_Obj_t *pNode)
int Abc_NodeCompareCubes1(char **pp1, char **pp2)
void Abc_NtkOrderFaninsByLitCountAndCubeCount(Abc_Ntk_t *pNtk)
ABC_NAMESPACE_IMPL_START void Abc_NtkOrderFaninsById(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
void Abc_NodeMakeDist1Free(Abc_Obj_t *pNode)
int Abc_NodeCompareCubes2(char **pp1, char **pp2)
void Abc_NodeSortCubes(Abc_Obj_t *pNode, Vec_Ptr_t *vCubes, Vec_Str_t *vStore, int fWeight)
void Abc_NtkSortCubes(Abc_Ntk_t *pNtk, int fWeight)
int Abc_NodeMakeLegit(Abc_Obj_t *pNode)
void Abc_NtkOrderFaninsBySortingColumns(Abc_Ntk_t *pNtk)
void Abc_NtkSplitLarge(Abc_Ntk_t *pNtk, int nFaninsMax, int nCubesMax)
void Abc_NtkSortSops(Abc_Ntk_t *pNtk)
struct Abc_Obj_t_ Abc_Obj_t
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
ABC_DLL Abc_Obj_t * Abc_NtkDupObj(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, int fCopyName)
#define Abc_ObjForEachFanin(pObj, pFanin, i)
ABC_DLL char * Abc_SopCreateOr(Mem_Flex_t *pMan, int nVars, int *pfCompl)
#define Abc_SopForEachCubePair(pSop, nFanins, pCube, pCube2)
struct Abc_Ntk_t_ Abc_Ntk_t
#define Abc_SopForEachCube(pSop, nFanins, pCube)
ABC_DLL int Abc_SopGetVarNum(char *pSop)
ABC_DLL void Abc_ObjRemoveFanins(Abc_Obj_t *pObj)
ABC_DLL int Abc_SopGetCubeNum(char *pSop)
#define Abc_NtkForEachNode(pNtk, pNode, i)
#define ABC_SWAP(Type, a, b)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Vec_Str_t_ Vec_Str_t
struct Mem_Flex_t_ Mem_Flex_t
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.