1

I am attempting to used the ufixed datatype and add 2 ufixed values together, I have calculated I should have enough bits to store the result and the output should be able to be stored in the signal, but when I attempt to perform it I get a bound check failure. Can someone tell me why I am getting this?

The important parts of the code are:

-- definition of parameters used in the failing calculation

input : in ufixed(0 downto -15); -- Q1.15

constant VectorLength : integer := 3;
type vector_ufixed is array(0 to VectorLength-1) of ufixed(1 downto -14);

constant InnerProductArray : vector_ufixed := (to_ufixed(1.2,1,-14), to_ufixed(1.0,1,-14), to_ufixed(0.2,1,-14));

signal InnerProductResult : ufixed(4 downto -29); -- Q5.29

signal counter : integer := 0;


write(l, real'image(to_real(InnerProductResult)));
write(l, string'(", "));
write(l, real'image(to_real(InnerProductResult + input*InnerProductArray(counter))));
writeline(output, l);
InnerProductResult <= InnerProductResult +                                                                            
                      input*InnerProductArray(counter);

When I simulate this with ghdl I get the following result:

0.0, 6.00006103515625e-1
ghdl:error: bound check failure at InnerProduct.vhd:55
  from: process work.innerproduct(innerproductarchitecture).P0 at InnerProduct.vhd:55
ghdl:error: simulation failed

line 55 in this case is the line InnerProductResult <= InnerProductResult + input*InnerProductArray(counter);

input takes the value 0.5, as can be observed from the resulting value of 6.00006103515625e-1 when input is multiplied by 1.2.

The value 6.00006103515625e^-1*2^29 is 322125824 as well which is an integer less than 2^34 so it should fit fine, I don't understand why this might be?

4

1 回答 1

0

在这种情况下执行诸如加法和乘法之类的算术运算时,有必要调整运算结果的大小以适合其存储位置。在这种情况下,我们将一个 34 位数字添加到 2 个 16 位数字中,因此我们需要将结果调整为 34 位宽,以便精确地适合存储位置,即 InnerProductResult。

fixed_pkg 中调整大小的语法似乎与 numeric_std 中用于有符号和无符号数的语法不同。以下语法对于使用 fixed_pkg 完成的操作是必需的,可在http://www.klabs.org/mapld05/presento/189_lewis_p.pdf中找到:

InnerProductResult <= resize(                                                                                         
    arg => InnerProductResult + input*InnerProductArray(counter),                                                       
    size_res => InnerProductResult                                                                                      
    ); 
于 2017-06-21T18:09:12.553 回答