首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SRA不能有这样的操作数吗?

SRA不能有这样的操作数吗?
EN

Stack Overflow用户
提问于 2011-01-10 02:30:11
回答 2查看 3.4K关注 0票数 2

我已经用VHDL编写了一个算法,但是我收到了这样的信息:我不理解"sra/sla在这个上下文中不能有这样的操作数“。有什么需要帮忙的吗?

代码语言:javascript
复制
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;
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-01-10 23:37:48

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

或者(正如Charles所指出的)使用ieee.numeric_std library中的signedunsigned类型。

顺便说一句,既然已经使用了conv_std_logic_vector,为什么还要使用ieee.numeric_std呢?

代码语言:javascript
复制
ored <= std_logic_vector(to_unsigned(mid1, 6));

应该是您所需要的,然后您就可以摆脱讨厌的ieee.std_logic_arith库了

(旁白:如果你(或未来的读者)的目标是FPGA (我承认你可能不是,但现在很多人都是),你可能会发现,如果目标频率是具有挑战性的,那么你可能会发现有必要在某种程度上流水线架构。在简短的眼球综合中,有六个以上的加法器,几个实数乘法器和几个多路复用器-所有这些都在一个时钟周期内。特别是,这将排除在我所知的所有FPGA中使用硬乘法器)

票数 2
EN

Stack Overflow用户

发布于 2011-01-10 08:55:40

问题是,您已经将std_logic_vector I/O转换为整数以执行数学运算,但sra/srl操作数仅适用于位或布尔类型的一维数组。与混合使用std_logic_vectors (没有固有的数值)和整数(没有位向量表示)相比,尝试使用有符号或无符号类型(这是数字的位向量表示)可能会好得多。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4640938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档