-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.cpp
More file actions
995 lines (768 loc) · 25.6 KB
/
engine.cpp
File metadata and controls
995 lines (768 loc) · 25.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
/*
* engine.cpp
*
* Created on: Nov 11, 2013
* Author: babis
*/
#include "engine.hpp"
#include "./dominators/dgraph.h"
#include "auxiliary.hpp"
#include <queue>
#include <iostream>
#include <limits>
#include <boost/thread/mutex.hpp>
using namespace std;
using namespace boost;
mutex critical;
mutex critical2;
mutex critical3;
unsigned int counter = 0;
void sta_engine(node_map& PIs, vector<node*>& test_pins, clk *clock, vector<container *>& container_ptrs, int& nof_ff_clocks)
{
at_propagation( PIs, clock, container_ptrs, nof_ff_clocks );
}
void at_propagation(node_map& PIs, clk *clock, vector<container *>& container_ptrs, int& nof_ff_clocks)
{
/* Create a Q */
queue<node*> Q; // empty queue
node_map::iterator p;
/* enqueue all PIs */
for (p = PIs.begin(); p != PIs.end(); ++p)
{
/* mark PI p as visited */
p->second->visited = true;
/* Initialize path for PIs */
/* Enqueue PI */
Q.push( p->second );
}
#if !TREE_CLK_NW
vector<int> temp_arclist;
int edges = 0;
bool clk_nw_is_tree = true;
#endif
while (!Q.empty())
{
/* t <- Q.dequeue() */
node *t = Q.front();
/* for all edges in G.adjacentEdges(t) loop */
for (unsigned int i = 0; i < t->delays_forward.size(); ++i)
{
/* u <- G.adjancentVertex(t,e) */
node *u = t->delays_forward[i]->connected_to;
bool chain_reaction = false;
#if !TREE_CLK_NW
/* Extract the clock network */
if (t->clk_network == CLOCK_NODE || t->clk_network == CNW_NODE) // the father node is either a clock pin or in the clock network
{
if (u->clk_network == NOT_A_CNW_NODE) // the child node is examined for the first time
{
if (u->test_pin != NULL) // special case, the clock reaches a test pin
{
u->clk_network = CNW_TEST_NODE;
container *temp = new container;
container_ptrs.push_back( temp );
#if CACHING
temp->ff_clk_id = nof_ff_clocks++;
#endif
temp->clk_nw_node = u;
u->set_ptr.insert( temp );
set<container *>::iterator k;
for (k = t->set_ptr.begin(); k != t->set_ptr.end(); k++) // add connections
{
temp_arclist.push_back( (*k)->id );
temp_arclist.push_back( temp->id );
edges++;
}
temp->prev.insert( t->set_ptr.begin(), t->set_ptr.end() ); // backward connections
}
else
{
u->clk_network = CNW_NODE; // add it in the clock network
if (u->delays_forward.size() > 1)// fanout > 1 include the child to the graph
{
container *temp = new container;
container_ptrs.push_back( temp );
temp->id = container_ptrs.size();
#if CACHING
temp->ff_clk_id = -1;
#endif
temp->clk_nw_node = u;
u->set_ptr.insert( temp );
set<container *>::iterator k;
for (k = t->set_ptr.begin(); k != t->set_ptr.end(); k++) // add connections
{
temp_arclist.push_back( (*k)->id );
temp_arclist.push_back( temp->id );
edges++;
}
temp->prev.insert( t->set_ptr.begin(), t->set_ptr.end() ); // backward connections
}
else if (u->delays_forward.size() == 1) // fanout = 1, exclude the child from the graph
{
unsigned int old_size = u->set_ptr.size();
u->set_ptr.insert( t->set_ptr.begin(), t->set_ptr.end() ); // merge sets
if (old_size != u->set_ptr.size())
{
chain_reaction = true;
}
}
}
}
else if (u->clk_network == FF_CLOCK_NODE) // the child is a flip flop clock pin, include it to the graph despite the fanout
{
if (!u->set_ptr.empty()) // this child was processed before, the graph is not a tree!!
{
clk_nw_is_tree = false;
set<container *>::iterator k;
for (k = t->set_ptr.begin(); k != t->set_ptr.end(); k++) // add connections
{
temp_arclist.push_back( (*k)->id );
temp_arclist.push_back( (*(u->set_ptr.begin()))->id );
edges++;
}
(*(u->set_ptr.begin()))->prev.insert( t->set_ptr.begin(), t->set_ptr.end() ); // backward connections
}
else // first occurrence of the child
{
container *temp = new container;
container_ptrs.push_back( temp );
temp->id = container_ptrs.size();
#if CACHING
temp->ff_clk_id = nof_ff_clocks++;
#endif
temp->clk_nw_node = u;
u->set_ptr.insert( temp );
set<container *>::iterator k;
for (k = t->set_ptr.begin(); k != t->set_ptr.end(); k++) // add connections
{
temp_arclist.push_back( (*k)->id );
temp_arclist.push_back( temp->id );
edges++;
}
temp->prev.insert( t->set_ptr.begin(), t->set_ptr.end() ); // backward connections
}
}
else if (u->clk_network == CNW_TEST_NODE) // the child was processed before, the graph is not a tree!!
{
clk_nw_is_tree = false;
set<container *>::iterator k;
for (k = t->set_ptr.begin(); k != t->set_ptr.end(); k++) // add connections
{
temp_arclist.push_back( (*k)->id );
temp_arclist.push_back( (*(u->set_ptr.begin()))->id );
edges++;
}
(*(u->set_ptr.begin()))->prev.insert( t->set_ptr.begin(), t->set_ptr.end() ); // backward connections
}
else // the child was processed before, the graph is not a tree!!
{
clk_nw_is_tree = false;
if (u->delays_forward.size() > 1) // fanout > 1 include the child to the graph
{
set<container *>::iterator k;
for (k = t->set_ptr.begin(); k != t->set_ptr.end(); k++) // add connections
{
temp_arclist.push_back( (*k)->id );
temp_arclist.push_back( (*(u->set_ptr.begin()))->id );
edges++;
}
(*(u->set_ptr.begin()))->prev.insert( t->set_ptr.begin(), t->set_ptr.end() ); // backward connections
}
else if (u->delays_forward.size() == 1) // fanout = 1, exclude the child from the graph
{
unsigned int old_size = u->set_ptr.size();
u->set_ptr.insert( t->set_ptr.begin(), t->set_ptr.end() ); // merge sets
if (old_size != u->set_ptr.size())
{
chain_reaction = true;
}
}
}
}
#endif
#if TREE_CLK_NW
/* Extract the clock network */
if (t->clk_network == CLOCK_NODE || t->clk_network == CNW_NODE) // the father node is either a clock pin or in the clock network
{
if (u->clk_network == NOT_A_CNW_NODE) // the child node is examined for the first time
{
if (u->test_pin != NULL) // special case, the clock reaches a test pin
{
u->clk_network = CNW_TEST_NODE;
container *temp = new container;
container_ptrs.push_back( temp );
#if CACHING
temp->ff_clk_id = nof_ff_clocks++;
#endif
temp->clk_nw_node = u;
u->ptr = temp;
temp->prev = t->ptr; // backward connection
}
else
{
u->clk_network = CNW_NODE; // add it in the clock network
if (u->delays_forward.size() > 1) // fanout > 1 include the child to the graph
{
container *temp = new container;
container_ptrs.push_back( temp );
#if CACHING
temp->ff_clk_id = -1;
#endif
temp->clk_nw_node = u;
u->ptr = temp;
temp->prev = t->ptr; // backward connection
}
else if (u->delays_forward.size() == 1) // fanout = 1, exclude the child from the graph
{
u->ptr = t->ptr; // keep pointer to prev
}
}
}
else if (u->clk_network == FF_CLOCK_NODE) // the child is a flip flop clock pin, include it to the graph despite the fanout
{
container *temp = new container;
container_ptrs.push_back( temp );
#if CACHING
temp->ff_clk_id = nof_ff_clocks++;
#endif
temp->clk_nw_node = u;
u->ptr = temp;
temp->prev = t->ptr; // backward connection
}
}
#endif
/* update arrival times */
/* Early */
fp_type at_early = t->at_early + t->delays_forward[i]->delay_early;
if (at_early < u->at_early)
{
u->at_early = at_early;
chain_reaction = true;
}
/* Late */
fp_type at_late = t->at_late + t->delays_forward[i]->delay_late;
if (at_late > u->at_late)
{
u->at_late = at_late;
chain_reaction = true;
}
/* if u has not been visited yet */
if (!u->visited || chain_reaction)
{
/* u has been visited */
u->visited = true;
/* enqueue u onto Q */
Q.push( u );
}
}
/* Remove front element */
Q.pop();
}
container_ptrs.shrink_to_fit(); //trim the extra space
#if !TREE_CLK_NW
/* The clock network is not a tree, find the dominators of each node and transform the graph into a tree */
if (!clk_nw_is_tree)
{
int *arclist = new int[2 * edges];
for (unsigned int i = 0; i < temp_arclist.size(); i += 2)
{
arclist[i] = temp_arclist[i];
arclist[i + 1] = temp_arclist[i + 1];
}
DominatorGraph g;
temp_arclist.clear();
g.buildGraph( container_ptrs.size(), edges, clock->clk_nw_root->id, arclist, false );
int *idom = new int[g.getNVertices() + 1];
g.snca( clock->clk_nw_root->id, idom );
for (unsigned int i = 0; i < container_ptrs.size(); i++) // delete old connections
{
container_ptrs[i]->prev.clear();
}
for (int i = 1; i <= g.getNVertices(); i++) // recreate graph
{
if (i != idom[i])
{
container_ptrs[i - 1]->prev.insert( container_ptrs[idom[i] - 1] ); // backward connection
}
}
delete[] idom;
delete[] arclist;
}
#endif
}
void cppr(node * test, int numPaths, multiset<pathInfo>& setup_paths, multiset<pathInfo>& hold_paths, int nof_ff_clocks)
{
vector<node *> temp_path;
vector<dfs> S;
dfs initial_path;
initial_path.route = 0;
initial_path.launching_pin = NULL;
if (test->test_pin->critical_hold) // this test was critical on hold
{
initial_path.pre_slack_hold = -test->test_pin->rat_early;
}
if (test->test_pin->critical_setup) // this test was critical on setup
{
initial_path.pre_slack_setup = test->test_pin->rat_late;
}
temp_path.push_back( test );
S.push_back( initial_path );
#if DEBUGGING
int max_path_length = 0;
long num_paths = 0;
#endif
#if CACHING
vector<credit_cache> cache( nof_ff_clocks );
#endif
fp_type min_slack_post_hold = numeric_limits<fp_type>::max();
fp_type min_slack_post_setup = numeric_limits<fp_type>::max();
/* Run Depth First Search and discover all paths */
while (!S.empty())
{
dfs temp2 = S.back();
node * current = temp_path.back();
if (temp2.route < current->delays_backward.size()) // There are more routes from this node, not yet explored
{
dfs temp3 = temp2;
delay_to_node *ptr = current->delays_backward[temp2.route];
node * next = ptr->connected_to;
temp3.route = 0; // always start exploring far left child
if (next->clk_network == FF_CLOCK_NODE && temp3.launching_pin == NULL) //we found a clock pin of a flip flop for the first time
{
temp3.launching_pin = next;
}
/* backward calculation of pre slack */
if (test->test_pin->critical_hold) // this test was critical on hold
{
temp3.pre_slack_hold += ptr->delay_early;
}
if (test->test_pin->critical_setup) // this test was critical on setup
{
temp3.pre_slack_setup -= ptr->delay_late;
}
#if BRANCH_AND_BOUND
if (!test->test_pin->critical_setup)
{
if (temp3.pre_slack_hold >= 0)
{
if (!S.empty())
{
S.back().route++;
}
continue;
}
}
#endif
S.push_back( temp3 );
temp_path.push_back( next );
}
else if (current->delays_backward.empty()) // End of path, We reached a PI
{
if (test->test_pin->critical_hold) // this test was critical on hold
{
temp2.pre_slack_hold += current->at_early;
}
if (test->test_pin->critical_setup) // this test was critical on setup
{
temp2.pre_slack_setup -= current->at_late;
}
#if DEBUGGING
num_paths++;
max_path_length = temp_path.size() > max_path_length ? temp_path.size() : max_path_length;
#endif
/* Examine path */
fp_type credit_setup = 0;
fp_type credit_hold = 0;
fp_type path_pre_slack_hold = 0;
fp_type path_pre_slack_setup = 0;
if (test->test_pin->critical_hold) // this test was critical on hold
{
path_pre_slack_hold = temp2.pre_slack_hold; // pre slack for hold
}
if (test->test_pin->critical_setup) // this test was critical on setup
{
path_pre_slack_setup = temp2.pre_slack_setup; // pre slack for setup
}
int p = temp_path.size() - 1;
if (temp2.launching_pin != NULL) // this path is driven from a ff
{
#if CACHING
#if !TREE_CLK_NW
int id = (*(temp2.launching_pin->set_ptr.begin()))->ff_clk_id;
#endif
#if TREE_CLK_NW
int id = temp2.launching_pin->ptr->ff_clk_id;
#endif
if (cache[id].credit_hold != -1)
{
credit_hold = cache[id].credit_hold;
credit_setup = cache[id].credit_setup;
}
else
{
#endif
#if !TREE_CLK_NW
container * common = find_common_node( *(temp2.launching_pin->set_ptr.begin()), *(test->test_pin->clk->set_ptr.begin()) );
int next = p;
credit_hold = temp_path[p]->at_late - temp_path[p]->at_early;
while (p > 0 && temp_path[p] != common->clk_nw_node)
{
next--;
unsigned int i;
for (i = 0; temp_path[p]->delays_forward[i]->connected_to != temp_path[next]; i++)
;
credit_setup += (temp_path[p]->delays_forward[i]->delay_late - temp_path[p]->delays_forward[i]->delay_early);
p--;
}
credit_hold += credit_setup;
#endif
#if TREE_CLK_NW
container * common = find_common_node( temp2.launching_pin->ptr, test->test_pin->clk->ptr );
credit_hold = common->clk_nw_node->at_late - common->clk_nw_node->at_early;
credit_setup = credit_hold - (temp_path[p]->at_late - temp_path[p]->at_early);
#endif
#if CACHING
cache[id].credit_hold = credit_hold;
cache[id].credit_setup = credit_setup;
}
#endif
}
else if (test->clk_network == CNW_TEST_NODE && temp_path[p]->clk_network == CLOCK_NODE) // special case, this path is not driven by a ff, but connects to clock network
{
#if CACHING
#if !TREE_CLK_NW
int id = (*(test->set_ptr.begin()))->ff_clk_id;
#endif
#if TREE_CLK_NW
int id = test->ptr->ff_clk_id;
#endif
if (cache[id].credit_hold != -1)
{
credit_hold = cache[id].credit_hold;
credit_setup = cache[id].credit_setup;
}
else
{
#endif
#if !TREE_CLK_NW
container * common = find_common_node( *(test->set_ptr.begin()), *(test->test_pin->clk->set_ptr.begin()) );
int next = p;
credit_hold = temp_path[p]->at_late - temp_path[p]->at_early;
while (p > 0 && temp_path[p] != common->clk_nw_node)
{
next--;
unsigned int i;
for (i = 0; temp_path[p]->delays_forward[i]->connected_to != temp_path[next]; i++)
;
credit_setup += (temp_path[p]->delays_forward[i]->delay_late - temp_path[p]->delays_forward[i]->delay_early);
p--;
}
credit_hold += credit_setup;
#endif
#if TREE_CLK_NW
container * common = find_common_node( test->ptr, test->test_pin->clk->ptr );
credit_hold = common->clk_nw_node->at_late - common->clk_nw_node->at_early;
credit_setup = credit_hold - (temp_path[p]->at_late - temp_path[p]->at_early);
#endif
#if CACHING
cache[id].credit_hold = credit_hold;
cache[id].credit_setup = credit_setup;
}
#endif
}
if (test->test_pin->critical_hold) // this test was critical on hold
{
fp_type path_post_slack_hold = path_pre_slack_hold + credit_hold; // compute post hold slack
min_slack_post_hold = path_post_slack_hold < min_slack_post_hold ? path_post_slack_hold : min_slack_post_hold; // keep track of the min post hold slack
if (path_pre_slack_hold < 0) // this is a critical hold path
{
pathInfo temp3;
temp3.path = temp_path;
temp3.pre_slack = path_pre_slack_hold;
temp3.post_slack = path_post_slack_hold;
if (numPaths != ALL_PATHS && hold_paths.size() >= numPaths)
{
if (temp3.post_slack < (*(hold_paths.rbegin())).post_slack)
{
hold_paths.insert( temp3 ); // add this path to the hold set
hold_paths.erase( *(hold_paths.rbegin()) ); // remove the less critical
}
}
else
{
hold_paths.insert( temp3 ); // add this path to the hold set
}
#if DEBUGGING
cout << test->name << " has the following critical hold path\n";
cout << "with pre cppr hold slack = " << temp3.pre_slack << "\n";
cout << "with post cppr hold slack = " << temp3.post_slack << "\n";
for (unsigned int l = 0; l < temp3.path.size(); l++)
{
cout << temp3.path[l]->name << "\n";
}
cout << "\n\n";
#endif
}
}
if (test->test_pin->critical_setup) // this test was critical on setup
{
fp_type path_post_slack_setup = path_pre_slack_setup + credit_setup; // compute post setup slack
min_slack_post_setup = path_post_slack_setup < min_slack_post_setup ? path_post_slack_setup : min_slack_post_setup; // keep track of the min post setup slack
if (path_pre_slack_setup < 0) // this is a critical setup path
{
pathInfo temp4;
temp4.path = temp_path;
temp4.pre_slack = path_pre_slack_setup;
temp4.post_slack = path_post_slack_setup;
if (numPaths != ALL_PATHS && setup_paths.size() >= numPaths)
{
if (temp4.post_slack < (*(setup_paths.rbegin())).post_slack)
{
setup_paths.insert( temp4 ); // add this path to the setup set
setup_paths.erase( *(setup_paths.rbegin()) ); // remove the less critical
}
}
else
{
setup_paths.insert( temp4 ); // add this path to the setup set
}
#if DEBUGGING
cout << test->name << " has the following critical setup path\n";
cout << "with pre cppr setup slack = " << temp4.pre_slack << "\n";
cout << "with post cppr setup slack = " << temp4.post_slack << "\n";
for (unsigned int l = 0; l < temp4.path.size(); l++)
{
cout << temp4.path[l]->name << "\n";
}
cout << "\n\n";
#endif
}
}
temp_path.pop_back();
S.pop_back();
S.back().route++;
}
else //This node is completely explored
{
temp_path.pop_back();
S.pop_back();
if (!S.empty())
{
S.back().route++;
}
}
}
if (test->test_pin->critical_hold) // this test was critical on hold
{
test->test_pin->post_slack_hold = min_slack_post_hold;
}
if (test->test_pin->critical_setup) // this test was critical on setup
{
test->test_pin->post_slack_setup = min_slack_post_setup;
}
#if DEBUGGING
cout << "Test: " << test->name << ", Num paths = " << num_paths << ", Max length = " << max_path_length << "\n";
#endif
}
#if TREE_CLK_NW
container * find_common_node(container * launching_pin, container * capturing_pin)
{
set<container *> backward_launching_path;
set<container *> backward_capturing_path;
if (launching_pin == NULL || capturing_pin == NULL)
{
#if DEBUGGING
cout << "No common node found.\n\n";
#endif
return NULL;
}
#if DEBUGGING
cout << "Searching the common node between " << launching_pin->clk_nw_node->name << " and " << capturing_pin->clk_nw_node->name << ".\n";
#endif
if (launching_pin == capturing_pin)
{
#if DEBUGGING
cout << "The common node is " << launching_pin->clk_nw_node->name << ".\n\n";
#endif
return launching_pin;
}
container * launching_temp = launching_pin;
container * capturing_temp = capturing_pin;
backward_launching_path.insert( launching_temp ); // add the node to the backward launch path
backward_capturing_path.insert( capturing_temp ); // add the node to the backward capture path
while (launching_temp->prev != NULL || capturing_temp->prev != NULL) // While exist predecessors
{
if (launching_temp->prev != NULL)
{
launching_temp = launching_temp->prev; // extend path from launch node backward
if (backward_capturing_path.find( launching_temp ) != backward_capturing_path.end()) // is the node in the backward capture path?
{
#if DEBUGGING
cout << "The common node is " << launching_temp->clk_nw_node->name << ".\n\n";
#endif
return launching_temp;
}
backward_launching_path.insert( launching_temp ); // add the node to the backward launch path
}
if (capturing_temp->prev != NULL)
{
capturing_temp = capturing_temp->prev; // extend path from capture node backward
if (backward_launching_path.find( capturing_temp ) != backward_launching_path.end()) // is the node in the backward launch path?
{
#if DEBUGGING
cout << "The common node is " << capturing_temp->clk_nw_node->name << ".\n\n";
#endif
return capturing_temp;
}
backward_capturing_path.insert( capturing_temp ); // add the node to the backward capture path
}
}
#if DEBUGGING
cout << "No common node found.\n\n";
#endif
return NULL;
}
#endif
#if !TREE_CLK_NW
container * find_common_node(container * launching_pin, container * capturing_pin)
{
set<container *> backward_launching_path;
set<container *> backward_capturing_path;
if (launching_pin == NULL || capturing_pin == NULL)
{
#if DEBUGGING
cout << "No common node found.\n\n";
#endif
return NULL;
}
#if DEBUGGING
cout << "Searching the common node between " << launching_pin->clk_nw_node->name << " and " << capturing_pin->clk_nw_node->name << ".\n";
#endif
if (launching_pin == capturing_pin)
{
#if DEBUGGING
cout << "The common node is " << launching_pin->clk_nw_node->name << ".\n\n";
#endif
return launching_pin;
}
container * launching_temp = launching_pin;
container * capturing_temp = capturing_pin;
backward_launching_path.insert( launching_temp ); // add the node to the backward launch path
backward_capturing_path.insert( capturing_temp );// add the node to the backward capture path
while (!launching_temp->prev.empty() || !capturing_temp->prev.empty())// While exist predecessors
{
if (!launching_temp->prev.empty())
{
launching_temp = *(launching_temp->prev.begin()); // extend path from launch node backward
if (backward_capturing_path.find( launching_temp ) != backward_capturing_path.end())// is the node in the backward capture path?
{
#if DEBUGGING
cout << "The common node is " << launching_temp->clk_nw_node->name << ".\n\n";
#endif
return launching_temp;
}
backward_launching_path.insert( launching_temp ); // add the node to the backward launch path
}
if (!capturing_temp->prev.empty())
{
capturing_temp = *(capturing_temp->prev.begin()); // extend path from capture node backward
if (backward_launching_path.find( capturing_temp ) != backward_launching_path.end())// is the node in the backward launch path?
{
#if DEBUGGING
cout << "The common node is " << capturing_temp->clk_nw_node->name << ".\n\n";
#endif
return capturing_temp;
}
backward_capturing_path.insert( capturing_temp ); // add the node to the backward capture path
}
}
#if DEBUGGING
cout << "No common node found.\n\n";
#endif
return NULL;
}
#endif
void cppr_worker(vector<node*>& test_pins, clk *clock, TESTS_TYPE test, int numTests, int numPaths, multiset<testInfo> *hold_tests,
multiset<testInfo>* setup_tests, int nof_ff_clocks)
{
unsigned int local;
do
{
{
boost::mutex::scoped_lock lock( critical );
local = counter; // atomic get and increment of a global counter, each thread gets the next available job out of the job pool
#if PROGRESS_BAR
if (local < test_pins.size())
{
DrawProgressBar( 50, (( double ) local) / (test_pins.size() + 1) );
}
#endif
counter++;
}
if (local >= test_pins.size()) // the job pool is empty
{
break;
}
/* Calculate required arrival time early/late for this test */
test_pins[local]->test_pin->rat_late = clock->clk_T + test_pins[local]->test_pin->clk->at_early - test_pins[local]->test_pin->setup;
test_pins[local]->test_pin->rat_early = test_pins[local]->test_pin->clk->at_late + test_pins[local]->test_pin->hold;
/* Calculate pre slack setup/hold for this test */
test_pins[local]->test_pin->pre_slack_hold = test_pins[local]->at_early - test_pins[local]->test_pin->rat_early;
test_pins[local]->test_pin->pre_slack_setup = test_pins[local]->test_pin->rat_late - test_pins[local]->at_late;
if ((test == HOLD_TEST || test == BOTH_TESTS) && test_pins[local]->test_pin->pre_slack_hold < 0) // criticality test
{
test_pins[local]->test_pin->critical_hold = true;
}
if ((test == SETUP_TEST || test == BOTH_TESTS) && test_pins[local]->test_pin->pre_slack_setup < 0) // criticality test
{
test_pins[local]->test_pin->critical_setup = true;
}
if (!test_pins[local]->test_pin->critical_hold && !test_pins[local]->test_pin->critical_setup) // the test was not critical, skip it
{
continue;
}
multiset<pathInfo> setup_paths;
multiset<pathInfo> hold_paths;
cppr( test_pins[local], numPaths, setup_paths, hold_paths, nof_ff_clocks ); //run cppr for this test
if (!hold_paths.empty())
{
boost::mutex::scoped_lock lock( critical2 );
testInfo temp2;
temp2.pre_slack = test_pins[local]->test_pin->pre_slack_hold;
temp2.post_slack = test_pins[local]->test_pin->post_slack_hold;
temp2.paths = hold_paths;
if (numTests != ALL_TESTS && hold_tests->size() >= numTests)
{
if (temp2.post_slack < (*(hold_tests->rbegin())).post_slack)
{
hold_tests->insert( temp2 ); // add this test to the hold set
hold_tests->erase( *(hold_tests->rbegin()) ); // remove the less critical
}
}
else
{
hold_tests->insert( temp2 ); // add this test to the hold set
}
}
if (!setup_paths.empty())
{
boost::mutex::scoped_lock lock( critical3 );
testInfo temp;
temp.pre_slack = test_pins[local]->test_pin->pre_slack_setup;
temp.post_slack = test_pins[local]->test_pin->post_slack_setup;
temp.paths = setup_paths;
if (numTests != ALL_TESTS && setup_tests->size() >= numTests)
{
if (temp.post_slack < (*(setup_tests->rbegin())).post_slack)
{
setup_tests->insert( temp ); // add this test to the setup set
setup_tests->erase( *(setup_tests->rbegin()) ); // remove the less critical
}
}
else
{
setup_tests->insert( temp ); // add this test to the setup set
}
}
} while (true);
}