2016-03-15 41 views
1

我正在制作一个接收32位输入和7位控制输入的组件。这是什么成分做的是,它着眼于S的最后2位和'sra'在VHDL中不工作

  • S = 00,但它留下了INP
  • S = 01逻辑移位,它逻辑右移上INP
  • S = 10,但它确实算术右移在InP上
  • S = 11,但它确实在InP上向右旋转

中位移的量/数由S的前5位例如决定如果S=0001001 ,那么输入必须逻辑移位d右2个地方。以下是我的代码。

发现经营者“SRA”的“0”的定义,不能确定为“SRA” 我的代码的确切超载匹配的定义是::

的问题在“SRA”,其中以下错误表明了未来
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; 
+0

sll工作正常。尽管如此,如果我把该代码,它显示语法错误。 –

回答

4

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

sra没有在-2008之前的IEEE package 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条件语句是互斥的,你可以,如果更换内有一个case语句的语句或者带有elsif替代条件的单个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; 

所有这些代码样本分析。这三种架构尚未被模拟,我们鼓励您这样做以确保操作员按照您的期望做到。

一般来说,您应该使用shift_right,shift_left,向右旋转并将包中numeric_std中定义的左侧函数旋转为PlayDough注释。

4

首先,我建议你使用shift_left()shift_right()rotate_left()rotate_right()功能来代替。在VHDL'87和VHDL'08之间存在已知的问题和可移植性问题(参见here)。

对于numeric_std中的所有类型,未定义“sra”运算符。你必须做一些演员才能获得你想要的东西。但最好使用shift_leftshift_right函数,并且要明确。

还请注意,对于unsigned输入,sra的含义与srl相同。为什么在这种情况下甚至定义了一个sra操作?也许你想要签名输入?

如果你输入的signed,可以srlsra之间做选择:

outp <= signed(shift_right(unsigned(inp), to_integer(samt))); -- srl 
outp <= shift_right(inp, to_integer(samt)); --sra 

(编辑:您还缺少你的过程,它的换挡您rising_edge()检查)

(编辑2:您最好使用case语句来选择您的换档操作。您拥有的if链虽然相互排斥,但不是典型的编码风格,可以使用if/elsif/else或case。)

+0

感谢您指出sra与无符号输入的srl相同。但是现在,如果我将unsigned视为signed,那么我可以尝试进行什么操作? –

+0

'signed'和'unsigned'都与'std_logic'(与'std_logic_vector'相同)的数组相关,因此它们可以相互转换。所以,假设你有'signed'输入。我通过上面的回答编辑来展示一个例子。 – PlayDough