1a57241ea9eb789ff92c56d65fa74405112912c0
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

1) LIBRARY ieee;
2) USE ieee.std_logic_1164.all;
3) USE ieee.numeric_std.all;
4) USE work.mips_types.all;
5) 
6) ENTITY e_mips_alu IS
7)     PORT (
8)         i_alu: IN  t_alu;
9)         i_op1: IN  std_logic_vector(31 DOWNTO 0);
10)         i_op2: IN  std_logic_vector(31 DOWNTO 0);
11)         o_res: OUT std_logic_vector(31 DOWNTO 0)
12)     );
13) END ENTITY e_mips_alu;
14) 
15) ARCHITECTURE a_mips_alu OF e_mips_alu IS
16) 
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

17)     SIGNAL s_shift_arith: std_logic;
18)     SIGNAL s_shift_left:  std_logic;
19)     SIGNAL s_shift_out:   std_logic_vector(31 DOWNTO 0);
20) 
21)     COMPONENT e_mips_shifter IS
22)         PORT (
23)             i_arith: IN  std_logic;
24)             i_left:  IN  std_logic;
25)             i_val:   IN  std_logic_vector(31 DOWNTO 0);
26)             i_num:   IN  std_logic_vector(31 DOWNTO 0);
27)             o_val:   OUT std_logic_vector(31 DOWNTO 0)
28)         );
29)     END COMPONENT e_mips_shifter;
30) 
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

31) BEGIN
32) 
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

33)     shifter: e_mips_shifter
34)         PORT MAP (
35)             i_arith => s_shift_arith,
36)             i_left  => s_shift_left,
Stefan Schuermans s operand is number of bits

Stefan Schuermans authored 12 years ago

37)             i_val   => i_op2,
38)             i_num   => i_op1,
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

39)             o_val   => s_shift_out
40)         );
41) 
42)     p_alu: PROCESS(i_alu, i_op1, i_op2, s_shift_out)
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

43)         VARIABLE v_op1_s: signed(31 DOWNTO 0);
44)         VARIABLE v_op2_s: signed(31 DOWNTO 0);
45)         VARIABLE v_op1_u: unsigned(31 DOWNTO 0);
46)         VARIABLE v_op2_u: unsigned(31 DOWNTO 0);
47)     BEGIN
48)         v_op1_s := signed(i_op1);
49)         v_op2_s := signed(i_op2);
50)         v_op1_u := unsigned(i_op1);
51)         v_op2_u := unsigned(i_op2);
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

52)         s_shift_arith <= '0';
53)         s_shift_left <= '0';
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

54)         CASE i_alu IS
55)             WHEN alu_add => o_res <= std_logic_vector(v_op1_s + v_op2_s);
56)             WHEN alu_and => o_res <= i_op1 AND i_op2;
57)             WHEN alu_nor => o_res <= i_op1 NOR i_op2;
58)             WHEN alu_or  => o_res <= i_op1 OR i_op2;
59)             WHEN alu_sub => o_res <= std_logic_vector(v_op1_s - v_op2_s);
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

60)             WHEN alu_sll => s_shift_arith <= '0'; s_shift_left <= '1'; o_res <= s_shift_out;
61)             WHEN alu_sra => s_shift_arith <= '1'; s_shift_left <= '0'; o_res <= s_shift_out;
62)             WHEN alu_srl => s_shift_arith <= '1'; s_shift_left <= '0'; o_res <= s_shift_out;
Stefan Schuermans start of MIPS core: begin o...

Stefan Schuermans authored 12 years ago

63)             WHEN alu_slt => IF v_op1_s < v_op2_s THEN
64)                                 o_res <= X"00000001";
65)                             ELSE
66)                                 o_res <= X"00000000";
67)                             END IF;
Stefan Schuermans separated shifter from ALU

Stefan Schuermans authored 12 years ago

68)             WHEN alu_sltu => IF v_op1_u < v_op2_u THEN
69)                                  o_res <= X"00000001";
70)                              ELSE
71)                                  o_res <= X"00000000";
72)                              END IF;