1 | /**CFile*********************************************************************** |
---|
2 | |
---|
3 | FileName [truesimSim.c] |
---|
4 | |
---|
5 | PackageName [truesim] |
---|
6 | |
---|
7 | Synopsis [Top-level routine to perform simulation.] |
---|
8 | |
---|
9 | Author [Balakrishna Kumthekar] |
---|
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 variable from truesimCmd.c. */ |
---|
39 | extern int truesimRptHeader; |
---|
40 | extern int truesimVerbose; |
---|
41 | |
---|
42 | /**AutomaticStart*************************************************************/ |
---|
43 | |
---|
44 | /*---------------------------------------------------------------------------*/ |
---|
45 | /* Static function prototypes */ |
---|
46 | /*---------------------------------------------------------------------------*/ |
---|
47 | |
---|
48 | |
---|
49 | /**AutomaticEnd***************************************************************/ |
---|
50 | |
---|
51 | |
---|
52 | /*---------------------------------------------------------------------------*/ |
---|
53 | /* Definition of exported functions */ |
---|
54 | /*---------------------------------------------------------------------------*/ |
---|
55 | |
---|
56 | |
---|
57 | /*---------------------------------------------------------------------------*/ |
---|
58 | /* Definition of internal functions */ |
---|
59 | /*---------------------------------------------------------------------------*/ |
---|
60 | /**Function******************************************************************** |
---|
61 | |
---|
62 | Synopsis [Entry routine to perform network simulation.] |
---|
63 | |
---|
64 | Description [Entry routine to perform network simulation. |
---|
65 | simFile provides bit-vectors for simulation. In the absence of |
---|
66 | simFile, probFile provides the primary input probabilites using with |
---|
67 | random bit-vector patterns are generated. delayFile has the |
---|
68 | <delay,load> pair for each node in the circuit. If simFile is not |
---|
69 | specified and random vectors are generated, those vectors are dumped |
---|
70 | to dumpFile. If genVectors is 0, no vectors are generated. |
---|
71 | |
---|
72 | Some of the arguments are redundant, but they are kept here for |
---|
73 | historical reasons.] |
---|
74 | |
---|
75 | SideEffects [required] |
---|
76 | |
---|
77 | ******************************************************************************/ |
---|
78 | int |
---|
79 | TruesimSimulateNetwork( |
---|
80 | Ntk_Network_t *network, |
---|
81 | char *simFile, |
---|
82 | char *probFile, |
---|
83 | char *delayFile, |
---|
84 | char *dumpFile, |
---|
85 | boolean trueDelay, |
---|
86 | int genVectors, |
---|
87 | int N) |
---|
88 | { |
---|
89 | array_t *inputArray,*patternArray; |
---|
90 | int i,status; |
---|
91 | char *str; |
---|
92 | |
---|
93 | /* inputArray stores the names of primary input nodes and patternArray stores |
---|
94 | the simulation vectors as char strings. One could use bit packing, but |
---|
95 | this is fast and simple. */ |
---|
96 | inputArray = array_alloc(Ntk_Node_t *,0); |
---|
97 | patternArray = array_alloc(char *,0); |
---|
98 | |
---|
99 | if (genVectors == 0) { /* Read simulation file */ |
---|
100 | Truesim_ReadSimulationVectors(network,simFile,inputArray,patternArray); |
---|
101 | } else { /* Generate random vectors */ |
---|
102 | array_t *probArray; |
---|
103 | int numInputs; |
---|
104 | |
---|
105 | probArray = array_alloc(float,0); |
---|
106 | Truesim_ReadInputProbabilities(network,probFile,inputArray,probArray); |
---|
107 | |
---|
108 | if(array_n(probArray) == 0) { |
---|
109 | array_free(inputArray); |
---|
110 | array_free(patternArray); |
---|
111 | array_free(probArray); |
---|
112 | return 0; |
---|
113 | } |
---|
114 | numInputs = array_n(inputArray); |
---|
115 | Truesim_GenerateRandomVectors(network,probArray,patternArray, |
---|
116 | numInputs,N); |
---|
117 | array_free(probArray); |
---|
118 | |
---|
119 | /* Output pattern vectors */ |
---|
120 | if (dumpFile) { |
---|
121 | Truesim_DumpSimulationVectors(network,inputArray,patternArray,dumpFile); |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | /* Initialize the simulation data structures */ |
---|
126 | Truesim_InitializeSimulation(network,delayFile,trueDelay,truesimRptHeader, |
---|
127 | truesimVerbose,NIL(st_table)); |
---|
128 | |
---|
129 | /* Now perform true delay simulation or zero delay simulation |
---|
130 | according to 'trueDelay' */ |
---|
131 | if (trueDelay) { /* Perform event driven simulation */ |
---|
132 | status = Truesim_RealDelayPatternSimulate(network,inputArray,patternArray); |
---|
133 | } else { /* Perform zero-delay simulation */ |
---|
134 | status = Truesim_ZeroDelayPatternSimulate(network,inputArray,patternArray); |
---|
135 | } |
---|
136 | |
---|
137 | /* End the simulation */ |
---|
138 | Truesim_QuitSimulation(network); |
---|
139 | |
---|
140 | /* Free the space used to store the input nodes */ |
---|
141 | array_free(inputArray); |
---|
142 | /* Free the pattern vectors */ |
---|
143 | arrayForEachItem(char *, patternArray,i,str) { |
---|
144 | FREE(str); |
---|
145 | } |
---|
146 | array_free(patternArray); |
---|
147 | |
---|
148 | return status; |
---|
149 | |
---|
150 | } /* End of TruesimSimulateNetwork */ |
---|
151 | |
---|
152 | /*---------------------------------------------------------------------------*/ |
---|
153 | /* Definition of static functions */ |
---|
154 | /*---------------------------------------------------------------------------*/ |
---|
155 | |
---|