是什么原因导致“VHDL代码中的数据类型没有为运算符'COMPARE'实现?”

时间:2012-10-01 00:37:32

标签: compiler-errors vhdl

我想比较两个变量:

variable E1, E2 : unsigned(5 downto 0);

使用:

if (E1 < E2) then
lt_val := '1';
end if;

但是当我尝试编译时会出现错误。

我不知道我做错了什么。

编辑:这是完整的文件,我将unsigned更改回std_logic_vector并使用了numeric_std库。

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;

entity FPA is
    port (clk, st : in  std_logic;
          d1      : in  std_logic_vector(15 downto 0);
          d2      : in  std_logic_vector(15 downto 0);
          sum     : out std_logic_vector(15 downto 0);
          rdy     : out std_logic);

end FPA;

architecture behav of FPA is

    type state is (s0, s1, s2, s3, s4, s5, s6, s7);
    signal new_state : state;
    signal norm      : std_logic;
    signal lt, gt    : std_logic;

begin

    process is
        variable curr_state : state := s7;
    begin
        if clk = '1' then
            case curr_state is
                when s0 =>
                    if st = '1' then curr_state := s1;
                    end if;
                when s1 =>
                    curr_state := s2;
                when s2 =>
                    if gt = '1' then curr_state := s4;
                    end if;
                    if lt = '1' then curr_state := s3;
                    end if;
                    if not((lt = '1') or (gt = '1')) then
                        curr_state := s5;
                    end if;
                when s3 =>
                    curr_state := s1;
                when s4 =>
                    curr_state := s1;
                when s5 =>
                    if norm = '1' then
                        curr_state := s6;
                    else
                        curr_state := s7;
                    end if;
                when s6 =>
                    curr_state := s7;
                when s7 =>
                    if st = '0' then curr_state := s0;
                    end if;
            end case;
            new_state <= curr_state;
        end if;
        new_state <= curr_state;
        wait on clk;
    end process;

    process is
        variable E1                : std_logic_vector(5 downto 0);
        variable E2                : std_logic_vector(5 downto 0);
        variable sum_val           : std_logic_vector(15 downto 0);
        variable X, Y              : std_logic_vector(11 downto 0);
        variable SGR               : std_logic_vector(11 downto 0);
        variable rdy_val, norm_val : std_logic;
        variable gt_val, lt_val    : std_logic;
    begin

        -- defaults

        rdy_val := '0';
        case new_state is

            when s0 =>
                sum_val := "ZZZZZZZZZZZZZZZZ";
                E1      := d1(15 downto 10);
                X       := "01" & d1(9 downto 0);
                E2      := d2(15 downto 10);
                Y       := "01" & d2(9 downto 0);
            when s1 =>
                if (E1 < E2) then
                    lt_val := '1';
                end if;
                if (E1 > E2) then
                    gt_val := '1';
                end if;
                SGR := X + Y;
            when s2 =>
                if SGR(11) = '1' then
                    norm_val := '1';
                end if;
            when s3 =>
                X  := X ror 1;
                E1 := E1 + "000001";
            when s4 =>
                Y  := Y ror 1;
                E2 := E2 + "000001";
            when s5 =>
            when s6 =>
                SGR := SGR ror 1;
                E2  := E2 + "000001";
            when s7 =>
                sum_val := E2 & SGR(9 downto 0);
                rdy_val := '1';
        end case;

        rdy  <= rdy_val;
        lt   <= lt_val;
        gt   <= gt_val;
        sum  <= sum_val;
        norm <= norm_val;

        wait on new_state;
    end process;

end behav;

3 个答案:

答案 0 :(得分:1)

除非您使用非标准软件包,否则不会为std_logic_vector定义比较运算符。在你提到你所做的更改之前,我不知道你的代码是什么样的,但是现在代码是你应该能够通过更改行来解决这个问题

if (E1<E2) then

if (unsigned(E1) < unsigned(E2)) then

请注意,“+”运算符也没有为std_logic_vector定义,因此无论何时对unsigned和std_logic_vector进行算术运算,都必须在无符号和std_logic_vector之间来回转换E1和E2。在你的情况下,最好将E1和E2定义为unsigned而不是std_logic_vector,只要你使用numeric_std包而不使用IEEE库中的其他非标准包,它应该可以正常工作。 (例如std_logic_unsigned)

答案 1 :(得分:1)

E1E2声明为unsigned是正确的选择,但还不够。

您需要将其他几个变量声明为unsigned,将输入从std_logic_vector动态转换为unsigned,然后将变量sum_val动态转换回std_logic_vector分配输出sum

修补以下几行似乎没问题(至少它在ModelSim中编译):

    variable E1                : unsigned(5 downto 0);
    variable E2                : unsigned(5 downto 0);
    variable sum_val           : unsigned(15 downto 0);
    variable X, Y              : unsigned(11 downto 0);
    variable SGR               : unsigned(11 downto 0);
    -- ...
    E1      := unsigned(d1(15 downto 10));
    X       := unsigned("01" & d1(9 downto 0));
    E2      := unsigned(d2(15 downto 10));
    Y       := unsigned("01" & d2(9 downto 0));
    -- ...
    sum  <= std_logic_vector(sum_val);

答案 2 :(得分:0)

将所有向量更改回unsigned(它们毕竟代表数字)。

如果它仍然没有编译,你可能有一个有缺陷的编译器(它适用于我的Modelsim)