-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhtree2.cc
577 lines (521 loc) · 18.4 KB
/
htree2.cc
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
/*------------------------------------------------------------
* CACTI 6.5
* Copyright 2008 Hewlett-Packard Development Corporation
* All Rights Reserved
*
* Permission to use, copy, and modify this software and its documentation is
* hereby granted only under the following terms and conditions. Both the
* above copyright notice and this permission notice must appear in all copies
* of the software, derivative works or modified versions, and any portions
* thereof, and both notices must appear in supporting documentation.
*
* Users of this software agree to the terms and conditions set forth herein, and
* hereby grant back to Hewlett-Packard Company and its affiliated companies ("HP")
* a non-exclusive, unrestricted, royalty-free right and license under any changes,
* enhancements or extensions made to the core functions of the software, including
* but not limited to those affording compatibility with other hardware or software
* environments, but excluding applications which incorporate this software.
* Users further agree to use their best efforts to return to HP any such changes,
* enhancements or extensions that they make and inform HP of noteworthy uses of
* this software. Correspondence should be provided to HP at:
*
* Director of Intellectual Property Licensing
* Office of Strategy and Technology
* Hewlett-Packard Company
* 1501 Page Mill Road
* Palo Alto, California 94304
*
* This software may be distributed (but not offered for sale or transferred
* for compensation) to third parties, provided such third parties agree to
* abide by the terms and conditions of this notice.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND HP DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL HP
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*------------------------------------------------------------*/
#include "htree2.h"
#include "wire.h"
#include <assert.h>
#include <iostream>
Htree2::Htree2(
enum Wire_type wire_model, double mat_w, double mat_h,
int a_bits, int d_inbits, int d_outbits, int bl, int wl, enum Htree_type htree_type,
bool uca_tree_, TechnologyParameter::DeviceType *dt)
:in_rise_time(0), out_rise_time(0),
tree_type(htree_type), mat_width(mat_w), mat_height(mat_h),
add_bits(a_bits), data_in_bits(d_inbits), data_out_bits(d_outbits), ndbl(bl), ndwl(wl),
uca_tree(uca_tree_), wt(wire_model), deviceType(dt)
{
assert(bl >= 2 && wl >= 2);
// if (bl == 1 && wl == 1)
// {
// delay = 0;
// power.readOp.dynamic = 0;
// power.readOp.leakage = 0;
// area.w = mat_w;
// area.h = mat_h;
// return;
// }
// if (bl == 1) ndbl++;
// if (wl == 1) ndwl++;
max_unpipelined_link_delay = 0; //TODO
min_w_nmos = g_tp.min_w_nmos_;
min_w_pmos = deviceType->n_to_p_eff_curr_drv_ratio * min_w_nmos;
switch (htree_type)
{
case Add_htree:
wire_bw = init_wire_bw = add_bits;
in_htree();
break;
case Data_in_htree:
wire_bw = init_wire_bw = data_in_bits;
in_htree();
break;
case Data_out_htree:
wire_bw = init_wire_bw = data_out_bits;
out_htree();
break;
default:
assert(0);
break;
}
power_bit = power;
power.readOp.dynamic *= init_wire_bw;
assert(power.readOp.dynamic >= 0);
assert(power.readOp.leakage >= 0);
}
// nand gate sizing calculation
void Htree2::input_nand(double s1, double s2, double l_eff)
{
Wire w1(wt, l_eff);
double pton_size = deviceType->n_to_p_eff_curr_drv_ratio;
// input capacitance of a repeater = input capacitance of nand.
double nsize = s1*(1 + pton_size)/(2 + pton_size);
nsize = (nsize < 1) ? 1 : nsize;
double tc = 2*tr_R_on(nsize*min_w_nmos, NCH, 1) *
(drain_C_(nsize*min_w_nmos, NCH, 1, 1, g_tp.cell_h_def)*2 +
2 * gate_C(s2*(min_w_nmos + min_w_pmos), 0));
delay+= horowitz (w1.out_rise_time, tc,
deviceType->Vth/deviceType->Vdd, deviceType->Vth/deviceType->Vdd, RISE);
power.readOp.dynamic += 0.5 *
(2*drain_C_(pton_size * nsize*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def)
+ drain_C_(nsize*min_w_nmos, NCH, 1, 1, g_tp.cell_h_def)
+ 2*gate_C(s2*(min_w_nmos + min_w_pmos), 0)) *
deviceType->Vdd * deviceType->Vdd;
power.readOp.leakage += (wire_bw*cmos_Ileak(min_w_nmos*(nsize*2), min_w_pmos * nsize * 2, false)*deviceType->Vdd);
}
// tristate buffer model consisting of not, nand, nor, and driver transistors
void Htree2::output_buffer(double s1, double s2, double l_eff)
{
Wire w1(wt, l_eff);
double pton_size = deviceType->n_to_p_eff_curr_drv_ratio;
// input capacitance of repeater = input capacitance of nand + nor.
double size = s1*(1 + pton_size)/(2 + pton_size + 1 + 2*pton_size);
double s_eff = //stage eff of a repeater in a wire
(gate_C(s2*(min_w_nmos + min_w_pmos), 0) + w1.wire_cap(l_eff*1e-6))/
gate_C(s2*(min_w_nmos + min_w_pmos), 0);
double tr_size = gate_C(s1*(min_w_nmos + min_w_pmos), 0) * 1/2/(s_eff*gate_C(min_w_pmos, 0));
size = (size < 1) ? 1 : size;
double res_nor = 2*tr_R_on(size*min_w_pmos, PCH, 1);
double res_ptrans = tr_R_on(tr_size*min_w_nmos, NCH, 1);
double cap_nand_out = drain_C_(size*min_w_nmos, NCH, 1, 1, g_tp.cell_h_def) +
drain_C_(size*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def)*2 +
gate_C(tr_size*min_w_pmos, 0);
double cap_ptrans_out = 2 *(drain_C_(tr_size*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def) +
drain_C_(tr_size*min_w_nmos, NCH, 1, 1, g_tp.cell_h_def)) +
gate_C(s1*(min_w_nmos + min_w_pmos), 0);
double tc = res_nor * cap_nand_out + (res_nor + res_ptrans) * cap_ptrans_out;
delay += horowitz (w1.out_rise_time, tc,
deviceType->Vth/deviceType->Vdd, deviceType->Vth/deviceType->Vdd, RISE);
//nand
power.readOp.dynamic += 0.5 *
(2*drain_C_(size*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def) +
drain_C_(size*min_w_nmos, NCH, 1, 1, g_tp.cell_h_def) +
gate_C(tr_size*(min_w_pmos), 0)) *
deviceType->Vdd * deviceType->Vdd;
//not
power.readOp.dynamic += 0.5 *
(drain_C_(size*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def)
+drain_C_(size*min_w_nmos, NCH, 1, 1, g_tp.cell_h_def)
+gate_C(size*(min_w_nmos + min_w_pmos), 0)) *
deviceType->Vdd * deviceType->Vdd;
//nor
power.readOp.dynamic += 0.5 *
(drain_C_(size*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def)
+ 2*drain_C_(size*min_w_nmos, NCH, 1, 1, g_tp.cell_h_def)
+gate_C(tr_size*(min_w_nmos + min_w_pmos), 0)) *
deviceType->Vdd * deviceType->Vdd;
//output transistor
power.readOp.dynamic += 0.5 *
((drain_C_(tr_size*min_w_pmos, PCH, 1, 1, g_tp.cell_h_def)
+drain_C_(tr_size*min_w_nmos, NCH, 1, 1, g_tp.cell_h_def))*2
+ gate_C(s1*(min_w_nmos + min_w_pmos), 0)) *
deviceType->Vdd * deviceType->Vdd;
if(uca_tree) {
power.readOp.leakage += (deviceType->Vdd*cmos_Ileak(min_w_nmos*(tr_size*2/*inverter + output tr*/ + size*6 /*nand + nor*/),
min_w_pmos*(tr_size*2 + size*6), false)*wire_bw);
}
else {
power.readOp.leakage += (deviceType->Vdd*cmos_Ileak(min_w_nmos*(tr_size*2/*inverter + output tr*/ + size*6 /*nand + nor*/),
min_w_pmos*(tr_size*2 + size*6), false)*wire_bw);
}
}
/* calculates the input h-tree delay/power
* A nand gate is used at each node to
* limit the signal
* The area of an unbalanced htree (rows != columns)
* depends on how data is traversed.
* In the following function, if ( no. of rows < no. of columns),
* then data first traverse in excess hor. links until vertical
* and horizontal nodes are same.
* If no. of rows is bigger, then data traverse in
* a hor. link followed by a ver. link in a repeated
* fashion (similar to a balanced tree) until there are no
* hor. links left. After this it goes through the remaining vertical
* links.
*/
void
Htree2::in_htree()
{
//temp var
double s1 = 0, s2 = 0, s3 = 0;
double l_eff = 0;
Wire *wtemp1 = 0, *wtemp2 = 0, *wtemp3 = 0;
double len = 0, ht = 0;
int option = 0;
int h = (int) _log2(ndwl/2); // horizontal nodes
int v = (int) _log2(ndbl/2); // vertical nodes
double len_temp;
double ht_temp;
if (uca_tree)
{
ht_temp = (mat_height*ndbl/2 +/* since uca_tree models interbank tree, mat_height => bank height */
((add_bits + data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch *
2 * (1-pow(0.5,h))))/2;
len_temp = (mat_width*ndwl/2 +
((add_bits + data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch *
2 * (1-pow(0.5,v))))/2;
}
else
{
if (ndwl == ndbl) {
ht_temp = ((mat_height*ndbl/2) +
(add_bits * (ndbl/2-1) * g_tp.wire_outside_mat.pitch) +
((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * h)
)/2;
len_temp = (mat_width*ndwl/2 +
(add_bits * (ndwl/2-1) * g_tp.wire_outside_mat.pitch) +
((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * v))/2;
}
else if (ndwl > ndbl) {
double excess_part = (_log2(ndwl/2) - _log2(ndbl/2));
ht_temp = ((mat_height*ndbl/2) +
(add_bits * ((ndbl/2-1) + excess_part) * g_tp.wire_outside_mat.pitch) +
(data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch *
(2*(1 - pow(0.5, h-v)) + pow(0.5, v-h) * v))/2;
len_temp = (mat_width*ndwl/2 +
(add_bits * (ndwl/2-1) * g_tp.wire_outside_mat.pitch) +
((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * v))/2;
}
else {
double excess_part = (_log2(ndbl/2) - _log2(ndwl/2));
ht_temp = ((mat_height*ndbl/2) +
(add_bits * ((ndwl/2-1) + excess_part) * g_tp.wire_outside_mat.pitch) +
((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * h)
)/2;
len_temp = (mat_width*ndwl/2 +
(add_bits * ((ndwl/2-1) + excess_part) * g_tp.wire_outside_mat.pitch) +
(data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * (h + 2*(1-pow(0.5, v-h))))/2;
}
}
area.h = ht_temp * 2;
area.w = len_temp * 2;
delay = 0;
power.readOp.dynamic = 0;
power.readOp.leakage = 0;
len = len_temp;
ht = ht_temp/2;
while (v > 0 || h > 0)
{
if (wtemp1) delete wtemp1;
if (wtemp2) delete wtemp2;
if (wtemp3) delete wtemp3;
if (h > v)
{
//the iteration considers only one horizontal link
wtemp1 = new Wire(wt, len); // hor
wtemp2 = new Wire(wt, len/2); // next hor
len_temp = len;
len /= 2;
wtemp3 = 0;
h--;
option = 0;
}
else if (v>0 && h>0)
{
//considers one horizontal link and one vertical link
wtemp1 = new Wire(wt, len); // hor
wtemp2 = new Wire(wt, ht); // ver
wtemp3 = new Wire(wt, len/2); // next hor
len_temp = len;
ht_temp = ht;
len /= 2;
ht /= 2;
v--;
h--;
option = 1;
}
else
{
// considers only one vertical link
assert(h == 0);
wtemp1 = new Wire(wt, ht); // ver
wtemp2 = new Wire(wt, ht/2); // next ver
ht_temp = ht;
ht /= 2;
wtemp3 = 0;
v--;
option = 2;
}
delay += wtemp1->delay;
power.readOp.dynamic += wtemp1->power.readOp.dynamic;
power.readOp.leakage += wtemp1->power.readOp.leakage*wire_bw;
if (uca_tree == false && option == 2)
{
wire_bw*=2; // wire bandwidth doubles only for vertical branches
}
if (uca_tree == false)
{
if (len_temp > wtemp1->repeater_spacing)
{
s1 = wtemp1->repeater_size;
l_eff = wtemp1->repeater_spacing;
}
else
{
s1 = (len_temp/wtemp1->repeater_spacing) * wtemp1->repeater_size;
l_eff = len_temp;
}
if (ht_temp > wtemp2->repeater_spacing)
{
s2 = wtemp2->repeater_size;
}
else
{
s2 = (len_temp/wtemp2->repeater_spacing) * wtemp2->repeater_size;
}
// first level
input_nand(s1, s2, l_eff);
}
if (option != 1)
{
continue;
}
// second level
delay += wtemp2->delay;
power.readOp.dynamic += wtemp2->power.readOp.dynamic;
power.readOp.leakage += wtemp2->power.readOp.leakage*wire_bw;
if (uca_tree)
{
power.readOp.leakage += (wtemp2->power.readOp.leakage*wire_bw);
}
else
{
power.readOp.leakage += (wtemp2->power.readOp.leakage*wire_bw);
wire_bw*=2;
if (ht_temp > wtemp3->repeater_spacing)
{
s3 = wtemp3->repeater_size;
l_eff = wtemp3->repeater_spacing;
}
else
{
s3 = (len_temp/wtemp3->repeater_spacing) * wtemp3->repeater_size;
l_eff = ht_temp;
}
input_nand(s2, s3, l_eff);
}
}
if (wtemp1) delete wtemp1;
if (wtemp2) delete wtemp2;
if (wtemp3) delete wtemp3;
}
/* a tristate buffer is used to handle fan-ins
* The area of an unbalanced htree (rows != columns)
* depends on how data is traversed.
* In the following function, if ( no. of rows < no. of columns),
* then data first traverse in excess hor. links until vertical
* and horizontal nodes are same.
* If no. of rows is bigger, then data traverse in
* a hor. link followed by a ver. link in a repeated
* fashion (similar to a balanced tree) until there are no
* hor. links left. After this it goes through the remaining vertical
* links.
*/
void Htree2::out_htree()
{
//temp var
double s1 = 0, s2 = 0, s3 = 0;
double l_eff = 0;
Wire *wtemp1 = 0, *wtemp2 = 0, *wtemp3 = 0;
double len = 0, ht = 0;
int option = 0;
int h = (int) _log2(ndwl/2);
int v = (int) _log2(ndbl/2);
double len_temp;
double ht_temp;
if (uca_tree)
{
ht_temp = (mat_height*ndbl/2 +/* since uca_tree models interbank tree, mat_height => bank height */
((add_bits + data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch *
2 * (1-pow(0.5,h))))/2;
len_temp = (mat_width*ndwl/2 +
((add_bits + data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch *
2 * (1-pow(0.5,v))))/2;
}
else
{
if (ndwl == ndbl) {
ht_temp = ((mat_height*ndbl/2) +
(add_bits * (ndbl/2-1) * g_tp.wire_outside_mat.pitch) +
((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * h)
)/2;
len_temp = (mat_width*ndwl/2 +
(add_bits * (ndwl/2-1) * g_tp.wire_outside_mat.pitch) +
((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * v))/2;
}
else if (ndwl > ndbl) {
double excess_part = (_log2(ndwl/2) - _log2(ndbl/2));
ht_temp = ((mat_height*ndbl/2) +
(add_bits * ((ndbl/2-1) + excess_part) * g_tp.wire_outside_mat.pitch) +
(data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch *
(2*(1 - pow(0.5, h-v)) + pow(0.5, v-h) * v))/2;
len_temp = (mat_width*ndwl/2 +
(add_bits * (ndwl/2-1) * g_tp.wire_outside_mat.pitch) +
((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * v))/2;
}
else {
double excess_part = (_log2(ndbl/2) - _log2(ndwl/2));
ht_temp = ((mat_height*ndbl/2) +
(add_bits * ((ndwl/2-1) + excess_part) * g_tp.wire_outside_mat.pitch) +
((data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * h)
)/2;
len_temp = (mat_width*ndwl/2 +
(add_bits * ((ndwl/2-1) + excess_part) * g_tp.wire_outside_mat.pitch) +
(data_in_bits + data_out_bits) * g_tp.wire_outside_mat.pitch * (h + 2*(1-pow(0.5, v-h))))/2;
}
}
area.h = ht_temp * 2;
area.w = len_temp * 2;
delay = 0;
power.readOp.dynamic = 0;
power.readOp.leakage = 0;
len = len_temp;
ht = ht_temp/2;
while (v > 0 || h > 0)
{ //finds delay/power of each link in the tree
if (wtemp1) delete wtemp1;
if (wtemp2) delete wtemp2;
if (wtemp3) delete wtemp3;
if(h > v) {
//the iteration considers only one horizontal link
wtemp1 = new Wire(wt, len); // hor
wtemp2 = new Wire(wt, len/2); // next hor
len_temp = len;
len /= 2;
wtemp3 = 0;
h--;
option = 0;
}
else if (v>0 && h>0) {
//considers one horizontal link and one vertical link
wtemp1 = new Wire(wt, len); // hor
wtemp2 = new Wire(wt, ht); // ver
wtemp3 = new Wire(wt, len/2); // next hor
len_temp = len;
ht_temp = ht;
len /= 2;
ht /= 2;
v--;
h--;
option = 1;
}
else {
// considers only one vertical link
assert(h == 0);
wtemp1 = new Wire(wt, ht); // ver
wtemp2 = new Wire(wt, ht/2); // next ver
ht_temp = ht;
ht /= 2;
wtemp3 = 0;
v--;
option = 2;
}
delay += wtemp1->delay;
power.readOp.dynamic += wtemp1->power.readOp.dynamic;
power.readOp.leakage += wtemp1->power.readOp.leakage*wire_bw;
if (uca_tree == false && option == 2)
{
wire_bw*=2;
}
if (uca_tree == false)
{
if (len_temp > wtemp1->repeater_spacing)
{
s1 = wtemp1->repeater_size;
l_eff = wtemp1->repeater_spacing;
}
else
{
s1 = (len_temp/wtemp1->repeater_spacing) * wtemp1->repeater_size;
l_eff = len_temp;
}
if (ht_temp > wtemp2->repeater_spacing)
{
s2 = wtemp2->repeater_size;
}
else
{
s2 = (len_temp/wtemp2->repeater_spacing) * wtemp2->repeater_size;
}
// first level
output_buffer(s1, s2, l_eff);
}
if (option != 1)
{
continue;
}
// second level
delay += wtemp2->delay;
power.readOp.dynamic += wtemp2->power.readOp.dynamic;
power.readOp.leakage += wtemp2->power.readOp.leakage*wire_bw;
if (uca_tree)
{
power.readOp.leakage += (wtemp2->power.readOp.leakage*wire_bw);
}
else
{
power.readOp.leakage += (wtemp2->power.readOp.leakage*wire_bw);
wire_bw*=2;
if (ht_temp > wtemp3->repeater_spacing)
{
s3 = wtemp3->repeater_size;
l_eff = wtemp3->repeater_spacing;
}
else
{
s3 = (len_temp/wtemp3->repeater_spacing) * wtemp3->repeater_size;
l_eff = ht_temp;
}
output_buffer(s2, s3, l_eff);
}
}
if (wtemp1) delete wtemp1;
if (wtemp2) delete wtemp2;
if (wtemp3) delete wtemp3;
}