1 | /**CFile*********************************************************************** |
---|
2 | |
---|
3 | FileName [partInOut.c] |
---|
4 | |
---|
5 | PackageName [part] |
---|
6 | |
---|
7 | Synopsis [Implements the partition of a network considering only the |
---|
8 | functions at the combinational outputs in terms of the combinational |
---|
9 | inputs.] |
---|
10 | |
---|
11 | Description [This module creates a partition where each combinational output |
---|
12 | is defined in terms of the combinational inputs. More specifically, for each |
---|
13 | combinational output and for some combinational inputs, there is a vertex in |
---|
14 | the partition (a combinational input doesn't appear if no combinational |
---|
15 | output depends on it). There is an edge from combinational input x to |
---|
16 | combinational output y if the multi-valued function (MVF) for y depends on |
---|
17 | x. Every vertex in the graph has a vertex name and an MVF (for combinational |
---|
18 | inputs, the MVF is the trivial variable function). In addition, each |
---|
19 | combinational input has an MDD id; a combinational output may or may not |
---|
20 | have an MDD id.] |
---|
21 | |
---|
22 | SeeAlso [partPart.c] |
---|
23 | |
---|
24 | Author [Abelardo Pardo, Balakrishna Kumthekar] |
---|
25 | |
---|
26 | Copyright [This file was created at the University of Colorado at Boulder. |
---|
27 | The University of Colorado at Boulder makes no warranty about the |
---|
28 | suitability of this software for any purpose. It is presented on an AS IS |
---|
29 | basis.] |
---|
30 | |
---|
31 | ******************************************************************************/ |
---|
32 | |
---|
33 | #include "partInt.h" |
---|
34 | |
---|
35 | static char rcsid[] UNUSED = "$Id: partInOut.c,v 1.15 2005/04/16 14:52:45 fabio Exp $"; |
---|
36 | |
---|
37 | /**AutomaticStart*************************************************************/ |
---|
38 | |
---|
39 | /*---------------------------------------------------------------------------*/ |
---|
40 | /* Static function prototypes */ |
---|
41 | /*---------------------------------------------------------------------------*/ |
---|
42 | |
---|
43 | |
---|
44 | /**AutomaticEnd***************************************************************/ |
---|
45 | |
---|
46 | |
---|
47 | /*---------------------------------------------------------------------------*/ |
---|
48 | /* Definition of exported functions */ |
---|
49 | /*---------------------------------------------------------------------------*/ |
---|
50 | |
---|
51 | /**Function******************************************************************** |
---|
52 | |
---|
53 | Synopsis [Creates the graph representing a set of Mvfs as functions of the |
---|
54 | variables in the collective support of the specified Mvfs. A copy of the Mvf |
---|
55 | function is stored in vertex.] |
---|
56 | |
---|
57 | Description [The input nameToMvf is a table which provides the names and the |
---|
58 | corresponding Mvfs functions. The procedure works as follows. For each |
---|
59 | function, a vertex in the graph is created. For each variable in the support |
---|
60 | of a given MVF, a vertex is created (if one doesn't already exist), and an |
---|
61 | edge is added from the that vertex to that MVF. The support of an MVF is |
---|
62 | taken as the union of the support of its constituent MDDs. The table nameToId |
---|
63 | is optional and can be NULL. It provides a map from the name of the MVF to |
---|
64 | its mddId. leafTable provides the pair (mddId, name) for each variable in the |
---|
65 | support of the MVFs. partName can be NULL in which case the name of the |
---|
66 | partition would be "dummy".] |
---|
67 | |
---|
68 | SideEffects [] |
---|
69 | |
---|
70 | SeeAlso [Part_NetworkCreatePartition Part_NetworkCreatePartitionFromMvfs] |
---|
71 | |
---|
72 | ******************************************************************************/ |
---|
73 | graph_t * |
---|
74 | Part_CreatePartitionFromMvfs( |
---|
75 | mdd_manager *manager, |
---|
76 | st_table *nameToMvf, |
---|
77 | st_table *nameToId, |
---|
78 | st_table *leafTable, |
---|
79 | char *partName) |
---|
80 | { |
---|
81 | graph_t *partition; |
---|
82 | Mvf_Function_t *mddFunction; |
---|
83 | vertex_t *toVertex; |
---|
84 | lsList sinkList; |
---|
85 | lsGen gen; |
---|
86 | st_table *mddIdToNodeName; |
---|
87 | st_generator *stGen; |
---|
88 | char *str; |
---|
89 | long mddId; |
---|
90 | |
---|
91 | /* Initialize variables */ |
---|
92 | mddIdToNodeName = leafTable; |
---|
93 | |
---|
94 | /* Allocate the new partition to be returned */ |
---|
95 | partition = g_alloc(); |
---|
96 | if (partName) { |
---|
97 | partition->user_data = |
---|
98 | (gGeneric)PartPartitionInfoCreate(partName,manager,Part_InOut_c); |
---|
99 | } /* End of if */ |
---|
100 | else { |
---|
101 | partition->user_data = |
---|
102 | (gGeneric)PartPartitionInfoCreate("dummy",manager,Part_InOut_c); |
---|
103 | } /* End of if-then-else */ |
---|
104 | |
---|
105 | /* Create vertices for the functions in nameToMvf */ |
---|
106 | st_foreach_item(nameToMvf,stGen,&str,&mddFunction) { |
---|
107 | toVertex = g_add_vertex(partition); |
---|
108 | |
---|
109 | /* Update the look-up tables in the graph */ |
---|
110 | st_insert(PartPartitionReadNameToVertex(partition),str,toVertex); |
---|
111 | if (nameToId) { |
---|
112 | if (st_lookup(nameToId, str, &mddId)) { |
---|
113 | st_insert(PartPartitionReadMddIdToVertex(partition), |
---|
114 | (char *)mddId, toVertex); |
---|
115 | } /* End of if */ |
---|
116 | } /* End of if */ |
---|
117 | |
---|
118 | /* Fill in the fields of the data attached to the vertex */ |
---|
119 | toVertex->user_data = |
---|
120 | (gGeneric)PartVertexInfoCreateSingle(str, |
---|
121 | Mvf_FunctionDuplicate(mddFunction), |
---|
122 | mddId); |
---|
123 | } |
---|
124 | |
---|
125 | /* Read the list of vertices on the graph */ |
---|
126 | sinkList = lsCopy(g_get_vertices(partition), (lsGeneric (*)(lsGeneric))0); |
---|
127 | |
---|
128 | /* |
---|
129 | * For every function on every combinational output, compute the |
---|
130 | * support and create vertices in the graph when needed |
---|
131 | */ |
---|
132 | lsForEachItem(sinkList, gen, toVertex) { |
---|
133 | st_table *mddSupport; /* Support of the Mvf_Function */ |
---|
134 | st_generator *stGen; /* To iterate over the MddIds of the support */ |
---|
135 | vertex_t *fromVertex; /* Holds the current vertex in the support */ |
---|
136 | |
---|
137 | /* Obtain an array of mdd_t * */ |
---|
138 | mddFunction = PartVertexReadFunction(toVertex); |
---|
139 | |
---|
140 | /* Compute the support of the set of mdds*/ |
---|
141 | mddSupport = PartCreateFunctionSupportTable(mddFunction); |
---|
142 | |
---|
143 | /* |
---|
144 | * Create one edge (and one vertex if necessary) for every element |
---|
145 | * in mddSupport |
---|
146 | */ |
---|
147 | st_foreach_item(mddSupport, stGen, &mddId, NULL) { |
---|
148 | char *name; |
---|
149 | |
---|
150 | /* Create vertex with the information if needed */ |
---|
151 | if (st_lookup(PartPartitionReadMddIdToVertex(partition), |
---|
152 | (char *)mddId, &fromVertex) == 0) { |
---|
153 | fromVertex = g_add_vertex(partition); |
---|
154 | |
---|
155 | st_lookup(mddIdToNodeName, (char *)mddId, &name); |
---|
156 | |
---|
157 | /* Update the look-up tables in the graph */ |
---|
158 | st_insert(PartPartitionReadNameToVertex(partition), |
---|
159 | name, (char *)fromVertex); |
---|
160 | st_insert(PartPartitionReadMddIdToVertex(partition), |
---|
161 | (char *)(long) mddId, (char *)fromVertex); |
---|
162 | |
---|
163 | /* Create vertex data */ |
---|
164 | fromVertex->user_data = |
---|
165 | (gGeneric)PartVertexInfoCreateSingle(name, |
---|
166 | Mvf_FunctionCreateFromVariable(manager,mddId), |
---|
167 | mddId); |
---|
168 | } /* End of if */ |
---|
169 | |
---|
170 | /* |
---|
171 | * Add the edge to the graph. Make sure a self loop is not added. |
---|
172 | * The self loop may be produced by a mdd that has in its support |
---|
173 | * the same variables that represent the mddId of the node. |
---|
174 | */ |
---|
175 | if (fromVertex != toVertex) { |
---|
176 | g_add_edge(fromVertex, toVertex); |
---|
177 | } /* End of if */ |
---|
178 | |
---|
179 | } /* End of st_foreach_item */ |
---|
180 | |
---|
181 | /* Clean the support table */ |
---|
182 | st_free_table(mddSupport); |
---|
183 | } /* End of lsForEachItem */ |
---|
184 | |
---|
185 | lsDestroy(sinkList, (void (*)(lsGeneric))0); |
---|
186 | |
---|
187 | return partition; |
---|
188 | } /* End of Part_CreatePartitionFromMvfs */ |
---|
189 | |
---|
190 | /**Function******************************************************************** |
---|
191 | |
---|
192 | Synopsis [Creates the graph representing the combinational outputs as |
---|
193 | functions of the combinational inputs given as input a network and |
---|
194 | Mvf functions representing the combinational outputs. A copy of the |
---|
195 | Mvf function is stored in vertex.] |
---|
196 | |
---|
197 | Description [The input nameToMvf is a table which provides the names |
---|
198 | of the nodes and their corresponding Mvfs functions. |
---|
199 | The procedure works as follows. For each combinational output, |
---|
200 | a vertex in the graph is created. For each combinational input in the |
---|
201 | support of a given combinational output MVF, a vertex is created |
---|
202 | (if one doesn't already exist), and an edge is added |
---|
203 | from the combinational input to the combinational output. The support of |
---|
204 | an MVF is taken as the union of the support of its constituent MDDs.] |
---|
205 | |
---|
206 | SideEffects [] |
---|
207 | |
---|
208 | SeeAlso [Part_NetworkCreatePartition Part_CreatePartitionFromMvfs] |
---|
209 | |
---|
210 | ******************************************************************************/ |
---|
211 | graph_t * |
---|
212 | Part_NetworkCreatePartitionFromMvfs( |
---|
213 | Ntk_Network_t *network, |
---|
214 | st_table *nameToMvf) |
---|
215 | { |
---|
216 | graph_t *partition; |
---|
217 | Ntk_Node_t *node; |
---|
218 | Mvf_Function_t *mddFunction; |
---|
219 | vertex_t *toVertex; |
---|
220 | mdd_manager *manager; |
---|
221 | lsList sinkList; |
---|
222 | lsGen gen; |
---|
223 | st_table *mddIdToNodeName; |
---|
224 | st_generator *stGen; |
---|
225 | char *ntkName; |
---|
226 | char *str; |
---|
227 | long mddId; |
---|
228 | |
---|
229 | /* Initialize variables */ |
---|
230 | manager = Ntk_NetworkReadMddManager(network); |
---|
231 | ntkName = Ntk_NetworkReadName(network); |
---|
232 | |
---|
233 | /* Allocate the new partition to be returned */ |
---|
234 | partition = g_alloc(); |
---|
235 | partition->user_data = |
---|
236 | (gGeneric)PartPartitionInfoCreate(ntkName,manager,Part_InOut_c); |
---|
237 | |
---|
238 | /* Create vertices for the functions in nameToMvf */ |
---|
239 | st_foreach_item(nameToMvf,stGen,&str,&mddFunction) { |
---|
240 | node = Ntk_NetworkFindNodeByName(network,str); |
---|
241 | if (node == NIL(Ntk_Node_t)) { |
---|
242 | fprintf(vis_stderr,"%s has no corresponding node in network \n", |
---|
243 | str); |
---|
244 | Part_PartitionFree(partition); |
---|
245 | return NIL(graph_t); |
---|
246 | } |
---|
247 | mddId = Ntk_NodeReadMddId(node); |
---|
248 | toVertex = g_add_vertex(partition); |
---|
249 | |
---|
250 | /* Update the look-up tables in the graph */ |
---|
251 | st_insert(PartPartitionReadNameToVertex(partition),str, |
---|
252 | (char *)toVertex); |
---|
253 | |
---|
254 | if (mddId != NTK_UNASSIGNED_MDD_ID) { |
---|
255 | st_insert(PartPartitionReadMddIdToVertex(partition), |
---|
256 | (char *)(long) mddId, (char *)toVertex); |
---|
257 | } |
---|
258 | |
---|
259 | /* Fill in the fields of the data attached to the vertex */ |
---|
260 | toVertex->user_data = |
---|
261 | (gGeneric)PartVertexInfoCreateSingle(str, |
---|
262 | Mvf_FunctionDuplicate(mddFunction), |
---|
263 | mddId); |
---|
264 | } |
---|
265 | |
---|
266 | /* Create a table for all the combinational inputs */ |
---|
267 | mddIdToNodeName = st_init_table(st_numcmp, st_numhash); |
---|
268 | Ntk_NetworkForEachCombInput(network, gen, node) { |
---|
269 | st_insert(mddIdToNodeName, (char *) (long)Ntk_NodeReadMddId(node), |
---|
270 | Ntk_NodeReadName(node)); |
---|
271 | } |
---|
272 | |
---|
273 | /* Read the list of vertices on the graph */ |
---|
274 | sinkList = lsCopy(g_get_vertices(partition), (lsGeneric (*)(lsGeneric))0); |
---|
275 | |
---|
276 | /* |
---|
277 | * For every function on every combinational output, compute the |
---|
278 | * support and create vertices in the graph when needed |
---|
279 | */ |
---|
280 | lsForEachItem(sinkList, gen, toVertex) { |
---|
281 | st_table *mddSupport; /* Support of the Mvf_Function */ |
---|
282 | st_generator *stGen; /* To iterate over the MddIds of the support */ |
---|
283 | vertex_t *fromVertex; /* Holds the current vertex in the support */ |
---|
284 | |
---|
285 | /* Obtain an array of mdd_t * */ |
---|
286 | mddFunction = PartVertexReadFunction(toVertex); |
---|
287 | |
---|
288 | /* Compute the support of the set of mdds*/ |
---|
289 | mddSupport = PartCreateFunctionSupportTable(mddFunction); |
---|
290 | |
---|
291 | /* |
---|
292 | * Create one edge (and one vertex if necessary) for every element |
---|
293 | * in mddSupport |
---|
294 | */ |
---|
295 | st_foreach_item(mddSupport, stGen, &mddId, NULL) { |
---|
296 | char *name; |
---|
297 | |
---|
298 | /* Create vertex with the information if needed */ |
---|
299 | if (st_lookup(PartPartitionReadMddIdToVertex(partition), |
---|
300 | (char *)mddId, &fromVertex) == 0) { |
---|
301 | fromVertex = g_add_vertex(partition); |
---|
302 | |
---|
303 | st_lookup(mddIdToNodeName, (char *)mddId, &name); |
---|
304 | |
---|
305 | /* Update the look-up tables in the graph */ |
---|
306 | st_insert(PartPartitionReadNameToVertex(partition), |
---|
307 | name, (char *)fromVertex); |
---|
308 | st_insert(PartPartitionReadMddIdToVertex(partition), |
---|
309 | (char *)(long) mddId, (char *)fromVertex); |
---|
310 | |
---|
311 | /* Create vertex data */ |
---|
312 | fromVertex->user_data = |
---|
313 | (gGeneric)PartVertexInfoCreateSingle(name, |
---|
314 | Mvf_FunctionCreateFromVariable(manager,mddId), |
---|
315 | mddId); |
---|
316 | } /* End of if */ |
---|
317 | |
---|
318 | /* |
---|
319 | * Add the edge to the graph. Make sure a self loop is not added. |
---|
320 | * The self loop may be produced by a mdd that has in its support |
---|
321 | * the same variables that represent the mddId of the node. |
---|
322 | */ |
---|
323 | if (fromVertex != toVertex) { |
---|
324 | g_add_edge(fromVertex, toVertex); |
---|
325 | } /* End of if */ |
---|
326 | |
---|
327 | } /* End of st_foreach_item */ |
---|
328 | |
---|
329 | /* Clean the support table */ |
---|
330 | st_free_table(mddSupport); |
---|
331 | } /* End of lsForEachItem */ |
---|
332 | |
---|
333 | st_free_table(mddIdToNodeName); |
---|
334 | lsDestroy(sinkList, (void (*)(lsGeneric))0); |
---|
335 | |
---|
336 | return partition; |
---|
337 | } /* End of Part_NetworkCreatePartitionFromMvfs */ |
---|
338 | |
---|
339 | /*---------------------------------------------------------------------------*/ |
---|
340 | /* Definition of internal functions */ |
---|
341 | /*---------------------------------------------------------------------------*/ |
---|
342 | |
---|
343 | /**Function******************************************************************** |
---|
344 | |
---|
345 | Synopsis [Creates the graph representing the combinational outputs as |
---|
346 | functions of the combinational inputs.] |
---|
347 | |
---|
348 | Description [The procedure works as follows. It calls the function |
---|
349 | Ntm_NetworkBuildMvfs with the combinational outputs as roots and the |
---|
350 | combinational inputs as leaves to obtain the multi-valued functions for |
---|
351 | every combinational output. For each combinational output, a vertex in the |
---|
352 | graph is created. For each combinational input in the support of a given |
---|
353 | combinational output MVF, a vertex is created for the combinational input |
---|
354 | (if one doesn't already exist), and an edge is added from the combinational |
---|
355 | input to the combinational output. The support of an MVF is taken as the |
---|
356 | union of the support of its constituent MDDs.] |
---|
357 | |
---|
358 | SideEffects [] |
---|
359 | |
---|
360 | SeeAlso [Part_NetworkCreatePartition] |
---|
361 | |
---|
362 | ******************************************************************************/ |
---|
363 | void |
---|
364 | PartPartitionInputsOutputs( |
---|
365 | Ntk_Network_t *network, |
---|
366 | graph_t *partition, |
---|
367 | lsList rootList, |
---|
368 | lsList leaveList, |
---|
369 | mdd_t *careSet) |
---|
370 | { |
---|
371 | Ntk_Node_t *node; /* Pointer to iterate over nodes */ |
---|
372 | Mvf_Function_t *mddFunction; /* Pointer to a MDD */ |
---|
373 | mdd_manager *manager; /* Mdd manager in the partition */ |
---|
374 | st_table *tableOfLeaves; /* To store the leaves of the graph */ |
---|
375 | st_table *mddIdToNodeName; /* For quick lookup of node's name */ |
---|
376 | array_t *arrayOfMvf; /* To store the next state functions */ |
---|
377 | array_t *arrayOfRoots; /* To store the roots of the graph */ |
---|
378 | lsList sinkList; /* Vertices representing comb. outputs */ |
---|
379 | lsGen gen; /* To iterate over lists */ |
---|
380 | vertex_t *toVertex; /* Will hold the current function vertex */ |
---|
381 | int i; /* Index for loops */ |
---|
382 | long mddId; /* Will hold the mddId being processed */ |
---|
383 | |
---|
384 | |
---|
385 | manager = PartPartitionReadMddManager(partition); |
---|
386 | |
---|
387 | /* Take the nodes in leaveList as the leaves */ |
---|
388 | tableOfLeaves = st_init_table(st_ptrcmp, st_ptrhash); |
---|
389 | mddIdToNodeName = st_init_table(st_numcmp, st_numhash); |
---|
390 | if (leaveList == (lsList)0) { |
---|
391 | Ntk_NetworkForEachCombInput(network, gen, node) { |
---|
392 | st_insert(tableOfLeaves, (char *)node, (char *) (long) (-1) ); |
---|
393 | st_insert(mddIdToNodeName, (char *) (long)Ntk_NodeReadMddId(node), |
---|
394 | Ntk_NodeReadName(node)); |
---|
395 | } |
---|
396 | } /* End of then */ |
---|
397 | else { |
---|
398 | lsForEachItem(leaveList, gen, node) { |
---|
399 | st_insert(tableOfLeaves, (char *)node, (char *) (long) (-1) ); |
---|
400 | st_insert(mddIdToNodeName, (char *) (long)Ntk_NodeReadMddId(node), |
---|
401 | Ntk_NodeReadName(node)); |
---|
402 | } |
---|
403 | } /* End of if-then-else */ |
---|
404 | |
---|
405 | /* Take the nodes in rootList as the roots */ |
---|
406 | if (rootList == (lsList)0) { |
---|
407 | arrayOfRoots = array_alloc(Ntk_Node_t *, |
---|
408 | Ntk_NetworkReadNumCombOutputs(network)); |
---|
409 | i = 0; |
---|
410 | Ntk_NetworkForEachCombOutput(network, gen, node) { |
---|
411 | array_insert(Ntk_Node_t *, arrayOfRoots, i++, node); |
---|
412 | } |
---|
413 | } /* End of then */ |
---|
414 | else { |
---|
415 | arrayOfRoots = array_alloc(Ntk_Node_t *, lsLength(rootList)); |
---|
416 | i = 0; |
---|
417 | lsForEachItem(rootList, gen, node) { |
---|
418 | array_insert(Ntk_Node_t *, arrayOfRoots, i++, node); |
---|
419 | } |
---|
420 | } /* End of if-then-else */ |
---|
421 | |
---|
422 | /* Build the next state functions as a function of the inputs */ |
---|
423 | arrayOfMvf = Ntm_NetworkBuildMvfs(network, arrayOfRoots, tableOfLeaves, |
---|
424 | careSet); |
---|
425 | |
---|
426 | /* Create one vertex for every component of arrayOfMvf */ |
---|
427 | for (i=0; i < array_n(arrayOfRoots); i++) { |
---|
428 | node = array_fetch(Ntk_Node_t *, arrayOfRoots, i); |
---|
429 | |
---|
430 | mddId = Ntk_NodeReadMddId(node); |
---|
431 | |
---|
432 | /* obtain the function attached to the node */ |
---|
433 | mddFunction = array_fetch(Mvf_Function_t *, arrayOfMvf, i); |
---|
434 | toVertex = g_add_vertex(partition); |
---|
435 | |
---|
436 | /* Update the look-up tables in the graph */ |
---|
437 | st_insert(PartPartitionReadNameToVertex(partition), |
---|
438 | Ntk_NodeReadName(node), (char *)toVertex); |
---|
439 | if (mddId != NTK_UNASSIGNED_MDD_ID) { |
---|
440 | st_insert(PartPartitionReadMddIdToVertex(partition), |
---|
441 | (char *)(long) mddId, (char *)toVertex); |
---|
442 | } /* End of if */ |
---|
443 | toVertex->user_data = |
---|
444 | (gGeneric)PartVertexInfoCreateSingle(Ntk_NodeReadName(node), |
---|
445 | mddFunction, |
---|
446 | mddId); |
---|
447 | } /* End of for */ |
---|
448 | |
---|
449 | /* Read the list of vertices on the graph */ |
---|
450 | sinkList = lsCopy(g_get_vertices(partition), (lsGeneric (*)(lsGeneric))0); |
---|
451 | |
---|
452 | /* |
---|
453 | * For every function on every combinational output, compute the |
---|
454 | * support and create vertices in the graph when needed |
---|
455 | */ |
---|
456 | lsForEachItem(sinkList, gen, toVertex) { |
---|
457 | st_table *mddSupport; /* To store the support of the Mvf_Function */ |
---|
458 | st_generator *stGen; /* To iterate over the MddIds of the support */ |
---|
459 | vertex_t *fromVertex; /* Will hold the current vertex in the support */ |
---|
460 | |
---|
461 | /* Obtain an array of mdd_t * */ |
---|
462 | mddFunction = PartVertexReadFunction(toVertex); |
---|
463 | |
---|
464 | /* Compute the support of the set of mdds*/ |
---|
465 | mddSupport = PartCreateFunctionSupportTable(mddFunction); |
---|
466 | |
---|
467 | /* |
---|
468 | * Create one edge (and one vertex if necessary) for every element |
---|
469 | * in mddSupport |
---|
470 | */ |
---|
471 | st_foreach_item(mddSupport, stGen, &mddId, NULL) { |
---|
472 | char *name; |
---|
473 | |
---|
474 | /* Create vertex with the information if needed */ |
---|
475 | if (st_lookup(PartPartitionReadMddIdToVertex(partition), |
---|
476 | (char *)mddId, &fromVertex) == 0) { |
---|
477 | fromVertex = g_add_vertex(partition); |
---|
478 | |
---|
479 | st_lookup(mddIdToNodeName, (char *)mddId, &name); |
---|
480 | |
---|
481 | /* Update the look-up tables in the graph */ |
---|
482 | st_insert(PartPartitionReadNameToVertex(partition), |
---|
483 | name, (char *)fromVertex); |
---|
484 | st_insert(PartPartitionReadMddIdToVertex(partition), |
---|
485 | (char *)(long) mddId, (char *)fromVertex); |
---|
486 | |
---|
487 | /* Create vertex data */ |
---|
488 | fromVertex->user_data = |
---|
489 | (gGeneric)PartVertexInfoCreateSingle(name, |
---|
490 | Mvf_FunctionCreateFromVariable(manager,mddId), |
---|
491 | mddId); |
---|
492 | } /* End of if */ |
---|
493 | |
---|
494 | /* |
---|
495 | * Add the edge to the graph. Make sure a self loop is not added. The |
---|
496 | * self loop may be produced by a mdd that has in its support the same |
---|
497 | * variables that represent the mddId of the node. |
---|
498 | */ |
---|
499 | if (fromVertex != toVertex) { |
---|
500 | g_add_edge(fromVertex, toVertex); |
---|
501 | } /* End of if */ |
---|
502 | |
---|
503 | } /* End of st_foreach_item */ |
---|
504 | |
---|
505 | /* Clean the support table */ |
---|
506 | st_free_table(mddSupport); |
---|
507 | } /* End of lsForEachItem */ |
---|
508 | |
---|
509 | /* Clean up */ |
---|
510 | st_free_table(mddIdToNodeName); |
---|
511 | st_free_table(tableOfLeaves); |
---|
512 | array_free(arrayOfRoots); |
---|
513 | lsDestroy(sinkList, (void (*)(lsGeneric))0); |
---|
514 | /* |
---|
515 | * The contents of this array (array of mdds) is not deallocated because the |
---|
516 | * information has been transferred to the partition structure. All the |
---|
517 | * functions are stored now as part of the vertex information. |
---|
518 | */ |
---|
519 | array_free(arrayOfMvf); |
---|
520 | |
---|
521 | } /* End of PartPartitionInputsOutputs */ |
---|
522 | |
---|
523 | |
---|
524 | /**Function******************************************************************** |
---|
525 | |
---|
526 | Synopsis [Creates the graph representing the combinational outputs as |
---|
527 | functions of the combinational inputs.] |
---|
528 | |
---|
529 | Description [The procedure works as follows. It calls the function |
---|
530 | Ntm_NetworkBuildMvfs with the combinational outputs as roots and the |
---|
531 | combinational inputs as leaves to obtain the multi-valued functions for |
---|
532 | every combinational output. For each combinational output, a vertex in the |
---|
533 | graph is created. For each combinational input in the support of a given |
---|
534 | combinational output MVF, a vertex is created for the combinational input |
---|
535 | (if one doesn't already exist), and an edge is added from the combinational |
---|
536 | input to the combinational output. The support of an MVF is taken as the |
---|
537 | union of the support of its constituent MDDs.] |
---|
538 | |
---|
539 | SideEffects [] |
---|
540 | |
---|
541 | SeeAlso [Part_NetworkCreatePartition] |
---|
542 | |
---|
543 | ******************************************************************************/ |
---|
544 | int |
---|
545 | PartPartitionInOutChangeRoots( |
---|
546 | Ntk_Network_t *network, |
---|
547 | graph_t *partition, |
---|
548 | lsList rootList, |
---|
549 | int verbosity) |
---|
550 | { |
---|
551 | Ntk_Node_t *node; /* Pointer to iterate over nodes */ |
---|
552 | mdd_manager *manager; /* Mdd manager in the partition */ |
---|
553 | lsList newRootList; |
---|
554 | lsList vertexList; |
---|
555 | lsGen gen; /* To iterate over lists */ |
---|
556 | vertex_t *vertex; |
---|
557 | char *vertexName; |
---|
558 | long initialTime, finalTime; |
---|
559 | st_table *rootNodesTable = st_init_table(st_ptrcmp, st_ptrhash); |
---|
560 | mdd_t *careSet; |
---|
561 | |
---|
562 | int prevNumOfLatchDataInput = 0; |
---|
563 | int prevNumOfPrimaryOutput = 0; |
---|
564 | int newNumOfLatchDataInput = 0; |
---|
565 | int newNumOfPrimaryOutput = 0; |
---|
566 | int overlapNumOfLatchDataInput = 0; |
---|
567 | int overlapNumOfPrimaryOutPut = 0; |
---|
568 | |
---|
569 | initialTime = util_cpu_time(); |
---|
570 | |
---|
571 | manager = PartPartitionReadMddManager(partition); |
---|
572 | vertexList = g_get_vertices(partition); |
---|
573 | |
---|
574 | lsForEachItem(vertexList, gen, vertex){ |
---|
575 | vertexName = PartVertexReadName(vertex); |
---|
576 | node = Ntk_NetworkFindNodeByName(network, vertexName); |
---|
577 | if (Ntk_NodeTestIsCombOutput(node)){ |
---|
578 | st_insert(rootNodesTable, (char *)node, (char *)(long)(-1)); |
---|
579 | if (Ntk_NodeTestIsLatchDataInput(node)){ |
---|
580 | prevNumOfLatchDataInput++; |
---|
581 | }else if (Ntk_NodeTestIsPrimaryOutput(node)){ |
---|
582 | prevNumOfPrimaryOutput++; |
---|
583 | } |
---|
584 | } |
---|
585 | } |
---|
586 | |
---|
587 | newRootList = lsCreate(); |
---|
588 | lsForEachItem(rootList, gen, node){ |
---|
589 | if (!(st_is_member(rootNodesTable, (char *)node))){ |
---|
590 | lsNewEnd(newRootList, (lsGeneric)node, LS_NH); |
---|
591 | if (Ntk_NodeTestIsLatchDataInput(node)){ |
---|
592 | newNumOfLatchDataInput++; |
---|
593 | }else if (Ntk_NodeTestIsPrimaryOutput(node)){ |
---|
594 | newNumOfPrimaryOutput++; |
---|
595 | } |
---|
596 | }else{ |
---|
597 | if (Ntk_NodeTestIsLatchDataInput(node)){ |
---|
598 | overlapNumOfLatchDataInput++; |
---|
599 | }else if (Ntk_NodeTestIsPrimaryOutput(node)){ |
---|
600 | overlapNumOfPrimaryOutPut++; |
---|
601 | } |
---|
602 | } |
---|
603 | } |
---|
604 | |
---|
605 | st_free_table(rootNodesTable); |
---|
606 | |
---|
607 | if (lsLength(newRootList) > 0){ |
---|
608 | careSet = mdd_one(manager); |
---|
609 | PartPartitionInputsOutputs(network, partition, newRootList, |
---|
610 | (lsList)0, careSet); |
---|
611 | mdd_free(careSet); |
---|
612 | } |
---|
613 | |
---|
614 | lsDestroy(newRootList, (void (*)(lsGeneric))0); |
---|
615 | |
---|
616 | finalTime = util_cpu_time(); |
---|
617 | |
---|
618 | if (verbosity >= 2){ |
---|
619 | fprintf(vis_stdout, "PART: Partition is changed.\n"); |
---|
620 | fprintf(vis_stdout, "PART: Old - %d next state functions\n", |
---|
621 | prevNumOfLatchDataInput); |
---|
622 | fprintf(vis_stdout, "PART: Old - %d primary outputs\n", |
---|
623 | prevNumOfPrimaryOutput); |
---|
624 | fprintf(vis_stdout, "PART: New - %d next state functions\n", |
---|
625 | prevNumOfLatchDataInput + newNumOfLatchDataInput); |
---|
626 | fprintf(vis_stdout, "PART: New - %d primary outputs\n", |
---|
627 | prevNumOfPrimaryOutput + newNumOfPrimaryOutput); |
---|
628 | fprintf(vis_stdout, "PART: Partitioning time = %10ld\n", |
---|
629 | (finalTime - initialTime) / 1000); |
---|
630 | Part_PartitionPrintStats(vis_stdout, partition, FALSE); |
---|
631 | } |
---|
632 | |
---|
633 | /* |
---|
634 | * Is partition increased? |
---|
635 | */ |
---|
636 | if (newNumOfLatchDataInput + newNumOfPrimaryOutput > 0){ |
---|
637 | return 1; |
---|
638 | }else{ |
---|
639 | return 0; |
---|
640 | } |
---|
641 | } /* End of PartPartitionInOutChangeRoots */ |
---|
642 | |
---|
643 | /*---------------------------------------------------------------------------*/ |
---|
644 | /* Definition of static functions */ |
---|
645 | /*---------------------------------------------------------------------------*/ |
---|
646 | |
---|
647 | |
---|
648 | |
---|
649 | |
---|
650 | |
---|
651 | |
---|
652 | |
---|
653 | |
---|
654 | |
---|
655 | |
---|
656 | |
---|