58 #define PRD(p) printf( "\nDECOMPOSITION TREE:\n\n" ); PrintDecEntry( (p), 0 )
59 #define PRB_(f) printf( #f " = " ); Cudd_bddPrint(dd,f); printf( "\n" )
60 #define PRK(f,n) Cudd_PrintKMap(stdout,dd,(f),Cudd_Not(f),(n),NULL,0); printf( "K-map for function" #f "\n\n" )
61 #define PRK2(f,g,n) Cudd_PrintKMap(stdout,dd,(f),(g),(n),NULL,0); printf( "K-map for function <" #f ", " #g ">\n\n" )
94 char FileNameIni[100];
95 char FileNameFin[100];
106 strcpy( FileNameIni, pFileGeneric );
107 strcat( FileNameIni,
"_ENC.blif" );
109 strcpy( FileNameFin, pFileGeneric );
110 strcat( FileNameFin,
"_LUT.blif" );
115 for ( i = 0; i < nVarsEnc; i++ )
120 nNames = nVars + nVarsEnc;
121 for ( i = 0; i < nVars; i++ )
124 sprintf( Buffer,
"pi%03d", i );
128 for ( ; i < nNames; i++ )
130 sprintf( Buffer,
"OutEnc_%02d", i-nVars );
169 printf(
"MTBDD reordered = %6d nodes\n",
Cudd_DagSize( aFunc ) );
171 printf(
"Variable reordering time = %.2f sec\n", (
float)(
Abc_Clock() - clk1)/(
float)(CLOCKS_PER_SEC) );
189 // verification of single output function
196 g_Func.FileInput = Extra_UtilStrsav(FileNameIni);
198 if ( Extra_ReadFile( &g_Func ) == 0 )
200 printf( "\nSomething did not work out while reading the input file for verification\n");
201 Extra_Dissolve( &g_Func );
205 aRes = Cudd_BddToAdd( dd, g_Func.pOutputs[0] ); Cudd_Ref( aRes );
208 printf( "\nVerification FAILED!\n");
210 printf( "\nVerification okay!\n");
212 Cudd_RecursiveDeref( dd, aRes );
215 Extra_Dissolve( &g_Func );
217 printf( "Preliminary verification time = %.2f sec\n", (float)(Abc_Clock() - clk1)/(float)(CLOCKS_PER_SEC) );
226 // verification of the decomposed LUT network
233 g_Func.FileInput = Extra_UtilStrsav(FileNameFin);
235 if ( Extra_ReadFile( &g_Func ) == 0 )
237 printf( "\nSomething did not work out while reading the input file for verification\n");
238 Extra_Dissolve( &g_Func );
242 aRes = Cudd_BddToAdd( dd, g_Func.pOutputs[0] ); Cudd_Ref( aRes );
245 printf( "\nFinal verification FAILED!\n");
247 printf( "\nFinal verification okay!\n");
249 Cudd_RecursiveDeref( dd, aRes );
252 Extra_Dissolve( &g_Func );
254 printf( "Final verification time = %.2f sec\n", (float)(Abc_Clock() - clk1)/(float)(CLOCKS_PER_SEC) );
262 sprintf( Command,
"cec %s %s", FileNameIni, FileNameFin );
269 for ( i = 0; i < nNames; i++ )
292 void Experiment2( BFunc * pFunc )
295 int nVars = pFunc->nInputs;
296 int nOuts = pFunc->nOutputs;
308 char FileNameIni[100];
309 char FileNameFin[100];
321 strcpy( FileNameIni, pFunc->FileGeneric );
322 strcat( FileNameIni,
"_ENC.blif" );
324 strcpy( FileNameFin, pFunc->FileGeneric );
325 strcat( FileNameFin,
"_LUT.blif" );
331 printf(
"Single-output function derivation time = %.2f sec\n", (
float)(
Abc_Clock() - clk1)/(
float)(CLOCKS_PER_SEC) );
335 Extra_Dissolve( pFunc );
338 printf(
"\nReordering variables in the new manager...\n");
340 printf(
"Node count before = %d\n",
Cudd_DagSize( aFunc ) );
344 printf(
"Node count after = %d\n",
Cudd_DagSize( aFunc ) );
345 printf(
"Variable reordering time = %.2f sec\n", (
float)(
Abc_Clock() - clk1)/(
float)(CLOCKS_PER_SEC) );
353 nNames = DdNew->
size;
354 for ( x = 0; x < nNames; x++ )
365 printf(
"Single-output function writing time = %.2f sec\n", (
float)(
Abc_Clock() - clk1)/(
float)(CLOCKS_PER_SEC) );
378 if ( Extra_ReadFile( &g_Func ) == 0 )
380 printf(
"\nSomething did not work out while reading the input file for verification\n");
381 Extra_Dissolve( &g_Func );
388 printf(
"\nVerification FAILED!\n");
390 printf(
"\nVerification okay!\n");
395 Extra_Dissolve( &g_Func );
397 printf(
"Preliminary verification time = %.2f sec\n", (
float)(
Abc_Clock() - clk1)/(
float)(CLOCKS_PER_SEC) );
405 // verification of the decomposed LUT network
412 g_Func.FileInput = Extra_UtilStrsav(FileNameFin);
414 if ( Extra_ReadFile( &g_Func ) == 0 )
416 printf( "\nSomething did not work out while reading the input file for verification\n");
417 Extra_Dissolve( &g_Func );
421 aRes = Cudd_BddToAdd( DdNew, g_Func.pOutputs[0] ); Cudd_Ref( aRes );
424 printf( "\nFinal verification FAILED!\n");
426 printf( "\nFinal verification okay!\n");
428 Cudd_RecursiveDeref( DdNew, aRes );
431 Extra_Dissolve( &g_Func );
433 printf( "Final verification time = %.2f sec\n", (float)(Abc_Clock() - clk1)/(float)(CLOCKS_PER_SEC) );
441 for ( i = 0; i < nNames; i++ )
449 printf(
"\nThe number of referenced nodes in the new manager = %d\n", RetValue );
479 return ( s_SuppSize[*ptrY] - s_SuppSize[*ptrX] );
488 return ( s_MintOnes[*ptrY] - s_MintOnes[*ptrX] );
494 return BinCode ^ ( BinCode >> 1 );
511 DdNode * bResult, * aResult;
512 DdNode * bCube, * bTemp, * bProd;
518 for ( i = 0; i < nOuts; i++ )
527 qsort( (
void*)Order, nOuts,
sizeof(
int), (
int(*)(
const void*,
const void*))
CompareSupports );
533 for ( i = 0; i < nOuts; i++ )
548 printf(
"Single BDD size = %6d nodes\n",
Cudd_DagSize(bResult) );
616 for ( i = 0; i < nOuts; i++ )
623 for ( bTemp = bSupp; bTemp != dd->
one; bTemp =
cuddT(bTemp) )
624 Permute[bTemp->
index] = Counter++;
641 for ( i = 0; i < nOuts; i++ )
682 for ( i = 0; i < nOuts; i++ )
690 for ( bTemp = bSupp; bTemp != dd->
one; bTemp =
cuddT(bTemp) )
701 if ( nVarsMax < Counter )
715 for ( v = 0; v < nVarsEnc; v++ )
729 for ( v = 0; v < nVarsMax + nVarsEnc; v++ )
746 for ( i = 0; i < nOuts; i++ )
787 pFile = fopen( FileName,
"w" );
788 fprintf( pFile,
".model %s\n", FileName );
790 fprintf( pFile,
".inputs" );
791 for ( i = 0; i < nNames; i++ )
792 fprintf( pFile,
" %s", pNames[i] );
793 fprintf( pFile,
"\n" );
794 fprintf( pFile,
".outputs F" );
795 fprintf( pFile,
"\n" );
800 fprintf( pFile,
".end\n" );
826 long refAddr, diff, mask;
827 DdNode * Node, * Else, * ElseR, * Then;
850 while (
st__gen( gen, (
const char ** ) &Node, NULL ) )
852 diff |= refAddr ^ ( long ) Node;
858 for ( i = 0; ( unsigned ) i < 8 *
sizeof(
long ); i += 4 )
860 mask = ( 1 << i ) - 1;
867 fprintf( pFile,
".names %s%lx %s\n", Prefix, ( mask & (
long)
Cudd_Regular(Func) ) /
sizeof(
DdNode), OutputName );
872 while (
st__gen( gen, (
const char ** ) &Node, NULL ) )
877 fprintf( pFile,
".names %s%lx\n", Prefix, ( mask & (
long)Node ) /
sizeof(
DdNode) );
878 fprintf( pFile,
" %s\n", (
cuddV(Node) == 0.0)?
"0":
"1" );
889 fprintf( pFile,
".names %s %s%lx %s%lx %s%lx\n", InputNames[Node->
index],
890 Prefix, ( mask & (
long)ElseR ) /
sizeof(
DdNode),
891 Prefix, ( mask & (
long)Then ) /
sizeof(
DdNode),
892 Prefix, ( mask & (
long)Node ) /
sizeof(
DdNode) );
893 fprintf( pFile,
"01- 1\n" );
894 fprintf( pFile,
"1-1 1\n" );
899 fprintf( pFile,
".names %s %s%lx_i %s%lx %s%lx\n", InputNames[Node->
index],
900 Prefix, ( mask & (
long)ElseR ) /
sizeof(
DdNode),
901 Prefix, ( mask & (
long)Then ) /
sizeof(
DdNode),
902 Prefix, ( mask & (
long)Node ) /
sizeof(
DdNode) );
903 fprintf( pFile,
"01- 1\n" );
904 fprintf( pFile,
"1-1 1\n" );
907 if ( !
st__find( visited, (
char *)ElseR, (
char ***)&pSlot ) )
913 fprintf( pFile,
".names %s%lx %s%lx_i\n",
914 Prefix, ( mask & (
long)ElseR ) /
sizeof(
DdNode),
915 Prefix, ( mask & (
long)ElseR ) /
sizeof(
DdNode) );
916 fprintf( pFile,
"0 1\n" );
951 long refAddr, diff, mask;
952 DdNode * Node, * Else, * ElseR, * Then;
959 if ( s_ddmin == NULL )
995 while (
st__gen( gen, (
const char ** ) &Node, NULL ) )
997 diff |= refAddr ^ ( long ) Node;
1003 for ( i = 0; ( unsigned ) i < 8 *
sizeof(
long ); i += 4 )
1005 mask = ( 1 << i ) - 1;
1012 fprintf( pFile,
".names %s%lx %s\n", Prefix, ( mask & (
long)
Cudd_Regular(bFmin) ) /
sizeof(
DdNode), OutputName );
1017 while (
st__gen( gen, (
const char ** ) &Node, NULL ) )
1022 fprintf( pFile,
".names %s%lx\n", Prefix, ( mask & (
long)Node ) /
sizeof(
DdNode) );
1023 fprintf( pFile,
" %s\n", (
cuddV(Node) == 0.0)?
"0":
"1" );
1032 if ( Else == ElseR )
1034 fprintf( pFile,
".names %s %s%lx %s%lx %s%lx\n", InputNames[Node->
index],
1035 Prefix, ( mask & (
long)ElseR ) /
sizeof(
DdNode),
1036 Prefix, ( mask & (
long)Then ) /
sizeof(
DdNode),
1037 Prefix, ( mask & (
long)Node ) /
sizeof(
DdNode) );
1038 fprintf( pFile,
"01- 1\n" );
1039 fprintf( pFile,
"1-1 1\n" );
1043 fprintf( pFile,
".names %s %s%lx_i %s%lx %s%lx\n", InputNames[Node->
index],
1044 Prefix, ( mask & (
long)ElseR ) /
sizeof(
DdNode),
1045 Prefix, ( mask & (
long)Then ) /
sizeof(
DdNode),
1046 Prefix, ( mask & (
long)Node ) /
sizeof(
DdNode) );
1047 fprintf( pFile,
"01- 1\n" );
1048 fprintf( pFile,
"1-1 1\n" );
1050 fprintf( pFile,
".names %s%lx %s%lx_i\n",
1051 Prefix, ( mask & (
long)ElseR ) /
sizeof(
DdNode),
1052 Prefix, ( mask & (
long)ElseR ) /
sizeof(
DdNode) );
1053 fprintf( pFile,
"0 1\n" );
1103 while ( ddDestination->
reordered == 1 );
1136 if ( table == NULL )
1148 while (
st__gen( gen, (
const char ** ) &key, (
char ** ) &value ) )
1162 if ( table != NULL )
1205 if (
st__lookup( table, (
char * ) f, (
char ** ) &res ) )
1209 index = Permute[f->
index];
void st__free_table(st__table *table)
#define CUDD_UNIQUE_SLOTS
static int s_MintOnes[MAXOUTPUTS]
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
DdNode * cuddBddTransferPermute(DdManager *ddS, DdManager *ddD, DdNode *f, int *Permute)
DdNode * Cudd_bddTransferPermute(DdManager *ddSource, DdManager *ddDestination, DdNode *f, int *Permute)
void st__free_gen(st__generator *gen)
int Cmd_CommandExecute(void *pAbc, char *pCommandLine)
DdNode * Cudd_Support(DdManager *dd, DdNode *f)
void Cudd_Deref(DdNode *node)
#define MAXINPUTS
INCLUDES ///.
#define Cudd_IsConstant(node)
ABC_NAMESPACE_IMPL_START DdNode * GetSingleOutputFunction(DdManager *dd, DdNode **pbOuts, int nOuts, DdNode **pbVarsEnc, int nVarsEnc, int fVerbose)
static functions ///
static int s_SuppSize[MAXOUTPUTS]
SINGLE OUTPUT FUNCTION ///.
int Abc_CascadeExperiment(char *pFileGeneric, DdManager *dd, DdNode **pOutputs, int nInputs, int nOutputs, int nLutSize, int fCheck, int fVerbose)
EXTERNAL FUNCTIONS ///.
#define Cudd_Regular(node)
void WriteSingleOutputFunctionBlif(DdManager *dd, DdNode *aFunc, char **pNames, int nNames, char *FileName)
static DdNode *cuddBddTransferPermuteRecur ARGS((DdManager *ddS, DdManager *ddD, DdNode *f, st__table *table, int *Permute))
TRANSFER WITH MAPPING ///.
int st__ptrcmp(const char *, const char *)
static abctime Abc_Clock()
DdNode * Cudd_bddTransfer(DdManager *ddSource, DdManager *ddDestination, DdNode *f)
void WriteDDintoBLIFfileReorder(DdManager *dd, FILE *pFile, DdNode *Func, char *OutputName, char *Prefix, char **InputNames)
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
static DdNode * cuddBddTransferPermuteRecur(DdManager *ddS, DdManager *ddD, DdNode *f, st__table *table, int *Permute)
int CreateDecomposedNetwork(DdManager *dd, DdNode *aFunc, char **pNames, int nNames, char *FileName, int nLutSize, int fCheck, int fVerbose)
EXTERNAL FUNCTIONS ///.
#define Cudd_IsComplement(node)
int CompareMinterms(int *ptrX, int *ptrY)
DdNode * Cudd_bddNewVarAtLevel(DdManager *dd, int level)
int GrayCode(int BinCode)
DdNode * Cudd_bddPermute(DdManager *manager, DdNode *node, int *permut)
DdNode * GetSingleOutputFunctionRemappedNewDD(DdManager *dd, DdNode **pOutputs, int nOuts, DdManager **DdNew)
#define ABC_NAMESPACE_IMPL_END
DdManager * Cudd_Init(unsigned int numVars, unsigned int numVarsZ, unsigned int numSlots, unsigned int cacheSize, unsigned long maxMemory)
void * Abc_FrameGetGlobalFrame()
DdNode * GetSingleOutputFunctionRemapped(DdManager *dd, DdNode **pOutputs, int nOuts, DdNode **pbVarsEnc, int nVarsEnc)
INPUT REMAPPING ///.
int CompareSupports(int *ptrX, int *ptrY)
DdNode * Cudd_BddToAdd(DdManager *dd, DdNode *B)
DdNode * Cudd_bddOr(DdManager *dd, DdNode *f, DdNode *g)
int st__find(st__table *table, char *key, char ***slot)
st__generator * st__init_gen(st__table *table)
#define ABC_NAMESPACE_IMPL_START
int Cudd_CheckZeroRef(DdManager *manager)
void Cudd_AutodynDisable(DdManager *unique)
int st__lookup(st__table *table, const char *key, char **value)
static DdManager * s_ddmin
static int Abc_Base2Log(unsigned n)
int st__add_direct(st__table *table, char *key, char *value)
#define Cudd_NotCond(node, c)
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
int cuddCollectNodes(DdNode *f, st__table *visited)
void Cudd_Quit(DdManager *unique)
int Cudd_ReduceHeap(DdManager *table, Cudd_ReorderingType heuristic, int minsize)
void Cudd_AutodynEnable(DdManager *unique, Cudd_ReorderingType method)
void WriteDDintoBLIFfile(FILE *pFile, DdNode *Func, char *OutputName, char *Prefix, char **InputNames)
BLIF WRITING FUNCTIONS ///.
int Cudd_SupportSize(DdManager *dd, DdNode *f)
int st__ptrhash(const char *, int)
DdNode * cuddUniqueInter(DdManager *unique, int index, DdNode *T, DdNode *E)
int st__gen(st__generator *gen, const char **key_p, char **value_p)
int Cudd_DagSize(DdNode *node)
DdNode * cuddBddIteRecur(DdManager *dd, DdNode *f, DdNode *g, DdNode *h)