30static void Dsd_TreeUnmark_rec(
Dsd_Node_t * pNode );
31static void Dsd_TreeGetInfo_rec(
Dsd_Node_t * pNode,
int RankCur );
32static int Dsd_TreeCountNonTerminalNodes_rec(
Dsd_Node_t * pNode );
33static int Dsd_TreeCountPrimeNodes_rec(
Dsd_Node_t * pNode );
34static int Dsd_TreeCollectDecomposableVars_rec( DdManager * dd,
Dsd_Node_t * pNode,
int * pVars,
int * nVars );
35static void Dsd_TreeCollectNodesDfs_rec(
Dsd_Node_t * pNode,
Dsd_Node_t * ppNodes[],
int * pnNodes );
36static void Dsd_TreePrint_rec( FILE * pFile,
Dsd_Node_t * pNode,
int fCcmp,
char * pInputNames[],
char * pOutputName,
int nOffset,
int * pSigCounter,
int fShortNames );
37static void Dsd_NodePrint_rec( FILE * pFile,
Dsd_Node_t * pNode,
int fComp,
char * pOutputName,
int nOffset,
int * pSigCounter );
44static int s_GateSizeMax;
89 if ( pNode->
G ) Cudd_RecursiveDeref( dd, pNode->
G );
90 if ( pNode->
S ) Cudd_RecursiveDeref( dd, pNode->
S );
110 for ( i = 0; i < pDsdMan->
nRoots; i++ )
140 for ( i = 0; i < pNode->
nDecs; i++ )
162 for ( i = 0; i < pDsdMan->
nRoots; i++ )
166 *DepthMax = s_DepthMax;
168 *GateSizeMax = s_GateSizeMax;
191 *DepthMax = s_DepthMax;
193 *GateSizeMax = s_GateSizeMax;
212void Dsd_TreeGetInfo_rec(
Dsd_Node_t * pNode,
int RankCur )
226 GateSize = pNode->
nDecs;
229 if ( s_GateSizeMax < GateSize )
230 s_GateSizeMax = GateSize;
232 if ( pNode->
nDecs < 2 )
236 if ( s_DepthMax < RankCur+1 )
237 s_DepthMax = RankCur+1;
240 for ( i = 0; i < pNode->
nDecs; i++ )
263 if ( pNode->
nDecs < 2 )
268 Counter += pNode->
nDecs - 1;
270 Counter += 3*(pNode->
nDecs - 1);
275 for ( i = 0; i < pNode->
nDecs; i++ )
314 for ( i = 0; i < pDsdMan->
nRoots; i++ )
315 Counter += Dsd_TreeCountNonTerminalNodes_rec(
Dsd_Regular( pDsdMan->
pRoots[i] ) );
336 Counter = Dsd_TreeCountNonTerminalNodes_rec(
Dsd_Regular(pRoot) );
354int Dsd_TreeCountNonTerminalNodes_rec(
Dsd_Node_t * pNode )
366 if ( pNode->
nDecs <= 1 )
370 for ( i = 0; i < pNode->
nDecs; i++ )
371 Counter += Dsd_TreeCountNonTerminalNodes_rec(
Dsd_Regular(pNode->
pDecs[i]) );
393 for ( i = 0; i < pDsdMan->
nRoots; i++ )
415 Counter = Dsd_TreeCountPrimeNodes_rec(
Dsd_Regular(pRoot) );
433int Dsd_TreeCountPrimeNodes_rec(
Dsd_Node_t * pNode )
445 if ( pNode->
nDecs <= 1 )
449 for ( i = 0; i < pNode->
nDecs; i++ )
476 Dsd_TreeCollectDecomposableVars_rec( pDsdMan->
dd,
Dsd_Regular(pDsdMan->
pRoots[0]), pVars, &nVars );
494int Dsd_TreeCollectDecomposableVars_rec( DdManager * dd,
Dsd_Node_t * pNode,
int * pVars,
int * nVars )
496 int fSkipThisNode, i;
503 if ( pNode->
nDecs <= 1 )
508 for ( i = 0; i < pNode->
nDecs; i++ )
509 if ( Dsd_TreeCollectDecomposableVars_rec(dd,
Dsd_Regular(pNode->
pDecs[i]), pVars, nVars) )
515printf(
"Node of type <%d> (OR=6,EXOR=8,RAND=1): ", pNode->
Type );
517 for ( i = 0; i < pNode->
nDecs; i++ )
523 pVars[ (*nVars)++ ] = pTemp->
S->index;
528printf(
"%d ", pTemp->
S->index );
538 return fSkipThisNode;
558 int nNodes, nNodesAlloc;
564 for ( i = 0; i < pDsdMan->
nRoots; i++ )
565 Dsd_TreeCollectNodesDfs_rec(
Dsd_Regular(pDsdMan->
pRoots[i]), ppNodes, &nNodes );
567 assert( nNodesAlloc == nNodes );
588 int nNodes, nNodesAlloc;
592 Dsd_TreeCollectNodesDfs_rec(
Dsd_Regular(pNode), ppNodes, &nNodes );
594 assert( nNodesAlloc == nNodes );
620 if ( pNode->
nDecs <= 1 )
624 for ( i = 0; i < pNode->
nDecs; i++ )
625 Dsd_TreeCollectNodesDfs_rec(
Dsd_Regular(pNode->
pDecs[i]), ppNodes, pnNodes );
627 ppNodes[ (*pnNodes)++ ] = pNode;
648 for (
int i = 0; i < pNode->
nDecs; i++ )
651 MaxBlock = Abc_MaxInt( MaxBlock, MaxThis );
660 for ( i = 0; i < pDsdMan->
nRoots; i++ )
666 assert( Output >= 0 && Output < pDsdMan->nRoots );
689 for (
int i = 0; i < pNode->
nDecs; i++ )
698 for ( i = 0; i < pDsdMan->
nRoots; i++ )
704 assert( Output >= 0 && Output < pDsdMan->nRoots );
723 Vec_StrPush(
p, (
int)(pNode->
S->index >= 26 ?
'A' - 26 :
'a') + pNode->
S->index );
727 Vec_StrPush(
p,
'{' );
729 Vec_StrPush(
p,
'(' );
731 Vec_StrPush(
p,
'[' );
733 for (
int i = 0; i < pNode->
nDecs; i++ )
736 if ( pInput != pNode->
pDecs[i] )
737 Vec_StrPush(
p,
'~' );
741 Vec_StrPush(
p,
'}' );
743 Vec_StrPush(
p,
')' );
745 Vec_StrPush(
p,
']' );
751 assert( Output >= 0 && Output < pDsdMan->nRoots );
753 int fCompl = pNode != pDsdMan->
pRoots[Output];
755 Vec_StrPush(
p, fCompl ?
'0' :
'1' );
758 Vec_StrPush(
p,
'~' );
761 Vec_StrPush(
p,
'\0' );
778 Vec_StrPush(
p, (
int)(pNode->
S->index >= 26 ?
'A' - 26 :
'a') + pNode->
S->index );
782 Vec_StrPush(
p,
'{' );
784 Vec_StrPush(
p,
'(' );
786 Vec_StrPush(
p,
'[' );
788 for (
int i = 0; i < pNode->
nDecs; i++ )
792 Vec_StrPush(
p,
'~' );
796 Vec_StrPush(
p,
'}' );
798 Vec_StrPush(
p,
')' );
800 Vec_StrPush(
p,
']' );
806 assert( Output >= 0 && Output < pDsdMan->nRoots );
808 int fCompl = pNode != pDsdMan->
pRoots[Output];
810 Vec_StrPush(
p, fCompl ?
'0' :
'1' );
813 Vec_StrPush(
p,
'~' );
816 Vec_StrPush(
p,
'\0' );
830void Dsd_TreePrint( FILE * pFile,
Dsd_Manager_t * pDsdMan,
char * pInputNames[],
char * pOutputNames[],
int fShortNames,
int Output,
int OffSet )
839 for ( i = 0; i < pDsdMan->
nRoots; i++ )
842 Dsd_TreePrint_rec( pFile, pNode, (pNode != pDsdMan->
pRoots[i]), pInputNames, pOutputNames[i], OffSet, &SigCounter, fShortNames );
847 assert( Output >= 0 && Output < pDsdMan->nRoots );
849 Dsd_TreePrint_rec( pFile, pNode, (pNode != pDsdMan->
pRoots[Output]), pInputNames, pOutputNames[Output], OffSet, &SigCounter, fShortNames );
864void Dsd_TreePrint_rec( FILE * pFile,
Dsd_Node_t * pNode,
int fComp,
char * pInputNames[],
char * pOutputName,
int nOffset,
int * pSigCounter,
int fShortNames )
876 fprintf( pFile,
"%s = ", pOutputName );
878 fprintf( pFile,
"~%s = ", pOutputName );
882 fprintf( pFile,
" Constant 1.\n" );
887 fprintf( pFile,
"%d",
'a' + pNode->
S->index );
889 fprintf( pFile,
"%s", pInputNames[pNode->
S->index] );
890 fprintf( pFile,
"\n" );
895 fprintf( pFile,
"PRIME(" );
896 for ( i = 0; i < pNode->
nDecs; i++ )
899 fCompNew = (int)( pInput != pNode->
pDecs[i] );
901 fprintf( pFile,
"," );
903 fprintf( pFile,
" ~" );
905 fprintf( pFile,
" " );
910 fprintf( pFile,
"%d", pInput->
S->index );
912 fprintf( pFile,
"%s", pInputNames[pInput->
S->index] );
916 pInputNums[i] = (*pSigCounter)++;
917 fprintf( pFile,
"<%d>", pInputNums[i] );
922 fprintf( pFile,
" )\n" );
924 for ( i = 0; i < pNode->
nDecs; i++ )
928 sprintf( Buffer,
"<%d>", pInputNums[i] );
929 Dsd_TreePrint_rec( pFile,
Dsd_Regular( pNode->
pDecs[i] ), 0, pInputNames, Buffer, nOffset + 6, pSigCounter, fShortNames );
935 fprintf( pFile,
"OR(" );
936 for ( i = 0; i < pNode->
nDecs; i++ )
939 fCompNew = (int)( pInput != pNode->
pDecs[i] );
941 fprintf( pFile,
"," );
943 fprintf( pFile,
" ~" );
945 fprintf( pFile,
" " );
950 fprintf( pFile,
"%c",
'a' + pInput->
S->index );
952 fprintf( pFile,
"%s", pInputNames[pInput->
S->index] );
956 pInputNums[i] = (*pSigCounter)++;
957 fprintf( pFile,
"<%d>", pInputNums[i] );
962 fprintf( pFile,
" )\n" );
964 for ( i = 0; i < pNode->
nDecs; i++ )
968 sprintf( Buffer,
"<%d>", pInputNums[i] );
969 Dsd_TreePrint_rec( pFile,
Dsd_Regular( pNode->
pDecs[i] ), 0, pInputNames, Buffer, nOffset + 6, pSigCounter, fShortNames );
975 fprintf( pFile,
"EXOR(" );
976 for ( i = 0; i < pNode->
nDecs; i++ )
979 fCompNew = (int)( pInput != pNode->
pDecs[i] );
981 fprintf( pFile,
"," );
983 fprintf( pFile,
" ~" );
985 fprintf( pFile,
" " );
990 fprintf( pFile,
"%c",
'a' + pInput->
S->index );
992 fprintf( pFile,
"%s", pInputNames[pInput->
S->index] );
996 pInputNums[i] = (*pSigCounter)++;
997 fprintf( pFile,
"<%d>", pInputNums[i] );
1002 fprintf( pFile,
" )\n" );
1004 for ( i = 0; i < pNode->
nDecs; i++ )
1005 if ( pInputNums[i] )
1008 sprintf( Buffer,
"<%d>", pInputNums[i] );
1009 Dsd_TreePrint_rec( pFile,
Dsd_Regular( pNode->
pDecs[i] ), 0, pInputNames, Buffer, nOffset + 6, pSigCounter, fShortNames );
1034 if ( Cudd_IsComplement(bFunc) )
1036 Level = dd->perm[bFunc->index];
1037 assert( Level >= 0 && Level < 6 );
1040 return (s_Truths6[Level] & Cof1) | (~s_Truths6[Level] & Cof0);
1047 fprintf( pFile,
"Const%d", !fComp );
1054 fprintf( pFile,
"%s", fComp?
"!" :
"" );
1055 fprintf( pFile,
"%s", pInputNames[pNode->
S->index] );
1059 fprintf( pFile,
" " );
1060 if ( pNode->
nDecs <= 6 )
1062 char pCanonPerm[6];
int uCanonPhase;
1067 Cudd_RecursiveDeref( dd, bFunc );
1070 fprintf( pFile,
"%s", (fComp ^ ((uCanonPhase >> pNode->
nDecs) & 1)) ?
"!" :
"" );
1071 Abc_TtPrintHexRev( pFile, &uTruth, pNode->
nDecs );
1072 fprintf( pFile,
"{" );
1073 for ( i = 0; i < pNode->
nDecs; i++ )
1078 fprintf( pFile,
"} " );
1082 fprintf( pFile,
"|%d|", pNode->
nDecs );
1083 fprintf( pFile,
"{" );
1084 for ( i = 0; i < pNode->
nDecs; i++ )
1086 fprintf( pFile,
"} " );
1091 fprintf( pFile,
"%s", !fComp?
"!" :
"" );
1092 fprintf( pFile,
"(" );
1093 for ( i = 0; i < pNode->
nDecs; i++ )
1095 fprintf( pFile,
")" );
1099 fprintf( pFile,
"%s", fComp?
"!" :
"" );
1100 fprintf( pFile,
"[" );
1101 for ( i = 0; i < pNode->
nDecs; i++ )
1103 fprintf( pFile,
"]" );
1111 for ( i = 0; i < pDsdMan->
nRoots; i++ )
1113 fprintf( pFile,
"%8s = ", pOutputNames[i] );
1115 fprintf( pFile,
"\n" );
1120 assert( Output >= 0 && Output < pDsdMan->nRoots );
1121 fprintf( pFile,
"%8s = ", pOutputNames[Output] );
1123 fprintf( pFile,
"\n" );
1143 Dsd_NodePrint_rec( pFile, pNodeR, pNodeR != pNode,
"F", 0, &SigCounter );
1157void Dsd_NodePrint_rec( FILE * pFile,
Dsd_Node_t * pNode,
int fComp,
char * pOutputName,
int nOffset,
int * pSigCounter )
1169 fprintf( pFile,
"%s = ", pOutputName );
1171 fprintf( pFile,
"~%s = ", pOutputName );
1175 fprintf( pFile,
" Constant 1.\n" );
1179 fprintf( pFile,
" " );
1180 fprintf( pFile,
"%c",
'a' + pNode->
S->index );
1181 fprintf( pFile,
"\n" );
1186 fprintf( pFile,
"PRIME(" );
1187 for ( i = 0; i < pNode->
nDecs; i++ )
1190 fCompNew = (int)( pInput != pNode->
pDecs[i] );
1193 fprintf( pFile,
"," );
1197 fprintf( pFile,
" %c",
'a' + pInput->
S->index );
1201 pInputNums[i] = (*pSigCounter)++;
1202 fprintf( pFile,
" <%d>", pInputNums[i] );
1205 fprintf( pFile,
"\'" );
1207 fprintf( pFile,
" )\n" );
1218 for ( i = 0; i < pNode->
nDecs; i++ )
1219 if ( pInputNums[i] )
1222 sprintf( Buffer,
"<%d>", pInputNums[i] );
1223 Dsd_NodePrint_rec( pFile,
Dsd_Regular( pNode->
pDecs[i] ), 0, Buffer, nOffset + 6, pSigCounter );
1229 fprintf( pFile,
"OR(" );
1230 for ( i = 0; i < pNode->
nDecs; i++ )
1233 fCompNew = (int)( pInput != pNode->
pDecs[i] );
1235 fprintf( pFile,
"," );
1239 fprintf( pFile,
" %c",
'a' + pInput->
S->index );
1243 pInputNums[i] = (*pSigCounter)++;
1244 fprintf( pFile,
" <%d>", pInputNums[i] );
1247 fprintf( pFile,
"\'" );
1249 fprintf( pFile,
" )\n" );
1251 for ( i = 0; i < pNode->
nDecs; i++ )
1252 if ( pInputNums[i] )
1255 sprintf( Buffer,
"<%d>", pInputNums[i] );
1256 Dsd_NodePrint_rec( pFile,
Dsd_Regular( pNode->
pDecs[i] ), 0, Buffer, nOffset + 6, pSigCounter );
1262 fprintf( pFile,
"EXOR(" );
1263 for ( i = 0; i < pNode->
nDecs; i++ )
1266 fCompNew = (int)( pInput != pNode->
pDecs[i] );
1269 fprintf( pFile,
"," );
1273 fprintf( pFile,
" %c",
'a' + pInput->
S->index );
1277 pInputNums[i] = (*pSigCounter)++;
1278 fprintf( pFile,
" <%d>", pInputNums[i] );
1281 fprintf( pFile,
"\'" );
1283 fprintf( pFile,
" )\n" );
1285 for ( i = 0; i < pNode->
nDecs; i++ )
1286 if ( pInputNums[i] )
1289 sprintf( Buffer,
"<%d>", pInputNums[i] );
1290 Dsd_NodePrint_rec( pFile,
Dsd_Regular( pNode->
pDecs[i] ), 0, Buffer, nOffset + 6, pSigCounter );
1311 DdNode * bCof0, * bCof1, * bCube0, * bCube1, * bNewFunc, * bTemp;
1326 bNewFunc = pNode->
G; Cudd_Ref( bNewFunc );
1328 for ( i = 0; i < pNode->
nDecs; i++ )
1332 bCof0 = Cudd_Cofactor( dd, bNewFunc, bCube0 ); Cudd_Ref( bCof0 );
1333 Cudd_RecursiveDeref( dd, bCube0 );
1336 bCof1 = Cudd_Cofactor( dd, bNewFunc, bCube1 ); Cudd_Ref( bCof1 );
1337 Cudd_RecursiveDeref( dd, bCube1 );
1339 Cudd_RecursiveDeref( dd, bNewFunc );
1344 bNewFunc = Cudd_bddIte( dd, dd->vars[pNode->
pDecs[i]->
S->index],bCof1,bCof0 ); Cudd_Ref( bNewFunc );
1345 Cudd_RecursiveDeref( dd, bCof0 );
1346 Cudd_RecursiveDeref( dd, bCof1 );
1353 for ( i = 0; i < pNode->
nDecs; i++ )
1355 Permute[ pNode->
pDecs[i]->
S->index ] = i;
1357 bNewFunc = Cudd_bddPermute( dd, bTemp = bNewFunc, Permute ); Cudd_Ref( bNewFunc );
1358 Cudd_RecursiveDeref( dd, bTemp );
1361 Cudd_Deref( bNewFunc );
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
struct Vec_Str_t_ Vec_Str_t
#define MAXINPUTS
INCLUDES ///.
unsigned Abc_TtCanonicize(word *pTruth, int nVars, char *pCanonPerm)
FUNCTION DECLARATIONS ///.
int Dsd_TreeCountPrimeNodesOne(Dsd_Node_t *pRoot)
void Dsd_TreePrint3_rec(Vec_Str_t *p, Dsd_Node_t *pNode)
Dsd_Node_t ** Dsd_TreeCollectNodesDfsOne(Dsd_Manager_t *pDsdMan, Dsd_Node_t *pNode, int *pnNodes)
void Dsd_TreeNodeGetInfoOne(Dsd_Node_t *pNode, int *DepthMax, int *GateSizeMax)
int Dsd_TreeCountPrimeNodes(Dsd_Manager_t *pDsdMan)
int Dsd_TreeNonDsdMax_rec(Dsd_Node_t *pNode)
int Dsd_TreeCountNonTerminalNodes(Dsd_Manager_t *pDsdMan)
word Dsd_TreeFunc2Truth_rec(DdManager *dd, DdNode *bFunc)
Dsd_Node_t * Dsd_TreeNodeCreate(int Type, int nDecs, int BlockNum)
FUNCTION DEFINITIONS ///.
void Dsd_TreePrint(FILE *pFile, Dsd_Manager_t *pDsdMan, char *pInputNames[], char *pOutputNames[], int fShortNames, int Output, int OffSet)
void Dsd_TreeNodeDelete(DdManager *dd, Dsd_Node_t *pNode)
int Dsd_TreeCountNonTerminalNodesOne(Dsd_Node_t *pRoot)
int Dsd_TreeSuppSize(Dsd_Manager_t *pDsdMan, int Output)
int Dsd_TreeCollectDecomposableVars(Dsd_Manager_t *pDsdMan, int *pVars)
void Dsd_TreePrint2_rec(FILE *pFile, DdManager *dd, Dsd_Node_t *pNode, int fComp, char *pInputNames[])
Dsd_Node_t ** Dsd_TreeCollectNodesDfs(Dsd_Manager_t *pDsdMan, int *pnNodes)
void Dsd_TreePrint4_rec(Vec_Str_t *p, Dsd_Node_t *pNode)
void Dsd_TreePrint4(void *pStr, Dsd_Manager_t *pDsdMan, int Output)
int Dsd_TreeGetAigCost(Dsd_Node_t *pNode)
void Dsd_TreePrint2(FILE *pFile, Dsd_Manager_t *pDsdMan, char *pInputNames[], char *pOutputNames[], int Output)
void Dsd_TreePrint3(void *pStr, Dsd_Manager_t *pDsdMan, int Output)
void Dsd_NodePrint(FILE *pFile, Dsd_Node_t *pNode)
void Dsd_TreeNodeGetInfo(Dsd_Manager_t *pDsdMan, int *DepthMax, int *GateSizeMax)
void Dsd_TreeUnmark(Dsd_Manager_t *pDsdMan)
int Dsd_TreeSuppSize_rec(Dsd_Node_t *pNode)
DdNode * Dsd_TreeGetPrimeFunctionOld(DdManager *dd, Dsd_Node_t *pNode, int fRemap)
int Dsd_TreeNonDsdMax(Dsd_Manager_t *pDsdMan, int Output)
int Dsd_TreeGetAigCost_rec(Dsd_Node_t *pNode)
enum Dsd_Type_t_ Dsd_Type_t
struct Dsd_Manager_t_ Dsd_Manager_t
TYPEDEF DEFINITIONS ///.
struct Dsd_Node_t_ Dsd_Node_t
DdNode * Dsd_TreeGetPrimeFunction(DdManager *dd, Dsd_Node_t *pNode)
FUNCTION DEFINITIONS ///.
#define Dsd_IsComplement(p)
MACRO DEFINITIONS ///.
unsigned __int64 word
DECLARATIONS ///.