VIS

src/restr/restrCProj.c

Go to the documentation of this file.
00001 
00025 #include "restrInt.h"
00026 
00027 /*---------------------------------------------------------------------------*/
00028 /* Constant declarations                                                     */
00029 /*---------------------------------------------------------------------------*/
00030 
00031 
00032 /*---------------------------------------------------------------------------*/
00033 /* Type declarations                                                         */
00034 /*---------------------------------------------------------------------------*/
00035 
00036 
00037 /*---------------------------------------------------------------------------*/
00038 /* Structure declarations                                                    */
00039 /*---------------------------------------------------------------------------*/
00040 
00041 /*---------------------------------------------------------------------------*/
00042 /* Variable declarations                                                     */
00043 /*---------------------------------------------------------------------------*/
00044 
00045 
00046 /*---------------------------------------------------------------------------*/
00047 /* Macro declarations                                                        */
00048 /*---------------------------------------------------------------------------*/
00049 
00050 
00053 /*---------------------------------------------------------------------------*/
00054 /* Static function prototypes                                                */
00055 /*---------------------------------------------------------------------------*/
00056 
00057 
00061 /*---------------------------------------------------------------------------*/
00062 /* Definition of exported functions                                          */
00063 /*---------------------------------------------------------------------------*/
00064 
00065 /*---------------------------------------------------------------------------*/
00066 /* Definition of internal functions                                          */
00067 /*---------------------------------------------------------------------------*/
00068 
00094 bdd_node *
00095 RestrMinimizeFsmByCProj(
00096   bdd_manager   *ddManager,
00097   bdd_node      *equivRel,
00098   bdd_node      *originalTR,
00099   bdd_node      *initBdd,
00100   bdd_node      **xVars,
00101   bdd_node      **yVars,
00102   bdd_node      **uVars,
00103   bdd_node      **vVars,
00104   bdd_node      **piVars,
00105   int           nVars,
00106   int           nPi,
00107   array_t       **outBdds,
00108   bdd_node      **newInit)
00109 
00110 {
00111   bdd_node *resultYV, *temp, *temp1, *temp2;
00112   bdd_node *result, *resultXU;
00113   bdd_node *xCube, *yCube;
00114   bdd_node *oneInitState;
00115   array_t *newOutBdds;
00116   int i;
00117 
00118   /* Select one state from the set of initial states. This is redundant in case
00119      of circuits described in blif format.*/
00120   oneInitState = bdd_bdd_pick_one_minterm(ddManager,initBdd,xVars,nVars);
00121   bdd_ref(oneInitState);
00122 
00123   temp = bdd_bdd_swap_variables(ddManager,oneInitState,xVars,vVars,nVars);
00124   bdd_ref(temp);
00125   bdd_recursive_deref(ddManager,oneInitState);
00126 
00127   /* Select a representative for each equivalence class. The vVars encode the
00128    * representative for each class. resultYV has yVars and vVars in its
00129    * support. equivRel is a function of yVars and vVars.
00130    */
00131   resultYV = bdd_bdd_cprojection(ddManager, equivRel, temp);
00132   bdd_ref(resultYV);
00133   bdd_recursive_deref(ddManager,temp);
00134 
00135   temp = bdd_bdd_swap_variables(ddManager,resultYV,yVars,xVars,nVars);
00136   bdd_ref(temp);
00137   resultXU = bdd_bdd_swap_variables(ddManager,temp,vVars,uVars,nVars);
00138   bdd_ref(resultXU);
00139   bdd_recursive_deref(ddManager, temp);
00140 
00141   /* Change the initBdd accordingly
00142    * initBdd^{new} = [\exists_x (initBdd(x) * result(x,u))]_{u=x}
00143    */
00144   xCube = bdd_bdd_compute_cube(ddManager,xVars,NIL(int),nVars);
00145   bdd_ref(xCube);
00146   bdd_ref(temp1 = bdd_bdd_and_abstract(ddManager,initBdd,resultXU,
00147                                        xCube));
00148   bdd_ref(*newInit = bdd_bdd_swap_variables(ddManager,temp1,uVars,
00149                                             xVars,nVars));
00150   bdd_recursive_deref(ddManager,temp1);
00151 
00152   /* compute the new TR.
00153    * TR^{new}(x,w,y) = 
00154    *    [\exists_{xy}(result(x,u) * TR(x,w,y) * result(y,v))]_{u=x,v=y}
00155    * result is the new restructured/minimized TR.
00156    */
00157   bdd_ref(yCube = bdd_bdd_compute_cube(ddManager,yVars,NIL(int),nVars));
00158   bdd_ref(temp = bdd_bdd_and_abstract(ddManager,resultYV,originalTR,yCube));
00159   bdd_recursive_deref(ddManager,resultYV);
00160   bdd_recursive_deref(ddManager,yCube);
00161 
00162   bdd_ref(result = bdd_bdd_and_abstract(ddManager,temp,resultXU,xCube));
00163   bdd_recursive_deref(ddManager,temp);
00164 
00165   bdd_ref(temp = bdd_bdd_swap_variables(ddManager,result,uVars,
00166                                         xVars,nVars));
00167   bdd_recursive_deref(ddManager,result);
00168   bdd_ref(result = bdd_bdd_swap_variables(ddManager,temp,vVars,
00169                                           yVars,nVars));
00170   bdd_recursive_deref(ddManager,temp);
00171 
00172   /* Change the outputs accordingly
00173    * lambda^{new}_i(x,w) = [\exists_x (lambda_i(x,w) * result(x,u))]_{u=x}
00174    *
00175    * lambda_i(x,w) is the ith primary output.
00176    */
00177   newOutBdds = array_alloc(bdd_node *,0);
00178   arrayForEachItem(bdd_node *,*outBdds,i,temp) {
00179     temp1 = bdd_bdd_and_abstract(ddManager,temp,resultXU,xCube);
00180     bdd_ref(temp1);
00181     temp2 = bdd_bdd_swap_variables(ddManager,temp1,uVars,xVars,nVars);
00182     bdd_ref(temp2);
00183     bdd_recursive_deref(ddManager,temp1);
00184     array_insert_last(bdd_node *,newOutBdds,temp2);
00185   }
00186   bdd_recursive_deref(ddManager, xCube);
00187   bdd_recursive_deref(ddManager,resultXU);
00188 
00189 #ifdef RESTR_DIAG
00190   {
00191     int flag1,flag2;
00192 
00193     (void) fprintf(vis_stdout,"Old transition relation ...\n");
00194     flag1 = RestrTestIsDeterministic(ddManager,originalTR,initBdd,
00195                                      xVars,yVars,nVars);
00196     (void) fprintf(vis_stdout,"New transition relation ...\n");
00197     flag2 = RestrTestIsDeterministic(ddManager,result,*newInit,
00198                                      xVars,yVars,nVars);
00199   }
00200 #endif
00201   
00202   /* Delete the old array */
00203   arrayForEachItem(bdd_node *,*outBdds,i,temp) {
00204     bdd_recursive_deref(ddManager,temp);
00205   }
00206   array_free(*outBdds);
00207   *outBdds = newOutBdds;
00208   
00209   return result;
00210 
00211 }
00212 
00213 /*---------------------------------------------------------------------------*/
00214 /* Definition of static functions                                            */
00215 /*---------------------------------------------------------------------------*/