2011-06-22 248 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({平移,旋轉} _ {左,右})以切換和旋轉。