From 8224c2959adc49a459a58e6d6a5a9f3a4ec18aba Mon Sep 17 00:00:00 2001 From: Daniel Van Blerkom Date: Sat, 24 Oct 2026 19:55:50 -0400 Subject: [PATCH 1/2] synth: SYNTH_ABC_PARTITION, one abc call per register group Co-Authored-By: Claude Opus 5.5 Signed-off-by: Daniel Van Blerkom --- docs/user/FlowVariables.md | 2 + flow/scripts/synth.tcl | 7 ++- flow/scripts/synth_abc_partition.tcl | 65 ++++++++++++++++++++++++++++ flow/scripts/variables.json | 7 +++ flow/scripts/variables.yaml | 12 +++++ 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 flow/scripts/synth_abc_partition.tcl diff --git a/docs/user/FlowVariables.md b/docs/user/FlowVariables.md index 8d32a9d6ad..c7e983274d 100644 --- a/docs/user/FlowVariables.md +++ b/docs/user/FlowVariables.md @@ -294,6 +294,7 @@ configuration file. | SKIP_VT_SWAP| Do not perform VT swap to improve QoR (default: do VT swap).| | | SLEW_MARGIN| Specifies a slew margin when fixing max slew violations. This option allows you to overfix.| | | SWAP_ARITH_OPERATORS| Improve timing QoR by swapping ALU and MULT arithmetic operators.| 0| +| SYNTH_ABC_PARTITION| Map the top module with one abc call per register group instead of one for the whole module, so that each group is optimised against its own critical delay rather than the module's (abc area-recovers every cone that is faster than its single critical path). Flops are grouped by name; the value is the minimum cone size, in cells, for a group to get its own call. 0 disables. Ignored when SYNTH_WRAPPED_OPERATORS or SWAP_ARITH_OPERATORS is set.| 0| | SYNTH_ARGS| Optional synthesis variables for yosys.| | | SYNTH_BLACKBOXES| List of cells treated as a black box by Yosys. With Bazel, this can be used to run synthesis in parallel for the large modules of the design. Non-existant modules are ignored silently, useful when listing modules statically, even if modules come and go dynamically.| | | SYNTH_CANONICALIZE_TCL| Specifies a Tcl script with commands to run as part of the synth canonicalize step.| | @@ -364,6 +365,7 @@ configuration file. - [SDC_FILE](#SDC_FILE) - [SEC_CHECK](#SEC_CHECK) - [SKIP_REPORT_METRICS](#SKIP_REPORT_METRICS) +- [SYNTH_ABC_PARTITION](#SYNTH_ABC_PARTITION) - [SYNTH_ARGS](#SYNTH_ARGS) - [SYNTH_BLACKBOXES](#SYNTH_BLACKBOXES) - [SYNTH_CANONICALIZE_TCL](#SYNTH_CANONICALIZE_TCL) diff --git a/flow/scripts/synth.tcl b/flow/scripts/synth.tcl index aa4d3afb6c..e8c95933c5 100644 --- a/flow/scripts/synth.tcl +++ b/flow/scripts/synth.tcl @@ -282,7 +282,12 @@ if { ![env_var_equals SYNTH_WRAPPED_OPERATORS 1] && ![env_var_equals SWAP_ARITH_OPERATORS 1] } { - log_cmd abc {*}$abc_args + if { [env_var_exists_and_non_empty SYNTH_ABC_PARTITION] && $::env(SYNTH_ABC_PARTITION) > 0 } { + source $::env(SCRIPTS_DIR)/synth_abc_partition.tcl + synth_abc_partition $abc_args $::env(SYNTH_ABC_PARTITION) + } else { + log_cmd abc {*}$abc_args + } } else { # Not dead code: abc_new mistakes the "-script" in /OpenROAD-flow-scripts/... # paths for a given -script and drops its default (YosysHQ/yosys#6320). diff --git a/flow/scripts/synth_abc_partition.tcl b/flow/scripts/synth_abc_partition.tcl new file mode 100644 index 0000000000..4ff876d300 --- /dev/null +++ b/flow/scripts/synth_abc_partition.tcl @@ -0,0 +1,65 @@ +# Technology mapping with one abc call per register group +# (SYNTH_ABC_PARTITION). +# +# abc maps a netlist against a single delay target, the netlist's own +# critical path, and recovers area on every cone that is faster than that. +# A cone that is not the deepest one in the module is rebuilt smaller and +# slower, even when it limits the design. Mapping each register group +# separately gives every group its own critical path. +# +# Flops (liberty cells after dfflibmap) are grouped by name with bit indices +# and the "$_DFF..." suffix removed. A group's cone is the still-unmapped +# combinational fan-in of its flops' inputs. Groups are mapped largest cone +# first; logic shared by several groups goes to the first group that +# reaches it. Groups with fewer than min_cells unmapped cells, and anything +# left over, are mapped by one final abc call. +proc synth_abc_partition { abc_args min_cells } { + set top $::env(DESIGN_NAME) + set groups [dict create] + foreach cell [tee -q -s result.string select -list "$top/t:*" "$top/t:\$*" %d] { + set name [string range $cell [string length "$top/"] end] + regsub {\$_.*$} $name {} key + regsub -all {\[[0-9]+\]} $key {} key + if { $key ne "" } { + dict incr groups $key + } + } + + # '?' stands for the '[' or '$' after the base name; groups whose name + # extends this one (acc vs. acc_next) are removed from the selection. + set keys [dict keys $groups] + set sized {} + foreach key $keys { + set sel [list "$top/$key?*"] + foreach other $keys { + if { $other ne $key && [string match "$key*" $other] } { + lappend sel "$top/$other?*" %d + } + } + select -set abc_partition_group {*}$sel + # select -count returns " objects." + regexp {[0-9]+} [tee -q -s result.string select -count \ + @abc_partition_group %ci1 %cie* "$top/t:\$_*" %i] n + lappend sized [list $key $n $sel] + } + + set i 0 + foreach group [lsort -integer -decreasing -index 1 $sized] { + lassign $group key n sel + if { $n < $min_cells } { + continue + } + select -set abc_partition_group {*}$sel + select -set abc_partition_cone \ + @abc_partition_group %ci1 %cie* "$top/t:\$_*" %i + regexp {[0-9]+} [tee -q -s result.string select -count @abc_partition_cone] left + if { $left < $min_cells } { + continue + } + puts "abc partition [incr i]: $key, $left cells" + log_cmd abc {*}$abc_args @abc_partition_cone + } + puts "abc partition: remaining logic" + log_cmd abc {*}$abc_args "t:\$_*" + select -clear +} diff --git a/flow/scripts/variables.json b/flow/scripts/variables.json index 2810d1ec80..77711a2140 100644 --- a/flow/scripts/variables.json +++ b/flow/scripts/variables.json @@ -1286,6 +1286,13 @@ ], "tunable": 1 }, + "SYNTH_ABC_PARTITION": { + "default": 0, + "description": "Map the top module with one abc call per register group instead of one\nfor the whole module, so that each group is optimised against its own\ncritical delay rather than the module's (abc area-recovers every cone\nthat is faster than its single critical path). Flops are grouped by\nname; the value is the minimum cone size, in cells, for a group to get\nits own call. 0 disables. Ignored when SYNTH_WRAPPED_OPERATORS or\nSWAP_ARITH_OPERATORS is set.\n", + "stages": [ + "synth" + ] + }, "SYNTH_ARGS": { "description": "Optional synthesis variables for yosys.\n", "stages": [ diff --git a/flow/scripts/variables.yaml b/flow/scripts/variables.yaml index 4d71623a35..34c84f879e 100644 --- a/flow/scripts/variables.yaml +++ b/flow/scripts/variables.yaml @@ -1070,6 +1070,18 @@ ABC_AREA: stages: - synth default: 0 +SYNTH_ABC_PARTITION: + description: | + Map the top module with one abc call per register group instead of one + for the whole module, so that each group is optimised against its own + critical delay rather than the module's (abc area-recovers every cone + that is faster than its single critical path). Flops are grouped by + name; the value is the minimum cone size, in cells, for a group to get + its own call. 0 disables. Ignored when SYNTH_WRAPPED_OPERATORS or + SWAP_ARITH_OPERATORS is set. + stages: + - synth + default: 0 ABC_SCRIPT: description: | Replaces the ABC script synthesis runs, so that a design can vendor and From 19498f6455b7ef238911f861aa2248c131c0b866 Mon Sep 17 00:00:00 2001 From: Daniel Van Blerkom Date: Mon, 26 Oct 2026 23:01:01 -0400 Subject: [PATCH 2/2] synth: SYNTH_ABC_PARTITION: review fixes, corrected explanation - Initialize n and left before regexp, so a failed match cannot reuse the previous group's count. - Declare the variable as type int. - Explain the effect as ABC lacking timing context (no SDC, no arrival times at cells mapped before it, such as extract_fa's adders), which can make the critical path it maps against the wrong one. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Daniel Van Blerkom --- docs/user/FlowVariables.md | 2 +- flow/scripts/synth_abc_partition.tcl | 9 ++++++--- flow/scripts/variables.json | 5 +++-- flow/scripts/variables.yaml | 15 +++++++++------ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/docs/user/FlowVariables.md b/docs/user/FlowVariables.md index c7e983274d..1653e499dc 100644 --- a/docs/user/FlowVariables.md +++ b/docs/user/FlowVariables.md @@ -294,7 +294,7 @@ configuration file. | SKIP_VT_SWAP| Do not perform VT swap to improve QoR (default: do VT swap).| | | SLEW_MARGIN| Specifies a slew margin when fixing max slew violations. This option allows you to overfix.| | | SWAP_ARITH_OPERATORS| Improve timing QoR by swapping ALU and MULT arithmetic operators.| 0| -| SYNTH_ABC_PARTITION| Map the top module with one abc call per register group instead of one for the whole module, so that each group is optimised against its own critical delay rather than the module's (abc area-recovers every cone that is faster than its single critical path). Flops are grouped by name; the value is the minimum cone size, in cells, for a group to get its own call. 0 disables. Ignored when SYNTH_WRAPPED_OPERATORS or SWAP_ARITH_OPERATORS is set.| 0| +| SYNTH_ABC_PARTITION| Map the top module with one abc call per register group instead of one for the whole module. abc maps each call against that call's own critical path and sees neither the SDC (clocks, false paths) nor the arrival times at cells mapped before it, such as extract_fa's adders. When that critical path is the wrong one, the real cones are area-recovered into slow structures; separate calls limit this to one group. Flops are grouped by name; the value is the minimum cone size, in cells, for a group to get its own call. 0 disables. Ignored when SYNTH_WRAPPED_OPERATORS or SWAP_ARITH_OPERATORS is set.| 0| | SYNTH_ARGS| Optional synthesis variables for yosys.| | | SYNTH_BLACKBOXES| List of cells treated as a black box by Yosys. With Bazel, this can be used to run synthesis in parallel for the large modules of the design. Non-existant modules are ignored silently, useful when listing modules statically, even if modules come and go dynamically.| | | SYNTH_CANONICALIZE_TCL| Specifies a Tcl script with commands to run as part of the synth canonicalize step.| | diff --git a/flow/scripts/synth_abc_partition.tcl b/flow/scripts/synth_abc_partition.tcl index 4ff876d300..e4d9fd2e75 100644 --- a/flow/scripts/synth_abc_partition.tcl +++ b/flow/scripts/synth_abc_partition.tcl @@ -3,9 +3,10 @@ # # abc maps a netlist against a single delay target, the netlist's own # critical path, and recovers area on every cone that is faster than that. -# A cone that is not the deepest one in the module is rebuilt smaller and -# slower, even when it limits the design. Mapping each register group -# separately gives every group its own critical path. +# It sees no SDC and no arrival times at cells mapped before it (extract_fa's +# adders), so that critical path can be a false path, or shorter than the +# real one; the real cones are then rebuilt smaller and slower. Mapping each +# register group separately gives every group its own critical path. # # Flops (liberty cells after dfflibmap) are grouped by name with bit indices # and the "$_DFF..." suffix removed. A group's cone is the still-unmapped @@ -38,6 +39,7 @@ proc synth_abc_partition { abc_args min_cells } { } select -set abc_partition_group {*}$sel # select -count returns " objects." + set n 0 regexp {[0-9]+} [tee -q -s result.string select -count \ @abc_partition_group %ci1 %cie* "$top/t:\$_*" %i] n lappend sized [list $key $n $sel] @@ -52,6 +54,7 @@ proc synth_abc_partition { abc_args min_cells } { select -set abc_partition_group {*}$sel select -set abc_partition_cone \ @abc_partition_group %ci1 %cie* "$top/t:\$_*" %i + set left 0 regexp {[0-9]+} [tee -q -s result.string select -count @abc_partition_cone] left if { $left < $min_cells } { continue diff --git a/flow/scripts/variables.json b/flow/scripts/variables.json index 77711a2140..7feb0c4518 100644 --- a/flow/scripts/variables.json +++ b/flow/scripts/variables.json @@ -1288,10 +1288,11 @@ }, "SYNTH_ABC_PARTITION": { "default": 0, - "description": "Map the top module with one abc call per register group instead of one\nfor the whole module, so that each group is optimised against its own\ncritical delay rather than the module's (abc area-recovers every cone\nthat is faster than its single critical path). Flops are grouped by\nname; the value is the minimum cone size, in cells, for a group to get\nits own call. 0 disables. Ignored when SYNTH_WRAPPED_OPERATORS or\nSWAP_ARITH_OPERATORS is set.\n", + "description": "Map the top module with one abc call per register group instead of one\nfor the whole module. abc maps each call against that call's own\ncritical path and sees neither the SDC (clocks, false paths) nor the\narrival times at cells mapped before it, such as extract_fa's adders.\nWhen that critical path is the wrong one, the real cones are\narea-recovered into slow structures; separate calls limit this to one\ngroup. Flops are grouped by name; the value is the minimum cone size,\nin cells, for a group to get its own call. 0 disables. Ignored when\nSYNTH_WRAPPED_OPERATORS or SWAP_ARITH_OPERATORS is set.\n", "stages": [ "synth" - ] + ], + "type": "int" }, "SYNTH_ARGS": { "description": "Optional synthesis variables for yosys.\n", diff --git a/flow/scripts/variables.yaml b/flow/scripts/variables.yaml index 34c84f879e..26acccb09d 100644 --- a/flow/scripts/variables.yaml +++ b/flow/scripts/variables.yaml @@ -1073,12 +1073,15 @@ ABC_AREA: SYNTH_ABC_PARTITION: description: | Map the top module with one abc call per register group instead of one - for the whole module, so that each group is optimised against its own - critical delay rather than the module's (abc area-recovers every cone - that is faster than its single critical path). Flops are grouped by - name; the value is the minimum cone size, in cells, for a group to get - its own call. 0 disables. Ignored when SYNTH_WRAPPED_OPERATORS or - SWAP_ARITH_OPERATORS is set. + for the whole module. abc maps each call against that call's own + critical path and sees neither the SDC (clocks, false paths) nor the + arrival times at cells mapped before it, such as extract_fa's adders. + When that critical path is the wrong one, the real cones are + area-recovered into slow structures; separate calls limit this to one + group. Flops are grouped by name; the value is the minimum cone size, + in cells, for a group to get its own call. 0 disables. Ignored when + SYNTH_WRAPPED_OPERATORS or SWAP_ARITH_OPERATORS is set. + type: int stages: - synth default: 0