Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / api / tcl / router_API.c
1 /****************************************************************************/
2 /* */
3 /* Chaine de CAO & VLSI Alliance */
4 /* */
5 /* Produit : ROUTER Version 1 */
6 /* Fichier : router.c */
7 /* */
8 /* (c) copyright 1997-1998 Laboratoire LIP6 equipe ASIM */
9 /* Tous droits reserves */
10 /* Support : e-mail alliance-support@asim.lip6.fr */
11 /* */
12 /* Auteur(s) : Karim DIOURY */
13 /* */
14 /****************************************************************************/
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include MUT_H
19 #include MLO_H
20 #include RCN_H
21
22 typedef struct router_data {
23 float MINCAPA;
24 float MAXCAPA;
25 float MINRES;
26 float MAXRES;
27 int MAXWIRE;
28 } router_dt;
29
30 static int router_seed=-1;
31
32 void avt_SetSEED(int val)
33 {
34 router_seed=val;
35 }
36 /****************************************************************************/
37 /*{{{ */
38 /* */
39 /* */
40 /****************************************************************************/
41 void
42 initRouter(router_dt *rte)
43 {
44 if (router_seed!=-1) srand(router_seed);
45 rte->MINCAPA = 100.0;
46 rte->MAXCAPA = 10000.0;
47 rte->MINRES = 100.0;
48 rte->MAXRES = 10000.0;
49 rte->MAXWIRE = 1000;
50 }
51
52 long max( long a, long b )
53 {
54 if( a<b)
55 return b;
56 return a;
57 }
58
59 float route_rand(float min, float max)
60 {
61 int a, b, c;
62
63 a = (int)(max*100000.0);
64 b = (int)(min*100000.0);
65 c = b + rand()%(a-b+1);
66 return ((float)c/100000.0);
67 }
68
69 float route_capa(router_dt *rte)
70 {
71 return ((float)route_rand(rte->MINCAPA*1e15,rte->MAXCAPA*1e15))*1e-3 ;
72 }
73
74 float route_resis(router_dt *rte)
75 {
76 return ((float)route_rand(rte->MINRES,rte->MAXRES)/100.0) ;
77 }
78
79 /*}}}************************************************************************/
80 /*{{{ route_treelosig */
81 /* */
82 /* */
83 /****************************************************************************/
84 long
85 route_treelosig(losig_list *losig, long node, int nbcon,
86 num_list **loconlist, router_dt *rte)
87 {
88 num_list *ptnum ;
89 long nodex ;
90 int nbwirelist ;
91 int nbbranch ;
92 int i ;
93
94 nbwirelist = route_rand(0,rte->MAXWIRE) ;
95
96 for (i = 1; i < nbwirelist; i++, node++)
97 addlowire(losig,0,route_resis(rte),route_capa(rte),node,node+1) ;
98
99 if (nbcon == 1)
100 {
101 ptnum = *loconlist ;
102 *loconlist = (*loconlist)->NEXT ;
103 ptnum->NEXT = NULL ;
104 addlowire(losig,0,route_resis(rte),route_capa(rte),node,ptnum->DATA) ;
105 freenum(ptnum) ;
106
107 return node ;
108 }
109 else
110 nbbranch = route_rand(1,nbcon-1) ;
111
112 addlowire(losig,0,route_resis(rte),route_capa(rte),node,node+1) ;
113
114 nodex = node + 1;
115 node = route_treelosig(losig,node+1,nbbranch,loconlist,rte) ;
116
117 addlowire(losig,0,route_resis(rte),route_capa(rte),nodex,node+1) ;
118
119 node = route_treelosig(losig,node+1,nbcon-nbbranch,loconlist,rte) ;
120
121 return node;
122 }
123
124 /*}}}************************************************************************/
125 /*{{{ */
126 /* */
127 /* */
128 /****************************************************************************/
129 void
130 route_losig(losig_list *losig, router_dt *rte)
131 {
132 locon_list *locon = NULL ;
133 ptype_list *ptype ;
134 chain_list *chain ;
135 num_list *ptnum = NULL ;
136 int nbcon ;
137
138 ptype = getptype(losig->USER,LOFIGCHAIN) ;
139
140 if (losig->PRCN != NULL)
141 freelorcnet(losig) ;
142 addlorcnet(losig) ;
143
144 for (chain = ptype->DATA , nbcon = 0; chain; chain = chain->NEXT, nbcon++)
145 {
146 locon = (locon_list *)chain->DATA ;
147 setloconnode(locon,nbcon+1) ;
148 if(chain->NEXT != NULL)
149 ptnum = addnum(ptnum,locon->PNODE->DATA) ;
150 }
151
152 if (locon && nbcon != 1)
153 route_treelosig(losig,locon->PNODE->DATA,nbcon-1,&ptnum,rte) ;
154 }
155
156 /*}}}************************************************************************/
157 /*{{{ */
158 /* */
159 /* */
160 /****************************************************************************/
161 void
162 routeCC(lofig_list *lofig, router_dt *rte)
163 {
164 losig_list *losig ;
165 losig_list **tabsig ;
166 int nbsig ;
167 int i ;
168 int j ;
169 int k ;
170 int a;
171
172 for (losig = lofig->LOSIG, nbsig = 0; losig; losig = losig->NEXT)
173 if (!(mbk_LosigIsVDD(losig) || mbk_LosigIsVSS(losig)))
174 nbsig++ ;
175
176 tabsig = (losig_list **)mbkalloc(nbsig * sizeof(losig_list*)) ;
177
178 for (losig = lofig->LOSIG, nbsig = 0; losig; losig = losig->NEXT)
179 if (!(mbk_LosigIsVDD(losig) || mbk_LosigIsVSS(losig)))
180 tabsig[nbsig++] = losig ;
181
182 for (i = 0; i < nbsig; i++)
183 for (j = 1; j < tabsig[i]->PRCN->NBNODE; j++)
184 if (route_rand(0,1))
185 {
186 k = route_rand(0,nbsig-1) ;
187 a = route_rand(1,max(1,tabsig[k]->PRCN->NBNODE-1));
188 if (k != i)
189 addloctc(tabsig[i],j,tabsig[k],a,route_capa(rte));
190 }
191
192 mbkfree(tabsig) ;
193 }
194
195 /*}}}************************************************************************/
196 /*{{{ routeRC */
197 /* */
198 /* */
199 /****************************************************************************/
200 void
201 routeRC(lofig_list *lofig,router_dt *rte)
202 {
203 losig_list *losig ;
204
205 for(losig = lofig->LOSIG; losig; losig = losig->NEXT)
206 if (!(mbk_LosigIsVDD(losig) || mbk_LosigIsVSS(losig)))
207 route_losig(losig,rte);
208 }
209
210 /*}}}************************************************************************/
211 /*{{{ avt_AddRC */
212 /* */
213 /* */
214 /****************************************************************************/
215 void avt_AddRC(lofig_list *lofig, int maxwire,
216 double minc, double maxc, double minr, double maxr)
217 {
218 router_dt rte;
219
220 // for debugging purpose
221 //srand(67);
222 //printf("MC:%f mC:%f MR:%f mR:%f MW:%d\n",maxc,minc,maxr,minr,maxwire);
223
224 if (lofig!=NULL)
225 {
226 initRouter(&rte);
227
228 if (minc >= 0) rte.MINCAPA = minc;
229 if (maxc >= 0) rte.MAXCAPA = maxc;
230 if (minr >= 0) rte.MINRES = (int)(100.0*minr);
231 if (maxr >= 0) rte.MAXRES = (int)(100.0*maxr);
232 if (maxwire >= 0) rte.MAXWIRE = maxwire;
233
234 if(rte.MINCAPA > rte.MAXCAPA) rte.MINCAPA = rte.MAXCAPA ;
235 if(rte.MINRES > rte.MAXRES) rte.MINRES = rte.MAXRES ;
236
237 routeRC(lofig,&rte);
238 }
239 }
240
241 /*}}}************************************************************************/
242 /*{{{ avt_AddCC */
243 /* */
244 /* */
245 /****************************************************************************/
246 void
247 avt_AddCC(lofig_list *lofig, double minc, double maxc)
248 {
249 router_dt rte;
250
251 if (lofig!=NULL)
252 {
253 initRouter(&rte);
254
255 if (minc >= 0) rte.MINCAPA = minc;
256 if (maxc >= 0) rte.MAXCAPA = maxc;
257
258 if (rte.MINCAPA > rte.MAXCAPA) rte.MINCAPA = rte.MAXCAPA ;
259
260 routeCC(lofig,&rte);
261 }
262 }
263
264 /*}}}************************************************************************/