3

これが私の問題です。組み合わせロジックを使用して、16 ビットの左/右論理/算術シフト コンポーネントを最初から設計する必要があります (std_logic_vector と std_logic を使用する場合を除く)。

ここに私が持っているものがあります:

library ieee;
use ieee.std_logic_1164.all;

entity Shift16 is
    port
    (
        -- Input ports
        I       : in std_logic_vector(15 downto 0);
        Shift   : in std_logic_vector(3 downto 0);

        -- Sel(1) == 0 -> Logical ; Sel(0) == Left
        Sel : in std_logic_vector(1 downto 0);

        -- Output ports
        O       : out std_logic_vector(15 downto 0)
    );
end Shift16;

architecture Struct of Shift16 is
component Mux16to1 is
    port (I :   in std_logic_vector(15 downto 0);
            S   :   in std_logic_vector(3 downto 0);
            O   :   out std_logic);
end component;

component Mux2to1_16 is
    port
    ( A, B : in  std_logic_vector(15 downto 0); S : in  std_logic;
      Q : out std_logic_vector(15 downto 0) );
end component;

signal OLeft, ORight : std_logic_vector(15 downto 0);

signal PadVal   : std_logic;

type gen_signal is array (15 downto 0) of std_logic_vector(15 downto 0);

signal leftPad, rightPad : gen_signal;

begin

    process (I, Sel)
    begin
        if (Sel(0) = '0') then -- logical
            PadVal <= '0';
        else 
            PadVal <= I(15); -- aritmetic
        end if;

        for j in 15 downto 0 loop
            for k in j downto 0 loop
                leftPad(j, k) <= I(15-j);
                rightPad(j, k) <= PadVal;
            end loop;

            for k in 15 downto j+1 loop 
                leftPad(j, k) <= PadVal;
                rightPad(j, k) <= I(15-j);
            end loop;
        end loop;
    end process;



    muxarr_left_shift: for index in 15 downto 0 generate
    begin  
        mux: Mux16to1 port map (leftPad(index), Shift, OLeft(index));
    end generate;

    muxarr_right_shift: for index in 15 downto 0 generate
    begin
        mux: Mux16to1 port map (rightPad(index), Shift, ORight(index));
    end generate;   

    OutputMux: Mux2to1_16 port map (ORight, OLeft, Sel(1), O);

end Struct;

コンポーネントは、Muxまさに私のカスタム バージョンです。

私の最初のアイデアは、16 個の 16 対 1 の Mux を使用し、それらを配線して、シフト量がそれぞれの選択になるようにすることでした。これは非常に高速ですが、何らかの理由でコードがコンパイルされません。

私もこれを複雑にしすぎていると思います.

コンパイルエラーは次のとおりです。Error (10382): VHDL error at Shl16.vhd(52): index of object of array type gen_signal must have 1 dimensions

4

2 に答える 2

1

変更する必要があると思います:

    for j in 15 downto 0 loop
        for k in j downto 0 loop
            leftPad(j, k) <= I(15-j);
            rightPad(j, k) <= PadVal;
        end loop;

        for k in 15 downto j+1 loop 
            leftPad(j, k) <= PadVal;
            rightPad(j, k) <= I(15-j);
        end loop;
    end loop;

    for j in 15 downto 0 loop
        for k in j downto 0 loop
            leftPad(j)(k) <= I(15-j);
            rightPad(j)(k) <= PadVal;
        end loop;

        for k in 15 downto j+1 loop
            leftPad(j)(k) <= PadVal;
            rightPad(j)(k) <= I(15-j);
        end loop;
    end loop;

あなたの型宣言のため。

type gen_signal is array (15 downto 0) of std_logic_vector(15 downto 0);

P/s: 割り当てをループで保持したい場合は、タイプを次のように変更してください:

type gen_signal is array (15 downto 0, 15 downto 0) of std_logic;

しかし、ポートマップには適していないと思います。したがって、上記の方法を使用する必要があります。Questasim 10.0b で最初の方法を確認しました。

P/S (再度): 私はあなたのコードを注意深く読み、見つけました:

process (I, Sel)

機密リストは、希望以外のループには適していない場合がありますlatch。2つのプロセスに分割する必要があると思います。

于 2012-10-16T06:37:56.683 に答える
0

次のようなものはどうですか:

process (all) is
    variable shift_bits : integer;
begin
    shift_bits := to_integer(unsigned(shift));
    O <= (others => '0');            -- fill with padding first - stop latch
    if sel(0) = '1' then                 -- left shift
        O(O'high downto - O'high-shift_bits) <=
            I(shift_bits-1 downto 0);
    else                                 -- right shift
        if sel(1) = '1' then             -- if arithmetic
            O <= (others => I(I'high));  -- pad with sign bit
        end if;
        O(shift_bits-1 downto 0) <=
            I(I'high downto i'high-shift_bits);
    end if;
end process;

67 個の LUT6 への合成


別のコメント - 何が起こっているのかを説明するためにコメントを入れる必要がないように、制御ビットが明示的に定義されていないのはなぜですか。

entity Shift16 is
    port
    (
        I             : in std_logic_vector(15 downto 0);
        Shift_count   : in unsigned(3 downto 0);
        shift_logical : in std_logic;
        shift_right  : in std_logic;

        O       : out std_logic_vector(15 downto 0)
    );
end Shift16;
于 2012-10-16T12:23:28.813 に答える