⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cuddsplit.c

📁 主要进行大规模的电路综合
💻 C
📖 第 1 页 / 共 2 页
字号:
/**CFile***********************************************************************  FileName    [cuddSplit.c]  PackageName [cudd]  Synopsis    [Returns a subset of minterms from a boolean function.]  Description [External functions included in this modoule:		<ul>		<li> Cudd_SplitSet()		</ul>	Internal functions included in this module:		<ul>		<li> cuddSplitSetRecur()		</u>        Static functions included in this module:		<ul>		<li> selectMintermsFromUniverse()		<li> mintermsFromUniverse()		<li> bddAnnotateMintermCount()		</ul> ]  SeeAlso     []  Author      [Balakrishna Kumthekar]  Copyright [This file was created at the University of Colorado at  Boulder.  The University of Colorado at Boulder makes no warranty  about the suitability of this software for any purpose.  It is  presented on an AS IS basis.]******************************************************************************/#include "util.h"#include "cuddInt.h"/*---------------------------------------------------------------------------*//* Constant declarations                                                     *//*---------------------------------------------------------------------------*//*---------------------------------------------------------------------------*//* Type declarations                                                         *//*---------------------------------------------------------------------------*//*---------------------------------------------------------------------------*//* Structure declarations                                                    *//*---------------------------------------------------------------------------*//*---------------------------------------------------------------------------*//* Variable declarations                                                     *//*---------------------------------------------------------------------------*//*---------------------------------------------------------------------------*//* Macro declarations                                                        *//*---------------------------------------------------------------------------*//**AutomaticStart*************************************************************//*---------------------------------------------------------------------------*//* Static function prototypes                                                *//*---------------------------------------------------------------------------*/static DdNode * selectMintermsFromUniverse ARGS((DdManager *manager, int *varSeen, double n));static DdNode * mintermsFromUniverse ARGS((DdManager *manager, DdNode **vars, int numVars, double n, int index));static double bddAnnotateMintermCount ARGS((DdManager *manager, DdNode *node, double max, st_table *table));/**AutomaticEnd***************************************************************//*---------------------------------------------------------------------------*//* Definition of exported functions                                          *//*---------------------------------------------------------------------------*//**Function********************************************************************  Synopsis    [Returns m minterms from a BDD.]  Description [Returns <code>m</code> minterms from a BDD whose  support has <code>n</code> variables at most.  The procedure tries  to create as few extra nodes as possible. The function represented  by <code>S</code> depends on at most <code>n</code> of the variables  in <code>xVars</code>. Returns a BDD with <code>m</code> minterms  of the on-set of S if successful; NULL otherwise.]  SideEffects [None]  SeeAlso     []******************************************************************************/DdNode *Cudd_SplitSet(  DdManager * manager,  DdNode * S,  DdNode ** xVars,  int  n,  double  m){    DdNode *result;    DdNode *zero, *one;    double  max, num;    st_table *mtable;    int *varSeen;    int i,index, size;    size = manager->size;    one = DD_ONE(manager);    zero = Cudd_Not(one);    /* Trivial cases. */    if (m == 0.0) {	return(zero);    }    if (S == zero) {	return(NULL);    }    max = pow(2.0,(double)n);    if (m > max)	return(NULL);    do {	manager->reordered = 0;	/* varSeen is used to mark the variables that are encountered	** while traversing the BDD S.	*/	varSeen = ALLOC(int, size);	if (varSeen == NULL) {	    manager->errorCode = CUDD_MEMORY_OUT;	    return(NULL);	}	for (i = 0; i < size; i++) {	    varSeen[i] = -1;	}	for (i = 0; i < n; i++) {	    index = (xVars[i])->index;	    varSeen[manager->invperm[index]] = 0;	}	if (S == one) {	    if (m == max) 		return(S);	    result = selectMintermsFromUniverse(manager,varSeen,m);	    if (result)		cuddRef(result);	    FREE(varSeen);	} else {	    mtable = st_init_table(st_ptrcmp,st_ptrhash);	    if (mtable == NULL) {		(void) fprintf(manager->out,			       "Cudd_SplitSet: out-of-memory.\n");		FREE(varSeen);		manager->errorCode = CUDD_MEMORY_OUT;		return(NULL);	    }	    /* The nodes of BDD S are annotated by the number of minterms	    ** in their onset. The node and the number of minterms in its	    ** onset are stored in mtable.	    */	    num = bddAnnotateMintermCount(manager,S,max,mtable);	    if (m == num) {		st_foreach(mtable,cuddStCountfree,NIL(char));		st_free_table(mtable);		FREE(varSeen);		return(S);	    }	    	    result = cuddSplitSetRecur(manager,mtable,varSeen,S,m,max,0);	    if (result)		cuddRef(result);	    st_foreach(mtable,cuddStCountfree,NULL);	    st_free_table(mtable);	    FREE(varSeen);	}    } while (manager->reordered == 1);    cuddDeref(result);    return(result);} /* end of Cudd_SplitSet *//*---------------------------------------------------------------------------*//* Definition of internal functions                                          *//*---------------------------------------------------------------------------*//**Function********************************************************************  Synopsis    [Implements the recursive step of Cudd_SplitSet.]  Description [Implements the recursive step of Cudd_SplitSet. The  procedure recursively traverses the BDD and checks to see if any  node satisfies the minterm requirements as specified by 'n'. At any  node X, n is compared to the number of minterms in the onset of X's  children. If either of the child nodes have exactly n minterms, then  that node is returned; else, if n is greater than the onset of one  of the child nodes, that node is retained and the difference in the  number of minterms is extracted from the other child. In case n  minterms can be extracted from constant 1, the algorithm returns the  result with at most log(n) nodes.]  SideEffects [The array 'varSeen' is updated at every recursive call  to set the variables traversed by the procedure.]  SeeAlso     []******************************************************************************/DdNode*cuddSplitSetRecur(  DdManager * manager,  st_table * mtable,  int * varSeen,  DdNode * p,  double  n,  double  max,  int  index){    DdNode *one, *zero, *N, *Nv;    DdNode *Nnv, *q, *r, *v;    DdNode *result;    double *dummy, numT, numE;    int variable, positive;      statLine(manager);    one = DD_ONE(manager);    zero = Cudd_Not(one);    /* If p is constant, extract n minterms from constant 1.  The procedure by    ** construction guarantees that minterms will not be extracted from    ** constant 0.    */    if (Cudd_IsConstant(p)) {	q = selectMintermsFromUniverse(manager,varSeen,n);	return(q);    }    N = Cudd_Regular(p);    /* Set variable as seen. */    variable = N->index;    varSeen[manager->invperm[variable]] = -1;    Nv = cuddT(N);    Nnv = cuddE(N);    if (Cudd_IsComplement(p)) {	Nv = Cudd_Not(Nv);	Nnv = Cudd_Not(Nnv);    }    /* If both the children of 'p' are constants, extract n minterms from a    ** constant node.    */    if (Cudd_IsConstant(Nv) && Cudd_IsConstant(Nnv)) {	q = selectMintermsFromUniverse(manager,varSeen,n);	if (q == NULL) {	    return(NULL);	}	cuddRef(q);	r = cuddBddAndRecur(manager,p,q);	if (r == NULL) {	    Cudd_RecursiveDeref(manager,q);	    return(NULL);	}	cuddRef(r);	Cudd_RecursiveDeref(manager,q);	cuddDeref(r);	return(r);    }      /* Lookup the # of minterms in the onset of the node from the table. */    if (!Cudd_IsConstant(Nv)) {	st_lookup(mtable,(char *)Nv, (char **)&dummy);	numT = *dummy/(2*(1<<index));    } else if (Nv == one) {	numT = max/(2*(1<<index));    } else {	numT = 0;    }      if (!Cudd_IsConstant(Nnv)) {	st_lookup(mtable,(char *)Nnv, (char **)&dummy);	numE = *dummy/(2*(1<<index));    } else if (Nnv == one) {	numE = max/(2*(1<<index));    } else {	numE = 0;    }    v = cuddUniqueInter(manager,variable,one,zero);    cuddRef(v);    /* If perfect match. */    if (numT == n) {	q = cuddBddAndRecur(manager,v,Nv);	if (q == NULL) {	    Cudd_RecursiveDeref(manager,v);	    return(NULL);	}	cuddRef(q);	Cudd_RecursiveDeref(manager,v);	cuddDeref(q);	return(q);    }    if (numE == n) {	q = cuddBddAndRecur(manager,Cudd_Not(v),Nnv);	if (q == NULL) {	    Cudd_RecursiveDeref(manager,v);	    return(NULL);	}	cuddRef(q);	Cudd_RecursiveDeref(manager,v);	cuddDeref(q);	return(q);    }    /* If n is greater than numT, extract the difference from the ELSE child    ** and retain the function represented by the THEN branch.    */    if (numT < n) {	q = cuddSplitSetRecur(manager,mtable,varSeen,			      Nnv,(n-numT),max,index+1);	if (q == NULL) {	    Cudd_RecursiveDeref(manager,v);	    return(NULL);	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -