Skip to content

Commit a1e2e83

Browse files
committed
wip: yosys-synlig
1 parent bf244d5 commit a1e2e83

File tree

8 files changed

+110
-51
lines changed

8 files changed

+110
-51
lines changed

flake.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
description = "Environment for developing and simulating the ibex core.";
33

44
inputs = {
5+
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
56
# The input 'lowrisc-nix' contains some common dependencies that can be used
67
# by lowRISC projects. There is also an associated public binary cache.
78
lowrisc-nix.url = "github:lowRISC/lowrisc-nix";
@@ -34,6 +35,13 @@
3435
};
3536
};
3637

38+
pkgs-unstable = import inputs.nixpkgs-unstable {
39+
inherit system;
40+
config = {
41+
allowUnfree = true;
42+
};
43+
};
44+
3745
# This import creates internal-use only outputs, which build on
3846
# input attributes that cannot be fetched without appropriate credentials.
3947
lr = import ./nix/lowrisc.nix {
@@ -85,7 +93,7 @@
8593
srecord
8694
]);
8795

88-
ibex_syn = import ./nix/syn.nix {inherit inputs pkgs;};
96+
ibex_syn = import ./nix/syn.nix {inherit inputs pkgs pkgs-unstable;};
8997

9098
################
9199
# ENVIRONMENTS #

nix/syn.nix

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
{
88
inputs,
99
pkgs,
10+
pkgs-unstable,
1011
...
1112
}: let
1213

