static branch incl prediction rc1
[calu.git] / cpu / src / common_pkg.vhd
1 library IEEE;
2
3 use IEEE.std_logic_1164.all;
4 use IEEE.numeric_std.all;
5
6 package common_pkg is
7
8
9         
10         constant WORD_WIDTH   : INTEGER := 32;
11         constant HWORD_WIDTH  : INTEGER := 16;
12         constant BYTE_WIDTH   : INTEGER :=  8;
13         constant OPCODE_WIDTH : INTEGER :=  5;
14         constant DISPL_WIDTH  : INTEGER := 15;
15
16         subtype byte_t is std_logic_vector(BYTE_WIDTH-1 downto 0);
17         subtype hword_t is std_logic_vector(HWORD_WIDTH-1 downto 0);
18         subtype word_t  is std_logic_vector(WORD_WIDTH-1 downto 0);
19
20         subtype gp_register_t is word_t;
21
22         
23         constant REG_ZERO : gp_register_t := (others => '0');
24
25         constant INSTR_ADDR_WIDTH       : INTEGER := 32;
26         constant PHYS_INSTR_ADDR_WIDTH  : INTEGER := 11;
27         constant REG_ADDR_WIDTH         : INTEGER := 4;
28         constant DATA_ADDR_WIDTH        : INTEGER := 11;
29         constant PHYS_DATA_ADDR_WIDTH   : INTEGER := 32;
30         
31         constant NUM_OP_OPT_WIDTH       : INTEGER := 6;
32         constant COND_WIDTH : INTEGER := 4;
33
34         
35         subtype instruction_word_t is std_logic_vector(WORD_WIDTH-1 downto 0);
36         subtype instruction_addr_t is std_logic_vector(INSTR_ADDR_WIDTH-1 downto 0);
37         subtype instr_addr_t is instruction_addr_t;
38         
39         subtype gp_addr_t       is std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
40         subtype data_ram_word_t is std_logic_vector(WORD_WIDTH-1 downto 0);
41         subtype data_ram_addr_t is std_logic_vector(DATA_ADDR_WIDTH-1 downto 0);
42
43         subtype opcode_t is std_logic_vector(OPCODE_WIDTH-1 downto 0);
44         subtype condition_t is std_logic_vector(COND_WIDTH-1 downto 0);
45         
46         --Opcode consits of decoded group information type and option bits
47         --currently not complete, might need option increase too.
48         --IMMEDIATE always in right_operand (src2)
49         
50         constant IMM_OPT : integer := 0; -- no sharing
51         
52         constant SUB_OPT : integer := 1;
53         constant ARITH_OPT : integer := 1;
54         
55         constant CARRY_OPT : integer := 2;
56
57         constant RIGHT_OPT : integer := 3;
58         constant JMP_REG_OPT : integer := 3;
59         constant ST_OPT  : integer := 3;
60         
61         constant NO_PSW_OPT : integer := 4;--no sharing
62         constant NO_DST_OPT : integer := 5; --no sharing
63         
64         type op_info_t is (ADDSUB_OP,AND_OP,OR_OP, XOR_OP,SHIFT_OP, LDST_OP, JMP_OP, JMP_ST_OP);
65         subtype op_opt_t is std_logic_vector(NUM_OP_OPT_WIDTH-1 downto 0);
66         
67         
68         type instruction_rec is record
69
70                 predicates : std_logic_vector(3 downto 0);
71
72                 opcode : opcode_t;
73
74                 reg_dest_addr : std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
75                 reg_src1_addr : std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
76                 reg_src2_addr : std_logic_vector(REG_ADDR_WIDTH-1 downto 0);
77
78                 immediate : std_logic_vector(WORD_WIDTH-1 downto 0);
79
80                 displacement : gp_register_t;
81
82                 jmptype : std_logic_vector(1 downto 0);
83
84                 high_low, fill, signext, bp: std_logic;
85
86                 op_detail : op_opt_t;
87                 op_group : op_info_t;
88
89         end record;
90
91
92         type read_through_write_rec is record
93
94                 rtw_reg : gp_register_t;
95                 rtw_reg1 : std_logic;
96                 rtw_reg2 : std_logic;
97                 immediate : gp_register_t;
98                 imm_set : std_logic;
99                 reg1_addr : gp_addr_t;
100                 reg2_addr : gp_addr_t;
101
102         end record;
103
104         type dec_op is record
105                 condition : condition_t;
106                 op_group : op_info_t;
107                 op_detail : op_opt_t;
108                 brpr : std_logic;
109
110                 displacement : gp_register_t;
111                 prog_cnt     : instr_addr_t;
112                 
113                 src1 : gp_register_t;
114                 src2 : gp_register_t;
115                 
116                 saddr1 : gp_addr_t;
117                 saddr2 : gp_addr_t;
118                 
119                 daddr   : gp_addr_t;
120                 
121         end record;
122
123         type writeback_rec is record
124 --              result : in gp_register_t;      --reg  (alu result or jumpaddr)
125 --              result_addr : in gp_addr_t;     --reg
126                 address : word_t;               --ureg 
127 --              alu_jmp : in std_logic;         --reg
128 --              br_pred : in std_logic;         --reg
129 --              write_en : in std_logic;        --reg  (register file)
130                 dmem_en : std_logic;            --ureg (jump addr in mem or in address)
131                 dmem_write_en : std_logic;      --ureg
132                 hword : std_logic;              --ureg
133                 byte_s : std_logic;
134         end record;
135         
136         
137         function inc(value : in std_logic_vector; constant by : in integer := 1) return std_logic_vector;
138         function log2c(constant value : in integer range 0 to integer'high) return integer;
139 end package common_pkg;
140
141 package body common_pkg is
142
143         function inc(value : in std_logic_vector; constant by : in integer := 1) return std_logic_vector is
144         begin
145                 return std_logic_vector(UNSIGNED(value)+by);
146         end function inc;
147         
148         function log2c(constant value : in integer range 0 to integer'high) return integer is
149                 variable ret_value : integer;
150                 variable cur_value : integer;
151         begin
152                 ret_value := 0;
153                 cur_value := 1;
154                 
155                 while cur_value < value loop
156                         ret_value := ret_value + 1;
157                         cur_value := cur_value * 2;
158                 end loop;
159                 return ret_value;
160         end function log2c;
161         
162 end package body common_pkg;