gpt4 book ai didi

type-conversion - SRA不能有这样的操作数吗?

转载 作者:行者123 更新时间:2023-12-04 06:37:55 31 4
gpt4 key购买 nike

我已经在 VHDL 中编写了一个算法,但是我有一条消息,我不明白“sra/sla 在这种情况下不能有这样的操作数。”。请问有什么帮助吗?

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_arith.conv_std_logic_vector;

entity hsl2rgb is
generic(
constant hue : integer := 85;
constant sat : integer := 127
);
port(
lum : in std_logic_vector(7 downto 0);
ored : out std_logic_vector(5 downto 0);
ogreen : out std_logic_vector(5 downto 0);
oblue : out std_logic_vector(5 downto 0)
);
end entity;

architecture behavioral of hsl2rgb is
begin

process(lum)
variable v : integer;
variable m : integer;
variable sextant : integer;
variable fract : integer;
variable vsf : integer;
variable mid1 : integer;
variable mid2 : integer;
variable lumx : integer;
begin
lumx := to_integer(unsigned(lum));
if (lumx < 127) then
v := (lumx * (256 + sat)) sra 8;
else
v := (((lumx + sat) sla 8) - lumx * sat) sla 8;
end if;

if (v <= 0) then
ored <= (others => '0');
ogreen <= (others => '0');
oblue <= (others => '0');
else
m := (2 * lumx) - v;
sextant := (hue * 6) sra 8;
fract := (hue * 6) - (sextant sla 8);
vsf := (fract * (v - m)) sra 8;
mid1 := m + vsf;
mid2 := v - vsf;

case sextant is
when 0 =>
ored <= conv_std_logic_vector(v, 6);
ogreen <= conv_std_logic_vector(mid1, 6);
oblue <= conv_std_logic_vector(m, 6);
when 1 =>
ored <= conv_std_logic_vector(mid2, 6);
ogreen <= conv_std_logic_vector(v, 6);
oblue <= conv_std_logic_vector(m, 6);
when 2 =>
ored <= conv_std_logic_vector(m, 6);
ogreen <= conv_std_logic_vector(v, 6);
oblue <= conv_std_logic_vector(mid1, 6);
when 3 =>
ored <= conv_std_logic_vector(m, 6);
ogreen <= conv_std_logic_vector(mid2, 6);
oblue <= conv_std_logic_vector(v, 6);
when 4 =>
ored <= conv_std_logic_vector(mid1, 6);
ogreen <= conv_std_logic_vector(m, 6);
oblue <= conv_std_logic_vector(v, 6);
when 5 =>
ored <= conv_std_logic_vector(v, 6);
ogreen <= conv_std_logic_vector(m, 6);
oblue <= conv_std_logic_vector(mid2, 6);
when others =>
ored <= (others => '0');
ogreen <= (others => '0');
oblue <= (others => '0');
end case;
end if;
end process;
end architecture;

最佳答案

对于整数,您必须使用 */运营商。如果它们在正确的位置(即在除法的右侧,乘法的两侧)具有恒定的 2 次幂,则合成器将“做正确的事情”。

或者(正如查尔斯所说)使用 signedunsigned类型来自 ieee.numeric_std library .

顺便说一句,你为什么使用 conv_std_logic_vector当您使用过 ieee.numeric_std ?

ored <= std_logic_vector(to_unsigned(mid1, 6));

应该是你所需要的,然后你就可以摆脱讨厌的 ieee.std_logic_arith图书馆

(旁白:如果您(或此书的 future 读者)的目标是 FPGA(我承认您可能不是,但现在很多人都在:)您可能会发现如果目标频率完全具有挑战性。在简短的眼球综合中,有六个以上的加法器、几个实数乘法器和几个多路复用器——所有这些都在一个时钟周期内。特别是这将排除使用硬我所知道的所有 FPGA 中的乘法器)

关于type-conversion - SRA不能有这样的操作数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4640938/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com