3 use IEEE.std_logic_1164.all;
4 use IEEE.numeric_std.all;
8 use work.common_pkg.all;
11 architecture behav of decode_stage is
13 signal instr_spl : instruction_rec;
15 signal rtw_rec, rtw_rec_nxt : read_through_write_rec;
16 signal reg1_mem_data, reg2_mem_data, reg1_rd_data, reg2_rd_data : gp_register_t;
17 signal dec_op_inst, dec_op_inst_nxt : dec_op;
23 register_ram : r2_w_ram
32 instr_spl.reg_src1_addr,
33 instr_spl.reg_src2_addr,
41 decoder_inst : decoder
48 -- sync process for read through write registers
49 syn: process(clk, reset)
53 if (reset = RESET_VALUE) then
54 rtw_rec.rtw_reg <= (others => '0');
55 rtw_rec.rtw_reg1 <= '0';
56 rtw_rec.rtw_reg2 <= '0';
57 rtw_rec.immediate <= (others => '0');
58 rtw_rec.imm_set <= '0';
60 dec_op_inst.condition <= (others => '0');
61 dec_op_inst.op_detail <= (others => '0');
62 dec_op_inst.brpr <= '0'; --branch_prediction_bit;
63 dec_op_inst.src1 <= (others => '0');
64 dec_op_inst.src2 <= (others => '0');
65 dec_op_inst.saddr1 <= (others => '0');
66 dec_op_inst.saddr2 <= (others => '0');
67 dec_op_inst.daddr <= (others => '0');
70 elsif rising_edge(clk) then
71 rtw_rec <= rtw_rec_nxt;
72 dec_op_inst <= dec_op_inst_nxt;
77 -- type dec_op is record
78 -- condition : condition_t;
79 -- op_group : op_info_t;
80 -- op_detail : op_opt_t;
83 -- src1 : gp_register_t;
84 -- src2 : gp_register_t;
86 -- saddr1 : gp_addr_t;
87 -- saddr2 : gp_addr_t;
93 -- output logic incl. bypassing reg-file
94 output_next_stage: process(dec_op_inst, reg1_rd_data, reg2_rd_data)
98 to_next_stage <= dec_op_inst;
99 to_next_stage.src1 <= reg1_rd_data;
100 to_next_stage.src2 <= reg2_rd_data;
105 -- fills output register
106 to_next: process(instr_spl)
109 dec_op_inst_nxt.condition <= instr_spl.predicates;
110 dec_op_inst_nxt.op_detail <= instr_spl.op_detail;
111 dec_op_inst_nxt.brpr <= instr_spl.bp; --branch_prediction_bit;
112 dec_op_inst_nxt.src1 <= (others => '0');
113 dec_op_inst_nxt.src2 <= (others => '0');
114 dec_op_inst_nxt.saddr1 <= instr_spl.reg_src1_addr;
115 dec_op_inst_nxt.saddr2 <= instr_spl.reg_src2_addr;
116 dec_op_inst_nxt.daddr <= (others => '0');
120 -- async process: decides between memory and read-through-write buffer on output
121 output: process(rtw_rec, reg1_mem_data, reg2_mem_data)
124 if (rtw_rec.rtw_reg1 = '1') then
125 reg1_rd_data <= rtw_rec.rtw_reg;
127 reg1_rd_data <= reg1_mem_data;
130 if (rtw_rec.rtw_reg2 = '1') then
131 reg2_rd_data <= rtw_rec.rtw_reg;
133 reg2_rd_data <= reg2_mem_data;
136 if (rtw_rec.imm_set = '1') then
137 reg2_rd_data <= rtw_rec.immediate;
142 -- async process: checks forward condition
143 forward: process(instr_spl, reg_w_addr, reg_wr_data, reg_we)
147 rtw_rec_nxt.rtw_reg <= reg_wr_data;
148 rtw_rec_nxt.rtw_reg1 <= '0';
149 rtw_rec_nxt.rtw_reg2 <= '0';
150 rtw_rec_nxt.immediate <= (others => '0');
151 rtw_rec_nxt.imm_set <= '0';
153 if (instr_spl.op_detail(IMM_OPT) = '1') then
154 rtw_rec_nxt.immediate <= instr_spl.immediate;
155 rtw_rec_nxt.imm_set <= '1';
158 if (reg_w_addr = instr_spl.reg_src1_addr) then
159 rtw_rec_nxt.rtw_reg1 <= ('1' and reg_we);
162 if (reg_w_addr = instr_spl.reg_src2_addr) then
163 rtw_rec_nxt.rtw_reg2 <= ('1' and reg_we);
169 -- async process: calculates branch prediction
170 br_pred: process(instr_spl)
174 branch_prediction_res <= (others => '0');
175 branch_prediction_bit <= '0';
177 if ((instr_spl.opcode = "10110" or instr_spl.opcode = "10111") and instr_spl.bp = '1') then
178 branch_prediction_res <= instr_spl.immediate; --both 32 bit
179 branch_prediction_bit <= '1';