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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v7/] [rtl/] [twoway/] [FT64_BranchPredictor.v] - Blame information for rev 60

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 60 robfinch
//=============================================================================
2
//        __
3
//   \\__/ o\    (C) 2013-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//  
8
//      FT64_BranchPredictor.v
9
//
10
//  
11
// This source file is free software: you can redistribute it and/or modify 
12
// it under the terms of the GNU Lesser General Public License as published 
13
// by the Free Software Foundation, either version 3 of the License, or     
14
// (at your option) any later version.                                      
15
//                                                                          
16
// This source file is distributed in the hope that it will be useful,      
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
19
// GNU General Public License for more details.                             
20
//                                                                          
21
// You should have received a copy of the GNU General Public License        
22
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
23
//                                                                          
24
//
25
//=============================================================================
26
//
27
module FT64_BranchPredictor(rst, clk, en,
28
    xisBranch0, xisBranch1, xisBranch2,
29
    pcA, pcB, pcC, pcD, pcE, pcF, xpc0, xpc1, xpc2, takb0, takb1, takb2,
30
    predict_takenA, predict_takenB, predict_takenC, predict_takenD,
31
    predict_takenE, predict_takenF);
32
parameter AMSB=63;
33
parameter DBW=32;
34
input rst;
35
input clk;
36
input en;
37
input xisBranch0;
38
input xisBranch1;
39
input xisBranch2;
40
input [AMSB:0] pcA;
41
input [AMSB:0] pcB;
42
input [AMSB:0] pcC;
43
input [AMSB:0] pcD;
44
input [AMSB:0] pcE;
45
input [AMSB:0] pcF;
46
input [AMSB:0] xpc0;
47
input [AMSB:0] xpc1;
48
input [AMSB:0] xpc2;
49
input takb0;
50
input takb1;
51
input takb2;
52
output predict_takenA;
53
output predict_takenB;
54
output predict_takenC;
55
output predict_takenD;
56
output predict_takenE;
57
output predict_takenF;
58
 
59
integer n;
60
reg [AMSB:0] pcs [0:31];
61
reg [AMSB:0] pc;
62
reg takb;
63
reg [4:0] pcshead,pcstail;
64
reg wrhist;
65
reg [2:0] gbl_branch_hist;
66
reg [1:0] branch_history_table [511:0];
67
// For simulation only, initialize the history table to zeros.
68
// In the real world we don't care.
69
initial begin
70
    gbl_branch_hist = 3'b000;
71
        for (n = 0; n < 512; n = n + 1)
72
                branch_history_table[n] = 3;
73
end
74
wire [8:0] bht_wa = {pc[7:1],gbl_branch_hist[2:1]};              // write address
75
wire [8:0] bht_raA = {pcA[7:1],gbl_branch_hist[2:1]};    // read address (IF stage)
76
wire [8:0] bht_raB = {pcB[7:1],gbl_branch_hist[2:1]};    // read address (IF stage)
77
wire [8:0] bht_raC = {pcC[7:1],gbl_branch_hist[2:1]};    // read address (IF stage)
78
wire [8:0] bht_raD = {pcD[7:1],gbl_branch_hist[2:1]};    // read address (IF stage)
79
wire [8:0] bht_raE = {pcE[7:1],gbl_branch_hist[2:1]};    // read address (IF stage)
80
wire [8:0] bht_raF = {pcF[7:1],gbl_branch_hist[2:1]};    // read address (IF stage)
81
wire [1:0] bht_xbits = branch_history_table[bht_wa];
82
wire [1:0] bht_ibitsA = branch_history_table[bht_raA];
83
wire [1:0] bht_ibitsB = branch_history_table[bht_raB];
84
wire [1:0] bht_ibitsC = branch_history_table[bht_raC];
85
wire [1:0] bht_ibitsD = branch_history_table[bht_raD];
86
wire [1:0] bht_ibitsE = branch_history_table[bht_raE];
87
wire [1:0] bht_ibitsF = branch_history_table[bht_raF];
88
assign predict_takenA = (bht_ibitsA==2'd0 || bht_ibitsA==2'd1) && en;
89
assign predict_takenB = (bht_ibitsB==2'd0 || bht_ibitsB==2'd1) && en;
90
assign predict_takenC = (bht_ibitsC==2'd0 || bht_ibitsC==2'd1) && en;
91
assign predict_takenD = (bht_ibitsD==2'd0 || bht_ibitsD==2'd1) && en;
92
assign predict_takenE = (bht_ibitsE==2'd0 || bht_ibitsE==2'd1) && en;
93
assign predict_takenF = (bht_ibitsF==2'd0 || bht_ibitsF==2'd1) && en;
94
 
