1 -- `Deep Thought', a softcore CPU implemented on a FPGA
3 -- Copyright (C) 2010 Markus Hofstaetter <markus.manrow@gmx.at>
4 -- Copyright (C) 2010 Martin Perner <e0725782@student.tuwien.ac.at>
5 -- Copyright (C) 2010 Stefan Rebernig <stefan.rebernig@gmail.com>
6 -- Copyright (C) 2010 Manfred Schwarz <e0725898@student.tuwien.ac.at>
7 -- Copyright (C) 2010 Bernhard Urban <lewurm@gmail.com>
9 -- This program is free software: you can redistribute it and/or modify
10 -- it under the terms of the GNU General Public License as published by
11 -- the Free Software Foundation, either version 3 of the License, or
12 -- (at your option) any later version.
14 -- This program is distributed in the hope that it will be useful,
15 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
16 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 -- GNU General Public License for more details.
19 -- You should have received a copy of the GNU General Public License
20 -- along with this program. If not, see <http://www.gnu.org/licenses/>.
24 use IEEE.std_logic_1164.all;
25 use IEEE.numeric_std.all;
28 use work.core_pkg.all;
29 use work.common_pkg.all;
32 architecture behav of decode_stage is
34 signal instr_spl : instruction_rec;
36 signal rtw_rec, rtw_rec_nxt : read_through_write_rec;
37 signal reg1_mem_data, reg2_mem_data, reg1_rd_data, reg2_rd_data : gp_register_t;
38 signal dec_op_inst, dec_op_inst_nxt : dec_op;
44 register_ram : r2_w_ram
53 instr_spl.reg_src1_addr,
54 instr_spl.reg_src2_addr,
62 decoder_inst : decoder
69 -- sync process for read through write registers
70 syn: process(clk, reset)
74 if (reset = RESET_VALUE) then
75 rtw_rec.rtw_reg <= (others => '0');
76 rtw_rec.rtw_reg1 <= '0';
77 rtw_rec.rtw_reg2 <= '0';
78 rtw_rec.immediate <= (others => '0');
79 rtw_rec.imm_set <= '0';
81 dec_op_inst.condition <= (others => '1');
82 dec_op_inst.op_detail <= (others => '0');
83 dec_op_inst.op_group <= ADDSUB_OP;
84 dec_op_inst.brpr <= '0'; --branch_prediction_bit;
85 dec_op_inst.src1 <= (others => '0');
86 dec_op_inst.src2 <= (others => '0');
87 dec_op_inst.saddr1 <= (others => '0');
88 dec_op_inst.saddr2 <= (others => '0');
89 dec_op_inst.daddr <= (others => '0');
90 dec_op_inst.displacement <= (others => '0');
91 dec_op_inst.prog_cnt <= (others => '0');
93 elsif rising_edge(clk) then
94 rtw_rec <= rtw_rec_nxt;
95 dec_op_inst <= dec_op_inst_nxt;
100 -- type dec_op is record
101 -- condition : condition_t;
102 -- op_group : op_info_t;
103 -- op_detail : op_opt_t;
106 -- src1 : gp_register_t;
107 -- src2 : gp_register_t;
109 -- saddr1 : gp_addr_t;
110 -- saddr2 : gp_addr_t;
112 -- daddr : gp_addr_t;
116 -- output logic incl. bypassing reg-file
117 output_next_stage: process(dec_op_inst, reg1_rd_data, reg2_rd_data, nop)
121 to_next_stage <= dec_op_inst;
122 to_next_stage.src1 <= reg1_rd_data;
123 to_next_stage.src2 <= reg2_rd_data;
126 to_next_stage.condition <= "1111";
132 -- fills output register
133 to_next: process(instr_spl, prog_cnt)
136 dec_op_inst_nxt.condition <= instr_spl.predicates;
137 dec_op_inst_nxt.op_detail <= instr_spl.op_detail;
138 dec_op_inst_nxt.brpr <= instr_spl.bp; --branch_prediction_bit;
139 dec_op_inst_nxt.src1 <= (others => '0');
140 dec_op_inst_nxt.src2 <= (others => '0');
141 dec_op_inst_nxt.saddr1 <= instr_spl.reg_src1_addr;
142 dec_op_inst_nxt.saddr2 <= instr_spl.reg_src2_addr;
143 dec_op_inst_nxt.daddr <= instr_spl.reg_dest_addr; --(others => '0');
144 dec_op_inst_nxt.op_group <= instr_spl.op_group;
145 dec_op_inst_nxt.displacement <= instr_spl.displacement;
146 dec_op_inst_nxt.prog_cnt <= prog_cnt;
150 -- async process: decides between memory and read-through-write buffer on output
151 output: process(rtw_rec, rtw_rec_nxt, reg1_mem_data, reg2_mem_data)
154 if ((rtw_rec.rtw_reg1) = '1') then
155 reg1_rd_data <= rtw_rec.rtw_reg;
157 reg1_rd_data <= reg1_mem_data;
160 if ((rtw_rec.rtw_reg2) = '1') then
161 reg2_rd_data <= rtw_rec.rtw_reg;
163 reg2_rd_data <= reg2_mem_data;
166 if (rtw_rec.imm_set = '1') then
167 reg2_rd_data <= rtw_rec.immediate;
173 -- async process: checks forward condition
174 forward: process(instr_spl, reg_w_addr, reg_wr_data, reg_we)
178 rtw_rec_nxt.rtw_reg <= reg_wr_data;
179 rtw_rec_nxt.rtw_reg1 <= '0';
180 rtw_rec_nxt.rtw_reg2 <= '0';
181 rtw_rec_nxt.immediate <= (others => '0');
182 rtw_rec_nxt.imm_set <= '0';
184 rtw_rec_nxt.reg1_addr <= instr_spl.reg_src1_addr;
185 rtw_rec_nxt.reg2_addr <= instr_spl.reg_src2_addr;
187 if (instr_spl.op_detail(IMM_OPT) = '1') then -- or instr_spl.op_group = LDST_OP
188 rtw_rec_nxt.immediate <= instr_spl.immediate;
189 rtw_rec_nxt.imm_set <= '1';
192 if (reg_w_addr = instr_spl.reg_src1_addr) then
193 rtw_rec_nxt.rtw_reg1 <= ('1' and reg_we);
196 if (reg_w_addr = instr_spl.reg_src2_addr) then
197 rtw_rec_nxt.rtw_reg2 <= ('1' and reg_we);
203 -- async process: calculates branch prediction
204 br_pred: process(instr_spl, prog_cnt, reset)
208 branch_prediction_res <= (others => '0');
209 branch_prediction_bit <= '0';
211 if ((instr_spl.opcode = "10110" or instr_spl.opcode = "10111") and instr_spl.bp = '1') then
212 if instr_spl.int = '0' then
213 branch_prediction_res <= std_logic_vector(unsigned(instr_spl.immediate) + unsigned(prog_cnt)); --both 32 bit
215 branch_prediction_res <= instr_spl.immediate;
217 branch_prediction_bit <= '1';
220 if reset = RESET_VALUE then
221 branch_prediction_bit <= '0';