-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRdCkt.cpp
More file actions
1478 lines (1416 loc) · 37.9 KB
/
Copy pathRdCkt.cpp
File metadata and controls
1478 lines (1416 loc) · 37.9 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
995
996
997
998
999
1000
#include <iostream> // basic C++ input/output (e.g., cin, //cout)
#include <fstream> // needed to open files in C++
#include <sstream> // needed if you are using sstream (C++)
#include <stdio.h> // needed to open files in C
#include <cstring>
#include <vector>
#include <cstdlib>
#include <map>
#include <algorithm>
#include <list>
#include "ReadLib.h"
#include "ReadLibFunc.h"
#include <chrono>
#include <deque>
using namespace std::chrono;
#define MAX_FAN 8
std::ofstream outfile("ckt_traversal.txt"); //Output text file
void find_outputnodes();
void find_fanouts();
//***********To compile the program please use the command mentioned in the next line
//g++ -std=c++11 <Filename>.cpp
using namespace std;
//std::ofstream outfile("ghosh211.txt"); //Output text file store the names of the GATE type
//int num_celltype=0;
class Graph; //Number of gates counter
map<string, Graph> circuit;
class Graph{
string GID;
string type;
int ready;
int rev_ready;
double arrival_time;
double output_slew;
double req_arrival_time;
double node_delay;
double slack;
list <string> inputs;
vector<string> fanin;
vector<string> fanout;
vector<double> Fi_Delays;
public:
Graph(string ID, string t, vector<string> inp, int r, double at, double os, double node_delays)
{
GID=ID;
transform(t.begin(), t.end(), t.begin(), ::toupper);
type=t;
////cout<<GID;
////cout<<t<<"\n";
vector<string>::iterator p;
for(p=inp.begin();p!=inp.end();p++)
{
inputs.push_back(*p);
}
fanin=inp;
ready=r;
arrival_time=at;
output_slew=os;
node_delay=node_delays;
//outfile << GID << ' ' << ready << ' ' << type << '\n';
//if (GID == "2259") {
// int x = 1;
//}
}
void writeFiDelay(vector<double> v)
{
Fi_Delays=v;
}
vector<double> getFiDelays()
{
return Fi_Delays;
}
double getCustomNodeDelay(int i)
{
//outfile<<"\n";
//for(auto t=Fi_Delays.begin();t!=Fi_Delays.end();t++)
// outfile<<" "<<*t;
return Fi_Delays[i];
}
string giveGID()
{
return GID;
}
void writeSlack(double s)
{
slack=s;
}
void printGATE()
{
outfile<<type;
}
void displaySlack()
{
////cout<<slack;
outfile<<slack;
}
void displaySlackps()
{
////cout<<slack;
outfile<<slack*1000;
}
double getSlack()
{
return slack;
}
void writeNodeDelay(double d)
{
node_delay=d;
}
void displayNodeDelay()
{
////cout<<node_delay;
outfile<<node_delay;
}
double getNodeDelay()
{
return node_delay;
}
void writeReady(int i)
{
ready=i;
}
void writeRevReady(int i)
{
rev_ready=i;
}
int getRevReady()
{
return rev_ready;
}
void RemoveFanouts()
{
if (fanout.size()!=0)
fanout.clear();
}
int checkReady()
{
int t=0;
map<string,Graph>::iterator m=circuit.begin();
for(vector<string>::iterator p=fanin.begin();p!=fanin.end();p++)
{
m=circuit.find(*p);
t=m->second.getReady();
if(t==0)
break;
}
return t;
}
int checkRevReady()
{
int t=0;
map<string,Graph>::iterator m=circuit.begin();
for(vector<string>::iterator p=fanout.begin();p!=fanout.end();p++)
{
m=circuit.find(*p);
t=m->second.getRevReady();
if(t==0)
break;
}
return t;
}
void displayReady()
{
////cout<<ready;
outfile<<ready;
}
void displayRevReady()
{
////cout<<rev_ready;
outfile<<rev_ready;
}
void write_req_arrival_time(double t)
{
req_arrival_time=t;
}
double give_req_arrival_time()
{
return req_arrival_time;
}
void display_req_arrival_time()
{
////cout<<req_arrival_time;
outfile<<req_arrival_time*1000;
}
void displayID()
{
////cout<<GID;
outfile<<GID;
}
string displayGATE()
{
////cout<<" "<<type;
return type;
}
void displayINPUTS()
{
list<string>::iterator x;
for(x=inputs.begin();x!=inputs.end();x++)
{
// //cout<<*x<<"\t";
}
////cout<<"\n";
////cout<<inputs.front()<<" ";
////cout<<inputs.back()<<" ";
}
void displayFANINS()
{
vector<string>::iterator i;
if(i!=fanin.end())
{
//for(i=fanin.begin();i!=fanin.end();i++)
//cout<<*i<<"\t";
}
else;
//cout<<"\nNO FANINS____PRIMARY INPUT NODE";
}
std::vector<string> getFanin()
{
return fanin;
}
void updateFanout(string s)
{
fanout.push_back(s);
}
void writeFanout(vector<string> d)
{
fanout=d;
}
std::vector<string> getFanout()
{
return fanout;
}
void displayFANOUTS()
{
vector<string>::iterator i;
//if(i!=fanout.end())
//{
// for(i=fanout.begin();i!=fanout.end();i++)
// //cout<<*i<<"\t";
//}
//else
// //cout<<"\nNO FANOUTS____PRIMARY OUTPUT NODE";
}
int getReady()
{
return ready;
}
double getArrivalTime()
{
return arrival_time;
}
double getOutputSlew()
{
return output_slew;
}
void writeArrivaltime(double A)
{
arrival_time=A;
}
void writeOutputSlewtime(double T)
{
output_slew=T;
}
void displayArrivaltime()
{
////cout<<arrival_time;
outfile<<arrival_time*1000;
}
void displayOutputSlew()
{
////cout<<output_slew;
outfile<<output_slew*1000;
}
};
vector<string> inputsonly;
vector<string> outputsonly;
void remove_duplicates(vector <string> V)
{
auto end = V.end();
for (auto it = V.begin(); it != end; ++it)
{
end = std::remove(it + 1, end, *it);
}
V.erase(end, V.end());
}
void update_ready()
{
map<string, Graph>::iterator c=circuit.begin();
map<string, Graph>::iterator d=circuit.begin();
for(c=circuit.begin();c!=circuit.end();c++)
{
vector<string> fi=c->second.getFanin();
vector<string>::iterator k=fi.begin();
int r=0;
for(k=fi.begin();k!=fi.end();k++)
{
d=circuit.find(*k);
r=d->second.getReady();
if(r==0)
break;
}
if(r==1)
{
c->second.writeReady(r);
//outfile << "updating ready : " << c->second.displayGATE() << ' ' << c->second.giveGID() <<'\n';
r=0;
}
else
c->second.writeRevReady(r);
}
//cout<<"\nALL READY UPDATED";
}
void update_rev_ready()
{
map<string, Graph>::iterator c=circuit.begin();
map<string, Graph>::iterator d=circuit.begin();
for(c=circuit.begin();c!=circuit.end();c++)
{
vector<string> fi=c->second.getFanout();
vector<string>::iterator k=fi.begin();
int r=0;
if(k!=fi.end())
{
for(k=fi.begin();k!=fi.end();k++)
{
d=circuit.find(*k);
r=d->second.getRevReady();
if(r==0)
break;
}
if(r==1)
{
c->second.writeRevReady(r);
}
else
c->second.writeRevReady(r);
}
}
}
///////////////////////////////////////////CIRCUIT PARSE/////////////////////////////////////////////////////
void ckt_parse(string file_name)
{
////cout<<"\nPARSING CIRCUIT FILE INTO FUNCTION";
std::string line; //This is the string type LINE that will store the line by line read data from file
std::ifstream infile(file_name);
if(!infile) //To check for successful opening of file
{
////cout<<"Could not open File : "<<file_name;
exit(1);
}
int num_celltype=0;
int num_celltypei=0;
std::string read="*=*(*)"; //The wildcard string that we have to search for
vector<string> inputv; //vector to store the values of delay table one by one
string ID;
std::string gatename;
while (infile.good())
{
////cout<<"\nworking";
getline(infile,line); // Takes one line at a time
////cout<<"\n"<<line;
line.erase(std::remove_if(line.begin(), line.end(), ::isspace), line.end()); //Removes empty spaces from line read from file
////cout<<"\n"<<line;
std::string readinp="INPUT(";
std::string readop="OUTPUT(";
if (line.find(readinp,0)!=string::npos) //Check the gate type by searching for the keyword CELL
{
num_celltypei++; //Updates the no. of Gate types
char ch4='('; //Character "("
int f1=line.find_first_of(ch4); //Find the first occurence of (
////cout<<f;
char ch5=')'; //Character ")"
int k1=line.find_first_of(ch5); //Find the last occurence of )
string t=line.substr(f1+1,k1-f1-1);
inputsonly.push_back(t);
vector <string> temp;
temp.clear();
circuit.insert(pair<string, Graph> (t,Graph(t,"INPUT",temp,1,0,0.002,0))); //For input nodes only
}
if (line.find(readop,0)!=string::npos) //Check the gate type by searching for the keyword CELL
{
//num_celltypeo++; //Updates the no. of Gate types
char ch4='('; //Character "("
int f1=line.find_first_of(ch4); //Find the first occurence of (
////cout<<f;
char ch5=')'; //Character ")"
int k1=line.find_first_of(ch5); //Find the last occurence of )
string t=line.substr(f1+1,k1-f1-1);
outputsonly.push_back(t);
//vector <string> temp;
//temp.clear();
//circuit.insert(pair<string, Graph> (t,Graph(t,"INPUT",temp,1,0,2,0))); //For input nodes only
}
if (line.find(read,0)!=string::npos) //Check the gate type by searching for the keyword CELL
{
num_celltype++; //Updates the no. of Gate types
}
char ch1='='; //Character "("
int f=line.find_first_of(ch1); //Find the first occurence of (
////cout<<f;
char ch2='('; //Character ")"
int k=line.find_first_of(ch2); //Find the last occurence of )
char ch3=')';
int g=line.find_last_of(ch3);
string temp_string;
if (((f>=0)&&(k>=0)&&(g>=0))&&(f<k)&&(k<g)&&(f<g)) //Get into the loop
{
////cout<<"\n"<<line;
////cout<<"I AM IN";
f=line.find_first_of(ch1); //Find the first occurence of (
////cout<<f;
string ID=line.substr(0,f);
////cout<<ID;
k=line.find_first_of(ch2); //Find the last occurence of )
////cout<<k;
gatename=line.substr(f+1,k-f-1);//Find the characters in between = & ) and stores it in the name array
transform(gatename.begin(), gatename.end(), gatename.begin(), ::toupper);
////cout<<gatename;
//ch3=')';
g=line.find_last_of(ch3);
string input_line=line.substr(k+1,g-k-1); //Find the characters in between ( & ) and stores it in the Array
////cout<<input_line;
std::stringstream ss1(input_line); //Creates string stream from the string
while (ss1.good())
{
string sub1;
getline(ss1,sub1,','); //get first string delimited by comma
////cout<<sub1<<"\t";
temp_string=sub1;
inputv.push_back(sub1); //push the sub string into the vector from back
}
////cout<<"\n";
//vector<string>::iterator it;
//for(it=inputv.begin();it!=inputv.end();it++)
//{
////cout<<*it<<"\n";
//}
//DFF CHECKING
if(gatename=="DFF" || gatename=="dff")
{
////cout<<"\nFOUND ONE DFF";
vector <string> temp;
temp.clear();
circuit.insert(pair<string, Graph> (ID,Graph(ID,"DFF",temp,1,0,0.002,0))); //For input nodes only
inputsonly.push_back(ID);
//cout<<"\t"<<temp_string;
outputsonly.push_back(temp_string);
}
else
{
circuit.insert(pair<string, Graph> (ID,Graph(ID,gatename,inputv,0,0,0,0)));
}
inputv.clear();
}
}
//cout<<"\nFINDING FANOUTS";
find_fanouts();
//cout<<"\nFINDING FANOUTS COMPLETED";
//cout<<"\nDONE CIRCUIT PARSE";
}
///////////////////FINDING FANOUTS OF ALL NODES///////////////////////////////////////////
void find_fanouts()
{
map<string,Graph>::iterator itr=circuit.begin();
map<string,Graph>::iterator temp=circuit.begin();
for(itr=circuit.begin();itr!=circuit.end();itr++)
{
std::vector<string> fani;
fani=itr->second.getFanin();
for(std::vector<string>::iterator m=fani.begin();m!=fani.end();m++)
{
if(m!=fani.end())
{
////cout<<*m;
temp=circuit.find(*m);
string z=itr->first;
temp->second.updateFanout(z);
}
}
}
//cout<<"\nALL FANOUTS COLLECTED";
}
/////////////////////////////////CALCULATE DI FROM NLDM LUT//////////////////////////////
vector<double> get_di(string typ,vector<double> inp_slew,double cap,double s)
{
////cout<<"\nARRIVAL TIMES OF INPUTS OF GATE "<<typ;
map<string,ReadLib>::iterator h=lib.find(typ);
vector<double> delay;
//h->second.display_index_1();
//h->second.display_index_2();
vector<double> index1_array=h->second.giveIndex1();
vector<double> index2_array=h->second.giveIndex2();
//for(vector<double>::iterator i=index1_array.begin();i!=index1_array.end();i++)
//{
// //cout<<"\t"<<*i;
//}
int row=0;
int ind1_found=0;
int col=0;
int ind2_found=0;
double T1,T2,C1,C2;
int r1=0,r2=0,c1=0,c2=0;
double temp_delay;
////cout<<"\nOUTPUT CAP "<<cap;
////cout<<"\nINPUT SLEW OF FANINS ";
for(vector<double>::iterator g=inp_slew.begin();g!=inp_slew.end();g++) //Traversing though all the input pins
{
////cout<<*g;
for(int i=0;i<NLDM_size;i++) //Checking all index_1 values
{
row=i;
if(index1_array[i]==*g)
{
ind1_found=1; //Exact match of Input slew found
break;
}
}
for(int j=0;j<NLDM_size;j++) //Checking all index_2 values
{
col=j;
if(index2_array[j]==cap)
{
ind2_found=1; //Exact match of load capciatance found
break;
}
}
if(ind1_found==1 && ind2_found==1) //If both indices exact match found
{
temp_delay=h->second.give_custom_delay(row,col);
}
if(ind1_found==0) //If exact Ti is not found in LUT
{
int counter=0;
if(*g>index1_array.back())
{
r1=NLDM_size-2;
r2=r1+1;
}
else{
while(*g>index1_array[counter])
{
r1=counter;
r2=r1+1;
counter++;
}
}
}
if(ind2_found==0) //If exact Cl is not found in LUT
{
int counter=0;
if(cap>index2_array.back())
{
c1=NLDM_size-2;
c2=c1+1;
}
else{
while(cap>index2_array[counter])
{
c1=counter;
c2=c1+1;
counter++;
}
}
}
if(ind1_found==0 && ind2_found==0)// 2D Interpolation in case of Ti and Cl mismatch in LUT
{
T1=index1_array[r1];
T2=index1_array[r2];
C1=index2_array[c1];
C2=index2_array[c2];
//outfile<<"\nT1="<<T1;
//outfile<<"\nT2="<<T2;
//outfile<<"\nC1="<<C1;
//outfile<<"\nC2="<<C2;
double v11=h->second.give_custom_delay(r1,c1);
//outfile<<"\nV11="<<v11;
double v12=h->second.give_custom_delay(r1,c1+1);
//outfile<<"\nV12="<<v12;
double v21=h->second.give_custom_delay(r1+1,c1);
//outfile<<"\nV21="<<v21;
double v22=h->second.give_custom_delay(r1+1,c1+1);
//outfile<<"\nV22="<<v22;
temp_delay=((v11*(C2-cap)*(T2-*g))+(v12*(cap-C1)*(T2-*g))+(v21*(C2-cap)*(*g-T1))+(v22*(cap-C1)*(*g-T1)))/((C2-C1)*(T2-T1));
//outfile<<"\nTEMP DELAY:"<<temp_delay;
}
if(s>2)
{
temp_delay=temp_delay*(s/2);
}
//outfile<<"\n2D Interpolation V="<<temp_delay;
delay.push_back(temp_delay); //Delay from LUT is added to vector;
ind1_found=0;
ind2_found=0;
row=0;
col=0;
r1=0;r2=0;c1=0;c2=0;
}
return delay;
}
///////////////////////////////CALCULATE FINAL TOUT////////////////////////////////////
double find_Tout(string typ,double tdi,double cap,double size)
{
outfile<<"\nCALCULATING FINAL TOUT OF "<<typ<<" Corresponding to C "<<cap<<" and Slew "<<tdi;
map<string,ReadLib>::iterator h=lib.find(typ);
vector<double> index1_array=h->second.giveIndex1();
vector<double> index2_array=h->second.giveIndex2();
// //cout<<"\nIn_slew\t"<<tdi<<"\tCapacitance"<<cap;
int row=0;
int ind1_found=0;
int col=0;
int ind2_found=0;
double T1,T2,C1,C2;
int r1=0,r2=0,c1=0,c2=0;
double temp_Tout;
for(int i=0;i<NLDM_size;i++) //Checking all index_1 values
{
row=i;
if(index1_array[i]==tdi)
{
ind1_found=1; //Exact match of Input slew found
break;
}
}
for(int j=0;j<NLDM_size;j++) //Checking all index_2 values
{
col=j;
if(index2_array[j]==cap)
{
ind2_found=1; //Exact match of load capciatance found
break;
}
}
if(ind1_found==1 && ind2_found==1) //If both indices exact match found
{
temp_Tout=h->second.give_custom_slew(row,col);
}
if(ind1_found==0) //If exact Ti is not found in LUT
{
int counter=0;
if(tdi>index1_array.back())
{
r1=NLDM_size-2;
r2=r1+1;
}
else
{
while(tdi>index1_array[counter])
{
r1=counter;
r2=r1+1;
counter++;
}
}
}
if(ind2_found==0) //If exact Cl is not found in LUT
{
int counter=0;
if(cap>index2_array.back())
{
c1=NLDM_size-2;
c2=c1+1;
}
else
{
while(cap>index2_array[counter])
{
c1=counter;
c2=c1+1;
counter++;
}
}
}
if(ind1_found==0 && ind2_found==0) // 2D Interpolation in case of Ti and Cl mismatch in LUT
{
T1=index1_array[r1];
T2=index1_array[r2];
C1=index2_array[c1];
C2=index2_array[c2];
// //cout<<"\nT1="<<T1;
// //cout<<"\nT2="<<T2;
// //cout<<"\nC1="<<C1;
// //cout<<"\nC2="<<C2;
double v11=h->second.give_custom_slew(r1,c1);
//outfile<<"\nV11="<<v11;
double v12=h->second.give_custom_slew(r1,c1+1);
//outfile<<"\nV12="<<v12;
double v21=h->second.give_custom_slew(r1+1,c1);
//outfile<<"\nV21="<<v21;
double v22=h->second.give_custom_slew(r1+1,c1+1);
//outfile<<"\nV22="<<v22;
temp_Tout=((v11*(C2-cap)*(T2-tdi))+(v12*(cap-C1)*(T2-tdi))+(v21*(C2-cap)*(tdi-T1))+(v22*(cap-C1)*(tdi-T1)))/((C2-C1)*(T2-T1));
//outfile<<"\n2D Interpolation V="<<temp_Tout;
}
ind1_found=0;
ind2_found=0;
if(size>2)
{
temp_Tout=temp_Tout*(size/2);
}
row=0;
col=0;
r1=0;r2=0;c1=0;c2=0;
return temp_Tout;
}
////////////////////////////////CALCULATE T_INS FROM NLDM LUT/////////////////////////////
vector <double> get_Tout(string typ,vector<double> inp_slew,double cap,double s)
{
// //cout<<"\nCALCULATION T_INS OF "<<typ;
map<string,ReadLib>::iterator h=lib.find(typ);
vector<double> toutslew;
vector<double> index1_array=h->second.giveIndex1();
vector<double> index2_array=h->second.giveIndex2();
int row=0;
int ind1_found=0;
int col=0;
int ind2_found=0;
double T1,T2,C1,C2;
int r1=0,r2=0,c1=0,c2=0;
double temp_Tout;
// //cout<<"\nOUTPUT CAP "<<cap;
// //cout<<"\nINPUT SLEW OF FANINS ";
for(vector<double>::iterator g=inp_slew.begin();g!=inp_slew.end();g++) //Traversing though all the input pins
{
// //cout<<"n"<<*g;
for(int i=0;i<NLDM_size;i++) //Checking all index_1 values
{
row=i;
if(index1_array[i]==*g)
{
ind1_found=1; //Exact match of Input slew found
break;
}
}
for(int j=0;j<NLDM_size;j++) //Checking all index_2 values
{
col=j;
if(index2_array[j]==cap)
{
ind2_found=1; //Exact match of load capciatance found
break;
}
}
if(ind1_found==1 && ind2_found==1) //If both indices exact match found
{
temp_Tout=h->second.give_custom_slew(row,col);
}
if(ind1_found==0) //If exact Ti is not found in LUT
{
int counter=0;
if(*g>index1_array.back())
{
r1=NLDM_size-2;
r2=r1+1;
}
else{
while(*g>index1_array[counter])
{
r1=counter;
r2=r1+1;
counter++;
}
}
}
if(ind2_found==0) //If exact Cl is not found in LUT
{
int counter=0;
if(cap>index2_array.back())
{
c1=NLDM_size-2;
c2=c1+1;
}
else{
while(cap>index2_array[counter])
{
c1=counter;
c2=c1+1;
counter++;
}
}
}
if(ind1_found==0 && ind2_found==0)// 2D Interpolation in case of Ti and Cl mismatch in LUT
{
T1=index1_array[r1];
T2=index1_array[r2];
C1=index2_array[c1];
C2=index2_array[c2];
//outfile<<"\nT1="<<T1;
///outfile<<"\nT2="<<T2;
//outfile<<"\nC1="<<C1;
//outfile<<"\nC2="<<C2;
double v11=h->second.give_custom_slew(r1,c1);
//outfile<<"\nV11"<<v11;
double v12=h->second.give_custom_slew(r1,c1+1);
//outfile<<"\nV12"<<v12;
double v21=h->second.give_custom_slew(r1+1,c1);
//outfile<<"\nV21"<<v21;
double v22=h->second.give_custom_slew(r1+1,c1+1);
//outfile<<"\nV22"<<v22;
temp_Tout=((v11*(C2-cap)*(T2-*g))+(v12*(cap-C1)*(T2-*g))+(v21*(C2-cap)*(*g-T1))+(v22*(cap-C1)*(*g-T1)))/((C2-C1)*(T2-T1));
//outfile<<"\n2D Interpolation V="<<temp_Tout;
}
if(s>2)
{
temp_Tout=temp_Tout*(s/2);
}
toutslew.push_back(temp_Tout); //Output slew from LUT is added to vector;
}
ind1_found=0;
ind2_found=0;
row=0;
col=0;
r1=0;r2=0;c1=0;c2=0;
return toutslew;
}
////////////////////////////////CALCULATE ARRIVAL TIME///////////////////////////
void calculate_arrival_time(string s)
{
//outfile<<"\nCALCULATING ARRIVAL TIME OF NODE "<<s;
map<string,Graph>::iterator m=circuit.begin();
m=circuit.find(s);
string ty=m->second.displayGATE();
transform(ty.begin(), ty.end(), ty.begin(), ::toupper);
vector<string> J=m->second.getFanin();
vector<string> K=m->second.getFanout();
vector<double> Ti;
double load_cap=0;
vector<double> At;
vector<double> Tdi;
//Gathering all Arrival times of Fanins
for(vector<string>::iterator u=J.begin();u!=J.end();u++)
{
m=circuit.find(*u);
double Atime=m->second.getArrivalTime();
At.push_back(Atime);
////cout<<"\nALL ARRIVAL TIMES OF FANINS GATHERED";
}
//Gathering all Output slew of Fanins
for(vector<string>::iterator t=J.begin();t!=J.end();t++)
{
m=circuit.find(*t);
double Slew=m->second.getOutputSlew();
Ti.push_back(Slew);
//if(s =="202")
//outfile<<"\nOutput slew of Fanins of node "<<s<<" are: "<<Slew;
//outfile<<"\nAT of Fanins of node "<<m->second.getArrivalTime();
}
//Gathering all Input capacitances of Fanouts
vector<string>::iterator c=K.begin();
vector<string>::iterator ccc = std::find (outputsonly.begin(), outputsonly.end(), s);
if(c!=K.end() && ccc!=outputsonly.end()) //When node is primary output node and also feeding some other gate
{
////cout<<"\nI AM HERE";
for(c=K.begin();c!=K.end();c++)
{
////cout<<"\nALL INPUT CAPACITANCES GATHERED";
map<string,Graph>::iterator g=circuit.begin();
g=circuit.find(*c);
string t=g->second.displayGATE();
transform(t.begin(), t.end(), t.begin(), ::toupper);
map<string, ReadLib>::iterator n =lib.find(t);
string cl=n->second.give_capa();
double cll=std::stod(cl);
//if(s =="202")
//outfile<<"\nCapacitance of node "<<s<<" are: "<<cll;
load_cap=load_cap+cll; //Final Load capacitance of node under test
}
map<string, ReadLib>::iterator n =lib.find("INV");
string cl=n->second.give_capa();
double cll=std::stod(cl);
double ddd=4*cll;
load_cap=load_cap+ddd;
}
else if(c!=K.end() && ccc==outputsonly.end()) //when node is not ouputnode but feeding another gate
{ ////cout<<"\nI AM HERE";
for(c=K.begin();c!=K.end();c++)
{
////cout<<"\nALL INPUT CAPACITANCES GATHERED";
map<string,Graph>::iterator g=circuit.begin();
g=circuit.find(*c);
string t=g->second.displayGATE();
transform(t.begin(), t.end(), t.begin(), ::toupper);
map<string, ReadLib>::iterator n =lib.find(t);
string cl=n->second.give_capa();
double cll=std::stod(cl);
load_cap=load_cap+cll; //Final Load capacitance of node under test
}
}
else if(c==K.end()) //When gate is output node and not feeding any other gate
{
map<string, ReadLib>::iterator n =lib.find("INV");
string cl=n->second.give_capa();
double cll=std::stod(cl);
load_cap=4*cll;
}
//Counting number of Inputs to the GATE and collecting Tdi and Touti
double size=J.size();
vector <double> di;
vector <double> Tout;
//for(vector<double>::iterator y=Ti.begin();y!=Ti.end();y++)
{
m=circuit.find(s);
string ty=m->second.displayGATE();
transform(ty.begin(), ty.end(), ty.begin(), ::toupper);
////cout<<"\nCALLING DI";
// outfile<<"\nLOAD CAPACITANCE : "<<load_cap;
// outfile<<"\nSIZE :"<<size;
// outfile<<"\nTYPE: "<<ty;
// outfile<<"\nINput slews of fanins for node "<<s<<"\t";
// for(auto i=Ti.begin();i!=Ti.end();i++)
// {
// outfile<<*i<<"\t";
// }
di = get_di(ty,Ti,load_cap,size);
//outfile<<"\nALL DELAYS : ";
//for(auto i=di.begin();i!=di.end();i++)
{
// outfile<<*i<<"\t";
}
// outfile<<"\nDELAY COLLECTED FROM LUT for node"<<s<<"\t";
// for(auto i=di.begin();i!=di.end();i++)
{
// outfile<<*i<<"\t";
}
Tout=get_Tout(ty,Ti,load_cap,size);
// outfile<<"\nALL OUTPUT SLEW : ";
//for(auto i=Tout.begin();i!=Tout.end();i++)
{
// outfile<<*i<<"\t";
}
}
vector <double> aout;
vector<double>::iterator w=At.begin();
vector<double>::iterator x=di.begin();
for(w=At.begin(),x=di.begin();w!=At.end(),x!=di.end();w++,x++)
{
aout.push_back(*w+*x);
}
double maxAout=*max_element(aout.begin(),aout.end()); //Arrival time (Final)
vector<double>::iterator it=find(aout.begin(),aout.end(),maxAout);
int tdi_index=distance(aout.begin(), it);
double d_i=di[tdi_index];
m->second.writeFiDelay(di);
//outfile<<"\nDELAY CORRESPONDING TO DIFFERENT INPUT SLEW for node"<<s<<"\t";
//for(auto i=di.begin();i!=di.end();i++)
//{
// outfile<<*i<<"\t";
//}
//cout<<d_i<<"\t";
// m->second.writeNodeDelay(d_i);
// outfile<<"\nLOAD CAPACIATANCE: "<<load_cap;
//double maxTout=find_Tout(ty,d_i,load_cap,size);
double maxTout=Tout[tdi_index];
m=circuit.find(s);
////cout<<"\nMAX ARRIVAL TIME "<<maxAout;
////cout<<maxTout;
m->second.writeArrivaltime(maxAout);
m->second.writeOutputSlewtime(maxTout);
//outfile<<"\nOUTPUT SLEW/AT : "<<maxTout << ' ' << maxAout << ' ' << m->second.giveGID() << ' ' << m->second.displayGATE() ;
m->second.writeReady(1);
J.clear();