2016-03-15 42 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