VHDL操作数在合成期间具有不同的长度误差

问题描述 投票:0回答:1

我有一个代码段,它将两个可变长度向量连接起来,并对结果与另一个固定长度向量进行异或。相关向量的可变长度不影响串联结果的总长度。这是受人尊敬的代码

-- Find the number of bits to be skipped.
-- This is done for better optimization of hardware.
bits2MSB := 15 - findHighestIndex(m_xorResult);

-- If there are sufficient number of remaining bits in the extended data
-- Then we can continue the XOR operation
if(bits2MSB < remainingXorCount) then
    m_xorResult         <= (m_xorResult((15 - bits2MSB - 1) downto 0) & m_dataExtended(remainingXorCount downto (remainingXorCount - bits2MSB))) xor STD_LOGIC_VECTOR(to_unsigned(polynom, 16));
    remainingXorCount   := remainingXorCount - bits2MSB - 1; -- Decrease remainingXorCount

-- If the remaining bit count of the extended data is equal to the number of bits to be skipped until the first HIGH bit
-- Then the last XOR operation for given data can be made.
elsif(bits2MSB = remainingXorCount) then
    m_xorResult         <= (m_xorResult((14 - remainingXorCount) downto 0) & m_dataExtended(remainingXorCount downto 0)) xor STD_LOGIC_VECTOR(to_unsigned(polynom, 16));
    remainingXorCount   := remainingXorCount - bits2MSB;
    state               <= FINISH;

-- If the remaining bits are not sufficient for a new XOR operation 
-- Then the result is equal to the extended version of the last XOR result.
else
    m_xorResult         <= (m_xorResult((14 - remainingXorCount) downto 0) & m_dataExtended(remainingXorCount downto 0));
    remainingXorCount   := 0; -- Decrease remainingXorCount
    state               <= FINISH;
end if;

错误消息指向if语句下面的行。它说

[[Synth 8-509]逻辑运算符'^'的操作数具有不同的长度(40对16)

相关向量的声明如下

variable bits2MSB : integer range 0 to 8 := 0;
variable remainingXorCount : integer range 0 to 7 := 7;
signal m_xorResult : STD_LOGIC_VECTOR(15 downto 0);
signal m_dataExtended : STD_LOGIC_VECTOR(23 downto 0);
variable polynom : natural := 16#1021#;

除了这些以外,函数findHighestIndex(...)可以返回7到15之间的整数值。

给定模块的测试台可以正常工作。我测试了模块的任何给定输入。 Vivado表示,以某种方式,在某些情况下,我可以产生40位向量的长度,并尝试对16位向量的长度进行XOR。您认为问题是什么?

concatenation vhdl xor vivado
1个回答
0
投票

而不是将可变宽度的单词连接成一个固定宽度的单词,您可以将两个固定宽度的单词或在一起,或者将每个可变宽度的位屏蔽掉。

在轮廓上,代替

X"AAAA"(15 downto var) & X"5555"(var-1 downto 0) XOR X"1234";

计算

((X"AAAA" AND upper_mask(var)) OR (X"5555" AND not upper_mask(var))) XOR X"1234";

掩码可以通过这样的函数生成;

function upper_mask(var : natural) return std_logic_vector is
   mask : std_logic_vector(15 downto 0) := (others => '1');
begin
   mask(var - 1 downto 0) := (others => '0');
   return mask;
end;

如果Vivado仍然无法合成upper_mask,则在upper_mask中的所有位上循环应起作用:

for i in mask'range loop
   if i < var then
      mask(i) := '0';
   end if;
end loop
© www.soinside.com 2019 - 2024. All rights reserved.