简体   繁体   English

生成块的执行

[英]Execution of Generate Block

  1. When is "GENERATE BLOCK" executed in a Verilog module ? 什么时候在Verilog模块中执行“ GENERATE BLOCK”?
  2. Will the code inside Generate Block execute sequentially ? 生成块中的代码会顺序执行吗?

Generate block cannot be executed like always or initial blocks, it is evaluated during elaboration stage. 生成块不能像总是块或初始块一样执行,它在详细说明阶段进行评估。 Generate is commonly used to instantiate multiple instance of same module or logic, for example: 生成通常用于实例化同一模块或逻辑的多个实例,例如:

module and_mod (input bit a, input bit b, output out);
  assign out = a & b;
endmodule


module test #( 
   parameter NUM_INSTANCES = 3 
) (
   input bit [NUM_INSTANCES - 1 : 0] a, 
   input bit [NUM_INSTANCES - 1 : 0] b, 
   output bit [NUM_INSTANCES - 1 : 0] a_and_b, 
   output bit [NUM_INSTANCES - 1 : 0] a_or_b,
   output bit [NUM_INSTANCES - 1 : 0] a_xor_b
);


   genvar i;
   generate 
      for( i = 0; i < NUM_INSTANCES; i++ )
      begin
        //module instance
        and_mod and_inst (.a(a[i]),.b(b[i]), .out(a_and_b[i]));
        //contionous assignement                         
        assign a_xor_b[i] = a[i] ^ b[i]; 

        //always block
        always @(*)
        begin
          a_or_b[i] = a[i] | b[i];
        end
      end
    endgenerate
endmodule

This generate block will evaluate to NUM_INSTANCES copies of code inside generate block. 此generate块将评估generate块内的NUM_INSTANCES代码副本。 As you can see you can have module instantiation, assignments, always/initial blocks inside generate block. 如您所见,您可以在generate块中包含模块实例化,分配,始终/初始块。 Pay attention to the fact that and_mod has only 1-bit wide ports so we need 3 instances of it to calculate and of 3-bit registers, but thanks to generate block you don't have to write 3 instances in your code. 请注意以下事实:and_mod只有1位宽的端口,因此我们需要3个实例来计算和3位寄存器,但是由于产生了块,因此您不必在代码中编写3个实例。

Execution of code inside generate block depends on code itself, assignments will execute concurrently, code inside always block will execute sequentially, same as without generate block. 生成块内部的代码执行取决于代码本身,赋值将并发执行,始终块内部的代码将按顺序执行,与没有生成块的情况相同。

You can test it here . 您可以在这里进行测试。

generate block is not for execution. 生成块不用于执行。 It is just that if you want to have multiple repetitive blocks in a module, then you can use generate block. 只是如果您想在一个模块中有多个重复块,则可以使用generate块。

Generate constructs are used to either conditionally or multiply instantiate generate blocks into a model. 生成构造用于有条件地或将实例化生成块乘以一个模型。

A generate block is a collection of one or more module items. 生成块是一个或多个模块项的集合。 A generate block may not contain port declarations, specify blocks, or specparam declarations. 生成块可能不包含端口声明,指定块或specparam声明。 Parameters declared in generate blocks shall be treated as localparams. 在generate块中声明的参数应视为localparams。 All other module items, including other generate constructs, are allowed in a generate block. 生成块中允许所有其他模块项,包括其他生成构造。

Generate constructs provide the ability for parameter values to affect the structure of the design. 生成构造提供了参数值影响设计结构的能力。 They also allow for modules with repetitive structure to be described more concisely, and they make recursive module instantiation possible. 它们还允许更简洁地描述具有重复结构的模块,并使递归模块实例化成为可能。

Generate schemes are evaluated during elaboration of the design. 在详细设计过程中评估生成方案。 They do not execute at simulation time. 它们不会在仿真时执行。 They are evaluated at elaboration time, and the result is determined before simulation begins. 在精心设计的时候对它们进行评估,并在仿真开始之前确定结果。

Refer to Topic 27, in SV1800-2012 LRM for more details. 有关更多详细信息,请参阅SV1800-2012 LRM中的主题27。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM