我需要取结果的绝对值,我只对最重要的位感兴趣.这就是我所做的:
data_ram_h <= std_logic_vector(abs(signed(resize(r4(calc_cnt - 2), data_ram_h'length) + r4(calc_cnt - 1) +
r4(calc_cnt) + r4(calc_cnt + 1) + r4(calc_cnt + 2) -
r2(calc_cnt - 2) - r2(calc_cnt - 1) - r2(calc_cnt) -
r2(calc_cnt + 1) - r2(calc_cnt + 2))))(11 downto 4);
Run Code Online (Sandbox Code Playgroud)
我尝试检查语法,我收到此错误:
type conversion std_logic_vector is not allowed as a prefix for an slice name.
Run Code Online (Sandbox Code Playgroud)
data_ram_h是正确维度的std_logic_vector,而abs函数返回一个signed,在转换为std_logic_vector时应该没有问题.我使用的库是使用ieee.numeric_std.all.
我哪里错了?在此先感谢c:
类型转换是一个基本操作,恰好需要围绕它的操作数表达式括起来.并且存在问题,它的使用不是函数调用,因此它不能用作切片名称的前缀.
切片名称的前缀是function_call或名称.(IEEE Std 1076-2008,5种类型,5.1通用,显式类型转换,8名称,8.1通用,8.5切片名称).
如果是函数调用,则可以对结果进行切片.
另一方面,你可以切片""abs",所以切片然后进行类型转换:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity slice is
end entity;
architecture foo of slice is
signal h_tmp: signed (11 downto 0);
signal h_tmp_vec: std_logic_vector (11 downto 0);
signal data_ram_h: std_logic_vector(7 downto 0);
signal calc_cnt: integer := 3;
type r_array is array (0 to 15) of unsigned(15 downto 0);
signal r2, r4: r_array := (others => (others => '0'));
begin
data_ram_h<= std_logic_vector (
"abs"(signed(resize(r4(calc_cnt - 2), data_ram_h'length) + r4(calc_cnt - 1) +
r4(calc_cnt) + r4(calc_cnt + 1) + r4(calc_cnt + 2) -
r2(calc_cnt - 2) - r2(calc_cnt - 1) - r2(calc_cnt) -
r2(calc_cnt + 1) - r2(calc_cnt + 2)))(11 downto 4)
);
end architecture;
Run Code Online (Sandbox Code Playgroud)
使用abs函数调用需要使用它的声明名称"abs".
我只是在猜测一些声明,所以我无法保证这在您的代码中有效.以上示例进行了分析,详细说明和运行,其中说明子类型范围是兼容的.