简体   繁体   English

如何使MyHDL在过程中生成具有任意宽度的变量?

[英]How to make MyHDL generate variable with arbitrary width in process?

I would like to do a sum of signals that I have in a list, naturally I have used variable and for (as I would in VHDL): 我想对列表中的信号求和,自然地,我使用了变量for和(就像在VHDL中一样):

    @always_comb
    def sum():
        sum = 0
        for i in range(len(summands)):
            sum = sum + summands[i]
        product.next = sum

The problem is that this will use integer (in VHDL) for sum variable, which is not much useful when the width of sum will be more than 32bits. 问题在于,这将对sum变量使用整数(在VHDL中),当sum的宽度大于32位时,它的用处不大。

So I tried to do something like this: 所以我试图做这样的事情:

    @always_comb
    def sum():
        sum = intbv(0, min=vmin, max=vmax)
        for i in range(len(summands)):
            sum = sum + summands[i]
        product.next = sum

I get following error (during conversion): 我收到以下错误(在转换过程中):

    Type mismatch with earlier assignment: sum

Which I don't understand how to work around. 我不知道该如何解决。 I guess it gets the value of intbv in sum as integer and therefore is different type. 我猜它以整数形式获取intbv的值,因此是另一种类型。

Thanks for any suggestion 感谢您的任何建议

I have managed to make very ugly workaround: 我设法做出了非常丑陋的解决方法:

@always_comb
def sum():
    sum = intbv(0, min=vmin, max=vmax)
    for i in range(len(summands)):
        sum = intbv(sum + summands[i], min=vmin, max=vmax)
    product.next = sum

In this manner it will generate correct VHDL: 这样,它将生成正确的VHDL:

IIR_SOS_INST_0_PRODUCTS_1_SUM: process (sos_inst_0_products_1_summands) is
    variable sum: signed(44 downto 0);
begin
    sum := to_signed(0, 45);
    for i in 0 to 21-1 loop
        sum := to_signed((sum + sos_inst_0_products_1_summands(i)), 45);
    end loop;
    sos_inst_0_b1p <= sum;
end process IIR_SOS_INST_0_PRODUCTS_1_SUM;

But the performance of the simulation suffers considerably on creating a new intbv object on every assignment to sum. 但是,在对每个求和的分配上创建一个新的intbv对象时,仿真的性能会受到很大影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM