source: vis_dev/vis-2.3/src/truesim/truesimZero.c @ 99

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

vis2.3

File size: 8.0 KB
Line 
1/**CFile***********************************************************************
2
3  FileName    [truesimZero.c]
4
5  PackageName [truesim]
6
7  Synopsis    [Routines to perform zero-delay vector simulation.]
8
9  Author      [Balakrishna KumthekarK] <kumtheka@colorado.edu>]
10
11  Copyright [This file was created at the University of Colorado at Boulder.
12  The University of Colorado at Boulder makes no warranty about the suitability
13  of this software for any purpose.  It is presented on an AS IS basis.]
14
15******************************************************************************/
16
17#include "truesimInt.h"
18
19/*---------------------------------------------------------------------------*/
20/* Constant declarations                                                     */
21/*---------------------------------------------------------------------------*/
22
23
24/*---------------------------------------------------------------------------*/
25/* Type declarations                                                         */
26/*---------------------------------------------------------------------------*/
27
28
29/*---------------------------------------------------------------------------*/
30/* Structure declarations                                                    */
31/*---------------------------------------------------------------------------*/
32
33
34/*---------------------------------------------------------------------------*/
35/* Variable declarations                                                     */
36/*---------------------------------------------------------------------------*/
37
38/* Global variables used in truesim package. */
39extern int truesimVerbose;
40extern int truesimRptHeader;
41
42/**AutomaticStart*************************************************************/
43
44/*---------------------------------------------------------------------------*/
45/* Static function prototypes                                                */
46/*---------------------------------------------------------------------------*/
47
48static void SetInputValues(array_t *inputArray, char *vector, st_table *nodeToSimTable);
49
50/**AutomaticEnd***************************************************************/
51
52
53/*---------------------------------------------------------------------------*/
54/* Definition of exported functions                                          */
55/*---------------------------------------------------------------------------*/
56/**Function********************************************************************
57
58  Synopsis [This function performs BDD based zero-delay vector simulation.]
59
60  Description [This function performs BDD based zero-delay vector
61  simulation. The nodes in the network are simulated according to their
62  topological depth. ]
63
64  SideEffects [None]
65
66  SeeAlso []
67
68******************************************************************************/
69int
70Truesim_ZeroDelayPatternSimulate(
71  Ntk_Network_t *network,
72  array_t *inputArray,
73  array_t *patternArray)
74{
75  graph_t *partition;
76  TrueSim_t *sim;
77  st_table *nodeToSimTable;
78  Ntk_Node_t *node;
79  array_t *depthArray;
80  bdd_manager *ddManager = Ntk_NetworkReadMddManager(network);
81  lsGen gen;
82  char prev,next;
83  long numVectors = array_n(patternArray);
84  int maxDepth;
85  int i,j,k;
86 
87  nodeToSimTable = TruesimNetworkReadSimTable(network);
88  if (nodeToSimTable == NIL(st_table)) {
89    (void) fprintf(vis_stderr,
90                   "** truesim error: Simulation structures not initialized\n");
91    (void) fprintf(vis_stderr,
92                   "** truesim error: Call Truesim_InitializeSimulation before ");
93    (void) fprintf(vis_stderr,"calling this function.\n");
94    return -1;
95  }
96
97  depthArray = TruesimNetworkReadDepthArray(network);
98  maxDepth = array_n(depthArray);
99 
100  partition = Part_NetworkReadPartition(network);
101
102  /* Initialize the prob and switching fields of the simulation structure for
103     each node in the network. */
104  TruesimInitializeActivityFields(network,nodeToSimTable);
105
106  /* Warm up simulation */
107  TruesimWarmUpPatternSimulate(network,inputArray,
108                                  array_fetch(char *,patternArray,0));
109
110  for (i = 1; i < numVectors; i++) {
111    char *vector;
112    vector = array_fetch(char *,patternArray,i);
113    /* Set the input nodes to the input pattern vector. Do not update
114       the switching field of the sim structure if it is the first
115       vector */
116    SetInputValues(inputArray,vector,nodeToSimTable);
117    for (j = 1; j < maxDepth; j++) {
118      array_t *nodeList;
119     
120      nodeList = array_fetch(array_t *,depthArray,j);
121      arrayForEachItem(Ntk_Node_t *,nodeList,k,node) {
122        TrueSim_t *sim;
123
124        st_lookup(nodeToSimTable,(char *)node,&sim);
125        next =  TruesimEvaluateNode(node,partition,ddManager,
126                                    nodeToSimTable);
127        if (i != 0) {
128          prev = sim->value;
129          if (prev != next)
130            (sim->switching)++;
131        }
132        sim->value = next;
133        if (next == '1')
134          (sim->prob)++;
135      }
136    }
137    if (truesimVerbose) {
138      if (truesimRptHeader != -1) {
139        if (i % truesimRptHeader == 0) 
140          TruesimPrintNameHeader(network);
141      }
142      TruesimPrintNetworkNodeLogicState(network);
143    }
144  }
145
146  /* Update the statistics for each node */
147  Ntk_NetworkForEachNode(network,gen,node) {
148    if (!st_lookup(nodeToSimTable,(char *)node,&sim)) {
149      (void) fprintf(vis_stderr,
150                     "** truesim fatal: In Truesim_ZeroDelayPatternSimulate\n");
151      assert(0);
152    }
153    sim->switching /= ((float) array_n(patternArray));
154    sim->prob /= ((float) array_n(patternArray));
155  }
156
157  return 1;
158
159} /* End of Truesim_ZeroDelayPatternSimulate */
160
161/*---------------------------------------------------------------------------*/
162/* Definition of internal functions                                          */
163/*---------------------------------------------------------------------------*/
164
165/**Function********************************************************************
166
167  Synopsis [Simulates a single pattern to initialize initial state of network
168  nodes.]
169
170  SideEffects [None]
171
172  SeeAlso []
173
174******************************************************************************/
175void
176TruesimWarmUpPatternSimulate(
177  Ntk_Network_t *network,
178  array_t *inputArray,
179  char *vector)
180{
181  graph_t *partition;
182  st_table *nodeToSimTable;
183  array_t *depthArray;
184  Ntk_Node_t *node;
185  bdd_manager *ddManager = Ntk_NetworkReadMddManager(network);
186  long maxDepth;
187  int j,k;
188 
189  nodeToSimTable = TruesimNetworkReadSimTable(network);
190
191  depthArray = TruesimNetworkReadDepthArray(network);
192  maxDepth = array_n(depthArray);
193 
194  partition = Part_NetworkReadPartition(network);
195  /* Set the input nodes to the input pattern vector. Do not update
196     the switching field of the sim structure if it is the first
197     vector */
198  SetInputValues(inputArray,vector,nodeToSimTable);
199  for (j = 1; j < maxDepth; j++) {
200    array_t *nodeList;
201   
202    nodeList = array_fetch(array_t *,depthArray,j);
203    arrayForEachItem(Ntk_Node_t *,nodeList,k,node) {
204      TrueSim_t *sim;
205     
206      st_lookup(nodeToSimTable,(char *)node,&sim);
207      sim->value =  TruesimEvaluateNode(node,partition,ddManager,
208                                        nodeToSimTable);
209    }
210  }
211
212  /* Print network status */
213  if (truesimVerbose) {
214    TruesimPrintNameHeader(network);
215    TruesimPrintNetworkNodeLogicState(network);
216  }
217
218  return ;
219
220} /* End of TruesimWarmUpPatternSimulate */
221
222/*---------------------------------------------------------------------------*/
223/* Definition of static functions                                            */
224/*---------------------------------------------------------------------------*/
225/**Function********************************************************************
226
227  Synopsis [Initialize the vector pattern for PI.]
228
229  Description [Initialize the vector pattern for PI.]
230
231  SideEffects [None]
232
233  SeeAlso []
234
235******************************************************************************/
236static void
237SetInputValues(
238  array_t *inputArray,
239  char *vector,
240  st_table *nodeToSimTable)
241{
242  Ntk_Node_t *node;
243  TrueSim_t *sim;
244  int i;
245  char prev;
246
247  arrayForEachItem(Ntk_Node_t *,inputArray,i,node) {
248    st_lookup(nodeToSimTable,(char *)node,&sim);
249    prev = sim->value;
250    if (prev != vector[i])
251      (sim->switching)++;
252    sim->value = vector[i];
253    if (vector[i] == '1')
254      (sim->prob)++;
255  }
256} /* End of SetInputValues */
257
Note: See TracBrowser for help on using the repository browser.