OpenCores
URL https://opencores.org/ocsvn/potato/potato/trunk

Subversion Repositories potato

[/] [potato/] [trunk/] [src/] [pp_alu_control_unit.vhd] - Blame information for rev 47

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 skordal
-- The Potato Processor - A simple processor for FPGAs
2
-- (c) Kristian Klomsten Skordal 2014 - 2015 <kristian.skordal@wafflemail.net>
3 3 skordal
-- Report bugs and issues on <http://opencores.org/project,potato,bugtracker>
4 2 skordal
 
5
library ieee;
6
use ieee.std_logic_1164.all;
7
 
8
use work.pp_types.all;
9
use work.pp_constants.all;
10
 
11
entity pp_alu_control_unit is
12
        port(
13
                opcode  : in std_logic_vector( 4 downto 0);
14
                funct3  : in std_logic_vector( 2 downto 0);
15
                funct7  : in std_logic_vector( 6 downto 0);
16
 
17
                -- Sources of ALU operands:
18
                alu_x_src, alu_y_src : out alu_operand_source;
19
 
20
                -- ALU operation:
21
                alu_op : out alu_operation
22
        );
23
end entity pp_alu_control_unit;
24
 
25
architecture behaviour of pp_alu_control_unit is
26
begin
27
 
28
        decode_alu: process(opcode, funct3, funct7)
29
        begin
30
                case opcode is
31
                        when b"01101" => -- Load upper immediate
32
                                alu_x_src <= ALU_SRC_NULL;
33
                                alu_y_src <= ALU_SRC_IMM;
34
                                alu_op <= ALU_ADD;
35
                        when b"00101" => -- Add upper immediate to PC
36
                                alu_x_src <= ALU_SRC_PC;
37
                                alu_y_src <= ALU_SRC_IMM;
38
                                alu_op <= ALU_ADD;
39
                        when b"11011" => -- Jump and link
40
                                alu_x_src <= ALU_SRC_PC_NEXT;
41
                                alu_y_src <= ALU_SRC_NULL;
42
                                alu_op <= ALU_ADD;
43
                        when b"11001" => -- Jump and link register
44
                                alu_x_src <= ALU_SRC_PC_NEXT;
45
                                alu_y_src <= ALU_SRC_NULL;
46
                                alu_op <= ALU_ADD;
47
                        when b"11000" => -- Branch operations
48
                                -- The funct3 field decides which type of branch comparison is
49
                                -- done; this is decoded in the branch comparator module.
50
                                alu_x_src <= ALU_SRC_NULL;
51
                                alu_y_src <= ALU_SRC_NULL;
52
                                alu_op <= ALU_NOP;
53
                        when b"00000" => -- Load instruction
54
                                alu_x_src <= ALU_SRC_REG;
55
                                alu_y_src <= ALU_SRC_IMM;
56
                                alu_op <= ALU_ADD;
57
                        when b"01000" => -- Store instruction
58
                                alu_x_src <= ALU_SRC_REG;
59
                                alu_y_src <= ALU_SRC_IMM;
60
                                alu_op <= ALU_ADD;
61
                        when b"00100" => -- Register-immediate operations
62
                                alu_x_src <= ALU_SRC_REG;
63
 
64
                                if funct3 = b"001" or funct3 = b"101" then
65
                                        alu_y_src <= ALU_SRC_SHAMT;
66
                                else
67
                                        alu_y_src <= ALU_SRC_IMM;
68
                                end if;
69
 
70
                                case funct3 is
71
                                        when b"000" =>
72
                                                alu_op <= ALU_ADD;
73
                                        when b"001" =>
74
                                                alu_op <= ALU_SLL;
75
                                        when b"010" =>
76
                                                alu_op <= ALU_SLT;
77
                                        when b"011" =>
78
                                                alu_op <= ALU_SLTU;
79
                                        when b"100" =>
80
                                                alu_op <= ALU_XOR;
81
                                        when b"101" =>
82
                                                if funct7 = b"0000000" then
83
                                                        alu_op <= ALU_SRL;
84
                                                else
85
                                                        alu_op <= ALU_SRA;
86
                                                end if;
87
                                        when b"110" =>
88
                                                alu_op <= ALU_OR;
89
                                        when b"111" =>
90
                                                alu_op <= ALU_AND;
91
                                        when others =>
92 14 skordal
                                                alu_op <= ALU_INVALID;
93 2 skordal
                                end case;
94
                        when b"01100" => -- Register-register operations
95
                                alu_x_src <= ALU_SRC_REG;
96
                                alu_y_src <= ALU_SRC_REG;
97
 
98
                                case funct3 is
99
                                        when b"000" =>
100
                                                if funct7 = b"0000000" then
101
                                                        alu_op <= ALU_ADD;
102
                                                else
103
                                                        alu_op <= ALU_SUB;
104
                                                end if;
105
                                        when b"001" =>
106
                                                alu_op <= ALU_SLL;
107
                                        when b"010" =>
108
                                                alu_op <= ALU_SLT;
109
                                        when b"011" =>
110
                                                alu_op <= ALU_SLTU;
111
                                        when b"100" =>
112
                                                alu_op <= ALU_XOR;
113
                                        when b"101" =>
114
                                                if funct7 = b"0000000" then
115
                                                        alu_op <= ALU_SRL;
116
                                                else
117
                                                        alu_op <= ALU_SRA;
118
                                                end if;
119
                                        when b"110" =>
120
                                                alu_op <= ALU_OR;
121
                                        when b"111" =>
122
                                                alu_op <= ALU_AND;
123
                                        when others =>
124 14 skordal
                                                alu_op <= ALU_INVALID;
125 2 skordal
                                end case;
126 14 skordal
                        when b"00011" => -- Fence instructions, ignored
127
                                alu_x_src <= ALU_SRC_REG;
128
                                alu_y_src <= ALU_SRC_REG;
129
                                alu_op <= ALU_NOP;
130 2 skordal
                        when b"11100" => -- System instructions
131
                                alu_x_src <= ALU_SRC_CSR;
132
                                alu_y_src <= ALU_SRC_NULL;
133
                                alu_op <= ALU_ADD;
134
                        when others =>
135
                                alu_x_src <= ALU_SRC_REG;
136
                                alu_y_src <= ALU_SRC_REG;
137 14 skordal
                                alu_op <= ALU_INVALID;
138 2 skordal
                end case;
139
        end process decode_alu;
140
 
141
end architecture behaviour;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.