Pae*_*els 6 type-conversion vhdl xilinx xilinx-ise vivado
在调试Vivado中用户定义的物理类型的处理时(更多内容),我发现了从真实到整数的类型转换的不同行为.
这是我的示例代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--use IEEE.MATH_REAL.all;
entity Top_PhysicalTest_Simple is
port (
Clock : in STD_LOGIC;
Input : in STD_LOGIC;
Output : out STD_LOGIC
);
end;
architecture top of Top_PhysicalTest_Simple is
constant int_1 : INTEGER := natural(0.5);
constant int_2 : INTEGER := integer(-0.5);
-- constant int_2 : INTEGER := natural(-0.5);
begin
assert FALSE report "16 - int_1 (natural(0.5)): " & INTEGER'image(int_1) severity note;
assert FALSE report "17 - int_2 (natural(-0.5)): " & INTEGER'image(int_2) severity note;
Output <= Input when rising_edge(Clock);
end;
Run Code Online (Sandbox Code Playgroud)
虚拟触发器用于防止某些工具抱怨空设计.
XST 14.7:
Elaborating entity <Top_PhysicalTest_Simple> (architecture <top>) from library <work>.
Note: "16 - int_1 (natural(0.5)): 1"
Note: "17 - int_2 (natural(-0.5)): 0"
Run Code Online (Sandbox Code Playgroud)
XST似乎使用模式向上舍入,它处理类型转换包括范围检查.所以我必须用integer(-0.5)而不是natural(-0.5).
Vivado 2014.4:
[Synth 8-63] RTL assertion: "16 - int_1 (natural(0.5)): 1" ["D:/Temp/PhysicalTest_Vivado2014.4/vhdl/Top_PhysicalTest_Simple.vhdl":80]
[Synth 8-63] RTL assertion: "17 - int_2 (natural(-0.5)): -1" ["D:/Temp/PhysicalTest_Vivado2014.4/vhdl/Top_PhysicalTest_Simple.vhdl":81]
Run Code Online (Sandbox Code Playgroud)
Synth似乎使用模式舍入到无穷大,它处理类型转换而不进行范围检查.所以也许natural(..)只是一个别名integer(..).
注释行:constant int_2 : INTEGER := natural(-0.5);不会抛出任何错误.
GHDL 0.29:
GHDL 0.29不进行范围检查natural(..).我知道它已经过时了,但是因为0.31讨厌我,我不知道这是否已经修复.
GHDL 0.31:
我稍后会介绍结果.GHDL拒绝分析我的代码,因为:
Top_PhysicalTest_Simple.vhdl:29:14:文件std_logic_1164.v93已更改,必须重新分析
我的问题:
来自IEEE Std 1076-2002第7.3.5节"类型转换"
Run Code Online (Sandbox Code Playgroud)The conversion of a floating point value to an integer type rounds to the nearest integer; if the value is halfway between two integers, rounding may be up or down.
如果你想要别的东西,也许在功能IEEE.MATH_REAL可以将一些使用(特别是中CEIL,FLOOR和/或TRUNC).
| 归档时间: |
|
| 查看次数: |
12871 次 |
| 最近记录: |