1 |
2 |
azmathmoos |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// Copyright (C) 2014-2015 Azmath Moosa ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This source file may be used and distributed without ////
|
6 |
|
|
//// restriction provided that this copyright statement is not ////
|
7 |
|
|
//// removed from the file and that any derivative work contains ////
|
8 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
9 |
|
|
//// ////
|
10 |
|
|
//// This source file is free software; you can redistribute it ////
|
11 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
12 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
13 |
|
|
//// either version 3 of the License, or (at your option) any ////
|
14 |
|
|
//// later version. ////
|
15 |
|
|
//// ////
|
16 |
|
|
//// This source is distributed in the hope that it will be ////
|
17 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
18 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
19 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
20 |
|
|
//// details. ////
|
21 |
|
|
//// ////
|
22 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
23 |
|
|
//// Public License along with this source; if not, download it ////
|
24 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
25 |
|
|
//// ////
|
26 |
|
|
//////////////////////////////////////////////////////////////////////
|
27 |
|
|
`timescale 1ns / 1ps
|
28 |
|
|
`include "Configuration.v"
|
29 |
|
|
module Reg_Hist(
|
30 |
|
|
// input Clk, RST,
|
31 |
|
|
input [0:`reg_sel_w] ID_EX_reg, EX_MEM_reg,
|
32 |
|
|
input [0:`reg_sel_w] nxt_reg_A, nxt_reg_B, st_reg,
|
33 |
|
|
output [0:1] reg_src_A, reg_src_B, st_src,
|
34 |
|
|
output [0:2] load_hazard_abs,
|
35 |
|
|
output load_hazard,
|
36 |
|
|
input rrr_adm, rri_adm, ID_EX_load, fw_c_1, fw_c_2
|
37 |
|
|
);
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
// //pure combinational
|
41 |
|
|
wire reg_src_a_1, reg_src_a_2, reg_src_b_1, reg_src_b_2;
|
42 |
|
|
//store hazards
|
43 |
|
|
wire st_src_1, st_src_2;
|
44 |
|
|
|
45 |
|
|
//assign rrr_adm = (~(|(adm ^ `RRR)));
|
46 |
|
|
// assign not_branch = (|(type ^ `type_branch));
|
47 |
|
|
// assign not_ID_EX_branch = (|(ID_EX_type ^ `type_branch));
|
48 |
|
|
// assign not_EX_MEM_branch = (|(EX_MEM_type ^ `type_branch));
|
49 |
|
|
assign load_hazard = (reg_src_a_1 | reg_src_b_1 | st_src_1) & ID_EX_load;//~(|(ID_EX_type ^ `type_load));
|
50 |
|
|
//WORK HERE WORK HERE --- below --- below
|
51 |
|
|
assign reg_src_a_1 = (rrr_adm & fw_c_1 & (~(|(nxt_reg_A ^ ID_EX_reg))));//
|
52 |
|
|
assign reg_src_a_2 = (rrr_adm & fw_c_2 & (~(|(nxt_reg_A ^ EX_MEM_reg))));//
|
53 |
|
|
assign reg_src_b_1 = ((rrr_adm | rri_adm) & fw_c_1 & (~(|(nxt_reg_B ^ ID_EX_reg))));
|
54 |
|
|
assign reg_src_b_2 = ((rrr_adm | rri_adm) & fw_c_2 & (~(|(nxt_reg_B ^ EX_MEM_reg))));
|
55 |
|
|
assign st_src_1 = (fw_c_1 & (~(|(st_reg ^ ID_EX_reg))));
|
56 |
|
|
assign st_src_2 = (fw_c_2 & (~(|(st_reg ^ EX_MEM_reg))));
|
57 |
|
|
|
58 |
|
|
assign reg_src_A = {reg_src_a_1,reg_src_a_2};//load_hazard_abs[0] ? 2'b01 :
|
59 |
|
|
assign reg_src_B = {reg_src_b_1,reg_src_b_2};//load_hazard_abs[1] ? 2'b01 :
|
60 |
|
|
assign st_src = load_hazard_abs[2] ? 2'b01 : {st_src_1,st_src_2};
|
61 |
|
|
assign load_hazard_abs = {load_hazard & reg_src_a_1,load_hazard & reg_src_b_1,load_hazard & st_src_1};
|
62 |
|
|
|
63 |
|
|
// always@(Clk) begin
|
64 |
|
|
// if (|(type ^ `type_branch)) begin
|
65 |
|
|
// if ((|(ID_EX_type ^ `type_branch))&(~(|(nxt_reg_A ^ ID_EX_reg)))) reg_src_A <= 2'b01;
|
66 |
|
|
// else if ((|(ID_EX_type ^ `type_branch))&(~(|(nxt_reg_A ^ EX_MEM_reg)))) reg_src_A <= 2'b10;
|
67 |
|
|
// else reg_src_A <= 2'b00;
|
68 |
|
|
//
|
69 |
|
|
// if ((|(EX_MEM_type ^ `type_branch))&(~(|(nxt_reg_B ^ ID_EX_reg)))) reg_src_B <= 2'b01;
|
70 |
|
|
// else if ((|(EX_MEM_type ^ `type_branch))&(~(|(nxt_reg_B ^ EX_MEM_reg)))) reg_src_B <= 2'b10;
|
71 |
|
|
// else reg_src_B <= 2'b00;
|
72 |
|
|
// end else begin
|
73 |
|
|
// reg_src_A <= 2'b00;
|
74 |
|
|
// reg_src_B <= 2'b00;
|
75 |
|
|
// end
|
76 |
|
|
// end
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
// wire Clk_RST;
|
80 |
|
|
// assign Clk_RST = Clk || RST;
|
81 |
|
|
// reg stall_reg;
|
82 |
|
|
//
|
83 |
|
|
// initial begin
|
84 |
|
|
// stall_reg <= 0;
|
85 |
|
|
// end
|
86 |
|
|
// always@(posedge Clk_RST) begin
|
87 |
|
|
// if (RST) begin
|
88 |
|
|
// bubble_reg <= 9'b111100000;
|
89 |
|
|
// end else begin
|
90 |
|
|
// if (bubble) begin
|
91 |
|
|
// bubble_reg <= 9'b111100000;
|
92 |
|
|
// end else begin
|
93 |
|
|
// bubble_reg <= {1,bubble_reg[0:7]};
|
94 |
|
|
// end
|
95 |
|
|
//
|
96 |
|
|
// if (~stall_reg) begin
|
97 |
|
|
// if (load_hazard) begin
|
98 |
|
|
// stall_reg <= 1;
|
99 |
|
|
// end else begin
|
100 |
|
|
// stall_reg <= 0;
|
101 |
|
|
// end
|
102 |
|
|
// end else begin
|
103 |
|
|
// stall_reg <= 0;
|
104 |
|
|
// end
|
105 |
|
|
// end
|
106 |
|
|
//
|
107 |
|
|
// assign stall = stall_reg;
|
108 |
|
|
endmodule
|