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 | ###############################################################################
# Copyright (c) 2023-2024 by Altair Engineering, Inc.
# All rights reserved.
#
# Altair Engineering, Inc. makes this software available as part of the Vision
# tool platform. As long as you are a licensee of the Vision tool platform
# you may make copies of the software and modify it to be used within the
# Vision tool platform, but you must include all of this notice on any copy.
# Redistribution without written permission to any third party, with or
# without modification, is not permitted.
# Altair Engineering, Inc. does not warrant that this software is error free
# or fit for any purpose. Altair Engineering, Inc. disclaims any liability for
# all claims, expenses, losses, damages and costs any user may incur as a
# result of using, copying or modifying the software.
# =============================================================================
# @plugin
# Transistor Device Statistics
# @namespace
# TransistorStatistics
# @section
# Analyze the Loaded Database
# @description
# Report all the unique combinations for L and W in the design to gain
# insight into how many different combinations of L and W transistors
# exist in the design and where the different combinations are in the
# hcells.
# @files
# cust32/transistorStatistics.tcl
# @tag
# gui zdb spice
###############################################################################
namespace eval TransistorStatistics {
variable _Name "Transistor Statistics"
variable _TransistorStatistic
variable _Table ""
variable _TotalInstances 0
variable _CurrentInstance 0
}
# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc ::TransistorStatistics::Init {} {
variable _Name
##
# Add menu entries.
#
gui menu command [list $_Name "Show"] \
[list ::TransistorStatistics::_showWidget]
gui menu customizeEntry [list $_Name "Show"] \
[list ::TransistorStatistics::_customizeMenu "show"]
gui menu command [list $_Name "Hide"] \
[list ::TransistorStatistics::_closeWidget]
gui menu customizeEntry [list $_Name "Hide"] \
[list ::TransistorStatistics::_customizeMenu "hide"]
gui menu separator [list $_Name]
gui menu command [list $_Name "Export CSV"] \
[list ::TransistorStatistics::_exportCSV]
gui menu customizeEntry [list $_Name "Export CSV"] \
[list ::TransistorStatistics::_customizeMenu "hide"]
}
# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc ::TransistorStatistics::Finit {} {
variable _Name
::TransistorStatistics::_closeWidget
gui menu removeEntry [list $_Name]
}
# -----------------------------------------------------------------------------
# _showWidget -
# -----------------------------------------------------------------------------
#
proc ::TransistorStatistics::_showWidget {} {
variable _Name
variable _Table
set w [gui window insertCustomWidget \
-pluginNamespace "TransistorStatistics" \
-destroyCallback ::TransistorStatistics::_onWidgetClosed \
$_Name]
ttk::frame $w.f
set _Table $w.f.table
tablelist::tablelist $_Table \
-columns { \
0 "W" left \
0 "L" left \
0 "Type" left \
0 "Number of Instances" left \
0 "Number of HCells" left \
0 "HCells" left \
} \
-labelcommand tablelist::sortByColumn \
-stripebackground #f0f0f0
$_Table columnconfigure 3 -sortmode integer
$_Table columnconfigure 4 -sortmode integer
gui window autoscroll $w.f $_Table
grid $w.f -row 0 -column 0 -sticky news
grid rowconfigure $w 0 -weight 1
grid columnconfigure $w 0 -weight 1
gui database runAndRegisterChangedCallback ::TransistorStatistics::_showTree
}
# -----------------------------------------------------------------------------
# _closeWidget -
# -----------------------------------------------------------------------------
#
proc ::TransistorStatistics::_closeWidget {} {
variable _Name
gui window removeCustomWidget $_Name
}
# -----------------------------------------------------------------------------
# _onWidgetClosed -
# -----------------------------------------------------------------------------
#
proc ::TransistorStatistics::_onWidgetClosed {} {
gui database removeChangedCallback ::TransistorStatistics::_showTree
}
# -----------------------------------------------------------------------------
# _showTree -
# -----------------------------------------------------------------------------
#
proc ::TransistorStatistics::_showTree {{db {}}} {
variable _DeviceList
variable _Table
variable _TotalInstances
variable _CurrentInstance
if {$db == {}} {
set db [gui database get]
}
$_Table delete 0 end
if {$db == {}} {
return
}
zprogress begin
zprogress push "Calculate Transistor Statistic" 1.0
set _TotalInstances [$db report objCount -inst]
set _CurrentInstance 0
::TransistorStatistics::_start $db
zprogress end
::TransistorStatistics::_fillTable
}
# -----------------------------------------------------------------------------
# _start -
# -----------------------------------------------------------------------------
#
proc ::TransistorStatistics::_start {db} {
variable _TransistorStatistic
variable _TotalInstances
variable _CurrentInstance
$db foreach primitive prim {
$db flag $prim clear red
set func [$db primitiveFuncOf $prim]
if {($func eq "NMOS") || ($func eq "PMOS")} {
$db flag $prim set red
}
}
set _TransistorStatistic [dict create]
set top [$db get_top_design]
$db flat foreach instOfCell red $top inst {
if {[zprogress update "" [incr _CurrentInstance] $_TotalInstances]} {
break
}
set w [$db flatattr $inst getMergedValue "w"]
set spcW [zdb formatvalue fromspice -hspice $w]
set l [$db flatattr $inst getMergedValue "l"]
set spcL [zdb formatvalue fromspice -hspice $l]
set func [$db primitiveFuncOf $inst]
set key "$func:$spcW:$spcL"
if {![dict exists $_TransistorStatistic $key]} {
dict set _TransistorStatistic $key w $w
dict set _TransistorStatistic $key l $l
dict set _TransistorStatistic $key type $func
dict set _TransistorStatistic $key count 0
dict set _TransistorStatistic $key instList {}
dict set _TransistorStatistic $key hcells {}
}
set count [dict get $_TransistorStatistic $key count]
dict set _TransistorStatistic $key count [incr count]
set instList [dict get $_TransistorStatistic $key instList]
dict set _TransistorStatistic $key instList [lappend instList $inst]
set hcells [dict get $_TransistorStatistic $key hcells]
set hcell [$db oid oname [$db parentModule $inst]]
dict set _TransistorStatistic $key hcells [lappend hcells $hcell]
}
}
# -----------------------------------------------------------------------------
# _fillTable -
# -----------------------------------------------------------------------------
#
proc ::TransistorStatistics::_fillTable {} {
variable _Table
variable _TransistorStatistic
dict for {key value} $_TransistorStatistic {
set hcells [lsort -unique [dict get $value hcells]]
set hcellDisplay [join $hcells ", "]
$_Table insert end [list \
[dict get $value w] \
[dict get $value l] \
[dict get $value type] \
[dict get $value count] \
[llength $hcells] \
$hcellDisplay \
]
}
}
# -----------------------------------------------------------------------------
# _doExportCSV - Export a CSV file.
# -----------------------------------------------------------------------------
#
proc ::TransistorStatistics::_doExportCSV {fname} {
variable _TransistorStatistic
set out [open $fname w]
##
# Print a CSV file header.
#
set header {
"W"
"L"
"Type"
"Number of Instances"
"Number of HCells"
"HCells"
}
puts $out [join $header ","]
##
# Print each CSV file data row.
#
dict for {key value} $_TransistorStatistic {
set hcells [lsort -unique [dict get $value hcells]]
set data [list \
[dict get $value w] \
[dict get $value l] \
[dict get $value type] \
[dict get $value count] \
[llength $hcells] \
$hcells \
]
puts $out [join $data ","]
}
close $out
}
# -----------------------------------------------------------------------------
# _exportCSV - Export a CSV file.
# -----------------------------------------------------------------------------
#
proc ::TransistorStatistics::_exportCSV {} {
variable _Table
if {![winfo exists $_Table]} {
return
}
set title "Export Transistor Statistics as CSV"
set file_types {{"CSV Files" .csv}}
set file_name [gui window fileDialog saveFile $title $file_types]
if {$file_name ne ""} {
::TransistorStatistics::_doExportCSV $file_name
}
}
# -----------------------------------------------------------------------------
# _customizeMenu -
# -----------------------------------------------------------------------------
#
proc ::TransistorStatistics::_customizeMenu {mode menu} {
variable _Table
switch -exact -- $mode {
"show" {
set state [expr {[winfo exists $_Table] ? "disabled" : "normal"}]
}
"hide" {
set state [expr {[winfo exists $_Table] ? "normal" : "disabled"}]
}
default {
error "Bad mode: $mode"
}
}
$menu entryconfigure end -state $state
}
##
# Initialize the plugin.
#
::TransistorStatistics::Init
|