95
always @(posedge clk)
96
if (rst)
97
        pcstail <= 5'd0;
98
else begin
99
        case({xisBranch0,xisBranch1,xisBranch2})
100
        3'b000: ;
101
        3'b001:
102
                begin
103
                pcs[pcstail] <= {xpc2[31:1],takb2};
104
                pcstail <= pcstail + 5'd1;
105
                end
106
        3'b010:
107
                begin
108
                pcs[pcstail] <= {xpc1[31:1],takb1};
109
                pcstail <= pcstail + 5'd1;
110
                end
111
        3'b011:
112
                begin
113
                pcs[pcstail] <= {xpc1[31:1],takb1};
114
                pcs[pcstail+1] <= {xpc2[31:1],takb2};
115
                pcstail <= pcstail + 5'd2;
116
                end
117
        3'b100:
118
                begin
119
                pcs[pcstail] <= {xpc0[31:1],takb0};
120
                pcstail <= pcstail + 5'd1;
121
                end
122
        3'b101:
123
                begin
124
                pcs[pcstail] <= {xpc0[31:1],takb0};
125
                pcs[pcstail+1] <= {xpc2[31:1],takb2};
126
                pcstail <= pcstail + 5'd2;
127
                end
128
        3'b110:
129
                begin
130
                pcs[pcstail] <= {xpc0[31:1],takb0};
131
                pcs[pcstail+1] <= {xpc1[31:1],takb1};
132
                pcstail <= pcstail + 5'd2;
133
                end
134
        3'b111:
135
                begin
136
                pcs[pcstail] <= {xpc0[31:1],takb0};
137
                pcs[pcstail+1] <= {xpc1[31:1],takb1};
138
                pcs[pcstail+2] <= {xpc2[31:1],takb2};
139
                pcstail <= pcstail + 5'd3;
140
                end
141
        endcase
142
end
143
 
144
always @(posedge clk)
145
if (rst)
146
        pcshead <= 5'd0;
147
else begin
148
        wrhist <= 1'b0;
149
        if (pcshead != pcstail) begin
150
                pc <= pcs[pcshead];
151
                takb <= pcs[pcshead][0];
152
                wrhist <= 1'b1;
153
                pcshead <= pcshead + 5'd1;
154
        end
155
end
156
 
157
// Two bit saturating counter
158
// If taking a branch in commit0 then a following branch
159
// in commit1 is never encountered. So only update for
160
// commit1 if commit0 is not taken.
161
reg [1:0] xbits_new;
162
always @*
163
if (wrhist) begin
164
        if (takb) begin
165
                if (bht_xbits != 2'd1)
166
                        xbits_new <= bht_xbits + 2'd1;
167
                else
168
                        xbits_new <= bht_xbits;
169
        end
170
        else begin
171
                if (bht_xbits != 2'd2)
172
                        xbits_new <= bht_xbits - 2'd1;
173
                else
174
                        xbits_new <= bht_xbits;
175
        end
176
end
177
else
178
        xbits_new <= bht_xbits;
179
 
180
always @(posedge clk)
181
if (rst)
182
        gbl_branch_hist <= 3'b000;
183
else begin
184
  if (en) begin
185
    if (wrhist) begin
186
      gbl_branch_hist <= {gbl_branch_hist[1:0],takb};
187
      branch_history_table[bht_wa] <= xbits_new;
188
    end
189
        end
190
end
191
 
192
endmodule
193
 

powered by: WebSVN 2.1.0

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