【发布时间】: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