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

📄 cuddmatmult.c

📁 主要进行大规模的电路综合
💻 C
📖 第 1 页 / 共 2 页
字号:
/**CFile***********************************************************************  FileName    [cuddMatMult.c]  PackageName [cudd]  Synopsis    [Matrix multiplication functions.]  Description [External procedures included in this module:		<ul>		<li> Cudd_addMatrixMultiply()		<li> Cudd_addTimesPlus()		<li> Cudd_addTriangle()		<li> Cudd_addOuterSum()		</ul>	Static procedures included in this module:		<ul>		<li> addMMRecur()		<li> addTriangleRecur()		<li> cuddAddOuterSumRecur()		</ul>]  Author      [Fabio Somenzi]  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                                                     *//*---------------------------------------------------------------------------*//*---------------------------------------------------------------------------*//* Stucture declarations                                                     *//*---------------------------------------------------------------------------*//*---------------------------------------------------------------------------*//* Type declarations                                                         *//*---------------------------------------------------------------------------*//*---------------------------------------------------------------------------*//* Variable declarations                                                     *//*---------------------------------------------------------------------------*/#ifndef lintstatic char rcsid[] DD_UNUSED = "$Id: cuddMatMult.c,v 1.1.1.1 2003/02/24 22:23:52 wjiang Exp $";#endif/*---------------------------------------------------------------------------*//* Macro declarations                                                        *//*---------------------------------------------------------------------------*//**AutomaticStart*************************************************************//*---------------------------------------------------------------------------*//* Static function prototypes                                                *//*---------------------------------------------------------------------------*/static DdNode * addMMRecur ARGS((DdManager *dd, DdNode *A, DdNode *B, int topP, int *vars));static DdNode * addTriangleRecur ARGS((DdManager *dd, DdNode *f, DdNode *g, int *vars, DdNode *cube));static DdNode * cuddAddOuterSumRecur ARGS((DdManager *dd, DdNode *M, DdNode *r, DdNode *c));/**AutomaticEnd***************************************************************//*---------------------------------------------------------------------------*//* Definition of exported functions                                          *//*---------------------------------------------------------------------------*//**Function********************************************************************  Synopsis [Calculates the product of two matrices represented as  ADDs.]  Description [Calculates the product of two matrices, A and B,  represented as ADDs. This procedure implements the quasiring multiplication  algorithm.  A is assumed to depend on variables x (rows) and z  (columns).  B is assumed to depend on variables z (rows) and y  (columns).  The product of A and B then depends on x (rows) and y  (columns).  Only the z variables have to be explicitly identified;  they are the "summation" variables.  Returns a pointer to the  result if successful; NULL otherwise.]  SideEffects [None]  SeeAlso     [Cudd_addTimesPlus Cudd_addTriangle Cudd_bddAndAbstract]******************************************************************************/DdNode *Cudd_addMatrixMultiply(  DdManager * dd,  DdNode * A,  DdNode * B,  DdNode ** z,  int  nz){    int i, nvars, *vars;    DdNode *res;     /* Array vars says what variables are "summation" variables. */    nvars = dd->size;    vars = ALLOC(int,nvars);    if (vars == NULL) {	dd->errorCode = CUDD_MEMORY_OUT;	return(NULL);    }    for (i = 0; i < nvars; i++) {        vars[i] = 0;    }    for (i = 0; i < nz; i++) {        vars[z[i]->index] = 1;    }    do {	dd->reordered = 0;	res = addMMRecur(dd,A,B,-1,vars);    } while (dd->reordered == 1);    FREE(vars);    return(res);} /* end of Cudd_addMatrixMultiply *//**Function********************************************************************  Synopsis    [Calculates the product of two matrices represented as  ADDs.]  Description [Calculates the product of two matrices, A and B,  represented as ADDs, using the CMU matrix by matrix multiplication  procedure by Clarke et al..  Matrix A has x's as row variables and z's  as column variables, while matrix B has z's as row variables and y's  as column variables. Returns the pointer to the result if successful;  NULL otherwise. The resulting matrix has x's as row variables and y's  as column variables.]  SideEffects [None]  SeeAlso     [Cudd_addMatrixMultiply]******************************************************************************/DdNode *Cudd_addTimesPlus(  DdManager * dd,  DdNode * A,  DdNode * B,  DdNode ** z,  int  nz){    DdNode *w, *cube, *tmp, *res;     int i;    tmp = Cudd_addApply(dd,Cudd_addTimes,A,B);    if (tmp == NULL) return(NULL);    Cudd_Ref(tmp);    Cudd_Ref(cube = DD_ONE(dd));    for (i = nz-1; i >= 0; i--) {	 w = Cudd_addIte(dd,z[i],cube,DD_ZERO(dd));	 if (w == NULL) {	    Cudd_RecursiveDeref(dd,tmp);	    return(NULL);	 }	 Cudd_Ref(w);	 Cudd_RecursiveDeref(dd,cube);	 cube = w;    }    res = Cudd_addExistAbstract(dd,tmp,cube);    if (res == NULL) {	Cudd_RecursiveDeref(dd,tmp);	Cudd_RecursiveDeref(dd,cube);	return(NULL);    }    Cudd_Ref(res);    Cudd_RecursiveDeref(dd,cube);    Cudd_RecursiveDeref(dd,tmp);    Cudd_Deref(res);    return(res);} /* end of Cudd_addTimesPlus *//**Function********************************************************************  Synopsis    [Performs the triangulation step for the shortest path  computation.]  Description [Implements the semiring multiplication algorithm used in  the triangulation step for the shortest path computation.  f  is assumed to depend on variables x (rows) and z (columns).  g is  assumed to depend on variables z (rows) and y (columns).  The product  of f and g then depends on x (rows) and y (columns).  Only the z  variables have to be explicitly identified; they are the  "abstraction" variables.  Returns a pointer to the result if  successful; NULL otherwise. ]  SideEffects [None]  SeeAlso     [Cudd_addMatrixMultiply Cudd_bddAndAbstract]******************************************************************************/DdNode *Cudd_addTriangle(  DdManager * dd,  DdNode * f,  DdNode * g,  DdNode ** z,  int  nz){    int    i, nvars, *vars;    DdNode *res, *cube;    nvars = dd->size;    vars = ALLOC(int, nvars);    if (vars == NULL) {	dd->errorCode = CUDD_MEMORY_OUT;	return(NULL);    }    for (i = 0; i < nvars; i++) vars[i] = -1;    for (i = 0; i < nz; i++) vars[z[i]->index] = i;    cube = Cudd_addComputeCube(dd, z, NULL, nz);    if (cube == NULL) {	FREE(vars);	return(NULL);    }    cuddRef(cube);    do {	dd->reordered = 0;	res = addTriangleRecur(dd, f, g, vars, cube);    } while (dd->reordered == 1);    if (res != NULL) cuddRef(res);    Cudd_RecursiveDeref(dd,cube);    if (res != NULL) cuddDeref(res);    FREE(vars);    return(res);} /* end of Cudd_addTriangle *//**Function********************************************************************  Synopsis    [Takes the minimum of a matrix and the outer sum of two vectors.]  Description [Takes the pointwise minimum of a matrix and the outer  sum of two vectors.  This procedure is used in the Floyd-Warshall  all-pair shortest path algorithm.  Returns a pointer to the result if  successful; NULL otherwise.]  SideEffects [None]  SeeAlso     []******************************************************************************/DdNode *Cudd_addOuterSum(  DdManager *dd,  DdNode *M,  DdNode *r,  DdNode *c){    DdNode *res;    do {	dd->reordered = 0;	res = cuddAddOuterSumRecur(dd, M, r, c);    } while (dd->reordered == 1);    return(res);} /* end of Cudd_addOuterSum *//*---------------------------------------------------------------------------*//* Definition of internal functions                                          *//*---------------------------------------------------------------------------*//*---------------------------------------------------------------------------*//* Definition of static functions                                            *//*---------------------------------------------------------------------------*//**Function********************************************************************  Synopsis    [Performs the recursive step of Cudd_addMatrixMultiply.]  Description [Performs the recursive step of Cudd_addMatrixMultiply.  Returns a pointer to the result if successful; NULL otherwise.]  SideEffects [None]******************************************************************************/static DdNode *addMMRecur(  DdManager * dd,  DdNode * A,  DdNode * B,  int  topP,  int * vars){    DdNode *zero,           *At,		/* positive cofactor of first operand */	   *Ae,		/* negative cofactor of first operand */	   *Bt,		/* positive cofactor of second operand */	   *Be,		/* negative cofactor of second operand */	   *t,		/* positive cofactor of result */	   *e,		/* negative cofactor of result */	   *scaled,	/* scaled result */	   *add_scale,	/* ADD representing the scaling factor */	   *res;    int	i;		/* loop index */    double scale;	/* scaling factor */    int index;		/* index of the top variable */    CUDD_VALUE_TYPE value;    unsigned int topA, topB, topV;    DdNode *(*cacheOp)(DdManager *, DdNode *, DdNode *);    statLine(dd);    zero = DD_ZERO(dd);    if (A == zero || B == zero) {        return(zero);    }    if (cuddIsConstant(A) && cuddIsConstant(B)) {	/* Compute the scaling factor. It is 2^k, where k is the	** number of summation variables below the current variable.	** Indeed, these constants represent blocks of 2^k identical	** constant values in both A and B.	*/	value = cuddV(A) * cuddV(B);	for (i = 0; i < dd->size; i++) {	    if (vars[i]) {

⌨️ 快捷键说明

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