Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17240 Discussions

What is usage of "generate" in Verilog?

Altera_Forum
Honored Contributor II
7,659 Views

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.
0 Kudos
10 Replies
Altera_Forum
Honored Contributor II
2,699 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
2,699 Views

 

--- 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.
0 Kudos
Altera_Forum
Honored Contributor II
2,699 Views

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

0 Kudos
Altera_Forum
Honored Contributor II
2,699 Views

 

--- 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?
0 Kudos
Altera_Forum
Honored Contributor II
2,699 Views

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)!

0 Kudos
Altera_Forum
Honored Contributor II
2,699 Views

 

--- 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?
0 Kudos
Altera_Forum
Honored Contributor II
2,699 Views

The one in the link I just posted.

0 Kudos
Altera_Forum
Honored Contributor II
2,699 Views

 

--- Quote Start ---  

The one in the link I just posted. 

--- Quote End ---  

 

 

Thanks. But where is the link? I did not see it.
0 Kudos
Altera_Forum
Honored Contributor II
2,699 Views

Put your cursor over the words "get one"

0 Kudos
Altera_Forum
Honored Contributor II
2,699 Views

Thanks very much.

0 Kudos
Reply