verilog paramer array的定义和使用

问题描述:

在UVM验证环境中定义类Aparameter定义如下:

parameter A1 = 100;
parameter int B[6] = '{32h'01,32h'02,32h'03,32h'04,32h'05,32h'06};

top.sv中引用 parameter A1,如下:

generate
	for (genvar ii = 0; i < A::A1; i++) begin: apb_loop_if
		svt_apb_if sys_apb_if();
	end
endgenerate

编译结果:

报segmentation fault。

问题追踪

https://stackoverflow.com/questions/23507629/parameter-array-in-verilog

The given example is assigning unpacked values to packed parameter array. This in not allowed with Verilog.

Verilog only support simple vector based parameters. It does not support unpacked arrays. SystemVerilog, which superseded Verilog, does support parameter arrays. Almost all modern Verilog simulators are really SystemVerilog simulators (at least for the commercial simulators; open source simulators have incomplete support). To have your files read as SystemVerilog, change the file extension for .v to .sv. Then you can assign unpacked to a 2 dimensional parameter array:

parameter [7:0] PARAM_ARRAY [TOTAL-1 : 0]   = {8'd1, 8'd0, 8'd0, 8'd2};

Type names are also allowed. For example, using integer to creates a 32x4 array:

parameter integer PARAM_ARRAY [TOTAL-1 : 0]   = {1, 0, 0, 2};

This is documented in:
IEEE Std 1364-2001 § 3.11 Parameters
IEEE Std 1364-2005 § 4.10 Parameters
(SystemVerilog) IEEE Std 1800-2012 § 6.20 Constants
As a pure Verilog solution, you will need to created one long vector:

parameter [8*TOTAL-1:0] PARAM_ARRAY = {8'd1, 8'd0, 8'd0, 8'd2};

Then access with a slice as hard coded PARAM_ARRAY[7:0] or using the +:: PARAM_ARRAY[8*index +: 8]. Note that +: requires Verilog-2001 or higher (which even most open-source simulators support). Indexing vectors and arrays with +:

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunvally

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值