2017-06-21 46 views
0

我正在嘗試使用ufixed數據類型並將2個固定值加在一起,我已經計算出我應該有足夠的位來存儲結果並且輸出應該能夠被存儲在信號中,但是當我嘗試執行它時,我得到了一個綁定檢查失敗。有人能告訴我爲什麼我得到這個?VHDL Fixed_pkg當添加2個不確定值時獲取綁定檢查失敗

代碼的重要部分是:

-- 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); 

當我模擬這個與ghdl我得到以下結果:在這種情況下

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 

55行是行 InnerProductResult <= InnerProductResult + input*InnerProductArray(counter);

輸入取值0.5,如輸入乘以1.2時得到的值6.00006103515625e-1所示。

值6.00006103515625e^-1 * 2^29是322125824以及這是一個小於2^34的整數,所以它應該適合罰款,我不明白爲什麼這可能是?

+0

6.00006103515625e^-1 * 2^29是322125824以及比2^34所以應該更小的整數。很好,我不明白爲什麼這可能是? – SomeRandomPhysicist

+0

這個問題似乎是我需要通過執行 'InnerProductResult <= InnerProductResult +調整(輸入,34)*調整大小來調整所得到的相加結果(InnerProductArray(計數器),34);' 這樣的結果加法是34位寬。如果這些變量是無符號的,這將起作用,但如果它們是未固定的,則不起作用。我沒有找到與''resize''匹配的重載函數 – SomeRandomPhysicist

+1

您不提供[最小,完整和可驗證的示例](https://stackoverflow.com/help/mcve),而不是識別第55行,不提供一個「input」的值,也不允許讀者複製錯誤信息。 (請注意,textio不是便攜式的 - IEEE Std 1076-2008 Annex D,不保證輸出將如您所示顯示,取決於標準輸出的fflush,這是不能保證的)。對於那些不太願意費力地創建MCVe的人來說,第55行是賦值給'InnerProductResult'。你的代碼片段也有很多尾隨空格。 – user1155120

回答

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                      
    ); 
+0

由於調整大小時需要調整添加和乘法值的結果,因爲它們被放入與自身大小不同的值中,所以我會更新我的答案以使其更清晰。 – SomeRandomPhysicist

+0

在另一個非常相似的一段代碼我有一個類似線,其中我有 'InnerProductResult <= InnerProductResult +輸入* InnerProductArray(計數器);' 凡InnerProductResult是一個34位無符號,輸入和InnerProductArray(計數器)是16位無符號數。在這種情況下,除了存儲的值是整數乘以2的適當冪之外,這些值是相同的。爲什麼在這種情況下調整大小不是必需的? – SomeRandomPhysicist

+0

你剛剛在StackOverflow上提出一個問題來編寫自己的答案? – JHBonarius