shuffle_macro.tcl 1.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
proc shuffle1 {list} {
    set n [llength $list]
    for {set i 0} {$i < $n} {incr i} {
        set j [expr {int(rand() * $n)}]
        set temp [lindex $list $j]
        set list [lreplace $list $j $j [lindex $list $i]]
        set list [lreplace $list $i $i $temp]
    }
    return $list
}

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
proc shuffle2 {ilist seed} {
  set fp_name "temp_list.txt"
  set fp [open $fp_name "w"]
  foreach item $ilist {
    puts $fp "$item"
  }
  close $fp
  exec /home/sakundu/.conda/envs/py37-tf2/bin/python3.7 ../../../../util/shuffle_file_line.py $fp_name $seed
  set new_list {}
  set fp [open $fp_name "r"]
  while {[gets $fp line] >= 0 } {
    lappend new_list $line
  }
  exec rm -rf $fp_name
  return $new_list
}

proc shuffle_macros {seed} {
30 31 32 33 34 35 36
  foreach macro_ref [dbget [dbget top.insts.cell.subClass block -p ].name -u] {
    set macro_list [dbget [dbget top.insts.cell.name $macro_ref -p2 ].name]
    set pt_x_list [dbget [dbget top.insts.cell.name $macro_ref -p2 ].pt_x]
    set pt_y_list [dbget [dbget top.insts.cell.name $macro_ref -p2 ].pt_y]
    set orient_list [dbget [dbget top.insts.cell.name $macro_ref -p2 ].orient]

    set number_macros [llength $macro_list]
37
    set shuffle_macros [shuffle2 $macro_list $seed]
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

    ## Unplace all macros ##
    dbset [dbget top.insts.cell.name $macro_ref -p2 ].pStatus unplaced
    set i 0
    set k 0
    foreach macro $shuffle_macros {
      set pt_x [lindex $pt_x_list $i]
      set pt_y [lindex $pt_y_list $i]
      set orient [lindex $orient_list $i]
      placeInstance $macro $pt_x $pt_y $orient -fixed
      incr i
      if {[lindex $macro_list $i] != $macro} {
        incr k
      }
    }
    puts "$k macros (ref name: ${macro_ref}) are shuffled"
  }
}