gpt4 book ai didi

vhdl - 'sra' 在 VHDL 中不工作

转载 作者:行者123 更新时间:2023-12-05 09:20:47 24 4
gpt4 key购买 nike

我正在制作一个接受 32 位输入和 7 位控制输入的组件。该组件所做的是查看 S 的最后 2 位,并为

  • S = 00,它在 inp 上做逻辑左移
  • S = 01,它在 inp 上做逻辑右移
  • S = 10,对inp进行算术右移
  • S = 11,它确实在 inp 上向右旋转

移位的数量/数量由 S 的前 5 位决定。例如,如果 S=0001001,则输入必须在逻辑上右移 2 位。下面是我的代码。问题出现在出现以下错误的“sra”中:

found '0' definitions of operator "sra", cannot determine exact overloaded matching definition for "sra" My code is:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity barrelshifter is
port(
clk : in std_logic;
inp : in unsigned (31 downto 0):= (others => '0');
s : in unsigned (6 downto 0);
outp : out unsigned (31 downto 0)
);
end barrelshifter;

architecture Behavioral of barrelshifter is
signal samt : unsigned (4 downto 0);
signal stype : unsigned (1 downto 0);
signal inp1 : unsigned (31 downto 0);
begin
samt <= s(6 downto 2);
stype <= s(1 downto 0);
inp1 <= inp;

process(clk)
begin
if stype = "00" then
outp <= inp sll to_integer(samt);
end if;
if stype = "01" then
outp <= inp srl to_integer(samt);
end if;
if stype = "10" then
outp <= inp sra to_integer(samt);
end if;
if stype = "11" then
outp <= inp ror to_integer(samt);
end if;
end process;
end Behavioral;

最佳答案

您的代码可以在 VHDL 中“按原样”使用。

sra 未在 -2008 之前的 IEEE 包 numeric_std 中定义。您的代码将使用符合 -2008 的 VHDL 实现进行分析而不会出错

否则对于先前版本兼容的实现:

outp <= unsigned (to_stdlogicvector(to_bitvector(std_logic_vector(inp)) sra to_integer(samt)));

因为 sra 是为类型 bit_vector 预定义的,而 samt 是类型 unsigned(具有具有自然范围的等效二进制值)。

您还缺少符合条件的时序逻辑综合 RTL 描述 - 未标记的进程在其敏感列表中包含 clk

更改它并在 -2008 之前兼容的 VHDL 实现中显示上述修复:

library ieee;
use ieee.std_logic_1164.all;

use ieee.numeric_std.all;

entity barrelshifter is
port (
clk: in std_logic;
inp: in unsigned (31 downto 0):= (others => '0');
s: in unsigned (6 downto 0);
outp: out unsigned (31 downto 0)
);
end entity barrelshifter;

architecture behavioral of barrelshifter is
signal samt: unsigned (4 downto 0);
signal stype: unsigned (1 downto 0);
signal inp1: unsigned (31 downto 0);
begin
samt <= s(6 downto 2);
stype <= s(1 downto 0);
inp1 <= inp;

UNLABELLED:
process(clk)
begin
if rising_edge(clk) then
if stype = "00" then
outp <= inp sll to_integer(samt);
end if;
if stype = "01" then
outp <= inp srl to_integer(samt);
end if;
if stype = "10" then
outp <= unsigned (to_stdlogicvector(to_bitvector(std_logic_vector(inp)) sra to_integer(samt)));
end if;
if stype = "11" then
outp <= inp ror to_integer(samt);
end if;
end if;
end process;
end architecture behavioral;

因为条件取决于 stype 的 if 语句是互斥的,您可以用 case 语句或带有 elsif 替代条件的单个 if 语句替换内部 if 语句。这将在 stype 的第一个匹配值之后允许条件。

看起来像这样:

architecture with_elsif of barrelshifter is
signal samt: unsigned (4 downto 0);
signal stype: unsigned (1 downto 0);
signal inp1: unsigned (31 downto 0);
begin
samt <= s(6 downto 2);
stype <= s(1 downto 0);
inp1 <= inp;

UNLABELLED:
process(clk)
begin
if rising_edge(clk) then
if stype = "00" then
outp <= inp sll to_integer(samt);
-- end if;
elsif stype = "01" then
outp <= inp srl to_integer(samt);
-- end if;
elsif stype = "10" then
outp <= unsigned (to_stdlogicvector(to_bitvector(std_logic_vector(inp)) sra to_integer(samt)));
-- end if;
elsif stype = "11" then
outp <= inp ror to_integer(samt);
end if;
end if;
end process;
end architecture with_elsif;

或者这个:

architecture with_case of barrelshifter is
signal samt: unsigned (4 downto 0);
signal stype: unsigned (1 downto 0);
signal inp1: unsigned (31 downto 0);
begin
samt <= s(6 downto 2);
stype <= s(1 downto 0);
inp1 <= inp;

UNLABELLED:
process(clk)
begin
if rising_edge(clk) then
case stype is
when "00" =>
outp <= inp sll to_integer(samt);
when "01" =>
outp <= inp srl to_integer(samt);
when "10" =>
outp <= unsigned (to_stdlogicvector(to_bitvector(std_logic_vector(inp)) sra to_integer(samt)));
when "11" =>
outp <= inp ror to_integer(samt);
when others =>
end case;
end if;
end process;
end architecture with_case;

所有这些代码样本分析。这三种架构尚未被模拟,我们鼓励您这样做以确保运算符(operator)按照您的期望进行操作。

通常,您应该使用 numeric_std 包中定义的 shift_right、shift_left、向右旋转和向左旋转函数,如 PlayDough 注释。

关于vhdl - 'sra' 在 VHDL 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36021163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com