Skip to content

Commit 8ad8c61

Browse files
authored
Merge pull request #2 from aignacio/synthesis_yosys
Added synthesis / yosys setup
2 parents 97861e7 + cf7d2c5 commit 8ad8c61

File tree

585 files changed

+42335
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

585 files changed

+42335
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ output_temp/
3232
riscof_work/
3333
riscv-arch-test/
3434
*.txt
35+
synth/syn_out

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
[submodule "bus_arch_sv_pkg"]
1111
path = bus_arch_sv_pkg
1212
url = https://github.com/aignacio/bus_arch_sv_pkg.git
13+
[submodule "synth/pdk_45nm"]
14+
path = synth/pdk_45nm
15+
url = https://github.com/The-OpenROAD-Project/OpenROAD-flow-scripts

Dockerfile.nox

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
66
RUN apt-get update && apt-get upgrade -y
77
RUN apt-get install git file gcc make time wget zip -y
88
#[sv2v]
9-
RUN wget https://github.com/zachjs/sv2v/releases/download/v0.0.9/sv2v-Linux.zip
9+
RUN wget https://github.com/zachjs/sv2v/releases/download/v0.0.11/sv2v-Linux.zip
1010
RUN unzip sv2v-Linux.zip && rm sv2v-Linux.zip
1111
RUN ln -s /sv2v-Linux/sv2v /usr/bin/sv2v && chmod +x /sv2v-Linux/sv2v
1212
# [Verilator]

Dockerfile.synlig

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM ubuntu:latest
2+
LABEL author="Anderson Ignacio da Silva"
3+
LABEL maintainer="[email protected]"
4+
ENV TZ=Europe/Dublin
5+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
6+
RUN apt-get update && apt-get upgrade -y
7+
RUN apt-get install git file gcc make time wget zip -y
8+
# Install synlig / Yosys / surelog
9+
RUN apt install -y gcc-11 g++-11 build-essential cmake tclsh ant default-jre swig google-perftools libgoogle-perftools-dev python3 python3-dev python3-pip uuid uuid-dev tcl-dev flex libfl-dev git pkg-config libreadline-dev bison libffi-dev wget python3-orderedmultidict
10+
RUN git clone https://github.com/chipsalliance/synlig.git
11+
WORKDIR /synlig
12+
RUN git submodule sync
13+
RUN git submodule init
14+
ENV GIT_TRACE=1
15+
RUN git submodule update --init --recursive third_party/surelog
16+
RUN git submodule update --init --recursive third_party/yosys
17+
RUN make install
18+
ENV PATH=/synlig/out/release/bin:$PATH
19+
20+
21+

