Generate If Optional Pipeline Stage
The same multiplier may need one pipeline stage on a fast process and two on a slow one. A generate if decides at elaboration time, so the unused stage costs no registers at all.
The module computes the 32-bit product of two 16-bit unsigned inputs. A parameter controls the pipeline depth. When the parameter is set to 0, the product is registered once and output on the next clock cycle. When the parameter is set to 1, the product is registered, and then that intermediate value is registered a second time before reaching the output, delaying the result by two clock cycles.
- Clock edge:
posedge clk - Reset type: Asynchronous
- Reset polarity: Active-low (
rst_n) - Output values on reset: All pipeline registers and the output
pmust be cleared to0. - Parameter:
EXTRA_PIPEdictates the pipeline depth; defaults to0.
Cycle 1: rst_n=0 → p=0 (for both configurations)
Cycle 2: rst_n=1, a=2, b=3 → p=0 (previous)
Cycle 3: a=4, b=5 → p=6 (EXTRA_PIPE=0), p=0 (EXTRA_PIPE=1)
Cycle 4: a=1, b=1 → p=20 (EXTRA_PIPE=0), p=6 (EXTRA_PIPE=1)
Cycle 5: a=0, b=0 → p=1 (EXTRA_PIPE=0), p=20 (EXTRA_PIPE=1)
| Parameter | Default | Type | Description |
|---|---|---|---|
EXTRA_PIPE |
0 |
integer | When 1, adds an additional pipeline stage to the output. |
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered clock |
rst_n |
input | 1 | Asynchronous active-low reset; clears all registers to 0 |
a |
input | 16 | First multiplicand |
b |
input | 16 | Second multiplicand |
p |
output | 32 | Product output; delayed by 1 cycle if EXTRA_PIPE=0, or 2 cycles if EXTRA_PIPE=1 |
Constraints
- Must use
generateandifconstructs to conditionally instantiate the second pipeline stage. EXTRA_PIPEmust default to0.- The multiplier must be purely combinational before the first register; the first register holds the product.
- When
EXTRA_PIPEis0, the intermediate product register drives the outputpdirectly. - When
EXTRA_PIPEis1, a second register delays the intermediate product by one additional clock cycle. rst_nmust asynchronously clear all instantiated registers to0.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.
Part of SystemVerilog RTL
Problem 11 of 15 in the SystemVerilog RTL track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks