Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

What is usage of "generate" in Verilog?

I am confused by the usage of "generate" in Verilog. I checked it online, find some demo codes like:

genvar index;

generate

for (index= 0;index < 64;index = index+1) begin : dq_delay

WireDelay#

(

.Delay_g (TPROP_PCB_DATA),

.Delay_rd (TPROP_PCB_DATA_RD),

.ERR_INSERT ("OFF")

)

u_delay_dq

(

.A (ddr3_dq_fpga[index]),

.B (ddr3_dq_sdram[index]),

.reset (~i_rst_p),

.phy_init_done (init_calib_complete)

);

end

endgenerate

But what is the difference between using "generate" and only use "For" without "generate"? If I wrote the above codes as:

for (index= 0;index < 64;index = index+1) begin : dq_delay

WireDelay#

(

.Delay_g (TPROP_PCB_DATA),

.Delay_rd (TPROP_PCB_DATA_RD),

.ERR_INSERT ("OFF")

)

u_delay_dq

(

.A (ddr3_dq_fpga[index]),

.B (ddr3_dq_sdram[index]),

.reset (~i_rst_p),

.phy_init_done (init_calib_complete)

);

end

No "generate", what is the difference?

Thanks.

10 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You still need the genvar index; statement in either situation.

    Verilog 2005 made the generate/endgenerate keywords optional. Since the for loop appears outside of a procedural context, the extra keywords are unnecessary. The compiler is able to figure out that a for/if/case statement in a module context outside a procedural context is a generate block.

    Verilog is a language full of implicit defaults. But sometimes it is better to document your intent by putting the extra keywords in there.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    You still need the genvar index; statement in either situation.

    Verilog 2005 made the generate/endgenerate keywords optional. Since the for loop appears outside of a procedural context, the extra keywords are unnecessary. The compiler is able to figure out that a for/if/case statement in a module context outside a procedural context is a generate block.

    Verilog is a language full of implicit defaults. But sometimes it is better to document your intent by putting the extra keywords in there.

    --- Quote End ---

    Thanks, dave_59. So that means two codes I wrote are same in Verilog 2005, right?

    Another question, you mentioned "for/if/case statement in a module context outside a procedural context is a generate block." Do you mean "if" or "case" out of "always"? I have never see that.

    Thanks.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Yes, those construct have always been available together with for as a generate construct. See LRM 27.5 conditional generate constructs.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Yes, those construct have always been available together with for as a generate construct. See LRM 27.5 conditional generate constructs.

    --- Quote End ---

    Thanks, dave_59. I am still confused by this. Could you please give an example that "if/case" out of "always"? They must work with generate together, right? I mean if "if/case" is out of "always", "generate" can't be neglected like "for" statement. right?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    There are examples in the LRM section I mentioned, particularity a for nested inside a case generate. Don't have a copy of the LRM? get one (go.mentor.com/get-1800)!

    --- Quote End ---

    Thanks. I should get one. Do you know what is the latest version?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    The one in the link I just posted.

    --- Quote End ---

    Thanks. But where is the link? I did not see it.