5 #include "stb_clocks.h"
6 #include "stb_clock_tree.h"
8 static void stb_clock_tree_mark_diverging_node(stbfig_list
*stbfig
, ttvevent_list
*event
)
11 ttvevent_list
*ckevent
;
15 if ((stbfig
->STABILITYMODE
& STB_STABILITY_LAST
) == STB_STABILITY_LAST
)
16 level
= stbfig
->FIG
->INFO
->LEVEL
;
18 level
= event
->ROOT
->ROOT
->INFO
->LEVEL
;
20 if (stbfig
->GRAPH
== STB_RED_GRAPH
)
22 ttv_expfigsig (stbfig
->FIG
, event
->ROOT
, level
, stbfig
->FIG
->INFO
->LEVEL
,
23 TTV_STS_CL_PJT
, TTV_FILE_TTX
);
28 ttv_expfigsig (stbfig
->FIG
, event
->ROOT
, level
, stbfig
->FIG
->INFO
->LEVEL
,
29 TTV_STS_CLS_FED
, TTV_FILE_DTX
);
33 for (; line
; line
= line
->NEXT
)
35 if (((line
->TYPE
& TTV_LINE_CONT
) == TTV_LINE_CONT
) ||
36 (((line
->TYPE
& (TTV_LINE_D
| TTV_LINE_T
)) != 0) &&
37 (line
->FIG
!= stbfig
->FIG
)) ||
38 (((line
->TYPE
& (TTV_LINE_P
| TTV_LINE_F
)) != 0) &&
39 (line
->FIG
!= stbfig
->FIG
) &&
40 ((stbfig
->STABILITYMODE
& STB_STABILITY_LAST
) == STB_STABILITY_LAST
)))
44 if (getptype(ckevent
->USER
, TTV_NODE_MARQUE
)!=NULL
)
46 if ((cknode
= stb_getstbnode (ckevent
))!=NULL
)
47 cknode
->FLAG
|=STB_NODE_DIVERGING
;
49 else ckevent
->USER
=addptype(ckevent
->USER
, TTV_NODE_MARQUE
, 0);
53 void stb_free_clock_tree_info(ttvevent_list
*node
)
55 node
->USER
=testanddelptype(node
->USER
, STB_CLOCK_TREE_INFO
);
58 void stb_clock_tree_mark_divergence(stbfig_list
*stbfig
)
63 for (cl
=stbfig
->NODE
; cl
!=NULL
; cl
=cl
->NEXT
)
65 node
=(ttvevent_list
*)cl
->DATA
;
66 stb_clock_tree_mark_diverging_node(stbfig
, node
);
68 for (cl
=stbfig
->NODE
; cl
!=NULL
; cl
=cl
->NEXT
)
70 node
=(ttvevent_list
*)cl
->DATA
;
71 node
->USER
=testanddelptype(node
->USER
, TTV_NODE_MARQUE
);
72 if ((pt
=getptype(node
->USER
, STB_CLOCK_TREE_INFO
))!=NULL
)
74 DelHeapItem(&stbfig
->CLOCK_TREE_HEAP
, pt
->DATA
);
75 stb_free_clock_tree_info(node
);
80 static inline stb_clock_tree
*stb_get_clock_tree(ttvevent_list
*node
)
84 if (node
==NULL
) return NULL
;
85 if ((pt
=getptype(node
->USER
, STB_CLOCK_TREE_INFO
))!=NULL
)
86 return (stb_clock_tree
*)pt
->DATA
;
91 static stb_clock_tree
*stb_give_clock_tree(stbfig_list
*sbf
, ttvevent_list
*node
)
95 if ((sct
=stb_get_clock_tree(node
))==NULL
)
97 sct
=(stb_clock_tree
*)AddHeapItem(&sbf
->CLOCK_TREE_HEAP
);
99 sct
->delaymin
=sct
->delaymax
=TTV_NOTIME
;
100 sct
->previous_divergence
=sct
->previous_divergence_hz
=NULL
;
101 node
->USER
=addptype(node
->USER
, STB_CLOCK_TREE_INFO
, sct
);
107 static int importantnode(stbnode
*node
)
110 ((node
->FLAG
& STB_NODE_DIVERGING
)!=0
111 || (node
->EVENT
->ROOT
->TYPE
& TTV_SIG_Q
)!=0)) return 1;
115 void stb_mark_path_diverging_node(stbfig_list
*sbf
, ttvpath_list
*pth
)
127 for (tc
=pth
->CRITIC
; tc
!=NULL
; tc
=tc
->NEXT
)
130 node
=stb_getstbnode (tc
->NODE
);
131 if (tc
==pth
->CRITIC
|| tc
->NEXT
==NULL
|| importantnode(node
)!=0)
133 sct
=stb_give_clock_tree(sbf
, tc
->NODE
);
135 if (tc
->NEXT
==NULL
&& (pth
->TYPE
& TTV_FIND_HZ
)==TTV_FIND_HZ
) sct
->previous_divergence_hz
=prev
;
136 else sct
->previous_divergence
=prev
;
138 if ((pth
->TYPE
& TTV_FIND_MAX
)==TTV_FIND_MAX
)
140 if (sct
->delaymax
==TTV_NOTIME
|| sct
->delaymax
<delay
)
143 if (sct
->delaymin
==TTV_NOTIME
) sct
->delaymin
=delay
;
148 if (sct
->delaymin
==TTV_NOTIME
|| sct
->delaymin
>delay
)
151 if (sct
->delaymax
==TTV_NOTIME
|| sct
->delaymax
<delay
) sct
->delaymax
=delay
;
158 static stb_clock_tree
*stb_find_common_node(ttvevent_list
*a
, ttvevent_list
*b
, int maxdepth
, ttvevent_list
**common_node
, int hza
, int hzb
)
160 stb_clock_tree
*sct_a
, *sct_b
;
161 ttvevent_list
*sct_up
;
162 int depth
=0, firsta
=1, firstb
=1;
164 if (maxdepth
==0) return NULL
;
167 if ((sct_a
=stb_get_clock_tree(a
))==NULL
) return NULL
;
168 if ((sct_b
=stb_get_clock_tree(b
))==NULL
) return NULL
;
170 while (depth
<maxdepth
&& sct_a
!=NULL
&& sct_b
!=NULL
&& sct_a
!=sct_b
)
172 if (sct_a
->level
==sct_b
->level
)
174 if (firsta
&& hza
) sct_up
=sct_a
->previous_divergence_hz
;
175 else sct_up
=sct_a
->previous_divergence
;
177 sct_a
=stb_get_clock_tree(sct_up
);
178 if (firstb
&& hzb
) sct_up
=sct_b
->previous_divergence_hz
;
179 else sct_up
=sct_b
->previous_divergence
;
180 sct_b
=stb_get_clock_tree(sct_up
);
184 else if (sct_a
->level
<sct_b
->level
)
186 if (firstb
&& hzb
) sct_up
=sct_b
->previous_divergence_hz
;
187 else sct_up
=sct_b
->previous_divergence
;
189 sct_b
=stb_get_clock_tree(sct_up
);
194 if (firsta
&& hza
) sct_up
=sct_a
->previous_divergence_hz
;
195 else sct_up
=sct_a
->previous_divergence
;
197 sct_a
=stb_get_clock_tree(sct_up
);
202 if (sct_a
==NULL
|| sct_b
==NULL
|| depth
>=maxdepth
) return NULL
;
206 int stb_get_common_node_info(ttvevent_list
*a
, ttvevent_list
*b
, int maxdepth
, long *min
, long *max
, ttvevent_list
**common_node
, int hza
, int hzb
)
209 if ((sct
=stb_find_common_node(a
, b
, maxdepth
, common_node
, hza
, hzb
))==NULL
)
217 // printf("common: for %s %s at node %s : %d %d\n", a->ROOT->NAME, b->ROOT->NAME, (*common_node)->ROOT->NAME, *min, *max);
221 ttvevent_list
*stb_get_top_node(ttvevent_list
*a
, int hza
)
223 stb_clock_tree
*sct_a
;
224 ttvevent_list
*sct_up
;
225 ttvevent_list
*top
=NULL
;
229 if ((sct_a
=stb_get_clock_tree(a
))==NULL
) return top
;
231 if (hza
) sct_up
=sct_a
->previous_divergence_hz
;
232 else sct_up
=sct_a
->previous_divergence
;
236 sct_a
=stb_get_clock_tree(sct_up
);
237 sct_up
=sct_a
->previous_divergence
;
242 long stb_get_generated_clock_common_node_info(ptype_list
*geneclockinfo
, ttvevent_list
*a
, ttvevent_list
*b
, int hza
, int hzb
, ttvevent_list
**common
)
244 ttvevent_list
*clocka
, *clockb
;
246 clocka
=stb_get_top_node(a
, hza
);
247 clockb
=stb_get_top_node(b
, hzb
);
248 minmax
=stb_get_generated_clock_skew(geneclockinfo
, clocka
, clockb
, common
);
249 if (minmax
==TTV_NOTIME
) return 0;