mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-06 14:13:23 +00:00
Switching example synth to fifo
Fifo code based on SBY quick start. Instead of showing the full design we are (currently) focusing on a single output (rdata), using `%ci*` to get the subcircuit it relies on.
This commit is contained in:
parent
80c78aaad6
commit
742ec78ca3
9 changed files with 2538 additions and 326 deletions
|
@ -1,15 +0,0 @@
|
|||
PROGRAM_PREFIX :=
|
||||
|
||||
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
|
||||
|
||||
DOTS = control_hier.dot control_proc.dot
|
||||
DOTS += example_hier.dot
|
||||
|
||||
dots: $(DOTS) example.out
|
||||
|
||||
$(DOTS) example.out: example.v example.ys
|
||||
$(YOSYS) example.ys -l example.out -Q
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f *.dot
|
|
@ -1,147 +0,0 @@
|
|||
|
||||
-- Executing script file `example.ys' --
|
||||
echo on
|
||||
|
||||
yosys> read_verilog -defer example.v
|
||||
|
||||
1. Executing Verilog-2005 frontend: example.v
|
||||
Parsing Verilog input from `example.v' to AST representation.
|
||||
Storing AST representation for module `$abstract\example'.
|
||||
Storing AST representation for module `$abstract\control'.
|
||||
Storing AST representation for module `$abstract\data'.
|
||||
Successfully finished Verilog frontend.
|
||||
|
||||
yosys> hierarchy -top control
|
||||
|
||||
2. Executing HIERARCHY pass (managing design hierarchy).
|
||||
|
||||
3. Executing AST frontend in derive mode using pre-parsed AST for module `\control'.
|
||||
Generating RTLIL representation for module `\control'.
|
||||
|
||||
3.1. Analyzing design hierarchy..
|
||||
Top module: \control
|
||||
|
||||
3.2. Analyzing design hierarchy..
|
||||
Top module: \control
|
||||
Removing unused module `$abstract\data'.
|
||||
Removing unused module `$abstract\control'.
|
||||
Removing unused module `$abstract\example'.
|
||||
Removed 3 unused modules.
|
||||
|
||||
yosys> show -notitle -format dot -prefix control_hier
|
||||
|
||||
4. Generating Graphviz representation of design.
|
||||
Writing dot description to `control_hier.dot'.
|
||||
Dumping module control to page 1.
|
||||
|
||||
yosys> proc
|
||||
|
||||
5. Executing PROC pass (convert processes to netlists).
|
||||
|
||||
yosys> proc_clean
|
||||
|
||||
5.1. Executing PROC_CLEAN pass (remove empty switches from decision trees).
|
||||
Cleaned up 0 empty switches.
|
||||
|
||||
yosys> proc_rmdead
|
||||
|
||||
5.2. Executing PROC_RMDEAD pass (remove dead branches from decision trees).
|
||||
Marked 1 switch rules as full_case in process $proc$example.v:43$1 in module control.
|
||||
Removed a total of 0 dead cases.
|
||||
|
||||
yosys> proc_prune
|
||||
|
||||
5.3. Executing PROC_PRUNE pass (remove redundant assignments in processes).
|
||||
Removed 1 redundant assignment.
|
||||
Promoted 0 assignments to connections.
|
||||
|
||||
yosys> proc_init
|
||||
|
||||
5.4. Executing PROC_INIT pass (extract init attributes).
|
||||
|
||||
yosys> proc_arst
|
||||
|
||||
5.5. Executing PROC_ARST pass (detect async resets in processes).
|
||||
|
||||
yosys> proc_rom
|
||||
|
||||
5.6. Executing PROC_ROM pass (convert switches to ROMs).
|
||||
Converted 0 switches.
|
||||
<suppressed ~2 debug messages>
|
||||
|
||||
yosys> proc_mux
|
||||
|
||||
5.7. Executing PROC_MUX pass (convert decision trees to multiplexers).
|
||||
Creating decoders for process `\control.$proc$example.v:43$1'.
|
||||
1/2: $0\addr[7:0]
|
||||
2/2: $0\state[1:0]
|
||||
|
||||
yosys> proc_dlatch
|
||||
|
||||
5.8. Executing PROC_DLATCH pass (convert process syncs to latches).
|
||||
|
||||
yosys> proc_dff
|
||||
|
||||
5.9. Executing PROC_DFF pass (convert process syncs to FFs).
|
||||
Creating register for signal `\control.\state' using process `\control.$proc$example.v:43$1'.
|
||||
created $dff cell `$procdff$12' with positive edge clock.
|
||||
Creating register for signal `\control.\addr' using process `\control.$proc$example.v:43$1'.
|
||||
created $dff cell `$procdff$13' with positive edge clock.
|
||||
|
||||
yosys> proc_memwr
|
||||
|
||||
5.10. Executing PROC_MEMWR pass (convert process memory writes to cells).
|
||||
|
||||
yosys> proc_clean
|
||||
|
||||
5.11. Executing PROC_CLEAN pass (remove empty switches from decision trees).
|
||||
Found and cleaned up 2 empty switches in `\control.$proc$example.v:43$1'.
|
||||
Removing empty process `control.$proc$example.v:43$1'.
|
||||
Cleaned up 2 empty switches.
|
||||
|
||||
yosys> opt_expr -keepdc
|
||||
|
||||
5.12. Executing OPT_EXPR pass (perform const folding).
|
||||
Optimizing module control.
|
||||
|
||||
yosys> show -notitle -format dot -prefix control_proc
|
||||
|
||||
6. Generating Graphviz representation of design.
|
||||
Writing dot description to `control_proc.dot'.
|
||||
Dumping module control to page 1.
|
||||
|
||||
yosys> design -reset
|
||||
|
||||
yosys> read_verilog example.v
|
||||
|
||||
7. Executing Verilog-2005 frontend: example.v
|
||||
Parsing Verilog input from `example.v' to AST representation.
|
||||
Generating RTLIL representation for module `\example'.
|
||||
Generating RTLIL representation for module `\control'.
|
||||
Generating RTLIL representation for module `\data'.
|
||||
Successfully finished Verilog frontend.
|
||||
|
||||
yosys> hierarchy -check -top example
|
||||
|
||||
8. Executing HIERARCHY pass (managing design hierarchy).
|
||||
|
||||
8.1. Analyzing design hierarchy..
|
||||
Top module: \example
|
||||
Used module: \data
|
||||
Used module: \control
|
||||
|
||||
8.2. Analyzing design hierarchy..
|
||||
Top module: \example
|
||||
Used module: \data
|
||||
Used module: \control
|
||||
Removed 0 unused modules.
|
||||
|
||||
yosys> show -notitle -format dot -prefix example_hier example
|
||||
|
||||
9. Generating Graphviz representation of design.
|
||||
Writing dot description to `example_hier.dot'.
|
||||
Dumping module example to page 1.
|
||||
|
||||
End of script. Logfile hash: b45465606c, CPU: user 0.01s system 0.00s, MEM: 11.86 MB peak
|
||||
Yosys 0.35+39 (git sha1 0cd4a10c8, clang 10.0.0-4ubuntu1 -fPIC -Os)
|
||||
Time spent: 37% 4x read_verilog (0 sec), 23% 3x show (0 sec), ...
|
|
@ -1,76 +0,0 @@
|
|||
module example (
|
||||
input clk,
|
||||
input rst,
|
||||
input inc,
|
||||
input [7:0] a,
|
||||
input [7:0] b,
|
||||
output [15:0] c
|
||||
);
|
||||
|
||||
wire [1:0] state;
|
||||
wire [7:0] addr;
|
||||
|
||||
control ctrl (
|
||||
.clk(clk),
|
||||
.rst(rst),
|
||||
.inc(inc),
|
||||
.addr_o(addr),
|
||||
.state_o(state)
|
||||
);
|
||||
|
||||
data dat (
|
||||
.clk(clk),
|
||||
.addr_i(addr),
|
||||
.state_i(state),
|
||||
.a(a),
|
||||
.b(b),
|
||||
.c(c)
|
||||
);
|
||||
|
||||
endmodule
|
||||
|
||||
module control (
|
||||
input clk,
|
||||
input rst,
|
||||
input inc,
|
||||
output [7:0] addr_o,
|
||||
output [1:0] state_o
|
||||
);
|
||||
|
||||
reg [1:0] state;
|
||||
reg [7:0] addr;
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (rst) begin
|
||||
state <= 2'b00;
|
||||
addr <= 0;
|
||||
end else begin
|
||||
if (inc) state <= state + 1'b1;
|
||||
addr <= addr + 1'b1;
|
||||
end
|
||||
end
|
||||
|
||||
endmodule //control
|
||||
|
||||
module data (
|
||||
input clk,
|
||||
input [7:0] addr_i,
|
||||
input [1:0] state_i,
|
||||
input [7:0] a,
|
||||
input [7:0] b,
|
||||
output reg [15:0] c
|
||||
);
|
||||
|
||||
reg [15:0] mem[255:0];
|
||||
|
||||
always @(posedge clk) begin
|
||||
case (state_i)
|
||||
2'b00: mem[addr_i] <= a*b;
|
||||
2'b01: mem[addr_i] <= a+b;
|
||||
2'b10: mem[addr_i] <= a-b;
|
||||
2'b11: mem[addr_i] <= addr_i;
|
||||
endcase
|
||||
c <= mem[addr_i];
|
||||
end
|
||||
|
||||
endmodule //data
|
|
@ -1,17 +0,0 @@
|
|||
# turn command echoes on to use the log output as a console session
|
||||
echo on
|
||||
|
||||
# ========================================================
|
||||
read_verilog -defer example.v
|
||||
hierarchy -top control
|
||||
show -notitle -format dot -prefix control_hier
|
||||
|
||||
# ========================================================
|
||||
proc
|
||||
show -notitle -format dot -prefix control_proc
|
||||
|
||||
# ========================================================
|
||||
design -reset
|
||||
read_verilog example.v
|
||||
hierarchy -check -top example
|
||||
show -notitle -format dot -prefix example_hier example
|
16
docs/source/code_examples/fifo/Makefile
Normal file
16
docs/source/code_examples/fifo/Makefile
Normal file
|
@ -0,0 +1,16 @@
|
|||
PROGRAM_PREFIX :=
|
||||
|
||||
YOSYS ?= ../../../../$(PROGRAM_PREFIX)yosys
|
||||
|
||||
DOTS = addr_gen_hier.dot addr_gen_proc.dot
|
||||
DOTS += rdata_proc.dot rdata_flat.dot
|
||||
DOTS += fifo_flat.dot fifo_synth.dot
|
||||
|
||||
dots: $(DOTS) fifo.out
|
||||
|
||||
$(DOTS) fifo.out: fifo.v fifo.ys
|
||||
$(YOSYS) fifo.ys -l fifo.out -Q
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f *.dot
|
2331
docs/source/code_examples/fifo/fifo.out
Normal file
2331
docs/source/code_examples/fifo/fifo.out
Normal file
File diff suppressed because it is too large
Load diff
73
docs/source/code_examples/fifo/fifo.v
Normal file
73
docs/source/code_examples/fifo/fifo.v
Normal file
|
@ -0,0 +1,73 @@
|
|||
// address generator/counter
|
||||
module addr_gen
|
||||
#( parameter MAX_DATA=256
|
||||
) ( input en, clk, rst,
|
||||
output reg [AWIDTH-1:0] addr
|
||||
);
|
||||
localparam AWIDTH = $clog2(MAX_DATA);
|
||||
|
||||
initial addr <= 0;
|
||||
|
||||
// async reset
|
||||
// increment address when enabled
|
||||
always @(posedge clk or posedge rst)
|
||||
if (rst)
|
||||
addr <= 0;
|
||||
else if (en) begin
|
||||
if (addr == MAX_DATA-1)
|
||||
addr <= 0;
|
||||
else
|
||||
addr <= addr + 1;
|
||||
end
|
||||
endmodule //addr_gen
|
||||
|
||||
// Define our top level fifo entity
|
||||
module fifo
|
||||
#( parameter MAX_DATA=256
|
||||
) ( input wen, ren, clk, rst,
|
||||
input [7:0] wdata,
|
||||
output reg [7:0] rdata,
|
||||
output reg [AWIDTH:0] count
|
||||
);
|
||||
localparam AWIDTH = $clog2(MAX_DATA);
|
||||
|
||||
// fifo storage
|
||||
// sync read before write
|
||||
wire [AWIDTH-1:0] waddr, raddr;
|
||||
reg [7:0] data [MAX_DATA-1:0];
|
||||
always @(posedge clk) begin
|
||||
if (wen)
|
||||
data[waddr] <= wdata;
|
||||
rdata <= data[raddr];
|
||||
end // storage
|
||||
|
||||
// addr_gen for both write and read addresses
|
||||
addr_gen #(.MAX_DATA(MAX_DATA))
|
||||
fifo_writer (
|
||||
.en (wen),
|
||||
.clk (clk),
|
||||
.rst (rst),
|
||||
.addr (waddr)
|
||||
);
|
||||
|
||||
addr_gen #(.MAX_DATA(MAX_DATA))
|
||||
fifo_reader (
|
||||
.en (ren),
|
||||
.clk (clk),
|
||||
.rst (rst),
|
||||
.addr (raddr)
|
||||
);
|
||||
|
||||
// status signals
|
||||
initial count <= 0;
|
||||
|
||||
always @(posedge clk or posedge rst) begin
|
||||
if (rst)
|
||||
count <= 0;
|
||||
else if (wen && !ren)
|
||||
count <= count + 1;
|
||||
else if (ren && !wen)
|
||||
count <= count - 1;
|
||||
end
|
||||
|
||||
endmodule
|
39
docs/source/code_examples/fifo/fifo.ys
Normal file
39
docs/source/code_examples/fifo/fifo.ys
Normal file
|
@ -0,0 +1,39 @@
|
|||
# ========================================================
|
||||
# throw in some extra text to match what we expect if we were opening an
|
||||
# interactive terminal
|
||||
log $ yosys fifo.v
|
||||
log
|
||||
log -- Parsing `fifo.v' using frontend ` -vlog2k' --
|
||||
read_verilog -defer fifo.v
|
||||
|
||||
# turn command echoes on to use the log output as a console session
|
||||
echo on
|
||||
hierarchy -top addr_gen
|
||||
show -notitle -format dot -prefix addr_gen_hier
|
||||
|
||||
# ========================================================
|
||||
proc
|
||||
show -notitle -format dot -prefix addr_gen_proc
|
||||
|
||||
# ========================================================
|
||||
design -reset
|
||||
read_verilog fifo.v
|
||||
hierarchy -check -top fifo
|
||||
proc
|
||||
show -notitle -format dot -prefix rdata_proc o:rdata %ci*
|
||||
|
||||
# ========================================================
|
||||
|
||||
flatten
|
||||
show -notitle -format dot -prefix rdata_flat o:rdata %ci*
|
||||
|
||||
# ========================================================
|
||||
|
||||
opt_clean
|
||||
show -notitle -format dot -prefix fifo_flat
|
||||
|
||||
design -reset
|
||||
read_verilog fifo.v
|
||||
synth_ice40 -dsp -top fifo
|
||||
show -notitle -format dot -prefix fifo_synth
|
||||
stat
|
Loading…
Add table
Add a link
Reference in a new issue