source: vis_dev/vis-2.3/src/mvfaig/mvfaigUtil.c @ 31

Last change on this file since 31 was 14, checked in by cecile, 13 years ago

vis2.3

File size: 10.4 KB
RevLine 
[14]1/**CFile***********************************************************************
2
3  FileName    [mvfaigUtil.c]
4
5  PackageName [mvfaig]
6
7  Synopsis    [Routines to create, manipulate and free multi-valued functions.]
8
9  SeeAlso     [mvfAig.h]
10
11  Author      [Mohammad Awedh]
12
13  Copyright  [.]
14
15******************************************************************************/
16
17#include "mvfaigInt.h"
18
19/**AutomaticStart*************************************************************/
20
21/*---------------------------------------------------------------------------*/
22/* Static function prototypes                                                */
23/*---------------------------------------------------------------------------*/
24
25
26/**AutomaticEnd***************************************************************/
27
28
29/*---------------------------------------------------------------------------*/
30/* Definition of exported functions                                          */
31/*---------------------------------------------------------------------------*/
32
33/**Function********************************************************************
34
35  Synopsis    [Initializes the mvfAig package.]
36
37  SideEffects []
38
39  SeeAlso     [MvfAig_End]
40
41******************************************************************************/
42void
43MvfAig_Init(void)
44{
45}
46
47
48/**Function********************************************************************
49
50  Synopsis    [Ends the mvfAig package.]
51
52  SideEffects []
53
54  SeeAlso     [MvfAig_Init]
55
56******************************************************************************/
57void
58MvfAig_End(void)
59{
60}
61
62
63/**Function********************************************************************
64
65  Synopsis    [Allocates a multi-valued function of n components.]
66
67  Description [Allocates a multi-valued function of n components.  Each
68  component is initialized to the zero bAig.]
69
70  SideEffects []
71
72  SeeAlso     []
73
74******************************************************************************/
75MvfAig_Function_t *
76MvfAig_FunctionAlloc(
77  int n)
78{
79  int      i;
80  array_t *bAndInvArray = array_alloc(bAigEdge_t, n);
81
82  for (i = 0; i < n; i++) {
83    array_insert(bAigEdge_t, bAndInvArray, i, bAig_Zero);
84  }
85  return ((MvfAig_Function_t *) bAndInvArray);
86}
87
88/**Function********************************************************************
89
90  Synopsis    [Frees a multi-valued output function.]
91
92  Description [Frees a multi-valued output function. Does nothing if
93  function is NULL.]
94 
95  SideEffects []
96
97  SeeAlso     [MvfAig_FunctionAlloc]
98
99******************************************************************************/
100void
101MvfAig_FunctionFree(
102  MvfAig_Function_t *function)
103{
104  array_free((array_t *) function);
105}
106
107/**Function********************************************************************
108
109  Synopsis    [Duplicates a multi-valued output function.]
110
111  Description [Returns a new multi-valued output function, whose constituent
112  MAIGs have been duplicated. Assumes that function is not NULL.]
113
114  SideEffects []
115
116  SeeAlso     [Mvf_FunctionFree]
117
118******************************************************************************/
119MvfAig_Function_t *
120MvfAig_FunctionDuplicate(
121  MvfAig_Function_t *function)
122{
123  return ((MvfAig_Function_t *) array_dup((array_t *) function));
124}
125
126
127/**Function********************************************************************
128
129  Synopsis    [Frees an array of multi-valued output functions.]
130
131  Description [Frees an array of multi-valued output functions.  Does nothing
132  if functionArray is NULL.]
133
134  SideEffects []
135
136  SeeAlso     [Mvf_FunctionFree]
137
138******************************************************************************/
139void
140MvfAig_FunctionArrayFree(
141  array_t *functionArray)
142{
143  int i;
144
145  if (functionArray != NIL(array_t)) {
146    for (i = 0; i < array_n(functionArray); i++) {
147      MvfAig_Function_t *function = array_fetch(MvfAig_Function_t*, functionArray, i);
148      MvfAig_FunctionFree(function);
149    }
150    array_free(functionArray);
151  }
152}
153
154
155/**Function********************************************************************
156
157  Synopsis    [Returns the number of components of a multi-valued function.]
158
159  Description [Returns the number of components of a multi-valued function.
160  This is the same number as the value of the parameter passed to
161  Mvf_FunctionAlloc.]
162
163  SideEffects []
164
165  SeeAlso     [Mvf_FunctionAlloc]
166
167******************************************************************************/
168int
169MvfAig_FunctionReadNumComponents(
170  MvfAig_Function_t *function)
171{
172  return (array_n((array_t *) function));
173}
174
175
176/**Function********************************************************************
177
178  Synopsis [Returns the ith component of a multi-valued function.]
179
180  Description [Returns the mAndInv giving the minterms for which a
181  multi-valued function evaluates to its ith value. ]
182
183  SideEffects []
184
185  SeeAlso     []
186
187******************************************************************************/
188mAigEdge_t
189MvfAig_FunctionReadComponent(
190  MvfAig_Function_t *function,
191  int i)
192{
193  bAigEdge_t component = array_fetch(bAigEdge_t, (array_t *) function, i);
194  return (component);
195}
196
197
198/**Function********************************************************************
199
200  Synopsis [Creates the multi-output function for a variable.]
201
202  Description [Given a variable, creates a function with as many components as
203  values of the variable.  The ith component of the function is true exactly
204  when the variable is equal to the ith value (i.e. fi(x) = (x==i), where x is
205  the variable specified by mddId).  For the case where x is binary valued,
206  the result is \[!x, x\]. Assumes that mddId is non-negative.]
207
208  SideEffects []
209
210  SeeAlso [Mvf_FunctionAlloc]
211
212******************************************************************************/
213MvfAig_Function_t *
214MvfAig_FunctionCreateFromVariable(
215  mAig_Manager_t *manager,
216  mAigEdge_t mVarId)
217{
218  int        i;
219  array_t   *mVarList    = mAigReadMulVarList(manager);
220  mAigMvar_t mVar;
221  array_t   *result;
222
223  assert( (mVarId >= 0) && (mVarId <= array_n(mVarList)));
224  mVar   = array_fetch(mAigMvar_t, mVarList, mVarId);
225  result = array_alloc(bAigEdge_t, mVar.values);  /* array of all possible values of this variable */
226  for(i = 0; i < mVar.values; i++) {
227    bAigEdge_t literal;
228
229    literal = mAig_EquC(manager, mVarId, i);       /* AndInv graph = 1 if the variable = i*/
230    array_insert(bAigEdge_t, result, i, literal);
231    {
232      /*
233        The name of the node in AIG is node name = node value.
234       */
235      /*
236      char *valueStr = util_inttostr(i);
237      char *name     = util_strcat3(mVar.name,"=", valueStr);
238      char *tmpName;
239      int  index;
240     
241      bAig_NodeSetName(manager, literal, name);
242      FREE(valueStr);
243      */
244    }
245  }
246  return ((MvfAig_Function_t *) result);
247} 
248
249
250/**Function********************************************************************
251
252  Synopsis    [Adds a set of minterms to the ith component of a function.]
253
254  Description [Adds a set of minterms, represented by the onset of an mAig g,
255  to the onset of the ith component of a function.  The mAig g is not freed.]
256
257  SideEffects []
258
259  SeeAlso     [Mvf_FunctionAlloc]
260
261******************************************************************************/
262void
263MvfAig_FunctionAddMintermsToComponent(
264  mAig_Manager_t    *manager,
265  MvfAig_Function_t *function,
266  int               i,
267  mAigEdge_t        g)
268{
269  mAigEdge_t oldComponent;
270  mAigEdge_t newComponent;
271  array_t    *mAigArray = (array_t *) function;
272
273  assert((i >= 0) && (i < array_n(mAigArray)));
274
275  oldComponent = array_fetch(mAigEdge_t , mAigArray, i);
276  newComponent = mAig_Or(manager, oldComponent, g);
277  array_insert(mAigEdge_t , mAigArray, i, newComponent);
278}
279
280/**Function********************************************************************
281
282  Synopsis    [Returns the set of minterms on which two functions agree.]
283
284  Description [Returns the set of minterms on which two functions agree.  For
285  f = \[f1, f2, ..., fn\] and g = \[g1, g2, ..., gn\], the returned set is:
286  AND(i = 1, ..., n) (fi XNOR gi).  For the special case where f and g are
287  binary valued, this function computes (f XNOR g).  It is an error if the two
288  functions have a different number of components.]
289
290  SideEffects []
291
292******************************************************************************/
293mAigEdge_t
294MvfAig_FunctionsComputeEquivalentSet(
295  mAig_Manager_t *manager, 
296  MvfAig_Function_t *function1,
297  MvfAig_Function_t *function2)
298{
299  int          i;
300  array_t     *mAigArray1     = (array_t *) function1;
301  array_t     *mAigArray2     = (array_t *) function2;
302  int          numComponents = array_n(mAigArray1);
303  mAigEdge_t   product       = mAig_One;
304
305  assert(numComponents == array_n(mAigArray1));
306  assert(numComponents == array_n(mAigArray2));
307 
308  for (i = 0; i < numComponents; i++) {
309    mAigEdge_t mAig1 = array_fetch(mAigEdge_t, mAigArray1, i);
310    mAigEdge_t mAig2 = array_fetch(mAigEdge_t, mAigArray2, i);
311    mAigEdge_t xnor = mAig_Eq(manager, mAig1, mAig2);
312    mAigEdge_t temp = product;
313
314    product = mAig_And(manager, temp, xnor);
315  }
316
317  return product;
318}
319
320/**Function********************************************************************
321
322  Synopsis    [Computes the domain of a multi-valued function.]
323
324  Description [Returns an mAig representing the set of minterms which turn on
325  some component of a function.  In other words, returns the union of the
326  onsets of the components.  The domain is the tautology if and only if the
327  function is completely specified.]
328
329  SideEffects []
330
331  SeeAlso     [Mvf_FunctionTestIsCompletelySpecified]
332
333******************************************************************************/
334mAigEdge_t
335MvfAig_FunctionComputeDomain(
336  mAig_Manager_t *manager,
337  MvfAig_Function_t *function)
338{
339  int          i;
340  array_t     *mAigArray     = (array_t *) function;
341  int          numComponents = array_n(mAigArray);
342  mAigEdge_t   sum           = mAig_Zero;
343
344  for (i = 0; i < numComponents; i++) {
345    mAigEdge_t ithComponent = array_fetch(mAigEdge_t , mAigArray, i);
346    mAigEdge_t temp = sum;
347   
348    sum = mAig_Or(manager, temp, ithComponent);
349  }
350  return sum;
351}
352
353/*---------------------------------------------------------------------------*/
354/* Definition of internal functions                                          */
355/*---------------------------------------------------------------------------*/
356
357
358/*---------------------------------------------------------------------------*/
359/* Definition of static functions                                            */
360/*---------------------------------------------------------------------------*/
361
362
363
364
365
366
367
368
369
Note: See TracBrowser for help on using the repository browser.