Trying to verify Verilog/VHDL designs with formal methods and tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity alu is
  5. generic (
  6. Width : natural := 8
  7. );
  8. port (
  9. Reset_n_i : in std_logic;
  10. Clk_i : in std_logic;
  11. Opc_i : in std_logic_vector(1 downto 0);
  12. DinA_i : in std_logic_vector(Width-1 downto 0);
  13. DinB_i : in std_logic_vector(Width-1 downto 0);
  14. Dout_o : out std_logic_vector(Width-1 downto 0);
  15. OverFlow_o : out std_logic
  16. );
  17. end entity alu;
  18. architecture rtl of alu is
  19. subtype t_opc is std_logic_vector(Opc_i'length-1 downto 0);
  20. constant c_add : t_opc := "00";
  21. constant c_sub : t_opc := "01";
  22. constant c_and : t_opc := "10";
  23. constant c_or : t_opc := "11";
  24. begin
  25. process (Reset_n_i, Clk_i) is
  26. begin
  27. if (Reset_n_i = '0') then
  28. Dout_o <= (others => '0');
  29. elsif (rising_edge(Clk_i)) then
  30. case Opc_i is
  31. when c_add => (OverFlow_o, Dout_o) <=
  32. std_logic_vector(resize(unsigned(DinA_i), Dout_o'length+1) +
  33. resize(unsigned(DinB_i), Dout_o'length+1));
  34. when c_sub => (OverFlow_o, Dout_o) <=
  35. std_logic_vector(resize(unsigned(DinA_i), Dout_o'length+1) -
  36. resize(unsigned(DinB_i), Dout_o'length+1));
  37. when c_and => Dout_o <= DinA_i and DinB_i;
  38. when c_or => Dout_o <= DinA_i or DinB_i;
  39. when others => null;
  40. end case;
  41. end if;
  42. end process;
  43. end architecture rtl;