【问题标题】:Verilog: Altenative way for indexing signal on the LHSVerilog:在 LHS 上索引信号的替代方法
【发布时间】:2016-03-09 22:53:54
【问题描述】:

我正在使用 Xilinx,它使用 XST 来综合我的设计。我在写someReg[offest*index+:constant] <= someOtherReg; 之类的东西时遇到了麻烦。给出的错误是“信号中不支持变量索引。”我在网上搜索后收集到的是 XST 综合工具不支持索引左侧的信号。


我想知道的是如何在不使用该语法的情况下实现索引信号的逻辑。在下面的示例中,我正在创建一个重用“rowByColumn”乘数的矩阵乘数。


基本上在每个时钟上升沿,我都会将新值加载到“rowByColumn”乘法器的输入端,并在下一个时钟上升沿将结果保存在新寄存器中。将结果保存在新寄存器中是我遇到的主要问题。


这是给出错误的代码。您能否就解决或解决问题的方法提出建议。

module MatrixSeq(clk,A,B,C);
    // param
    parameter WIDTH = 32;
    parameter ROW_A  = 2;
    parameter COL_A  = 2;
    parameter ROW_B  = 2;
    parameter COL_B  = 2;
    //ports
    input clk;
    input [WIDTH*COL_A*ROW_A-1:0] A;
    input [WIDTH*COL_B*ROW_B-1:0] B;
    output [WIDTH*ROW_A*COL_B-1:0] C;

    // inputs to rowBycol 
    reg signed [WIDTH*COL_A-1:0] currentRowA;
    reg signed [WIDTH*ROW_B-1:0] currentColB;
    reg signed [WIDTH-1:0] rowByColOut;
    wire signed [WIDTH-1:0] rowByColOutWire; // wire to connet to rowByColOut

    // A,B matrix holders
    reg signed [WIDTH*COL_A*ROW_A-1:0] AsigHolder;
    reg signed [WIDTH*COL_B*ROW_B-1:0] BsigHolder;
    reg signed [WIDTH*ROW_A*ROW_B-1:0] CsigHolder; // C = A*B

    // reg signed [WIDTH-1:0] count;
    integer idxA = 0;       // iterates through the rows of A
    integer idxB = 0;       // iterates through the 'rows' of B

    // Indexing Syntax:
    //  signalAdd[some_expression +: some_range];
    //  Resolves to
    //  signalAdd[some_expression + (some_range - 1) : some_expression];

    always @(posedge clk) begin     // assume we have the transpose of matrix B
        currentRowA <= AsigHolder[WIDTH*COL_A*idxA+:WIDTH*COL_A];
        currentColB <= BsigHolder[WIDTH*COL_B+idxB+:WIDTH*COL_B];
        CsigHolder[WIDTH*(idxA*ROW_A+idxB)+:WIDTH] <= rowByColOut;  // Error: 'Variable index is not supported in signal.'
        idxB <= idxB +1;
        if(idxB == ROW_B) begin     // multiply each row of A with every 'row' B
            idxA <= idxA + 1;
            idxB <= 0;
        end else if(idxA == ROW_A) begin
            idxA <= 0;
            idxB <= 0;
        end
    end
    assign rowByColOutWire = rowByColOut;
    rowBycol rowMultColumn (.CLK(clk), .a(currentRowA), .b(currentColB), .y(rowByColOutWire));  // row by column multiplier
    assign C = CsigHolder;

endmodule

为了清楚起见,问题是 always 块内的第三行给出错误“信号中不支持变量索引。”

【问题讨论】:

    标签: indexing verilog xilinx hdl xilinx-ise


    【解决方案1】:

    如果 XST 不支持部分选择 (+:/-:) 并且您无法升级到符合 IEEE Std 1364-2001 的内容,那么您将需要使用 1995 方法;位赋值:

    for(bit_idx = 0; bit_idx < WIDTH*COL_A; bit_idx=bit_idx+1) begin
      currentRowA[idx] <= AsigHolder[WIDTH*COL_A*idxA + bit_idx];
    end
    

    或者二维数组:

    reg signed [WIDTH*COL_A-1:0] AsigHolder [0:ROW_A-1];
    ...
    
    always @(posedge clk) begin     // assume we have the transpose of matrix B
      currentRowA <= AsigHolder[idxA];
    

    我注意到您的 idxA 和 idxB 可能超出范围。所有分配有非阻塞 (&lt;=) 的寄存器在评估后都会更新。这意味着 idxB==ROW_B 将在 idxB &lt;= idxB +1 更新之前进行评估。
    您应该有类似以下的内容:

    if (idxB < ROW_B-1) begin
      idxB <= idxB + 1;
    end
    else begin
      idxB <= 0;
      if (idxA < ROW_A-1) begin
        idxA <= idxA + 1;
      end
      else begin
        idxA <= 0;
      end
    end
    

    注意:通过修复索引分配,部分选择 (+:/-:) 可能会起作用,因为设计无法超出界限索引。

    【讨论】:

    • 感谢您注意到idxA 和idxB 可能超出范围。 XST 只在这条线上抱怨 CsigHolder[WIDTH*(idxA*ROW_A+idxB)+:WIDTH] &lt;= rowByColOut; 。我将尝试使用“二维”数组,看看它是否可以合成。
    • 我这样定义 CsigHolder reg signed [WIDTH-1:0] CsigHolder [0:ROW_A*COL_B-1];。当我尝试使用类似assign C = CsigHolder; 的分配语句将线C 连接到CsigHolder 时,XST 给出错误。我应该如何将C 连接到CsigHolder?
    猜你喜欢
    • 2017-05-02
    • 2022-01-13
    • 2012-06-18
    • 1970-01-01
    • 2016-08-09
    • 2015-01-11
    • 2019-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多