相关阅读
HDL Compiler
https://blog.csdn.net/weixin_45791458/category_12893238.html?spm=1001.2014.3001.5482
简介
生成块结构(Generate)用于有条件地(称为条件生成块)或重复地(称为循环生成块)将生成块实例化到模块中,由Verilog 2001标准借鉴VHDL引入。HDL Compiler默认使用Verilog 2005标准读取设计,控制hdlin_vrlg_std变量(默认值为2005)可以改变读取规则,并同时支持Verilog 2001标准和Verilog 2005标准中的生成块结构。
有关生成块结构的更多介绍,可以参考下面的博客。
生成块的种类
普通生成块
循环生成块结构允许使用类似for循环语句的语法,而条件生成块结构(包括if-generate和case-generate)用于在多个选项生成块中选择至多一个实例化。它们可以互相嵌套,如例1所示。
// 例1
module top(input D1, input clk, output Q1);
genvar i, j;
parameter param1 = 0;
parameter param2 = 1;
generate
for (i = 0; i < 3; i = i + 1) begin : loop1
for (j = 0; j < 2; j = j + 1) begin : loop2
if (j == param1) begin : if1_label
memory U_00 (D1,clk,Q1);
end
if (j == param2) begin : if2_label
memory U_00 (D1,clk,Q1);
end
end //loop2
end //loop1
endgenerate
endmodule
module memory(input D1, input clk, output Q1);
endmodule
下面展示了HDL Compiler读取例1后report_cell命令的结果,可以看出即使对于仿真器,会为生成块结构中的命名块创建新的层次,但对于HDL Compiler,所有实例被视为同一个模块层次,而命名块层次则使用实例名中的.分隔。
Cell Reference Library Area Attributes
------------------------------------------------------------------------------
loop1[0].loop2[0].if1_label.U_00
memory 0.000000 b
loop1[0].loop2[1].if2_label.U_00
memory 0.000000 b
loop1[1].loop2[0].if1_label.U_00
memory 0.000000 b
loop1[1].loop2[1].if2_label.U_00
memory 0.000000 b
loop1[2].loop2[0].if1_label.U_00
memory 0.000000 b
loop1[2].loop2[1].if2_label.U_00
memory 0.000000 b
------------------------------------------------------------------------------
Total 6 cells 0.000000
这不代表标识符的引用无需遵守Verilog标准中的规则,HDL Compiler在读取例2后会出现VER-956错误,因为标识符w实际上被定义在命名块中,而却在顶层引用。
// 例2
module top(input in, output out);
generate
if (1) begin: label1
wire w = in;
end
endgenerate
assign out = w;
endmodule
独立生成块
// 例3
module top (input in1, output out1);
generate
begin : b1
mod1 U1(in1, out1);
end
endgenerate
endmodule
module mod1 (input in1, output out1);
endmodule
Verilog 2001标准支持一种不属于普通生成块的生成块结构,即不使用for、if或case语句,如例3所示。当使用Verilog 2001标准时,下面展示了HDL Compiler读取例3后report_cell命令的结果。
Cell Reference Library Area Attributes
------------------------------------------------------------
b1.U1 mod1 0.000000 b
------------------------------------------------------------
Total 1 cells 0.000000
当使用Verilog 2005标准时,HDL Compiler在读取例3后会出现VER-946错误。
匿名生成块
// 例4
module top(input [0:3] in1, output [0:3] out1);
genvar I;
generate
for (I = 0; I < 3; I = I+1) begin : b1
if (1) begin : b2
if (1) begin
if (1) begin
if (1) begin
mod1 U1(in1[I], out1[I]);
end
end
end
end
end
endgenerate
endmodule
module mod1(input in1, output out1);
endmodule
Verilog 2005标准规定,在一个命名空间内的每个生成块结构都会被分配一个编号。在该命名空间中文本上最先出现的生成块结构编号为1,每出现一个新的生成块结构,编号就加1(注意,即使生成块结构不是匿名的,其依然拥有编号)。生成块结构中的匿名生成块将拥有隐式名称genblk<n>,其中<n>是其所在生成块结构被分配的编号。如果这样的隐式名称与该命名空间中显式声明的名称发生冲突,那么将在编号前添加前导零,直到名称不再冲突为止。当使用Verilog 2005标准时,下面展示了HDL Compiler读取例4后report_cell命令的结果,出现VER-944警告。
Cell Reference Library Area Attributes
----------------------------------------------------------------------------------------
b1[0].b2.genblk1.genblk1.genblk1.U1 mod1 0.000000 b
b1[1].b2.genblk1.genblk1.genblk1.U1 mod1 0.000000 b
b1[2].b2.genblk1.genblk1.genblk1.U1 mod1 0.000000 b
----------------------------------------------------------------------------------------
Total 3 cells 0.000000
Verilog 2001标准没有对匿名生成块有额外规定,因此不创建新的层次,当使用Verilog 2001标准时,下面展示了HDL Compiler读取例4后report_cell命令的结果。
Cell Reference Library Area Attributes
----------------------------------------------------------------
b1[0].b2.U1 mod1 0.000000 b
b1[1].b2.U1 mod1 0.000000 b
b1[2].b2.U1 mod1 0.000000 b
----------------------------------------------------------------
Total 3 cells 0.000000
直接嵌套
// 例5
module top(input [0:3] in1, output [0:3] out1);
genvar I;
generate
for (I = 0; I < 3; I = I+1) begin : b1
if (1) begin : b2
if (1)
if (1)
if (1)
mod1 U1(in1[I], out1[I]);
end
end
endgenerate
endmodule
module mod1(input in1, output out1);
endmodule
Verilog 2005标准规定,如果条件生成块结构中的生成块只包含一个项目(并且没有使用begin-end块),而这个项目本身又是一个条件生成块结构,那么,这个外层条件生成块结构不会被视为一个单独的层次结构和命名空间,这种情况称为直接嵌套(direct nesting),直接嵌套的生成块会被视为属于外层条件生成块结构。当使用Verilog 2005标准时,下面展示了HDL Compiler读取例5后report_cell命令的结果,其中的genblk1层次来自最内层if语句。
Cell Reference Library Area Attributes
--------------------------------------------------------------------
b1[0].b2.genblk1.U1 mod1 0.000000 b
b1[1].b2.genblk1.U1 mod1 0.000000 b
b1[2].b2.genblk1.U1 mod1 0.000000 b
--------------------------------------------------------------------
Total 3 cells 0.000000
Verilog 2001标准没有对匿名生成块有额外规定,因此不创建新的层次,当使用Verilog 2001标准时,下面展示了HDL Compiler读取例5后report_cell命令的结果。
Cell Reference Library Area Attributes
------------------------------------------------------------
b1[0].b2.U1 mod1 0.000000 b
b1[1].b2.U1 mod1 0.000000 b
b1[2].b2.U1 mod1 0.000000 b
------------------------------------------------------------
Total 3 cells 0.000000