systemverilog 中逻辑语句的非常量索引 [英] Non-constant indexing for a logic statement in systemverilog

查看:50
本文介绍了systemverilog 中逻辑语句的非常量索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 for 循环,根据循环的迭代将不同的值分配给逻辑数组.

例如,假设我正在尝试实例化两个不同的砖块,宽度均为 10,高度均为 5.假设这些值中的每一个都是 10 位.对于两块砖,我有代码:

logic[19:0] Brick_Width;逻辑[19:0] Brick_Height;

第一个砖块的宽度和高度将被分配到最高的 10 位,第二个被分配到最低的 10 位.

这是我目前拥有的代码:

int i = 19;最初的开始for(i=19; i>=0; i=i-10)开始分配 Brick_Width[i:i-9] = 10;分配 Brick_Height[i:i-9] = 5;结尾结尾

但是,我收到一条错误消息,指出i"不是常量.关于我如何去做这件事的任何想法?

解决方案

常用的范围选择使用 : 运算符必须有一个 常量.您的意图可以通过所谓的 bit-select 运算符来实现.

参考 LRM 1800-2012 中的示例,第 11.5 节如下:

 logic [31: 0] a_vect;逻辑 [0:31] b_vect;逻辑 [63: 0] 双字;整数 sel;a_vect[ 0 +: 8]//== a_vect[ 7 : 0]a_vect[15 -: 8]//== a_vect[15 : 8]b_vect[ 0 +: 8]//== b_vect[0 : 7]b_vect[15 -: 8]//== b_vect[8 :15]dword[8*sel +: 8]//固定宽度的可变部分选择

+:-: 运算符必须用于位切片或部分选择,就像您的情况一样.在这里,您要选择从 ii-9 的部分,因此必须使用 -: 运算符.喜欢 Brick_Height[i-:9]=...

例如

x +:Y,起始位置为x,从x 向上计数Y.Y 必须是常数.x - :Y,起始位置为 x,从 x 倒数 Y.Y 必须是常数.

还有一件事,initial 块中的 assign 语句使其成为连续过程赋值.在这种情况下,位选择将不起作用.要实现这一点,只需删除 assign 语句.如下:

for(i=19; i>=0; i=i-10)开始Brick_Width[i-:9] = 10;//没有赋值,其余的东西都是一样的Brick_Height[i-:9] = 5;结尾

或者使用生成块,如果连续驾驶是意图.

genvar i;产生for(i=19; i>=0; i=i-10)开始分配 Brick_Width[i-:9] = 10;分配 Brick_Height[i-:9] = 5;结尾最终生成

有关位选择的更多信息可以在这个链接中找到.>

边注:

在您的问题中提及以下短语:

<块引用>

对于两块砖,我有代码:

你必须有和 array 一样的 logic[9:0] Brick [2].

I am trying to create a for loop that assigns different values to a logic array given the iteration of the loop.

So, for instance, let's say I am trying to instantiate two different bricks, both with a width of 10 and height of 5. Let's also say that each of these values are 10 bits. For two bricks, I have the code:

logic[19:0] Brick_Width;
logic[19:0] Brick_Height;

Where the first brick's width and height will be assigned into the most significant 10 bits and the second's in the least significant 10 bits.

This is the code that I currently have for this:

int i = 19;
initial
begin
 for(i=19; i>=0; i=i-10)
 begin
  assign Brick_Width[i:i-9] = 10;
  assign Brick_Height[i:i-9] = 5;
 end
end

However, I get an error saying that "i" is not a constant. Any ideas on how I can go about doing this?

解决方案

Commonly used range-select using : operator must have a constant. Your intent can be accomplished by what is known as bit-select operators.

Referring to example from LRM 1800-2012, section 11.5 as below:

logic [31: 0] a_vect;
logic [0 :31] b_vect;
logic [63: 0] dword;
integer sel;
a_vect[ 0 +: 8] // == a_vect[ 7 : 0]
a_vect[15 -: 8] // == a_vect[15 : 8]
b_vect[ 0 +: 8] // == b_vect[0 : 7]
b_vect[15 -: 8] // == b_vect[8 :15]
dword[8*sel +: 8] // variable part-select with fixed width

The +: and -: operators must be used for bit-slicing or part select as in your case. Here, you want to select a part from i to i-9, so the -: operator must be used. Like Brick_Height[i-:9]=...

For example,

x +: Y, the start position is x and count up from x by Y. Y is necessarily a constant.
x -: Y, the start position is x and count down from x by Y. Y is necessarily a constant.

One more thing, assign statement inside initial block, makes it continuous procedural assignment. The bit-select won't work in that case. To accomplish that, either simply remove assign statement. as follows:

for(i=19; i>=0; i=i-10)
 begin
    Brick_Width[i-:9] = 10; // no assign, rest all the stuff is same
    Brick_Height[i-:9] = 5;
 end

Or use a generate block, if continuous driving is the intent.

genvar i;
generate
for(i=19; i>=0; i=i-10)
begin
    assign Brick_Width[i-:9] = 10;
    assign Brick_Height[i-:9] = 5;
end
endgenerate

More information on bit-select can be found at this link.

SIDE NOTE:

Referring to following phrase in your question:

For two bricks, I have the code:

You must have and array like logic[9:0] Brick [2].

这篇关于systemverilog 中逻辑语句的非常量索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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