2011-06-22 125 views
2

所以,我正在为MIPS架构开发一个ALU,并且我正在尝试左移右移,以便ALU可以移位任意数量的位。右移并左移(SLL/SRL)

我的想法是将shift值转换为整数并选择结果中的条目(整数存储在X中),但Quartus不接受变量值常量。

我该怎么做才能做到这一点? (案件在线“WHEN”1000“=> ...”和“WHEN”1001“=> ...”)

谢谢。

PROCESS (ALU_ctl, Ainput, Binput, X) 
BEGIN 
       -- Select ALU operation 
    --ALU_output_mux <= X"00000000"; --padrao 
CASE ALU_ctl IS 
    WHEN "1000" => ALU_output_mux(31 DOWNTO X) <= (Ainput(31-X DOWNTO 0)); 
    WHEN "1001" => ALU_output_mux(31-X DOWNTO 0) <= (Ainput(31 DOWNTO X)); 
    WHEN OTHERS => ALU_output_mux <= X"00000000"; 
END CASE; 
END PROCESS; 
+0

自从我使用VHDL以来,它已经有3年的时间了,甚至还在Vortex 3板上。你不需要定义电线,输入和输出吗,还是我的记忆力让我失望?我假设Quartus是我的例子中的IDE,我使用了完全不同的东西。 –

回答

0

我在的Quartus曾与这个问题为好,虽然你的代码也有一些隐含的锁存器(你是不是在你的两个移位的情况下分配输出的所有位)。

我使用的解决方法是定义一个包含所有可能结果的中间数组,然后使用您的选择器选择其中一个结果。在你的情况下,类似如下:

subtype DWORD_T   is std_logic_vector(31 downto 0); 
type DWORD_A   is array (natural range <>) of DWORD_T; 
signal shift_L   : DWORD_A(31 downto 0); 
signal shift_R   : DWORD_A(31 downto 0); 
signal zero   : DWORD_T; 

... 

zero <= (others=>'0'); 

process (Ainput) 
begin  
    for index in Ainput'range loop 
     shift_L(index) <= Ainput(31 - index downto 0) & zero(index - 1 downto 0); 
     shift_R(index) <= zero(index - 1 downto 0) & Ainput(31 downto index); 
    end loop; 
end process; 

ALR_output_mux <= shift_L(to_integer(X)) when ALU_ctl="1000", 
        shift_R(to_integer(X)) when ALU_ctl="1001", 
        (others=>'0') when others; 
3

的Quartus如果不喜欢它,你有两个选择:

  1. 写某种方式的Quartus确实喜欢 - 你试图推断桶移位器,所以你可以写出一个longhand然后实例化。可能在时间上很昂贵
  2. 获得一个可以接受它的不同合成器。可能在金钱上很贵。
0

您可以解决此通过使用generatefor创建每个移位/循环水平,或者您可以使用standard functions({平移,旋转} _ {左,右})以切换和旋转。