Skip to content

Commit 4577332

Browse files
synth: add opt-in ABC_USE_CLOCK_PERIOD to give ABC a delay target
synth_preamble.tcl passes ABC_CLOCK_PERIOD_IN_PS to Yosys as "abc -script <file> ... -D <period>", but Yosys hands -D to ABC only through the {D} placeholder of its built-in scripts and of inline ("-script +...") scripts. For a script file it just emits "source <file>", so the period never reaches ABC and the synthesized netlist does not depend on the clock. In addition, since 8ce4ee1 the default taken from the SDC is no longer converted from ns to ps on nangate45, sky130hd, sky130hs and gf180. Add ABC_USE_CLOCK_PERIOD, default 0. When it is 1: - the selected ABC script (abc_speed.script or abc_area.script) is passed inline, with {D} appended to its &nf, map, upsize and dnsize commands, so that Yosys substitutes "-D <ABC_CLOCK_PERIOD_IN_PS>"; - a default ABC_CLOCK_PERIOD_IN_PS read from SDC_FILE is converted to ps with the time_unit of the first liberty file. A value set on the command line or in a platform or design config is taken as ps, so ihp-sg13g2, which converts in its config.mk, is not converted twice; - synthesis stops with an error if no period is available, and the abc_new branch prints a warning that the setting has no effect there. With the default of 0 nothing changes: the abc arguments, clock_period.txt and the synthesized netlists are the same as before. Correct the description of ABC_CLOCK_PERIOD_IN_PS, which is not used by STA, document ABC_USE_CLOCK_PERIOD, and regenerate variables.json and FlowVariables.md. Signed-off-by: Zheng Zhang <zz13240206005@gmail.com>
1 parent a12d469 commit 4577332

6 files changed

Lines changed: 72 additions & 4 deletions

File tree

