67static inline Sfm_Fun_t * Sfm_LibFun(
Sfm_Lib_t *
p,
int i ) {
return i == -1 ? NULL :
p->pObjs + i; }
70#define Sfm_LibForEachSuper( p, pObj, Func ) \
71 for ( pObj = Sfm_LibFun(p, Vec_IntEntry(&p->vLists, Func)); pObj; pObj = Sfm_LibFun(p, pObj->Next) )
74static word s_Truth8[8][4] = {
106 vCnf = Vec_StrAlloc( 100 );
107 vCover = Vec_IntAlloc( 100 );
110 nCubes =
Sfm_TruthToCnf( uTruth, NULL, Vec_IntEntry(vGateSizes, i), vCover, vCnf );
111 vCnfBase = (
Vec_Str_t *)Vec_WecEntry( vGateCnfs, i );
112 Vec_StrGrow( vCnfBase, Vec_StrSize(vCnf) );
113 memcpy( Vec_StrArray(vCnfBase), Vec_StrArray(vCnf), (
size_t)Vec_StrSize(vCnf) );
114 vCnfBase->
nSize = Vec_StrSize(vCnf);
116 Vec_IntFree( vCover );
135 Vec_IntGrow( vGateSizes, nGates );
136 Vec_WrdGrow( vGateFuncs, nGates );
137 Vec_WecInit( vGateCnfs, nGates );
138 Vec_PtrGrow( vGateHands, nGates );
144 Vec_PtrPush( vGateHands, pGate );
163 word uTruthGate = Vec_WrdEntry( vFuncs, iGate );
164 word uTruthFlip = Abc_Tt6Flip( uTruthGate, iFanin );
165 word uTruth, uTruthSwap;
int i;
166 assert( iFanin >= 0 && iFanin < nFanins );
167 if ( piFaninNew ) *piFaninNew = iFanin;
169 if ( uTruth == uTruthFlip )
173 if ( piFaninNew ) *piFaninNew = iFanin-1;
174 uTruthSwap = Abc_Tt6SwapAdjacent( uTruthFlip, iFanin-1 );
176 if ( uTruth == uTruthSwap )
179 if ( iFanin+1 < nFanins )
181 if ( piFaninNew ) *piFaninNew = iFanin+1;
182 uTruthSwap = Abc_Tt6SwapAdjacent( uTruthFlip, iFanin );
184 if ( uTruth == uTruthSwap )
188 if ( piFaninNew ) *piFaninNew = -1;
208 p->vTtMem = Vec_MemAllocForTT( nVars, 0 );
209 Vec_IntGrow( &
p->vLists, (1 << 16) );
210 Vec_IntGrow( &
p->vCounts, (1 << 16) );
211 Vec_IntGrow( &
p->vHits, (1 << 16) );
212 Vec_IntFill( &
p->vLists, 2, -1 );
213 Vec_IntFill( &
p->vCounts, 2, -1 );
214 Vec_IntFill( &
p->vHits, 2, -1 );
215 p->nObjsAlloc = (1 << 16);
218 if ( fDelay ) Vec_IntGrow( &
p->vProfs, (1 << 16) );
219 if ( fDelay ) Vec_IntGrow( &
p->vStore, (1 << 18) );
220 Vec_IntGrow( &
p->vTemp, 16 );
222 p->nWords = Abc_TtWordNum( nVars );
223 p->fVerbose = fVerbose;
228 Vec_MemHashFree(
p->vTtMem );
229 Vec_MemFree(
p->vTtMem );
230 Vec_IntErase( &
p->vLists );
231 Vec_IntErase( &
p->vCounts );
232 Vec_IntErase( &
p->vHits );
233 Vec_IntErase( &
p->vProfs );
234 Vec_IntErase( &
p->vStore );
235 Vec_IntErase( &
p->vTemp );
257 for ( i = 0, k = pCellBot->
nFanins; i < (
int)pCellTop->
nFanins; i++ )
259 uFanins[i] = uTruthBot;
261 uFanins[i] = s_Truths6[k++];
263 uTruthBot = Exp_Truth6( pCellTop->
nFanins, pCellTop->
vExpr, uFanins );
269 Exp_Truth8( pCellBot->
nFanins, pCellBot->
vExpr, NULL, uTruthBot );
271 for ( i = 0, k = pCellBot->
nFanins; i < (
int)pCellTop->
nFanins; i++ )
273 puFanins[i] = uTruthBot;
275 puFanins[i] = s_Truth8[k++];
277 Exp_Truth8( pCellTop->
nFanins, pCellTop->
vExpr, puFanins, pRes );
306 int i, DelayAdd = pCellTop ? 1 : 0;
307 for ( i = 0; i < nFanins; i++ )
308 if ( Perm[i] < (
int)pCellBot->
nFanins )
309 pProf[i] = 1 + DelayAdd;
310 else if ( Perm[i] < (
int)pCellBot->
nFanins + InTop )
315static inline int Sfm_LibNewIsContained(
Sfm_Fun_t * pObj,
int * pProf,
int Area,
int * pProfNew,
int nFanins )
318 if ( Area < pObj->Area )
320 for ( k = 0; k < nFanins; k++ )
321 if ( pProfNew[k] < pProf[k] )
325static inline int Sfm_LibNewContains(
Sfm_Fun_t * pObj,
int * pProf,
int Area,
int * pProfNew,
int nFanins )
328 if ( Area > pObj->
Area )
330 for ( k = 0; k < nFanins; k++ )
331 if ( pProfNew[k] > pProf[k] )
339 int Area = (int)pCellBot->
AreaW + (pCellTop ? (
int)pCellTop->
AreaW : 0);
340 int i, k, Id, Prev, Offset, * pProf, iFunc = Vec_MemHashInsert(
p->vTtMem, pTruth );
341 if ( iFunc == Vec_IntSize(&
p->vLists) )
343 Vec_IntPush( &
p->vLists, -1 );
344 Vec_IntPush( &
p->vCounts, 0 );
345 Vec_IntPush( &
p->vHits, 0 );
347 assert( pCellBot != NULL );
351 assert( Vec_IntSize(&
p->vProfs) ==
p->nObjs );
354 Vec_IntClear( &
p->vTemp );
357 Vec_IntPush( &
p->vTemp, Sfm_LibFunId(
p, pObj) );
358 Offset = Vec_IntEntry( &
p->vProfs, Sfm_LibFunId(
p, pObj) );
359 pProf = Vec_IntEntryP( &
p->vStore, Offset );
360 if ( Sfm_LibNewIsContained(pObj, pProf, Area, Profile, nFanins) )
370 Offset = Vec_IntEntry( &
p->vProfs, Id );
371 pProf = Vec_IntEntryP( &
p->vStore, Offset );
372 if ( !Sfm_LibNewContains(Sfm_LibFun(
p, Id), pProf, Area, Profile, nFanins) )
373 Vec_IntWriteEntry( &
p->vTemp, k++, Id );
380 Vec_IntWriteEntry( &
p->vLists, iFunc, -1 );
383 Vec_IntShrink( &
p->vTemp, k );
384 Prev = Vec_IntEntry(&
p->vTemp, 0);
385 Vec_IntWriteEntry( &
p->vLists, iFunc, Prev );
388 Sfm_LibFun(
p, Prev)->Next = Id;
391 Sfm_LibFun(
p, Prev)->Next = -1;
399 if ( Area >= pObj->
Area )
403 for ( k = 0; k < nFanins; k++ )
404 InvPerm[Perm[k]] = k;
408 Vec_IntPush( &
p->vProfs, Vec_IntSize(&
p->vStore) );
409 for ( k = 0; k < nFanins; k++ )
410 Vec_IntPush( &
p->vStore, Profile[k] );
413 if (
p->nObjs ==
p->nObjsAlloc )
415 int nObjsAlloc = 2 *
p->nObjsAlloc;
418 p->nObjsAlloc = nObjsAlloc;
420 pObj =
p->pObjs +
p->nObjs;
422 pObj->
Next = Vec_IntEntry(&
p->vLists, iFunc);
423 Vec_IntWriteEntry( &
p->vLists, iFunc,
p->nObjs++ );
424 Vec_IntAddToEntry( &
p->vCounts, iFunc, 1 );
427 pObj->
pFansB[0] = (char)pCellBot->
Id;
428 for ( k = 0; k < (int)pCellBot->
nFanins; k++ )
429 pObj->
pFansB[k+1] = InvPerm[k];
430 if ( pCellTop == NULL )
433 pObj->
pFansT[0] = (char)pCellTop->
Id;
434 for ( i = 0; i < (int)pCellTop->
nFanins; i++ )
435 pObj->
pFansT[i+1] = (
char)(i == InTop ? 16 : InvPerm[k++]);
445 word tTemp1[4], tCur[4];
450 pLimit =
p->pCells +
p->nCells;
452 for ( pCell1 =
p->pCells + 4; pCell1 < pLimit; pCell1++ )
456 if ( Abc_Tt6IsAndType(uTruth, pCell1->
nFanins) || Abc_Tt6IsOrType(uTruth, pCell1->
nFanins) )
460 else if ( fLibVerbose )
461 printf(
"Skipping gate \"%s\" with non-DSD function %s\n", pCell1->
pName, pRes );
464 for ( i = 2; i <= nVars; i++ )
466 for ( i = 2; i <= nVars; i++ )
469 for ( pCell1 =
p->pCells + 4; pCell1 < pLimit; pCell1++ )
472 assert( nFanins >= 2 && nFanins <= nVars );
473 for ( i = 0; i < nFanins; i++ )
476 tCur[0] = tTemp1[0] = pCell1->
uTruth;
478 tTemp1[1] = tTemp1[2] = tTemp1[3] = tCur[1] = tCur[2] = tCur[3] = tCur[0];
479 for ( n = 0; n < nPerms[nFanins]; n++ )
483 Abc_TtSwapAdjacent( tCur,
p->nWords, pPerm[nFanins][n] );
484 Perm1 = Perm + pPerm[nFanins][n];
488 assert( Abc_TtEqual(tTemp1, tCur,
p->nWords) );
492 for ( pCell1 =
p->pCells + 4; pCell1 < pLimit; pCell1++ )
493 if ( pCell1->
Type > 0 )
494 for ( pCell2 =
p->pCells + 4; pCell2 < pLimit; pCell2++ )
495 if ( pCell2->
Type > 0 )
497 for ( f = 0; f < (int)pCell2->
nFanins; f++ )
500 assert( nFanins >= 2 && nFanins <= nVars );
501 for ( i = 0; i < nFanins; i++ )
507 Abc_TtCopy( tTemp1, tCur,
p->nWords, 0 );
511 for ( n = 0; n < nPerms[nFanins]; n++ )
517 Abc_TtSwapAdjacent( tCur,
p->nWords, pPerm[nFanins][n] );
518 Perm1 = Perm + pPerm[nFanins][n];
522 assert( Abc_TtEqual(tTemp1, tCur,
p->nWords) );
525 for ( i = 2; i <= nVars; i++ )
529 printf(
"Library processing: Var = %d. Cell = %d. Fun = %d. Obj = %d. Ave = %.2f. Skip = %d. Rem = %d. ",
530 nVars,
p->nCells, Vec_MemEntryNum(
p->vTtMem)-2,
531 p->nObjs-
p->nObjRemoved, 1.0*(
p->nObjs-
p->nObjRemoved)/(Vec_MemEntryNum(
p->vTtMem)-2),
532 p->nObjSkipped,
p->nObjRemoved );
533 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
540 printf(
" %-20s(", pCell->
pName );
541 for ( k = 0; k < (int)pCell->
nFanins; k++ )
542 if ( pFanins[k] == (
char)16 )
545 printf(
" %c",
'a' + pFanins[k] );
552 int i, nFanins = pCellB->
nFanins + (pCellT ==
p->pCells ? 0 : pCellT->
nFanins - 1);
553 printf(
"F = %d A =%6.2f ", nFanins, Scl_Int2Flt(pObj->
Area) );
554 if ( pCellT ==
p->pCells )
561 int Offset = Vec_IntEntry( &
p->vProfs, Sfm_LibFunId(
p, pObj) );
562 int * pProf = Vec_IntEntryP( &
p->vStore, Offset );
563 for ( i = 0; i < nFanins; i++ )
564 printf(
"%6.2f ", Scl_Int2Flt(pProf[i]) );
572 if ( i < 2 || Vec_IntEntry(&
p->vHits, i) == 0 )
574 nFanins = Abc_TtSupportSize(pTruth,
p->nVars);
575 printf(
"%8d : ", i );
576 printf(
"Num =%5d ", Vec_IntEntry(&
p->vCounts, i) );
577 printf(
"Hit =%4d ", Vec_IntEntry(&
p->vHits, i) );
593 printf(
"There is no current library.\n" );
616 int iFunc = *Vec_MemHashLookup(
p->vTtMem, pTruth );
622 *piObj = pObj -
p->pObjs;
633 Abc_TtCopy( pCopy, pTruth, 4, 0 );
636 Vec_PtrClear( vGates );
637 Vec_PtrClear( vFans );
639 assert( !Abc_TtIsConst0(pTruth,
p->nWords) &&
640 !Abc_TtIsConst1(pTruth,
p->nWords) &&
641 !Abc_TtEqual(pTruth, s_Truth8[0],
p->nWords) &&
642 !Abc_TtOpposite(pTruth, s_Truth8[0],
p->nWords) );
643 iFunc = *Vec_MemHashLookup(
p->vTtMem, pTruth );
647 if (
p->fVerbose || nFanins > 6 )
649 printf(
"Not found in the precomputed library: " );
654 Vec_IntAddToEntry( &
p->vHits, iFunc, 1 );
658 pCellB =
p->pCells + (int)pObj->
pFansB[0];
659 pCellT =
p->pCells + (int)pObj->
pFansT[0];
660 Vec_PtrPush( vGates, pCellB->
pMioGate );
661 Vec_PtrPush( vGates, pCellT ==
p->pCells ? NULL : pCellT->
pMioGate );
662 Vec_PtrPush( vFans, pObj->
pFansB + 1 );
663 Vec_PtrPush( vFans, pCellT ==
p->pCells ? NULL : pObj->
pFansT + 1 );
665 return Vec_PtrSize(vGates) / 2;
684 if ( Abc_TtIsConst0(pTruth,
p->nWords) || Abc_TtIsConst1(pTruth,
p->nWords) )
689 vLevel = Vec_WecPushLevel( vFanins );
692 if ( Abc_TtEqual(pTruth, s_Truth8[0],
p->nWords) || Abc_TtOpposite(pTruth, s_Truth8[0],
p->nWords) )
697 vLevel = Vec_WecPushLevel( vFanins );
698 Vec_IntPush( vLevel, pFanins[0] );
713 pCellB =
p->pCells + (int)pObjMin->
pFansB[0];
714 pCellT =
p->pCells + (int)pObjMin->
pFansT[0];
719 vLevel = Vec_WecPushLevel( vFanins );
720 for ( i = 0; i < (int)pCellB->
nFanins; i++ )
721 Vec_IntPush( vLevel, pFanins[(
int)pObjMin->
pFansB[i+1]] );
722 if ( pCellT ==
p->pCells )
728 vLevel = Vec_WecPushLevel( vFanins );
729 for ( i = 0; i < (int)pCellT->
nFanins; i++ )
730 if ( pObjMin->
pFansT[i+1] == (
char)16 )
731 Vec_IntPush( vLevel, Vec_WecSize(vFanins)-2 );
733 Vec_IntPush( vLevel, pFanins[(
int)pObjMin->
pFansT[i+1]] );
742 vLevel = Vec_WecPushLevel( vFanins );
744 for ( i = 0; i < nFanins; i++ )
745 Vec_IntPush( vLevel, pFanins[(
int)pFansB[i]] );
746 if ( pGateT == NULL )
750 vLevel = Vec_WecPushLevel( vFanins );
752 for ( i = 0; i < nFanins; i++ )
753 if ( pFansT[i] == (
char)16 )
754 Vec_IntPush( vLevel, Vec_WecSize(vFanins)-2 );
756 Vec_IntPush( vLevel, pFanins[(
int)pFansT[i]] );
#define ABC_SWAP(Type, a, b)
#define ABC_REALLOC(type, obj, num)
#define ABC_CALLOC(type, num)
#define ABC_CONST(number)
PARAMETERS ///.
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_DLL void * Abc_FrameReadLibGen()
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Vec_Str_t_ Vec_Str_t
int Dau_DsdDecompose(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
void Dau_DsdPrintFromTruth(word *pTruth, int nVarsInit)
unsigned __int64 word
DECLARATIONS ///.
Mio_Gate_t * Mio_LibraryReadConst0(Mio_Library_t *pLib)
int Mio_GateReadPinNum(Mio_Gate_t *pGate)
struct Mio_LibraryStruct_t_ Mio_Library_t
Mio_Cell2_t * Mio_CollectRootsNewDefault2(int nInputs, int *pnGates, int fVerbose)
word Mio_GateReadTruth(Mio_Gate_t *pGate)
Mio_Gate_t * Mio_LibraryReadGateByName(Mio_Library_t *pLib, char *pName, char *pOutName)
struct Mio_Cell2_t_ Mio_Cell2_t
int Mio_GateReadValue(Mio_Gate_t *pGate)
void Mio_GateSetValue(Mio_Gate_t *pGate, int Value)
#define Mio_LibraryForEachGate(Lib, Gate)
GLOBAL VARIABLES ///.
Mio_Gate_t * Mio_LibraryReadConst1(Mio_Library_t *pLib)
int Mio_LibraryReadGateNum(Mio_Library_t *pLib)
Mio_Gate_t * Mio_LibraryReadInv(Mio_Library_t *pLib)
struct Mio_GateStruct_t_ Mio_Gate_t
Mio_Gate_t * Mio_LibraryReadBuf(Mio_Library_t *pLib)
int Sfm_TruthToCnf(word Truth, word *pTruth, int nVars, Vec_Int_t *vCover, Vec_Str_t *vCnf)
struct Sfm_Fun_t_ Sfm_Fun_t
BASIC TYPES ///.
struct Sfm_Lib_t_ Sfm_Lib_t
void Sfm_LibPrepareAdd(Sfm_Lib_t *p, word *pTruth, int *Perm, int nFanins, Mio_Cell2_t *pCellBot, Mio_Cell2_t *pCellTop, int InTop)
int Sfm_LibImplementGatesArea(Sfm_Lib_t *p, int *pFanins, int nFanins, int iObj, Vec_Int_t *vGates, Vec_Wec_t *vFanins)
word Sfm_LibTruth6Two(Mio_Cell2_t *pCellBot, Mio_Cell2_t *pCellTop, int InTop)
void Sfm_LibPrint(Sfm_Lib_t *p)
void Sfm_DecCreateCnf(Vec_Int_t *vGateSizes, Vec_Wrd_t *vGateFuncs, Vec_Wec_t *vGateCnfs)
FUNCTION DEFINITIONS ///.
Sfm_Lib_t * Sfm_LibStart(int nVars, int fDelay, int fVerbose)
void Sfm_LibPreprocess(Mio_Library_t *pLib, Vec_Int_t *vGateSizes, Vec_Wrd_t *vGateFuncs, Vec_Wec_t *vGateCnfs, Vec_Ptr_t *vGateHands)
Sfm_Lib_t * Sfm_LibPrepare(int nVars, int fTwo, int fDelay, int fVerbose, int fLibVerbose)
int Sfm_LibFindComplInputGate(Vec_Wrd_t *vFuncs, int iGate, int nFanins, int iFanin, int *piFaninNew)
void Sfm_LibStop(Sfm_Lib_t *p)
int Sfm_LibImplementGatesDelay(Sfm_Lib_t *p, int *pFanins, Mio_Gate_t *pGateB, Mio_Gate_t *pGateT, char *pFansB, char *pFansT, Vec_Int_t *vGates, Vec_Wec_t *vFanins)
int Sfm_LibFindDelayMatches(Sfm_Lib_t *p, word *pTruth, int *pFanins, int nFanins, Vec_Ptr_t *vGates, Vec_Ptr_t *vFans)
void Sfm_LibTruth8Two(Mio_Cell2_t *pCellBot, Mio_Cell2_t *pCellTop, int InTop, word *pRes)
int Sfm_LibImplementSimple(Sfm_Lib_t *p, word *pTruth, int *pFanins, int nFanins, Vec_Int_t *vGates, Vec_Wec_t *vFanins)
#define Sfm_LibForEachSuper(p, pObj, Func)
int Sfm_LibFindAreaMatch(Sfm_Lib_t *p, word *pTruth, int nFanins, int *piObj)
void Sfm_LibCellProfile(Mio_Cell2_t *pCellBot, Mio_Cell2_t *pCellTop, int InTop, int nFanins, int *Perm, int *pProf)
void Sfm_LibPrintObj(Sfm_Lib_t *p, Sfm_Fun_t *pObj)
void Sfm_LibPrintGate(Mio_Cell2_t *pCell, char *pFanins, Mio_Cell2_t *pCell2, char *pFanins2)
char pFansB[SFM_SUPP_MAX+1]
char pFansT[SFM_SUPP_MAX+1]
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
#define Vec_MemForEachEntry(p, pEntry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
#define Vec_WrdForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.