Writing Efficient Code - 2022.2 English

Vivado Design Suite User Guide: Using Tcl Scripting (UG894)

Document ID
UG894
Release Date
2022-10-19
Version
2022.2 English

One way to improve runtime is to write code efficiently such that a container is built and a command runs on the entire container versus running the command within a loop on each item that would be part of the container. The following example illustrates this and is similar to that seen in the Creating Custom Design Rules Checks (DRCs) section.

Inefficient code:

foreach bram [get_cells -hier -filter {PRIMITIVE_SUBGROUP == bram}] {
    set bwidth [get_property WRITE_WIDTH_B $bram]
    if { $bwidth > 36} {
        highlight_object -color red [get_cells $bram]
    }; # End IF
}; # End FOR

Efficient code:

foreach bram [get_cells -hier -filter {PRIMITIVE_SUBGROUP == bram}] {
    set bwidth [get_property WRITE_WIDTH_B $bram]
    if { $bwidth > 36} {
        lappend bram_list $bram
    }; # End IF
}; # End FOR
highlight_object -color red [get_cells $bram_list]

An even more compact and efficient way to code this is to apply the filter as part of the get_cells command. This removes the need to perform a foreach loop with individualized checking at the expense of a slightly more complicated filter.

highlight_object -color red [get_cells -hier -filter {PRIMITIVE_SUBGROUP == bram && 
WRITE_WIDTH_B > 36}]