I'm writing a project with Verilog and want to use parameter
to define some parameter in my module. But when I read in some source code, localparam
sometimes is used instead of parameter
.
What's difference between them?
I'm writing a project with Verilog and want to use parameter
to define some parameter in my module. But when I read in some source code, localparam
sometimes is used instead of parameter
.
What's difference between them?
Generally, the idea behind the
localparam
(added to the Verilog-2001 standard) is to protect value oflocalparam
from accidental or incorrect redefinition by an end-user (unlike aparameter
value, this value can't be modified by parameter redefinition or by adefparam
statement).Based on IEEE 1364-2005 (ch. 4.10.2):
Additionally, in SystemVerilog (IEEE 1800-2012 (ch. 6.20.4)):
If you want to learn more about this topic, I'd recommend you Clifford E. Cummings paper "New Verilog-2001 Techniques for Creating Parameterized Models (or Down With `define and Death of a defparam!)".
Minimal example
Here is an example of what Qiu mentioned.
In a RAM, the memory size is a function of the word and address sizes.
So if the parent module specifies word and address size, it should not be able to specify the memory size as well.
And on parent module, this is fine:
but this should be an error:
iverilog
doesn't fail, and I believe that this is a bug: https://github.com/steveicarus/iverilog/issues/157Incisive gives an error as expected.