26#define LARGE_LEVEL 1000000
33#define SCL_VARS_MAX 15
34#define SCL_NODE_MAX 1000
59static Abc_ManScl_t * Abc_ManSclStart(
int nLutSize,
int nCutSizeMax,
int nNodesMax );
64static int Abc_NodeDecomposeStep(
Abc_ManScl_t * pManScl );
88 int i, LevelMax, nNodes;
89 int nNodesTried, nNodesDec, nNodesExist, nNodesUsed;
91 assert( Abc_NtkIsSopLogic(pNtk) );
94 printf(
"LUT size (%d) does not belong to the interval: 3 <= LUT size <= %d\n", nLutSize,
SCL_LUT_MAX );
97 if ( nCutSizeMax <= nLutSize || nCutSizeMax >
SCL_VARS_MAX )
99 printf(
"Cut size (%d) does not belong to the interval: LUT size (%d) < Cut size <= %d\n", nCutSizeMax, nLutSize,
SCL_VARS_MAX );
105 nNodesTried = nNodesDec = nNodesExist = nNodesUsed = 0;
114 pManScl = Abc_ManSclStart( nLutSize, nCutSizeMax, 1000 );
115 pManCuts = Abc_NtkStartCutManForScl( pNtk, nLutSize );
121 nNodes = Abc_NtkObjNumMax(pNtk);
127 Extra_ProgressBarUpdate( pProgress, i, NULL );
130 if ( Abc_ObjFaninNum(pObj) != 2 )
136 Abc_NodeLutMap( pManCuts, pObj );
139 if ( Vec_PtrSize(pManScl->
vLeaves) <= nLutSize )
147 pObjTop = Abc_NodeSuperChoiceLut( pManScl, pObj );
148 if ( pObjTop == NULL )
164 Abc_ManSclStop( pManScl );
172 pFanin = Abc_ObjFanin0( pObj );
174 if ( Abc_ObjFaninNum(pFanin) == 1 )
175 pFanin = Abc_ObjFanin0( pFanin );
177 LevelMax = Abc_MaxInt( LevelMax, (
int)pFanin->
Level );
181 printf(
"Try = %d. Dec = %d. Exist = %d. Use = %d. SUPER = %d levels of %d-LUTs.\n",
182 nNodesTried, nNodesDec, nNodesExist, nNodesUsed, LevelMax, nLutSize );
193 printf(
"Abc_NtkSuperChoiceLut: The network check has failed.\n" );
220 for ( pCut = pCut->
pNext; pCut; pCut = pCut->
pNext )
223 for ( i = 0; i < (int)pCut->
nLeaves; i++ )
225 pFanin = Abc_NtkObj( pObj->
pNtk, pCut->
pLeaves[i] );
227 if ( DelayMax < (
int)pFanin->
Level )
228 DelayMax = pFanin->
Level;
230 if ( (
int)pObj->
Level > DelayMax )
231 pObj->
Level = DelayMax;
264 pParams->
nIdsMax = Abc_NtkObjNumMax( pNtk );
266 if ( pParams->
fDrop )
270 if ( Abc_ObjFanoutNum(pObj) > 0 )
286Abc_ManScl_t * Abc_ManSclStart(
int nLutSize,
int nCutSizeMax,
int nNodesMax )
290 assert(
sizeof(
unsigned) == 4 );
293 p->nLutSize = nLutSize;
294 p->nCutSizeMax = nCutSizeMax;
295 p->nNodesMax = nNodesMax;
296 p->nWords = Extra_TruthWordNum(nCutSizeMax);
301 memset(
p->uVars[0], 0, nCutSizeMax *
p->nWords * 4 );
303 for ( k = 0; k <
p->nCutSizeMax; k++ )
304 for ( i = 0; i <
p->nWords * 32; i++ )
306 p->uVars[k][i>>5] |= (1 << (i&31));
347 unsigned * puData0, * puData1, * puData = NULL;
359 puData = (
unsigned *)pObj->
pNext;
360 puData0 = (
unsigned *)Abc_ObjFanin0(pObj)->pNext;
361 puData1 = (
unsigned *)Abc_ObjFanin1(pObj)->pNext;
363 pSop = (
char *)pObj->
pData;
364 if ( pSop[0] ==
'0' && pSop[1] ==
'0' )
365 for ( k = 0; k < pManScl->
nWords; k++ )
366 puData[k] = ~puData0[k] & ~puData1[k];
367 else if ( pSop[0] ==
'0' )
368 for ( k = 0; k < pManScl->
nWords; k++ )
369 puData[k] = ~puData0[k] & puData1[k];
370 else if ( pSop[1] ==
'0' )
371 for ( k = 0; k < pManScl->
nWords; k++ )
372 puData[k] = puData0[k] & ~puData1[k];
374 for ( k = 0; k < pManScl->
nWords; k++ )
375 puData[k] = puData0[k] & puData1[k];
396 assert( Abc_ObjFaninNum(pObj) == 2 );
399 Vec_PtrPush( vVolume, pObj );
419 Vec_PtrClear( vVolume );
442 Vec_PtrPush( vLeaves, pObj );
448 assert( Abc_ObjFaninNum(pObj) == 2 );
451 Vec_PtrPush( vVolume, pObj );
469 nLeaves = Vec_PtrSize(vLeaves);
472 Vec_PtrClear( vVolume );
473 Vec_PtrClear( vLeaves );
475 assert( Vec_PtrSize(vLeaves) == nLeaves );
496 for ( i = nVars - 1; i >= 0; i-- )
497 if ( uPhase & (1 << i) )
498 Vec_PtrRemove( vLeaves, Vec_PtrEntry(vLeaves, i) );
518 Level = Abc_MaxInt( Level, (
int)pFanin->
Level );
536 int i, nVars, uSupport, nSuppVars;
539 assert( Vec_PtrEntryLast(
p->vVolume) == pObj );
543 nVars = Vec_PtrSize(
p->vLeaves);
545 nSuppVars = Extra_WordCountOnes(uSupport);
546 assert( nSuppVars <= nVars );
547 if ( nSuppVars == 0 )
552 if ( nSuppVars == 1 )
555 for ( i = 0; i < nVars; i++ )
556 if ( uSupport & (1 << i) )
559 pFanin = (
Abc_Obj_t *)Vec_PtrEntry(
p->vLeaves, i );
564 if ( nSuppVars != nVars )
567 Extra_TruthCopy(
p->uTruth,
p->uCofs[0], nVars );
572 while ( Vec_PtrSize(
p->vLeaves) >
p->nLutSize )
573 if ( !Abc_NodeDecomposeStep(
p ) )
576 if ( Abc_ObjIsNode(pFanin) && Abc_ObjFanoutNum(pFanin) == 0 )
581 pObjNew = Abc_NtkCreateNode( pObj->
pNtk );
604 pNode1 = (
Abc_Obj_t *)Vec_PtrEntry(s_pLeaves, *pp1);
605 pNode2 = (
Abc_Obj_t *)Vec_PtrEntry(s_pLeaves, *pp2);
627 int i, k, kBest, LevelMin;
628 assert( nLutSize < nVars );
632 for ( i = 0; i < nVars; i++ )
634 pTemp[i] = pLeaves[i];
639 for ( i = 0; i < nLutSize; i++ )
643 for ( k = 0; k < nVars; k++ )
644 if ( pTemp[k] && LevelMin > (
int)pTemp[k]->Level )
646 LevelMin = pTemp[k]->
Level;
671 unsigned * pTruthCof, * pTruthClass, * pTruth, uPhase;
672 int i, k, c, v, w, nVars, nVarsNew, nClasses, nCofs;
674 pNtk = ((
Abc_Obj_t *)Vec_PtrEntry(
p->vLeaves, 0))->pNtk;
676 nVars = Vec_PtrSize(
p->vLeaves);
686 ((
Abc_Obj_t *)Vec_PtrEntry(
p->vLeaves,
p->pBSet[1]))->Level );
688 Extra_TruthCopy(
p->uCofs[1],
p->uTruth, nVars );
690 for ( v = 0; v <
p->nLutSize; v++ )
691 for ( k = 0; k < (1<<v); k++ )
693 Extra_TruthCopy(
p->uCofs[c],
p->uCofs[c/2], nVars );
694 Extra_TruthCopy(
p->uCofs[c+1],
p->uCofs[c/2], nVars );
699 assert( c == (2 <<
p->nLutSize) );
702 nCofs = (1 <<
p->nLutSize);
703 for ( i = 0; i < nCofs; i++ )
705 pTruthCof =
p->uCofs[ nCofs + i ];
706 for ( k = 0; k < nClasses; k++ )
708 pTruthClass =
p->uCofs[ nCofs + pCofClasses[k][0] ];
709 if ( Extra_TruthIsEqual( pTruthCof, pTruthClass, nVars ) )
711 pCofClasses[k][(int)nCofClasses[k]++ ] = i;
718 pCofClasses[nClasses][0] = i;
719 nCofClasses[nClasses] = 1;
721 if ( nClasses > nCofs/2 )
725 nVarsNew = Abc_Base2Log( nClasses );
726 assert( nVarsNew < p->nLutSize );
729 Extra_TruthClear(
p->uTruth, nVars );
730 for ( k = 0; k < nClasses; k++ )
732 pTruthClass =
p->uCofs[ nCofs + pCofClasses[k][0] ];
733 for ( v = 0; v < nVarsNew; v++ )
735 Extra_TruthAnd( pTruthClass, pTruthClass,
p->uVars[
p->pBSet[v]], nVars );
737 Extra_TruthSharp( pTruthClass, pTruthClass,
p->uVars[
p->pBSet[v]], nVars );
738 Extra_TruthOr(
p->uTruth,
p->uTruth, pTruthClass, nVars );
741 pTruth =
p->uCofs[0];
742 for ( v = 0; v < nVarsNew; v++ )
744 Extra_TruthClear( pTruth,
p->nLutSize );
745 for ( k = 0; k < nClasses; k++ )
747 for ( i = 0; i < nCofClasses[k]; i++ )
749 pTruthCof =
p->uCofs[1];
750 Extra_TruthFill( pTruthCof,
p->nLutSize );
751 for ( w = 0; w <
p->nLutSize; w++ )
752 if ( pCofClasses[k][i] & (1 << (
p->nLutSize-1-w)) )
753 Extra_TruthAnd( pTruthCof, pTruthCof,
p->uVars[w],
p->nLutSize );
755 Extra_TruthSharp( pTruthCof, pTruthCof,
p->uVars[w],
p->nLutSize );
756 Extra_TruthOr( pTruth, pTruth, pTruthCof,
p->nLutSize );
759 pObjNew = Abc_NtkCreateNode( pNtk );
760 for ( i = 0; i <
p->nLutSize; i++ )
762 pFanin = (
Abc_Obj_t *)Vec_PtrEntry(
p->vLeaves,
p->pBSet[i] );
768 pNodesNew[v] = pObjNew;
771 for ( v = 0; v < nVarsNew; v++ )
772 Vec_PtrWriteEntry(
p->vLeaves,
p->pBSet[v], pNodesNew[v] );
775 for ( v = nVarsNew; v <
p->nLutSize; v++ )
776 uPhase |= (1 <<
p->pBSet[v]);
780 Extra_TruthShrink(
p->uCofs[0],
p->uTruth, nVars -
p->nLutSize + nVarsNew, nVars, ((1 << nVars) - 1) & ~uPhase );
781 Extra_TruthCopy(
p->uTruth,
p->uCofs[0], nVars );
797static word s__Truths6[6] = {
807 int Index;
word t0, t1, tc;
808 assert( Vec_IntSize(vSupp) <= 6 );
809 if ( (Index = Vec_IntFind(vSupp, Abc_ObjId(pObj))) >= 0 )
810 return s__Truths6[Index];
811 assert( Abc_ObjIsNode(pObj) );
812 if ( Abc_ObjFaninNum(pObj) == 0 )
814 assert( Abc_ObjFaninNum(pObj) == 3 );
818 return (tc & t1) | (~tc & t0);
824 if ( Abc_ObjFaninNum(pObj) == 0 )
826 assert( Abc_ObjFaninNum(pObj) == 3 );
843 Vec_Int_t * vSupp = Vec_WecEntry( vSupps, Abc_ObjId(pObj) );
846 pObj->
pCopy = Abc_NtkCreateNode( pNew );
858 Vec_Int_t * vCover = Vec_IntAlloc( 1 << 16 );
859 Vec_Wec_t * vSupps = Vec_WecStart( Abc_NtkObjNumMax(pNtk) );
860 Abc_Obj_t * pObj, * pFan0, * pFan1, * pFanC;
int i, Count[2] = {0};
862 Vec_IntPush( Vec_WecEntry(vSupps, i), i );
865 Vec_Int_t * vSupp = Vec_WecEntry(vSupps, i);
866 if ( Abc_ObjFaninNum(pObj) == 0 )
868 assert( Abc_ObjFaninNum(pObj) == 3 );
869 pFan0 = Abc_ObjFanin( pObj, 2 );
870 pFan1 = Abc_ObjFanin( pObj, 1 );
871 pFanC = Abc_ObjFanin0( pObj );
872 assert( Abc_ObjIsCi(pFanC) );
876 Vec_IntPush( vSupp, Abc_ObjId(pObj) );
879 Vec_IntTwoMerge2( Vec_WecEntry(vSupps, Abc_ObjId(pFan0)), Vec_WecEntry(vSupps, Abc_ObjId(pFan1)), vSupp );
880 assert( Vec_IntFind(vSupp, Abc_ObjId(pFanC)) == -1 );
881 Vec_IntPushOrder( vSupp, Abc_ObjId(pFanC) );
882 if ( Vec_IntSize(vSupp) <= 6 )
884 Vec_IntClear( vSupp );
888 Vec_IntPush( vSupp, Abc_ObjId(pObj) );
892 Vec_IntPushOrder( vSupp, Abc_ObjId(pFan0) );
893 Vec_IntPushOrder( vSupp, Abc_ObjId(pFan1) );
894 Vec_IntPushOrder( vSupp, Abc_ObjId(pFanC) );
902 printf(
"Node %4d : ", i );
911 Vec_IntPrint( Vec_WecEntry(vSupps, i) );
918 if ( Abc_ObjFaninNum(Abc_ObjFanin0(pObj)) == 0 )
924 Vec_WecFree( vSupps );
925 Vec_IntFree( vCover );
939 printf(
"Abc_NtkSpecialMapping: The network check has failed.\n" );
void Abc_NodeLeavesRemove(Vec_Ptr_t *vLeaves, unsigned uPhase, int nVars)
int Abc_NodeCompareLevelsInc(int *pp1, int *pp2)
void Abc_NodeSuperChoiceCollect2(Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
int Abc_NtkSuperChoiceLut(Abc_Ntk_t *pNtk, int nLutSize, int nCutSizeMax, int fVerbose)
FUNCTION DEFINITIONS ///.
struct Abc_ManScl_t_ Abc_ManScl_t
#define SCL_LUT_MAX
DECLARATIONS ///.
void Abc_NodeSuperChoiceCollect(Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
Abc_Obj_t * Abc_NtkSpecialMap_rec(Abc_Ntk_t *pNew, Abc_Obj_t *pObj, Vec_Wec_t *vSupps, Vec_Int_t *vCover)
void Abc_NodeSuperChoiceCollect2_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vVolume)
void Abc_NodeDecomposeSort(Abc_Obj_t **pLeaves, int nVars, int *pBSet, int nLutSize)
void Abc_NodeSuperChoiceCollect_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
unsigned * Abc_NodeSuperChoiceTruth(Abc_ManScl_t *pManScl)
word Abc_ObjComputeTruth(Abc_Obj_t *pObj, Vec_Int_t *vSupp)
int Abc_NodeGetLevel(Abc_Obj_t *pObj)
Abc_Ntk_t * Abc_NtkSpecialMapping(Abc_Ntk_t *pNtk, int fVerbose)
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_NtkForEachCo(pNtk, pCo, i)
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
ABC_DLL char * Abc_SopCreateFromTruthIsop(Mem_Flex_t *pMan, int nVars, word *pTruth, Vec_Int_t *vCover)
#define Abc_ObjForEachFanin(pObj, pFanin, i)
struct Abc_ManCut_t_ Abc_ManCut_t
ABC_DLL void Abc_NtkManCutStop(Abc_ManCut_t *p)
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL void * Abc_NodeGetCutsRecursive(void *p, Abc_Obj_t *pObj, int fDag, int fTree)
ABC_DLL void Abc_NtkFinalize(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew)
ABC_DLL int Abc_NodeIsConst0(Abc_Obj_t *pNode)
ABC_DLL char * Abc_SopCreateFromTruth(Mem_Flex_t *pMan, int nVars, unsigned *pTruth)
ABC_DLL Vec_Int_t * Abc_NtkFanoutCounts(Abc_Ntk_t *pNtk)
ABC_DLL Vec_Ptr_t * Abc_NodeFindCut(Abc_ManCut_t *p, Abc_Obj_t *pRoot, int fContain)
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeMux(Abc_Ntk_t *pNtk, Abc_Obj_t *pNodeC, Abc_Obj_t *pNode1, Abc_Obj_t *pNode0)
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadVisited(Abc_ManCut_t *p)
ABC_DLL int Abc_SopGetVarNum(char *pSop)
#define Abc_NtkForEachCi(pNtk, pCi, i)
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
ABC_DLL void Abc_NtkCleanMarkAB(Abc_Ntk_t *pNtk)
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadCutSmall(Abc_ManCut_t *p)
#define Abc_NtkForEachObjVec(vIds, pNtk, pObj, i)
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
ABC_DLL Abc_ManCut_t * Abc_NtkManCutStart(int nNodeSizeMax, int nConeSizeMax, int nNodeFanStop, int nConeFanStop)
#define Abc_NtkForEachNode(pNtk, pNode, i)
#define ABC_ALLOC(type, num)
#define ABC_CONST(number)
PARAMETERS ///.
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
struct Cut_ParamsStruct_t_ Cut_Params_t
void Cut_NodeSetTriv(Cut_Man_t *p, int Node)
Cut_Man_t * Cut_ManStart(Cut_Params_t *pParams)
FUNCTION DEFINITIONS ///.
struct Cut_ManStruct_t_ Cut_Man_t
BASIC TYPES ///.
void Cut_ManSetFanoutCounts(Cut_Man_t *p, Vec_Int_t *vFanCounts)
struct Cut_CutStruct_t_ Cut_Cut_t
void Cut_ManStop(Cut_Man_t *p)
unsigned __int64 word
DECLARATIONS ///.
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 ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.