13-
sv2v_local = import ./sv2v.nix {inherit inputs pkgs;};
14-
15-
ibex_syn_deps = [
16-
sv2v_local.default
17-
] ++ (with pkgs; [
18-
# haskellPackages.sv2v # broken
19-
yosys
14+
ibex_syn_deps = (with pkgs; [
15+
pkgs-unstable.yosys
16+
pkgs-unstable.yosys-synlig
2017
openroad
2118
]);
2219

@@ -42,6 +39,7 @@
4239
ibex_syn_profile = ''
4340
export LR_SYNTH_CELL_LIBRARY_NAME=nangate
4441
export LR_SYNTH_CELL_LIBRARY_PATH=${nangate45}/lib/NangateOpenCellLibrary_typical.lib
42+
export LR_SYNTH_SYNLIG_PLUGIN_PATH=${pkgs-unstable.yosys-synlig}/share/yosys/plugins/systemverilog.so
4543
'';
4644

4745
in {

rtl/ibex_top.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module ibex_top import ibex_pkg::*; #(
2121
parameter bit RV32E = 1'b0,
2222
parameter rv32m_e RV32M = RV32MFast,
2323
parameter rv32b_e RV32B = RV32BNone,
24-
parameter regfile_e RegFile = RegFileFF,
24+
parameter regfile_e RegFile = RegFileLatch,
2525
parameter bit BranchTargetALU = 1'b0,
2626
parameter bit WritebackStage = 1'b0,
2727
parameter bit ICache = 1'b0,

syn/rtl/prim_buf.sv

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
module prim_buf #(
6+
parameter int Width = 1
7+
) (
8+
input [Width-1:0] in_i,
9+
output logic [Width-1:0] out_o
10+
);
11+
12+
logic [Width-1:0] inv;
13+
assign inv = ~in_i;
14+
assign out_o = ~inv;
15+
16+
endmodule

syn/rtl/prim_flop.sv

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
module prim_flop #(
6+
parameter int Width = 1,
7+
parameter logic [Width-1:0] ResetValue = 0
8+
) (
9+
input clk_i,
10+
input rst_ni,
11+
input [Width-1:0] d_i,
12+
output logic [Width-1:0] q_o
13+
);
14+
15+
always_ff @(posedge clk_i or negedge rst_ni) begin
16+
if (!rst_ni) begin
17+
q_o <= ResetValue;
18+
end else begin
19+
q_o <= d_i;
20+
end
21+
end
22+
23+
endmodule

syn/syn_yosys.sh

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ fi
2828
#-------------------------------------------------------------------------
2929
source syn_setup.sh
3030

31-
#-------------------------------------------------------------------------
32-
# use sv2v to convert all SystemVerilog files to Verilog
33-
#-------------------------------------------------------------------------
34-
3531
LR_DEP_SOURCES=(
3632
"../vendor/lowrisc_ip/ip/prim_generic/rtl/prim_generic_buf.sv"
3733
"../vendor/lowrisc_ip/ip/prim_generic/rtl/prim_generic_flop.sv"
@@ -41,42 +37,6 @@ mkdir -p "$LR_SYNTH_OUT_DIR/generated"
4137
mkdir -p "$LR_SYNTH_OUT_DIR/log"
4238
mkdir -p "$LR_SYNTH_OUT_DIR/reports/timing"
4339

44-
# Convert dependency sources
45-
for file in "${LR_DEP_SOURCES[@]}"; do
46-
module=$(basename -s .sv "$file")
47-
48-
sv2v \
49-
--define=SYNTHESIS --define=YOSYS \
50-
-I../vendor/lowrisc_ip/ip/prim/rtl \
51-
"$file" \
52-
> "$LR_SYNTH_OUT_DIR"/generated/"${module}".v
53-
done
54-
55-
# Convert core sources
56-
for file in ../rtl/*.sv; do
57-
module=$(basename -s .sv "$file")
58-
59-
# Skip packages
60-
if echo "$module" | grep -q '_pkg$'; then
61-
continue
62-
fi
63-
64-
sv2v \
65-
--define=SYNTHESIS --define=YOSYS \
66-
../rtl/*_pkg.sv \
67-
../vendor/lowrisc_ip/ip/prim/rtl/prim_ram_1p_pkg.sv \
68-
../vendor/lowrisc_ip/ip/prim/rtl/prim_secded_pkg.sv \
69-
-I../vendor/lowrisc_ip/ip/prim/rtl \
70-
-I../vendor/lowrisc_ip/dv/sv/dv_utils \
71-
"$file" \
72-
> "$LR_SYNTH_OUT_DIR"/generated/"${module}".v
73-
74-
# Make sure auto-generated primitives are resolved to generic primitives
75-
# where available.
76-
sed -i 's/prim_buf/prim_generic_buf/g' "$LR_SYNTH_OUT_DIR"/generated/"${module}".v
77-
sed -i 's/prim_flop/prim_generic_flop/g' "$LR_SYNTH_OUT_DIR"/generated/"${module}".v
78-
done
79-
8040
# remove tracer (not needed for synthesis)
8141
rm -f "$LR_SYNTH_OUT_DIR"/generated/ibex_tracer.v
8242

@@ -85,7 +45,7 @@ rm -f "$LR_SYNTH_OUT_DIR"/generated/ibex_tracer.v
8545
rm -f "$LR_SYNTH_OUT_DIR"/generated/ibex_register_file_ff.v
8646
rm -f "$LR_SYNTH_OUT_DIR"/generated/ibex_register_file_fpga.v
8747

88-
yosys -c ./tcl/yosys_run_synth.tcl |& teelog syn || {
48+
yosys -m "$LR_SYNTH_SYNLIG_PLUGIN_PATH" -c ./tcl/yosys_run_synth.tcl |& teelog syn || {
8949
error "Failed to synthesize RTL with Yosys"
9050
}
9151

syn/tcl/yosys_run_synth.tcl

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,44 @@ if { $lr_synth_timing_run } {
1414
write_sdc_out $lr_synth_sdc_file_in $lr_synth_sdc_file_out
1515
}
1616

17-
yosys "read_verilog -defer -sv ./rtl/prim_clock_gating.v $lr_synth_out_dir/generated/*.v"
17+
yosys "read_systemverilog -defer \
18+
-PSYNTHESIS=true \
19+
-PYOSYS=true \
20+
-I../vendor/lowrisc_ip/ip/prim/rtl/ \
21+
-I../vendor/lowrisc_ip/dv/sv/dv_utils \
22+
rtl/prim_clock_gating.v \
23+
rtl/prim_buf.sv \
24+
rtl/prim_flop.sv \
25+
../vendor/lowrisc_ip/ip/prim_generic/rtl/prim_generic_buf.sv \
26+
../vendor/lowrisc_ip/ip/prim_generic/rtl/prim_generic_flop.sv \
27+
../rtl/ibex_pkg.sv \
28+
../vendor/lowrisc_ip/ip/prim/rtl/prim_ram_1p_pkg.sv \
29+
../vendor/lowrisc_ip/ip/prim/rtl/prim_secded_pkg.sv \
30+
../rtl/ibex_alu.sv \
31+
../rtl/ibex_branch_predict.sv \
32+
../rtl/ibex_compressed_decoder.sv \
33+
../rtl/ibex_controller.sv \
34+
../rtl/ibex_core.sv \
35+
../rtl/ibex_counter.sv \
36+
../rtl/ibex_cs_registers.sv \
37+
../rtl/ibex_csr.sv \
38+
../rtl/ibex_decoder.sv \
39+
../rtl/ibex_dummy_instr.sv \
40+
../rtl/ibex_ex_block.sv \
41+
../rtl/ibex_fetch_fifo.sv \
42+
../rtl/ibex_icache.sv \
43+
../rtl/ibex_id_stage.sv \
44+
../rtl/ibex_if_stage.sv \
45+
../rtl/ibex_load_store_unit.sv \
46+
../rtl/ibex_lockstep.sv \
47+
../rtl/ibex_multdiv_fast.sv \
48+
../rtl/ibex_multdiv_slow.sv \
49+
../rtl/ibex_pmp.sv \
50+
../rtl/ibex_prefetch_buffer.sv \
51+
../rtl/ibex_register_file_latch.sv \
52+
../rtl/ibex_top.sv \
53+
../rtl/ibex_wb_stage.sv"
54+
yosys "read_systemverilog -link"
1855

1956
if { $lr_synth_ibex_branch_target_alu } {
2057
yosys "chparam -set BranchTargetALU 1 $lr_synth_top_module"

0 commit comments

Comments
 (0)