00001
00019 #include "reo.h"
00020
00024
00028
00040 void Extra_ReorderTest( DdManager * dd, DdNode * Func )
00041 {
00042 reo_man * pReo;
00043 DdNode * Temp, * Temp1;
00044 int pOrder[1000];
00045
00046 pReo = Extra_ReorderInit( 100, 100 );
00047
00048
00049 Temp = Extra_Reorder( pReo, dd, Func, pOrder ); Cudd_Ref( Temp );
00050
00051
00052 Temp1 = Extra_ReorderCudd(dd, Func, NULL ); Cudd_Ref( Temp1 );
00053 printf( "Initial = %d. Final = %d. Cudd = %d.\n", Cudd_DagSize(Func), Cudd_DagSize(Temp), Cudd_DagSize(Temp1) );
00054 Cudd_RecursiveDeref( dd, Temp1 );
00055 Cudd_RecursiveDeref( dd, Temp );
00056
00057 Extra_ReorderQuit( pReo );
00058 }
00059
00060
00072 void Extra_ReorderTestArray( DdManager * dd, DdNode * Funcs[], int nFuncs )
00073 {
00074 reo_man * pReo;
00075 DdNode * FuncsRes[1000];
00076 int pOrder[1000];
00077 int i;
00078
00079 pReo = Extra_ReorderInit( 100, 100 );
00080 Extra_ReorderArray( pReo, dd, Funcs, FuncsRes, nFuncs, pOrder );
00081 Extra_ReorderQuit( pReo );
00082
00083 printf( "Initial = %d. Final = %d.\n", Cudd_SharingSize(Funcs,nFuncs), Cudd_SharingSize(FuncsRes,nFuncs) );
00084
00085 for ( i = 0; i < nFuncs; i++ )
00086 Cudd_RecursiveDeref( dd, FuncsRes[i] );
00087
00088 }
00089
00106 DdNode * Extra_ReorderCudd( DdManager * dd, DdNode * aFunc, int pPermuteReo[] )
00107 {
00108 static DdManager * ddReorder = NULL;
00109 static int * Permute = NULL;
00110 static int * PermuteReo1 = NULL;
00111 static int * PermuteReo2 = NULL;
00112 DdNode * aFuncReorder, * aFuncNew;
00113 int lev, var;
00114
00115
00116 if ( ddReorder == NULL )
00117 {
00118 Permute = ALLOC( int, dd->size );
00119 PermuteReo1 = ALLOC( int, dd->size );
00120 PermuteReo2 = ALLOC( int, dd->size );
00121 ddReorder = Cudd_Init( dd->size, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
00122 Cudd_AutodynDisable(ddReorder);
00123 }
00124
00125
00126
00127 for ( lev = 0; lev < dd->size; lev++ )
00128 {
00129 Permute[ dd->invperm[lev] ] = ddReorder->invperm[lev];
00130 PermuteReo1[ ddReorder->invperm[lev] ] = dd->invperm[lev];
00131 }
00132
00133 aFuncReorder = Extra_TransferPermute( dd, ddReorder, aFunc, Permute ); Cudd_Ref( aFuncReorder );
00134
00135
00136
00137 printf( "Nodes before = %d.\n", Cudd_DagSize(aFuncReorder) );
00138 Cudd_ReduceHeap( ddReorder, CUDD_REORDER_SYMM_SIFT, 1 );
00139 printf( "Nodes before = %d.\n", Cudd_DagSize(aFuncReorder) );
00140
00141
00142 for ( lev = 0; lev < dd->size; lev++ )
00143 {
00144 Permute[ ddReorder->invperm[lev] ] = dd->invperm[lev];
00145 PermuteReo2[ dd->invperm[lev] ] = ddReorder->invperm[lev];
00146 }
00147
00148
00149 aFuncNew = Extra_TransferPermute( ddReorder, dd, aFuncReorder, Permute ); Cudd_Ref( aFuncNew );
00150
00151 Cudd_RecursiveDeref( ddReorder, aFuncReorder );
00152
00153
00154 if ( pPermuteReo )
00155 for ( var = 0; var < dd->size; var++ )
00156 pPermuteReo[var] = PermuteReo1[ PermuteReo2[var] ];
00157
00158 Cudd_Deref( aFuncNew );
00159 return aFuncNew;
00160 }
00161
00162
00177 int Extra_bddReorderTest( DdManager * dd, DdNode * bF )
00178 {
00179 static DdManager * s_ddmin;
00180 DdNode * bFmin;
00181 int nNodes;
00182
00183
00184 if ( s_ddmin == NULL )
00185 s_ddmin = Cudd_Init( dd->size, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0);
00186
00187
00188
00189
00190 bFmin = Cudd_bddTransfer( dd, s_ddmin, bF ); Cudd_Ref( bFmin );
00191 Cudd_ReduceHeap(s_ddmin,CUDD_REORDER_SIFT,1);
00192
00193 nNodes = Cudd_DagSize( bFmin );
00194 Cudd_RecursiveDeref( s_ddmin, bFmin );
00195
00196
00197 return nNodes;
00198 }
00199
00214 int Extra_addReorderTest( DdManager * dd, DdNode * aF )
00215 {
00216 static DdManager * s_ddmin;
00217 DdNode * bF;
00218 DdNode * bFmin;
00219 DdNode * aFmin;
00220 int nNodesBeg;
00221 int nNodesEnd;
00222 int clk1;
00223
00224 if ( s_ddmin == NULL )
00225 s_ddmin = Cudd_Init( dd->size, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0);
00226
00227
00228
00229 clk1 = clock();
00230 bF = Cudd_addBddPattern( dd, aF ); Cudd_Ref( bF );
00231 bFmin = Cudd_bddTransfer( dd, s_ddmin, bF ); Cudd_Ref( bFmin );
00232 Cudd_RecursiveDeref( dd, bF );
00233 aFmin = Cudd_BddToAdd( s_ddmin, bFmin ); Cudd_Ref( aFmin );
00234 Cudd_RecursiveDeref( s_ddmin, bFmin );
00235
00236 nNodesBeg = Cudd_DagSize( aFmin );
00237 Cudd_ReduceHeap(s_ddmin,CUDD_REORDER_SIFT,1);
00238
00239 nNodesEnd = Cudd_DagSize( aFmin );
00240 Cudd_RecursiveDeref( s_ddmin, aFmin );
00241
00242 printf( "Classical reordering of ADDs: Before = %d. After = %d.\n", nNodesBeg, nNodesEnd );
00243 printf( "Classical variable reordering time = %.2f sec\n", (float)(clock() - clk1)/(float)(CLOCKS_PER_SEC) );
00244 return nNodesEnd;
00245 }
00246
00247
00251