VHDL で ALU を作成しようとしていますが、いくつかの操作を実装するのに苦労しています。加算、減算、または演算を実装しましたが、論理シフト演算をどのように実装するのだろうか? ALU は 32 ビットですが、どんなデザインでも構いません。
1 に答える
1
パッケージには、との両方のnumeric_std
論理シフト演算が含まれています。shift_right
shift_left
function SHIFT_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED;
-- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
-- Result: Performs a shift-left on an UNSIGNED vector COUNT times.
-- The vacated positions are filled with '0'.
-- The COUNT leftmost elements are lost.
function SHIFT_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED;
-- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)
-- Result: Performs a shift-right on an UNSIGNED vector COUNT times.
-- The vacated positions are filled with '0'.
-- The COUNT rightmost elements are lost.
したがって、これに基づいて、次のようなコードを簡単に記述できます。
library ieee;
use ieee.numeric_std.all;
architecture syn of mdl is
signal arg : std_logic_vector(31 downto 0);
signal count : std_logic_vector( 4 downto 0);
signal res_r : std_logic_vector(31 downto 0);
signal res_l : std_logic_vector(31 downto 0);
begin
res_r <= std_logic_vector(shift_right(unsigned(arg), to_integer(unsigned(count))));
res_l <= std_logic_vector(shift_left(unsigned(arg), to_integer(unsigned(count))));
end architecture;
これらの操作は合成可能であり、ターゲット デバイスの場合は FPGA リソースに適切にマップされます。
以前は、VHDL シフト/回転演算子に関して混乱がありました。このリンクを参照してください。しかし、VHDL-2008 ではクリーンアップされています。ただし、下位互換性のために、上記の提案は演算子ではなく関数に基づいています。
于 2014-02-03T20:37:49.850 に答える