56static inline word ** Dau_DsdTtElems()
59 if ( pTtElems[0] == NULL )
63 pTtElems[v] = TtElems[v];
85 for ( v = 0;
p[v]; v++ )
88 if (
p[v] ==
'(' ||
p[v] ==
'[' ||
p[v] ==
'<' ||
p[v] ==
'{' )
89 pNested[nNested++] = v;
90 else if (
p[v] ==
')' ||
p[v] ==
']' ||
p[v] ==
'>' ||
p[v] ==
'}' )
91 pMatches[pNested[--nNested]] = v;
114 if ( *pDsd >=
'a' && *pDsd <=
'z' )
115 vMax = Abc_MaxInt( vMax, *pDsd -
'a' );
121 for ( v = 0; v < nVars; v++ )
123 for ( v = 0; v < nVars; v++ )
125 vNew = rand() % nVars;
126 ABC_SWAP(
int, pPerm[v], pPerm[vNew] );
136 if ( *pDsd >=
'a' && *pDsd <
'a' + nVars )
137 *pDsd =
'a' + pPerm[*pDsd -
'a'];
154 for ( s = pMarks[i]; s < pMarks[i+1]; s++ )
160 char * pStr1 = pStr + pMarks[i];
161 char * pStr2 = pStr + pMarks[j];
162 char * pLimit1 = pStr + pMarks[i+1];
163 char * pLimit2 = pStr + pMarks[j+1];
164 for ( ; pStr1 < pLimit1 && pStr2 < pLimit2; pStr1++, pStr2++ )
166 if ( !(*pStr1 >=
'a' && *pStr1 <=
'z') )
171 if ( !(*pStr2 >=
'a' && *pStr2 <=
'z') )
176 if ( *pStr1 < *pStr2 )
178 if ( *pStr1 > *pStr2 )
181 assert( pStr1 < pLimit1 || pStr2 < pLimit2 );
182 if ( pStr1 == pLimit1 )
184 if ( pStr2 == pLimit2 )
193 for ( i = 0; i < nMarks; i++ )
195 for ( i = 0; i < nMarks; i++ )
198 for ( k = i + 1; k < nMarks; k++ )
201 ABC_SWAP(
int, pPerm[i], pPerm[iBest] );
210 while ( (**
p >=
'A' && **
p <=
'F') || (**
p >=
'0' && **
p <=
'9') )
214 char * q = pStr + pMatches[*
p - pStr];
218 if ( **
p >=
'a' && **
p <=
'z' )
220 if ( **
p ==
'(' || **
p ==
'[' )
222 char * pStore, * pOld = *
p + 1;
223 char * q = pStr + pMatches[ *
p - pStr ];
225 assert( *q == **
p + 1 + (**
p !=
'(') );
226 for ( (*
p)++; *
p < q; (*p)++ )
228 pMarks[nMarks++] = *
p - pStr;
231 pMarks[nMarks] = *
p - pStr;
237 for ( i = 0; i < nMarks; i++ )
239 assert( pStore - pBuffer == *
p - pOld );
240 memcpy( pOld, pBuffer, (
size_t)(pStore - pBuffer) );
243 if ( **
p ==
'<' || **
p ==
'{' )
245 char * q = pStr + pMatches[ *
p - pStr ];
246 assert( *q == **
p + 1 + (**
p !=
'(') );
247 if ( (**
p ==
'<') && (*(q+1) ==
'{') )
253 for ( (*
p)++; *
p < q; (*p)++ )
283 while ( (**
p >=
'A' && **
p <=
'F') || (**
p >=
'0' && **
p <=
'9') )
287 char * q = pStr + pMatches[*
p - pStr];
291 if ( **
p >=
'a' && **
p <=
'z' )
293 if ( **
p ==
'(' || **
p ==
'[' )
295 int Counter = 0, AddOn = (**
p ==
'(')? 1 : 3;
296 char * q = pStr + pMatches[ *
p - pStr ];
297 assert( *q == **
p + 1 + (**
p !=
'(') );
298 for ( (*
p)++; *
p < q; (*p)++ )
301 return Counter - AddOn;
303 if ( **
p ==
'<' || **
p ==
'{' )
306 char * q = pStr + pMatches[ *
p - pStr ];
307 assert( *q == **
p + 1 + (**
p !=
'(') );
308 for ( (*
p)++; *
p < q; (*p)++ )
339 if ( Func == ~(
word)0 )
344 assert( Func == s_Truths6[0] || Func == s_Truths6Neg[0] );
345 return (Func == s_Truths6[0]) ? pFanins[0] : ~pFanins[0];
347 if ( !Abc_Tt6HasVar(Func, nVars) )
351 return (~pFanins[nVars] & t0) | (pFanins[nVars] & t1);
358 if ( **
p >=
'a' && **
p <=
'f' )
360 assert( **
p -
'a' >= 0 && **
p -
'a' < 6 );
361 return fCompl ? ~pTruths[**
p -
'a'] : pTruths[**
p -
'a'];
365 char * q = pStr + pMatches[ *
p - pStr ];
367 assert( **
p ==
'(' && *q ==
')' );
368 for ( (*
p)++; *
p < q; (*p)++ )
371 return fCompl ? ~Res : Res;
375 char * q = pStr + pMatches[ *
p - pStr ];
377 assert( **
p ==
'[' && *q ==
']' );
378 for ( (*
p)++; *
p < q; (*p)++ )
381 return fCompl ? ~Res : Res;
386 word Temp[3], * pTemp = Temp, Res;
387 word Fanins[6], * pTruths2;
389 char * q = pStr + pMatches[ *
p - pStr ];
395 q2 = pStr + pMatches[ *
p - pStr ];
396 assert( **
p ==
'{' && *q2 ==
'}' );
397 for ( nVars = 0, (*
p)++; *
p < q2; (*p)++, nVars++ )
406 q = pStr + pMatches[ *
p - pStr ];
407 assert( **
p ==
'<' && *q ==
'>' );
410 for ( ; pOld < q; pOld++ )
411 if ( *pOld >=
'a' && *pOld <=
'z' )
412 assert( *pOld -
'a' < nVars );
414 for ( (*
p)++; *
p < q; (*p)++ )
416 assert( pTemp == Temp + 3 );
420 char * q = pStr + pMatches[ ++(*p) - pStr ];
421 assert( **
p ==
'{' && *q ==
'}' );
424 Res = (Temp[0] & Temp[1]) | (~Temp[0] & Temp[2]);
425 return fCompl ? ~Res : Res;
427 if ( (**
p >=
'A' && **
p <=
'F') || (**
p >=
'0' && **
p <=
'9') )
429 word Func, Fanins[6], Res;
431 int i, nVars = Abc_TtReadHex( &Func, *
p );
432 *
p += Abc_TtHexDigitNum( nVars );
433 q = pStr + pMatches[ *
p - pStr ];
434 assert( **
p ==
'{' && *q ==
'}' );
435 for ( i = 0, (*
p)++; *
p < q; (*p)++, i++ )
440 return fCompl ? ~Res : Res;
448 if ( *
p ==
'0' && *(
p+1) == 0 )
450 else if ( *
p ==
'1' && *(
p+1) == 0 )
473 Abc_TtConst0( pRes, nWordsR );
476 if ( Func == ~(
word)0 )
478 Abc_TtConst1( pRes, nWordsR );
484 assert( Func == s_Truths6[0] || Func == s_Truths6Neg[0] );
485 Abc_TtCopy( pRes, pFanins[0], nWordsR, Func == s_Truths6Neg[0] );
488 if ( !Abc_Tt6HasVar(Func, nVars) )
497 Abc_TtMux( pRes, pFanins[nVars], pTtTemp[1], pTtTemp[0], nWordsR );
509 nWordsF = Abc_TtWordNum( nVars );
511 if ( Abc_TtIsConst0(pFunc, nWordsF) )
513 Abc_TtConst0( pRes, nWordsR );
516 if ( Abc_TtIsConst1(pFunc, nWordsF) )
518 Abc_TtConst1( pRes, nWordsR );
521 if ( !Abc_TtHasVar( pFunc, nVars, nVars-1 ) )
531 Abc_TtMux( pRes, pFanins[nVars], pTtTemp[1], pTtTemp[0], nWordsR );
537 int nWords = Abc_TtWordNum( nVars );
541 if ( **
p >=
'a' && **
p <=
'z' )
543 assert( **
p -
'a' >= 0 && **
p -
'a' < nVars );
544 Abc_TtCopy( pRes, pTtElems[**
p -
'a'],
nWords, fCompl );
549 char * q = pStr + pMatches[ *
p - pStr ];
551 assert( **
p ==
'(' && *q ==
')' );
552 Abc_TtConst1( pRes,
nWords );
553 for ( (*
p)++; *
p < q; (*p)++ )
556 Abc_TtAnd( pRes, pRes, pTtTemp,
nWords, 0 );
559 if ( fCompl ) Abc_TtNot( pRes,
nWords );
564 char * q = pStr + pMatches[ *
p - pStr ];
566 assert( **
p ==
'[' && *q ==
']' );
567 Abc_TtConst0( pRes,
nWords );
568 for ( (*
p)++; *
p < q; (*p)++ )
571 Abc_TtXor( pRes, pRes, pTtTemp,
nWords, 0 );
574 if ( fCompl ) Abc_TtNot( pRes,
nWords );
579 char * q = pStr + pMatches[ *
p - pStr ];
582 assert( **
p ==
'<' && *q ==
'>' );
583 for ( i = 0, (*
p)++; *
p < q; (*p)++, i++ )
586 Abc_TtMux( pRes, pTtTemp[0], pTtTemp[1], pTtTemp[2],
nWords );
588 if ( fCompl ) Abc_TtNot( pRes,
nWords );
591 if ( (**
p >=
'A' && **
p <=
'F') || (**
p >=
'0' && **
p <=
'9') )
595 int i, nVarsF = Abc_TtReadHex( pFunc, *
p );
596 *
p += Abc_TtHexDigitNum( nVarsF );
597 q = pStr + pMatches[ *
p - pStr ];
598 assert( **
p ==
'{' && *q ==
'}' );
599 for ( i = 0, (*
p)++; *
p < q; (*p)++, i++ )
604 if ( fCompl ) Abc_TtNot( pRes,
nWords );
611 int nWords = Abc_TtWordNum( nVars );
612 word ** pTtElems = Dau_DsdTtElems();
615 if ( Dau_DsdIsConst0(
p) )
616 Abc_TtConst0( pRes,
nWords );
617 else if ( Dau_DsdIsConst1(
p) )
618 Abc_TtConst1( pRes,
nWords );
657static inline int Dau_DsdPerformReplace(
char * pBuffer,
int PosStart,
int Pos,
int Symb,
char * pNext )
662 for ( i = PosStart; i <
Pos; i++ )
663 if ( pBuffer[i] != Symb )
664 *pCur++ = pBuffer[i];
666 for ( k = 0; pNext[k]; k++ )
668 RetValue = PosStart + (pCur - pTemp);
669 for ( i = PosStart; i < RetValue; i++ )
670 pBuffer[i] = pTemp[i-PosStart];
676 word Cof0[6], Cof1[6], Cof[4];
677 int pVarsNew[6], nVarsNew, PosStart;
678 int v, u, vBest, CountBest;
682 for ( v = 0; v < nVars; v++ )
683 if ( Abc_Tt6HasVar( t, pVars[v] ) )
684 pVarsNew[ nVarsNew++ ] = pVars[v];
689 if ( t == s_Truths6[ pVarsNew[0] ] )
691 pBuffer[
Pos++] =
'a' + pVarsNew[0];
694 if ( t == ~s_Truths6[ pVarsNew[0] ] )
696 pBuffer[
Pos++] =
'!';
697 pBuffer[
Pos++] =
'a' + pVarsNew[0];
704 for ( v = 0; v < nVarsNew; v++ )
706 Cof0[v] = Abc_Tt6Cofactor0( t, pVarsNew[v] );
707 Cof1[v] = Abc_Tt6Cofactor1( t, pVarsNew[v] );
708 assert( Cof0[v] != Cof1[v] );
711 pBuffer[
Pos++] =
'(';
712 pBuffer[
Pos++] =
'a' + pVarsNew[v];
714 pBuffer[
Pos++] =
')';
717 if ( Cof0[v] == ~(
word)0 )
719 pBuffer[
Pos++] =
'!';
720 pBuffer[
Pos++] =
'(';
721 pBuffer[
Pos++] =
'a' + pVarsNew[v];
723 pBuffer[
Pos++] =
')';
728 pBuffer[
Pos++] =
'(';
729 pBuffer[
Pos++] =
'!';
730 pBuffer[
Pos++] =
'a' + pVarsNew[v];
732 pBuffer[
Pos++] =
')';
735 if ( Cof1[v] == ~(
word)0 )
737 pBuffer[
Pos++] =
'!';
738 pBuffer[
Pos++] =
'(';
739 pBuffer[
Pos++] =
'!';
740 pBuffer[
Pos++] =
'a' + pVarsNew[v];
742 pBuffer[
Pos++] =
')';
745 if ( Cof0[v] == ~Cof1[v] )
747 pBuffer[
Pos++] =
'[';
748 pBuffer[
Pos++] =
'a' + pVarsNew[v];
750 pBuffer[
Pos++] =
']';
755 for ( v = 0; v < nVarsNew; v++ )
756 for ( u = v+1; u < nVarsNew; u++ )
758 Cof[0] = Abc_Tt6Cofactor0( Cof0[v], pVarsNew[u] );
759 Cof[1] = Abc_Tt6Cofactor1( Cof0[v], pVarsNew[u] );
760 Cof[2] = Abc_Tt6Cofactor0( Cof1[v], pVarsNew[u] );
761 Cof[3] = Abc_Tt6Cofactor1( Cof1[v], pVarsNew[u] );
762 if ( Cof[0] == Cof[1] && Cof[0] == Cof[2] )
765 sprintf( pNest,
"(%c%c)",
'a' + pVarsNew[v],
'a' + pVarsNew[u] );
766 Pos =
Dau_DsdPerform_rec( (s_Truths6[pVarsNew[u]] & Cof[3]) | (~s_Truths6[pVarsNew[u]] & Cof[0]), pBuffer,
Pos, pVarsNew, nVarsNew );
767 Pos = Dau_DsdPerformReplace( pBuffer, PosStart,
Pos,
'a' + pVarsNew[u], pNest );
770 if ( Cof[0] == Cof[1] && Cof[0] == Cof[3] )
773 sprintf( pNest,
"(%c!%c)",
'a' + pVarsNew[v],
'a' + pVarsNew[u] );
774 Pos =
Dau_DsdPerform_rec( (s_Truths6[pVarsNew[u]] & Cof[2]) | (~s_Truths6[pVarsNew[u]] & Cof[0]), pBuffer,
Pos, pVarsNew, nVarsNew );
775 Pos = Dau_DsdPerformReplace( pBuffer, PosStart,
Pos,
'a' + pVarsNew[u], pNest );
778 if ( Cof[0] == Cof[2] && Cof[0] == Cof[3] )
781 sprintf( pNest,
"(!%c%c)",
'a' + pVarsNew[v],
'a' + pVarsNew[u] );
782 Pos =
Dau_DsdPerform_rec( (s_Truths6[pVarsNew[u]] & Cof[1]) | (~s_Truths6[pVarsNew[u]] & Cof[0]), pBuffer,
Pos, pVarsNew, nVarsNew );
783 Pos = Dau_DsdPerformReplace( pBuffer, PosStart,
Pos,
'a' + pVarsNew[u], pNest );
786 if ( Cof[1] == Cof[2] && Cof[1] == Cof[3] )
789 sprintf( pNest,
"(!%c!%c)",
'a' + pVarsNew[v],
'a' + pVarsNew[u] );
790 Pos =
Dau_DsdPerform_rec( (s_Truths6[pVarsNew[u]] & Cof[0]) | (~s_Truths6[pVarsNew[u]] & Cof[1]), pBuffer,
Pos, pVarsNew, nVarsNew );
791 Pos = Dau_DsdPerformReplace( pBuffer, PosStart,
Pos,
'a' + pVarsNew[u], pNest );
794 if ( Cof[0] == Cof[3] && Cof[1] == Cof[2] )
797 sprintf( pNest,
"[%c%c]",
'a' + pVarsNew[v],
'a' + pVarsNew[u] );
798 Pos =
Dau_DsdPerform_rec( (s_Truths6[pVarsNew[u]] & Cof[1]) | (~s_Truths6[pVarsNew[u]] & Cof[0]), pBuffer,
Pos, pVarsNew, nVarsNew );
799 Pos = Dau_DsdPerformReplace( pBuffer, PosStart,
Pos,
'a' + pVarsNew[u], pNest );
806 for ( v = 0; v < nVarsNew; v++ )
809 for ( u = 0; u < nVarsNew; u++ )
810 if ( u != v && Abc_Tt6HasVar(Cof0[v], pVarsNew[u]) && Abc_Tt6HasVar(Cof1[v], pVarsNew[u]) )
812 if ( CountBest > CountCur )
814 CountBest = CountCur;
821 pBuffer[
Pos++] =
'<';
822 pBuffer[
Pos++] =
'a' + pVarsNew[vBest];
825 pBuffer[
Pos++] =
'>';
831 int pVarsNew[6] = {0, 1, 2, 3, 4, 5};
834 pBuffer[
Pos++] =
'0';
835 else if ( t == ~(
word)0 )
836 pBuffer[
Pos++] =
'1';
875 printf(
"Verification failed.\n" );
897 int nWords = Abc_TtWordNum(nVarsInit);
898 int nSizeNonDec, nSizeNonDec0, nSizeNonDec1;
899 int i, vBest = -2, nSumCofsBest =
ABC_INFINITY, nSumCofs;
901 if ( nSizeNonDec == 0 )
903 assert( nSizeNonDec > 0 );
905 for ( i = 0; i < nVarsInit; i++ )
911 for ( i = 0; i < nVarsInit; i++ )
916 Vec_IntSelectSortCost2( pVarPrios, nVarsInit, pVarLevels );
921 for ( i = 0; i < nVarsInit; i++ )
923 assert( pVarPrios[i] >= 0 && pVarPrios[i] < nVarsInit );
925 Abc_TtCofactor0p( pCofTemp, pTruth,
nWords, pVarPrios[i] );
926 nSumCofs = Abc_TtSupportSize( pCofTemp, nVarsInit );
929 Abc_TtCofactor1p( pCofTemp, pTruth,
nWords, pVarPrios[i] );
930 nSumCofs += Abc_TtSupportSize( pCofTemp, nVarsInit );
933 if ( nSizeNonDec0 || nSizeNonDec1 )
935 if ( nSumCofsBest > nSumCofs )
937 vBest = pVarPrios[i];
938 nSumCofsBest = nSumCofs;
972static abctime s_Times[3] = {0};
985static inline void Dau_DsdInitialize(
Dau_Dsd_t *
p,
int nVarsInit )
988 assert( nVarsInit >= 0 && nVarsInit <= 16 );
989 p->nVarsInit = nVarsInit;
990 p->nVarsUsed = nVarsInit;
995 for ( i = 0; i < nVarsInit; i++ )
996 p->pVarDefs[i][0] =
'a' + i,
p->pVarDefs[i][1] = 0;
997 for ( v = 0; v < nVarsInit; v++ )
998 for ( u = 0; u < nVarsInit; u++ )
1002static inline void Dau_DsdWriteString(
Dau_Dsd_t *
p,
char * pStr )
1005 p->pOutput[
p->nPos++ ] = *pStr++;
1007static inline void Dau_DsdWriteVar(
Dau_Dsd_t *
p,
int iVar,
int fInv )
1011 p->pOutput[
p->nPos++ ] =
'!';
1012 for ( pStr =
p->pVarDefs[iVar]; *pStr; pStr++ )
1013 if ( *pStr >=
'a' +
p->nVarsInit && *pStr <
'a' +
p->nVarsUsed )
1014 Dau_DsdWriteVar(
p, *pStr -
'a', 0 );
1016 p->pOutput[
p->nPos++ ] = *pStr;
1022 int LevelMax = 0, Level;
1023 for ( pStr =
p->pVarDefs[iVar]; *pStr; pStr++ )
1025 if ( *pStr >=
'a' +
p->nVarsInit && *pStr <
'a' +
p->nVarsUsed )
1028 Level =
p->pVarLevels[*pStr -
'a'];
1029 LevelMax = Abc_MaxInt( LevelMax, Level );
1033static inline void Dau_DsdTranslate(
Dau_Dsd_t *
p,
int * pVars,
int nVars,
char * pStr )
1035 for ( ; *pStr; pStr++ )
1036 if ( *pStr >=
'a' && *pStr <
'a' + nVars )
1037 Dau_DsdWriteVar(
p, pVars[*pStr -
'a'], 0 );
1039 p->pOutput[
p->nPos++ ] = *pStr;
1041static inline int Dau_DsdWritePrime(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars )
1043 int v, RetValue = 2;
1045 if (
p->fSplitPrime )
1048 int nWords = Abc_TtWordNum(nVars);
1052 p->nPos += Abc_TtWriteHexRev(
p->pOutput +
p->nPos, pTruth, nVars );
1058 Dau_DsdWriteString(
p,
"<" );
1059 Dau_DsdWriteVar(
p, vBest, 0 );
1061 Abc_TtCofactor1p( pCofTemp, pTruth,
nWords, vBest );
1063 assert( nNonDecSize == 0 );
1064 Dau_DsdWriteString(
p, pRes );
1066 Abc_TtCofactor0p( pCofTemp, pTruth,
nWords, vBest );
1068 assert( nNonDecSize == 0 );
1069 Dau_DsdWriteString(
p, pRes );
1070 Dau_DsdWriteString(
p,
">" );
1074 else if (
p->fWriteTruth )
1075 p->nPos += Abc_TtWriteHexRev(
p->pOutput +
p->nPos, pTruth, nVars );
1076 Dau_DsdWriteString(
p,
"{" );
1077 for ( v = 0; v < nVars; v++ )
1078 Dau_DsdWriteVar(
p, pVars[v], 0 );
1079 Dau_DsdWriteString(
p,
"}" );
1080 p->nSizeNonDec = nVars;
1083static inline void Dau_DsdFinalize(
Dau_Dsd_t *
p )
1086 for ( i = 0; i <
p->nConsts; i++ )
1087 p->pOutput[
p->nPos++ ] = ((
p->uConstMask >> (
p->nConsts-1-i)) & 1) ?
']' :
')';
1088 p->pOutput[
p->nPos++ ] = 0;
1090static inline int Dau_DsdAddVarDef(
Dau_Dsd_t *
p,
char * pStr )
1095 for ( u = 0; u <
p->nVarsUsed; u++ )
1096 p->Cache[
p->nVarsUsed][u] = 0;
1097 for ( u = 0; u <
p->nVarsUsed; u++ )
1098 p->Cache[u][
p->nVarsUsed] = 0;
1099 sprintf(
p->pVarDefs[
p->nVarsUsed++],
"%s", pStr );
1100 return p->nVarsUsed - 1;
1102static inline int Dau_DsdFindVarDef(
int * pVars,
int nVars,
int VarDef )
1105 for ( v = 0; v < nVars; v++ )
1106 if ( pVars[v] == VarDef )
1111static inline void Dau_DsdInsertVarCache(
Dau_Dsd_t *
p,
int v,
int u,
int Status )
1114 assert( Status > 0 && Status < 4 );
1115 assert(
p->Cache[v][u] == 0 );
1118static inline int Dau_DsdLookupVarCache(
Dau_Dsd_t *
p,
int v,
int u )
1120 return p->Cache[v][u];
1134static inline int Dau_Dsd6DecomposeSingleVarOne(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars,
int v )
1137 if ( pTruth[0] & 1 )
1139 if ( Abc_Tt6Cof0IsConst1( pTruth[0], v ) )
1141 Dau_DsdWriteString(
p,
"!(" );
1142 pTruth[0] = ~Abc_Tt6Cofactor1( pTruth[0], v );
1148 if ( Abc_Tt6Cof0IsConst0( pTruth[0], v ) )
1150 Dau_DsdWriteString(
p,
"(" );
1151 pTruth[0] = Abc_Tt6Cofactor1( pTruth[0], v );
1156 if ( pTruth[0] >> 63 )
1158 if ( Abc_Tt6Cof1IsConst1( pTruth[0], v ) )
1160 Dau_DsdWriteString(
p,
"!(!" );
1161 pTruth[0] = ~Abc_Tt6Cofactor0( pTruth[0], v );
1167 if ( Abc_Tt6Cof1IsConst0( pTruth[0], v ) )
1169 Dau_DsdWriteString(
p,
"(!" );
1170 pTruth[0] = Abc_Tt6Cofactor0( pTruth[0], v );
1175 if ( Abc_Tt6CofsOpposite( pTruth[0], v ) )
1177 Dau_DsdWriteString(
p,
"[" );
1178 pTruth[0] = Abc_Tt6Cofactor0( pTruth[0], v );
1179 p->uConstMask |= (1 <<
p->nConsts);
1186 Dau_DsdWriteVar(
p, pVars[v], 0 );
1187 pVars[v] = pVars[nVars-1];
1188 Abc_TtSwapVars( pTruth, nVars, v, nVars-1 );
1198 for ( v = nVars - 1; v >= 0 && nVars > 1; v-- )
1199 if ( Dau_Dsd6DecomposeSingleVarOne(
p, pTruth, pVars, nVars, v ) )
1204 if ( v == -1 || nVars == 1 )
1208 Dau_DsdWriteVar(
p, pVars[--nVars], (
int)(pTruth[0] & 1) );
1209 s_Times[0] += Abc_Clock() - clk;
1212static inline int Dau_Dsd6FindSupportOne(
Dau_Dsd_t *
p,
word tCof0,
word tCof1,
int * pVars,
int nVars,
int v,
int u )
1214 int Status =
p ? Dau_DsdLookupVarCache(
p, pVars[v], pVars[u] ) : 0;
1217 Status = (Abc_Tt6HasVar(tCof1, u) << 1) | Abc_Tt6HasVar(tCof0, u);
1219 Dau_DsdInsertVarCache(
p, pVars[v], pVars[u], Status );
1223static inline unsigned Dau_Dsd6FindSupports(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars,
int v )
1226 unsigned uSupports = 0;
1227 word tCof0 = Abc_Tt6Cofactor0( pTruth[0], v );
1228 word tCof1 = Abc_Tt6Cofactor1( pTruth[0], v );
1231 for ( u = 0; u < nVars; u++ )
1233 uSupports |= (Dau_Dsd6FindSupportOne(
p, tCof0, tCof1, pVars, nVars, v, u ) << (2 * u));
1236static inline void Dau_DsdPrintSupports(
unsigned uSupp,
int nVars )
1239 printf(
"Cofactor supports: " );
1240 for ( v = nVars - 1; v >= 0; v-- )
1242 Value = ((uSupp >> (2*v)) & 3);
1245 else if ( Value == 2 )
1247 else if ( Value == 3 )
1257static inline int Dau_Dsd6DecomposeDoubleVarsOne(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars,
int v,
int u )
1259 char pBuffer[10] = { 0 };
1260 word tCof0 = Abc_Tt6Cofactor0( pTruth[0], v );
1261 word tCof1 = Abc_Tt6Cofactor1( pTruth[0], v );
1262 int Status = Dau_Dsd6FindSupportOne(
p, tCof0, tCof1, pVars, nVars, v, u );
1270 if ( Abc_Tt6Cof0EqualCof1(tCof0, tCof1, u) && Abc_Tt6Cof0EqualCof1(tCof1, tCof0, u) )
1272 pTruth[0] = (s_Truths6[u] & Abc_Tt6Cofactor1(tCof0, u)) | (~s_Truths6[u] & Abc_Tt6Cofactor0(tCof0, u));
1273 sprintf( pBuffer,
"[%c%c]",
'a' + pVars[v],
'a' + pVars[u] );
1277 else if ( Status == 2 )
1280 if ( Abc_Tt6Cof0EqualCof0(tCof0, tCof1, u) )
1282 sprintf( pBuffer,
"(%c%c)",
'a' + pVars[v],
'a' + pVars[u] );
1283 pTruth[0] = (s_Truths6[u] & Abc_Tt6Cofactor1(tCof1, u)) | (~s_Truths6[u] & Abc_Tt6Cofactor0(tCof0, u));
1286 if ( Abc_Tt6Cof0EqualCof1(tCof0, tCof1, u) )
1288 sprintf( pBuffer,
"(%c!%c)",
'a' + pVars[v],
'a' + pVars[u] );
1289 pTruth[0] = (s_Truths6[u] & Abc_Tt6Cofactor0(tCof1, u)) | (~s_Truths6[u] & Abc_Tt6Cofactor0(tCof0, u));
1293 else if ( Status == 1 )
1296 if ( Abc_Tt6Cof0EqualCof1(tCof0, tCof1, u) )
1298 sprintf( pBuffer,
"(!%c%c)",
'a' + pVars[v],
'a' + pVars[u] );
1299 pTruth[0] = (s_Truths6[u] & Abc_Tt6Cofactor1(tCof0, u)) | (~s_Truths6[u] & Abc_Tt6Cofactor0(tCof0, u));
1302 if ( Abc_Tt6Cof1EqualCof1(tCof0, tCof1, u) )
1304 sprintf( pBuffer,
"(!%c!%c)",
'a' + pVars[v],
'a' + pVars[u] );
1305 pTruth[0] = (s_Truths6[u] & Abc_Tt6Cofactor0(tCof0, u)) | (~s_Truths6[u] & Abc_Tt6Cofactor1(tCof1, u));
1313 pVars[u] = Dau_DsdAddVarDef(
p, pBuffer );
1314 pVars[v] = pVars[nVars-1];
1315 Abc_TtSwapVars( pTruth, nVars, v, nVars-1 );
1316 if ( Dau_Dsd6DecomposeSingleVarOne(
p, pTruth, pVars, --nVars, u ) )
1326 for ( v = nVars - 1; v > 0; v-- )
1328 for ( u = v - 1; u >= 0; u-- )
1330 if ( Dau_DsdLookupVarCache(
p, pVars[v], pVars[u] ) )
1333 nVars = Dau_Dsd6DecomposeDoubleVarsOne(
p, pTruth, pVars, nVars, v, u );
1336 s_Times[1] += Abc_Clock() - clk;
1339 if ( nVarsOld > nVars )
1348 s_Times[1] += Abc_Clock() - clk;
1353static inline int Dau_Dsd6DecomposeTripleVarsOuter(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars,
int v )
1358 p1->fSplitPrime = 0;
1359 p1->fWriteTruth =
p->fWriteTruth;
1361 ABC_SWAP(
int, pVars[v], pVars[nVars-1] );
1362 Abc_TtSwapVars( pTruth, nVars, v, nVars-1 );
1364 tCof0 = Abc_Tt6Cofactor0( pTruth[0], nVars - 1 );
1365 tCof1 = Abc_Tt6Cofactor1( pTruth[0], nVars - 1 );
1367 Dau_DsdWriteString(
p,
"<" );
1368 Dau_DsdWriteVar(
p, pVars[nVars - 1], 0 );
1371 Dau_DsdTranslate(
p, pVars, nVars - 1, p1->pOutput );
1372 p->nSizeNonDec = p1->nSizeNonDec;
1373 if ( p1->nSizeNonDec )
1377 Dau_DsdTranslate(
p, pVars, nVars - 1, p1->pOutput );
1378 Dau_DsdWriteString(
p,
">" );
1379 p->nSizeNonDec = Abc_MaxInt(
p->nSizeNonDec, p1->nSizeNonDec );
1380 if ( p1->nSizeNonDec )
1384static inline int Dau_Dsd6DecomposeTripleVarsInner(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars,
int v,
unsigned uSupports )
1386 int iVar0 = Abc_TtSuppFindFirst( uSupports & (~uSupports >> 1) & 0x55555555 ) >> 1;
1387 int iVar1 = Abc_TtSuppFindFirst( ~uSupports & ( uSupports >> 1) & 0x55555555 ) >> 1;
1388 word tCof0 = Abc_Tt6Cofactor0( pTruth[0], v );
1389 word tCof1 = Abc_Tt6Cofactor1( pTruth[0], v );
1390 word C00 = Abc_Tt6Cofactor0( tCof0, iVar0 );
1391 word C01 = Abc_Tt6Cofactor1( tCof0, iVar0 );
1392 word C10 = Abc_Tt6Cofactor0( tCof1, iVar1 );
1393 word C11 = Abc_Tt6Cofactor1( tCof1, iVar1 );
1394 int fEqual0 = (C00 == C10) && (C01 == C11);
1395 int fEqual1 = (C00 == C11) && (C01 == C10);
1396 if ( fEqual0 || fEqual1 )
1399 int VarId = pVars[iVar0];
1400 pTruth[0] = (s_Truths6[v] & C11) | (~s_Truths6[v] & C10);
1401 sprintf( pBuffer,
"<%c%c%s%c>",
'a' + pVars[v],
'a' + pVars[iVar1], fEqual1 ?
"!":
"",
'a' + pVars[iVar0] );
1402 pVars[v] = Dau_DsdAddVarDef(
p, pBuffer );
1404 ABC_SWAP(
int, pVars[iVar1], pVars[nVars-1] );
1405 Abc_TtSwapVars( pTruth, nVars, iVar1, nVars-1 ); nVars--;
1407 iVar0 = Dau_DsdFindVarDef( pVars, nVars, VarId );
1408 ABC_SWAP(
int, pVars[iVar0], pVars[nVars-1] );
1409 Abc_TtSwapVars( pTruth, nVars, iVar0, nVars-1 ); nVars--;
1411 v = Dau_DsdFindVarDef( pVars, nVars,
p->nVarsUsed-1 );
1413 if ( Dau_Dsd6DecomposeSingleVarOne(
p, pTruth, pVars, nVars, v ) )
1426 for ( v = nVars - 1; v >= 0; v-- )
1428 unsigned uSupports = Dau_Dsd6FindSupports(
p, pTruth, pVars, nVars, v );
1430 if ( (uSupports & (uSupports >> 1) & 0x55555555) == 0 )
1431 return Dau_Dsd6DecomposeTripleVarsOuter(
p, pTruth, pVars, nVars, v );
1432 if ( Abc_TtSuppOnlyOne( uSupports & (~uSupports >> 1) & 0x55555555) &&
1433 Abc_TtSuppOnlyOne(~uSupports & ( uSupports >> 1) & 0x55555555) )
1435 int nVarsNew = Dau_Dsd6DecomposeTripleVarsInner(
p, pTruth, pVars, nVars, v, uSupports );
1436 if ( nVarsNew == nVars )
1438 if ( nVarsNew == 0 )
1440 s_Times[2] += Abc_Clock() - clk;
1446 s_Times[2] += Abc_Clock() - clk;
1454 s_Times[2] += Abc_Clock() - clk;
1476 return Dau_DsdWritePrime(
p, pTruth, pVars, nVars );
1490static inline int Dau_DsdDecomposeSingleVarOne(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars,
int v )
1492 int nWords = Abc_TtWordNum(nVars);
1494 if ( pTruth[0] & 1 )
1496 if ( Abc_TtCof0IsConst1( pTruth,
nWords, v ) )
1498 Dau_DsdWriteString(
p,
"!(" );
1499 Abc_TtCofactor1( pTruth,
nWords, v );
1500 Abc_TtNot( pTruth,
nWords );
1506 if ( Abc_TtCof0IsConst0( pTruth,
nWords, v ) )
1508 Dau_DsdWriteString(
p,
"(" );
1509 Abc_TtCofactor1( pTruth,
nWords, v );
1514 if ( pTruth[
nWords-1] >> 63 )
1516 if ( Abc_TtCof1IsConst1( pTruth,
nWords, v ) )
1518 Dau_DsdWriteString(
p,
"!(!" );
1519 Abc_TtCofactor0( pTruth,
nWords, v );
1520 Abc_TtNot( pTruth,
nWords );
1526 if ( Abc_TtCof1IsConst0( pTruth,
nWords, v ) )
1528 Dau_DsdWriteString(
p,
"(!" );
1529 Abc_TtCofactor0( pTruth,
nWords, v );
1534 if ( Abc_TtCofsOpposite( pTruth,
nWords, v ) )
1536 Dau_DsdWriteString(
p,
"[" );
1537 Abc_TtCofactor0( pTruth,
nWords, v );
1538 p->uConstMask |= (1 <<
p->nConsts);
1545 Dau_DsdWriteVar(
p, pVars[v], 0 );
1546 pVars[v] = pVars[nVars-1];
1547 Abc_TtSwapVars( pTruth, nVars, v, nVars-1 );
1557 for ( v = nVars - 1; v >= 0 && nVars > 1; v-- )
1558 if ( Dau_DsdDecomposeSingleVarOne(
p, pTruth, pVars, nVars, v ) )
1563 if ( v == -1 || nVars == 1 )
1567 Dau_DsdWriteVar(
p, pVars[--nVars], (
int)(pTruth[0] & 1) );
1568 s_Times[0] += Abc_Clock() - clk;
1572static inline int Dau_DsdFindSupportOne(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars,
int v,
int u )
1574 int nWords = Abc_TtWordNum(nVars);
1575 int Status =
p ? Dau_DsdLookupVarCache(
p, pVars[v], pVars[u] ) : 0;
1580 Status = (!Abc_TtCheckEqualCofs(pTruth,
nWords, v, u, 1, 3) << 1) | !Abc_TtCheckEqualCofs(pTruth,
nWords, v, u, 0, 2);
1582 Status = (!Abc_TtCheckEqualCofs(pTruth,
nWords, u, v, 2, 3) << 1) | !Abc_TtCheckEqualCofs(pTruth,
nWords, u, v, 0, 1);
1585 Dau_DsdInsertVarCache(
p, pVars[v], pVars[u], Status );
1589static inline unsigned Dau_DsdFindSupports(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars,
int v )
1592 unsigned uSupports = 0;
1595 for ( u = 0; u < nVars; u++ )
1597 uSupports |= (Dau_DsdFindSupportOne(
p, pTruth, pVars, nVars, v, u ) << (2 * u));
1602static inline int Dau_DsdDecomposeDoubleVarsOne(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars,
int v,
int u )
1604 char pBuffer[10] = { 0 };
1605 int nWords = Abc_TtWordNum(nVars);
1606 int Status = Dau_DsdFindSupportOne(
p, pTruth, pVars, nVars, v, u );
1613 if ( Abc_TtCheckEqualCofs(pTruth,
nWords, u, v, 0, 3) && Abc_TtCheckEqualCofs(pTruth,
nWords, u, v, 1, 2) )
1616 sprintf( pBuffer,
"[%c%c]",
'a' + pVars[v],
'a' + pVars[u] );
1618 Abc_TtCofactor0p( pTtTemp[0], pTruth,
nWords, v );
1619 Abc_TtCofactor0( pTtTemp[0],
nWords, u );
1620 Abc_TtCofactor0p( pTtTemp[1], pTruth,
nWords, v );
1621 Abc_TtCofactor1( pTtTemp[1],
nWords, u );
1622 Abc_TtMux( pTruth, Dau_DsdTtElems()[u], pTtTemp[1], pTtTemp[0],
nWords );
1626 else if ( Status == 2 )
1630 if ( Abc_TtCheckEqualCofs(pTruth,
nWords, u, v, 0, 2) )
1633 sprintf( pBuffer,
"(%c%c)",
'a' + pVars[v],
'a' + pVars[u] );
1635 Abc_TtCofactor0p( pTtTemp[0], pTruth,
nWords, v );
1636 Abc_TtCofactor0( pTtTemp[0],
nWords, u );
1637 Abc_TtCofactor1p( pTtTemp[1], pTruth,
nWords, v );
1638 Abc_TtCofactor1( pTtTemp[1],
nWords, u );
1639 Abc_TtMux( pTruth, Dau_DsdTtElems()[u], pTtTemp[1], pTtTemp[0],
nWords );
1643 if ( Abc_TtCheckEqualCofs(pTruth,
nWords, u, v, 0, 3) )
1646 sprintf( pBuffer,
"(%c!%c)",
'a' + pVars[v],
'a' + pVars[u] );
1648 Abc_TtCofactor0p( pTtTemp[0], pTruth,
nWords, v );
1649 Abc_TtCofactor0( pTtTemp[0],
nWords, u );
1650 Abc_TtCofactor1p( pTtTemp[1], pTruth,
nWords, v );
1651 Abc_TtCofactor0( pTtTemp[1],
nWords, u );
1652 Abc_TtMux( pTruth, Dau_DsdTtElems()[u], pTtTemp[1], pTtTemp[0],
nWords );
1656 else if ( Status == 1 )
1660 if ( Abc_TtCheckEqualCofs(pTruth,
nWords, u, v, 0, 3) )
1663 sprintf( pBuffer,
"(!%c%c)",
'a' + pVars[v],
'a' + pVars[u] );
1665 Abc_TtCofactor0p( pTtTemp[0], pTruth,
nWords, v );
1666 Abc_TtCofactor0( pTtTemp[0],
nWords, u );
1667 Abc_TtCofactor0p( pTtTemp[1], pTruth,
nWords, v );
1668 Abc_TtCofactor1( pTtTemp[1],
nWords, u );
1669 Abc_TtMux( pTruth, Dau_DsdTtElems()[u], pTtTemp[1], pTtTemp[0],
nWords );
1673 if ( Abc_TtCheckEqualCofs(pTruth,
nWords, u, v, 1, 3) )
1676 sprintf( pBuffer,
"(!%c!%c)",
'a' + pVars[v],
'a' + pVars[u] );
1678 Abc_TtCofactor1p( pTtTemp[0], pTruth,
nWords, v );
1679 Abc_TtCofactor1( pTtTemp[0],
nWords, u );
1680 Abc_TtCofactor0p( pTtTemp[1], pTruth,
nWords, v );
1681 Abc_TtCofactor0( pTtTemp[1],
nWords, u );
1682 Abc_TtMux( pTruth, Dau_DsdTtElems()[u], pTtTemp[1], pTtTemp[0],
nWords );
1690 pVars[u] = Dau_DsdAddVarDef(
p, pBuffer );
1691 pVars[v] = pVars[nVars-1];
1692 Abc_TtSwapVars( pTruth, nVars, v, nVars-1 );
1693 if ( Dau_DsdDecomposeSingleVarOne(
p, pTruth, pVars, --nVars, u ) )
1703 for ( v = nVars - 1; v > 0; v-- )
1705 for ( u = v - 1; u >= 0; u-- )
1707 if ( Dau_DsdLookupVarCache(
p, pVars[v], pVars[u] ) )
1710 nVars = Dau_DsdDecomposeDoubleVarsOne(
p, pTruth, pVars, nVars, v, u );
1713 s_Times[1] += Abc_Clock() - clk;
1716 if ( nVarsOld > nVars )
1725 s_Times[1] += Abc_Clock() - clk;
1730static inline int Dau_DsdDecomposeTripleVarsOuter(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars,
int v )
1735 int nWords = Abc_TtWordNum(nVars);
1736 p1->fSplitPrime = 0;
1737 p1->fWriteTruth =
p->fWriteTruth;
1739 ABC_SWAP(
int, pVars[v], pVars[nVars-1] );
1740 Abc_TtSwapVars( pTruth, nVars, v, nVars-1 );
1744 Abc_TtCofactor0p( pTtCof[0], pTruth,
nWords, nVars - 1 );
1745 Abc_TtCofactor1p( pTtCof[1], pTruth,
nWords, nVars - 1 );
1747 Dau_DsdWriteString(
p,
"<" );
1748 Dau_DsdWriteVar(
p, pVars[nVars - 1], 0 );
1751 Dau_DsdTranslate(
p, pVars, nVars - 1, p1->pOutput );
1752 p->nSizeNonDec = p1->nSizeNonDec;
1753 if ( p1->nSizeNonDec )
1754 Abc_TtCopy( pTruth, pTtCof[1], Abc_TtWordNum(p1->nSizeNonDec), 0 );
1757 Dau_DsdTranslate(
p, pVars, nVars - 1, p1->pOutput );
1758 Dau_DsdWriteString(
p,
">" );
1759 p->nSizeNonDec = Abc_MaxInt(
p->nSizeNonDec, p1->nSizeNonDec );
1760 if ( p1->nSizeNonDec )
1761 Abc_TtCopy( pTruth, pTtCof[0], Abc_TtWordNum(p1->nSizeNonDec), 0 );
1764static inline int Dau_DsdDecomposeTripleVarsInner(
Dau_Dsd_t *
p,
word * pTruth,
int * pVars,
int nVars,
int v,
unsigned uSupports )
1766 int nWords = Abc_TtWordNum(nVars);
1767 int iVar0 = Abc_TtSuppFindFirst( uSupports & (~uSupports >> 1) & 0x55555555 ) >> 1;
1768 int iVar1 = Abc_TtSuppFindFirst( ~uSupports & ( uSupports >> 1) & 0x55555555 ) >> 1;
1769 int fEqual0, fEqual1;
1780 Abc_TtCofactor0p( pTtCof[0], pTruth,
nWords, v );
1781 Abc_TtCofactor1p( pTtCof[1], pTruth,
nWords, v );
1782 Abc_TtCofactor0p( pTtFour[0][0], pTtCof[0],
nWords, iVar0 );
1783 Abc_TtCofactor1p( pTtFour[0][1], pTtCof[0],
nWords, iVar0 );
1784 Abc_TtCofactor0p( pTtFour[1][0], pTtCof[1],
nWords, iVar1 );
1785 Abc_TtCofactor1p( pTtFour[1][1], pTtCof[1],
nWords, iVar1 );
1786 fEqual0 = Abc_TtEqual(pTtFour[0][0], pTtFour[1][0],
nWords) && Abc_TtEqual(pTtFour[0][1], pTtFour[1][1],
nWords);
1787 fEqual1 = Abc_TtEqual(pTtFour[0][0], pTtFour[1][1],
nWords) && Abc_TtEqual(pTtFour[0][1], pTtFour[1][0],
nWords);
1788 if ( fEqual0 || fEqual1 )
1791 int VarId = pVars[iVar0];
1793 Abc_TtMux( pTruth, Dau_DsdTtElems()[v], pTtFour[1][1], pTtFour[1][0],
nWords );
1794 sprintf( pBuffer,
"<%c%c%s%c>",
'a' + pVars[v],
'a' + pVars[iVar1], fEqual1 ?
"!":
"",
'a' + pVars[iVar0] );
1795 pVars[v] = Dau_DsdAddVarDef(
p, pBuffer );
1797 ABC_SWAP(
int, pVars[iVar1], pVars[nVars-1] );
1798 Abc_TtSwapVars( pTruth, nVars, iVar1, nVars-1 ); nVars--;
1800 iVar0 = Dau_DsdFindVarDef( pVars, nVars, VarId );
1801 ABC_SWAP(
int, pVars[iVar0], pVars[nVars-1] );
1802 Abc_TtSwapVars( pTruth, nVars, iVar0, nVars-1 ); nVars--;
1804 v = Dau_DsdFindVarDef( pVars, nVars,
p->nVarsUsed-1 );
1806 if ( Dau_DsdDecomposeSingleVarOne(
p, pTruth, pVars, nVars, v ) )
1819 for ( v = nVars - 1; v >= 0; v-- )
1821 unsigned uSupports = Dau_DsdFindSupports(
p, pTruth, pVars, nVars, v );
1823 if ( (uSupports & (uSupports >> 1) & 0x55555555) == 0 )
1824 return Dau_DsdDecomposeTripleVarsOuter(
p, pTruth, pVars, nVars, v );
1825 if ( Abc_TtSuppOnlyOne( uSupports & (~uSupports >> 1) & 0x55555555) &&
1826 Abc_TtSuppOnlyOne(~uSupports & ( uSupports >> 1) & 0x55555555) )
1828 int nVarsNew = Dau_DsdDecomposeTripleVarsInner(
p, pTruth, pVars, nVars, v, uSupports );
1829 if ( nVarsNew == nVars )
1831 if ( nVarsNew == 0 )
1833 s_Times[2] += Abc_Clock() - clk;
1839 s_Times[2] += Abc_Clock() - clk;
1847 s_Times[2] += Abc_Clock() - clk;
1869 return Dau_DsdWritePrime(
p, pTruth, pVars, nVars );
1886 for ( v = 0; v < nVars; v++ )
1888 for ( v = nVars - 1; v >= 0; v-- )
1890 if ( Abc_TtHasVar( pTruth, nVars, v ) )
1892 Abc_TtSwapVars( pTruth, nVars, v, nVars-1 );
1893 pVarsNew[v] = pVarsNew[--nVars];
1899 int Status = 0, nVars, pVars[16];
1900 Dau_DsdInitialize(
p, nVarsInit );
1902 assert( nVars > 0 && nVars <= nVarsInit );
1904 Dau_DsdWriteVar(
p, pVars[0], (
int)(pTruth[0] & 1) );
1905 else if ( nVars <= 6 )
1909 Dau_DsdFinalize(
p );
1915 p->fSplitPrime = fSplitPrime;
1916 p->fWriteTruth = fWriteTruth;
1917 p->pVarLevels = NULL;
1919 if ( (pTruth[0] & 1) == 0 && Abc_TtIsConst0(pTruth, Abc_TtWordNum(nVarsInit)) )
1920 {
if ( pRes ) pRes[0] =
'0', pRes[1] = 0; }
1921 else if ( (pTruth[0] & 1) && Abc_TtIsConst1(pTruth, Abc_TtWordNum(nVarsInit)) )
1922 {
if ( pRes ) pRes[0] =
'1', pRes[1] = 0; }
1929 assert( fSplitPrime || Status != 1 );
1930 if ( fSplitPrime && Status == 2 )
1934 return p->nSizeNonDec;
1939 p->fSplitPrime = fSplitPrime;
1940 p->fWriteTruth = fWriteTruth;
1941 p->pVarLevels = pVarLevels;
1943 if ( (pTruth[0] & 1) == 0 && Abc_TtIsConst0(pTruth, Abc_TtWordNum(nVarsInit)) )
1944 {
if ( pRes ) pRes[0] =
'0', pRes[1] = 0; }
1945 else if ( (pTruth[0] & 1) && Abc_TtIsConst1(pTruth, Abc_TtWordNum(nVarsInit)) )
1946 {
if ( pRes ) pRes[0] =
'1', pRes[1] = 0; }
1953 assert( fSplitPrime || Status != 1 );
1954 if ( fSplitPrime && Status == 2 )
1958 return p->nSizeNonDec;
1964 Abc_TtCopy( pTemp, pTruth, Abc_TtWordNum(nVarsInit), 0 );
1966 fprintf( pFile,
"%s\n", pRes );
1972 Abc_TtCopy( pTemp, pTruth, Abc_TtWordNum(nVarsInit), 0 );
1974 fprintf( stdout,
"%s\n", pRes );
1980 Abc_TtCopy( pTemp, pTruth, Abc_TtWordNum(nVarsInit), 0 );
1982 fprintf( stdout,
"%s", pRes );
1994 char * pStr =
"[dc<a(cbd)(!c!b!d)>{abef}]";
2017 char * pStr =
"(<abc>(<def><ghi>))";
2043 int nWords = Abc_TtWordNum(nVars);
2044 char * pFileName =
"_npn/npn/dsd10.txt";
2045 FILE * pFile = fopen( pFileName,
"rb" );
2051 abctime clk = Abc_Clock(), clkDec = 0, clk2;
2054 while ( fgets( pBuffer,
DAU_MAX_STR, pFile ) != NULL )
2056 char * pStr2 = pBuffer +
strlen(pBuffer)-1;
2057 if ( *pStr2 ==
'\n' )
2059 if ( *pStr2 ==
'\r' )
2061 if ( pBuffer[0] ==
'V' || pBuffer[0] == 0 )
2065 for ( i = 0; i < 1; i++ )
2068 pTruth =
Dau_DsdToTruth( pBuffer[0] ==
'*' ? pBuffer + 1 : pBuffer, nVars );
2069 Abc_TtCopy( Tru[0], pTruth,
nWords, 0 );
2070 Abc_TtCopy( Tru[1], pTruth,
nWords, 0 );
2073 clkDec += Abc_Clock() - clk2;
2076 assert( nSizeNonDec == 0 );
2078 if ( !Abc_TtEqual( pTruth, Tru[0],
nWords ) )
2083 printf(
"%s -> %s \n", pBuffer, pRes );
2084 printf(
"Verification failed.\n" );
2088 printf(
"Finished trying %d decompositions. ", Counter );
2089 Abc_PrintTime( 1,
"Time", clkDec );
2090 Abc_PrintTime( 1,
"Total", Abc_Clock() - clk );
2092 Abc_PrintTime( 1,
"Time1", s_Times[0] );
2093 Abc_PrintTime( 1,
"Time2", s_Times[1] );
2094 Abc_PrintTime( 1,
"Time3", s_Times[2] );
#define ABC_SWAP(Type, a, b)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_CONST(number)
PARAMETERS ///.
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Dau_Dsd_t_ Dau_Dsd_t
DECLARATIONS ///.
int Dau_Dsd6DecomposeDoubleVars(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
char * Dau_DsdPerform(word t)
void Dau_DsdNormalize_rec(char *pStr, char **p, int *pMatches)
int Dau_DsdDecomposeTripleVars(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
int Dau_DsdCheck1Step(void *p, word *pTruth, int nVarsInit, int *pVarLevels)
word Dau_Dsd6TruthCompose_rec(word Func, word *pFanins, int nVars)
int * Dau_DsdNormalizePerm(char *pStr, int *pMarks, int nMarks)
word * Dau_DsdToTruth(char *p, int nVars)
int Dau_Dsd6DecomposeSingleVar(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
int Dau_DsdDecomposeInternal(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
void Dau_DsdPrintFromTruthFile(FILE *pFile, word *pTruth, int nVarsInit)
void Dau_DsdToTruth_rec(char *pStr, char **p, int *pMatches, word **pTtElems, word *pRes, int nVars)
void Dau_DsdNormalize(char *pDsd)
int Dau_DsdDecompose(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes)
void Dau_DsdTruth6Compose_rec(word Func, word pFanins[DAU_MAX_VAR][DAU_MAX_WORD], word *pRes, int nVars, int nWordsR)
int Dau_DsdFindVarNum(char *pDsd)
int Dau_DsdDecomposeLevel(word *pTruth, int nVarsInit, int fSplitPrime, int fWriteTruth, char *pRes, int *pVarLevels)
int * Dau_DsdComputeMatches(char *p)
void Dau_DsdTruthCompose_rec(word *pFunc, word pFanins[DAU_MAX_VAR][DAU_MAX_WORD], word *pRes, int nVars, int nWordsR)
void Dau_DsdGenRandPerm(int *pPerm, int nVars)
void Dau_DsdPrintFromTruth(word *pTruth, int nVarsInit)
char * Dau_DsdNormalizeCopy(char *pDest, char *pSour, int *pMarks, int i)
word Dau_Dsd6ToTruth_rec(char *pStr, char **p, int *pMatches, word *pTruths)
int Dau_DsdCountAnds(char *pDsd)
void Dau_DsdPermute(char *pDsd)
int Dau_DsdNormalizeCompare(char *pStr, int *pMarks, int i, int j)
int Dau_DsdDecomposeDoubleVars(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
int Dau_DsdDecomposeInt(Dau_Dsd_t *p, word *pTruth, int nVarsInit)
int Dau_DsdDecomposeSingleVar(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
void Dau_DsdPrintFromTruth2(word *pTruth, int nVarsInit)
int Dau_Dsd6DecomposeTripleVars(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
int Dau_DsdLevelVar(void *pMan, int iVar)
int Dau_DsdCountAnds_rec(char *pStr, char **p, int *pMatches)
int Dau_Dsd6DecomposeInternal(Dau_Dsd_t *p, word *pTruth, int *pVars, int nVars)
int Dau_DsdMinBase(word *pTruth, int nVars, int *pVarsNew)
word Dau_Dsd6ToTruth(char *p)
int Dau_DsdPerform_rec(word t, char *pBuffer, int Pos, int *pVars, int nVars)
void Dau_DsdRemoveBraces(char *pDsd, int *pMatches)
int * Dau_DsdComputeMatches(char *p)
#define DAU_MAX_VAR
INCLUDES ///.
unsigned __int64 word
DECLARATIONS ///.
char pOutput[DAU_MAX_STR]