|
| 1 | +# Native Tcl script to extract path details directly from OpenSTA into CSV |
| 2 | +# Usage: source dump_paths_native.tcl |
| 3 | + |
| 4 | +set out_file $::env(DUMP_OUT_FILE) |
| 5 | +set stage_prefix $::env(DUMP_STAGE_PREFIX) |
| 6 | + |
| 7 | +if {![info exists ::env(DUMP_OUT_FILE)] || ![info exists ::env(DUMP_STAGE_PREFIX)]} { |
| 8 | + puts "Error: DUMP_OUT_FILE or DUMP_STAGE_PREFIX not set." |
| 9 | + exit 1 |
| 10 | +} |
| 11 | + |
| 12 | +puts "Extracting paths natively for stage: $stage_prefix to $out_file" |
| 13 | + |
| 14 | +set fp [open $out_file w] |
| 15 | +puts $fp "startpoint,endpoint,${stage_prefix}_min_clk_period,${stage_prefix}_net_delay,${stage_prefix}_logic_delay,${stage_prefix}_total_cap,${stage_prefix}_buffers" |
| 16 | + |
| 17 | +# Get top 2000 paths |
| 18 | +set paths [find_timing_paths -path_delay max -group_path_count 2000] |
| 19 | + |
| 20 | +foreach path_end $paths { |
| 21 | + set slack [$path_end slack] |
| 22 | + set path [$path_end path] |
| 23 | + |
| 24 | + set start_path [$path start_path] |
| 25 | + set start_pin [$start_path pin] |
| 26 | + set end_pin [$path_end pin] |
| 27 | + |
| 28 | + set startpoint [get_name $start_pin] |
| 29 | + set endpoint [get_name $end_pin] |
| 30 | + |
| 31 | + # Get clock period from active clocks or default to datapath arrival if no clocks |
| 32 | + set clocks [all_clocks] |
| 33 | + if {[llength $clocks] > 0} { |
| 34 | + set clk_period [[lindex $clocks 0] period] |
| 35 | + set min_clk_period [expr {$clk_period - $slack}] |
| 36 | + } else { |
| 37 | + set min_clk_period [$path arrival] |
| 38 | + } |
| 39 | + |
| 40 | + # Redirect standard report output to string for precise table parsing |
| 41 | + utl::redirectStringBegin |
| 42 | + sta::set_report_path_digits 4 |
| 43 | + sta::set_report_path_fields {capacitance net slew} |
| 44 | + sta::report_path_cmd $path |
| 45 | + set report_str [utl::redirectStringEnd] |
| 46 | + |
| 47 | + set net_delay 0.0 |
| 48 | + set logic_delay 0.0 |
| 49 | + set total_cap 0.0 |
| 50 | + set buffers 0 |
| 51 | + |
| 52 | + set datapath_delay [$path arrival] |
| 53 | + if {$datapath_delay < 1e-4} { |
| 54 | + set datapath_delay [expr {$datapath_delay * 1e9}] |
| 55 | + } |
| 56 | + |
| 57 | + # Process report_path_cmd text lines |
| 58 | + set lines [split $report_str "\n"] |
| 59 | + set prev_time 0.0 |
| 60 | + foreach line $lines { |
| 61 | + set tokens [regexp -all -inline {\S+} $line] |
| 62 | + if {[llength $tokens] >= 5 && [string is double -strict [lindex $tokens 3]]} { |
| 63 | + set curr_time [lindex $tokens 3] |
| 64 | + set cell_delay [lindex $tokens 2] |
| 65 | + if {[string is double -strict $cell_delay] && $cell_delay > 0.0} { |
| 66 | + set logic_delay [expr {$logic_delay + $cell_delay}] |
| 67 | + } |
| 68 | + set step [expr {$curr_time - $prev_time}] |
| 69 | + set n_delay [expr {$step - $cell_delay}] |
| 70 | + if {$n_delay > 0.0} { |
| 71 | + set net_delay [expr {$net_delay + $n_delay}] |
| 72 | + } |
| 73 | + set prev_time $curr_time |
| 74 | + |
| 75 | + set c_str [lindex $tokens 0] |
| 76 | + if {[string is double -strict $c_str]} { |
| 77 | + set c_val [expr {abs($c_str)}] |
| 78 | + if {$c_val > 0.0} { |
| 79 | + if {$c_val < 1e-9} { set c_val [expr {$c_val * 1e15}] } |
| 80 | + set total_cap [expr {$total_cap + $c_val}] |
| 81 | + } |
| 82 | + } |
| 83 | + if {[regexp {\(([^net][^\)]*)\)} $line -> cell_type]} { |
| 84 | + if {[regexp {sky130_fd_sc_hd__(buf|dly)} $cell_type] || [regexp {BUF} $cell_type]} { |
| 85 | + incr buffers |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + # Convert seconds to delay units (ps for asap7, ns for sky130hd) |
| 92 | + set is_asap7 0 |
| 93 | + if {[info exists ::env(DESIGN_PLATFORM)] && [string match "*asap7*" $::env(DESIGN_PLATFORM)]} { |
| 94 | + set is_asap7 1 |
| 95 | + } elseif {[string match "*asap7*" $out_file]} { |
| 96 | + set is_asap7 1 |
| 97 | + } |
| 98 | + |
| 99 | + if {$min_clk_period < 1e-4} { |
| 100 | + if {$is_asap7} { |
| 101 | + # asap7 is in ps |
| 102 | + set min_clk_period [expr {$min_clk_period * 1e12}] |
| 103 | + } else { |
| 104 | + # sky130hd is in ns |
| 105 | + set min_clk_period [expr {$min_clk_period * 1e9}] |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + puts $fp "$startpoint,$endpoint,$min_clk_period,$net_delay,$logic_delay,$total_cap,$buffers" |
| 110 | +} |
| 111 | + |
| 112 | +close $fp |
| 113 | +puts "Dump complete." |
0 commit comments