|
| 1 | +source $::env(SCRIPTS_DIR)/yosys_load.tcl |
| 2 | + |
| 3 | +proc convert_liberty_areas {} { |
| 4 | + cellmatch -derive_luts =A:liberty_cell |
| 5 | + # find a reference nand2 gate |
| 6 | + set found_cell "" |
| 7 | + set found_cell_area "" |
| 8 | + # iterate over all cells with a nand2 signature |
| 9 | + foreach cell [tee -q -s result.string select -list-mod =*/a:lut=4'b0111 %m] { |
| 10 | + if {! [rtlil::has_attr -mod $cell area]} { |
| 11 | + puts "Cell $cell missing area information" |
| 12 | + continue |
| 13 | + } |
| 14 | + set area [rtlil::get_attr -string -mod $cell area] |
| 15 | + if {$found_cell == "" || [expr $area < $found_cell_area]} { |
| 16 | + set found_cell $cell |
| 17 | + set found_cell_area $area |
| 18 | + } |
| 19 | + } |
| 20 | + if {$found_cell == ""} { |
| 21 | + error "reference nand2 cell not found" |
| 22 | + } |
| 23 | + |
| 24 | + # convert the area on all Liberty cells to a gate number equivalent |
| 25 | + foreach box [tee -q -s result.string select -list-mod =A:area =A:liberty_cell %i] { |
| 26 | + set area [rtlil::get_attr -mod -string $box area] |
| 27 | + set gate_eq [expr int($area / $found_cell_area)] |
| 28 | + rtlil::set_attr -mod -uint $box gate_cost_equivalent $gate_eq |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +convert_liberty_areas |
| 33 | + |
| 34 | +setattr -unset A:keep_hierarchy=1 |
| 35 | + |
| 36 | +# Don't know how to enumerate gate equivalents for cells in the design |
| 37 | +# so set keep threshold to one and parse log for now |
| 38 | +tee -o $::env(OBJECTS_DIR)/1_gates.txt keep_hierarchy -min_cost 1 |
| 39 | +set f [open $::env(OBJECTS_DIR)/1_gates.txt r] |
| 40 | +set keep_hierarchy [read $f] |
| 41 | +close $f |
| 42 | +set f [open $::env(REPORTS_DIR)/1_gates.txt w] |
| 43 | +foreach line [split $keep_hierarchy \n] { |
| 44 | + if {[regexp {Keeping (\S+) \(estimated size above threshold: (\d+) >} $line _ cell size]} { |
| 45 | + puts $f "$cell $size" |
| 46 | + } |
| 47 | +} |
| 48 | +close $f |
0 commit comments