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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [twoway/] [FT64_BranchPredicator.v] - Blame information for rev 57

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 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,
29 57 robfinch
    pcA, pcB, pcC, pcD, pcE, pcF, xpc0, xpc1, takb0, takb1,
30
    predict_takenA, predict_takenB, predict_takenC, predict_takenD,
31
    predict_takenE, predict_takenF);
32 48 robfinch
parameter DBW=32;
33
input rst;
34
input clk;
35
input en;
36
input xisBranch0;
37
input xisBranch1;
38
input [DBW-1:0] pcA;
39
input [DBW-1:0] pcB;
40
input [DBW-1:0] pcC;
41
input [DBW-1:0] pcD;
42 57 robfinch
input [DBW-1:0] pcE;
43
input [DBW-1:0] pcF;
44 48 robfinch
input [DBW-1:0] xpc0;
45
input [DBW-1:0] xpc1;
46
input takb0;
47
input takb1;
48
output predict_takenA;
49
output predict_takenB;
50
output predict_takenC;
51
output predict_takenD;
52 57 robfinch
output predict_takenE;
53
output predict_takenF;
54 48 robfinch
 
55
integer n;
56
reg [31:0] pcs [0:31];
57
reg [31:0] pc;
58
reg takb;
59
reg [4:0] pcshead,pcstail;
60
reg wrhist;
61
reg [2:0] gbl_branch_hist;
62
reg [1:0] branch_history_table [511:0];
63
// For simulation only, initialize the history table to zeros.
64
// In the real world we don't care.
65
initial begin
66
    gbl_branch_hist = 3'b000;
67
        for (n = 0; n < 512; n = n + 1)
68
                branch_history_table[n] = 3;
69
end
70
wire [8:0] bht_wa = {pc[8:2],gbl_branch_hist[2:1]};              // write address
71
wire [8:0] bht_raA = {pcA[8:2],gbl_branch_hist[2:1]};    // read address (IF stage)
72
wire [8:0] bht_raB = {pcB[8:2],gbl_branch_hist[2:1]};    // read address (IF stage)
73
wire [8:0] bht_raC = {pcC[8:2],gbl_branch_hist[2:1]};    // read address (IF stage)
74
wire [8:0] bht_raD = {pcD[8:2],gbl_branch_hist[2:1]};    // read address (IF stage)
75 57 robfinch
wire [8:0] bht_raE = {pcE[8:2],gbl_branch_hist[2:1]};    // read address (IF stage)
76
wire [8:0] bht_raF = {pcF[8:2],gbl_branch_hist[2:1]};    // read address (IF stage)
77 48 robfinch
wire [1:0] bht_xbits = branch_history_table[bht_wa];
78
wire [1:0] bht_ibitsA = branch_history_table[bht_raA];
79
wire [1:0] bht_ibitsB = branch_history_table[bht_raB];
80
wire [1:0] bht_ibitsC = branch_history_table[bht_raC];
81
wire [1:0] bht_ibitsD = branch_history_table[bht_raD];
82 57 robfinch
wire [1:0] bht_ibitsE = branch_history_table[bht_raE];
83
wire [1:0] bht_ibitsF = branch_history_table[bht_raF];
84 48 robfinch
assign predict_takenA = (bht_ibitsA==2'd0 || bht_ibitsA==2'd1) && en;
85
assign predict_takenB = (bht_ibitsB==2'd0 || bht_ibitsB==2'd1) && en;
86
assign predict_takenC = (bht_ibitsC==2'd0 || bht_ibitsC==2'd1) && en;
87
assign predict_takenD = (bht_ibitsD==2'd0 || bht_ibitsD==2'd1) && en;
88 57 robfinch
assign predict_takenE = (bht_ibitsE==2'd0 || bht_ibitsE==2'd1) && en;
89
assign predict_takenF = (bht_ibitsF==2'd0 || bht_ibitsF==2'd1) && en;
90 48 robfinch
 
91
always @(posedge clk)
92
if (rst)
93
        pcstail <= 5'd0;
94
else begin
95
        if (xisBranch0 & xisBranch1) begin
96
                pcs[pcstail] <= {xpc0[31:1],takb0};
97
                pcs[pcstail+1] <= {xpc1[31:1],takb1};
98
                pcstail <= pcstail + 5'd2;
99
        end
100
        else if (xisBranch0) begin
101
                pcs[pcstail] <= {xpc0[31:1],takb0};
102
                pcstail <= pcstail + 5'd1;
103
        end
104
        else if (xisBranch1) begin
105
                pcs[pcstail] <= {xpc1[31:1],takb1};
106
                pcstail <= pcstail + 5'd1;
107
        end
108
end
109
 
110
always @(posedge clk)
111
if (rst)
112
        pcshead <= 5'd0;
113
else begin
114
        wrhist <= 1'b0;
115
        if (pcshead != pcstail) begin
116
                pc <= pcs[pcshead];
117
                takb <= pcs[pcshead][0];
118
                wrhist <= 1'b1;
119
                pcshead <= pcshead + 5'd1;
120
        end
121
end
122
 
123
// Two bit saturating counter
124
// If taking a branch in commit0 then a following branch
125
// in commit1 is never encountered. So only update for
126
// commit1 if commit0 is not taken.
127
reg [1:0] xbits_new;
128
always @*
129 52 robfinch
if (wrhist) begin
130
        if (takb) begin
131
                if (bht_xbits != 2'd1)
132
                        xbits_new <= bht_xbits + 2'd1;
133
                else
134
                        xbits_new <= bht_xbits;
135
        end
136
        else begin
137
                if (bht_xbits != 2'd2)
138
                        xbits_new <= bht_xbits - 2'd1;
139
                else
140
                        xbits_new <= bht_xbits;
141
        end
142 48 robfinch
end
143 52 robfinch
else
144
        xbits_new <= bht_xbits;
145 48 robfinch
 
146
always @(posedge clk)
147
if (rst)
148
        gbl_branch_hist <= 3'b000;
149
else begin
150
    if (en) begin
151
        if (wrhist) begin
152
            gbl_branch_hist <= {gbl_branch_hist[1:0],takb};
153
            branch_history_table[bht_wa] <= xbits_new;
154
        end
155
        end
156
end
157
 
158
endmodule
159
 

powered by: WebSVN 2.1.0

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