IMOこれは属性を要求します:
procedure mul_fixed (
signal a : in unsigned_fixed;
signal b : in unsigned_fixed;
signal c : out unsigned_fixed
) is
constant a_temp : unsigned(a'length - 1 downto 0) := to_unsigned(a);
constant b_temp : unsigned(b'length - 1 downto 0) := to_unsigned(b);
variable result : unsigned(a'length + b'length - 1 downto 0);
-- notice this might be negative if a, b are (? downto +n), which is correct
constant num_fractional : integer := 0 - a'right - b'right;
-- c integral might be bigger than integral/fractional part, make sure we only access valid indices in result
constant result_left : integer := min(result'length - 1, num_fractional + c'left);
constant result_right : integer := max(0 , num_fractional + c'right);
begin
result := a_temp * b_temp;
c <= (others => '0'); -- make sure all bits are defined
c(result_left - num_fractional downto result_right - num_fractional) <= result(result_left downto result_right);
end procedure mul_fixed;
どこ
type unsigned_fixed is array(range <>) of std_logic;
署名されていないものとの間の変換機能が存在します。
だからあなたは
...
signal a : unsigned_fixed( 3 downto -10); -- 4Q10
signal b : unsigned_fixed(-1 downto -8); -- 0Q8
signal c : unsigned_fixed( 3 downto -10); -- 4Q10
mul_fixed(a, b, c);
これらすべての属性が最初は怖いように見えることは知っていますが、データ型が異なるという理由だけで、無意味に多くのパッケージを書いていることに気付くことがよくあります:-/ IMOは、これについて一度考えて、一般的なソリューションを考え出し、次に進む必要があります-それは結局のところ、VHDL属性の目的は何ですか。
- これを書いている間、私はテスト環境にアクセスできなかったので、結果をcに割り当てるときに型変換が必要な場合と必要でない場合があることに注意してください。
また、可能であれば、少なくとも固定小数点ライブラリを確認する必要があります。または、固定小数点パッケージでVHDL-2008を使用します。