- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 sfixed(从 ieee.fixed_pkg)转换为 std_logic_vector,我想知道正确的语法是什么以及为什么以下是(显然是错误的)。我尝试编译以下 3 种架构:
library ieee;
use ieee.std_logic_1164.all;
use ieee.fixed_pkg.all;
entity test is
port (input: in sfixed(0 downto -7) := x"00";
output: out std_logic_vector(7 downto 0) := x"00");
end;
架构一:
architecture a of test is begin
output <= std_logic_vector(input);
end;
架构b:
architecture b of test is begin
proc: process (input) begin
output <= std_logic_vector(input);
end process;
end;
架构c:
architecture c of test is begin
proc: process (input) begin
if ('1' and '1') then
output <= std_logic_vector(input);
end if;
end process;
end;
我使用的编译器是“ModelSim ALTERA vcom 10.3d Compiler 2014.10 Oct 7 2014”。架构 a 和 b 不编译并出现错误消息:
Error: [...] Index value -7 (of type std.STANDARD.NATURAL) is out of range 0 to 2147483647.
但是体系结构 c 编译,同时仍然给我警告信息:
Warning: [...] Index value -7 (of type std.STANDARD.NATURAL) is out of range 0 to 2147483647.
所以我的问题是:什么是正确的转换方式,以及为什么上面发布的三种架构之间存在差异?
最佳答案
@BrianDrmmond 讨论的对 std_logic_vector 具有负索引的 sfixed 类型转换导致的范围问题是在标准开发过程中发现的一个问题。对于 GHDL 以外的模拟器来说,这也是一个真正的问题。
因此,包提供了类型转换函数来处理这个问题。要从 sfixed 或 ufixed 转换为 std_logic_vector,请使用 to_slv 和 to_std_logic_vector:
output <= to_slv(input);
要从 std_logic_vector 转换为 sfixed/ufixed,请使用 to_sfixed/to_ufixed 之一。有一个将索引作为参数,另一个将对象作为参数。
signal a_sfixed : sfixed(0 downto -7) := x"00";
signal a_slv : std_logic_vector(7 downto 0) := x"00";
a_sfixed <= to_sfixed(a_slv, 0, -7);
. . .
a_sfixed <= to_sfixed(a_slv, a_sfixed);
是的,您可以使用类型转换(又名转换)代替上述方法进行赋值,但是,如果您想在表达式中使用转换后的值,结果的范围将不正确,因为它是确定的按输入范围。
signal a_sfixed : sfixed(0 downto -7) := x"00";
signal a_slv : std_logic_vector(7 downto 0) := x"00";
signal y_sfixed : sfixed(1 downto -7) := x"00";
y_sfixed <= a_sfixed + to_sfixed(a_slv, 0, -7);
关于vhdl - 在 vhdl 中将 sfixed 转换为 std_logic_vector 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33677920/
我正在尝试将 sfixed(从 ieee.fixed_pkg)转换为 std_logic_vector,我想知道正确的语法是什么以及为什么以下是(显然是错误的)。我尝试编译以下 3 种架构: libr
我是一名优秀的程序员,十分优秀!