-
Notifications
You must be signed in to change notification settings - Fork 2
/
dualVth.tcl
197 lines (177 loc) · 7.53 KB
/
dualVth.tcl
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
proc dualVth {args} {
parse_proc_arguments -args $args results
set savings $results(-leakage)
suppress_message NED-045
suppress_message LNK-041
suppress_message LNK-016
suppress_message PTE-139
suppress_message PWR-246
suppress_message PWR-601
suppress_message PWR-602
suppress_message PWR-604
set start_power [get_attribute [get_design] leakage_power]
if {$savings == 0} {
#Nothing to do
return
} elseif {$savings > 0 && $savings < 1} {
#Compute end power only
set end_power [expr $start_power*(1-$savings)]
}
#Get a list of all cells in descending order of slack
set max_slack [get_max_slack]
#For each tuple in the list
foreach tuple $max_slack {
#Get the cell name and reference
set cell_name [lindex $tuple 0]
set cell_ref [lindex $tuple 1]
#If the current cell is of HVT type try to resize to its minimum possible
if { [get_attribute [get_lib_cell -of_object $cell_name] threshold_voltage_group] == "HVT"} {
#Get the cell current size
regexp {\d+$} $cell_ref size
#Get a list of alternative cells
foreach alt [alt_lib $cell_name $cell_ref] {
#Get the size of the alternative cell
regexp {\d+$} $alt alt_size
#If the size retrieved from the library is smaller than the current one resize
if { $alt_size < $size } {
size_cell $cell_name CORE65LPHVT_nom_1.20V_25C.db:$alt
#If global slack is negative after resizing, undo
if { [get_attribute [get_timing_paths] slack] < 0} {
size_cell $cell_name CORE65LPHVT_nom_1.20V_25C.db:$cell_ref
#Otherwise cell was succesfully reduced to the minimum size and exit the loop
} else {
break
}
#Cell cannot be reduced to less than current size
} else {
break
}
}
#If the current cell is of LVT type try to swap into HVT
} elseif { [get_attribute [get_lib_cell -of_object $cell_name] threshold_voltage_group] == "LVT"} {
#Substitute the reference name from LVT to HVT before swapping
if { [regexp {CORE65LPLVT/HS65_LL} $cell_ref ] } {
regsub {CORE65LPLVT/HS65_LL} $cell_ref {CORE65LPHVT/HS65_LH} new_ref
} elseif { [regexp {CORE65LPLVT/HS65_LLS} $cell_ref ] } {
regsub {CORE65LPLVT/HS65_LLS} $cell_ref {CORE65LPHVT/HS65_LHS} new_ref
}
swap_cell $cell_name CORE65LPHVT_nom_1.20V_25C.db:$new_ref
#If global slack is negative after swapping, undo and try to reduce size
if { [get_attribute [get_timing_paths] slack] < 0} {
swap_cell $cell_name CORE65LPLVT_nom_1.20V_25C.db:$cell_ref
regexp {\d+$} $cell_ref size
foreach alt [alt_lib $cell_name $cell_ref] {
regexp {\d+$} $alt alt_size
if { $alt_size < $size } {
size_cell $cell_name CORE65LPLVT_nom_1.20V_25C.db:$alt
if { [get_attribute [get_timing_paths] slack] < 0} {
size_cell $cell_name CORE65LPLVT_nom_1.20V_25C.db:$cell_ref
} else {
break
}
} else {
break
}
}
#If slack is positive after swapping, try to reduce size
} else {
regexp {\d+$} $new_ref size
foreach alt [alt_lib $cell_name $new_ref] {
regexp {\d+$} $alt alt_size
if { $alt_size < $size } {
size_cell $cell_name CORE65LPHVT_nom_1.20V_25C.db:$alt
if { [get_attribute [get_timing_paths] slack] < 0} {
size_cell $cell_name CORE65LPHVT_nom_1.20V_25C.db:$new_ref
} else {
break
}
} else {
break
}
}
}
}
if { $savings < 1} {
if {[get_attribute [get_design] leakage_power -quiet] <= $end_power} {
break
}
}
}
#In case the amount of savings required was not achieved in the first round that guarantees a positive slack
#start swapping the cells with higher slacks into HVT (the critical cells are the last ones in the get_max_slack list)
foreach tuple [get_max_slack] {
set cell_name [lindex $tuple 0]
set cell_ref [lindex $tuple 1]
#Substitute the reference name from LVT to HVT before swapping
if { [regexp {CORE65LPLVT/HS65_LL} $cell_ref ] } {
regsub {CORE65LPLVT/HS65_LL} $cell_ref {CORE65LPHVT/HS65_LH} new_ref
swap_cell $cell_name CORE65LPHVT_nom_1.20V_25C.db:$new_ref
} elseif { [regexp {CORE65LPLVT/HS65_LLS} $cell_ref ] } {
regsub {CORE65LPLVT/HS65_LLS} $cell_ref {CORE65LPHVT/HS65_LHS} new_ref
swap_cell $cell_name CORE65LPHVT_nom_1.20V_25C.db:$new_ref
} else {
set new_ref $cell_ref
}
#Get the current cell slack
set cell_slack [get_attribute [get_timing_paths -nworst 1 -through $cell_name] slack]
regexp {\d+$} $new_ref size
foreach alt [alt_lib $cell_name $new_ref] {
regexp {\d+$} $alt alt_size
if { $alt_size < $size } {
size_cell $cell_name CORE65LPHVT_nom_1.20V_25C.db:$alt
#If the cell slack after swapping and resizing is lower than the current one, undo
if {[get_attribute [get_timing_paths -nworst 1 -through $cell_name] slack] < $cell_slack} {
size_cell $cell_name CORE65LPHVT_nom_1.20V_25C.db:$new_ref
} else {
break
}
} else {
break
}
}
if { $savings < 1} {
if {[get_attribute [get_design] leakage_power -quiet] <= $end_power} {
break
}
}
}
}
define_proc_attributes dualVth \
-info "Post-Synthesis Dual-Vth cell assignment" \
-define_args \
{
{-leakage "minimum % of leakage savings in range [0, 1]" value float required}
}
proc get_max_slack {} {
#Default variable from system that must be true
global timing_save_pin_arrival_and_slack
set timing_save_pin_arrival_and_slack 1
set max_slack_list {}
#Sort list from descending order of slack
foreach_in_collection pin [sort_collection [get_pins */Z] max_slack -descending] {
set cell [get_attribute $pin cell]
set ref_name [get_attribute $cell ref_name]
#Append the reference name ready to be used with swap_cell and size_cell
if { [regexp {_LL_|_LLS_} $ref_name ] } {
set ref_name "CORE65LPLVT/$ref_name"
} elseif { [regexp {_LH_|_LHS_} $ref_name ] } {
set ref_name "CORE65LPHVT/$ref_name"
}
lappend max_slack_list "[get_attribute $cell full_name] $ref_name"
}
return $max_slack_list
}
proc alt_lib {cell ref_name} {
#List containing the alternative cells for the input
set alternatives {}
regexp {.+\/(.+X)\d+} $ref_name match header
#Get alternative cells for the same type but different sizes, i.e., a header equals to HS65_LH_NOR2X would only return
#alternative sizes of that cell
foreach_in_collection lib [get_alternative_lib_cells [get_cell $cell]] {
if { [regexp ".+$header.+" [get_attribute $lib full_name] ref] } {
lappend alternatives $ref
}
}
set alternatives [lsort -dictionary $alternatives]
return $alternatives
}