无法在2D阵列中存储SystemVerilog模块的输出

时间:2018-03-08 17:14:02

标签: arrays verilog system-verilog

我有一个SystemVerilog模块 mFunc ,描述如下:

module mFunc #(parameter N = 1, parameter W=1)
        (input logic signed [W:0] x[N],
         output logic signed [W:0] Cx[N]);

always_comb 
  for(int k=0; k<N; k++)
    Cx[k] = N-x[k];

endmodule: mFunc

mFunc2 模块调用 mFunc

module mFunc2 #(parameter N = 1, parameter W=1)
         (input logic signed [W:0] x[N][N],
          output logic signed [W:0] Cx[N][N]);

logic signed [W:0] x_rows[N];
logic signed [W:0] C_rows[N]; 

mFunc #(.N(N), .W(W)) mFunc_rows(.x(x_rows), .Cx(C_rows));

always_comb begin
  for(int k=0; k<N; k++) begin
    for(int j=0; j<N; j++)begin
      x_rows[j] = x[k][j];
      Cx[k][j] = C_rows[j]; 
    end
  end 
end

endmodule: mFunc2

当我运行模拟时,模块的行为如图1所示, mFunc 的输出( C_rows )未正确存储在 Cx中,只保存 C_rows 的最后一个值,如图1所示。

请有人帮我解决这个问题吗?

Figure 1: Statement of the problem

以下是EDA Playground

中模拟的链接

谢谢。

1 个答案:

答案 0 :(得分:0)

您只看到填充整个矩阵的最后一行的原因是您实现mFunc2模块的方式。在其中,您有一个组合逻辑,其中包含一个for循环,将Cx[k]分配给C_rows,转换为x_rows分配给x[N-1]。然后,mFunc模块中的逻辑可以将x_rows转换为C_rowsx[N-1]。最后,mFunc2中的组合逻辑再次运行,将Cx的所有行分配给C_rows

从综合预测中考虑它,您只是实例化一个mFunc模块,这意味着将行从x转换为Cx的逻辑仅存在于单个N行。由于您没有时钟或其他同步机制,因此无法将单行馈送到模块中并获取其结果,然后在尝试使用for循环时输入下一行。要使设计以组合方式工作,您必须在设计中创建足够的资源来完成任务。在这种情况下,这意味着拥有N(因为有mFunc行)mFunc个模块,每行一个。否则,您可以在N周期的mFunc2周期内将时钟和Feed一行引入mFunc

纯粹的组合路径相对容易,因为你需要对generate模块做的所有事情都要在其中实例化更多module mFunc2 #(parameter N = 1, parameter W=1) (input logic signed [W:0] x[N][N], output logic signed [W:0] Cx[N][N]); // Here, we make use of arrays of modules to make N instantiations of mFunc // Note the [N] next to the mFunc_rows, meaning we are declaring an array // of mFunc modules, ie N of them. These can be hooked up to the unpacked // arrays x and Cx directly and will produce the desired output in Cx mFunc #(.N(N), .W(W)) mFunc_rows[N](.x(x), .Cx(Cx)); endmodule: mFunc2 。您可以使用W循环执行此操作,或者您可以使用适合您的情况的数组模块:

x

快速注意,如果您希望Cxlogic signed [W-1:0]logic signed [W:0]中值的位宽,则需要将它们声明为W+1而不是[7:0] {1}}后者将生成长度为[8:0]的变量。例如,一个字节为android { defaultConfig { vectorDrawables.useSupportLibrary = true } } ,而不是$("option").data(name);,因为它有8位。

相关问题