12 #include "gen_execute_VHDL.h"
13 #include "gen_model_utils.h"
14 #include "gen_model_transistor.h"
15 #include "gen_corresp.h"
16 #include "gen_search_utils.h"
17 #include "gen_symmetric.h"
18 #include "gen_optimizations.h"
19 #include "gen_display.h"
21 chain_list
*PENDING_LOFIG_CHAIN
=NULL
;
27 void SwapHeap_Manage(int mode
)
31 radindexht
=addht(1500);
32 radtable
=(char **)mbkalloc(sizeof(char *)*10000);
33 curradindex
=1; // 1 to avoid pnode=0
34 CreateHeap(sizeof(undoswap
), 0, &swap_heap
);
38 DeleteHeap(&swap_heap
);
44 int getradindex(char *name
)
47 res
=gethtitem(radindexht
, name
);
48 if (res
!=EMPTYHT
) return (int)res
;
49 radtable
[curradindex
++]=name
;
50 addhtitem(radindexht
, name
, (long)(curradindex
-1));
54 char *fastradical(locon_list
*lc
)
57 r
=(Pnode2Radical
*)&lc
->PNODE
;
58 if (r
->radindex
<1 || r
->radindex
>=curradindex
) {/*printf("%s",0x01);*/EXIT(44);}
59 return radtable
[r
->radindex
];
62 int fastindex(locon_list
*lc
)
65 r
=(Pnode2Radical
*)&lc
->PNODE
;
70 void *AddSwap(locon_list
*lc
, locon_list
*sym
)
73 temp
=(undoswap
*)AddHeapItem(&swap_heap
);
79 void UndoAndDeleteSwap(chain_list
*cl
)
81 undoswap
*temp
=(undoswap
*)cl
->DATA
;
82 SwapLoconWithSym(temp
->lc
, temp
->sym
);
83 DelHeapItem(&swap_heap
, temp
);
86 void JustFreeSwap(void *item
)
88 DelHeapItem(&swap_heap
, item
);
91 void UpdatePendingLofigChain(locon_list
*lc
, locon_list
*sym
)
93 exchange_pending_con(lc
, sym
);
96 void PushPendingLofigChain(chain_list
*cl
)
98 PENDING_LOFIG_CHAIN
=addchain(PENDING_LOFIG_CHAIN
, cl
);
101 add_pending_con((locon_list
*)cl
->DATA
, cl
);
106 void PopPendingLofigChain()
108 chain_list
*last
=PENDING_LOFIG_CHAIN
, *cl
;
109 for (cl
=(chain_list
*)last
->DATA
; cl
!=NULL
; cl
=cl
->NEXT
)
110 remove_pending_con((locon_list
*)cl
->DATA
);
111 PENDING_LOFIG_CHAIN
=PENDING_LOFIG_CHAIN
->NEXT
;
117 SymInfoItem
*FindVectorRadicalSymInChain(SymInfoItem
*sii
, locon_list
*lc
)
119 while (sii
!=NULL
&& sii
->ConnectorRadical
!=vectorradical(lc
->NAME
)) sii
=sii
->NEXT
;
123 locon_list
*FindALoconPlusIndexInChain(SymInfoItem
*ch
, locon_list
*lc_list
, int bit_wanted
)
127 for (sym
=lc_list
;sym
!=NULL
&& !(fastradical(sym
)==ch
->ConnectorRadical
&& fastindex(sym
)==bit_wanted
);sym
=sym
->NEXT
) ;
132 SymInfoItem
*AreYouMySymmetric(SymInfoItem
*ch
, locon_list
*you
/*, locon_list *me*/)
137 temp_name
=fastradical(you
);
139 for (ch1
=ch
;ch1
!=NULL
&& ch1
->ConnectorRadical
!=temp_name
;ch1
=ch1
->NEXT
) ;
144 // zinaps : a commenter
145 void SwapLoconWithSym(locon_list
*syms_locon
, locon_list
*circuit_con
)
148 ptype_list
*lfc
,*user
,*top
,*top1
;
149 mark_list
*mark0
, *mark1
;
150 ptype_list
*model_sig_last
,*model_sig_last1
;
151 int setfixed0
=0,setfixed1
=0;
154 if (GEN_DEBUG_LEVEL
>3)
155 gen_printf(3,"symmetry: for %s Swapping connector signals %s(%s) %s(%s)\n",((loins_list
*)circuit_con
->ROOT
)->INSNAME
,syms_locon
->NAME
,syms_locon
->SIG
->NAMECHAIN
->DATA
,circuit_con
->NAME
,circuit_con
->SIG
->NAMECHAIN
->DATA
);
158 UpdatePendingLofigChain(circuit_con
, syms_locon
);
160 // it's another than myself, we need to swap the fields
161 tmpsig
=syms_locon
->SIG
; syms_locon
->SIG
=circuit_con
->SIG
; circuit_con
->SIG
=tmpsig
;
162 user
=syms_locon
->USER
; syms_locon
->USER
=circuit_con
->USER
; circuit_con
->USER
=user
;
164 // les LOFIGCHAINs doivent etre updatées
166 fastswaplofigchain(syms_locon
->SIG
, circuit_con
, syms_locon
, 0);
167 fastswaplofigchain(circuit_con
->SIG
, syms_locon
, circuit_con
, 0);
170 if ((lfc
=getptype(syms_locon
->USER
,GEN_FIXED_PTYPE
))!=NULL
) setfixed0
=1;
171 if ((lfc
=getptype(circuit_con
->USER
,GEN_FIXED_PTYPE
))!=NULL
) setfixed1
=1;
172 if (setfixed0
|| setfixed1
) EXIT(110);
173 if ((setfixed0
&& !setfixed1
) || (!setfixed0
&& setfixed1
))
177 syms_locon
->USER
=delptype(syms_locon
->USER
, GEN_FIXED_PTYPE
);
178 circuit_con
->USER
=addptype(circuit_con
->USER
, GEN_FIXED_PTYPE
, circuit_con
);
182 circuit_con
->USER
=delptype(circuit_con
->USER
, GEN_FIXED_PTYPE
);
183 syms_locon
->USER
=addptype(syms_locon
->USER
, GEN_FIXED_PTYPE
, syms_locon
);
189 if ((lfc
=getptype(syms_locon
->USER
,GEN_LOCON_MARK_PTYPE
))!=NULL
)
191 mark0
=(mark_list
*)lfc
->DATA
;
195 if ((lfc
=getptype(circuit_con
->USER
,GEN_LOCON_MARK_PTYPE
))!=NULL
)
197 mark1
=(mark_list
*)lfc
->DATA
;
199 // gen_printf(5,"<%p %p>",mark0, mark1);
203 top
=getptype(circuit_con
->SIG
->USER
,GEN_VISITED_PTYPE
);
204 top1
=getptype(syms_locon
->SIG
->USER
,GEN_VISITED_PTYPE
);
205 // gen_printf(5,"(%s %s)",mark0->LOSIG->NAMECHAIN->DATA, mark1->LOSIG->NAMECHAIN->DATA);
206 if (mark0
->COUNT
>1) EXIT(55);
207 if (mark1
->COUNT
>1) EXIT(56);
208 for (model_sig_last
=(ptype_list
*)top
->DATA
; model_sig_last
&& model_sig_last
->DATA
!=mark1
; model_sig_last
=model_sig_last
->NEXT
) ;
209 if (model_sig_last
==NULL
) EXIT(35);
211 for (model_sig_last1
=(ptype_list
*)top1
->DATA
; model_sig_last1
&& model_sig_last1
->DATA
!=mark0
; model_sig_last1
=model_sig_last1
->NEXT
) ;
212 if (model_sig_last1
==NULL
) EXIT(36);
214 // inversement des mark dans les LOSIGs du circuit
215 model_sig_last
->DATA
=mark0
;
216 model_sig_last1
->DATA
=mark1
;
217 type
=model_sig_last
->TYPE
; model_sig_last
->TYPE
=model_sig_last1
->TYPE
;model_sig_last1
->TYPE
=type
;
219 // remise en place des marks dans les LOCONs
220 top
=getptype(circuit_con
->USER
, GEN_LOCON_MARK_PTYPE
);
221 top1
=getptype(syms_locon
->USER
, GEN_LOCON_MARK_PTYPE
);
222 if (top
->DATA
==mark0
) EXIT(54);
226 type
=mark0
->VISITED
; mark0
->VISITED
=mark1
->VISITED
; mark1
->VISITED
=type
;
227 tmpsig
=mark0
->LOSIG
; mark0
->LOSIG
=mark1
->LOSIG
; mark1
->LOSIG
=tmpsig
;
229 else if (mark0
|| mark1
) EXIT(123);
231 // gen_printf(5,"\n");
234 locon_list
*FindConWithSym(chain_list
*locons
, locon_list
*me
)
243 tmp_name
=fastradical(me
);
244 for (cl
=locons
;cl
!=NULL
;cl
=cl
->NEXT
)
246 lc
=(locon_list
*)cl
->DATA
;
247 syms
=GetSymmetricChain(lc
);
251 avt_errmsg(GNS_ERRMSG
, "115", AVT_FATAL
, ((loins_list
*)lc
->ROOT
)->INSNAME
,lc
->NAME
);
252 // fprintf(stderr,"connector %s.%s is in coupled list but has no symetric\n",((loins_list *)lc->ROOT)->INSNAME,lc->NAME);
258 for (ch
=syms
;ch
!=NULL
&& ch
->ConnectorRadical
!=tmp_name
;ch
=ch
->NEXT
) ;
262 if ((v_me
=fastindex(me
))==-1) return NULL
;
264 for (ch
=syms
;ch
!=NULL
;ch
=ch
->NEXT
)
266 if (ch
->ConnectorRadical
==tmp_name
&& fastindex(lc
)==v_me
) break;
269 if (ch
!=NULL
) return lc
;
271 avt_errmsg(GNS_ERRMSG
, "116", AVT_FATAL
, lc
->NAME
);
272 // fprintf(stderr,"no symmetry found for connector %s in coupled connector list (1)\n",lc->NAME);
274 return NULL
; // pour la forme
277 static int COUPLED_VECTOR_MODE
;
279 chain_list
*GrabConnectors(loins_list
*li
, SymInfoItem
*syms
, int index
)
282 chain_list
*found
=NULL
;
284 int hasone
=0/*, hasnone=0*/;
287 for (cl=syms;cl!=NULL; cl=cl->NEXT)
288 if (cl->FLAGS==1) hasone=1;
289 else if (cl->FLAGS==0) hasnone=1;
293 COUPLED_VECTOR_MODE
=1;
294 for (lc
=li
->LOCON
;lc
!=NULL
;lc
=lc
->NEXT
)
296 for (cl
=syms
;cl
!=NULL
; cl
=cl
->NEXT
)
297 if (cl
->FLAGS
!=1 && cl
->ConnectorRadical
==lc
->NAME
) break;
298 else if (cl
->ConnectorRadical
==fastradical(lc
)/* && index==fastindex(lc)*/) break;
301 found
=addchain(found
, lc
);
306 COUPLED_VECTOR_MODE
=0;
312 for (lc
=li
->LOCON
;lc
!=NULL
;lc
=lc
->NEXT
)
314 for (cl
=syms
;cl
!=NULL
&& cl
->ConnectorRadical
!=lc
->NAME
;cl
=cl
->NEXT
) ; // ne marche pas pour les vecteurs
316 found
=addchain(found
, lc
);
322 for (lc
=li
->LOCON
;lc
!=NULL
;lc
=lc
->NEXT
)
324 for (cl
=syms
;cl
!=NULL
&& !(cl
->ConnectorRadical
==fastradical(lc
) && index
==fastindex(lc
));cl
=cl
->NEXT
) ; // ne marche pas pour les vecteurs
327 found
=addchain(found
, lc
);
328 // printf(" '%s'",lc->NAME);
336 avt_errmsg(GNS_ERRMSG
, "117", AVT_FATAL
);
337 // fprintf(stderr,"coupling won't work with vectors ... yet...\n");
344 chain_list
*GrabVectorConnectors(loins_list
*li
, SymInfoItem
*syms
, char *radical
, int index
)
347 chain_list
*found
=NULL
;
353 for (lc
=li
->LOCON
;lc
!=NULL
;lc
=lc
->NEXT
)
355 for (cl
=syms
; cl
!=NULL
&& !(cl
->ConnectorRadical
==fastradical(lc
) && fastindex(lc
)==index
); cl
=cl
->NEXT
) ; // ne marche pas pour les vecteurs
357 found
=addchain(found
, lc
);
362 fprintf(stderr,"implicit coupling won't work with bits\n");
369 // check if all the connectors are not fixed
370 int CheckConnectorFreedom(chain_list
*cl
)
372 for (;cl
!=NULL
;cl
=cl
->NEXT
)
373 if (isfixed((locon_list
*)cl
->DATA
)) return 1;
377 chain_list
*BuildCorrespondance(chain_list
*me
, chain_list
*you
)
380 locon_list
*found
, *lc
;
381 chain_list
*cp
, *testyou
=you
;
382 for (;me
!=NULL
&& testyou
!=NULL
;me
=me
->NEXT
,testyou
=testyou
->NEXT
)
384 lc
=(locon_list
*)me
->DATA
;
385 found
=FindConWithSym(you
, lc
);
388 // zinaps : la fonction FindConWithSym fait le exit
389 // cette erreur ne sert donc a rien, mais je la laisse quant meme
390 avt_errmsg(GNS_ERRMSG
, "118", AVT_FATAL
, lc
->NAME
);
391 // fprintf(stderr,"can not find coupled connector for '%s'\n",lc->NAME);
394 cp
=addchain(addchain(NULL
,found
), lc
);
399 avt_errmsg(GNS_ERRMSG
, "116", AVT_FATAL
, ((locon_list
*)testyou
->DATA
)->NAME
);
400 // fprintf(stderr,"no symmetry found for connector %s in coupled connector list (2)\n",((locon_list *)testyou->DATA)->NAME);
406 void free_double_chain(chain_list
*con_cl
)
409 for (ch
=con_cl
;ch
!=NULL
;ch
=ch
->NEXT
)
411 freechain((chain_list
*)ch
->DATA
);
416 locon_list
*FindLoconWithIndex(locon_list
*lc
, char *radical
, int index
)
419 while (lc
!=NULL
&& !(fastindex(lc
)==index
&& fastradical(lc
)==radical
))
424 int CheckForCrossSymmetry(locon_list
*lc
, SymInfoItem
*syms
, char *v0
, int index0
, char *v1
, int index1
, chain_list
**con_cl
)
428 if (syms
->FLAGS
==1 && index1
!=-1 && index0
!=index1
)
433 gen_printf(3,"symmetry : cross symmetry detected %s(%d) - %s(%d)\n", v0
, index1
, v1
, index0
);
434 if ((pa
=FindLoconWithIndex(lc
, v0
, index1
))==NULL
)
436 avt_errmsg(GNS_ERRMSG
, "119", AVT_FATAL
, v0
, index1
, ((loins_list
*)lc
->ROOT
)->INSNAME
);
437 // fprintf(stderr,"Could not find connector '%s(%d)' for instance '%s'\n", v0, index1, ((loins_list *)lc->ROOT)->INSNAME);
440 if ((pb
=FindLoconWithIndex(lc
, v1
, index0
))==NULL
)
442 avt_errmsg(GNS_ERRMSG
, "119", AVT_FATAL
, v1
, index0
, ((loins_list
*)lc
->ROOT
)->INSNAME
);
443 // fprintf(stderr,"Could not find connector '%s(%d)' for instance '%s'\n", v1, index0, ((loins_list *)lc->ROOT)->INSNAME);
447 if (isfixed(pa
) || isfixed(pb
))
452 *con_cl
=addchain(*con_cl
, addchain(addchain(NULL
,pb
), pa
));
455 // implicit coupling for the other signal in symmetric list
456 for (ch
=syms
;ch
!=NULL
;ch
=ch
->NEXT
)
458 if (strcmp(ch
->ConnectorRadical
, v0
)!=0 &&
459 strcmp(ch
->ConnectorRadical
, v1
)!=0)
461 gen_printf(3,"symmetry : implicit coupling %s(%d) - %s(%d)\n", ch
->ConnectorRadical
, index0
, ch
->ConnectorRadical
, index1
);
462 if ((pa
=FindLoconWithIndex(lc
, ch
->ConnectorRadical
, index1
))==NULL
)
464 avt_errmsg(GNS_ERRMSG
, "119", AVT_FATAL
, ch
->ConnectorRadical
, index1
, ((loins_list
*)lc
->ROOT
)->INSNAME
);
465 // fprintf(stderr,"Could not find connector '%s(%d)' for instance '%s'\n", ch->ConnectorRadical, index1, ((loins_list *)lc->ROOT)->INSNAME);
468 if ((pb
=FindLoconWithIndex(lc
, ch
->ConnectorRadical
, index0
))==NULL
)
470 avt_errmsg(GNS_ERRMSG
, "119", AVT_FATAL
, ch
->ConnectorRadical
, index0
, ((loins_list
*)lc
->ROOT
)->INSNAME
);
471 // fprintf(stderr,"Could not find connector '%s(%d)' for instance '%s'\n", ch->ConnectorRadical, index0, ((loins_list *)lc->ROOT)->INSNAME);
475 if (isfixed(pa
) || isfixed(pb
))
480 *con_cl
=addchain(*con_cl
, addchain(addchain(NULL
,pb
), pa
));
487 static void bit_swapping(chain_list
*bi_list
, char *radi
, int index0
, int index1
)
490 chain_list
*a0
=NULL
, *a1
=NULL
, *b0
=NULL
, *b1
=NULL
;
492 locon_list
*one
, *two
;
494 for (cl
=bi_list
;cl
!=NULL
;cl
=cl
->NEXT
)
496 one
=(locon_list
*)((chain_list
*)cl
->DATA
)->DATA
;
497 two
=(locon_list
*)((chain_list
*)cl
->DATA
)->NEXT
->DATA
;
500 if (fastradical(one
)==radi
&& fastindex(one
)==index0
)
502 a0
=(chain_list
*)cl
->DATA
; a1
=((chain_list
*)cl
->DATA
)->NEXT
;
507 if (fastradical(one
)==radi
&& fastindex(one
)==index1
)
509 b0
=(chain_list
*)cl
->DATA
; b1
=((chain_list
*)cl
->DATA
)->NEXT
;
513 if (a0
==NULL
|| b0
==NULL
)
515 avt_errmsg(GNS_ERRMSG
, "004", AVT_FATAL
, 191);
516 // avt_error("gns", 1, AVT_ERR, "Internal error\n");
519 temp
=a0
->DATA
; a0
->DATA
=b0
->DATA
; b0
->DATA
=temp
;
520 // temp=a1->DATA; a1->DATA=b1->DATA; b1->DATA=temp;
524 int TryToSwapWithAConnectorWithTheSameName(locon_list
**circuit_c
, locon_list
*model_con
, SymInfoItem
*syms
, int bit_wanted
)
526 chain_list
*con_cl
, *cl
;
528 locon_list
*sym
, *one
, *two
;
529 locon_list
*circuit_con
=*circuit_c
;
533 tmp_name
=/*vectorradical(*/model_con
->NAME
/*)*/;
535 ch
=FindVectorRadicalSymInChain(syms
, model_con
);
537 if (ch
==NULL
) return 0;
539 if (!(fastradical(circuit_con
)==model_con
->NAME
&& fastindex(circuit_con
)==bit_wanted
))
541 chain_list
*circuit_list
, *sym_list
;
542 SymInfoItem
*circuit_list_p
, *sym_list_p
;
543 // search for the symmetric locon
545 gen_printf(3,"symmetry (A): '%s' found instead of '%s(%d)'\n",circuit_con
->NAME
,model_con
->NAME
, bit_wanted
);
547 if (isfixed(circuit_con
))
549 gen_printf(3,"*** fixed *** %s.%s\n",((loins_list
*)circuit_con
->ROOT
)->INSNAME
,circuit_con
->NAME
);
553 sym
=FindALoconPlusIndexInChain(ch
, ((loins_list
*)circuit_con
->ROOT
)->LOCON
, bit_wanted
);
558 // it simply means that the instance won't match because its
559 // paramaters don't match
560 gen_printf(3,"connector '%s(%d)' not found\n",model_con
->NAME
,bit_wanted
);
563 // it's fixed, we can do nothing about the swap
567 gen_printf(3,"*** fixed2 *** %s.%s",((loins_list
*)sym
->ROOT
)->INSNAME
,sym
->NAME
);
571 circuit_list_p
=GetCoupledChain(circuit_con
);
572 sym_list_p
=GetCoupledChain(sym
);
573 if (!((circuit_list_p
==NULL
&& sym_list_p
==NULL
) || (sym_list_p
!=NULL
&& circuit_list_p
!=NULL
)))
575 avt_errmsg(GNS_ERRMSG
, "120", AVT_FATAL
, circuit_con
->NAME
,sym
->NAME
);
576 // fprintf(stderr,"while swapping %s and %s, one of the connector did not have coupled connector list while the other has\n",circuit_con->NAME,sym->NAME);
580 if (circuit_list_p
!=NULL
)// && (fastindex(circuit_con)==-1 || (fastindex(circuit_con)!=-1 && fastradical(circuit_con)!=fastradical(sym))))
582 // there are coupled connectors
583 circuit_list
=GrabConnectors((loins_list
*)circuit_con
->ROOT
, circuit_list_p
, fastindex(circuit_con
));
584 sym_list
=GrabConnectors((loins_list
*)circuit_con
->ROOT
, sym_list_p
, fastindex(sym
));
586 if (CheckConnectorFreedom(circuit_list
) || CheckConnectorFreedom(sym_list
))
588 freechain(circuit_list
);
590 return 0; // at list one the connectors can't be moved
592 con_cl
=BuildCorrespondance(circuit_list
, sym_list
);
593 /* if (COUPLED_VECTOR_MODE==1)
595 bit_swapping(con_cl, fastradical(circuit_con), fastindex(circuit_con), fastindex(sym));
598 freechain(circuit_list
);
603 // we already know that the connectors can be freely moved
604 con_cl
=addchain(NULL
, addchain(addchain(NULL
,sym
), circuit_con
));
608 if (force_swap
|| CheckForCrossSymmetry(((loins_list
*)circuit_con
->ROOT
)->LOCON
, GetSymmetricChain(circuit_con
), fastradical(circuit_con
), fastindex(circuit_con
), fastradical(sym
), bit_wanted
, &con_cl
)!=0)
611 for (cl
=con_cl
;cl
!=NULL
;cl
=cl
->NEXT
)
613 one
=(locon_list
*)((chain_list
*)cl
->DATA
)->DATA
;
614 two
=(locon_list
*)((chain_list
*)cl
->DATA
)->NEXT
->DATA
;
615 SwapLoconWithSym(two
, one
);
619 free_double_chain(con_cl
);
625 free_double_chain(con_cl
);
630 printf("0. marked fixed %s.%s(%s)\n",((loins_list *)sym->ROOT)->INSNAME,sym->NAME,sym->SIG->NAMECHAIN->DATA); */
636 // return the next unfixed symmetric connector
637 // last==NULL => begin of the search
638 locon_list
*GetNextSymmetric(locon_list
*me
, locon_list
*last
)
640 locon_list
*syms_locon
;
641 SymInfoItem
*syms
, *symsrun
;
643 syms
=GetSymmetricChain(me
);
645 if (syms
==NULL
) return NULL
;
646 if (last
==NULL
) last
=((loins_list
*)me
->ROOT
)->LOCON
; // me->NEXT? pour etre + rapide ???
647 else last
=last
->NEXT
;
649 for (syms_locon
=last
;syms_locon
!=NULL
;syms_locon
=syms_locon
->NEXT
)
651 // we look in this locon is a symmetric
657 temp_name
=fastradical(syms_locon
);
661 for (symsrun
=syms
;symsrun
!=NULL
;symsrun
=symsrun
->NEXT
)
663 if (symsrun
->ConnectorRadical
==temp_name
&& !isfixed(syms_locon
))
665 gen_printf(3,"symmetry (B): slidingnext, choosing %s(%s) for %s\n",syms_locon
->NAME
,syms_locon
->SIG
->NAMECHAIN
->DATA
,me
->NAME
);
672 if ((v_me
=fastindex(me
))==-1) return NULL
;
674 for (symsrun
=syms
;symsrun
!=NULL
;symsrun
=symsrun
->NEXT
)
676 if ((v_you
=fastindex(syms_locon
))!=-1 && v_me
==v_you
)
678 if (symsrun
->ConnectorRadical
==temp_name
&& !isfixed(syms_locon
))
680 gen_printf(3,"symmetry (Bv): slidingnext, choosing %s(%s) for %s\n",syms_locon
->NAME
,syms_locon
->SIG
->NAMECHAIN
->DATA
,me
->NAME
);
691 // return the next unfixed symmetric connector
692 // last==NULL => begin of the search
693 locon_list
*GetNextSymmetric2(locon_list
*me
, locon_list
*last
)
695 locon_list
*syms_locon
;
696 SymInfoItem
*syms
, *symsrun
;
698 syms
=GetSymmetricChain(me
);
700 if (syms
==NULL
) return NULL
;
701 if (last
==NULL
) last
=me
->NEXT
;// pour etre + rapide ???
702 else last
=last
->NEXT
;
704 for (syms_locon
=last
;syms_locon
!=NULL
;syms_locon
=syms_locon
->NEXT
)
706 // we look in this locon is a symmetric
710 temp_name
=fastradical(syms_locon
);
714 for (symsrun
=syms
;symsrun
!=NULL
;symsrun
=symsrun
->NEXT
)
716 if (symsrun
->ConnectorRadical
==temp_name
&& !isfixed(syms_locon
))
718 gen_printf(3,"symmetry (B): slidingnext, choosing %s(%s) for %s\n",syms_locon
->NAME
,syms_locon
->SIG
->NAMECHAIN
->DATA
,me
->NAME
);
725 if ((v_me
=fastindex(me
))==-1) return NULL
;
727 for (symsrun
=syms
;symsrun
!=NULL
;symsrun
=symsrun
->NEXT
)
729 if ((v_you
=fastindex(syms_locon
))!=-1 && v_me
==v_you
)
731 if (symsrun
->ConnectorRadical
==temp_name
&& !isfixed(syms_locon
))
733 gen_printf(3,"symmetry (B): slidingnext, choosing %s(%s) for %s\n",syms_locon
->NAME
,syms_locon
->SIG
->NAMECHAIN
->DATA
,me
->NAME
);
744 Echange deux connections si cela est possible
745 Prend en compte les couplages
747 int TryToSwapConnectors(locon_list
*circuit_con
, locon_list
*sym
)
749 chain_list
*ch
, *con_cl
;
750 locon_list
*one
, *two
;
752 chain_list
*circuit_list
, *sym_list
;
753 SymInfoItem
*circuit_list_p
, *sym_list_p
;
755 circuit_list_p
=GetCoupledChain(circuit_con
);
756 sym_list_p
=GetCoupledChain(sym
);
757 if (!((circuit_list_p
==NULL
&& sym_list_p
==NULL
) || (sym_list_p
!=NULL
&& circuit_list_p
!=NULL
)))
759 avt_errmsg(GNS_ERRMSG
, "120", AVT_FATAL
, circuit_con
->NAME
,sym
->NAME
);
760 // fprintf(stderr,"while swapping %s and %s, one of the connector did not have coupled connector list while the other has\n",circuit_con->NAME,sym->NAME);
764 if (circuit_list_p
!=NULL
)
766 // there are coupled connectors
767 circuit_list
=GrabConnectors((loins_list
*)circuit_con
->ROOT
, circuit_list_p
, fastindex(circuit_con
));
768 sym_list
=GrabConnectors((loins_list
*)circuit_con
->ROOT
, sym_list_p
, fastindex(sym
));
770 if (CheckConnectorFreedom(circuit_list
) || CheckConnectorFreedom(sym_list
))
772 freechain(circuit_list
);
774 return 0; // at list one the connectors can't be moved
777 con_cl
=BuildCorrespondance(circuit_list
, sym_list
);
778 // were commented ---
779 freechain(circuit_list
);
781 // ------------------
785 // we already know that the connectors can be freely moved
786 con_cl
=addchain(NULL
, addchain(addchain(NULL
,sym
), circuit_con
));
789 if (CheckForCrossSymmetry(((loins_list
*)circuit_con
->ROOT
)->LOCON
, GetSymmetricChain(circuit_con
), fastradical(circuit_con
), fastindex(circuit_con
), fastradical(sym
), fastindex(sym
), &con_cl
)!=0)
792 for (ch
=con_cl
;ch
!=NULL
;ch
=ch
->NEXT
)
794 one
=(locon_list
*)((chain_list
*)ch
->DATA
)->DATA
;
795 two
=(locon_list
*)((chain_list
*)ch
->DATA
)->NEXT
->DATA
;
796 SwapLoconWithSym(two
, one
);
798 // they won't be moved anymore, except if Backward() is called
801 free_double_chain(con_cl
);
805 free_double_chain(con_cl
);
809 /* setfixed(circuit_con);
810 printf("1. marked fixed %s.%s(%s)\n",((loins_list *)circuit_con->ROOT)->INSNAME,circuit_con->NAME,circuit_con->SIG->NAMECHAIN->DATA);
815 int FindMarkContaining(locon_list
* lc
, losig_list
*ls
)
820 head
=getptype(lc
->SIG
->USER
,GEN_MARK_PTYPE
);
823 for (mark
=(mark_list
*)head
->DATA
; mark
; mark
=mark
->NEXT
)
825 if (mark
->LOSIG
==ls
) break;
828 if (mark
!=NULL
&& mark
->COUNT
==1) return 1;
832 int TryToSwapWithAConnectorWithTheSameSignalAndWithOneMark(locon_list
*circuit_con
, losig_list
*ls
, mark_list
**newmark
)
834 chain_list
*con_cl
, *cl
;
835 locon_list
*sym
, *one
, *two
;
836 SymInfoItem
*syms
, *ch
;
837 chain_list
*circuit_list
, *sym_list
;
838 SymInfoItem
*circuit_list_p
, *sym_list_p
;
839 mark_list
*cmark
, *cmark1
;
841 // if (isfixed(circuit_con)) { printf("*** fixed *** %s.%s\n",((loins_list *)circuit_con->ROOT)->INSNAME,circuit_con->NAME);} // can't be moved
842 // syms=getptype(circuit_con->USER,GEN_SYM_INFO_PTYPE);
844 syms
=GetSymmetricChain(circuit_con
);
845 if (syms
==NULL
) return 0;
847 for (sym
=((loins_list
*)circuit_con
->ROOT
)->LOCON
;sym
!=NULL
;sym
=sym
->NEXT
)
849 if (sym
!=circuit_con
)
851 ch
=AreYouMySymmetric(syms
, sym
/*, circuit_con*/);
853 if (ch
!=NULL
&& sym
->SIG
==ls
&& !isfixed(sym
))
855 if ((cmark
=getloconmark(sym
))!=NULL
&& cmark
->COUNT
==1) break;
860 if (sym
==NULL
) return 0;
862 cmark1
=getloconmark(circuit_con
);
865 gen_printf(3,"Symmetry (C): found candidate %s %c\n",sym
->NAME
,isfixed(sym
)?'F':'-');
867 if ((cmark=getloconmark(sym))!=NULL)
868 gen_printf(3,"mark_cnt_sym= %d\n",cmark->COUNT);
870 if ((cmark1=getloconmark(circuit_con))!=NULL)
871 gen_printf(3,"mark_cnt_circuit_con= %d\n",cmark1->COUNT);
873 circuit_list_p
=GetCoupledChain(circuit_con
);
874 sym_list_p
=GetCoupledChain(sym
);
875 if (!((circuit_list_p
==NULL
&& sym_list_p
==NULL
) || (sym_list_p
!=NULL
&& circuit_list_p
!=NULL
)))
877 avt_errmsg(GNS_ERRMSG
, "120", AVT_FATAL
, circuit_con
->NAME
,sym
->NAME
);
878 fprintf(stderr
,"while swapping %s and %s, one of the connector did not have coupled connector list when the other has\n",circuit_con
->NAME
,sym
->NAME
);
882 if (circuit_list_p
!=NULL
)
884 // there are coupled connectors
885 circuit_list
=GrabConnectors((loins_list
*)circuit_con
->ROOT
, circuit_list_p
, fastindex(circuit_con
));
886 sym_list
=GrabConnectors((loins_list
*)circuit_con
->ROOT
, sym_list_p
, fastindex(sym
));
888 if (CheckConnectorFreedom(circuit_list
) || CheckConnectorFreedom(sym_list
))
890 freechain(circuit_list
);
892 return 0; // at list one the connectors can't be moved
894 con_cl
=BuildCorrespondance(circuit_list
, sym_list
);
895 freechain(circuit_list
);
900 // we already know that the connectors can be freely moved
901 con_cl
=addchain(NULL
, addchain(addchain(NULL
,sym
), circuit_con
));
904 if (CheckForCrossSymmetry(((loins_list
*)circuit_con
->ROOT
)->LOCON
, syms
, fastradical(circuit_con
), fastindex(circuit_con
), fastradical(sym
), fastindex(sym
), &con_cl
)!=0)
906 for (cl
=con_cl
;cl
!=NULL
;cl
=cl
->NEXT
)
908 one
=(locon_list
*)((chain_list
*)cl
->DATA
)->DATA
;
909 if (isfixed(one
)) {free_double_chain(con_cl
); gen_printf(3,"no possible symmetry: '%s' is not free\n",ccname(one
)); return 0;}
911 two
=(locon_list
*)((chain_list
*)cl
->DATA
)->NEXT
->DATA
;
912 if (isfixed(one
)) {free_double_chain(con_cl
); gen_printf(3,"no possible symmetry: '%s' is not free\n",ccname(two
)); return 0;}
915 for (cl
=con_cl
;cl
!=NULL
;cl
=cl
->NEXT
)
917 one
=(locon_list
*)((chain_list
*)cl
->DATA
)->DATA
;
918 two
=(locon_list
*)((chain_list
*)cl
->DATA
)->NEXT
->DATA
;
919 SwapLoconWithSym(two
, one
);
923 free_double_chain(con_cl
);
927 free_double_chain(con_cl
);
931 setfixed(circuit_con
);
933 gen_printf(4,"2. now fixed %s.%s(%s)\n",((loins_list
*)circuit_con
->ROOT
)->INSNAME
,circuit_con
->NAME
,circuit_con
->SIG
->NAMECHAIN
->DATA
);
934 *newmark
=cmark1
; ///*cmark; //*/getloconmark(sym);
939 Si un connecteur i0.A est connecte' sur un mauvais signal S0
940 relie' a i1.D, s'il existe un connecteur i1.B ayant deja marque'
941 le bon signal S1, on essaie d'echanger les connections de i1.B et i1.D
944 int TryToSwapWithAConnectorWithTheMarkedSignal(locon_list
*circuit_con
, mark_list
*failedmark
, locon_list
**last
, SymInfoItem
*syms
)
950 if (failedmark
==NULL
) return 0;
954 for (lc
=(*last
)->NEXT
;lc
!=NULL
&& lc
->SIG
!=failedmark
->LOSIG
; lc
=lc
->NEXT
) ;
957 // we've found a locon connected to this signal,
958 // now we checked if it's a sym of the locon
963 ch
=AreYouMySymmetric(syms
, lc
/*, circuit_con*/);
967 // yes there's one, we exchange the connector signals
968 if (TryToSwapConnectors(circuit_con
, lc
)) return 1;
970 } else gen_printf(4,"-fixed %s-",lc
->NAME
);
978 Gestion des informations de symmetry et de couplage
980 Une table de hash permet de retrouver la liste des signaux
981 en couplage et symmetrique a partir de:
982 <nom de modele>.<nom de connecteur>
983 Un systeme de cache est cense' ameliorer les performances :)
988 chain_list
*myallocs
;
990 typedef struct biinfo
992 SymInfoItem
*syms
, *coupl
;
997 #define MAX_SYMLIST 1024
999 biinfo
*ALL_SYM_INFO
[MAX_SYMLIST
];
1009 void InitSymmetricAndCoupledInfoMecanism()
1013 for (i
=0;i
<CASHS
;i
++) {entry
[i
].model
=NULL
;entry
[i
].count
=0;}
1018 void RemoveSymmetricAndCoupledInfoMecanism()
1022 for (ch
=myallocs
;ch
!=NULL
;ch
=ch
->NEXT
)
1026 freechain(myallocs
);
1029 static char *getkey(char *a
, char *b
)
1034 for (i
=0;r
[i
]!='\0' && r
[i
]!='_'; i
++) ;
1035 if (r
[i
]=='_' && r
[i
+1]>='0' && r
[i
+1]<='9') r
[i
]='\0'; // 'toto_5_4' is model 'toto'
1036 strcat(r
,".");strcat(r
,b
);
1037 return namealloc(r
);
1040 void addcash(char *model
, char *con
, biinfo
*bf
)
1044 for (i
=1;i
<CASHS
;i
++) if (entry
[i
].count
<entry
[min
].count
) {min
=i
;}
1049 for (i
=0;i
<CASHS
;i
++) entry
[i
].count
=10;
1052 entry
[min
].model
=model
;
1057 biinfo
*getinfo(char *model
, char *con
)
1063 for (i
=0;i
<CASHS
;i
++)
1064 if (entry
[i
].model
==model
&& entry
[i
].con
==con
) {entry
[i
].count
++;return entry
[i
].info
;}
1066 name
=getkey(model
, con
);
1067 key
=((long)name
>>2);
1068 item
=gethtitem(scht
, (void *)key
);
1069 if (item
!=EMPTYHT
) {addcash(model
, con
, (biinfo
*)item
); return (biinfo
*)item
;}
1074 biinfo
*getorcreateinfo(char *model
, char *con
)
1079 if ((bf
=getinfo(model
,con
))!=NULL
) { return bf
; }
1080 bf
=(biinfo
*)mbkalloc(sizeof(biinfo
));
1083 bf
->index
=CUR_SYM_INDEX
;
1084 ALL_SYM_INFO
[CUR_SYM_INDEX
]=bf
;
1086 if (CUR_SYM_INDEX
==MAX_SYMLIST
)
1089 avt_errmsg(GNS_ERRMSG
, "121", AVT_FATAL
, MAX_SYMLIST
);
1090 // fprintf(stderr,"INTERNAL LIMITATION: too much symmetric informations.\n\tActual limit is %d.\n", MAX_SYMLIST);
1093 myallocs
=addchain(myallocs
, bf
);
1094 name
=getkey(model
, con
);
1095 key
=((long)name
>>2);
1096 addhtitem(scht
, (void *)key
, (long)bf
);
1100 void addSymmetricInfo(char *figname
, char *conname
, SymInfoItem
*syms
)
1103 bf
=getorcreateinfo(figname
, vectorradical(conname
));
1104 if (bf
->syms
!=NULL
) return; //EXIT(112);
1108 void addCoupledInfo(char *figname
, char *conname
, SymInfoItem
*coupl
)
1111 bf
=getorcreateinfo(figname
, vectorradical(conname
));
1112 if (bf
->coupl
!=NULL
) return; //EXIT(112);
1116 SymInfoItem
*GetSymmetricChain(locon_list
*lc
)
1118 if (lc
->TYPE
=='T' || lc
->FLAGS
==0) return NULL
;
1119 return ALL_SYM_INFO
[lc
->FLAGS
]->syms
;
1122 SymInfoItem
*OldFashionGetSymmetricChain(locon_list
*lc
)
1125 bf
=getinfo(((loins_list
*)lc
->ROOT
)->FIGNAME
, vectorradical(lc
->NAME
));
1126 if (bf
==NULL
) return NULL
;
1130 void SetSymmetricChainIndexInLoconFlags(locon_list
*lc
)
1133 if (lc
->TYPE
=='T') { lc
->FLAGS
=0; return; }
1134 bf
=getinfo(((loins_list
*)lc
->ROOT
)->FIGNAME
, vectorradical(lc
->NAME
));
1135 if (bf
==NULL
) { lc
->FLAGS
=0; return; }
1136 lc
->FLAGS
=bf
->index
;
1138 SymInfoItem
*GetCoupledChain(locon_list
*lc
)
1140 if (lc
->TYPE
=='T'|| lc
->FLAGS
==0) return NULL
;
1141 return ALL_SYM_INFO
[lc
->FLAGS
]->coupl
;
1144 void AddSymsOfLofig(lofig_list
*lf
)
1149 SymInfoItem
*sii
, *mysyms
;
1151 // retreive instance model
1152 syms
=getptype(lf
->USER
,GEN_SYM_INFO_PTYPE
);
1153 if (syms
==NULL
) return;
1155 for (lc
=lf
->LOCON
;lc
!=NULL
;lc
=lc
->NEXT
)
1158 // connector has sims?
1159 for (ch
=(chain_list
*)syms
->DATA
;ch
!=NULL
;ch
=ch
->NEXT
)
1161 sii
=FindVectorRadicalSymInChain((SymInfoItem
*)ch
->DATA
, lc
);
1164 // found, we add the sims
1167 avt_errmsg(GNS_ERRMSG
, "122", AVT_FATAL
);
1168 // fprintf(stderr,"AddSymsOfLofig: same signal in different symmetry list\n");
1172 mysyms
=(SymInfoItem
*)ch
->DATA
;
1177 addSymmetricInfo(lf
->NAME
, lc
->NAME
, mysyms
);
1182 void AddSymsFlagInLoinsLocon(loins_list
*li
)
1186 for (lc
=li
->LOCON
;lc
!=NULL
;lc
=lc
->NEXT
)
1188 SetSymmetricChainIndexInLoconFlags(lc
);
1192 /****************************************************************************/
1193 /* Add a list of signal names to each connector having coupled connectors */
1194 /****************************************************************************/
1195 void AddCoupledOfLofig(lofig_list
*lf
)
1200 SymInfoItem
*sii
, *mysyms
;
1202 // retreive instance model
1203 syms
=getptype(lf
->USER
,GEN_COUPLED_INFO_PTYPE
);
1204 if (syms
==NULL
) return;
1206 for (lc
=lf
->LOCON
;lc
!=NULL
;lc
=lc
->NEXT
)
1209 // connector has sims?
1210 for (ch
=(chain_list
*)syms
->DATA
;ch
!=NULL
;ch
=ch
->NEXT
)
1212 for (sii
=(SymInfoItem
*)ch
->DATA
;sii
!=NULL
&& sii
->ConnectorName
!=vectorradical(lc
->NAME
);sii
=sii
->NEXT
) ;
1215 // found, we add the sims
1218 avt_errmsg(GNS_ERRMSG
, "123", AVT_FATAL
);
1219 // fprintf(stderr,"AddCoupledOfLofig: same signal in different coupled list\n");
1223 mysyms
=(SymInfoItem
*)ch
->DATA
;
1228 addCoupledInfo(lf
->NAME
, lc
->NAME
, mysyms
);
1233 void AddRadicalInfoInPNODE(loins_list
*li
)
1238 for (lc
=li
->LOCON
; lc
!=NULL
; lc
=lc
->NEXT
)
1240 r
=(Pnode2Radical
*)&lc
->PNODE
;
1241 r
->radindex
=getradindex(vectorradical(lc
->NAME
));
1242 r
->index
=vectorindex(lc
->NAME
);
1246 void AddRadicalInfoInLOCON(locon_list
*lc
, int radindex
, int index
)
1250 r
=(Pnode2Radical
*)&lc
->PNODE
;
1251 r
->radindex
=radindex
;
1255 void ComputeWeightsForLoinsConnectors(lofig_list
*lf
)
1257 long sp
=50+curradindex
+100, cc
, coupl
=1, p
;
1260 locon_list
*lc
, *lc0
;
1262 chain_list
*circuit_list
, *cl
;
1265 if ((GEN_OPTIONS_PACK
& GEN_DEBUG_REMAPPING
)!=0)
1266 printf("compute weight on %s\n",lf
->NAME
);
1268 for (li
=lf
->LOINS
; li
!=NULL
; li
=li
->NEXT
)
1271 for (lc
=li
->LOCON
; lc
!=NULL
; lc
=lc
->NEXT
) lc
->FLAGS
=0;
1273 if ((p0
=getptype (li
->USER
, GEN_ORIG_LOINS_PTYPE
))==NULL
)
1275 if ((GEN_OPTIONS_PACK
& GEN_DEBUG_REMAPPING
)!=0)
1276 printf(" (1)%s *%s* %s\n",li
->INSNAME
,li
->FIGNAME
, li
->FIGNAME
);
1277 AddRadicalInfoInPNODE(li
);
1278 AddSymsFlagInLoinsLocon(li
);
1283 li
->FIGNAME
=((loins_list
*)p0
->DATA
)->FIGNAME
;
1284 if ((GEN_OPTIONS_PACK
& GEN_DEBUG_REMAPPING
)!=0)
1285 printf(" (2)%s *%s* %s\n",li
->INSNAME
,li
->FIGNAME
, ((loins_list
*)p0
->DATA
)->FIGNAME
);
1286 AddRadicalInfoInPNODE(li
);
1287 AddSymsFlagInLoinsLocon(li
);
1290 for (lc
=li
->LOCON
; lc
!=NULL
; lc
=lc
->NEXT
)
1292 si
=GetSymmetricChain(lc
);
1295 for (index
=1;index
<CUR_SYM_INDEX
&& ALL_SYM_INFO
[index
]->syms
!=si
; index
++) ;
1296 if (index
>=CUR_SYM_INDEX
) EXIT(124);
1301 lc
->USER
=addptype(lc
->USER
, FCL_WEIGHT_PTYPE
, (void *)cc
);
1302 if ((GEN_OPTIONS_PACK
& GEN_DEBUG_REMAPPING
)!=0)
1303 printf(" w: %s.%s %ld\n",li
->INSNAME
,lc
->NAME
,cc
);
1305 if (getptype(lc
->USER
, FCL_COUPLING_PTYPE
)!=NULL
) continue;
1312 circuit_list
=GrabVectorConnectors(li
, si
, fastradical(lc
), fastindex(lc
));
1315 if ((si
=GetCoupledChain(lc
))!=NULL
)
1317 circuit_list
=GrabConnectors(li
, si
, fastindex(lc
));
1320 if (circuit_list
!=NULL
)
1322 for (cl
=circuit_list
; cl
!=NULL
; cl
=cl
->NEXT
)
1324 lc0
=(locon_list
*)cl
->DATA
;
1326 if (getptype(lc
->USER
, FCL_COUPLING_PTYPE
)==NULL
)
1328 lc0
->USER
=addptype(lc0
->USER
, FCL_COUPLING_PTYPE
, (void *)coupl
);
1329 if ((GEN_OPTIONS_PACK
& GEN_DEBUG_REMAPPING
)!=0)
1330 printf(" cpl: %s %ld\n",lc0
->NAME
,coupl
);
1333 freechain(circuit_list
);
1339 for (lc
=li
->LOCON
; lc
!=NULL
; lc
=lc
->NEXT
)
1341 lc
->FLAGS
=(short)(long)getptype(lc
->USER
, FCL_WEIGHT_PTYPE
)->DATA
;
1342 lc
->USER
=delptype(lc
->USER
, FCL_WEIGHT_PTYPE
);
1349 static int compare_locon(const void *a
, const void *b
)
1351 locon_list
*a0
=*(locon_list
**)a
, *b0
=*(locon_list
**)b
;
1352 if (fastindex(a0
)<fastindex(b0
)) return -1;
1353 else if (fastindex(a0
)>fastindex(b0
)) return 1;
1354 EXIT(4); // a enlever
1358 static int compare_losig(const void *a
, const void *b
)
1360 losig_list
*a0
=*(losig_list
**)a
, *b0
=*(losig_list
**)b
;
1362 ia
=vectorindex((char *)a0
->NAMECHAIN
->DATA
);
1363 ib
=vectorindex((char *)b0
->NAMECHAIN
->DATA
);
1364 if (ia
<ib
) return -1;
1365 if (ia
>ib
) return 1;
1369 void TrytoArrangeSymmetricConnectors(loins_list
*li
)
1371 locon_list
*lc
, *next
, *end_lc
, *run
;
1378 for (lc
=li
->LOCON
; lc
!=NULL
; lc
=next
)
1381 if ((si
=GetSymmetricChain(lc
))==NULL
) continue;
1382 for (nb
=1, end_lc
=lc
, run
=lc
->NEXT
;
1383 run
!=NULL
&& fastradical(lc
)==fastradical(run
)
1384 && GetSymmetricChain(run
)==si
; nb
++, end_lc
=run
, run
=run
->NEXT
) ;
1386 if (nb
==1) continue;
1387 lcs
=(locon_list
**)mbkalloc(nb
*sizeof(locon_list
*));
1388 lss
=(losig_list
**)mbkalloc(nb
*sizeof(losig_list
*));
1390 sigradical
=vectorradical((char *)lc
->SIG
->NAMECHAIN
->DATA
);
1395 if (vectorindex((char *)lc
->SIG
->NAMECHAIN
->DATA
)==-1
1396 || vectorradical((char *)lc
->SIG
->NAMECHAIN
->DATA
)!=sigradical
1406 qsort(lcs
, nb
, sizeof(locon_list
*), compare_locon
);
1407 qsort(lss
, nb
, sizeof(losig_list
*), compare_losig
);
1409 for (i
=1; i
<nb
&& vectorindex((char *)lss
[i
]->NAMECHAIN
->DATA
)==vectorindex((char *)lss
[i
-1]->NAMECHAIN
->DATA
)+1; i
++) ;
1412 for (i
=0; i
<nb
; i
++)
1415 // printf("con %s -> sig %s\n", lcs[i]->NAME, (char *)lss[i]->NAMECHAIN->DATA);
1420 mbkfree(lcs
); mbkfree(lss
);
1425 typedef struct symentry
1427 struct symentry
*next
;
1446 chain_list
*BuildMatrices(chain_list
*groups
)
1448 chain_list
*cl
, *ch
;
1453 for (cl
=groups
, ch
=NULL
; cl
!=NULL
; cl
=cl
->NEXT
)
1455 se
=(symentry
*)cl
->DATA
;
1457 for (se0
=se
, h
=0; se0
!=NULL
&& se0
->nb
==w
; se0
=se0
->next
, h
++) ;
1458 if (se0
!=NULL
) EXIT(6);
1459 sm
=(SymMat
*)mbkalloc(sizeof(SymMat
));
1460 sm
->width
=w
; sm
->height
=h
;
1461 sm
->table
=(MatElem
*)mbkalloc(sizeof(MatElem
)*w
*h
);
1462 ch
=addchain(ch
, sm
);
1464 for (se0
=se
, h
=0; se0
!=NULL
; se0
=se0
->next
, h
++)
1466 for (i
=0; i
<sm
->width
; i
++)
1468 sm
->table
[h
*sm
->width
+i
].lc
=se0
->tab
[i
];
1469 sm
->table
[h
*sm
->width
+i
].ls
=se0
->tab
[i
]->SIG
;
1470 sm
->table
[h
*sm
->width
+i
].user
=se0
->tab
[i
]->USER
;
1475 for (se0
=se
; se0
!=NULL
; se0
=se
)
1486 chain_list
*GetLoinsSymmetryTables(loins_list
*li
)
1489 int index
, count
/*, cc=100*/;
1490 locon_list
*lc
, *lc0
;
1492 chain_list
*circuit_list
, *cl
;
1495 symentry
*group_list
, *se
;
1500 // printf("(1) *%s* %s\n",li->INSNAME, li->FIGNAME);
1502 li
->FIGNAME
=modelradical(li
->FIGNAME
);
1503 AddRadicalInfoInPNODE(li
);
1504 AddSymsFlagInLoinsLocon(li
);
1507 for (lc
=li
->LOCON
; lc
!=NULL
; lc
=lc
->NEXT
)
1509 if (fastindex(lc
)!=-1 && getptype(lc
->USER
, FCL_WEIGHT_PTYPE
)==NULL
)
1511 si
=GetSymmetricChain(lc
);
1514 for (index
=1;index
<CUR_SYM_INDEX
&& ALL_SYM_INFO
[index
]->syms
!=si
; index
++) ;
1515 if (index
>=CUR_SYM_INDEX
) EXIT(124);
1517 if ((l
=gethtitem(groups
, (void *)(long)index
))!=EMPTYHT
)
1518 group_list
=(symentry
*)l
;
1522 circuit_list
=GrabVectorConnectors(li
, si
, fastradical(lc
), fastindex(lc
));
1523 /* if (si->FLAGS==1)
1525 circuit_list=GrabVectorConnectors(li, si, fastradical(lc), fastindex(lc));
1528 if ((si=GetCoupledChain(lc))!=NULL)
1530 circuit_list=GrabConnectors(li, si, fastindex(lc));
1533 circuit_list=addchain(NULL, lc);
1535 for (cl
=circuit_list
, count
=0; cl
!=NULL
; cl
=cl
->NEXT
, count
++) ;
1536 se
=(symentry
*)mbkalloc(sizeof(symentry
));
1538 se
->tab
=mbkalloc(sizeof(locon_list
*)*count
);
1539 for (cl
=circuit_list
, count
=0; cl
!=NULL
; cl
=cl
->NEXT
, count
++)
1541 lc0
=(locon_list
*)cl
->DATA
;
1542 lc0
->USER
=addptype(lc0
->USER
, FCL_WEIGHT_PTYPE
, NULL
);
1546 se
->next
=group_list
;
1548 addhtitem(groups
, (void *)(long)index
, (long)group_list
);
1549 freechain(circuit_list
);
1554 for (lc
=li
->LOCON
; lc
!=NULL
; lc
=lc
->NEXT
)
1556 if (getptype(lc
->USER
, FCL_WEIGHT_PTYPE
)!=NULL
)
1557 lc
->USER
=delptype(lc
->USER
, FCL_WEIGHT_PTYPE
);
1561 // for (lc=li->LOCON, cc=1; lc!=NULL; lc=lc->NEXT, cc++) lc->FLAGS=cc;
1563 cl
=GetAllHTElems(groups
);
1568 static int SORT_INDEX
=0;
1569 #define _D_LIMITS 100000
1571 void disp_mat(int w
, int h
, MatElem
*tab
)
1574 printf("-- start -- w=%d -- h=%d --\n",w
,h
);
1575 for (j
=0;j
<_D_LIMITS
&& j
<h
;j
++)
1577 for (i
=0;i
<_D_LIMITS
&& i
<w
;i
++)
1579 printf("%10s (%10s)",tab
[j
*w
+i
].lc
->NAME
,(char *)tab
[j
*w
+i
].lc
->SIG
->NAMECHAIN
->DATA
);
1583 printf("-- end --\n");
1586 static int advanced_compare(char *a
, char *b
)
1592 while (*ai
!='\0' && *bi
!='\0')
1594 if (*ai
>='0' && *ai
<='9' && *bi
>='0' && *bi
<='9')
1596 av
=strtol(ai
, &aend
, 10);
1597 bv
=strtol(bi
, &bend
, 10);
1598 if (av
<bv
) return -1;
1599 else if (av
>bv
) return 1;
1604 if (*ai
<*bi
) return -1;
1605 else if (*ai
>*bi
) return 1;
1608 return strcmp(ai
,bi
);
1611 //#define BRUTE_FORCE
1614 static int compare_mat_line(const void *a
, const void *b
)
1616 MatElem
*a0
=(MatElem
*)a
, *b0
=(MatElem
*)b
;
1617 locon_list
*lca
, *lcb
;
1619 lca
=a0
[SORT_INDEX
].lc
;
1620 lcb
=b0
[SORT_INDEX
].lc
;
1621 // printf("%s - %s\n",(char *)lca->SIG->NAMECHAIN->DATA,(char *)lcb->SIG->NAMECHAIN->DATA);
1622 if (strcmp((char *)lca
->SIG
->NAMECHAIN
->DATA
, (char *)lcb
->SIG
->NAMECHAIN
->DATA
)<0) return -1;
1623 if (strcmp((char *)lca
->SIG
->NAMECHAIN
->DATA
, (char *)lcb
->SIG
->NAMECHAIN
->DATA
)>0) return 1;
1627 char *a_rad
, *b_rad
;
1628 int a_index
, b_index
;
1629 lca
=a0
[SORT_INDEX
].lc
;
1630 lcb
=b0
[SORT_INDEX
].lc
;
1631 a_rad
=vectorradical((char *)lca
->SIG
->NAMECHAIN
->DATA
);
1632 b_rad
=vectorradical((char *)lcb
->SIG
->NAMECHAIN
->DATA
);
1633 if (strcmp(a_rad
, b_rad
)<0) return -1;
1634 else if (strcmp(a_rad
, b_rad
)>0) return 1;
1635 a_index
=vectorindex((char *)lca
->SIG
->NAMECHAIN
->DATA
);
1636 b_index
=vectorindex((char *)lcb
->SIG
->NAMECHAIN
->DATA
);
1637 if (a_index
<b_index
) return -1;
1638 else if (a_index
>b_index
) return 1;
1641 lca
=a0
[SORT_INDEX
].lc
;
1642 lcb
=b0
[SORT_INDEX
].lc
;
1643 return advanced_compare((char *)lca
->SIG
->NAMECHAIN
->DATA
, (char *)lcb
->SIG
->NAMECHAIN
->DATA
);
1648 static void swap_locon(locon_list
*syms_locon
, locon_list
*circuit_con
)
1654 // if (GEN_DEBUG_LEVEL>3)
1655 // gen_printf(-1,"sort: for %s Swapping connector %s(%s) %s(%s)\n",((loins_list *)circuit_con->ROOT)->INSNAME,syms_locon->NAME,syms_locon->SIG->NAMECHAIN->DATA,circuit_con->NAME,circuit_con->SIG->NAMECHAIN->DATA);
1658 tmpsig
=syms_locon
->SIG
; syms_locon
->SIG
=circuit_con
->SIG
; circuit_con
->SIG
=tmpsig
;
1659 user
=syms_locon
->USER
; syms_locon
->USER
=circuit_con
->USER
; circuit_con
->USER
=user
;
1661 // les LOFIGCHAINs doivent etre updatées
1663 fastswaplofigchain(syms_locon
->SIG
, circuit_con
, syms_locon
, 0);
1664 fastswaplofigchain(circuit_con
->SIG
, syms_locon
, circuit_con
, 0);
1669 void ArrangeInstanceConnectors(loins_list
*li
)
1671 chain_list
*matrices
, *cl
;
1677 matrices
=BuildMatrices(GetLoinsSymmetryTables(li
));
1679 for (cl
=matrices
; cl
!=NULL
; cl
=cl
->NEXT
)
1681 sm
=(SymMat
*)cl
->DATA
;
1682 duptable
=(MatElem
*)mbkalloc(sm
->width
*sm
->height
*sizeof(MatElem
));
1683 memcpy(duptable
, sm
->table
, sm
->width
*sm
->height
*sizeof(MatElem
));
1685 SORT_INDEX
=0; // devrait passer par un appel de fonction pour etre determine
1687 if ((GEN_OPTIONS_PACK
& GEN_DEBUG_REMAPPING
)!=0)
1688 disp_mat(sm
->width
, sm
->height
, duptable
);
1690 qsort(duptable
, sm
->height
, sm
->width
*sizeof(MatElem
), compare_mat_line
);
1692 if ((GEN_OPTIONS_PACK
& GEN_DEBUG_REMAPPING
)!=0)
1693 disp_mat(sm
->width
, sm
->height
, duptable
);
1695 for (j
=0; j
<sm
->height
; j
++)
1697 for (i
=0; i
<sm
->width
; i
++)
1699 orig
=sm
->table
[j
*sm
->width
+i
].lc
;
1700 if (orig
!=duptable
[j
*sm
->width
+i
].lc
1701 && sm
->table
[j
*sm
->width
+i
].ls
!=duptable
[j
*sm
->width
+i
].ls
1704 // dest=duptable[j*sm->width+i].lc;
1706 orig
->SIG
=duptable
[j
*sm
->width
+i
].ls
;
1707 orig
->USER
=duptable
[j
*sm
->width
+i
].user
;
1708 if ((GEN_OPTIONS_PACK
& GEN_DEBUG_REMAPPING
)!=0)
1709 printf("%s -> %s\n",orig
->NAME
,(char*) orig
->SIG
->NAMECHAIN
->DATA
);
1710 fastswaplofigchain(orig
->SIG
, duptable
[j
*sm
->width
+i
].lc
, orig
, 1);
1720 freechain(matrices
);