source: icGREP/icgrep-devel/cudd-2.5.1/nanotrav/chkMterm.c @ 5815

Last change on this file since 5815 was 4597, checked in by nmedfort, 4 years ago

Upload of the CUDD library.

File size: 7.9 KB
Line 
1/**CFile***********************************************************************
2
3  FileName    [chkMterm.c]
4
5  PackageName [ntr]
6
7  Synopsis    [Functions to check that the minterm counts have not
8  changed.]
9
10  Description [Functions to check that the minterm counts have not
11  changed during reordering.<p>
12  Internal procedures included in this module:
13                <ul>
14                <li> check_minterms()
15                </ul>
16  Static procedures included in this module:
17                <ul>
18                <li> stFree()
19                </ul>]
20
21  SeeAlso     []
22
23  Author      [Fabio Somenzi]
24
25  Copyright   [Copyright (c) 1995-2012, Regents of the University of Colorado
26
27  All rights reserved.
28
29  Redistribution and use in source and binary forms, with or without
30  modification, are permitted provided that the following conditions
31  are met:
32
33  Redistributions of source code must retain the above copyright
34  notice, this list of conditions and the following disclaimer.
35
36  Redistributions in binary form must reproduce the above copyright
37  notice, this list of conditions and the following disclaimer in the
38  documentation and/or other materials provided with the distribution.
39
40  Neither the name of the University of Colorado nor the names of its
41  contributors may be used to endorse or promote products derived from
42  this software without specific prior written permission.
43
44  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
45  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
46  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
47  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
48  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
49  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
50  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
54  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55  POSSIBILITY OF SUCH DAMAGE.]
56
57******************************************************************************/
58
59#include "ntr.h"
60
61/*---------------------------------------------------------------------------*/
62/* Constant declarations                                                     */
63/*---------------------------------------------------------------------------*/
64
65/*---------------------------------------------------------------------------*/
66/* Stucture declarations                                                     */
67/*---------------------------------------------------------------------------*/
68
69/*---------------------------------------------------------------------------*/
70/* Type declarations                                                         */
71/*---------------------------------------------------------------------------*/
72
73/*---------------------------------------------------------------------------*/
74/* Variable declarations                                                     */
75/*---------------------------------------------------------------------------*/
76
77#ifndef lint
78static char rcsid[] UTIL_UNUSED = "$Id: chkMterm.c,v 1.9 2012/02/05 01:53:01 fabio Exp fabio $";
79#endif
80
81/*---------------------------------------------------------------------------*/
82/* Macro declarations                                                        */
83/*---------------------------------------------------------------------------*/
84
85/**AutomaticStart*************************************************************/
86
87/*---------------------------------------------------------------------------*/
88/* Static function prototypes                                                */
89/*---------------------------------------------------------------------------*/
90
91static enum st_retval stFree (char *key, char *value, char *arg);
92
93/**AutomaticEnd***************************************************************/
94
95/*---------------------------------------------------------------------------*/
96/* Definition of exported functions                                          */
97/*---------------------------------------------------------------------------*/
98
99/*---------------------------------------------------------------------------*/
100/* Definition of internal functions                                          */
101/*---------------------------------------------------------------------------*/
102
103
104/**Function********************************************************************
105
106  Synopsis    [Check that minterm counts have not changed.]
107
108  Description [Counts the minterms in the global functions of the
109  primary outputs of the network passed as argument.
110  When it is calld with the second argument set to NULL, it allocates
111  a symbol table and stores, for each output, the minterm count. If
112  an output does not have a BDD, it stores a NULL pointer for it.
113  If it is called with a non-null second argument, it assumes that
114  the symbol table contains the minterm counts measured previously
115  and it compares the new counts to the old ones. Finally, it frees
116  the symbol table.
117  check_minterms is designed so that it can be called twice: once before
118  reordering, and once after reordering.
119  Returns a pointer to the symbol table on the first invocation and NULL
120  on the second invocation.]
121
122  SideEffects [None]
123
124  SeeAlso     []
125
126******************************************************************************/
127st_table *
128checkMinterms(
129  BnetNetwork * net,
130  DdManager * dd,
131  st_table * previous)
132{
133    BnetNode *po;
134    int numPi;
135    char *name;
136    double *count, newcount, *oldcount;
137    int flag,err,i;
138
139    numPi = net->ninputs;
140
141    if (previous == NULL) {
142        previous = st_init_table(strcmp,st_strhash);
143        if (previous == NULL) {
144            (void) printf("checkMinterms out-of-memory\n");
145            return(NULL);
146        }
147        for (i = 0; i < net->noutputs; i++) {
148            if (!st_lookup(net->hash,net->outputs[i],&po)) {
149                exit(2);
150            }
151            name = net->outputs[i];
152            if (po->dd != NULL) {
153                count = ALLOC(double,1);
154                *count = Cudd_CountMinterm(dd,po->dd,numPi);
155                err = st_insert(previous, name, (char *) count);
156            } else {
157                err = st_insert(previous, name, NULL);
158            }
159            if (err) {
160                (void) printf("Duplicate input name (%s)\n",name);
161                return(NULL);
162            }
163        }
164        return(previous);
165    } else {
166        flag = 0;
167        if (st_count(previous) != net->noutputs) {
168            (void) printf("Number of outputs has changed from %d to %d\n",
169            st_count(previous), net->noutputs);
170            flag = 1;
171        }
172        for (i = 0; i < net->noutputs; i++) {
173            if (!st_lookup(net->hash,net->outputs[i],&po)) {
174                exit(2);
175            }
176            name = net->outputs[i];
177            if (st_lookup(previous,name,&oldcount)) {
178                if (po->dd != NULL) {
179                    newcount = Cudd_CountMinterm(dd,po->dd,numPi);
180                    if (newcount != *oldcount) {
181                        (void) printf("Number of minterms of %s has changed from %g to %g\n",name,*oldcount,newcount);
182                        flag = 1;
183                    }
184                } else {
185                    if (oldcount != NULL) {
186                        (void) printf("Output %s lost its BDD!\n",name);
187                        flag = 1;
188                    }
189                }
190            } else {
191                (void) printf("Output %s is new!\n",name);
192                flag = 1;
193            }
194        }
195        /*st_foreach(previous,(enum st_retval)stFree,NULL);*/
196        st_foreach(previous,(ST_PFSR)stFree,NULL);
197        st_free_table(previous);
198        if (flag) {
199            return((st_table *) 1);
200        } else {
201            return(NULL);
202        }
203    }
204
205} /* end of checkMinterms */
206
207
208/*---------------------------------------------------------------------------*/
209/* Definition of static functions                                            */
210/*---------------------------------------------------------------------------*/
211
212
213/**Function********************************************************************
214
215  Synopsis    [Frees the data of the symbol table.]
216
217  Description []
218
219  SideEffects [None]
220
221  SeeAlso     []
222
223*****************************************************************************/
224static enum st_retval
225stFree(
226  char *key,
227  char *value,
228  char *arg)
229{
230    if (value != NULL) {
231        FREE(value);
232    }
233    return(ST_CONTINUE);
234
235} /* end of stFree */
Note: See TracBrowser for help on using the repository browser.