-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbst.cxx
executable file
·5139 lines (4595 loc) · 166 KB
/
bst.cxx
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
995
996
997
998
999
1000
///////////////////////////////////////////////////////////////////////////////
// BSD 3-Clause License
//
// Copyright (c) 2018, The Regents of the University of California
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
///////////////////////////////////////////////////////////////////////////////
/*
#**************************************************************************
#** Please read README to see how to run this program
*** Created by Chung-Wen Albert Tsao on May 2, 2000*
#**
#**
#**************************************************************************
*/
#include <cmath>
#include "bst_header.h"
#include "bst.h"
#include "bst_sub1.h"
#include "bst_sub3.h"
#include "IME_code.h"
#include "facility.h"
#include "stdio.h"
#include "stdlib.h"
/*
Curr_Npoints is the current number of nodes (leaves + internal nodes + 1).
The leaves are numbered from 0 to nterms -1, and
the internal nodes from nterms to 2*nterms-1.`
The node indexed by "nterms" is preserved for the clock source, which
may not be used yet.
Initially, Curr_Npoints = nterms+1 , which means that
that are nterms leaves and one clock source.
Then Curr_Npoints is increased by one whenever a new tree root is produced
during bottom-up merging.
*/
static int Curr_Npoints ;
BstTree *gBoundedSkewTree ;
vector <NodeType > Node, CandiRoot, TempNode;
//AreaType *TempArea;
//int N_TempArea;
AreaType *TempArea = (AreaType*)calloc(1000, sizeof(AreaType)); //Modified
int N_TempArea=1000; //jianchao : value assigned for IME //Modified
TrrType *L_sampling, *R_sampling;
int N_Sampling = 7, n_L_sampling, n_R_sampling;
char *Marked;
int *UnMarkedNodes;
int CHECK = NO;
int Max_n_regions = 0;
int Max_irredundant_regions = 0;
int N_Area_Per_Node = 1;
int k_Parameter = -1;
int N_Neighbor = 1;
double Cost_Function = 1;
BucketType **Bucket;
int Local_Opt = NO;
int BST_Mode = BME_MODE;
int Dynamic_Selection = NO; /* no dynamic topology change */
int N_Index, MAX_N_Index;
double Start_Tcost = 0, Start_Skew_B = -2, Skew_B = 0, Skew_B_CLS[MAX_N_SINKS];
double Last_Time, Gamma=1;
double PURES[2], PUCAP[2]; /*per unit resistance and capacitance */
double PURES_V_SCALE = 1;
double PUCAP_V_SCALE = 1;
double K[2];
/* K[i] = 0.5*PURES[i]*PUCAP[i], quardratic terms in Elmore delay */
PairType *Best_Pair;
int Read_Delay_Skew_File = NO;
PointType Fms_Pt[2][2]; /* feasible merging section on JR */
int n_Fms_Pt[2];
PointType JR_corner[2];
int N_Bal_Pt[2];
PointType Bal_Pt[2][2];
int n_JR[2];
PointType JR[2][MAX_TURN_PTS];
int n_JS[2];
PointType JS[2][MAX_TURN_PTS];
TrrType L_MS, R_MS;
vector<double> EdgeLength, StubLength;
int *N_neighbors;
int **The_NEIghors;
double **Neighbor_Cost;
ClusterType *Cluster;
/* ============================= */
double MAX_x, MAX_y, MIN_x, MIN_y;
double Split_Factor = 10.0;
int *NearestCenter;
int *TmpClusterId;
TmpClusterType *TmpCluster, Tmp_x_Cluster, Tmp_y_Cluster;
/* =============================*/
int N_Buffer_Level = 1, N_Clusters[MAX_BUFFER_LEVEL], Total_CL =0;
int TreeRoots[MAX_N_SINKS]; /* nodes which are the roots */
int Cluster_id[MAX_N_NODES], *Buffered;
int R_buffer= 100;
double C_buffer= 50.0e-15*PUCAP_SCALE;
double Delay_buffer = 100e-12*PUCAP_SCALE;
int R_buffer_size[N_BUFFER_SIZE];
int All_Top = NO;
int Expand_Size = 3;
double Weight = 0.0;
int Cmode = 0;
PointType *Points;
int *TmpMarked;
double *Capac;
int Hierachy_Cluster_id[MAX_N_NODES];
int N_Obstacle = 0; /* Number of obstacles */
double MaxClusterDelay, *ClusterDelay;
int TmpCondition = NO, N_Top_Embed = 0;
double calc_merging_cost(int , int );
extern double calc_buffered_node_delay(int v);
extern int JR_corner_exist(int i);
extern void set_K();
extern void assign_NodeType(NodeType *node1, NodeType *node2);
extern int detour_Node(int v);
extern void sort_pts_on_line(PointType JR[], int n);
extern double Point_dist(PointType p1, PointType p2);
extern double pt2linedist(PointType , PointType , PointType , PointType *ans);
extern double ms_distance(TrrType *ms1,TrrType *ms2);
extern double min4(double x1, double x2, double x3,double x4);
extern double max4(double x1, double x2, double x3,double x4);
extern void kohck_Irredundant(AreaType *areas, int *n_areas);
extern void tsao_Irredundant(AreaType *areas, int *n_areas);
extern void Irredundant(AreaSetType *stair);
extern int equal(double x,double y);
extern int equivalent(double x,double y, double fuzz);
extern int pt_on_line_segment(PointType pt,PointType pt1,PointType pt2);
extern int PT_on_line_segment(PointType *pt,PointType pt1,PointType pt2);
extern int same_Point(PointType p1, PointType p2);
extern int Same_Point_delay(PointType *p, PointType *q);
extern int JS_line_type(NodeType *node);
extern int Manhattan_arc_JS(NodeType *node);
extern int area_Manhattan_arc_JS(AreaType *area);
extern double pt_skew(PointType pt);
extern double merge_cost(NodeType *node);
extern double area_merge_cost(AreaType *area);
extern int Manhattan_arc(PointType p1,PointType p2);
extern int merging_segment_area(AreaType *area);
extern int TRR_area(AreaType *area);
extern int case_Manhattan_arc();
extern void ms_to_line(TrrType *ms,double *x1,double *y1,double *x2,double *y2);
extern void ms2line(TrrType *ms, PointType *p1, PointType *p2);
extern void line_to_ms(TrrType *ms,double x1,double y1,double x2,double y2);
extern void line2ms(TrrType *ms, PointType p1, PointType p2);
extern void pts2TRR(PointType pts[], int n, TrrType *trr);
extern int trrContain(TrrType *t1,TrrType *t2);
extern int in_bbox(double x,double y,double x1,double y1,double x2,double y2);
extern void core_mid_point(TrrType *trr, PointType *p);
extern void make_intersect( TrrType *trr1, TrrType *trr2, TrrType *t );
extern void make_intersect_sub( TrrType *trr1, TrrType *trr2, TrrType *t );
extern void make_core(TrrType *trr,TrrType *core);
extern void make_1D_TRR(TrrType *trr,TrrType *core);
extern double radius(TrrType *trr);
extern void build_trr(TrrType *ms,double d,TrrType *trr);
extern double pt2ms_distance(PointType *pt, TrrType *ms);
extern double pt2TRR_distance_sub(PointType *pt, TrrType *trr);
extern double pt2TRR_distance(PointType *pt, PointType pts[], int n);
extern int bbox_overlap(double x1, double y1, double x2, double y2,
double x3, double y3, double x4, double y4);
extern int L_intersect(double *x, double *y, double x1, double y1,double x2,
double y2, double x3, double y3, double x4, double y4);
extern int lineIntersect(PointType *p, PointType p1, PointType p2, PointType p3,
PointType p4);
extern double linedist(PointType lpt0,PointType lpt1, PointType lpt2,
PointType lpt3, PointType ans[2]);
extern int parallel_line(PointType p1,PointType p2,PointType p3,PointType p4);
extern void check_Point_delay(PointType *pt);
extern void check_Point(PointType *pt);
extern void check_JS_line(NodeType *node,NodeType *node_L, NodeType *node_R);
extern void check_mss(AreaType *area,AreaType *area_L, AreaType *area_R);
extern void check_x(AreaType *, AreaType *, AreaType *, double *x);
extern void check_fms(AreaType *area_L, AreaType *area_R, int side);
extern void check_ZST_detour(NodeType *node,NodeType *node_L,NodeType *node_R);
extern void check_trr(TrrType *t) ;
extern void check_ms(TrrType *ms);
extern void check_a_sampling_segment(AreaType *area, TrrType *ms);
extern void check_tmparea(AreaType *tmparea, int n);
extern void check_const_delays(PointType *p1,PointType *p2);
extern void get_all_areas(int v, int i);
extern void store_n_areas(AreaType tmparea[], int n, NodeType *node);
extern void store_n_areas_IME(NodeType *node,AreaSetType *result);
extern void store_last_n_areas_IME(NodeType *node,AreaSetType *result);
extern void store_area_for_sink(int i);
extern void build_NodeTRR(NodeType *node);
extern double minskew(NodeType *node, int mode);
extern double maxskew(NodeType *node, int mode);
extern void print_IME_areas(NodeType *node,NodeType *node_L,
NodeType *node_R,int ,int );
extern void print_double_array(double *a, int n);
extern void print_JR_sub(FILE *f, NodeType *node);
extern void print_JS_sub(FILE *f, NodeType *node);
extern void print_merging_region(FILE *f, NodeType *node);
extern void print_node(NodeType *node) ;
extern void print_MR(NodeType *node);
extern void print_child_region(NodeType *node);
extern void print_max_npts();
extern void print_overlapped_regions();
extern void print_max_n_mr();
extern void print_n_region_type();
extern void print_tree_of_merging_segments(char fn[]);
extern void print_Bal_Pt(NodeType *node);
extern void print_Fms_Pt(NodeType *node);
extern void print_node_info(NodeType *node);
extern void print_node_informatio(NodeType *node,NodeType *node_L,
NodeType *node_R);
extern void JS_processing(AreaType *area);
extern void JS_processing_sub(AreaType *area);
extern void JS_processing_sub2(AreaType *area);
extern void recalculate_JS();
extern void remove_epsilon_err(PointType *q) ;
extern int same_line(PointType p0,PointType p1,PointType q0,PointType q1);
extern void construct_TRR_mr(AreaType *area);
extern int any_fms_on_JR();
extern void trace();
extern double calc_JR_area_sub(PointType p0,PointType p1,PointType p2,PointType p3);
extern int calc_line_type(PointType pt1,PointType pt2);
extern int calc_side_loc(int side);
extern void calc_merge_distance(double r, double c, double cap1,double delay1,
double cap2, double delay2, double d,double *d1,double *d2);
extern void new_calc_merge_distance(PointType pt1, PointType pt2, int delay_id,
double *d1,double *d2);
extern double calc_delay_increase(double p, double cap, double x, double y);
extern double pt_delay_increase(double p,double cap,PointType *q0,PointType *q1);
extern double _pt_delay_increase(double pat, double leng,double cap,
PointType *q0,PointType *q1);
extern void calc_pt_coor_on_a_line(PointType q0,PointType q1, double d0,double d1,
PointType *pts);
extern void calc_Bal_of_2pt(PointType *pt0, PointType *pt1, int delay_id,
int bal_pt_id, double *d0, double *d1, PointType *ans);
extern void check_calc_Bal_of_2pt(PointType *pt0, PointType *pt1, int delay_id,
PointType *ans, double d0, double d1);
extern void calc_vertices(AreaType *area);
extern void calc_pt_delays(AreaType *area, PointType *q1,PointType q0,PointType
q2);
extern void calc_BS_located(PointType *pt,AreaType *area, PointType *p1,
PointType *p2);
extern void calc_JS_delay(AreaType *area, AreaType *area_L,AreaType *area_R);
extern int calc_TreeCost(int v, double *Tcost, double *Tdist);
extern void print_cluster_cost(double cost);
extern void calc_BST_delay(int v);
extern void set_SuperRoot();
extern void alloca_NodeType(NodeType *node);
extern void free_NodeType(NodeType *node);
extern void ExG_DME_memory_allocation();
extern void Ex_DME_memory_allocation();
extern void read_clustering_info(char ClusterFile[]);
extern void init_marked(int v);
extern void init_turn_pt_on_JS(int side,PointType *pt);
extern void calc_merging_cost_sub(NodeType *node, int L, int R);
extern double path_between_JSline(AreaType *area, PointType line[2][2],
PointType path[],int *n);
extern int unblocked_segment(PointType *p0, PointType *p1);
extern double path_finder(PointType p1, PointType p2, PointType path[], int *n);
extern double calc_pathlength(PointType path[], int n, int mode);
extern void modify_blocked_areas(AreaType area[], int *n, int b1, int b2);
extern int calc_all_cluster_neighbors(PairType pair[], int n_clusters,int size);
extern void init_re_embed_top(int v);
extern void init_re_embed_top_sub(int v);
extern void draw_a_TRR(TrrType *trr);
void check_JR_linear_delay_skew(int side) ;
/********************************************************************/
/* find solution of equation: Ax*x+Bx+c=0 */
/********************************************************************/
static
double sol_equation(double A, double B, double C) {
double x, y;
y = B*B-4.0*A*C;
assert(y>=0);
x = (-B + sqrt(y))/(2.0*A);
assert(x > -FUZZ);
x = tMAX(0,x);
return(x);
}
/***********************************************************************/
/* Copyright (C) 1994-2000 by Andrew B. Kahng, C.-W. Albert Tsao */
/***********************************************************************/
static
double calc_x(AreaType *area) {
double x;
double r,c;
r = PURES[H_];
c = PUCAP[H_];
x = r*(area->unbuf_capac) + area->R_buffer*c;
return(x);
}
/***********************************************************************/
/* Copyright (C) 1994-2000 by Andrew B. Kahng, C.-W. Albert Tsao */
/***********************************************************************/
void calc_B0_B1(AreaType *area, double *B0, double *B1) {
double r,c;
r = PURES[H_];
c = PUCAP[H_];
*B0= r*(area->area_L->unbuf_capac) + area->area_L->R_buffer*c;
*B1= r*(area->area_R->unbuf_capac) + area->area_R->R_buffer*c;
}
/****************************************************************************/
/* */
/****************************************************************************/
double calc_merge_pt_delay_sub(AreaType *area, double d0, double d1) {
double B0, B1, x, t0, t1, r, c, cap0, cap1;
r = PURES[H_];
c = PUCAP[H_];
cap0 = area->area_L->capac;
cap1 = area->area_R->capac;
calc_B0_B1(area, &B0, &B1);
x = area->L_StubLen;
t0 = r*d0*(c*d0/2+cap0) + JS[0][0].max + K[H_]*x*x+B0*x;
x = area->R_StubLen;
t1 = r*d1*(c*d1/2+cap1) + JS[1][0].max + K[H_]*x*x+B1*x;
assert(equal(t0, t1));
return(t0);
}
/****************************************************************************/
/* */
/****************************************************************************/
void calc_merge_pt_delay(AreaType *area, double d0, double d1) {
area->mr[0].max = calc_merge_pt_delay_sub(area, d0, d1);
area->mr[0].min = area->mr[0].max - Skew_B;
check_Point_delay(&(area->mr[0]));
}
/***********************************************************************/
/* Copyright (C) 1994-2000 by Andrew B. Kahng, C.-W. Albert Tsao */
/***********************************************************************/
double set_StubLen_by_ClusterDelay(AreaType *area,double delay) {
double ans, x;
double origB = gBoundedSkewTree->Orig_Skew_B() ;
if (area->R_buffer>0) {
if (origB==0) { assert(area->ClusterDelay >= delay - FUZZ); }
area->ClusterDelay = tMAX(area->ClusterDelay, delay);
x = calc_x(area);
ans = sol_equation(K[H_], x, delay - area->ClusterDelay);
} else {
ans = 0;
}
return(ans);
}
/***********************************************************************/
/* Copyright (C) 1994-2000 by Andrew B. Kahng, C.-W. Albert Tsao */
/***********************************************************************/
void set_area_StubLen2(AreaType *area, double *d0, double *d1) {
double x,y,z,len0,len1, d, B0, B1;
double Lmax, Rmax;
Lmax = JS[0][0].max;
Rmax = JS[1][0].max;
calc_B0_B1(area, &B0, &B1);
d = area->dist;
x = B1*d + Rmax - Lmax + K[H_]*d*d;
y = B0 + B1 + 2*d*K[H_];
z = x/y;
if (z <0) {
len1 = sol_equation(K[H_], B1, Rmax - Lmax);
len0 = 0 ;
} else if (z > d) {
len0 = sol_equation(K[H_], B0, Lmax - Rmax);
len1 = 0;
} else {
len0 = z;
len1 = d - z ;
}
if (area->area_L->R_buffer > 0) {
area->L_StubLen = len0;
*d0 = 0;
} else {
area->L_StubLen = 0 ;
*d0 = len0;
}
if (area->area_R->R_buffer > 0) {
area->R_StubLen = len1;
*d1 = 0;
} else {
area->R_StubLen = 0 ;
*d1 = len1;
}
area->L_EdgeLen = len0;
area->R_EdgeLen = len1;
}
/***********************************************************************/
/* Copyright (C) 1994-2000 by Andrew B. Kahng, C.-W. Albert Tsao */
/***********************************************************************/
void calc_area_EdgeLen(AreaType *area, double *d0, double *d1) {
double cap0, cap1, tL, tR, diff;
double B0, B1, x;
cap0 = area->area_L->capac;
cap1 = area->area_R->capac;
calc_B0_B1(area, &B0, &B1);
x = area->L_StubLen;
tL = JS[0][0].max + K[H_]*x*x+B0*x;
x = area->R_StubLen;
tR = JS[1][0].max + K[H_]*x*x+B1*x;
diff = tMAX(0, area->dist - (area->L_StubLen+area->R_StubLen));
calc_merge_distance(PURES[H_], PUCAP[H_],cap0,tL, cap1,tR,diff,d0,d1);
/* just for check */
calc_merge_pt_delay_sub(area, *d0, *d1);
area->L_EdgeLen = *d0 + area->L_StubLen;
area->R_EdgeLen = *d1 + area->R_StubLen;
}
/****************************************************************************/
/* */
/****************************************************************************/
void set_ClusterDelay_CASE1(AreaType *area0, AreaType *area1, double L,
double delay) {
double r,c,A,B,C,x, t;
r = PURES[H_];
c = PUCAP[H_];
A = r*c;
B = area0->R_buffer*c+r*area0->unbuf_capac-r*c*L-r*C_buffer;
C = K[H_]*L*L+r*C_buffer*L+ delay - area1->ClusterDelay;
x = sol_equation(A,B,C);
if (x>= L) {
area0->ClusterDelay = area1->ClusterDelay;
} else {
t = delay + area0->R_buffer*c*x+ r*x*(c*x/2+area0->unbuf_capac);
assert( t >= area0->ClusterDelay - FUZZ);
area0->ClusterDelay = t;
}
}
/****************************************************************************/
/* area_L is unbuffered, area_R is buffered. */
/****************************************************************************/
void set_ClusterDelay_CASE2(AreaType *area_L,AreaType *area_R, double x,
double t0, double t1) {
double t, r, c;
assert(area_L->R_buffer == 0);
assert(area_R->R_buffer > 0);
r = PURES[H_];
c = PUCAP[H_];
t = t0 + r*x*(c*x/2+area_L->capac);
double origB = gBoundedSkewTree->Orig_Skew_B() ;
if (1 || origB == 0) assert(t<=area_R->ClusterDelay + FUZZ);
area_R->ClusterDelay = tMAX(t1, t);
assert(area_L->ClusterDelay == 0);
assert(area_L->capac == area_L->unbuf_capac);
assert(area_R->ClusterDelay > 0);
}
/**********************************************************************/
/* Copyright (C) 1994-2000 by Andrew B. Kahng, C.-W. Albert Tsao */
/**********************************************************************/
void print_current_time() {
long current_time;
time(¤t_time);
printf("\nCurrent Time: %s \n",ctime(¤t_time));
fflush(stdout);
}
/******************************************************************/
/* Copyright (C) 1994-2000 by Andrew B. Kahng, C.-W. Albert Tsao */
/******************************************************************/
void rm_same_JR_turn_pts(int side) {
unsigned n = n_JR[side];
unsigned j=1;
for (unsigned i=1;i<n;++i) {
PointType pt1 = JR[side][j-1];
PointType pt2 = JR[side][i];
if (!same_Point(pt1,pt2)) {
JR[side][j++] = pt2;
}
}
n_JR[side] = j;
}
/***********************************************************************/
/* Copyright (C) 1994-2000 by Andrew B. Kahng, C.-W. Albert Tsao */
/***********************************************************************/
void rm_same_pts_on_mr(AreaType *area) {
int i,j,n;
PointType pt, pre_pt;
n = area->n_mr;
for (i=1, j = 1;i<n;++i) { /* remove same turn points on mr */
pt = area->mr[i];
pre_pt = area->mr[j-1];
if (!same_Point(pt,pre_pt) ) {
area->mr[j++] = pt ;
}
}
if (j>1 && same_Point(area->mr[0],area->mr[j-1]) ) j--;
area->n_mr = j;
}
/**********************************************************************/
/* Copyright (C) 1994-2000 by Andrew B. Kahng, C.-W. Albert Tsao */
/**********************************************************************/
int rm_same_pts_on_sorted_array(PointType q[], int n) {
int i,j;
PointType pt, pre_pt;
for (i=1, j = 1;i<n;++i) { /* remove same turn points on mr */
pt = q[i];
pre_pt = q[j-1];
if (!same_Point(pt,pre_pt) ) {
q[j++] = pt ;
}
}
/*
*/
if (j>1 && same_Point(q[0],q[j-1]) ) j--;
return(j);
}
/****************************************************************************/
/* */
/****************************************************************************/
static int point_compare_dec(const void *p, const void *q) {
PointType *pp, *qq;
/*
if (p->t < q->t) {
return(1);
} else if (p->t > q->t ) {
return(-1);
} else {
return(0);
}
*/
pp = (PointType *) p;
qq = (PointType *) q;
return( (pp->t < qq->t) ? YES: NO);
}
/******************************************************************/
/* */
/******************************************************************/
void check_JR_turn_pts_coor(AreaType *area, int side) {
int i,n, type;
PointType p,p0,p1,q0,q1;
n = n_JR[side];
assert(n>=2);
p0 = JR[side][0];
p1 = JR[side][n-1];
q0 = area->line[side][0];
q1 = area->line[side][1];
assert(same_Point(p0,q0) && same_Point(p1,q1));
type = areaJS_line_type(area);
for (i=1;i<n;++i) {
p = JR[side][i];
if (type == VERTICAL ) {
assert(equal(p.x, p0.x));
JR[side][i].x = p0.x;
} else if (type == HORIZONTAL ) {
assert(equal(p.y, p0.y));
JR[side][i].y = p0.y;
} else if (type == TILT || type == FLAT) {
assert(i==n-1 || pt_on_line_segment(p,p0,p1));
} else {
assert(0);
}
}
}
/******************************************************************/
/* initialize JR[side][i] with turning pt child->mr[j] */
/* for the case when area->line{0] and area->line{1] are */
/* parallel hori./vert. lines */
/******************************************************************/
void add_JS_pts(AreaType *area,int side, AreaType *child) {
int i, n;
assert(!same_Point(JS[side][0],JS[side][1]));
n=2;
for (i=0;i<child->n_mr;++i) {
if ( pt_on_line_segment(child->mr[i],JS[side][0],JS[side][1])
&& !same_Point(child->mr[i],JS[side][0])
&& !same_Point(child->mr[i],JS[side][1]) ) {
JS[side][n] = child->mr[i];
n++;
}
}
n_JS[side] = n;
assert( n <= MAX_TURN_PTS);
sort_pts_on_line(JS[side], n_JS[side]);
}
/******************************************************************/
/* check if pt = any point in q[] */
/******************************************************************/
int repeated_pts(PointType q[], int n, PointType pt) {
int i;
for (i=0;i<n;++i) {
if (same_Point(pt,q[i])) {
return(i);
}
}
return(NIL);
}
/***********************************************************************/
/* */
/***********************************************************************/
void add_LINEAR_turn_point_sub(int side,double d0,double d1,
PointType p0,PointType p1) {
int n;
double d;
PointType pt, q;
if (d0<=0 || d1<=0 ) return;
d = d0+d1;
n = n_JR[side];
pt.x = (p0.x*d1 + p1.x*d0)/d;
pt.y = (p0.y*d1 + p1.y*d0)/d;
if (n==3) {
q = JR[side][2];
if (same_Point(pt,q)) {
return;
}
}
pt.max = tMAX(p0.max - d0, p1.max-d1);
pt.min = tMIN(p0.min + d0, p1.min+d1);
JR[side][n] = pt;
n_JR[side] = n+1;
}
/***********************************************************************/
/* */
/***********************************************************************/
void add_LINEAR_turn_point(AreaType *area) {
int side;
PointType p0,p1;
double d,t ;
for (side=0;side < 2; ++side) {
p0 = JR[side][0];
p1 = JR[side][1];
d = Point_dist(p0,p1);
t = p0.max-p1.max;
add_LINEAR_turn_point_sub(side,(d+t)/2, (d-t)/2,p0,p1);
t = p0.min-p1.min;
add_LINEAR_turn_point_sub(side,(d-t)/2, (d+t)/2,p0,p1);
sort_pts_on_line(JR[side], n_JR[side]);
/*
rm_same_JR_turn_pts(side);
*/
n_JR[side] = rm_same_pts_on_sorted_array( JR[side], n_JR[side]);
if (CHECK==1) {
check_JR_turn_pts_coor(area, side);
}
}
}
/******************************************************************/
/* */
/******************************************************************/
double delay_pt_JS(int JS_side, int x, int side, int i, double t_from[]) {
double ans;
if (i==0) { /* max-delay */
ans = JS[side][x].max;
} else { /* min_delay */
ans = JS[side][x].min;
}
if (JS_side != side) {
ans += t_from[side];
}
return(ans);
}
/***********************************************************************/
/* */
/***********************************************************************/
double calc_A(PointType *p0, PointType *p1) {
double A;
if (equal(p0->x, p1->x)) { /* JS is vertical */
assert( !equal(p0->y, p1->y) );
A = K[V_];
} else { /* JS is horizontal */
assert( equal(p0->y, p1->y) );
A = K[H_];
}
return(A);
}
/***********************************************************************/
/* add one turn point on JR due to the changing slopes of max- or min- */
/* delay (depending on the value of y) between JR[side][x] and */
/* JR[side][x+1] */
/***********************************************************************/
void add_turn_point(int side,int x,int y, double t_from[]) {
PointType pt1, pt2, new_pt;
int i,j;
double d,d1,d2, B[2][2], t2,t1, tmp[2][2];
double A;
pt1 = JR[side][x];
pt2 = JR[side][x+1];
A = calc_A(&pt1, &pt2);
d = Point_dist(JR[side][x],JR[side][x+1]);
assert(!equal(d,0));
for (i=0;i<2;++i) {
for (j=0;j<2;++j) {
t1 = delay_pt_JS(side,x, i,j, t_from);
t2 = delay_pt_JS(side,x+1,i,j, t_from);
B[i][j] = (t2-t1)/d-A*d;
}
}
d1 = (delay_pt_JS(side,x,0,y, t_from) - delay_pt_JS(side,x,1,y, t_from) )
/(B[1][y]-B[0][y]);
assert(d1 > 0 && d1 < d);
d2 = d - d1;
/* calc coordinate of new_pt */
new_pt = pt2;
new_pt.x = (pt1.x*d2 + pt2.x*d1)/d;
new_pt.y = (pt1.y*d2 + pt2.y*d1)/d;
/* calc delays of new_pt */
for (i=0;i<2;++i) {
for (j=0;j<2;++j) {
tmp[i][j] = delay_pt_JS(side,x, i,j, t_from) + A*d1*d1+B[i][j]*d1;
}
}
new_pt.max = tMAX(tmp[0][0],tmp[1][0]);
new_pt.min = tMIN(tmp[0][1],tmp[1][1]);
assert(equal(tmp[0][y],tmp[1][y]));
JR[side][(n_JR[side])++] = new_pt;
assert(n_JR[side] <= MAX_TURN_PTS);
}
/******************************************************************/
/* add turn points on JR[side] due to changing slopes of delays */
/******************************************************************/
void add_more_JR_pts(AreaType *area, int side, double t_from[]) {
int i, n;
double t;
n = n_JR[side];
for (i=0;i<n-1;++i) { /* for each point */
t = (JS[side][i].max - JS[1-side][i].max - t_from[1-side])*
(JS[side][i+1].max - JS[1-side][i+1].max - t_from[1-side]);
if ( t < - FUZZ ) {
add_turn_point(side,i,0, t_from);
}
t = (JS[side][i].min - JS[1-side][i].min - t_from[1-side])*
(JS[side][i+1].min - JS[1-side][i+1].min - t_from[1-side]);
if ( t < - FUZZ ) {
add_turn_point(side,i,1, t_from);
}
}
sort_pts_on_line(JR[side], n_JR[side]);
/*
rm_same_JR_turn_pts(side);
*/
n_JR[side] = rm_same_pts_on_sorted_array( JR[side], n_JR[side]);
if (CHECK==1) {
check_JR_turn_pts_coor(area, side);
}
}
/******************************************************************/
/* */
/******************************************************************/
void print_JR_slopes(int n, double *skew_rate,
double *maxD_slope, double *minD_slope) {
printf("maxD_slope: ");
print_double_array(maxD_slope, n-1);
printf("minD_slope: ");
print_double_array(minD_slope, n-1);
printf("skew_rate: ");
print_double_array(skew_rate, n-1);
assert(0);
}
/******************************************************************/
/* check turn_pts on JR[side] */
/******************************************************************/
void check_Elmore_delay_skew(PointType q[], int n, double delta) {
int i;
double d1,d2, t, t1,t2, skew_rate[MAX_TURN_PTS-1];
double maxD_slope[MAX_TURN_PTS-1], minD_slope[MAX_TURN_PTS-1];
double A;
PointType p0,p1,p2;
assert(n>=2);
p0 = q[0];
A = calc_A(&(q[0]), &(q[1]));
for (i=0;i<n-1;++i) {
p1 = q[i];
p2 = q[i+1];
d1 = Point_dist(p1,p0);
d2 = Point_dist(p2,p0);
t1 = d2 - d1;
t2 = d2 + d1;
assert(t1 > FUZZ);
skew_rate[i] = (pt_skew(p2) - pt_skew(p1) ) / t1;
maxD_slope[i] = (p2.max-p1.max)/t1 -A*t2;
minD_slope[i] = (p2.min-p1.min)/t1 -A*t2;
}
/* slopes of max-delays must be monotone increasing */
for (i=0;i<n-2;++i) {
t1 = maxD_slope[i];
t2 = maxD_slope[i+1];
if ( t1 > t2+100.0*FUZZ) {
print_JR_slopes(n, skew_rate, maxD_slope, minD_slope);
}
}
/* slopes of min-delays must be monotone decreasing */
for (i=0;i<n-2;++i) {
t1 = minD_slope[i];
t2 = minD_slope[i+1];
if ( t1 < t2-100.0*FUZZ) {
print_JR_slopes(n, skew_rate, maxD_slope, minD_slope);
}
}
/* slopes of skew must be strictly monotone increasing */
for (i=0;i<n-2;++i) {
t = skew_rate[i+1] - skew_rate[i];
if ( t < -100.0*delta ) {
print_JR_slopes(n, skew_rate, maxD_slope, minD_slope);
}
}
}
/***********************************************************************/
/* */
/***********************************************************************/
void set_pt_coord_case2(int side_loc, PointType *pt, double d) {
if (side_loc==LEFT) {
pt->x += d;
} else if (side_loc==RIGHT) {
pt->x -= d;
} else if (side_loc==BOTTOM) {
pt->y += d;
} else {
pt->y -= d;
}
}
/******************************************************************/
/* */
/******************************************************************/
void calc_JS_pt_delays(int side, PointType *pt) {
int i;
for (i=0;i<n_JS[side] -1 ;++i) {
if ( pt_on_line_segment(*pt,JS[side][i], JS[side][i+1]) ) {
break;
}
}
assert( i < n_JS[side] -1 );
calc_pt_delays(NULL, pt, JS[side][i], JS[side][i+1]);
}
/******************************************************************/
/* Copyright (C) 1994-2000 by Andrew B. Kahng, C.-W. Albert Tsao */
/* add turn points on JS[o_side] to JR[side] */
/******************************************************************/
void add_more_JS_pts(int side, double dist, int n) {
int i, j, k, o_side;
o_side = 1- side;
k = n_JS[side];
for (i=0;i<n ;++i) {
JS[side][k] = JS[o_side][i];
j = calc_side_loc(o_side);
set_pt_coord_case2(j, &(JS[side][k]),dist);
j = repeated_pts(JS[side], n_JS[side], JS[side][k]);
if (j <0) {
assert( k < MAX_TURN_PTS);
calc_JS_pt_delays(side, &(JS[side][k]));
k++;
}
}
n_JS[side] = k;
}
/******************************************************************/
/* */
/******************************************************************/
void calc_new_delay(AreaType *area, int side, PointType *pt) {
double tL, tR;
tL = pt_delay_increase(Gamma, area->area_L->capac,&(area->line[0][side]), pt);
tR = pt_delay_increase(Gamma, area->area_R->capac,&(area->line[1][side]), pt);
pt->max = tMAX(area->line[0][side].max + tL, area->line[1][side].max + tR);
pt->min = tMIN(area->line[0][side].min + tL, area->line[1][side].min + tR);
}
/******************************************************************/
/* find the corner points of Joining Box. */
/******************************************************************/
void calc_JR_corner_sub2(int i, double x0,double y0,double x1,double y1) {
if ( (x0-x1)*(y0-y1) < 0 ) {
if (i==0) {
JR_corner[i].x = tMAX(x0,x1);
JR_corner[i].y = tMAX(y0,y1);
} else {
JR_corner[i].x = tMIN(x0,x1);
JR_corner[i].y = tMIN(y0,y1);
}
} else {
if (i==0) {
JR_corner[i].x = tMIN(x0,x1);
JR_corner[i].y = tMAX(y0,y1);
} else {
JR_corner[i].x = tMAX(x0,x1);
JR_corner[i].y = tMIN(y0,y1);
}
}