Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / gsp / gsp_util.c
1 /****************************************************************************/
2 /* */
3 /* Chaine de CAO & VLSI Avertec */
4 /* */
5 /* Fichier : gsp_util.c */
6 /* */
7 /* (c) copyright 1991-2003 Avertec */
8 /* Tous droits reserves */
9 /* Support : contact@avertec.com */
10 /* */
11 /* Auteur(s) : Marc KUOCH */
12 /* */
13 /****************************************************************************/
14 /* simulation spice d'un chemin */
15 /****************************************************************************/
16 #include "gsp.h"
17
18 /*****************************************************************************/
19 /* */
20 /* FUNCTION : gsp_deltopname */
21 /* */
22 /* del top level name */
23 /* */
24 /*****************************************************************************/
25
26 void gsp_deltopname (ptype_list *cst)
27 {
28 ptype_list *ptype;
29 char *left,*right;
30
31 if (gsp_is_pat_indpd (cst) == 'Y')
32 return ;
33 for (ptype = cst; ptype; ptype = ptype->NEXT) {
34 if (ptype->TYPE == GSP_STUCK_INDPD) continue;
35 else {
36 leftunconcatname((char*)ptype->DATA,&left,&right);
37 ptype->DATA = right;
38 }
39 }
40 }
41
42 /*****************************************************************************/
43 /* */
44 /* FUNCTION : gsp_classlosig */
45 /* */
46 /* Fonction qui met la losig contenant le signal le + tardif */
47 /* dans la tete d'une chaine list */
48 /* */
49 /*****************************************************************************/
50 chain_list *gsp_classlosig (headchain, losig2class)
51 chain_list *headchain;
52 losig_list *losig2class;
53 {
54 chain_list *chain;
55 losig_list *losig;
56 chain_list *prev=NULL;
57
58 if ( headchain && ((losig_list*)headchain->DATA != losig2class) ) {
59 for (chain = headchain ; chain ; chain = chain->NEXT) {
60 losig = (losig_list*)chain->DATA;
61 if (losig == losig2class) {
62 if ( prev )
63 prev->NEXT = chain->NEXT;
64 chain->NEXT = headchain;
65 headchain = chain;
66 break;
67 }
68 prev = chain;
69 }
70 }
71
72 return headchain ;
73 }
74
75 /*****************************************************************************/
76 /* */
77 /* FUNCTION : gsp_GetLoconIn () */
78 /* */
79 /* Trouve l entree la plus tardive sur une instance */
80 /* Retourne egalement une ptype_list si plusieurs entrees connues attaquent */
81 /* cette instance. */
82 /* */
83 /*****************************************************************************/
84 locon_list *gsp_GetLoconIn(loins,listptype,slope)
85 loins_list *loins;
86 ptype_list *listptype;
87 long *slope;
88 {
89 lofig_list *lofig;
90 locon_list *locon;
91 locon_list *loconin = NULL;
92 chain_list *chainmarksig = NULL;
93 chain_list *chain;
94 ptype_list *ptype;
95 int maxnum = 0;
96 char direction,*loins_context;
97 int num;
98 ht *hash;
99
100 if (loins == NULL) return NULL;
101 if ((lofig = getloadedlofig(loins->FIGNAME)) == NULL)
102 return NULL;
103
104 for (locon = loins->LOCON ; locon ; locon = locon->NEXT) {
105 direction = locon->DIRECTION;
106 if (direction == 'X')
107 direction = (efg_FindLocon (lofig,locon->NAME))->DIRECTION;
108 if ((direction == 'I') || (direction == 'B') || (direction == 'T')) {
109 if ((ptype = getptype(locon->SIG->USER,EFG_SIG_SET)) != NULL) {
110 chainmarksig = addchain (chainmarksig,(void*)locon);
111 if (slope != NULL)
112 *slope = (long)ptype->DATA;
113 }
114 }
115 }
116 if (chainmarksig == NULL)
117 return NULL;
118 else if (chainmarksig->NEXT == NULL)
119 loconin = (locon_list*)chainmarksig->DATA;
120 else {
121 /* repere le sig le + tardif */
122 loins_context = loins->INSNAME;
123 for (chain = chainmarksig ; chain ; chain = chain->NEXT) {
124 locon = (locon_list*)chain->DATA;
125 if ((ptype = getptype(locon->SIG->USER,EFG_SIG_SET_NUM)) != NULL) {
126 hash = (ht*)ptype->DATA;
127 num = gethtitem(hash,(void*)(loins_context));
128 if ((num != EMPTYHT) && ((int)num > maxnum)) {
129 loconin = locon;
130 maxnum = (int)num;
131 }
132 }
133 }
134 listptype = gsp_FillPtypelistCst(chainmarksig,loconin);
135 }
136 freechain(chainmarksig);
137 return loconin;
138 }
139
140 /*****************************************************************************/
141 /* */
142 /* FUNCTION : gsp_GetLoconOut () */
143 /* */
144 /* Trouve la transition sur le connecteur de sortie */
145 /* */
146 /*****************************************************************************/
147 locon_list *gsp_GetLoconOut(loins,slope)
148 loins_list *loins;
149 long *slope;
150 {
151 lofig_list *lofig;
152 locon_list *locon;
153 locon_list *loconout = NULL;
154 char direction;
155 ptype_list *ptype;
156
157 if (loins == NULL) return NULL;
158 if ((lofig = getloadedlofig(loins->FIGNAME)) == NULL)
159 return NULL;
160
161 for (locon = loins->LOCON ; locon ; locon = locon->NEXT) {
162 direction = locon->DIRECTION;
163 if (direction == 'X')
164 direction = (efg_FindLocon (lofig,locon->NAME))->DIRECTION;
165 if ((direction == 'O') || (direction == 'B') ||
166 (direction == 'Z') || (direction == 'T')) {
167 if ((ptype = getptype(locon->SIG->USER,EFG_SIG_SET)) != NULL) {
168 loconout = locon;
169 if (slope != NULL)
170 *slope = (long)ptype->DATA;
171 }
172 }
173 }
174 return loconout;
175 }
176
177 /*****************************************************************************/
178 /* */
179 /* FUNCTION : gsp_GetTransition() */
180 /* */
181 /* Obtient la transition entre deux connecteurs */
182 /* */
183 /*****************************************************************************/
184 long gsp_GetTransition(loconin,loconout)
185 locon_list *loconin;
186 locon_list *loconout;
187 {
188 ptype_list *ptype;
189 char infront;
190 char outfront;
191 long trans;
192
193 if ((ptype = getptype(loconin->SIG->USER,EFG_SIG_SET)) != NULL) {
194 if (ptype->DATA == EFG_SIG_SET_RISE)
195 infront = 'U';
196 else
197 infront = 'D';
198 }
199 if ((ptype = getptype(loconout->SIG->USER,EFG_SIG_SET)) != NULL) {
200 if (ptype->DATA == EFG_SIG_SET_RISE)
201 outfront = 'U';
202 else
203 outfront = 'D';
204 }
205 if (infront == 'U') {
206 if (outfront == 'U')
207 trans = CBH_TRANS_UU ;
208 else
209 trans = CBH_TRANS_UD ;
210 }
211 else {
212 if (outfront == 'U')
213 trans = CBH_TRANS_DU ;
214 else
215 trans = CBH_TRANS_DD ;
216 }
217 return trans;
218 }
219
220 /*****************************************************************************/
221 /* */
222 /* FUNCTION : gsp_FreeMarksOnCnsfig */
223 /* */
224 /*****************************************************************************/
225 gsp_cone_info *gsp_get_cone_info(cone_list *cone)
226 {
227 ptype_list *pt;
228 if ((pt=getptype (cone->USER,GSP_CONE_NUMBER)) != NULL)
229 return (gsp_cone_info *)pt->DATA;
230 return NULL;
231 }
232
233 void gsp_delete_cone_info(cone_list *cone)
234 {
235 gsp_cone_info *ci;
236 ptype_list *pt;
237 if ((pt=getptype (cone->USER,GSP_CONE_NUMBER)) != NULL)
238 {
239 mbkfree(pt->DATA);
240 cone->USER=delptype(cone->USER,GSP_CONE_NUMBER);
241 }
242 }
243
244 gsp_cone_info *gsp_create_cone_info(cone_list *cone)
245 {
246 gsp_cone_info *ci;
247 ptype_list *pt;
248 if ((pt=getptype (cone->USER,GSP_CONE_NUMBER)) == NULL)
249 {
250 ci=(gsp_cone_info *)mbkalloc(sizeof(gsp_cone_info));
251 cone->USER=addptype(cone->USER,GSP_CONE_NUMBER, ci);
252 ci->Date=ci->MinDate=-1;
253 ci->BeforeTransitionState=ci->AfterTransitionState=-1;
254 ci->cmd=NULL;
255 ci->cmd_state=-1;
256 ci->precharged=0;
257 ci->usestate=0;
258 ci->used_ic=-1;
259 }
260 else
261 ci=(gsp_cone_info *)pt->DATA;
262 return ci;
263 }
264
265 void gsp_FreeMarksOnCnsfig (cnsfig_list *cnsfig)
266 {
267 cone_list *cone;
268
269 if (!cnsfig) return;
270 for (cone = cnsfig->CONE ; cone ; cone=cone->NEXT)
271 {
272 gsp_delete_cone_info(cone);
273 }
274 }
275
276 void gsp_FreeMarksOnCnsfigFromChainCone (chain_list *cl)
277 {
278 cone_list *cone;
279
280 while (cl!=NULL)
281 {
282 cone = (cone_list *)cl->DATA;
283 gsp_delete_cone_info(cone);
284 cl=cl->NEXT;
285 }
286 }
287
288