alu: erster (schlechter) versuch -- sim haut auch halbwegs hin
[hwmod.git] / src / alu.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4 use work.gen_pkg.all;
5
6 entity alu is
7         port
8         (
9                 sys_clk : in std_ulogic;
10                 sys_res_n : in std_ulogic;
11                 opcode : in alu_ops;
12                 op1 : in signed(31 downto 0);
13                 op2 : in signed(31 downto 0);
14                 op3 : out signed(31 downto 0);
15                 do_calc : in std_ulogic;
16                 calc_done : out std_ulogic
17         );
18 end entity alu;
19
20 architecture beh of alu is
21         -- signal cnt_int, cnt_next : integer range 0 to CNT_MAX;
22         signal op3_next : signed (31 downto 0);
23 begin
24         process(sys_clk, sys_res_n)
25         begin
26                 if sys_res_n = '0' then
27                         op3 <= (others => '0');
28                 elsif rising_edge(sys_clk) then
29                         op3 <= op3_next;
30                 end if;
31         end process;
32
33         process(do_calc, opcode, op1, op2)
34         begin
35                 case opcode is
36                         when ADD => op3_next <= op1 + op2;
37                         when SUB => op3_next <= op1 - op2;
38                         when MUL => op3_next <= op1 * op2;
39                         when DIV => op3_next <= op1 / op2;
40                         when others => op3_next <= (others => '0');
41                 end case;
42                 --      calc_done <= '1';
43                 --else
44                 --      calc_done <= '0';
45                 --end if;
46         end process;
47 end architecture beh;