From e8f97ee0f76a12a3dc1d950cc71b5fd6d6a56011 Mon Sep 17 00:00:00 2001 From: jeffhsu3 Date: Sat, 10 Oct 2026 19:08:24 -0700 Subject: [PATCH 1/2] asap7: snap hardened macros to the fin and gate grids The macro placer snaps a macro's pins to the routing tracks only, so the standard cells inside a hardened block land off the 27 nm fin and 54 nm gate grids of the rows around it. snap_macros_to_fin_grid.tcl, run as POST_MACRO_PLACE_TCL, moves each placed macro to the nearest origin that puts its cells on those grids and keeps its pins on the tracks of every layer they use, mirrored placements included. On aes-block, which now uses it, the 21 macros move by at most 0.192 um, each a whole number of tracks, and the DRM's FIN.S.1/GATE.S.1 markers go from 11940 to 0 (gdscheck asap7). Detailed routing has no DRC errors and VDD/VSS stay connected. Co-Authored-By: Claude Opus 5.5 Signed-off-by: jeffhsu3 --- flow/designs/asap7/aes-block/config.mk | 3 + .../openRoad/snap_macros_to_fin_grid.tcl | 166 ++++++++++++++++++ 2 files changed, 169 insertions(+) create mode 100644 flow/platforms/asap7/openRoad/snap_macros_to_fin_grid.tcl diff --git a/flow/designs/asap7/aes-block/config.mk b/flow/designs/asap7/aes-block/config.mk index a6574cb03f..c77e9166f1 100644 --- a/flow/designs/asap7/aes-block/config.mk +++ b/flow/designs/asap7/aes-block/config.mk @@ -28,5 +28,8 @@ export PWR_NETS_VOLTAGES = # The macros are very small so use a smaller halo export RTLMP_MIN_CHANNEL_SIZE ?= 6 6 +# Keep the hardened blocks' cells on the fin and gate grids of the rows around them +export POST_MACRO_PLACE_TCL = $(PLATFORM_DIR)/openRoad/snap_macros_to_fin_grid.tcl + export ROUTING_LAYER_ADJUSTMENT = 0.3 export HOLD_SLACK_MARGIN = -30 diff --git a/flow/platforms/asap7/openRoad/snap_macros_to_fin_grid.tcl b/flow/platforms/asap7/openRoad/snap_macros_to_fin_grid.tcl new file mode 100644 index 0000000000..5700a9ec36 --- /dev/null +++ b/flow/platforms/asap7/openRoad/snap_macros_to_fin_grid.tcl @@ -0,0 +1,166 @@ +# Move each placed macro to the nearest origin that keeps the transistors in it +# on ASAP7's fin and gate grids - fins every 27 nm, gates every 54 nm, as every +# standard-cell row has them - and its pins on the routing tracks. The macro +# placer snaps a macro's pins to the tracks only, so the cells of a hardened +# block land off the grids of the cells around it. +# +# A macro built in this flow holds its cells and tracks on the same grids, +# measured from its origin, as the top level does from the die's. Along an +# axis the macro is not mirrored on, the origin is then a whole number of each +# pitch; along a mirrored one, the origin plus the macro's size is twice the +# grid's offset, modulo the pitch. +# +# Use as POST_MACRO_PLACE_TCL. + +proc asap7_snap_macros_to_fin_grid { } { + set block [ord::get_db_block] + set tech [ord::get_db_tech] + set core [$block getCoreArea] + # Fin and gate centres sit half a pitch past a multiple of the pitch, so + # twice their offset is a whole pitch. + set gate [ord::microns_to_dbu 0.054] + set fin [ord::microns_to_dbu 0.027] + + set macros {} + foreach inst [$block getInsts] { + if { [[$inst getMaster] isBlock] && [$inst isPlaced] } { + lappend macros $inst + } + } + + foreach inst $macros { + set master [$inst getMaster] + set orient [$inst getOrient] + switch $orient { + R0 { set flip_x 0; set flip_y 0 } + MX { set flip_x 0; set flip_y 1 } + MY { set flip_x 1; set flip_y 0 } + R180 { set flip_x 1; set flip_y 1 } + default { + utl::warn FLW 25 "[$inst getName]: orientation $orient not snapped to the fin grid." + continue + } + } + set w [$master getWidth] + set h [$master getHeight] + + # Constraints {pitch twice-offset} per axis: the gate and fin grids, then + # the tracks of every routing layer the macro has pins on. + set cons_x [list [list $gate 0]] + set cons_y [list [list $fin 0]] + set layers {} + foreach mterm [$master getMTerms] { + foreach mpin [$mterm getMPins] { + foreach box [$mpin getGeometry] { + set layer [$box getTechLayer] + if { $layer != "NULL" && [$layer getType] == "ROUTING" } { + dict set layers [$layer getName] $layer + } + } + } + } + dict for {name layer} $layers { + set grid [$block findTrackGrid $layer] + if { $grid == "NULL" } { + continue + } + if { [$layer getDirection] == "VERTICAL" } { + for { set i 0 } { $i < [$grid getNumGridPatternsX] } { incr i } { + lassign [$grid getGridPatternX $i] origin count step + lappend cons_x [list $step [expr { 2 * $origin }]] + } + } else { + for { set i 0 } { $i < [$grid getNumGridPatternsY] } { incr i } { + lassign [$grid getGridPatternY $i] origin count step + lappend cons_y [list $step [expr { 2 * $origin }]] + } + } + } + + set loc [$inst getLocation] + set x [asap7_snap_axis [lindex $loc 0] $w $flip_x $cons_x] + set y [asap7_snap_axis [lindex $loc 1] $h $flip_y $cons_y] + if { $x == "" || $y == "" } { + # The tracks disagree with each other or with the fin grid: keep the + # fin and gate grids, which the cells need, and say so. + utl::warn FLW 26 "[$inst getName]: no origin puts both its pins on the\ + tracks and its cells on the fin grid; snapping to the fin grid only." + set x [asap7_snap_axis [lindex $loc 0] $w $flip_x [lrange $cons_x 0 0]] + set y [asap7_snap_axis [lindex $loc 1] $h $flip_y [lrange $cons_y 0 0]] + } + set dx [expr { $x - [lindex $loc 0] }] + set dy [expr { $y - [lindex $loc 1] }] + # The macro placer leaves its macros LOCKED, which setLocation refuses. + set status [$inst getPlacementStatus] + $inst setPlacementStatus PLACED + $inst setLocation $x $y + $inst setPlacementStatus $status + set bbox [$inst getBBox] + if { + [$bbox xMin] < [$core xMin] || [$bbox yMin] < [$core yMin] + || [$bbox xMax] > [$core xMax] || [$bbox yMax] > [$core yMax] + } { + utl::warn FLW 27 "[$inst getName] lies outside the core after snapping." + } + puts "Snapped [$inst getName] ($orient) to the fin grid by\ + ([ord::dbu_to_microns $dx], [ord::dbu_to_microns $dy]) um" + } + + # Snapping moves each macro by under a pitch's worth; make sure that did not + # push one onto another. + foreach a $macros { + foreach b $macros { + if { [$a getName] >= [$b getName] } { + continue + } + set ra [$a getBBox] + set rb [$b getBBox] + if { + [$ra xMin] < [$rb xMax] && [$rb xMin] < [$ra xMax] + && [$ra yMin] < [$rb yMax] && [$rb yMin] < [$ra yMax] + } { + utl::warn FLW 28 "[$a getName] and [$b getName] overlap after snapping." + } + } + } +} + +# The origin nearest `origin` (DBU) along one axis that meets every constraint +# {pitch twice-offset}: origin = 0 (mod pitch) unmirrored, origin + size = +# twice-offset (mod pitch) mirrored. Empty if none does within the lcm. +proc asap7_snap_axis { origin size mirrored cons } { + set period 1 + foreach c $cons { + set period [asap7_lcm $period [lindex $c 0]] + } + for { set d 0 } { $d <= $period } { incr d } { + foreach cand [list [expr { $origin - $d }] [expr { $origin + $d }]] { + set ok 1 + foreach c $cons { + lassign $c pitch twice + set want [expr { $mirrored ? ($twice - $size) % $pitch : 0 }] + if { ($cand - $want) % $pitch != 0 } { + set ok 0 + break + } + } + if { $ok } { + return $cand + } + } + } + return "" +} + +proc asap7_lcm { a b } { + set x $a + set y $b + while { $y != 0 } { + set t [expr { $x % $y }] + set x $y + set y $t + } + return [expr { $a / $x * $b }] +} + +asap7_snap_macros_to_fin_grid From 9f0f23942e63578efdec35041c124ae5309bfb58 Mon Sep 17 00:00:00 2001 From: jeffhsu3 Date: Mon, 12 Oct 2026 12:30:07 -0700 Subject: [PATCH 2/2] asap7: preserve per-axis track alignment when snapping macros Fall back to the gate or fin grid only on the axis with incompatible track constraints. Preserve a valid solution on the other axis and identify the failing axis in the warning. Precompute constraint residues and limit the nearest-origin search to half the repeating grid period. Validation: 5,008 Tcl axis cases match an independent exhaustive solver; nine mocked-database scenarios cover all supported orientations and fallback combinations, including four regressions that fail before this change. tclint 0.7.0, tclfmt, and git diff --check pass. The full physical-design flow was not rerun. Signed-off-by: jeffhsu3 --- .../openRoad/snap_macros_to_fin_grid.tcl | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/flow/platforms/asap7/openRoad/snap_macros_to_fin_grid.tcl b/flow/platforms/asap7/openRoad/snap_macros_to_fin_grid.tcl index 5700a9ec36..160c80e6a3 100644 --- a/flow/platforms/asap7/openRoad/snap_macros_to_fin_grid.tcl +++ b/flow/platforms/asap7/openRoad/snap_macros_to_fin_grid.tcl @@ -79,13 +79,16 @@ proc asap7_snap_macros_to_fin_grid { } { set loc [$inst getLocation] set x [asap7_snap_axis [lindex $loc 0] $w $flip_x $cons_x] + # Keep routing-track alignment on each axis whose constraints agree. + if { $x == "" } { + utl::warn FLW 26 "[$inst getName]: no X origin puts both its pins on the\ + tracks and its cells on the gate grid; snapping to the gate grid only." + set x [asap7_snap_axis [lindex $loc 0] $w $flip_x [lrange $cons_x 0 0]] + } set y [asap7_snap_axis [lindex $loc 1] $h $flip_y $cons_y] - if { $x == "" || $y == "" } { - # The tracks disagree with each other or with the fin grid: keep the - # fin and gate grids, which the cells need, and say so. - utl::warn FLW 26 "[$inst getName]: no origin puts both its pins on the\ + if { $y == "" } { + utl::warn FLW 26 "[$inst getName]: no Y origin puts both its pins on the\ tracks and its cells on the fin grid; snapping to the fin grid only." - set x [asap7_snap_axis [lindex $loc 0] $w $flip_x [lrange $cons_x 0 0]] set y [asap7_snap_axis [lindex $loc 1] $h $flip_y [lrange $cons_y 0 0]] } set dx [expr { $x - [lindex $loc 0] }] @@ -127,18 +130,23 @@ proc asap7_snap_macros_to_fin_grid { } { # The origin nearest `origin` (DBU) along one axis that meets every constraint # {pitch twice-offset}: origin = 0 (mod pitch) unmirrored, origin + size = -# twice-offset (mod pitch) mirrored. Empty if none does within the lcm. +# twice-offset (mod pitch) mirrored. Empty if the constraints are incompatible. proc asap7_snap_axis { origin size mirrored cons } { set period 1 + set prepared_cons {} foreach c $cons { - set period [asap7_lcm $period [lindex $c 0]] + lassign $c pitch twice + set period [asap7_lcm $period $pitch] + set want [expr { $mirrored ? ($twice - $size) % $pitch : 0 }] + lappend prepared_cons [list $pitch $want] } - for { set d 0 } { $d <= $period } { incr d } { + # Valid origins repeat every period, so the nearest is at most half a period away. + set max_d [expr { $period / 2 }] + for { set d 0 } { $d <= $max_d } { incr d } { foreach cand [list [expr { $origin - $d }] [expr { $origin + $d }]] { set ok 1 - foreach c $cons { - lassign $c pitch twice - set want [expr { $mirrored ? ($twice - $size) % $pitch : 0 }] + foreach c $prepared_cons { + lassign $c pitch want if { ($cand - $want) % $pitch != 0 } { set ok 0 break