What is Generate statement?
A Verilog construct that expands hardware descriptions by loops or conditions, used for example to instantiate a module repeatedly in a regular pattern.
Japanese name: generate文
A Verilog construct that expands hardware descriptions by loops or conditions, used for example to instantiate a module repeatedly in a regular pattern.
Japanese name: generate文
A generate statement is a construct that produces hardware description itself. The expansion takes place while the design is being assembled, before simulation or synthesis proper begins. Repetition uses a dedicated variable declared with genvar. For example, writing one fifo instance inside a for that runs from 0 to 3 produces 4 instances. Each can be connected to different signals, such as din[i] and dout[i]. If the count is set by a parameter, changing 4 to 8 produces 8 of them.
Besides for, there are forms that select descriptions with if or case. For example, the value of a parameter can switch between building a small implementation and a fast one. The description that is not selected does not become hardware. A block created by for is given a name. Each instance can then be told apart by a hierarchical name such as g[0].u_fifo or g[1].u_fifo. These names are used, for example, when looking at waveforms.
The counts and conditions of a generate statement can use constants whose values are fixed at expansion time, such as a parameter or a genvar. The value of a signal cannot be used, because it is not known until the circuit runs. Hardware does not grow or shrink after it has been built. To switch during operation, both circuits are built and a multiplexer selects between them. Note also that a large repetition count makes the circuit correspondingly large.
In what is repeated. A for inside always repeats procedural statements such as assignments. A for in generate can repeat module instances, always blocks and assign statements themselves.
No. A separate circuit is built for each repetition. What becomes shorter is the description, and the size of the circuit is the same as when the copies are written out by hand.
Generate statement appears in 1 practice question across 1 topic, including HDL & Verification.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.