Difference between “parameter” and “localparam”

后端 未结 2 1086
轻奢々
轻奢々 2021-01-31 18:27

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 so

2条回答
  •  暖寄归人
    2021-01-31 19:20

    Generally, the idea behind the localparam (added to the Verilog-2001 standard) is to protect value of localparam from accidental or incorrect redefinition by an end-user (unlike a parameter value, this value can't be modified by parameter redefinition or by a defparam statement).

    Based on IEEE 1364-2005 (ch. 4.10.2):

    Verilog HDL local parameters are identical to parameters except that they cannot directly be modified by defparam statements or module instance parameter value assignments. Local parameters can be assigned constant expressions containing parameters, which can be modified with defparam statements or module instance parameter value assignments.

    Additionally, in SystemVerilog (IEEE 1800-2012 (ch. 6.20.4)):

    Unlike nonlocal parameters, local parameters can be declared in a generate block, package, class body, or compilation-unit scope. In these contexts, the parameter keyword shall be a synonym for the localparam keyword.

    Local parameters may be declared in a module’s parameter_port_list. Any parameter declaration appearing in such a list between a localparam keyword and the next parameter keyword (or the end of the list, if there is no next parameter keyword) shall be a local parameter. Any other parameter declaration in such a list shall be a nonlocal parameter that may be overridden.

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

提交回复
热议问题