Dockerfile.yosys

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM ubuntu:latest
2+
LABEL author="Anderson Ignacio da Silva"
3+
LABEL maintainer="[email protected]"
4+
ENV TZ=Europe/Dublin
5+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
6+
RUN apt-get update && apt-get upgrade -y
7+
RUN apt-get install git file gcc make time wget zip -y
8+
# OSS CAD suite
9+
RUN wget -c http://github.com/YosysHQ/oss-cad-suite-build/releases/download/2024-04-23/oss-cad-suite-linux-x64-20240423.tgz -O - | tar -xz
10+
ENV PATH="/oss-cad-suite/bin:$PATH"
11+
#[sv2v]
12+
RUN wget https://github.com/zachjs/sv2v/releases/download/v0.0.11/sv2v-Linux.zip
13+
RUN unzip sv2v-Linux.zip && rm sv2v-Linux.zip
14+
RUN ln -s /sv2v-Linux/sv2v /usr/bin/sv2v && chmod +x /sv2v-Linux/sv2v
15+
RUN git clone https://github.com/parallaxsw/OpenSTA.git /opensta
16+
RUN apt-get install cmake build-essential flex bison swig clang expect tcl-dev libeigen3-dev -y
17+
WORKDIR /opensta
18+
RUN mkdir build
19+
RUN cd build && cmake ../
20+
RUN cd build && make -j`nproc`
21+
RUN cd build && make install

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [FreeRTOS](#freertos)
1414
* [Compliance Tests](#compliance)
1515
* [CoreMark](#coremark)
16+
* [Synthesis](#synth)
1617
* [License](#lic)
1718

1819
## <a name="intro"></a> Introduction
@@ -244,7 +245,25 @@ seedcrc : 0x18f2
244245
[0]crcfinal : 0x0cac
245246
Correct operation validated. See README.md for run and reporting rules.
246247
```
248+
## <a name="synth"></a> Synthesis
249+
250+
Adapting the setup to [Ibex Core - low risc](https://github.com/lowRISC/ibex/tree/master/syn), attached is the command to perform synthesis on the 45nm nangate PDK.
251+
```bash
252+
docker run -v .:/test -w /test --rm aignacio/oss_cad_suite:latest bash -c "cd /test/synth && ./syn_yosys.sh"
253+
```
254+
255+
### Area results:
256+
* 27.04 kGE @ 250MHz in 45nm
257+
258+
```bash
259+
...
260+
End of script. Logfile hash: 39230763f8, CPU: user 15.51s system 0.15s, MEM: 175.05 MB peak
261+
Yosys 0.40+25 (git sha1 171577f90, clang++ 14.0.0-1ubuntu1.1 -fPIC -Os)
262+
Time spent: 72% 2416x select (5 sec), 22% 2x read_verilog (1 sec), ...
263+
Area in kGE = 27.04
264+
```
247265
248266
## <a name="lic"></a> License
267+
249268
NoX is licensed under the permissive MIT license. Please refer to the [LICENSE](LICENSE) file for details.
250269

synth/README.md

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
**This synthesis flow is experimental and under development, it does not produce
2+
tape-out quality netlists and area/timing numbers it generates are not
3+
representative of what would be achievable with a tape-out quality flow**
4+
5+
# Yosys/OpenSTA Ibex Synthesis Flow
6+
7+
This is a synthesis-only implementation flow using Yosys for Synthesis and
8+
OpenSTA to produce timing reports. Its outputs are:
9+
10+
* A pre-mapping netlist - Gate-level verilog using generic gates that hasn't
11+
been mapped to a standard-cell library yet
12+
* A post synthesis netlist - Gate-level verilog after optimisation mapped to a
13+
standard-cell library
14+
* An STA netlist - Logically equivilent to the netlist above but with changes to
15+
allow processing by OpenSTA
16+
* Area/Cell Usage report - Total area consumed by utilised cells and counts of
17+
each cell instance used
18+
* Timing reports - Overal timing report and reports broken down into various
19+
path groups (register to register paths and per IO reports)
20+
21+
Yosys doesn't yet support the full subset of SystemVerilog used by Ibex so the
22+
sv2v tool is used to first convert the Ibex RTL into the SystemVerilog subset
23+
Yosys can process.
24+
25+
# Synthesis flow requirements
26+
27+
The following must be installed:
28+
29+
* Python 3 (version >= 3.5)
30+
* sv2v - https://github.com/zachjs/sv2v
31+
* Yosys - https://github.com/YosysHQ/yosys
32+
* OpenSTA - https://github.com/The-OpenROAD-Project/OpenSTA
33+
34+
The flow was tested with yosys 0.9 and OpenSTA 2.2 but may work with other
35+
versions. A standard cell library is also required in the liberty (.lib)
36+
format. The following Open Libraries can be used:
37+
38+
* Nangate45 - https://github.com/The-OpenROAD-Project/OpenROAD-flow/tree/master/flow/platforms/nangate45
39+
40+
# Synthesis flow setup
41+
42+
The synthesis flow is configured via environment variables. The `syn_setup.sh`
43+
file is used to set the environment variables for the flow and any changes made
44+
should be placed there. An example `syn_setup.example.sh` is included. A copy
45+
of this named `syn_setup.sh` must be made and the values in it set appropriately
46+
for the flow to work.
47+
48+
The environment variables that must be set in `syn_setup.sh` are
49+
50+
* `LR_SYNTH_CELL_LIBRARY_PATH` - The path to the standard cell library, this
51+
should point to the absolute path of the Nangate45 library
52+
(`NangateOpenCellLibrary_typical.lib`).
53+
* `LR_SYNTH_CELL_LIBRARY_NAME` - The name of the standard cell library, this is
54+
used to alter the flow configuration for the library, currently 'nangate' is
55+
the only supported value
56+
57+
# Running the synthesis flow
58+
59+
Once `syn_setup.sh` has been created, call `syn_yosys.sh` to run the entire
60+
flow. All outputs are placed under the `syn/syn_out` directory with the prefix
61+
`ibex_` with the current date/time forming the rest of the name, e.g.
62+
`syn/syn_out/ibex_06_01_2020_11_19_15`
63+
64+
- `syn/syn_out/ibex_date`
65+
- `reports` - All of the generated reports
66+
- area.rpt - Total area used and per cell instance counts
67+
- `timing`
68+
- *.rpt - Raw reports from OpenSTA, gives full paths
69+
- *.csv.rpt - CSV reports gives start and end point and slack
70+
- `log`
71+
- syn.log - Log of the Yosys run
72+
- sta.log - Log of the OpenSTA run
73+
- `generated`
74+
- *.v - Ibex RTL after sv2v processing
75+
- ibex_top.pre_map.v - Pre-mapping synthesis netlists
76+
- ibex_top_netlist.v - Post-synthesis netlist
77+
- ibex_top_netlist.sta.v - Post-synthesis netlist usable by OpenSTA
78+
- ibex_top.[library-name].out.sdc - Generated .sdc timing constraints
79+
file
80+
81+
If you wish to change the results directory naming or location edit
82+
`syn_setup.sh` appropriately.
83+
84+
# Timing constraints
85+
86+
Two files specify the timing constraints and timing related settings for the
87+
flow. These are used to generate a single .sdc file
88+
89+
* `ibex_top_lr_synth_core.tcl` - This specifies the constraints on all inputs
90+
and outputs as a fraction of a clock cycle, the names of the clock and reset
91+
inputs and the desired clock period in ps
92+
* `ibex.[library-name].sdc` - Header to include in generated .sdc file. Settings
93+
can be library dependent so the `LR_SYNTH_CELL_LIBRARY_NAME` environment
94+
varible is used to supply the `[library-name]` part of the name
95+
96+
# Timing reports
97+
98+
Timing reports are produced for the following path groups
99+
* Overall - Every path in the design, WNS (worst negative slack) from this report is the design WNS
100+
that limits the frequency
101+
* reg2reg - Paths from register to register
102+
* in2reg - Paths from any input to any register
103+
* reg2out - Paths from any register to any output
104+
* in2out - Paths from any input to any output
105+
106+
They are available in two formats .rpt and .csv.rpt. The .rpt is the full output
107+
from OpenSTA and gives the full path between the start and end points. The CSV
108+
version contains the start-point, end-point and WNS (one path per line). CSV
109+
reports have had their start and end points translated to human readable names
110+
(though this isn't 100% reliable). The raw OpenSTA reports generally contain
111+
only generated cell names so will require further netlist inspection (via Yosys
112+
or simply looking at the netlist .v) to make sense of.
113+
114+
# Post-synthesis inspection
115+
116+
Both Yosys and OpenSTA can be run to perform further inspection on the generated
117+
synthesis. TCL is provided to setup the tools appropriately.
118+
119+
First the environment variables must be setup for the flow and the directory
120+
containing the synthesis output set. This can be done with `syn_setup.sh`
121+
122+
```
123+
$ source syn_setup.sh syn_out_06_01_2020_11_19_15/
124+
```
125+
126+
Where `syn_out_06_01_2020_11_19_15/` is directory containing the synthesis
127+
outputs. Then start Yosys or OpenSTA and run one of the provided TCL files
128+
129+
* `./tcl/yosys_pre_map.tcl` - Loads the pre-mapping netlist
130+
* `./tcl/yosys_post_synth.tcl` - Load the post-synthesis netlist
131+
132+
So to load the post-synthesis netlist in Yosys:
133+
134+
```
135+
$ yosys
136+
yosys> tcl ./tcl/yosys_post_synth.tcl
137+
```
138+
139+
To open the design in OpenSTA
140+
141+
```
142+
$ sta
143+
% source ./tcl/sta_open_design.tcl
144+
```
145+

synth/lec_sv2v.do

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright lowRISC contributors.
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// LEC dofile for script lec_sv2v.sh. A similar script is used in
6+
// OpenTitan, any updates or fixes here may need to be reflected in the
7+
// OpenTitan script as well:
8+
// https://github.com/lowRISC/opentitan/blob/master/hw/formal/lec_sv2v.do
9+
10+
//-------------------------------------------------------------------------
11+
// read in golden (SystemVerilog) and revised (Verilog)
12+
//-------------------------------------------------------------------------
13+
14+
// map all multi-dimensional ports (including structs) onto 1-dim. ports
15+
set naming rule -mdportflatten
16+
17+
read design -golden -sv09 -f flist_gold -rootonly -root $LEC_TOP
18+
read design -revised -sys -f flist_rev -rootonly -root $LEC_TOP
19+
// TODO: instead of using switch -sys (for old SystemVerilog,
20+
// older than sv2009) we should use -ve (for Verilog). But
21+
// this currently doesn't work because sv2v doesn't translate
22+
// .* port connections. Is that an sv2v bug?
23+
24+
//-------------------------------------------------------------------------
25+
// pre-LEC reports
26+
//-------------------------------------------------------------------------
27+
report rule check -verbose
28+
report design data
29+
report black box
30+
report module
31+
32+
//-------------------------------------------------------------------------
33+
// compare
34+
//-------------------------------------------------------------------------
35+
set system mode lec
36+
set parallel option -threads 8
37+
38+
// map unreachable points
39+
set mapping method -nets -mem -unreach
40+
map key points
41+
report unmapped points
42+
43+
add compare point -all
44+
compare -threads 8 -noneq_stop 1
45+
analyze abort -compare
46+
47+
//-------------------------------------------------------------------------
48+
// reports
49+
//-------------------------------------------------------------------------
50+
report compare data -class nonequivalent -class abort -class notcompared
51+
report verification -verbose
52+
report statistics
53+
usage
54+
55+
exit -force

synth/lec_sv2v.sh

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
# Copyright lowRISC contributors.
4+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
5+
# SPDX-License-Identifier: Apache-2.0
6+
7+
# This script converts all SystemVerilog RTL files to Verilog
8+
# using sv2v and then runs LEC (Cadence Conformal) to check if
9+
# the generated Verilog is logically equivalent to the original
10+
# SystemVerilog. A similar script is used in OpenTitan, any updates
11+
# or fixes here may need to be reflected in the OpenTitan script as well
12+
# https://github.com/lowRISC/opentitan/blob/master/util/syn_yosys.sh
13+
#
14+
# The following tools are required:
15+
# - sv2v: SystemVerilog-to-Verilog converter from github.com/zachjs/sv2v
16+
# - Cadence Conformal
17+
#
18+
# Usage:
19+
# ./lec_sv2v.sh |& tee lec.log
20+
21+
#-------------------------------------------------------------------------
22+
# use fusesoc to generate files and file list
23+
#-------------------------------------------------------------------------
24+
rm -Rf build lec_out
25+
fusesoc --cores-root .. run --tool=icarus --target=lint \
26+
--setup "lowrisc:ibex:ibex_top" > /dev/null 2>&1
27+
28+
# copy all files to lec_out
29+
mkdir lec_out
30+
cp build/*/src/*/*.sv build/*/src/*/*/*.sv lec_out
31+
cd lec_out || exit
32+
33+
# copy file list and remove incdir, RVFI define, and sim-file
34+
grep -E -v 'incdir|RVFI|simulator_ctrl' ../build/*/*/*.scr > flist_gold
35+
36+
# remove all hierarchical paths
37+
sed -i 's!.*/!!' flist_gold
38+
39+
# generate revised flist by replacing '.sv' by '.v' and removing packages
40+
sed 's/.sv/.v/' flist_gold | grep -v "_pkg.v" > flist_rev
41+
42+
#-------------------------------------------------------------------------
43+
# convert all RTL files to Verilog using sv2v
44+
#-------------------------------------------------------------------------
45+
printf "\nSV2V ERRORS:\n"
46+
47+
for file in *.sv; do
48+
module=$(basename -s .sv "$file")
49+
sv2v --define=SYNTHESIS ./*_pkg.sv prim_assert.sv "$file" > "${module}".v
50+
done
51+
52+
# remove *pkg.v files (they are empty files and not needed)
53+
rm -f ./*_pkg.v prim_assert.v prim_util_memload.v
54+
55+
# overwrite the prim_clock_gating modules with the module from ../rtl
56+
cp ../rtl/prim_clock_gating.v .
57+
cp ../rtl/prim_clock_gating.v prim_clock_gating.sv
58+
59+
#-------------------------------------------------------------------------
60+
# run LEC (generated Verilog vs. original SystemVerilog)
61+
#-------------------------------------------------------------------------
62+
printf "\n\nLEC RESULTS:\n"
63+
64+
for file in *.v; do
65+
LEC_TOP=$(basename -s .v "$file")
66+
export LEC_TOP
67+
68+
# run Conformal LEC
69+
lec -xl -nogui -nobanner \
70+
-dofile ../lec_sv2v.do \
71+
-logfile lec_"${LEC_TOP}".log \
72+
<<< "exit -force" > /dev/null 2>&1
73+
74+
# summarize results
75+
check=$(grep "Compare Results" lec_"${LEC_TOP}".log)
76+
if [ $? -ne 0 ]; then
77+
result="CRASH"
78+
else
79+
result=$(echo "$check" | awk '{ print $4 }')
80+
fi
81+
printf "%-25s %s\n" "$LEC_TOP" "$result"
82+
done

synth/nox.nangate.sdc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright lowRISC contributors.
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
set_driving_cell [all_inputs] -lib_cell BUF_X2
6+
set_load 10.0 [all_outputs]

synth/nox_abc.nangate.sdc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright lowRISC contributors.
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
set_driving_cell BUF_X2
6+
set_load 10.0 [all_outputs]

0 commit comments

Comments
 (0)