“参数"和“参数"之间的区别和“本地参数" [英] Difference between "parameter" and "localparam"

查看:35
本文介绍了“参数"和“参数"之间的区别和“本地参数"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Verilog 编写一个项目,并想使用 parameter 在我的模块中定义一些参数.但是当我读入一些源代码时,有时会使用localparam 而不是parameter.

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.

它们之间有什么区别?

推荐答案

通常,localparam(添加到 Verilog-2001 标准)背后的想法是保护 localparam 来自最终用户意外或不正确的重新定义(与 parameter 值不同,此值不能通过参数重新定义或 defparam 语句修改).

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

基于 IEEE 1364-2005(第 4.10.2 章):

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

Verilog HDL 本地参数与参数相同,只是它们不能通过 defparam 语句或模块实例参数值赋值直接修改.局部参数可以被赋值为包含参数的常量表达式,可以通过 defparam 语句或模块实例参数值赋值来修改.

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.

此外,在 SystemVerilog 中(IEEE 1800-2012(第 6.20.4 章))):

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

与非局部参数不同,局部参数可以在生成块、包、类主体或编译单元范围内声明.在这些上下文中,参数关键字应是 localparam 关键字的同义词.

局部参数可以在模块的 parameter_port_list 中声明.出现在 localparam 关键字和下一个参数关键字(或列表的末尾,如果没有下一个参数关键字)之间的此类列表中的任何参数声明都应是本地参数.此类列表中的任何其他参数声明均应为可被覆盖的非局部参数.

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.

如果您想了解有关此主题的更多信息,我建议您阅读 Clifford E. Cummings 论文用于创建参数化模型的新 Verilog-2001 技术(或因 defparam 的定义和死亡而失败!)".

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

这篇关于“参数"和“参数"之间的区别和“本地参数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