‎docs/user/FlowVariables.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ configuration file.
9191
| Variable | Description | Default |
9292
| --- | --- | --- |
9393
| <a name="ABC_AREA"></a>ABC_AREA| Strategies for Yosys ABC synthesis: Area/Speed. Default ABC_SPEED.| 0|
94-
| <a name="ABC_CLOCK_PERIOD_IN_PS"></a>ABC_CLOCK_PERIOD_IN_PS| Clock period to be used by STA during synthesis. Default value read from `constraint.sdc`.| |
94+
| <a name="ABC_CLOCK_PERIOD_IN_PS"></a>ABC_CLOCK_PERIOD_IN_PS| Clock period in ps that synthesis passes to ABC as its delay target (`abc -D`). Yosys ignores `abc -D` for the ABC script files used by ORFS, so the value affects the netlist only when `ABC_USE_CLOCK_PERIOD` is 1. By default it is the first `clk_period` or `-period` value in `SDC_FILE`. When `ABC_USE_CLOCK_PERIOD` is 1, that value is converted to ps with the `time_unit` of the first liberty file; otherwise it is used as written, which is ns on nangate45, sky130hd, sky130hs and gf180. ihp-sg13g2 sets its own default in ps.| |
9595
| <a name="ABC_DRIVER_CELL"></a>ABC_DRIVER_CELL| Default driver cell used during ABC synthesis.| |
9696
| <a name="ABC_LOAD_IN_FF"></a>ABC_LOAD_IN_FF| During synthesis set_load value used.| |
97+
| <a name="ABC_USE_CLOCK_PERIOD"></a>ABC_USE_CLOCK_PERIOD| Use `ABC_CLOCK_PERIOD_IN_PS` as the delay target of ABC technology mapping. When set to 1, the ABC script is passed to Yosys inline with the delay target on its `&nf`, `map`, `upsize` and `dnsize` commands, and a default `ABC_CLOCK_PERIOD_IN_PS` read from `SDC_FILE` is converted to ps using the `time_unit` of the first liberty file. This changes the synthesized netlist. It has no effect with `SYNTH_WRAPPED_OPERATORS`, `SWAP_ARITH_OPERATORS` (abc_new) or `SYNTH_USE_SYN`.| 0|
9798
| <a name="ABSTRACT_SOURCE"></a>ABSTRACT_SOURCE| Which .odb file to use to create abstract| |
9899
| <a name="ADDER_MAP_FILE"></a>ADDER_MAP_FILE| Optional mapping file supplied to Yosys to map adders| |
99100
| <a name="ADDITIONAL_FILES"></a>ADDITIONAL_FILES| Additional files to be added to `make issue` archive.| |
@@ -345,6 +346,7 @@ configuration file.
345346
- [ABC_CLOCK_PERIOD_IN_PS](#ABC_CLOCK_PERIOD_IN_PS)
346347
- [ABC_DRIVER_CELL](#ABC_DRIVER_CELL)
347348
- [ABC_LOAD_IN_FF](#ABC_LOAD_IN_FF)
349+
- [ABC_USE_CLOCK_PERIOD](#ABC_USE_CLOCK_PERIOD)
348350
- [ADDER_MAP_FILE](#ADDER_MAP_FILE)
349351
- [ADDITIONAL_MEMORIES](#ADDITIONAL_MEMORIES)
350352
- [CACHED_REPORTS](#CACHED_REPORTS)

‎flow/scripts/synth.tcl‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ if {
284284
} {
285285
log_cmd abc {*}$abc_args
286286
} else {
287+
if { [env_var_equals ABC_USE_CLOCK_PERIOD 1] } {
288+
puts "Warning: ABC_USE_CLOCK_PERIOD has no effect with abc_new\
289+
(SYNTH_WRAPPED_OPERATORS or SWAP_ARITH_OPERATORS)."
290+
}
287291
scratchpad -set abc9.script $::env(SCRIPTS_DIR)/abc_speed_gia_only.script
288292
# crop out -script from arguments
289293
set abc_args [lrange $abc_args 2 end]

‎flow/scripts/synth_preamble.tcl‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,27 @@ if { [env_var_exists_and_non_empty DONT_USE_CELLS] } {
212212
}
213213
}
214214

215+
# "abc -D" reaches ABC only through the {D} placeholder, which Yosys fills in
216+
# for its built-in scripts and for inline "-script +cmd; cmd; ..." scripts,
217+
# but not for "-script <file>". With ABC_USE_CLOCK_PERIOD=1, pass the script
218+
# inline and add {D} to the commands that take a delay target.
219+
if { [env_var_equals ABC_USE_CLOCK_PERIOD 1] } {
220+
set fp [open $abc_script r]
221+
set abc_commands {}
222+
foreach cmd [split [read $fp] "\n;"] {
223+
set cmd [string trim $cmd]
224+
if { $cmd == "" || [string index $cmd 0] == "#" } {
225+
continue
226+
}
227+
if { [regexp {^(&nf|map|upsize|dnsize)(\s|$)} $cmd] } {
228+
append cmd " {D}"
229+
}
230+
lappend abc_commands $cmd
231+
}
232+
close $fp
233+
set abc_script "+[join $abc_commands {; }]"
234+
}
235+
215236
# Technology mapping for cells
216237
set abc_args [list -script $abc_script \
217238
{*}$lib_args {*}$lib_dont_use_args -constr $::env(OBJECTS_DIR)/abc.constr]
@@ -227,6 +248,10 @@ if { [env_var_exists_and_non_empty SDC_FILE_CLOCK_PERIOD] } {
227248
close $fp
228249
}
229250

251+
if { [env_var_equals ABC_USE_CLOCK_PERIOD 1] && "-D" ni $abc_args } {
252+
error "ABC_USE_CLOCK_PERIOD=1, but ABC_CLOCK_PERIOD_IN_PS is empty."
253+
}
254+
230255
set constr [open $::env(OBJECTS_DIR)/abc.constr w]
231256
puts $constr "set_driving_cell $::env(ABC_DRIVER_CELL)"
232257
puts $constr "set_load $::env(ABC_LOAD_IN_FF)"

‎flow/scripts/variables.json‎

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flow/scripts/variables.mk‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,18 @@ export COMMAND_LINE_ARGS := $(foreach V,$(.VARIABLES),$(if $(filter command% lin
218218
ifeq ($(origin ABC_CLOCK_PERIOD_IN_PS), undefined)
219219
ifneq ($(wildcard $(SDC_FILE)),)
220220
export ABC_CLOCK_PERIOD_IN_PS := $(shell sed -nE "s/^set\s+clk_period\s+(\S+).*|.*-period\s+(\S+).*/\1\2/p" $(SDC_FILE) | head -1 | awk '{print $$1}')
221+
ifeq ($(ABC_USE_CLOCK_PERIOD),1)
222+
# The SDC period is in the library time unit, ABC wants ps: scale it
223+
# by the time_unit of the first liberty file, e.g. "1ns" -> 1000.
224+
export ABC_CLOCK_PERIOD_IN_PS := $(shell gzip -dcf $(firstword $(LIB_FILES)) 2>/dev/null | \
225+
awk -v p=$(ABC_CLOCK_PERIOD_IN_PS) '/^[ \t]*time_unit[ \t]*:/ { \
226+
if (p != "" && match($$0, /[0-9.]+[ \t]*[pnu]s/)) { \
227+
u = substr($$0, RSTART, RLENGTH); \
228+
print p * u * (u ~ /ps/ ? 1 : u ~ /ns/ ? 1000 : 1000000) \
229+
} \
230+
exit \
231+
}')
232+
endif
221233
endif
222234
endif
223235

‎flow/scripts/variables.yaml‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,28 @@ MIN_BUF_CELL_AND_PORTS:
439439
- synth
440440
ABC_CLOCK_PERIOD_IN_PS:
441441
description: >
442-
Clock period to be used by STA during synthesis. Default value read from
443-
`constraint.sdc`.
442+
Clock period in ps that synthesis passes to ABC as its delay target
443+
(`abc -D`). Yosys ignores `abc -D` for the ABC script files used by
444+
ORFS, so the value affects the netlist only when `ABC_USE_CLOCK_PERIOD`
445+
is 1. By default it is the first `clk_period` or `-period` value in
446+
`SDC_FILE`. When `ABC_USE_CLOCK_PERIOD` is 1, that value is converted to
447+
ps with the `time_unit` of the first liberty file; otherwise it is used
448+
as written, which is ns on nangate45, sky130hd, sky130hs and gf180.
449+
ihp-sg13g2 sets its own default in ps.
444450
stages:
445451
- synth
452+
ABC_USE_CLOCK_PERIOD:
453+
description: >
454+
Use `ABC_CLOCK_PERIOD_IN_PS` as the delay target of ABC technology
455+
mapping. When set to 1, the ABC script is passed to Yosys inline with the
456+
delay target on its `&nf`, `map`, `upsize` and `dnsize` commands, and a
457+
default `ABC_CLOCK_PERIOD_IN_PS` read from `SDC_FILE` is converted to ps
458+
using the `time_unit` of the first liberty file. This changes the
459+
synthesized netlist. It has no effect with `SYNTH_WRAPPED_OPERATORS`,
460+
`SWAP_ARITH_OPERATORS` (abc_new) or `SYNTH_USE_SYN`.
461+
stages:
462+
- synth
463+
default: 0
446464
ABC_DRIVER_CELL:
447465
description: |
448466
Default driver cell used during ABC synthesis.

0 commit comments

Comments
 (0)