all about vlsi DV
Parameters & localparam — Making Designs Reusable
1. Introduction
After interfaces and modports, Alice and Bob face a new problem:
Why do I have to rewrite the same design for different widths or sizes?
Why can’t one design adapt easily?
This is exactly why parameters exist.
Parameters allow you to change behavior without rewriting code.
2. What Are Parameters and localparam in System Verilog?
(Featured Snippet Target)
In SystemVerilog, parameters allow design values to be configurable from outside a module, while localparam defines fixed constants that cannot be overridden.
In simple words:
-
parameter → configurable knob
localparam → internal constant
3. Alice & Bob Mental Model (Memorize This)
-
Alice builds a reusable machine
-
Bob wants the same machine in different sizes
Alice says:
“Don’t change my design. Just tell me the size.”
That “size” is a parameter.
4. parameter — Alice Allows Customization
Runnable Example — Configurable Width
module adder #(
parameter WIDTH = 8
)(
input logic [WIDTH-1:0] a,
input logic [WIDTH-1:0] b,
output logic [WIDTH-1:0] sum
);
assign sum = a + b;
endmodule
Here:
-
Alice wrote one adder
Bob can choose width
Bob Chooses the Size
module top;
logic [3:0] a4, b4, sum4;
logic [7:0] a8, b8, sum8;
adder #(.WIDTH(4)) add4 (.a(a4), .b(b4), .sum(sum4));
adder #(.WIDTH(8)) add8 (.a(a8), .b(b8), .sum(sum8));
endmodule
👉 Same design, different configurations.
5. localparam — Alice Locks Internal Values
Mental Picture
Alice says:
“Some numbers must NEVER change.”
Those go into localparam.
Runnable Example — Fixed Internal Constant
module counter #(
parameter WIDTH = 4
)(
input logic clk,
output logic [WIDTH-1:0] count
);
localparam MAX = (1 << WIDTH) - 1;
always_ff @(posedge clk) begin
if (count == MAX)
count <= 0;
else
count <= count + 1;
end
endmodule
Key idea:
-
WIDTH can change
-
MAX adapts internally
Bob cannot override MAX
6. Parameter vs localparam (One Clear Comparison)
Aspect | parameter | localparam
Can be overridden Yes No
Used for Configuration Internal constants
Visibility External Internal
Interview usage Very common Common
7. Common Beginner Mistakes
-
Using magic numbers instead of parameters
-
Allowing critical values to be overridden
-
Forgetting parameters affect signal widths
Overusing localparam for configurable values
8. Interview Perspective (Short & Sharp)
Interviewers usually ask:
-
“Difference between parameter and localparam?”
-
“Why use parameters?”
Best One-Line Answers
-
parameter enables reuse and configuration
localparam protects internal constants
9. One Sentence to Remember (Interview Gold)
Parameter lets users configure; localparam protects internals.
If you remember this, you’re done.
10. What’s Next
Now Alice can:
-
Reuse designs
-
Customize behavior safely
Next, Alice and Bob start running things in parallel.
👉 Next Article:
Fork–Join in System Verilog — Parallel Execution