103static inline int Dss_IsComplement(
Dss_Obj_t *
p ) {
return (
int)((ABC_PTRUINT_T)(
p) & 01); }
105static inline int Dss_EntWordNum(
Dss_Ent_t *
p ) {
return sizeof(
Dss_Ent_t) / 8 +
p->nShared / 4 + ((
p->nShared & 3) > 0); }
106static inline int Dss_FunWordNum(
Dss_Fun_t *
p ) {
assert(
p->nFans >= 2);
return (
p->nFans + 4) / 8 + (((
p->nFans + 4) & 7) > 0); }
107static inline int Dss_ObjWordNum(
int nFans ) {
return sizeof(
Dss_Obj_t) / 8 + nFans / 2 + ((nFans & 1) > 0); }
111static inline int Dss_ObjId(
Dss_Obj_t * pObj ) {
return pObj->
Id; }
112static inline int Dss_ObjType(
Dss_Obj_t * pObj ) {
return pObj->
Type; }
113static inline int Dss_ObjSuppSize(
Dss_Obj_t * pObj ) {
return pObj->
nSupp; }
114static inline int Dss_ObjFaninNum(
Dss_Obj_t * pObj ) {
return pObj->
nFans; }
115static inline int Dss_ObjFaninC(
Dss_Obj_t * pObj,
int i ) {
assert(i < (
int)pObj->
nFans);
return Abc_LitIsCompl(pObj->
pFans[i]); }
120static inline int Dss_VecLitSuppSize(
Vec_Ptr_t *
p,
int iLit ) {
return Dss_VecObj(
p, Abc_Lit2Var(iLit) )->nSupp; }
122static inline int Dss_Obj2Lit(
Dss_Obj_t * pObj ) {
return Abc_Var2Lit(Dss_Regular(pObj)->Id, Dss_IsComplement(pObj)); }
123static inline Dss_Obj_t * Dss_Lit2Obj(
Vec_Ptr_t *
p,
int iLit ) {
return Dss_NotCond(Dss_VecObj(
p, Abc_Lit2Var(iLit)), Abc_LitIsCompl(iLit)); }
127#define Dss_VecForEachObj( vVec, pObj, i ) \
128 Vec_PtrForEachEntry( Dss_Obj_t *, vVec, pObj, i )
129#define Dss_VecForEachObjVec( vLits, vVec, pObj, i ) \
130 for ( i = 0; (i < Vec_IntSize(vLits)) && ((pObj) = Dss_Lit2Obj(vVec, Vec_IntEntry(vLits,i))); i++ )
131#define Dss_VecForEachNode( vVec, pObj, i ) \
132 Vec_PtrForEachEntry( Dss_Obj_t *, vVec, pObj, i ) \
133 if ( pObj->Type == DAU_DSD_CONST0 || pObj->Type == DAU_DSD_VAR ) {} else
134#define Dss_ObjForEachFanin( vVec, pObj, pFanin, i ) \
135 for ( i = 0; (i < Dss_ObjFaninNum(pObj)) && ((pFanin) = Dss_ObjFanin(vVec, pObj, i)); i++ )
136#define Dss_ObjForEachChild( vVec, pObj, pFanin, i ) \
137 for ( i = 0; (i < Dss_ObjFaninNum(pObj)) && ((pFanin) = Dss_ObjChild(vVec, pObj, i)); i++ )
139static inline int Dss_WordCountOnes(
unsigned uWord )
141 uWord = (uWord & 0x55555555) + ((uWord>>1) & 0x55555555);
142 uWord = (uWord & 0x33333333) + ((uWord>>2) & 0x33333333);
143 uWord = (uWord & 0x0F0F0F0F) + ((uWord>>4) & 0x0F0F0F0F);
144 uWord = (uWord & 0x00FF00FF) + ((uWord>>8) & 0x00FF00FF);
145 return (uWord & 0x0000FFFF) + (uWord>>16);
148static inline int Dss_Lit2Lit(
int * pMapLit,
int Lit ) {
return Abc_Var2Lit( Abc_Lit2Var(pMapLit[Abc_Lit2Var(Lit)]), Abc_LitIsCompl(Lit) ^ Abc_LitIsCompl(pMapLit[Abc_Lit2Var(Lit)]) ); }
172 assert( !Dss_IsComplement(pObj) );
176 return (1 << pObj->
iVar);
180 int c0, c1, c2, uSuppTemp;
183 int nFanins = Dss_ObjFaninNum(pObj);
184 int uSupps[16], nSuppSizes[16];
187 uSupps[i] = Dss_ObjCheck666_rec(
p, pFanin, vSupps );
188 nSuppSizes[i] = Dss_WordCountOnes( uSupps[i] );
190 if ( nSuppSizes[i] == 1 )
191 uSuppVars[nSuppVars++] = uSupps[i];
194 for ( c0 = 0; c0 < nFanins; c0++ )
195 if ( nSuppSizes[c0] > 1 && nSuppSizes[c0] < 6 )
197 uSuppTemp = uSupps[c0];
198 for ( i = 0; i < nSuppVars; i++ )
199 if ( nSuppSizes[c0] + i < 6 )
200 uSuppTemp |= uSuppVars[i];
203 if ( Dss_WordCountOnes(uSuppTemp) <= 6 )
204 Vec_IntPush( vSupps, uSuppTemp );
206 for ( c1 = c0 + 1; c1 < nFanins; c1++ )
207 if ( nSuppSizes[c1] > 1 && nSuppSizes[c1] < 6 )
209 if ( nSuppSizes[c0] + nSuppSizes[c1] <= 6 )
210 Vec_IntPush( vSupps, uSupps[c0] | uSupps[c1] );
212 uSuppTemp = uSupps[c0] | uSupps[c1];
213 for ( i = 0; i < nSuppVars; i++ )
214 if ( nSuppSizes[c0] + nSuppSizes[c1] + i < 6 )
215 uSuppTemp |= uSuppVars[i];
218 if ( Dss_WordCountOnes(uSuppTemp) <= 6 )
219 Vec_IntPush( vSupps, uSuppTemp );
221 for ( c2 = c1 + 1; c2 < nFanins; c2++ )
222 if ( nSuppSizes[c2] > 1 && nSuppSizes[c2] < 6 )
224 if ( nSuppSizes[c0] + nSuppSizes[c1] + nSuppSizes[c2] <= 6 )
225 Vec_IntPush( vSupps, uSupps[c0] | uSupps[c1] | uSupps[c2] );
226 assert( nSuppSizes[c0] + nSuppSizes[c1] + nSuppSizes[c2] >= 6 );
230 if ( nSuppVars > 1 && nSuppVars <= 6 )
233 for ( i = 0; i < nSuppVars; i++ )
234 uSuppTemp |= uSuppVars[i];
235 Vec_IntPush( vSupps, uSuppTemp );
237 else if ( nSuppVars > 6 && nSuppVars <= 12 )
240 for ( i = 0; i < 6; i++ )
241 uSuppTemp |= uSuppVars[i];
242 Vec_IntPush( vSupps, uSuppTemp );
245 for ( i = 6; i < nSuppVars; i++ )
246 uSuppTemp |= uSuppVars[i];
247 Vec_IntPush( vSupps, uSuppTemp );
253 uSupp |= Dss_ObjCheck666_rec(
p, pFanin, vSupps );
255 if ( Dss_WordCountOnes( uSupp ) <= 6 )
256 Vec_IntPush( vSupps, uSupp );
262 int i, k, SuppI, SuppK;
263 int nSupp = Dss_ObjSuppSize(Dss_Regular(
p->pRoot));
267 vSupps = Vec_IntAlloc( 100 );
268 Dss_ObjCheck666_rec(
p, Dss_Regular(
p->pRoot), vSupps );
269 Vec_IntUniqify( vSupps );
272 k = Dss_WordCountOnes(SuppI);
273 assert( k > 0 && k <= 6 );
289 if ( Dss_WordCountOnes(SuppI | SuppK) + 4 >= nSupp )
291 Vec_IntFree( vSupps );
295 Vec_IntFree( vSupps );
314void Dau_DsdCheckStructOne(
word * pTruth,
int nVars,
int nLeaves )
328 if ( pTruth == NULL )
330 Abc_PrintTime( 1,
"TT runtime", timeTt );
331 Abc_PrintTime( 1,
"DSD runtime", timeDsd );
332 Abc_PrintTime( 1,
"Total ", if_dec_time );
340 Abc_TtCopy( Truth, pTruth, Abc_TtWordNum(nVars), 0 );
348 clkDsd = Abc_Clock();
349 Status = Dss_ObjCheck666( pNtk );
350 timeDsd += Abc_Clock() - clkDsd;
357 #define CLU_VAR_MAX 16
375 word Func0, Func1, Func2;
380 G =
If_CluCheck3( NULL, pTruth, nLeaves, nLutLeaf, nLutLeaf2, nLutRoot, &R, &G2, &Func0, &Func1, &Func2 );
384 timeTt += Abc_Clock() - clkTt;
401static inline word ** Dss_ManTtElems()
404 if ( pTtElems[0] == NULL )
408 pTtElems[v] = TtElems[v];
429 Dss_ObjClean( pObj );
431 pObj->
nWords = Dss_ObjWordNum( nFans );
433 pObj->
Id = Vec_PtrSize(
p->vObjs );
435 Vec_PtrPush(
p->vObjs, pObj );
436 p->nMem += pObj->
nWords + (nTruthVars ? Abc_TtWordNum(nTruthVars) : 0);
447 pObj->
pFans[i] = Entry;
448 pObj->
nSupp += Dss_VecLitSuppSize(
p->vObjs, Entry);
462 p->vObjs = Vec_PtrAlloc( 100 );
464 for ( i = 0; i < nVars; i++ )
474 Vec_PtrFree(
p->vObjs );
480 char OpenType[7] = {0, 0, 0,
'(',
'[',
'<',
'{'};
481 char CloseType[7] = {0, 0, 0,
')',
']',
'>',
'}'};
484 assert( !Dss_IsComplement(pObj) );
486 { printf(
"%c",
'a' + pObj->
iVar );
return; }
488 Abc_TtPrintHexRev( stdout, Dss_ObjTruth(pObj), pObj->
nFans );
489 printf(
"%c", OpenType[pObj->
Type] );
492 printf(
"%s", Dss_ObjFaninC(pObj, i) ?
"!":
"" );
495 printf(
"%c", CloseType[pObj->
Type] );
500 printf(
"%d", Dss_IsComplement(
p->pRoot) );
503 printf(
"%s", Dss_IsComplement(
p->pRoot) ?
"!":
"" );
505 printf(
"%c",
'a' + Dss_Regular(
p->pRoot)->iVar );
523static inline void Dau_DsdMergeMatches(
char * pDsd,
int * pMatches )
527 for ( i = 0; pDsd[i]; i++ )
530 if ( pDsd[i] ==
'(' || pDsd[i] ==
'[' || pDsd[i] ==
'<' || pDsd[i] ==
'{' )
531 pNested[nNested++] = i;
532 else if ( pDsd[i] ==
')' || pDsd[i] ==
']' || pDsd[i] ==
'>' || pDsd[i] ==
'}' )
533 pMatches[pNested[--nNested]] = i;
546 while ( (**
p >=
'A' && **
p <=
'F') || (**
p >=
'0' && **
p <=
'9') )
556 if ( **
p >=
'a' && **
p <=
'z' )
557 return Abc_Var2Lit( Dss_ObjId(Dss_VecVar(pNtk->
vObjs, **
p -
'a')), fCompl );
558 if ( **
p ==
'(' || **
p ==
'[' || **
p ==
'<' || **
p ==
'{' )
561 Vec_Int_t * vFaninLits = Vec_IntAlloc( 10 );
562 char * q = pStr + pMatches[ *
p - pStr ];
566 else if ( **
p ==
'[' )
568 else if ( **
p ==
'<' )
570 else if ( **
p ==
'{' )
573 assert( *q == **
p + 1 + (**
p !=
'(') );
574 for ( (*
p)++; *
p < q; (*p)++ )
582 int i, uCanonPhase, nFanins = Vec_IntSize(vFaninLits);
583 Abc_TtCopy( pTemp, pTruth, Abc_TtWordNum(nFanins), 0 );
585 fCompl = (uCanonPhase >> nFanins) & 1;
586 vFaninLitsNew = Vec_IntAlloc( nFanins );
587 for ( i = 0; i < nFanins; i++ )
588 Vec_IntPush( vFaninLitsNew, Abc_LitNotCond(Vec_IntEntry(vFaninLits, pCanonPerm[i]), (uCanonPhase>>i)&1) );
590 Abc_TtCopy( Dss_ObjTruth(pObj), pTemp, Abc_TtWordNum(nFanins), 0 );
591 Vec_IntFree( vFaninLitsNew );
595 Vec_IntFree( vFaninLits );
596 return Abc_LitNotCond( Dss_Obj2Lit(pObj), fCompl );
607 if ( Dau_DsdIsConst(pDsd) )
609 else if ( Dau_DsdIsVar(pDsd) )
610 pNtk->
pRoot = Dss_VecVar(pNtk->
vObjs, Dau_DsdReadVar(pDsd));
614 Dau_DsdMergeMatches( pDsd, pMatches );
616 pNtk->
pRoot = Dss_Lit2Obj( pNtk->
vObjs, iLit );
640 if ( Dss_ObjType(p0) < Dss_ObjType(p1) )
642 if ( Dss_ObjType(p0) > Dss_ObjType(p1) )
646 if ( Dss_ObjFaninNum(p0) < Dss_ObjFaninNum(p1) )
648 if ( Dss_ObjFaninNum(p0) > Dss_ObjFaninNum(p1) )
650 for ( i = 0; i < Dss_ObjFaninNum(p0); i++ )
652 pChild0 = Dss_ObjChild(
p, p0, i );
653 pChild1 = Dss_ObjChild(
p, p1, i );
658 if ( Dss_IsComplement(p0i) < Dss_IsComplement(p1i) )
660 if ( Dss_IsComplement(p0i) > Dss_IsComplement(p1i) )
667 for ( i = 0; i < nNodes-1; i++ )
670 for ( j = i+1; j < nNodes; j++ )
677 ABC_SWAP(
int, pPerm[i], pPerm[best_i] );
701 assert( Dss_ObjFaninC(pObj, k) );
705 assert( !Dss_ObjFaninC(pObj, 0) );
712 int k, fCompl = Dss_IsComplement(pObj);
713 pObj = Dss_Regular( pObj );
716 pPermDsd[*pnPerms] = Abc_Var2Lit(pObj->
iVar, fCompl);
717 pObj->
iVar = (*pnPerms)++;
722 pObj->
pFans[k] = (
unsigned char)Abc_LitRegular((
int)pObj->
pFans[k]);
737 pChildren[k] = pChild;
738 Dss_ObjSort(
p->vObjs, pChildren, Dss_ObjFaninNum(pObj), NULL );
739 for ( k = 0; k < Dss_ObjFaninNum(pObj); k++ )
740 pObj->
pFans[k] = Dss_Obj2Lit( pChildren[k] );
744 p->pRoot = Dss_Regular(
p->pRoot);
745 assert( nPerms == (
int)Dss_Regular(
p->pRoot)->nSupp );
762 int nWords = Dss_ObjWordNum(nFans) + (nTruthVars ? Abc_TtWordNum(nTruthVars) : 0);
764 Dss_ObjClean( pObj );
767 pObj->
nWords = Dss_ObjWordNum(nFans);
768 pObj->
Id = Vec_PtrSize(
p->vObjs );
770 Vec_PtrPush(
p->vObjs, pObj );
771 Vec_IntPush(
p->vNexts, 0 );
776 Dss_Obj_t * pObj, * pFanin, * pPrev = NULL;
781 assert( Type !=
DAU_DSD_MUX || !Abc_LitIsCompl(Vec_IntEntry(vFaninLits, 1)) || !Abc_LitIsCompl(Vec_IntEntry(vFaninLits, 2)) );
794 Abc_TtCopy( Dss_ObjTruth(pObj), pTruth, Abc_TtWordNum(Vec_IntSize(vFaninLits)), 0 );
798 pObj->
pFans[i] = Entry;
799 pObj->
nSupp += Dss_VecLitSuppSize(
p->vObjs, Entry);
826 for ( i = 0; i <
p->nBins; i++ )
829 for ( pSpot =
p->pBins + i; *pSpot; pSpot = (
unsigned *)Vec_IntEntryP(
p->vNexts, pObj->
Id), Counter++ )
830 pObj = Dss_VecObj(
p->vObjs, *pSpot );
832 printf(
"%d ", Counter );
838 static int s_Primes[8] = { 1699, 4177, 5147, 5647, 6343, 7103, 7873, 8147 };
840 unsigned uHash = Type * 7873 + Vec_IntSize(vFaninLits) * 8147;
842 uHash += Entry * s_Primes[i & 0x7];
846 unsigned char * pTruthC = (
unsigned char *)pTruth;
847 int nBytes = Abc_TtByteNum(Vec_IntSize(vFaninLits));
848 for ( i = 0; i < nBytes; i++ )
849 uHash += pTruthC[i] * s_Primes[i & 0x7];
851 return uHash %
p->nBins;
856 unsigned * pSpot =
p->pBins + Dss_ObjHashKey(
p, Type, vFaninLits, pTruth);
857 for ( ; *pSpot; pSpot = (
unsigned *)Vec_IntEntryP(
p->vNexts, pObj->
Id) )
859 pObj = Dss_VecObj(
p->vObjs, *pSpot );
860 if ( (
int)pObj->
Type == Type &&
861 (
int)pObj->
nFans == Vec_IntSize(vFaninLits) &&
863 (pTruth == NULL || !
memcmp(Dss_ObjTruth(pObj), pTruth, (
size_t)Abc_TtByteNum(pObj->
nFans))) )
873 return Dss_VecObj(
p->vObjs, *pSpot );
874 *pSpot = Vec_PtrSize(
p->vObjs );
893 p->nCache = Abc_PrimeCudd( 100000 );
898 if (
p->pCache == NULL )
906 static int s_Primes[8] = { 1699, 4177, 5147, 5647, 6343, 7103, 7873, 8147 };
909 for ( i = 0; i < 2*(int)pEnt->
nShared; i++ )
910 uHash += pEnt->
pShared[i] * s_Primes[i & 0x7];
911 return uHash %
p->nCache;
917 for ( i = 0; i <
p->nCache; i++ )
920 for ( pSpot =
p->pCache + i; *pSpot; pSpot = &(*pSpot)->
pNext, Counter++ )
923 printf(
"%d ", Counter );
929 Dss_Ent_t ** pSpot =
p->pCache + Dss_ManCacheHashKey(
p, pEnt );
930 for ( ; *pSpot; pSpot = &(*pSpot)->
pNext )
932 if ( (*pSpot)->iDsd0 == pEnt->
iDsd0 &&
933 (*pSpot)->iDsd1 == pEnt->
iDsd1 &&
934 (*pSpot)->nShared == pEnt->
nShared &&
941 p->nCacheMisses[pEnt->
nShared!=0]++;
949 memcpy( pFun, pFun0,
sizeof(
word) * Dss_FunWordNum(pFun0) );
952 p->nCacheEntries[pEnt->
nShared!=0]++;
972 p->nNonDecLimit = nNonDecLimit;
973 p->nBins = Abc_PrimeCudd( 1000000 );
976 p->vObjs = Vec_PtrAlloc( 10000 );
977 p->vNexts = Vec_IntAlloc( 10000 );
980 p->vLeaves = Vec_IntAlloc( 32 );
981 p->vCopies = Vec_IntAlloc( 32 );
982 p->pTtElems = Dss_ManTtElems();
989 Abc_PrintTime( 1,
"Time begin ",
p->timeBeg );
990 Abc_PrintTime( 1,
"Time decomp",
p->timeDec );
991 Abc_PrintTime( 1,
"Time lookup",
p->timeLook );
992 Abc_PrintTime( 1,
"Time end ",
p->timeEnd );
997 Vec_IntFreeP( &
p->vCopies );
998 Vec_IntFreeP( &
p->vLeaves );
999 Vec_IntFreeP( &
p->vNexts );
1000 Vec_PtrFreeP( &
p->vObjs );
1007 char OpenType[7] = {0, 0, 0,
'(',
'[',
'<',
'{'};
1008 char CloseType[7] = {0, 0, 0,
')',
']',
'>',
'}'};
1011 assert( !Dss_IsComplement(pObj) );
1013 { fprintf( pFile,
"0" );
return; }
1016 int iPermLit = pPermLits ? pPermLits[(*pnSupp)++] : Abc_Var2Lit((*pnSupp)++, 0);
1017 fprintf( pFile,
"%s%c", Abc_LitIsCompl(iPermLit)?
"!":
"",
'a' + Abc_Lit2Var(iPermLit) );
1021 Abc_TtPrintHexRev( pFile, Dss_ObjTruth(pObj), pObj->
nFans );
1022 fprintf( pFile,
"%c", OpenType[pObj->
Type] );
1025 fprintf( pFile,
"%s", Dss_ObjFaninC(pObj, i) ?
"!":
"" );
1028 fprintf( pFile,
"%c", CloseType[pObj->
Type] );
1033 fprintf( pFile,
"%6d : ", Abc_Lit2Var(iDsdLit) );
1034 fprintf( pFile,
"%2d ", Dss_VecLitSuppSize(
p->vObjs, iDsdLit) );
1035 fprintf( pFile,
"%s", Abc_LitIsCompl(iDsdLit) ?
"!" :
"" );
1036 Dss_ManPrint_rec( pFile,
p, Dss_VecObj(
p->vObjs, Abc_Lit2Var(iDsdLit)), pPermLits, &nSupp );
1037 fprintf( pFile,
"\n" );
1038 assert( nSupp == (
int)Dss_VecObj(
p->vObjs, Abc_Lit2Var(iDsdLit))->nSupp );
1044 assert( !Dss_IsComplement(pObj) );
1058 char * pFileName =
"dss_tts.txt";
1063 pFile = fopen( pFileName,
"wb" );
1064 if ( pFile == NULL )
1066 printf(
"Cannot open file \"%s\".\n", pFileName );
1073 Abc_TtCopy( Temp, Dss_ObjTruth(pObj), Abc_TtWordNum(pObj->
nFans), 0 );
1074 Abc_TtStretch6( Temp, pObj->
nFans,
p->nVars );
1075 fprintf( pFile,
"0x" );
1076 Abc_TtPrintHexRev( pFile, Temp,
p->nVars );
1077 fprintf( pFile,
"\n" );
1089 int CountNonDsd = 0, CountNonDsdStr = 0;
1090 int i, clk = Abc_Clock();
1092 pFile = pFileName ? fopen( pFileName,
"wb" ) : stdout;
1093 if ( pFileName && pFile == NULL )
1095 printf(
"cannot open output file\n" );
1103 fprintf( pFile,
"Total number of objects = %8d\n", Vec_PtrSize(
p->vObjs) );
1104 fprintf( pFile,
"Non-DSD objects (max =%2d) = %8d\n",
p->nNonDecLimit, CountNonDsd );
1105 fprintf( pFile,
"Non-DSD structures = %8d\n", CountNonDsdStr );
1106 fprintf( pFile,
"Memory used for objects = %6.2f MB.\n", 1.0*
Mem_FlexReadMemUsage(
p->pMem)/(1<<20) );
1107 fprintf( pFile,
"Memory used for array = %6.2f MB.\n", 1.0*
sizeof(
void *)*Vec_PtrCap(
p->vObjs)/(1<<20) );
1108 fprintf( pFile,
"Memory used for hash table = %6.2f MB.\n", 1.0*
sizeof(
int)*
p->nBins/(1<<20) );
1109 fprintf( pFile,
"Memory used for cache = %6.2f MB.\n", 1.0*
Mem_FlexReadMemUsage(
p->pMemEnts)/(1<<20) );
1110 fprintf( pFile,
"Cache hits = %8d %8d\n",
p->nCacheHits[0],
p->nCacheHits[1] );
1111 fprintf( pFile,
"Cache misses = %8d %8d\n",
p->nCacheMisses[0],
p->nCacheMisses[1] );
1112 fprintf( pFile,
"Cache entries = %8d %8d\n",
p->nCacheEntries[0],
p->nCacheEntries[1] );
1113 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
1123 fprintf( pFile,
"\n" );
1142 int nWords = Abc_TtWordNum(nVars);
1143 int i, fCompl = Dss_IsComplement(pObj);
1144 pObj = Dss_Regular(pObj);
1147 int iPermLit = pPermLits[(*pnSupp)++];
1148 assert( (*pnSupp) <= nVars );
1149 Abc_TtCopy( pRes,
p->pTtElems[Abc_Lit2Var(iPermLit)],
nWords, fCompl ^ Abc_LitIsCompl(iPermLit) );
1156 Abc_TtConst1( pRes,
nWords );
1158 Abc_TtConst0( pRes,
nWords );
1163 Abc_TtAnd( pRes, pRes, pTtTemp,
nWords, 0 );
1165 Abc_TtXor( pRes, pRes, pTtTemp,
nWords, 0 );
1167 if ( fCompl ) Abc_TtNot( pRes,
nWords );
1176 Abc_TtMux( pRes, pTtTemp[0], pTtTemp[1], pTtTemp[2],
nWords );
1177 if ( fCompl ) Abc_TtNot( pRes,
nWords );
1186 if ( fCompl ) Abc_TtNot( pRes,
nWords );
1194 Dss_Obj_t * pObj = Dss_Lit2Obj(
p->vObjs, iDsd);
1196 int nWords = Abc_TtWordNum( nVars );
1200 Abc_TtConst0( pRes,
nWords );
1201 else if ( iDsd == 1 )
1202 Abc_TtConst1( pRes,
nWords );
1203 else if ( Dss_Regular(pObj)->Type ==
DAU_DSD_VAR )
1205 int iPermLit = pPermLits[nSupp++];
1206 Abc_TtCopy( pRes,
p->pTtElems[Abc_Lit2Var(iPermLit)],
nWords, Abc_LitIsCompl(iDsd) ^ Abc_LitIsCompl(iPermLit) );
1210 assert( nSupp == (
int)Dss_Regular(pObj)->nSupp );
1231 int i, k, fCompl = Dss_IsComplement(pObj);
1232 pObj = Dss_Regular(pObj);
1234 return Abc_Var2Lit( 1, fCompl );
1239 pChildren[k] = Dss_Not(pChildren[k]), fCompl ^= 1;
1244 if ( Dss_IsComplement(pChildren[0]) )
1246 pChildren[0] = Dss_Not(pChildren[0]);
1249 if ( Dss_IsComplement(pChildren[1]) )
1251 pChildren[1] = Dss_Not(pChildren[1]);
1252 pChildren[2] = Dss_Not(pChildren[2]);
1257 Vec_IntClear(
p->vLeaves );
1258 for ( i = 0; i < k; i++ )
1259 Vec_IntPush(
p->vLeaves, Dss_Obj2Lit(pChildren[i]) );
1262 return Abc_Var2Lit( pObjNew->
Id, fCompl );
1268 return Dss_IsComplement(pNtk->
pRoot);
1270 return Abc_Var2Lit( Dss_Regular(pNtk->
pRoot)->iVar + 1, Dss_IsComplement(pNtk->
pRoot) );
1291 int i, k, nChildren = 0, fCompl = 0, fComplFan;
1298 for ( k = 0; k < nLits; k++ )
1300 pObj = Dss_Lit2Obj(
p->vObjs, pLits[k]);
1303 fComplFan = (Dss_Regular(pObj)->Type ==
DAU_DSD_VAR && Dss_IsComplement(pObj));
1305 pObj = Dss_Regular(pObj);
1306 pBegEnd[nChildren] = (nSSize << 16) | (fComplFan << 8) | (nSSize + Dss_Regular(pObj)->nSupp);
1307 nSSize += Dss_Regular(pObj)->nSupp;
1308 pChildren[nChildren++] = pObj;
1313 fComplFan = (Dss_Regular(pChild)->Type ==
DAU_DSD_VAR && Dss_IsComplement(pChild));
1315 pChild = Dss_Regular(pChild);
1316 pBegEnd[nChildren] = (nSSize << 16) | (fComplFan << 8) | (nSSize + Dss_Regular(pChild)->nSupp);
1317 nSSize += Dss_Regular(pChild)->nSupp;
1318 pChildren[nChildren++] = pChild;
1321 Dss_ObjSort(
p->vObjs, pChildren, nChildren, pBegEnd );
1323 for ( j = i = 0; i < nChildren; i++ )
1324 for ( k = (pBegEnd[i] >> 16); k < (pBegEnd[i] & 0xFF); k++ )
1325 pPerm[j++] = (
unsigned char)Abc_Var2Lit( k, (pBegEnd[i] >> 8) & 1 );
1330 for ( k = 0; k < nLits; k++ )
1332 pObj = Dss_Lit2Obj(
p->vObjs, pLits[k]);
1334 pChildren[nChildren++] = pObj;
1337 pChildren[nChildren++] = pChild;
1343 for ( k = 0; k < nLits; k++ )
1345 fCompl ^= Abc_LitIsCompl(pLits[k]);
1346 pObj = Dss_Lit2Obj(
p->vObjs, Abc_LitRegular(pLits[k]));
1348 pChildren[nChildren++] = pObj;
1352 assert( !Dss_IsComplement(pChild) );
1353 pChildren[nChildren++] = pChild;
1360 if ( Abc_LitIsCompl(pLits[0]) )
1362 pLits[0] = Abc_LitNot(pLits[0]);
1363 ABC_SWAP(
int, pLits[1], pLits[2] );
1365 if ( Abc_LitIsCompl(pLits[1]) )
1367 pLits[1] = Abc_LitNot(pLits[1]);
1368 pLits[2] = Abc_LitNot(pLits[2]);
1371 for ( k = 0; k < nLits; k++ )
1372 pChildren[nChildren++] = Dss_Lit2Obj(
p->vObjs, pLits[k]);
1376 for ( k = 0; k < nLits; k++ )
1377 pChildren[nChildren++] = Dss_Lit2Obj(
p->vObjs, pLits[k]);
1382 Vec_IntClear(
p->vLeaves );
1383 for ( i = 0; i < nChildren; i++ )
1384 Vec_IntPush(
p->vLeaves, Dss_Obj2Lit(pChildren[i]) );
1387 return Abc_Var2Lit( pObj->
Id, fCompl );
1391 static char Buffer[100];
1395 pFun->nFans = nFansTot;
1396 assert( (
int)pFun->nFans == Dss_VecLitSuppSize(
p->vObjs, pFun->iDsd) );
1414 printf(
"%d %d ",
p->iDsd0,
p->iDsd1 );
1415 for ( i = 0; i < (int)
p->nShared; i++ )
1416 printf(
"%d=%d ",
p->pShared[2*i],
p->pShared[2*i+1] );
1417 printf(
"-> %d ", pFun->iDsd );
1435 static char Buffer[100];
1443 int i, nNonDec, nSuppSize = 0;
1445 nFans[0] = Dss_VecLitSuppSize(
p->vObjs, pEnt->
iDsd0 );
1446 nFans[1] = Dss_VecLitSuppSize(
p->vObjs, pEnt->
iDsd1 );
1448 for ( i = 0; i < nFans[0]; i++ )
1450 pMapDsd2Truth[nSuppSize] = i;
1451 pPermLits[i] = Abc_Var2Lit( nSuppSize++, 0 );
1454 Abc_TtCopy( pTruth, pTruthOne, Abc_TtWordNum(
p->nVars), 0 );
1460 for ( i = 0; i < nFans[1]; i++ )
1462 for ( i = 0; i < (int)pEnt->
nShared; i++ )
1464 for ( i = 0; i < nFans[1]; i++ )
1465 if ( pPermLits[i] == -1 )
1467 pMapDsd2Truth[nSuppSize] = nFans[0] + i;
1468 pPermLits[i] = Abc_Var2Lit( nSuppSize++, 0 );
1475 Abc_TtAnd( pTruth, pTruth, pTruthOne, Abc_TtWordNum(
p->nVars), 0 );
1478 if (
p->nNonDecLimit && nNonDec >
p->nNonDecLimit )
1490 pFun->nFans = Dss_VecLitSuppSize(
p->vObjs, pFun->iDsd );
1491 for ( i = 0; i < (int)pFun->nFans; i++ )
1492 pFun->pFans[i] = (
unsigned char)Abc_Lit2LitV( pMapDsd2Truth, pPermDsd[i] );
1512 static char Buffer[100];
1514 pEnt->
iDsd0 = iDsd[0];
1515 pEnt->
iDsd1 = iDsd[1];
1520 for ( i = 0; i < nFans[0]; i++ )
1521 pMapGtoL[ Abc_Lit2Var(pFans[0][i]) ] = Abc_Var2Lit( i, Abc_LitIsCompl(pFans[0][i]) );
1522 for ( i = 0; i < nFans[1]; i++ )
1524 g = Abc_Lit2Var( pFans[1][i] );
1525 if ( (uSharedMask >> g) & 1 )
1527 assert( pMapGtoL[g] >= 0 );
1529 pEnt->
pShared[2*pEnt->
nShared+1] = (
unsigned char)Abc_LitNotCond( pMapGtoL[g], Abc_LitIsCompl(pFans[1][i]) );
1534 pEnt->
nWords = Dss_EntWordNum( pEnt );
1539int Dss_ManMerge(
Dss_Man_t *
p,
int * iDsd,
int * nFans,
int ** pFans,
unsigned uSharedMask,
int nKLutSize,
unsigned char * pPermRes,
word * pTruth )
1543 static int Counter = 0;
1554 printf(
"Parameter DAU_MAX_VAR (%d) smaller than LUT size (%d).\n",
DAU_MAX_VAR, nKLutSize );
1557 assert( iDsd[0] <= iDsd[1] );
1566 if ( iDsd[0] == 0 )
return 0;
1567 if ( iDsd[0] == 1 )
return iDsd[1];
1568 if ( iDsd[1] == 0 )
return 0;
1569 if ( iDsd[1] == 1 )
return iDsd[0];
1573 assert( nFans[0] == Dss_VecLitSuppSize(
p->vObjs, iDsd[0]) );
1574 assert( nFans[1] == Dss_VecLitSuppSize(
p->vObjs, iDsd[1]) );
1575 assert( nFans[0] + nFans[1] <= nKLutSize + Dss_WordCountOnes(uSharedMask) );
1578p->timeBeg += Abc_Clock() - clk;
1580 if (
p->pCache == NULL )
1583 if ( uSharedMask == 0 )
1589 assert( (
int)pFun->nFans == Dss_VecLitSuppSize(
p->vObjs, pFun->iDsd) );
1590 assert( (
int)pFun->nFans <= nKLutSize );
1591p->timeDec += Abc_Clock() - clk;
1597p->timeLook += Abc_Clock() - clk;
1599 if ( *ppSpot == NULL )
1601 if ( uSharedMask == 0 )
1607 assert( (
int)pFun->nFans == Dss_VecLitSuppSize(
p->vObjs, pFun->iDsd) );
1608 assert( (
int)pFun->nFans <= nKLutSize );
1612 pFun = (*ppSpot)->pFunc;
1613p->timeDec += Abc_Clock() - clk;
1617 for ( i = 0; i < (int)pFun->nFans; i++ )
1618 if ( pFun->pFans[i] < 2 * nFans[0] )
1619 pPermRes[i] = (
unsigned char)Dss_Lit2Lit( pFans[0], pFun->pFans[i] );
1621 pPermRes[i] = (
unsigned char)Dss_Lit2Lit( pFans[1], pFun->pFans[i] - 2 * nFans[0] );
1623 if ( uSharedMask && pFun->nFans > 1 )
1627 for ( i = 0; i <
p->nVars; i++ )
1629 for ( i = 0; i < (int)pFun->nFans; i++ )
1630 pVarPres[ Abc_Lit2Var(pPermRes[i]) ] = i;
1631 for ( i = 0; i <
p->nVars; i++ )
1632 if ( pVarPres[i] >= 0 )
1633 pPermRes[pVarPres[i]] = Abc_Var2Lit( nSupp++, Abc_LitIsCompl(pPermRes[pVarPres[i]]) );
1634 assert( nSupp == (
int)pFun->nFans );
1637 for ( i = 0; i < (int)pFun->nFans; i++ )
1638 pPermResInt[i] = pPermRes[i];
1639p->timeEnd += Abc_Clock() - clk;
1647if ( Counter == 43418 )
1657 if ( !Abc_TtEqual( pTruthOne, pTruth, Abc_TtWordNum(
p->nVars) ) )
1662 printf(
"Verification failed.\n" );
1683 static char Buffer[100];
1685 pEnt->
iDsd0 = iDsd0;
1686 pEnt->
iDsd1 = iDsd1;
1687 pEnt->
nShared = Vec_StrSize(vShared)/2;
1688 memcpy( pEnt->
pShared, (
unsigned char *)Vec_StrArray(vShared),
sizeof(
char) * Vec_StrSize(vShared) );
1689 pEnt->
nWords = Dss_EntWordNum( pEnt );
1699 int iDsd[2] = { iDsd0, iDsd1 };
1703 assert( iDsd0 <= iDsd1 );
1706 printf(
"Parameter DAU_MAX_VAR (%d) smaller than LUT size (%d).\n",
DAU_MAX_VAR, *pnLeaves );
1718p->timeLook += Abc_Clock() - clk;
1721 if ( *ppSpot == NULL )
1723 if ( Vec_StrSize(vShared) == 0 )
1729 assert( (
int)pFun->nFans == Dss_VecLitSuppSize(
p->vObjs, pFun->iDsd) );
1730 assert( (
int)pFun->nFans <= *pnLeaves );
1734 pFun = (*ppSpot)->pFunc;
1735p->timeDec += Abc_Clock() - clk;
1737 *pnLeaves = (int)pFun->nFans;
1738 for ( i = 0; i < (int)pFun->nFans; i++ )
1739 pPerm[i] = (
int)pFun->pFans[i];
1793 pFanin = Dss_ObjFanin(
p->vObjs, pObj, 1 );
1796 pFanin = Dss_ObjFanin(
p->vObjs, pObj, 2 );
1820 char * pDsd =
"(!(a!(bh))[cde]!(fg))";
1853 vFuncs = Vec_VecStart( nVars+1 );
1858 Vec_VecPushInt( vFuncs, 1, Dss_Obj2Lit(Dss_VecVar(
p->vObjs,0)) );
1861 for ( s = 2; s <= nVars; s++ )
1863 vRes = Vec_VecEntryInt( vFuncs, s );
1864 for ( i = 1; i < s; i++ )
1865 for ( k = i; k < s; k++ )
1868 vOne = Vec_VecEntryInt( vFuncs, i );
1869 vTwo = Vec_VecEntryInt( vFuncs, k );
1877 assert( !Abc_LitIsCompl(iLit) );
1878 Vec_IntPush( vRes, iLit );
1882 pEntries[0] = Abc_LitNot( pEntries[0] );
1884 pEntries[0] = Abc_LitNot( pEntries[0] );
1885 assert( !Abc_LitIsCompl(iLit) );
1886 Vec_IntPush( vRes, iLit );
1891 pEntries[1] = Abc_LitNot( pEntries[1] );
1893 pEntries[1] = Abc_LitNot( pEntries[1] );
1894 assert( !Abc_LitIsCompl(iLit) );
1895 Vec_IntPush( vRes, iLit );
1898 if ( fAddInv0 && fAddInv1 )
1900 pEntries[0] = Abc_LitNot( pEntries[0] );
1901 pEntries[1] = Abc_LitNot( pEntries[1] );
1903 pEntries[0] = Abc_LitNot( pEntries[0] );
1904 pEntries[1] = Abc_LitNot( pEntries[1] );
1905 assert( !Abc_LitIsCompl(iLit) );
1906 Vec_IntPush( vRes, iLit );
1910 assert( !Abc_LitIsCompl(iLit) );
1911 Vec_IntPush( vRes, Abc_LitRegular(iLit) );
1958 Vec_IntUniqify( vRes );
1963 Vec_VecFree( vFuncs );
1981 int iLit1[3] = { 2, 4 };
1982 int iLit2[3] = { 2, 4, 6 };
1984 int nFans[2] = { 4, 3 };
1985 int pPermLits1[4] = { 0, 2, 5, 6 };
1986 int pPermLits2[5] = { 2, 9, 10 };
1987 int * pPermLits[2] = { pPermLits1, pPermLits2 };
1988 unsigned char pPermRes[6];
1990 unsigned uMaskShared = 2;
2005 iRes[4] =
Dss_ManMerge(
p, iRes+2, nFans, pPermLits, uMaskShared, 6, pPermRes, NULL );
2007 for ( i = 0; i < 6; i++ )
2008 pPermResInt[i] = pPermRes[i];
#define ABC_SWAP(Type, a, b)
#define ABC_ALLOC(type, num)
#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
void Dss_NtkPrint_rec(Dss_Ntk_t *p, Dss_Obj_t *pObj)
int Dss_ManCheckNonDec_rec(Dss_Man_t *p, Dss_Obj_t *pObj)
int Dss_ManMerge(Dss_Man_t *p, int *iDsd, int *nFans, int **pFans, unsigned uSharedMask, int nKLutSize, unsigned char *pPermRes, word *pTruth)
void Dss_ManPrint(char *pFileName, Dss_Man_t *p)
Dss_Ntk_t * Dss_NtkAlloc(int nVars)
void Dss_ObjSort(Vec_Ptr_t *p, Dss_Obj_t **pNodes, int nNodes, int *pPerm)
void Dss_ManHashProfile(Dss_Man_t *p)
Dss_Ntk_t * Dss_NtkCreate(char *pDsd, int nVars, word *pTruth)
struct Dss_Ntk_t_ Dss_Ntk_t
Dss_Obj_t * Dss_ObjAlloc(Dss_Man_t *p, int Type, int nFans, int nTruthVars)
Dss_Ent_t * Dss_ManSharedMapDerive(Dss_Man_t *p, int iDsd0, int iDsd1, Vec_Str_t *vShared)
#define Dss_VecForEachObjVec(vLits, vVec, pObj, i)
Dss_Obj_t * Dss_ObjAllocNtk(Dss_Ntk_t *p, int Type, int nFans, int nTruthVars)
Dss_Ent_t * Dss_ManSharedMap(Dss_Man_t *p, int *iDsd, int *nFans, int **pFans, unsigned uSharedMask)
int Dss_NtkRebuild_rec(Dss_Man_t *p, Dss_Ntk_t *pNtk, Dss_Obj_t *pObj)
#define Dss_ObjForEachChild(vVec, pObj, pFanin, i)
unsigned * Dss_ObjHashLookup(Dss_Man_t *p, int Type, Vec_Int_t *vFaninLits, word *pTruth)
void Dss_ManCacheAlloc(Dss_Man_t *p)
int Dss_ObjCheckTransparent(Dss_Man_t *p, Dss_Obj_t *pObj)
void Dss_NtkPrint(Dss_Ntk_t *p)
void Dss_ManCacheProfile(Dss_Man_t *p)
Dss_Obj_t * Dss_ObjFindOrAdd(Dss_Man_t *p, int Type, Vec_Int_t *vFaninLits, word *pTruth)
Dss_Man_t * Dss_ManAlloc(int nVars, int nNonDecLimit)
int Mpm_FuncCompute(Dss_Man_t *p, int iDsd0, int iDsd1, Vec_Str_t *vShared, int *pPerm, int *pnLeaves)
Dss_Ent_t ** Dss_ManCacheLookup(Dss_Man_t *p, Dss_Ent_t *pEnt)
int Dss_NtkRebuild(Dss_Man_t *p, Dss_Ntk_t *pNtk)
void Dss_NtkFree(Dss_Ntk_t *p)
void Dss_ManPrint_rec(FILE *pFile, Dss_Man_t *p, Dss_Obj_t *pObj, int *pPermLits, int *pnSupp)
void Dss_ManComputeTruth_rec(Dss_Man_t *p, Dss_Obj_t *pObj, int nVars, word *pRes, int *pPermLits, int *pnSupp)
void Dss_ManCacheFree(Dss_Man_t *p)
void Dss_NtkTransform(Dss_Ntk_t *p, int *pPermDsd)
struct Dss_Ent_t_ Dss_Ent_t
int Dss_NtkCollectPerm_rec(Dss_Ntk_t *p, Dss_Obj_t *pObj, int *pPermDsd, int *pnPerms)
int Dss_ManOperation(Dss_Man_t *p, int Type, int *pLits, int nLits, unsigned char *pPerm, word *pTruth)
#define Dss_VecForEachObj(vVec, pObj, i)
void Dss_ManFree(Dss_Man_t *p)
Dss_Fun_t * Dss_ManBooleanAnd(Dss_Man_t *p, Dss_Ent_t *pEnt, int Counter)
void Dss_NtkCheck(Dss_Ntk_t *p)
int Dss_NtkCreate_rec(char *pStr, char **p, int *pMatches, Dss_Ntk_t *pNtk, word *pTruth)
typedefABC_NAMESPACE_IMPL_START struct Dss_Fun_t_ Dss_Fun_t
DECLARATIONS ///.
Dss_Fun_t * Dss_ManOperationFun(Dss_Man_t *p, int *iDsd, int nFansTot)
Dss_Ent_t * Dss_ManCacheCreate(Dss_Man_t *p, Dss_Ent_t *pEnt0, Dss_Fun_t *pFun0)
struct Dss_Obj_t_ Dss_Obj_t
#define Dss_ObjForEachFanin(vVec, pObj, pFanin, i)
int Dss_ObjCompare(Vec_Ptr_t *p, Dss_Obj_t *p0i, Dss_Obj_t *p1i)
#define Dss_VecForEachNode(vVec, pObj, i)
Dss_Obj_t * Dss_ObjCreateNtk(Dss_Ntk_t *p, int Type, Vec_Int_t *vFaninLits)
word * Dss_ManComputeTruth(Dss_Man_t *p, int iDsd, int nVars, int *pPermLits)
void Dss_EntPrint(Dss_Ent_t *p, Dss_Fun_t *pFun)
void Dss_ManDump(Dss_Man_t *p)
Dss_Obj_t * Dss_ObjCreate(Dss_Man_t *p, int Type, Vec_Int_t *vFaninLits, word *pTruth)
void Dss_ManPrintOne(FILE *pFile, Dss_Man_t *p, int iDsdLit, int *pPermLits)
int Dau_DsdDecompose(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
void Dau_DsdTruthCompose_rec(word *pFunc, word pFanins[DAU_MAX_VAR][DAU_MAX_WORD], word *pRes, int nVars, int nWordsR)
struct Dss_Man_t_ Dss_Man_t
#define DAU_MAX_VAR
INCLUDES ///.
unsigned Abc_TtCanonicize(word *pTruth, int nVars, char *pCanonPerm)
FUNCTION DECLARATIONS ///.
struct If_Grp_t_ If_Grp_t
DECLARATIONS ///.
If_Grp_t If_CluCheck3(If_Man_t *p, word *pTruth0, int nVars, int nLutLeaf, int nLutLeaf2, int nLutRoot, If_Grp_t *pR, If_Grp_t *pG2, word *pFunc0, word *pFunc1, word *pFunc2)
unsigned __int64 word
DECLARATIONS ///.
Mem_Flex_t * Mem_FlexStart()
char * Mem_FlexEntryFetch(Mem_Flex_t *p, int nBytes)
int Mem_FlexReadMemUsage(Mem_Flex_t *p)
void Mem_FlexStop(Mem_Flex_t *p, int fVerbose)
struct Mem_Flex_t_ Mem_Flex_t
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.