VHDL 生成 STD_LOGIC_VECTORS 的数组并减少长度
VHDL Generate Array Of STD_LOGIC_VECTORS with Reducing Length
我正在尝试创建一个 std_logic_vectors 的数组,减少长度。我尝试使用通用 std_logic_vector 创建一个数组,然后使用生成语句创建向量。
architecture behavioral of dadda_mul_32bit is
type and_planes is array (0 to 31) of std_logic_vector;
begin
generate_and_plane:
for i in 0 to 31 generate
and_planes(i) <= and_vector(a, b(i), i);
end generate generate_and_plane;
end behavioral;
连同 returns 通用的函数 std_logic_vector:
function and_vector(vec: std_logic_vector; x: std_logic; length: natural) return std_logic_vector is
variable result: std_logic_vector(length - 1 downto 0);
begin
for i in 0 to length - 1 loop
result(i) := vec(i) and x;
end loop;
return result;
end function;
我是否错误地使用了 generate 语句?
and_planes
是一个类型而不是一个信号,所以你不能分配给它!
此外,您正在创建一个部分约束的类型,需要在对象(例如信号)声明中对其进行约束。
VHDL 不支持参差不齐的数组。 (其中每个元素大小不同的数组)。如果您需要它进行模拟,您可以使用访问类型并像在 C 中一样模拟参差不齐的数组。如果您需要它进行综合,那么您可以使用一维数组和一些函数来模拟参差不齐的数组来计算嵌套的边界矢量。
看我这个回答:
- VHDL Multidimensional arrays with different internal size
- vhdl port declaration with different sizes
顺便说一句。 VHDL-2008 添加了一个重载:"and"(std_logic, std_logic_vector)
,因此不需要函数来计算单个位与向量中的每一位的与运算。
-- slice 'a' and gate it by 'b(i)'
and_planes(i) <= a(i downto 0) and b(i);
我正在尝试创建一个 std_logic_vectors 的数组,减少长度。我尝试使用通用 std_logic_vector 创建一个数组,然后使用生成语句创建向量。
architecture behavioral of dadda_mul_32bit is
type and_planes is array (0 to 31) of std_logic_vector;
begin
generate_and_plane:
for i in 0 to 31 generate
and_planes(i) <= and_vector(a, b(i), i);
end generate generate_and_plane;
end behavioral;
连同 returns 通用的函数 std_logic_vector:
function and_vector(vec: std_logic_vector; x: std_logic; length: natural) return std_logic_vector is
variable result: std_logic_vector(length - 1 downto 0);
begin
for i in 0 to length - 1 loop
result(i) := vec(i) and x;
end loop;
return result;
end function;
我是否错误地使用了 generate 语句?
and_planes
是一个类型而不是一个信号,所以你不能分配给它!
此外,您正在创建一个部分约束的类型,需要在对象(例如信号)声明中对其进行约束。
VHDL 不支持参差不齐的数组。 (其中每个元素大小不同的数组)。如果您需要它进行模拟,您可以使用访问类型并像在 C 中一样模拟参差不齐的数组。如果您需要它进行综合,那么您可以使用一维数组和一些函数来模拟参差不齐的数组来计算嵌套的边界矢量。
看我这个回答:
- VHDL Multidimensional arrays with different internal size
- vhdl port declaration with different sizes
顺便说一句。 VHDL-2008 添加了一个重载:"and"(std_logic, std_logic_vector)
,因此不需要函数来计算单个位与向量中的每一位的与运算。
-- slice 'a' and gate it by 'b(i)'
and_planes(i) <= a(i downto 0) and b(i);