Vhdl 为什么'to_unsigned(0,4)>;=-1`在运行时计算为`FALSE`?
使用以下测试代码:Vhdl 为什么'to_unsigned(0,4)>;=-1`在运行时计算为`FALSE`?,vhdl,Vhdl,使用以下测试代码: library ieee; use ieee.numeric_std.all; architecture sim of tb is begin process is begin for c in -1 to 1 loop assert to_unsigned(0, 4) >= c report "Fails: 0 >= " & integer'image(c) severity NOTE; end loop; w
library ieee;
use ieee.numeric_std.all;
architecture sim of tb is
begin
process is
begin
for c in -1 to 1 loop
assert to_unsigned(0, 4) >= c report "Fails: 0 >= " & integer'image(c) severity NOTE;
end loop;
wait;
end process;
end architecture;
使用ModelSim 10.5a显示此输出:
Loading work.tb(sim)
** Note: Fails: 0 >= -1
Time: 0 ns Iteration: 0 Instance: /tb
** Note: Fails: 0 >= 1
Time: 0 ns Iteration: 0 Instance: /tb
因此有效地to_unsigned(0,4)>=-1
计算为FALSE
,当我使用for
循环时,这不会在运行时报告。为什么会这样
请注意,如果我在运行时向_unsigned(0,4)>=-1写入
,而不使用for
循环来获取-1
值,那么ModelSim编译器将报告“值-1(std.STANDARD.NATURAL类型)超出范围0到2147483647。”TL/DR:无论您在哪里获得ModelSim的技术支持,请询问这个问题,并用他们的回答更新问题
快速重写和交叉检查(通常非常严格和准确)ghdl模拟器:
library ieee;
use ieee.numeric_std.all;
entity tb is
end tb;
architecture sim of tb is
begin
process is
begin
for c in -1 to 1 loop
assert to_unsigned(0, 4)
>=
c
report "Fails: 0 >= " & integer'image(c) severity NOTE;
end loop;
wait;
end process;
end architecture;
ghdl-结核分枝杆菌
./tb:错误:tb处绑定检查失败。vhd:14
./tb:错误:模拟失败
在计算c
时精确显示绑定检查错误,该错误不在未签名或自然签名的合法范围内
所以问题是,ghdl或Modelsim是否选择了不合适的操作员
numeric_std的源仅显示两个=
运算符定义,其中第一个参数是无符号
。(此文件为“版权所有2008”,适用于VHDL-2008标准。)
这两个参数都不允许将有符号数量(有符号或整数)作为第二个参数
因此,您可能希望查看安装中的numeric\u std
的源代码,看看它是否是一个不同的版本,使用=
运算符允许混合无符号和整数数据类型。我怀疑它的存在:它会很危险地倾向于这种误解
如果没有这样的操作员,Modelsim在这里是允许的;是否有编译选项来启用更严格的法规遵从性
如果你认为这是不必要的学究式的,考虑一下:
c := -1;
if to_unsigned(0, 4) >= c then
emergency_stop;
end if;
IEEE Std 1076-2008 9.3.4函数调用,第5段(部分):函数调用的评估包括对调用中指定的实际参数表达式的评估,以及对与函数的形式参数相关的默认表达式的评估,该函数的形式参数没有与之相关的实际参数。在这两种情况下,结果值应属于相关形式参数的子类型。。。应表示强制要求(1.3.1第4段),尽管Modelsim出于性能目的将其作为可选项。@BrianDrummond:mynumeric_std
软件包中没有额外的=
,如果我在模块或软件包中创建了自己的类似功能,则会立即报告负值。因此,正如@user1155120所建议的那样,它看起来像是ModelSim仅针对numeric\u std
进行的性能优化。我不会试图把这件事告诉Mentor,因为几乎不可能启动ModelSim的支持案例;至少我没有得到应有的关注。
c := -1;
if to_unsigned(0, 4) >= c then
emergency_stop;
end if;