2

32ビットの入力と7ビットの制御入力を取り込む部品を作っています。このコンポーネントが行うことは、S の最後の 2 ビットを調べて、

  • S = 00、inp を左に論理シフトします
  • S = 01、inp を右に論理シフトします
  • S = 10、inp で算術シフトを行います
  • S = 11、inp 上で右回転します

シフトの量/数は、S の最初の 5 ビットによって決定されます。たとえば、 の場合S=0001001、入力は論理的に右に 2 桁シフトする必要があります。以下は私のコードです。次のエラーが表示される「sra」で問題が発生しています。

演算子「sra」の「0」定義が見つかりました。「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;
4

2 に答える 2

4

コードは 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;

条件が依存する if ステートメントstypeは相互に排他的であるため、内側の if ステートメントを case ステートメントに置き換えるか、単一の if ステートメントを elsif 代替条件に置き換えることができます。これにより、 の最初の一致値の後に条件が許可されます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;

これらのコード サンプルはすべて分析します。3 つのアーキテクチャはまだシミュレートされていません。オペレーターが期待どおりに動作することを確認するために、シミュレートすることをお勧めします。

一般に、PlayDough のメモとしてパッケージ numeric_std で定義されている shift_right、shift_left、rotate right、rotate left 関数を使用する必要があります。

于 2016-03-15T23:23:37.840 に答える