File: Search.tcl

package info (click to toggle)
opensta 0~20191111gitc018cb2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 5,116 kB
  • sloc: cpp: 99,117; tcl: 8,530; yacc: 1,435; lex: 894; makefile: 541; sh: 107
file content (420 lines) | stat: -rw-r--r-- 11,705 bytes parent folder | download | duplicates (2)
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
# OpenSTA, Static Timing Analyzer
# Copyright (c) 2019, Parallax Software, Inc.
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

namespace eval sta {

################################################################
#
# Search debugging/probing commands
#
################################################################

define_cmd_args "report_arrival" {pin}

proc report_arrival { pin } {
  report_delays_wrt_clks $pin "arrivals_clk_delays"
}

proc report_delays_wrt_clks { pin_arg what } {
  set pin [get_port_pin_error "pin" $pin_arg]
  foreach vertex [$pin vertices] {
    if { $vertex != "NULL" } {
      report_delays_wrt_clk $vertex $what "NULL" "rise"
      report_delays_wrt_clk $vertex $what [default_arrival_clock] "rise"
      set clk_iter [clock_iterator]
      while {[$clk_iter has_next]} {
	set clk [$clk_iter next]
	report_delays_wrt_clk $vertex $what $clk "rise"
	report_delays_wrt_clk $vertex $what $clk "fall"
      }
      $clk_iter finish
    }
  }
}

proc report_delays_wrt_clk { vertex what clk clk_tr } {
  global sta_report_default_digits

  set rise [$vertex $what rise $clk $clk_tr $sta_report_default_digits]
  set fall [$vertex $what fall $clk $clk_tr $sta_report_default_digits]
  # Filter INF/-INF arrivals.
  if { !([delays_are_inf $rise] && [delays_are_inf $fall]) } {
    set rise_fmt [format_delays $rise]
    set fall_fmt [format_delays $fall]
    if {$clk != "NULL"} {
      set clk_str " ([get_name $clk] [rise_fall_short_name $clk_tr])"
    } else {
      set clk_str ""
    }
    puts "$clk_str r $rise_fmt f $fall_fmt"
  }
}

proc report_wrt_clks { pin_arg what } {
  set pin [get_port_pin_error "pin" $pin_arg]
  foreach vertex [$pin vertices] {
    if { $vertex != "NULL" } {
      report_wrt_clk $vertex $what "NULL" "rise"
      report_wrt_clk $vertex $what [default_arrival_clock] "rise"
      set clk_iter [clock_iterator]
      while {[$clk_iter has_next]} {
	set clk [$clk_iter next]
	report_wrt_clk $vertex $what $clk "rise"
	report_wrt_clk $vertex $what $clk "fall"
      }
      $clk_iter finish
    }
  }
}

proc report_wrt_clk { vertex what clk clk_tr } {
  global sta_report_default_digits

  set rise [$vertex $what rise $clk $clk_tr]
  set fall [$vertex $what fall $clk $clk_tr]
  # Filter INF/-INF arrivals.
  if { !([times_are_inf $rise] && [times_are_inf $fall]) } {
    set rise_fmt [format_times $rise $sta_report_default_digits]
    set fall_fmt [format_times $fall $sta_report_default_digits]
    if {$clk != "NULL"} {
      set clk_str " ([get_name $clk] [rise_fall_short_name $clk_tr])"
    } else {
      set clk_str ""
    }
    puts "$clk_str r $rise_fmt f $fall_fmt"
  }
}

proc rise_fall_short_name { tr } {
  if { $tr eq "rise" } {
    return [rise_short_name]
  } elseif { $tr eq "fall" } {
    return [fall_short_name]
  } else {
    error "unknown transition name $tr"
  }
}

proc times_are_inf { times } {
  foreach time $times {
    if { $time < 1e+10 && $time > -1e+10 } {
      return 0
    }
  }
  return 1
}

proc delays_are_inf { delays } {
  foreach delay $delays {
    if { !([string match "INF*" $delay] \
	     || [string match "-INF*" $delay]) } {
      return 0
    }
  }
  return 1
}

################################################################

# Note that -all and -tags are intentionally "hidden".
define_cmd_args "report_path" \
  {[-min|-max]\
     [-format full|full_clock|full_clock_expanded|short|end|summary]\
     [-fields [capacitance|slew|input_pin|net]\
     [-digits digits] [-no_line_splits]\
     [> filename] [>> filename]\
     pin ^|r|rise|v|f|fall}

proc_redirect report_path {
  parse_key_args "report_path" args keys {} \
    flags {-max -min -all -tags} 0

  if { [info exists flags(-min)] && [info exists flags(-max)] } {
    sta_error "-min and -max cannot both be specified."
  } elseif [info exists flags(-min)] {
    set min_max "min"
  } elseif [info exists flags(-max)] {
    set min_max "max"
  } else {
    # Default to max path.
    set min_max "max"
  }
  set report_tags [info exists flags(-tags)]
  set report_all [info exists flags(-all)]

  parse_report_path_options "report_path" args "full" 1
  check_argc_eq2 "report_path" $args

  set pin_arg [lindex $args 0]
  set tr [parse_rise_fall_arg [lindex $args 1]]

  set pin [get_port_pin_error "pin" $pin_arg]
  if { [$pin is_hierarchical] } {
    sta_error "pin '$pin_arg' is hierarchical."
  } else {
    foreach vertex [$pin vertices] {
      if { $vertex != "NULL" } {
	if { $report_all } {
	  set first 1
	  set path_iter [$vertex path_iterator $tr $min_max]
	  while {[$path_iter has_next]} {
	    set path [$path_iter next]
	    if { $first }  {
	      puts "Tag group: [$vertex tag_group_index]"
	    } else {
	      puts ""
	    }
	    if { $report_tags } {
	      puts "Tag: [$path tag]"
	    }
	    report_path_cmd $path
	    delete_path_ref $path
	    set first 0
	  }
	  $path_iter finish
	} else {
	  set worst_path [vertex_worst_arrival_path_tr $vertex $tr $min_max]
	  if { $worst_path != "NULL" } {
	    if { $report_tags } {
	      puts "Tag: [$worst_path tag]"
	    }
	    report_path_cmd $worst_path
	    delete_path_ref $worst_path
	  }
	}
      }
    }
  }
}

proc parse_rise_fall_arg { arg } {
  if { $arg eq "r" || $arg eq "^" || $arg eq "rise" } {
    return "rise"
  } elseif { $arg eq "f" || $arg eq "v" || $arg eq "fall" } {
    retur "fall"
  } else {
    error "unknown rise/fall transition name."
  }
}

proc parse_report_path_options { cmd args_var default_format
				 unknown_key_is_error } {
  variable path_options
  variable report_path_field_width_extra
  global sta_report_default_digits

  upvar 1 $args_var args
  if [info exists path_options] {
    unset path_options
  }
  parse_key_args $cmd args path_options {-format -digits -fields} \
    path_options {-no_line_splits} $unknown_key_is_error

  set format $default_format
  if [info exists path_options(-format)] {
    set format $path_options(-format)
    set formats {full full_clock full_clock_expanded short \
		   end slack_only summary}
    if { [lsearch $formats $format] == -1 } {
      sta_error "-format $format not recognized."
    }
  } else {
    set path_options(-format) $default_format
  }
  set_report_path_format $format

  set digits $sta_report_default_digits
  if [info exists path_options(-digits)] {
    set digits $path_options(-digits)
    check_positive_integer "-digits" $digits
  }
  set path_options(num_fmt) "%.${digits}f"
  set_report_path_digits $digits
  # Numberic field width expands with digits.
  set field_width [expr $digits + $report_path_field_width_extra]
  foreach field {total incr capacitance slew} {
    set_report_path_field_width $field $field_width
  }

  if { [info exists path_options(-fields)] } {
    set fields $path_options(-fields)
    set report_input_pin [expr [lsearch $fields "input*"] != -1]
    set report_cap [expr [lsearch $fields "cap*"] != -1]
    set report_net [expr [lsearch $fields "net*"] != -1]
    # transition_time - compatibility 06/24/2019
    set report_slew [expr [lsearch $fields "slew*"] != -1 \
		       || [lsearch $fields "trans*"] != -1]
  } else {
    set report_input_pin 0
    set report_cap 0
    set report_net 0
    set report_slew 0
  }
  set_report_path_fields $report_input_pin $report_net \
    $report_cap $report_slew

  set_report_path_no_split [info exists path_options(-no_line_splits)]
}

################################################################

define_cmd_args "report_required" {pin}

proc report_required { pin } {
  report_delays_wrt_clks $pin "requireds_clk_delays"
}

################################################################

define_cmd_args "report_slack" {pin}

proc report_slack { pin } {
  report_delays_wrt_clks $pin "slacks_clk_delays"
}

################################################################

# Internal debugging command.
proc report_tag_arrivals { pin } {
  set pin [get_port_pin_error "pin" $pin]
  foreach vertex [$pin vertices] {
    report_tag_arrivals_cmd $vertex
  }
}

################################################################

define_hidden_cmd_args "total_negative_slack" \
  {[-corner corner] [-min]|[-max]}

proc total_negative_slack { args } {
  parse_key_args "total_negative_slack" args \
    keys {-corner} flags {-min -max}
  check_argc_eq0 "total_negative_slack" $args
  set min_max [parse_min_max_flags flags]
  if { [info exists keys(-corner)] } {
    set corner [parse_corner_required keys]
    set tns [total_negative_slack_corner_cmd $corner $min_max]
  } else {
    set tns [total_negative_slack_cmd $min_max]
  }
  return [time_sta_ui $tns]
}

################################################################

define_hidden_cmd_args "worst_negative_slack" \
  {[-corner corner] [-min]|[-max]}

proc worst_negative_slack { args } {
  set worst_slack [worst_slack1 "worst_negative_slack" $args]
  if { $worst_slack < 0.0 } {
    return $worst_slack
  } else {
    return 0.0
  }
}

################################################################

define_hidden_cmd_args "worst_slack" \
  {[-corner corner] [-min]|[-max]}

proc worst_slack { args } {
  return [worst_slack1 "worst_slack" $args]
}

# arg parsing common to worst_slack/worst_negative_slack
proc worst_slack1 { cmd args1 } {
  parse_key_args $cmd args1 \
    keys {-corner} flags {-min -max}
  check_argc_eq0 $cmd $args1
  set min_max [parse_min_max_flags flags]
  if { [info exists keys(-corner)] } {
    set corner [parse_corner_required keys]
    set worst_slack [worst_slack_corner $corner $min_max]
  } else {
    set worst_slack [worst_slack_cmd $min_max]
  }
  return [time_sta_ui $worst_slack]
}

################################################################
#
# Helper functions
#
################################################################

proc parse_path_group_arg { group_names } {
  set names {}
  foreach name $group_names {
    if { [is_path_group_name $name] } {
      lappend names $name
    } else {
      sta_warn "unknown path group '$name'."
    }
  }
  return $names
}

proc report_slew_limits { corner min_max all_violators verbose nosplit } {
  if { $all_violators } {
    set violators [pin_slew_limit_violations $corner $min_max]
    if { $violators != {} } {
      puts "${min_max}_transition"
      puts ""
      if { $verbose } {
	foreach pin $violators {
	  report_slew_limit_verbose $pin $corner $min_max
	  puts ""
	}
      } else {
	report_slew_limit_short_header
	foreach pin $violators {
	  report_slew_limit_short $pin $corner $min_max
	}
	puts ""
      }
    }
  } else {
    set pin [pin_min_slew_limit_slack $corner $min_max]
    if { $pin != "NULL" } {
      puts "${min_max}_transition"
      puts ""
      if { $verbose } {
	report_slew_limit_verbose $pin $corner $min_max
	puts ""
      } else {
	report_slew_limit_short_header
	report_slew_limit_short $pin $corner $min_max
	puts ""
      }
    }
  }
}

proc report_path_ends { path_ends } {
  report_path_end_header
  set prev_end "NULL"
  foreach path_end $path_ends {
    report_path_end2 $path_end $prev_end
    set prev_end $path_end
  }
  report_path_end_footer
}

# sta namespace end.
}