Skip to content

Commit 93fad06

Browse files
Merge pull request #2629 from povik/wrapped-operators
Wrapped operators synthesis flow
2 parents 2f2cf54 + 5f9a9d6 commit 93fad06

File tree

6 files changed

+142
-4
lines changed

6 files changed

+142
-4
lines changed

docs/user/FlowVariables.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ configuration file.
184184
| <a name="SYNTH_HIERARCHICAL"></a>SYNTH_HIERARCHICAL| Enable to Synthesis hierarchically, otherwise considered flat synthesis.| 0| |
185185
| <a name="SYNTH_MEMORY_MAX_BITS"></a>SYNTH_MEMORY_MAX_BITS| Maximum number of bits for memory synthesis.| 4096| |
186186
| <a name="SYNTH_NETLIST_FILES"></a>SYNTH_NETLIST_FILES| Skips synthesis and uses the supplied netlist files. If the netlist files contains duplicate modules, which can happen when using hierarchical synthesis on indvidual netlist files and combining here, subsequent modules are silently ignored and only the first module is used.| | |
187+
| <a name="SYNTH_WRAPPED_OPERATORS"></a>SYNTH_WRAPPED_OPERATORS| Synthesize multiple architectural options for each arithmetic operator in the design. These options are available for switching among in later stages of the flow.| | |
187188
| <a name="TAPCELL_TCL"></a>TAPCELL_TCL| Path to Endcap and Welltie cells file.| | |
188189
| <a name="TAP_CELL_NAME"></a>TAP_CELL_NAME| Name of the cell to use in tap cell insertion.| | |
189190
| <a name="TECH_LEF"></a>TECH_LEF| A technology LEF file of the PDK that includes all relevant information regarding metal layers, vias, and spacing requirements.| | |
@@ -213,6 +214,7 @@ configuration file.
213214
- [SYNTH_HIERARCHICAL](#SYNTH_HIERARCHICAL)
214215
- [SYNTH_MEMORY_MAX_BITS](#SYNTH_MEMORY_MAX_BITS)
215216
- [SYNTH_NETLIST_FILES](#SYNTH_NETLIST_FILES)
217+
- [SYNTH_WRAPPED_OPERATORS](#SYNTH_WRAPPED_OPERATORS)
216218
- [TIEHI_CELL_AND_PORT](#TIEHI_CELL_AND_PORT)
217219
- [TIELO_CELL_AND_PORT](#TIELO_CELL_AND_PORT)
218220
- [VERILOG_FILES](#VERILOG_FILES)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
&st
2+
&dch
3+
&nf
4+
&st
5+
&syn2
6+
&if -g -K 6
7+
&synch2
8+
&nf
9+
&st
10+
&syn2
11+
&if -g -K 6
12+
&synch2
13+
&nf
14+
&st
15+
&syn2
16+
&if -g -K 6
17+
&synch2
18+
&nf
19+
&st
20+
&syn2
21+
&if -g -K 6
22+
&synch2
23+
&nf
24+
&st
25+
&syn2
26+
&if -g -K 6
27+
&synch2
28+
&nf

flow/scripts/synth.tcl

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ if {![env_var_equals SYNTH_HIERARCHICAL 1]} {
3434
json -o $::env(RESULTS_DIR)/mem.json
3535
# Run report and check here so as to fail early if this synthesis run is doomed
3636
exec -- python3 $::env(SCRIPTS_DIR)/mem_dump.py --max-bits $::env(SYNTH_MEMORY_MAX_BITS) $::env(RESULTS_DIR)/mem.json
37-
synth -top $::env(DESIGN_NAME) -run fine: {*}$::env(SYNTH_FULL_ARGS)
37+
38+
if {![env_var_exists_and_non_empty SYNTH_WRAPPED_OPERATORS]} {
39+
synth -top $::env(DESIGN_NAME) -run fine: {*}$::env(SYNTH_FULL_ARGS)
40+
} else {
41+
source $::env(SCRIPTS_DIR)/synth_wrap_operators.tcl
42+
}
43+
3844
# Get rid of indigestibles
3945
chformal -remove
4046

@@ -76,7 +82,15 @@ if {[env_var_exists_and_non_empty DFF_LIB_FILE]} {
7682
}
7783
opt
7884

79-
log_cmd abc {*}$abc_args
85+
if {![env_var_exists_and_non_empty SYNTH_WRAPPED_OPERATORS]} {
86+
log_cmd abc {*}$abc_args
87+
} else {
88+
scratchpad -set abc9.script scripts/abc_speed_gia_only.script
89+
# crop out -script from arguments
90+
set abc_args [lrange $abc_args 2 end]
91+
log_cmd abc_new {*}$abc_args
92+
delete {t:$specify*}
93+
}
8094

8195
# Replace undef values with defined constants
8296
setundef -zero
@@ -101,10 +115,17 @@ tee -o $::env(REPORTS_DIR)/synth_check.txt check
101115
tee -o $::env(REPORTS_DIR)/synth_stat.txt stat {*}$stat_libs
102116

103117
# check the design is composed exclusively of target cells, and check for other problems
104-
check -assert -mapped
118+
if {![env_var_exists_and_non_empty SYNTH_WRAPPED_OPERATORS]} {
119+
check -assert -mapped
120+
} else {
121+
# Wrapped operator synthesis leaves around $buf cells which `check -mapped`
122+
# gets confused by, once Yosys#4931 is merged we can remove this branch and
123+
# always run `check -assert -mapped`
124+
check -assert
125+
}
105126

106127
# Write synthesized design
107-
write_verilog -noexpr -nohex -nodec $::env(RESULTS_DIR)/1_1_yosys.v
128+
write_verilog -nohex -nodec $::env(RESULTS_DIR)/1_1_yosys.v
108129
# One day a more sophisticated synthesis will write out a modified
109130
# .sdc file after synthesis. For now, just copy the input .sdc file,
110131
# making synthesis more consistent with other stages.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(* techmap_wrap = "booth" *)
2+
(* techmap_celltype = "$macc" *)
3+
module _70_macc;
4+
endmodule
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
set deferred_cells {
2+
{
3+
\$alu
4+
ALU_{A_WIDTH}_{A_SIGNED}_{B_WIDTH}_{B_SIGNED}_{Y_WIDTH}{%unused}
5+
{HAN_CARLSON -map +/choices/han-carlson.v}
6+
{KOGGE_STONE -map +/choices/kogge-stone.v}
7+
{SKLANSKY -map +/choices/sklansky.v}
8+
{BRENT_KUNG}
9+
}
10+
{
11+
\$macc
12+
MACC_{CONFIG}_{Y_WIDTH}{%unused}
13+
{BASE -map +/choices/han-carlson.v}
14+
{BOOTH -max_iter 1 -map ../flow/scripts/synth_wrap_operators-booth.v}
15+
}
16+
}
17+
18+
techmap {*}[join [lmap cell $deferred_cells {string cat "-dont_map [lindex $cell 0]"}] " "]
19+
20+
foreach info $deferred_cells {
21+
set type [lindex $info 0]
22+
set naming_template [lindex $info 1]
23+
# default architecture and its suffix
24+
set default [lindex $info 2]
25+
set default_suffix [lindex $default 0]
26+
27+
log -header "Generating architectural options for $type"
28+
log -push
29+
30+
wrapcell \
31+
-setattr arithmetic_operator \
32+
-setattr copy_pending \
33+
-formatattr implements_operator $naming_template \
34+
-formatattr architecture $default_suffix \
35+
-formatattr source_cell $type \
36+
-name ${naming_template}_${default_suffix} \
37+
t:$type r:A_WIDTH>=10 r:Y_WIDTH>=14 %i %i
38+
39+
# make per-architecture copies of the unmapped module
40+
foreach modname [tee -q -s result.string select -list-mod A:arithmetic_operator A:copy_pending %i] {
41+
setattr -mod -unset copy_pending $modname
42+
43+
# iterate over non-default architectures
44+
foreach arch [lrange $info 3 end] {
45+
set suffix [lindex $arch 0]
46+
set base [rtlil::get_attr -string -mod $modname implements_operator]
47+
set newname ${base}_${suffix}
48+
yosys copy $modname $newname
49+
yosys setattr -mod -set architecture \"$suffix\" $newname
50+
}
51+
}
52+
53+
# iterate over all architectures, both the default and non-default
54+
foreach arch [lrange $info 2 end] {
55+
set suffix [lindex $arch 0]
56+
set extra_map_args [lrange $arch 1 end]
57+
58+
# map all operator copies which were selected to have this architecture
59+
techmap -map +/techmap.v {*}$extra_map_args A:source_cell=$type A:architecture=$suffix %i
60+
61+
# booth isn't able to map all $macc configurations: catch if this is one
62+
# of those and delete the option
63+
delete A:source_cell=$type A:architecture=$suffix %i t:\$macc %m %i
64+
}
65+
66+
log -pop
67+
}
68+
69+
opt -fast -full
70+
memory_map
71+
opt -full
72+
# Get rid of indigestibles
73+
chformal -remove
74+
setattr -mod -set abc9_script {"+&dch;&nf -R 5;"} A:arithmetic_operator
75+
setattr -mod -set abc9_box 1 A:arithmetic_operator
76+
techmap -map +/techmap.v -map +/choices/han-carlson.v

flow/scripts/variables.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ MAX_UNGROUP_SIZE:
239239
platform's standard cell library. The default value is platform specific.
240240
stages:
241241
- synth
242+
SYNTH_WRAPPED_OPERATORS:
243+
description: >
244+
Synthesize multiple architectural options for each arithmetic operator in the
245+
design. These options are available for switching among in later stages of
246+
the flow.
247+
stages:
248+
- synth
242249
FLOORPLAN_DEF:
243250
description: |
244251
Use the DEF file to initialize floorplan.

0 commit comments

Comments
 (0)