Advertisement
Guest User

Operazioni

a guest
Nov 18th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.65 KB | None | 0 0
  1. -------------------------------------------------------------------------------
  2. --
  3. -- Title       : operazioni
  4. -- Design      : compito
  5. -- Author      : Mario
  6. -- Company     : UNICT
  7. --
  8. -------------------------------------------------------------------------------
  9. --
  10. -- File        : d:\My_Designs\07_02_2017_es2_2\compito\src\operazioni.vhd
  11. -- Generated   : Sat Nov 18 14:59:45 2017
  12. -- From        : interface description file
  13. -- By          : Itf2Vhdl ver. 1.22
  14. --
  15. -------------------------------------------------------------------------------
  16. --
  17. -- Description :
  18. --
  19. -------------------------------------------------------------------------------
  20.  
  21. --{{ Section below this comment is automatically maintained
  22. --   and may be overwritten
  23. --{entity {operazioni} architecture {operazioni}}
  24.  
  25. library IEEE;
  26. use IEEE.STD_LOGIC_1164.all;
  27. use IEEE.STD_LOGIC_signed.all;
  28. use IEEE.STD_LOGIC_arith.all;
  29.  
  30. entity operazioni is
  31.      port(
  32.          start : in STD_LOGIC;
  33.          clk : in STD_LOGIC;
  34.          Din : in STD_LOGIC_VECTOR(31 downto 0);
  35.          fine : out STD_LOGIC;
  36.          Dout : out STD_LOGIC_VECTOR(31 downto 0)
  37.          );
  38. end operazioni;
  39.  
  40. --}} End of automatically maintained section
  41.  
  42. architecture operazioni of operazioni is
  43.  
  44. type stati is (idle, decode, exelw, exeand, exeadd, exeshl);
  45. type reg is array(0 to 3) of STD_LOGIC_VECTOR(31 downto 0);
  46. signal state: stati;
  47. signal R: reg;
  48. signal OP: STD_LOGIC_VECTOR(7 downto 0);
  49. signal A: STD_LOGIC_VECTOR(31 downto 0);       
  50. signal cicli: INTEGER range 0 to 2;  
  51. signal enop, endecode, enexelw, enexeand, enexeadd, enexeshl: STD_LOGIC;
  52.  
  53. function nextstate(state: stati; start: STD_LOGIC; op: STD_LOGIC_VECTOR(1 downto 0); A: STD_LOGIC_VECTOR(31 downto 0); cicli: INTEGER range 0 to 2)
  54. return stati
  55. is
  56. variable nxt: stati;
  57. begin
  58.     case state is
  59.         when idle => if start = '1' then nxt := decode;
  60.         else nxt := idle;
  61.         end if;
  62.        
  63.         when decode =>
  64.             case op is
  65.                 when "00" => nxt := exelw;
  66.                 when "01" => nxt := exeand;
  67.                 when "10" => nxt := exeadd;
  68.                 when "11" => nxt := exeshl;
  69.                 when others => null;
  70.             end case;
  71.        
  72.         when exelw => nxt := idle;     
  73.         when exeand => nxt := idle;
  74.        
  75.         when exeadd => if cicli < 2 and conv_integer(A) /= 0 then nxt := exeadd;
  76.         else nxt := idle;
  77.         end if;
  78.        
  79.         when exeshl => if cicli < 1 then nxt := exeshl;
  80.         else nxt := idle;
  81.         end if;
  82.        
  83.     end case;
  84.     return nxt;
  85. end nextstate;
  86.  
  87. function aluoperation(op: STD_LOGIC_VECTOR(1 downto 0); R: reg; A: STD_LOGIC_VECTOR(31 downto 0); s1, s2: INTEGER range 0 to 3)
  88. return STD_LOGIC_VECTOR
  89. is   
  90. variable tmp: STD_LOGIC_VECTOR(31 downto 0);
  91. begin
  92.     case op is
  93.         when "00" => tmp := A;
  94.         when "01" => tmp := R(s1) and R(s2);
  95.         when "10" => tmp := R(s1) + A;
  96.         when "11" => tmp := shl(R(s1), R(s2));
  97.         when others => null;
  98.     end case;
  99.     return tmp;
  100. end aluoperation;
  101.  
  102. begin
  103.  
  104.     -- UNITA' DI CONTROLLO --
  105.    
  106.     process(clk)
  107.     begin    
  108.         if clk'event and clk = '0' then
  109.             state <= nextstate(state, start, OP(1 downto 0), A, cicli);
  110.         end if;
  111.     end process;
  112.    
  113.     -- ENABLE --
  114.    
  115.     enop <= '1' when state = idle and start = '1' else '0';
  116.     endecode <= '1' when state = decode else '0';
  117.     enexelw <= '1' when state = exelw else '0';
  118.     enexeand <= '1' when state = exeand else '0';
  119.     enexeadd <= '1' when state = exeadd else '0';
  120.     enexeshl <= '1' when state = exeshl else '0';
  121.        
  122.     -- DATAPATH --
  123.    
  124.     process(clk)
  125.     variable s1, s2, d: INTEGER range 0 to 3;
  126.     begin      
  127.         if clk'event and clk = '0' then
  128.             if enop = '1' then
  129.                 op <= din(7 downto 0);
  130.                 cicli <= 0;
  131.             end if;
  132.            
  133.             if endecode = '1' then
  134.                 if op(0) = '0' then
  135.                     A <= din;
  136.                 end if;
  137.                 d := conv_integer(unsigned(op(7 downto 6)));
  138.                 s1 := conv_integer(unsigned(op(5 downto 4)));
  139.                 s2 := conv_integer(unsigned(op(3 downto 2)));
  140.             end if;  
  141.            
  142.             if enexelw = '1' or enexeand = '1' then
  143.                 dout <= aluoperation(op(1 downto 0), R, A, s1, s2);
  144.                 r(d) <= aluoperation(op(1 downto 0), R, A, s1, s2);
  145.             end if;
  146.            
  147.             if enexeadd = '1' then
  148.                 if cicli = 2 or conv_integer(A) = 0 then
  149.                     dout <= aluoperation(op(1 downto 0), R, A, s1, s2);
  150.                     r(d) <= aluoperation(op(1 downto 0), R, A, s1, s2);
  151.                 else
  152.                     cicli <= cicli + 1;
  153.                 end if;
  154.             end if;
  155.                
  156.             if enexeshl = '1' then
  157.                 if cicli = 1 then
  158.                     dout <= aluoperation(op(1 downto 0), R, A, s1, s2);
  159.                     r(d) <= aluoperation(op(1 downto 0), R, A, s1, s2);
  160.                 else
  161.                     cicli <= cicli + 1;
  162.                 end if;
  163.             end if;
  164.            
  165.             if enexelw = '1' or
  166.                 enexeand = '1' or
  167.                 (enexeadd = '1' and (cicli = 2 or conv_integer(A) = 0)) or
  168.                 (enexeshl = '1' and cicli = 1) then
  169.                 fine <= '1';
  170.             else
  171.                 fine <= '0';
  172.             end if;
  173.         end if;
  174.     end process;
  175. end operazioni;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement