【问题标题】:Shift unit in VHDLVHDL中的移位单元
【发布时间】:2015-05-03 18:15:08
【问题描述】:

作为 FPGA 课程 alu 设计的一部分,我需要构建一个能够进行左移和右算术移位的移位单元。

我编写了一些 VHDL 代码,在 ModelSim 中对其进行了仿真,并且运行良好。下一步是为 FPGA (ALTERA DE1) 编译它。现在 ALU 的所有其他操作都可以正常工作,但移位单元却不行。对于与移位相关的操作码,输出保持等于输入。

entity Shift is
    generic (
        N : integer := 8 );
    port (
        A,B:in std_logic_vector(N-1 downto 0);
        OP: in std_logic_vector(2 downto 0);
        Enable: in std_logic;
        shiftedA:out std_logic_vector(N-1 downto 0));
end Shift;

architecture rtl of Shift is
begin
    shift_process: process (Enable,op,A,B)
        variable TempVec : std_logic_vector(N-1 downto 0) ;--:= (others => '0');
        variable inVector : std_logic_vector(N-1 downto 0);
        variable bitNum : Integer;
    begin
        inVector:=A;
        TempVec:=A;
        bitNum := conv_integer(B);
        test <= "00000000";
        if Enable = '1' then

            if OP = "100" then
                for i in 1 to bitNum loop
                    TempVec := TempVec(N-2 downto 0) & "0";
                end loop ;

            elsif OP = "101" then
                for j in 1 to bitNum loop
                    TempVec := A(N-1) & TempVec(N-1 downto 1);
                end loop;
            else
                TempVec := (others => '0');
            end if;
        else
            TempVec := (others => '0');
        end if;
        shiftedA <= TempVec;
    end process;
end rtl;

我做错了什么?

【问题讨论】:

  • VHDL 有移位功能,应该合成一个高效的桶形移位器。或者制作自己的桶形移位器。但是您想在 log(N) 步中进行,而不是 N 步,并且绝对不是您当前的方法,即 2^N
  • 您的代码示例有一个错误,test 没有声明,您可以注释掉它的赋值。未使用 shift_process 中的变量 inVector。您没有显示您的上下文子句,而只使用来自 Synopsys 包 std_logic_arith 的conv_integer,这似乎需要将B 类型转换为unsigned。正如 Ben 所说,消除元素循环也可以减少对 TempVec 的需求。

标签: vhdl fpga intel-fpga


【解决方案1】:

for i in 1 to bitNum loop 这样的循环在综合中展开以作为电路实现,但在这种情况下,循环的结束条件取决于数据,因为bitNumconv_integer(B),因此转换为硬件是一个问题.模拟器可以处理这种结构,因为它们不会转换成电路。

可能有一个综合警告说明了这一点,因此请检查警告,因为有些警告实际上是相关的。

说得更多会破坏一个好的练习...... ;-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 2016-09-02
    相关资源
    最近更新 更多