在调试Vivado中用户定义的物理类型处理时(阅读更多),我发现了从实数到整数的类型转换有不同的行为。
以下是我的示例代码:
XST似乎使用“四舍五入”模式,并且它处理类型转换的包容性范围检查。因此,我必须使用“整数(-0.5)”而不是“自然数(-0.5)”。
Synth似乎使用了“向无穷取整”的模式,并且它处理类型转换时没有进行范围检查。因此,也许naturall(..)只是integer(..)的别名。
注释行:
Top_PhysicalTest_Simple.vhdl:29:14: file std_logic_1164.v93 has changed and must be reanalysed 我的问题:
以下是我的示例代码:
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;
虚拟触发器用于防止某些工具在设计为空时出现错误。
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"
XST似乎使用“四舍五入”模式,并且它处理类型转换的包容性范围检查。因此,我必须使用“整数(-0.5)”而不是“自然数(-0.5)”。
[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]
Synth似乎使用了“向无穷取整”的模式,并且它处理类型转换时没有进行范围检查。因此,也许naturall(..)只是integer(..)的别名。
注释行:
constant int_2 : INTEGER := natural(-0.5);
不会报错。
GHDL 0.29:
GHDL 0.29在naturall(..)中不进行范围检查。
我知道这已经过时了,但由于0.31版本对我有敌意,我无法确定是否已经修复了这个问题。
GHDL 0.31:
稍后我将介绍结果。GHDL拒绝分析我的代码,因为:Top_PhysicalTest_Simple.vhdl:29:14: file std_logic_1164.v93 has changed and must be reanalysed 我的问题:
- VHDL定义了舍入模式吗?如果是,那么是哪一个?
- 如果没有定义模式,应该如何处理舍入?
ghdl -e ...
打印出了什么 :) 我尝试在我的Linux虚拟机上安装ghdl 0.31,但存在软件包版本不匹配的问题。Debian 8.0(测试版)libgnat-4.9,ghdl需要4.6,但这是另一天的问题... - Paebbels