32#define LMS_MAX_WORD (1<<(LMS_VAR_MAX-6))
113static inline int Lms_DelayGet(
word D,
int v ) {
assert(v >= 0 && v <
LMS_VAR_MAX);
return (
int)((D >> (v << 2)) & 0xF); }
116static inline word Lms_DelayMax(
word D1,
word D2,
int nVars )
120 for ( v = 0; v < nVars; v++ )
121 if ( (Max = Abc_MaxInt(Lms_DelayGet(D1, v), Lms_DelayGet(D2, v))) )
122 Lms_DelaySet( &D, v, Abc_MinInt(Max + 1, 15) );
125static inline word Lms_DelayDecrement(
word D1,
int nVars )
129 for ( v = 0; v < nVars; v++ )
130 if ( Lms_DelayGet(D1, v) )
131 Lms_DelaySet( &D, v, Lms_DelayGet(D1, v) - 1 );
134static inline int Lms_DelayEqual(
word D1,
word D2,
int nVars )
137 for ( v = 0; v < nVars; v++ )
138 if ( Lms_DelayGet(D1, v) != Lms_DelayGet(D2, v) )
142static inline int Lms_DelayDom(
word D1,
word D2,
int nVars )
145 for ( v = 0; v < nVars; v++ )
146 if ( Lms_DelayGet(D1, v) > Lms_DelayGet(D2, v) )
150static inline void Lms_DelayPrint(
word D,
int nVars )
153 printf(
"Delay profile = {" );
154 for ( v = 0; v < nVars; v++ )
155 printf(
" %d", Lms_DelayGet(D, v) );
164 vDelays = Vec_WrdAlloc( Gia_ManObjNum(
p) );
165 Vec_WrdPush( vDelays, 0 );
168 if ( Gia_ObjIsAnd(pObj) )
169 Vec_WrdPush( vDelays, Lms_DelayMax( Vec_WrdEntry(vDelays, Gia_ObjFaninId0(pObj, i)), Vec_WrdEntry(vDelays, Gia_ObjFaninId1(pObj, i)), Gia_ManCiNum(
p) ) );
170 else if ( Gia_ObjIsCo(pObj) )
171 Vec_WrdPush( vDelays, Lms_DelayDecrement( Vec_WrdEntry(vDelays, Gia_ObjFaninId0(pObj, i)), Gia_ManCiNum(
p) ) );
172 else if ( Gia_ObjIsCi(pObj) )
173 Vec_WrdPush( vDelays, Lms_DelayInit( Gia_ObjCioId(pObj) ) );
177 vResult = Vec_WrdAlloc( Gia_ManCoNum(
p) );
179 Vec_WrdPush( vResult, Vec_WrdEntry(vDelays, Gia_ObjId(
p, pObj)) );
180 Vec_WrdFree( vDelays );
185 if ( pObj->
fMark0 || Gia_ObjIsCi(pObj) )
193 if ( !pObj->
fMark0 || Gia_ObjIsCi(pObj) )
201 assert( Gia_ObjIsAnd(pObj) );
210 vAreas = Vec_StrAlloc( Gia_ManCoNum(
p) );
212 Vec_StrPush( vAreas, (
char)(Gia_ObjIsAnd(Gia_ObjFanin0(pObj)) ?
Lms_ObjArea(Gia_ObjFanin0(pObj)) : 0) );
221 vSupps = Vec_StrAlloc( Gia_ManObjNum(
p) );
222 Vec_StrPush( vSupps, 0 );
225 if ( Gia_ObjIsAnd(pObj) )
226 Vec_StrPush( vSupps, (
char)Abc_MaxInt( Vec_StrEntry(vSupps, Gia_ObjFaninId0(pObj, i)), Vec_StrEntry(vSupps, Gia_ObjFaninId1(pObj, i)) ) );
227 else if ( Gia_ObjIsCo(pObj) )
228 Vec_StrPush( vSupps, Vec_StrEntry(vSupps, Gia_ObjFaninId0(pObj, i)) );
229 else if ( Gia_ObjIsCi(pObj) )
230 Vec_StrPush( vSupps, (
char)(Gia_ObjCioId(pObj)+1) );
233 assert( Vec_StrSize(vSupps) == Gia_ManObjNum(
p) );
234 vResult = Vec_StrAlloc( Gia_ManCoNum(
p) );
236 Vec_StrPush( vResult, Vec_StrEntry(vSupps, Gia_ObjId(
p, pObj)) );
237 Vec_StrFree( vSupps );
250 printf(
"%6d : ", i );
251 printf(
"A = %2d ", Vec_StrEntry(vAreas, i) );
252 Lms_DelayPrint( Vec_WrdEntry(vDelays, i), Gia_ManPiNum(
p) );
256 Vec_WrdFree( vDelays );
257 Vec_StrFree( vAreas );
273 if ( !pObj->
fMark0 || Gia_ObjIsCi(pObj) )
276 assert( Gia_ObjIsAnd(pObj) );
283 assert( Gia_ObjIsCo(pObj) );
284 if ( Gia_ObjIsAnd(Gia_ObjFanin0(pObj)) )
308 abctime clk, clk2 = Abc_Clock();
310 nVars = pGia ? Gia_ManCiNum(pGia) : nVars;
317 p->nWords = Abc_Truth6WordNum( nVars );
318 p->fFuncOnly = fFuncOnly;
320 p->vTtMem = Vec_MemAlloc(
p->nWords, 12 );
322 Vec_MemHashAlloc(
p->vTtMem, 10000 );
326 p->vTruthIds = Vec_IntAlloc( 10000 );
331 p->pGia->pName = Abc_UtilStrsav(
"record" );
332 for ( i = 0; i < nVars; i++ )
333 Gia_ManAppendCi(
p->pGia );
339 int i, Index, Prev = -1;
342 p->nAdded = Gia_ManCoNum(
p->pGia );
347 p->timeTruth += Abc_Clock() - clk;
349 Index = Vec_MemHashInsert(
p->vTtMem, pTruth );
350 p->timeInsert += Abc_Clock() - clk;
351 assert( Index == Prev || Index == Prev + 1 );
352 Vec_IntPush(
p->vTruthIds, Index );
357 p->vNodes = Vec_PtrAlloc( 1000 );
358 p->vLabelsP = Vec_PtrAlloc( 1000 );
359 p->vLabels = Vec_IntAlloc( 1000 );
360p->timeTotal += Abc_Clock() - clk2;
366 Vec_IntFreeP( &
p->vLabels );
367 Vec_PtrFreeP( &
p->vLabelsP );
368 Vec_PtrFreeP( &
p->vNodes );
370 Vec_IntFreeP( &
p->vTruthPo );
371 Vec_WrdFreeP( &
p->vDelays );
372 Vec_StrFreeP( &
p->vAreas );
373 Vec_IntFreeP( &
p->vFreqs );
374 Vec_IntFreeP( &
p->vTruthFreqs );
376 Vec_IntFreeP( &
p->vTruthIds );
377 Vec_MemHashFree(
p->vTtMem );
379 Vec_MemFree(
p->vTtMem );
390 p->vTruthPo = Vec_IntStartFull( Vec_MemEntryNum(
p->vTtMem)+1 );
391 assert( Vec_IntFindMin(
p->vTruthIds) >= 0 );
392 assert( Vec_IntFindMax(
p->vTruthIds) < Vec_MemEntryNum(
p->vTtMem) );
394 if ( Vec_IntEntry(
p->vTruthPo, Entry) == -1 )
395 Vec_IntWriteEntry(
p->vTruthPo, Entry, i );
396 Vec_IntWriteEntry(
p->vTruthPo, Vec_MemEntryNum(
p->vTtMem), Gia_ManCoNum(
p->pGia) );
403 p->vFreqs = Vec_IntStart( Gia_ManCoNum(
p->pGia) );
410 if (
p->pGia == NULL )
414 if (
p->vTruthPo == NULL )
419 if ( i == Vec_IntSize(
p->vTruthPo) - 1 )
421 Next = Vec_IntEntry(
p->vTruthPo, i+1 );
422 Counters[(int)Vec_StrEntry(vSupps, Entry)]++;
423 CountersS[(int)Vec_StrEntry(vSupps, Entry)] += Next - Entry;
427 printf(
"Inputs = %2d. Funcs = %8d. Subgrs = %8d. Ratio = %6.2f.\n", i, Counters[i], CountersS[i], 1.0*CountersS[i]/Counters[i] );
428 Vec_StrFree( vSupps );
432 int CountDsdNpn[3] = {0};
433 int CountDsdAll[3] = {0};
434 int CountStepNpn[3] = {0};
435 int CountStepAll[3] = {0};
441 printf(
"Cuts = %10d. ",
p->nTried );
443 printf(
"Class = %10d (%6.2f %%). ", Vec_MemEntryNum(
p->vTtMem), 100.0*Vec_MemEntryNum(
p->vTtMem)/
p->nTried );
449 pTruth = Vec_MemReadEntry(
p->vTtMem, i);
455 nSuppSize = Abc_TtSupportSize( pTruth,
p->nVars );
457 if ( nNonDecSize == 0 )
460 CountDsdAll[0] +=
Freq;
462 else if ( nNonDecSize < nSuppSize )
465 CountDsdAll[1] +=
Freq;
470 CountDsdAll[2] +=
Freq;
473 if ( nNonDecSize == 0 )
476 CountStepAll[0] +=
Freq;
485 CountStepAll[1] +=
Freq;
491 CountStepAll[2] +=
Freq;
497 printf(
"Full = %6.2f %% ", 100.0 * CountDsdNpn[0] / Vec_MemEntryNum(
p->vTtMem) );
498 printf(
"Part = %6.2f %% ", 100.0 * CountDsdNpn[1] / Vec_MemEntryNum(
p->vTtMem) );
499 printf(
"None = %6.2f %% ", 100.0 * CountDsdNpn[2] / Vec_MemEntryNum(
p->vTtMem) );
504 printf(
"Full = %6.2f %% ", 100.0 * CountDsdAll[0] /
p->nTried );
505 printf(
"Part = %6.2f %% ", 100.0 * CountDsdAll[1] /
p->nTried );
506 printf(
"None = %6.2f %% ", 100.0 * CountDsdAll[2] /
p->nTried );
511 printf(
"Full = %6.2f %% ", 100.0 * CountStepNpn[0] / Vec_MemEntryNum(
p->vTtMem) );
512 printf(
"1stp = %6.2f %% ", 100.0 * CountStepNpn[1] / Vec_MemEntryNum(
p->vTtMem) );
513 printf(
"Comp = %6.2f %% ", 100.0 * CountStepNpn[2] / Vec_MemEntryNum(
p->vTtMem) );
518 printf(
"Full = %6.2f %% ", 100.0 * CountStepAll[0] /
p->nTried );
519 printf(
"1stp = %6.2f %% ", 100.0 * CountStepAll[1] /
p->nTried );
520 printf(
"Comp = %6.2f %% ", 100.0 * CountStepAll[2] /
p->nTried );
527 printf(
"Library with %d vars has %d classes and %d AIG subgraphs with %d AND nodes.\n",
528 p->nVars, Vec_MemEntryNum(
p->vTtMem),
p->nAdded,
p->pGia ? Gia_ManAndNum(
p->pGia) : 0 );
533 p->nAddedFuncs = Vec_MemEntryNum(
p->vTtMem);
534 printf(
"Subgraphs tried = %10d. (%6.2f %%)\n",
p->nTried, !
p->nTried? 0 : 100.0*
p->nTried/
p->nTried );
535 printf(
"Subgraphs filtered by support size = %10d. (%6.2f %%)\n",
p->nFilterSize, !
p->nTried? 0 : 100.0*
p->nFilterSize/
p->nTried );
536 printf(
"Subgraphs filtered by structural redundancy = %10d. (%6.2f %%)\n",
p->nFilterRedund, !
p->nTried? 0 : 100.0*
p->nFilterRedund/
p->nTried );
537 printf(
"Subgraphs filtered by volume = %10d. (%6.2f %%)\n",
p->nFilterVolume, !
p->nTried? 0 : 100.0*
p->nFilterVolume/
p->nTried );
538 printf(
"Subgraphs filtered by TT redundancy = %10d. (%6.2f %%)\n",
p->nFilterTruth, !
p->nTried? 0 : 100.0*
p->nFilterTruth/
p->nTried );
539 printf(
"Subgraphs filtered by error = %10d. (%6.2f %%)\n",
p->nFilterError, !
p->nTried? 0 : 100.0*
p->nFilterError/
p->nTried );
540 printf(
"Subgraphs filtered by isomorphism = %10d. (%6.2f %%)\n",
p->nFilterSame, !
p->nTried? 0 : 100.0*
p->nFilterSame/
p->nTried );
541 printf(
"Subgraphs added = %10d. (%6.2f %%)\n",
p->nAdded, !
p->nTried? 0 : 100.0*
p->nAdded/
p->nTried );
542 printf(
"Functions added = %10d. (%6.2f %%)\n",
p->nAddedFuncs, !
p->nTried? 0 : 100.0*
p->nAddedFuncs/
p->nTried );
543 if (
p->nHoleInTheWall )
544 printf(
"Cuts whose logic structure has a hole = %10d. (%6.2f %%)\n",
p->nHoleInTheWall, !
p->nTried? 0 : 100.0*
p->nHoleInTheWall/
p->nTried );
546 p->timeOther =
p->timeTotal -
p->timeTruth -
p->timeCanon -
p->timeBuild -
p->timeCheck -
p->timeInsert;
547 ABC_PRTP(
"Runtime: Truth ",
p->timeTruth,
p->timeTotal );
548 ABC_PRTP(
"Runtime: Canon ",
p->timeCanon,
p->timeTotal );
549 ABC_PRTP(
"Runtime: Build ",
p->timeBuild,
p->timeTotal );
550 ABC_PRTP(
"Runtime: Check ",
p->timeCheck,
p->timeTotal );
551 ABC_PRTP(
"Runtime: Insert",
p->timeInsert,
p->timeTotal );
552 ABC_PRTP(
"Runtime: Other ",
p->timeOther,
p->timeTotal );
553 ABC_PRTP(
"Runtime: TOTAL ",
p->timeTotal,
p->timeTotal );
574 unsigned uCanonPhase;
576 int i, k, Index, iFanin0, iFanin1, nLeaves;
577 Gia_Obj_t * pObjPo, * pDriver, * pTemp = NULL;
578 abctime clk, clk2 = Abc_Clock();
580 if ( Gia_ManCiNum(pLib) != Gia_ManCiNum(pGia) )
582 printf(
"The number of Library inputs (%d) differs from the number of Gia inputs (%d).\n", Gia_ManCiNum(pLib), Gia_ManCiNum(pGia) );
585 assert( Gia_ManCiNum(pLib) == Gia_ManCiNum(pGia) );
588 if ( Vec_IntSize(&pGia->
vHTable) == 0 )
596 nLeaves = Vec_StrEntry(vSupps, k);
602p->timeTruth += Abc_Clock() - clk;
606#ifdef LMS_USE_OLD_FORM
611 Abc_TtStretch5( (
unsigned *)
p->pTemp1, nLeaves,
p->nVars );
612p->timeCanon += Abc_Clock() - clk;
614 if ( nLeaves == 2 && Abc_TtSupportSize(pTruth, 2) != 2 )
619 for ( i = 0; i < nLeaves; i++ )
620 Gia_ManCi( pLib, pCanonPerm[i] )->Value = Abc_Var2Lit( Gia_ObjId(pGia, Gia_ManPi(pGia, i)), (uCanonPhase >> i) & 1 );
625 iFanin0 = Abc_LitNotCond( Gia_ObjFanin0(pTemp)->Value, Gia_ObjFaninC0(pTemp) );
626 iFanin1 = Abc_LitNotCond( Gia_ObjFanin1(pTemp)->Value, Gia_ObjFaninC1(pTemp) );
629p->timeBuild += Abc_Clock() - clk;
632 assert( Gia_ObjIsAnd(pTemp) );
633 pDriver = Gia_ManObj(pGia, Abc_Lit2Var(pTemp->
Value));
641 Gia_ManAppendCo( pGia, Abc_LitNotCond( pTemp->
Value, (uCanonPhase >> nLeaves) & 1 ) );
647 pTemp = Gia_ManCo(pGia, Gia_ManCoNum(pGia)-1);
649p->timeCheck += Abc_Clock() - clk;
650 if (
memcmp(
p->pTemp1, pTruth,
p->nWords *
sizeof(
word) ) != 0 )
655 printf(
"Truth table verification has failed.\n" );
658 Gia_ManPatchCoDriver( pGia, Gia_ManCoNum(pGia)-1, 0 );
660 Vec_IntPush(
p->vTruthIds, -1 );
668 Index = Vec_MemHashInsert(
p->vTtMem,
p->pTemp1 );
670 Vec_IntPush(
p->vTruthIds, Index );
671 assert( Gia_ManCoNum(pGia) == Vec_IntSize(
p->vTruthIds) );
673p->timeInsert += Abc_Clock() - clk;
675 Vec_StrFree( vSupps );
676p->timeTotal += Abc_Clock() - clk2;
695 unsigned uCanonPhase;
696 int i, Index, iFanin0, iFanin1, fHole;
697 int nLeaves = If_CutLeaveNum(pCut);
708 if ( nLeaves < 2 || (nLeaves == 2 && Abc_TtSupportSize(If_CutTruthW(pIfMan, pCut), 2) != 2) )
719 memcpy(
p->pTemp1, If_CutTruthW(pIfMan, pCut),
p->nWords *
sizeof(
word) );
720#ifdef LMS_USE_OLD_FORM
725 Abc_TtStretch5( (
unsigned *)
p->pTemp1, nLeaves,
p->nVars );
726p->timeCanon += Abc_Clock() - clk;
729 if (
p->pGia == NULL )
733 Index = Vec_MemHashInsert(
p->vTtMem,
p->pTemp1 );
744p->timeInsert += Abc_Clock() - clk;
751p->timeTruth += Abc_Clock() - clk;
752 if ( Vec_PtrSize(vNodes) > 253 )
760 for ( i = 0; i < nLeaves; i++ )
761 If_ManObj( pIfMan, pCut->
pLeaves[(
int)pCanonPerm[i]] )->iCopy = Abc_Var2Lit( Gia_ObjId(pGia, Gia_ManPi(pGia, i)), (uCanonPhase >> i) & 1 );
764 assert( Vec_PtrSize(vNodes) > 0 );
767 if ( If_ObjIsCi(pIfObj) )
773 iFanin0 = Abc_LitNotCond( If_ObjFanin0(pIfObj)->iCopy, If_ObjFaninC0(pIfObj) );
774 iFanin1 = Abc_LitNotCond( If_ObjFanin1(pIfObj)->iCopy, If_ObjFaninC1(pIfObj) );
777 p->nHoleInTheWall += fHole;
778p->timeBuild += Abc_Clock() - clk;
781 assert( If_ObjIsAnd(pIfObj) );
782 pDriver = Gia_ManObj(pGia, Abc_Lit2Var(pIfObj->
iCopy));
790 Gia_ManAppendCo( pGia, Abc_LitNotCond( pIfObj->
iCopy, (uCanonPhase >> nLeaves) & 1 ) );
795p->timeCheck += Abc_Clock() - clk;
796 if (
memcmp(
p->pTemp1, pTruth,
p->nWords *
sizeof(
word) ) != 0 )
804 Gia_ManPatchCoDriver( pGia, Gia_ManCoNum(pGia)-1, 0 );
806 Vec_IntPush(
p->vTruthIds, -1 );
813 Index = Vec_MemHashInsert(
p->vTtMem,
p->pTemp1 );
815 Vec_IntPush(
p->vTruthIds, Index );
816 assert( Gia_ManCoNum(pGia) == Vec_IntSize(
p->vTruthIds) );
818p->timeInsert += Abc_Clock() - clk;
838 int clk = Abc_Clock();
840 printf(
"Performing recoding structures with choices.\n" );
842 s_pMan3->fLibConstr = 1;
844 if ( s_pMan3->pGia && Vec_IntSize(&s_pMan3->pGia->vHTable) == 0 )
876s_pMan3->timeTotal += Abc_Clock() - clk;
890static inline int If_CutComputeDelay(
If_Man_t *
p,
If_Cut_t * pCut,
char * pCanonPerm,
word DelayProfile )
893 int nLeaves = If_CutLeaveNum(pCut);
895 for ( i = 0; i < nLeaves; i++ )
897 pLeaf = If_ManObj(
p, (pCut)->pLeaves[(
int)pCanonPerm[i]]);
898 delayTemp = If_ObjCutBest(pLeaf)->Delay + Lms_DelayGet(DelayProfile, i);
899 delayMax = Abc_MaxInt( delayMax, delayTemp );
903static inline int If_CutFindBestStruct(
If_Man_t * pIfMan,
If_Cut_t * pCut,
char * pCanonPerm,
unsigned * puCanonPhase,
int * pBestPo )
906 int i, * pTruthId, iFirstPo, iFirstPoNext, iBestPo;
908 int uSupport, nLeaves = If_CutLeaveNum( pCut );
909 char * pPerm = If_CutPerm( pCut );
914 uSupport = Abc_TtSupport( If_CutTruthW(pIfMan, pCut), nLeaves );
918 for ( i = 0; i < nLeaves; i++ )
922 if ( !Abc_TtSuppIsMinBase(uSupport) || uSupport == 1 )
924 assert( Abc_TtSuppOnlyOne(uSupport) );
926 for ( i = 0; i < nLeaves; i++ )
928 pPerm[Abc_TtSuppFindFirst(uSupport)] = 0;
929 return If_ObjCutBest(If_ManObj(pIfMan, pCut->
pLeaves[Abc_TtSuppFindFirst(uSupport)]))->Delay;
931 assert( Gia_WordCountOnes(uSupport) == nLeaves );
935 memcpy(
p->pTemp1, If_CutTruthW(pIfMan, pCut),
p->nWords *
sizeof(
word) );
936#ifdef LMS_USE_OLD_FORM
941 Abc_TtStretch5( (
unsigned *)
p->pTemp1, nLeaves,
p->nVars );
942p->timeCanon += Abc_Clock() - clk;
945 pTruthId = Vec_MemHashLookup(
p->vTtMem,
p->pTemp1 );
946 if ( *pTruthId == -1 )
958 iFirstPo = Vec_IntEntry(
p->vTruthPo, *pTruthId );
960 iFirstPoNext = Vec_IntEntry(
p->vTruthPo, *pTruthId+1 );
963 for ( i = iFirstPo; i < iFirstPoNext; i++ )
965 Delay = If_CutComputeDelay( pIfMan, pCut, pCanonPerm, Vec_WrdEntry(
p->vDelays, i) );
966 Area = Vec_StrEntry(
p->vAreas, i);
967 if ( iBestPo == -1 || BestDelay > Delay || (BestDelay == Delay && BestArea > Area) )
978 DelayProfile = Vec_WrdEntry(
p->vDelays, iBestPo);
979 pCut->
Cost = Vec_StrEntry(
p->vAreas, iBestPo);
980 for ( i = 0; i < nLeaves; i++ )
981 pPerm[(
int)pCanonPerm[i]] = Lms_DelayGet(DelayProfile, i);
984 int Max = 0, Two = 0, pTimes[16];
985 for ( i = 0; i < nLeaves; i++ )
986 pTimes[i] = (
int)If_ObjCutBest(If_CutLeaf(pIfMan, pCut, i))->Delay;
987 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
988 Max = Abc_MaxInt( Max, pTimes[i] );
989 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
990 if ( pTimes[i] != Max )
991 Two = Abc_MaxInt( Two, pTimes[i] );
992 if ( Two + 2 < Max && Max + 3 < BestDelay )
994 for ( i = 0; i < If_CutLeaveNum(pCut); i++ )
995 printf(
"%3d ", pTimes[i] );
998 printf(
"-> %3d ", BestDelay );
1008 unsigned uCanonPhase = 0;
1014 if (
p->vTruthPo == NULL )
1017 return If_CutFindBestStruct( pIfMan, pCut, pCanonPerm, &uCanonPhase, NULL );
1035 unsigned uCanonPhase = 0;
1039 int i, uSupport, BestPo = -1, nLeaves = If_CutLeaveNum(pCut);
1043 uSupport = Abc_TtSupport( If_CutTruthW(pIfMan, pCut), nLeaves );
1044 if ( uSupport == 0 )
1045 return Hop_NotCond( Hop_ManConst0(pMan), If_CutTruthIsCompl(pCut) );
1046 if ( !Abc_TtSuppIsMinBase(uSupport) || uSupport == 1 )
1048 assert( Abc_TtSuppOnlyOne(uSupport) );
1049 return Hop_NotCond(
Hop_IthVar(pMan, Abc_TtSuppFindFirst(uSupport)), If_CutTruthIsCompl(pCut) );
1051 assert( Gia_WordCountOnes(uSupport) == nLeaves );
1054 If_CutFindBestStruct( pIfMan, pCut, pCanonPerm, &uCanonPhase, &BestPo );
1056 pGiaPo = Gia_ManCo( pGia, BestPo );
1059 pGia->
vTtNodes = Vec_IntAlloc( 256 );
1060 assert( Gia_ObjIsAnd( Gia_ObjFanin0(pGiaPo) ) );
1065 Vec_PtrClear(
p->vLabelsP );
1066 for ( i = 0; i < nLeaves; i++ )
1067 Vec_PtrPush(
p->vLabelsP, Hop_NotCond(
Hop_IthVar(pMan, pCanonPerm[i]), (uCanonPhase >> i) & 1) );
1073 if ( Gia_ObjIsAnd(Gia_ObjFanin0(pGiaTemp)) )
1074 pFan0 = (
Hop_Obj_t *)Vec_PtrEntry(
p->vLabelsP, Gia_ObjNum(pGia, Gia_ObjFanin0(pGiaTemp)) + nLeaves);
1076 pFan0 = (
Hop_Obj_t *)Vec_PtrEntry(
p->vLabelsP, Gia_ObjCioId(Gia_ObjFanin0(pGiaTemp)));
1077 pFan0 = Hop_NotCond(pFan0, Gia_ObjFaninC0(pGiaTemp));
1078 if ( Gia_ObjIsAnd(Gia_ObjFanin1(pGiaTemp)) )
1079 pFan1 = (
Hop_Obj_t *)Vec_PtrEntry(
p->vLabelsP, Gia_ObjNum(pGia, Gia_ObjFanin1(pGiaTemp)) + nLeaves);
1081 pFan1 = (
Hop_Obj_t *)Vec_PtrEntry(
p->vLabelsP, Gia_ObjCioId(Gia_ObjFanin1(pGiaTemp)));
1082 pFan1 = Hop_NotCond(pFan1, Gia_ObjFaninC1(pGiaTemp));
1084 pHopObj =
Hop_And(pMan, pFan0, pFan1);
1085 Vec_PtrPush(
p->vLabelsP, pHopObj);
1088 assert( Gia_ObjIsAnd(pGiaTemp) );
1089 pHopObj = (
Hop_Obj_t *)Vec_PtrEntry(
p->vLabelsP, Gia_ObjNum(pGia, pGiaTemp) + nLeaves);
1091 return Hop_NotCond( pHopObj, Gia_ObjFaninC0(pGiaPo) ^ ((uCanonPhase >> nLeaves) & 1) );
1109 unsigned uCanonPhase = 0;
1110 int iFan0, iFan1, iGiaObj;
1113 int i, uSupport, BestPo = -1, nLeaves = If_CutLeaveNum(pCut);
1115 assert( nLeaves == Vec_IntSize(vLeaves) );
1118 uSupport = Abc_TtSupport( If_CutTruthW(pIfMan, pCut), nLeaves );
1119 if ( uSupport == 0 )
1120 return Abc_LitNotCond( 0, If_CutTruthIsCompl(pCut) );
1121 if ( !Abc_TtSuppIsMinBase(uSupport) || uSupport == 1 )
1123 assert( Abc_TtSuppOnlyOne(uSupport) );
1124 return Abc_LitNotCond( Vec_IntEntry(vLeaves, Abc_TtSuppFindFirst(uSupport)), If_CutTruthIsCompl(pCut) );
1126 assert( Gia_WordCountOnes(uSupport) == nLeaves );
1129 If_CutFindBestStruct( pIfMan, pCut, pCanonPerm, &uCanonPhase, &BestPo );
1131 pGiaPo = Gia_ManCo( pGia, BestPo );
1135 pGia->
vTtNodes = Vec_IntAlloc( 256 );
1136 assert( Gia_ObjIsAnd( Gia_ObjFanin0(pGiaPo) ) );
1141 Vec_IntClear(
p->vLabels );
1142 for (i = 0; i < nLeaves; i++)
1143 Vec_IntPush(
p->vLabels, Abc_LitNotCond(Vec_IntEntry(vLeaves, pCanonPerm[i]), (uCanonPhase >> i) & 1) );
1149 if ( Gia_ObjIsAnd(Gia_ObjFanin0(pGiaTemp)) )
1150 iFan0 = Vec_IntEntry(
p->vLabels, Gia_ObjNum(pGia, Gia_ObjFanin0(pGiaTemp)) + nLeaves);
1152 iFan0 = Vec_IntEntry(
p->vLabels, Gia_ObjCioId(Gia_ObjFanin0(pGiaTemp)));
1153 iFan0 = Abc_LitNotCond(iFan0, Gia_ObjFaninC0(pGiaTemp));
1154 if ( Gia_ObjIsAnd(Gia_ObjFanin1(pGiaTemp)) )
1155 iFan1 = Vec_IntEntry(
p->vLabels, Gia_ObjNum(pGia, Gia_ObjFanin1(pGiaTemp)) + nLeaves);
1157 iFan1 = Vec_IntEntry(
p->vLabels, Gia_ObjCioId(Gia_ObjFanin1(pGiaTemp)));
1158 iFan1 = Abc_LitNotCond(iFan1, Gia_ObjFaninC1(pGiaTemp));
1162 iGiaObj = Gia_ManAppendAnd(pMan, iFan0, iFan1);
1163 Vec_IntPush(
p->vLabels, iGiaObj);
1166 assert( Gia_ObjIsAnd(pGiaTemp) );
1167 iGiaObj = Vec_IntEntry(
p->vLabels, Gia_ObjNum(pGia, pGiaTemp) + nLeaves);
1169 return Abc_LitNotCond( iGiaObj, Gia_ObjFaninC0(pGiaPo) ^ ((uCanonPhase >> nLeaves) & 1) ^ pCut->
fCompl );
1193 Vec_Int_t * vCounts = Vec_IntStart( Vec_MemEntryNum(
p->vTtMem) );
1197 Vec_IntAddToEntry( vCounts, Entry, 1 );
1203 Vec_Int_t * vBegins = Vec_IntAlloc( Vec_MemEntryNum(
p->vTtMem) );
1204 Vec_Int_t * vUseful = Vec_IntStartFull( Gia_ManCoNum(
p->pGia) + Vec_MemEntryNum(
p->vTtMem) );
1206 int i, Entry, * pPlace, SumTotal = 0;
1211 Vec_IntPush( vBegins, SumTotal );
1212 SumTotal += Entry + 1;
1215 Vec_IntPush( vBegins, SumTotal );
1217 Vec_IntFill( vCounts, Vec_IntSize(vCounts), 0 );
1222 pPlace = Vec_IntEntryP( vUseful, Vec_IntEntry(vBegins, Entry) + Vec_IntEntry(vCounts, Entry) );
1225 Vec_IntAddToEntry( vCounts, Entry, 1 );
1227 Vec_IntFree( vBegins );
1228 Vec_IntFree( vCounts );
1237 int i, k, EntryI, EntryK;
1245 D1 = Vec_WrdEntry(vDelays, EntryI);
1253 D2 = Vec_WrdEntry(vDelays, EntryK);
1255 if ( Lms_DelayDom(D1, D2, Gia_ManCiNum(
p->pGia)) )
1257 Vec_IntWriteEntry( vUseful, k, -2 );
1260 if ( Lms_DelayDom(D2, D1, Gia_ManCiNum(
p->pGia)) )
1262 Vec_IntWriteEntry( vUseful, i, -2 );
1268 vRemain = Vec_IntAlloc( 1000 );
1271 Vec_IntPush( vRemain, EntryI );
1272 Vec_IntFree( vUseful );
1273 Vec_WrdFree( vDelays );
1283 int i, Entry, Prev = -1, Next;
1287 vTruthIdsNew = Vec_IntAlloc( Vec_IntSize(vRemain) );
1290 pObj = Gia_ManCo(
p->pGia, Entry);
1291 assert( Gia_ObjIsAnd(Gia_ObjFanin0(pObj)) );
1292 Vec_IntWriteEntry( vRemain, i, Gia_ObjFaninLit0p(
p->pGia, pObj) );
1294 Next = Vec_IntEntry(
p->vTruthIds, Gia_ObjCioId(pObj));
1296 Vec_IntPush( vTruthIdsNew, Next );
1302 for ( i = 0; i < Gia_ManCoNum(
p->pGia); i++ )
1303 Gia_ManPatchCoDriver(
p->pGia, i, 0 );
1305 Gia_ManAppendCo(
p->pGia, Entry );
1310 Vec_IntFree( vRemain );
1312 Vec_IntFree(
p->vTruthIds );
1313 p->vTruthIds = vTruthIdsNew;
1330 int Diff = Vec_StrEntry( s_pMan3->vSupps, *p1 ) - Vec_StrEntry( s_pMan3->vSupps, *p2 );
1333 return memcmp( Vec_MemReadEntry(s_pMan3->vTtMem, *p1), Vec_MemReadEntry(s_pMan3->vTtMem, *p2),
sizeof(
word) * s_pMan3->nWords );
1342 int i, Entry, nVars =
p->nVars;
1343 int nEntries = Vec_MemEntryNum(
p->vTtMem);
1344 if ( nEntries == 0 )
1346 printf(
"There is not truth tables.\n" );
1349 pFile = fopen( pFileName,
"wb" );
1350 if ( pFile == NULL )
1352 printf(
"The file cannot be opened.\n" );
1355 p->vSupps = Vec_StrAlloc( nEntries );
1357 Vec_StrPush(
p->vSupps, (
char)Abc_TtSupportSize(pTruth, nVars) );
1358 vEntries = Vec_IntStartNatural( nEntries );
1359 qsort( (
void *)Vec_IntArray(vEntries), (
size_t)nEntries,
sizeof(
int), (
int(*)(
const void *,
const void *))
Abc_NtkRecTruthCompare );
1360 Vec_StrFreeP( &
p->vSupps );
1364 pTruth = Vec_MemReadEntry(
p->vTtMem, Entry);
1367 fwrite( pTruth, 1,
sizeof(
word) *
p->nWords, pFile );
1371 fprintf( pFile,
" " );
1374 fprintf( pFile,
"%s\n", pBuffer );
1377 Vec_IntFree( vEntries );
1393 return Gia_ManCiNum(s_pMan3->pGia);
1397 return s_pMan3 != NULL;
1402 printf(
"Before normalizing: Library has %d classes and %d AIG subgraphs with %d AND nodes.\n",
1403 Vec_MemEntryNum(s_pMan3->vTtMem), Gia_ManPoNum(s_pMan3->pGia), Gia_ManAndNum(s_pMan3->pGia) );
1405 printf(
"After normalizing: Library has %d classes and %d AIG subgraphs with %d AND nodes.\n",
1406 Vec_MemEntryNum(s_pMan3->vTtMem), Gia_ManPoNum(s_pMan3->pGia), Gia_ManAndNum(s_pMan3->pGia) );
1407 Abc_PrintTime( 1,
"Normalization runtime", Abc_Clock() - clk );
1408 s_pMan3->fLibConstr = 0;
1409 return s_pMan3->pGia;
1417 assert( s_pMan3 == NULL );
1418 s_pMan3 =
Lms_ManStart(
p, nVars, nCuts, fFuncOnly, fVerbose );
1423 assert( s_pMan3 != NULL );
Hop_Obj_t * Abc_RecToHop3(Hop_Man_t *pMan, If_Man_t *pIfMan, If_Cut_t *pCut, If_Obj_t *pIfObj)
void Lms_ManPrintFreqStats(Lms_Man_t *p)
int If_CutDelayRecCost3(If_Man_t *pIfMan, If_Cut_t *pCut, If_Obj_t *pObj)
void Abc_NtkRecPs3(int fPrintLib)
void Lms_ManPrintFuncStats(Lms_Man_t *p)
void Abc_NtkRecAdd3(Abc_Ntk_t *pNtk, int fUseSOPB)
int Lms_ObjArea(Gia_Obj_t *pObj)
Vec_Wrd_t * Lms_GiaDelays(Gia_Man_t *p)
struct Lms_Man_t_ Lms_Man_t
DECLARATIONS ///.
Vec_Str_t * Lms_GiaAreas(Gia_Man_t *p)
Vec_Int_t * Lms_GiaCollectUsefulCos(Lms_Man_t *p)
void Lms_ManStop(Lms_Man_t *p)
int Abc_RecToGia3(Gia_Man_t *pMan, If_Man_t *pIfMan, If_Cut_t *pCut, Vec_Int_t *vLeaves, int fHash)
void Lms_ObjAreaMark_rec(Gia_Obj_t *pObj)
void Lms_ManPrint(Lms_Man_t *p)
void Lms_GiaPrintSubgraph_rec(Gia_Man_t *p, Gia_Obj_t *pObj)
void Abc_NtkRecLibMerge3(Gia_Man_t *pLib)
void Lms_GiaNormalize(Lms_Man_t *p)
int Abc_NtkRecIsRunning3()
void Abc_NtkRecStart3(Gia_Man_t *p, int nVars, int nCuts, int fFuncOnly, int fVerbose)
Lms_Man_t * Lms_ManStart(Gia_Man_t *pGia, int nVars, int nCuts, int fFuncOnly, int fVerbose)
Gia_Man_t * Abc_NtkRecGetGia3()
int Abc_NtkRecTruthCompare(int *p1, int *p2)
int Lms_ObjAreaUnmark_rec(Gia_Obj_t *pObj)
void Lms_GiaProfilesPrint(Gia_Man_t *p)
void Abc_NtkRecDumpTt3(char *pFileName, int fBinary)
void Lms_ManPrepare(Lms_Man_t *p)
Vec_Int_t * Lms_GiaCountTruths(Lms_Man_t *p)
Vec_Str_t * Lms_GiaSuppSizes(Gia_Man_t *p)
int Abc_NtkRecInputNum3()
int Abc_NtkRecAddCut3(If_Man_t *pIfMan, If_Obj_t *pRoot, If_Cut_t *pCut)
void Lms_GiaPrintSubgraph(Gia_Man_t *p, Gia_Obj_t *pObj)
Vec_Int_t * Lms_GiaFindNonRedundantCos(Lms_Man_t *p)
ABC_DLL int Abc_NtkGetChoiceNum(Abc_Ntk_t *pNtk)
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
#define ABC_PRTP(a, t, T)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_CALLOC(type, num)
#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
int Dau_DsdCheck1Step(void *p, word *pTruth, int nVarsInit, int *pVarLevels)
int Dau_DsdDecompose(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
void Dau_DsdPrintFromTruth(word *pTruth, int nVarsInit)
unsigned Abc_TtCanonicize(word *pTruth, int nVars, char *pCanonPerm)
FUNCTION DECLARATIONS ///.
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
Abc_Ntk_t * Abc_NtkIf(Abc_Ntk_t *pNtk, If_Par_t *pPars)
void Gia_ManStop(Gia_Man_t *p)
void Gia_ManHashStart(Gia_Man_t *p)
#define Gia_ManForEachPo(p, pObj, i)
void Gia_ManStopP(Gia_Man_t **p)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
struct Gia_Obj_t_ Gia_Obj_t
void Gia_ObjPrint(Gia_Man_t *p, Gia_Obj_t *pObj)
struct Gia_Man_t_ Gia_Man_t
#define Gia_ManForEachObj1(p, pObj, i)
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Gia_Man_t * Gia_ManCleanupOutputs(Gia_Man_t *p, int nOutputs)
void Gia_ObjCollectInternal(Gia_Man_t *p, Gia_Obj_t *pObj)
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
#define Gia_ManForEachCo(p, pObj, i)
word * Gia_ObjComputeTruthTable(Gia_Man_t *p, Gia_Obj_t *pObj)
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Hop_Obj_t * Hop_And(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1)
struct Hop_Obj_t_ Hop_Obj_t
struct If_Par_t_ If_Par_t
struct If_Cut_t_ If_Cut_t
void If_CutTraverse(If_Man_t *p, If_Obj_t *pRoot, If_Cut_t *pCut, Vec_Ptr_t *vNodes)
struct If_Man_t_ If_Man_t
BASIC TYPES ///.
struct If_Obj_t_ If_Obj_t
unsigned __int64 word
DECLARATIONS ///.
unsigned Kit_TruthSemiCanonicize(unsigned *pInOut, unsigned *pAux, int nVars, char *pCanonPerm)
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
int(* pFuncUser)(If_Man_t *, If_Obj_t *, If_Cut_t *)
int(* pFuncCost)(If_Man_t *, If_Cut_t *)
word pTemp1[LMS_MAX_WORD]
word pTemp2[LMS_MAX_WORD]
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 ///.
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.