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

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [rtl/] [verilog/] [Raptor64_BranchHistory.v] - Blame information for rev 45

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

Line No. Rev Author Line
1 30 robfinch
`include "Raptor64_opcodes.v"
2
`timescale 1ns / 1ps
3
//=============================================================================
4
//        __
5 41 robfinch
//   \\__/ o\    (C) 2011-2013  Robert Finch, Stratford
6 30 robfinch
//    \  __ /    All rights reserved.
7
//     \/_//     robfinch<remove>@opencores.org
8
//       ||
9
//  
10
//      Raptor64_BranchHistory.v
11
//
12
//  
13
// This source file is free software: you can redistribute it and/or modify 
14
// it under the terms of the GNU Lesser General Public License as published 
15
// by the Free Software Foundation, either version 3 of the License, or     
16
// (at your option) any later version.                                      
17
//                                                                          
18
// This source file is distributed in the hope that it will be useful,      
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
21
// GNU General Public License for more details.                             
22
//                                                                          
23
// You should have received a copy of the GNU General Public License        
24
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
25
//                                                                          
26
//
27
//=============================================================================
28
//
29 45 robfinch
module Raptor64_BranchHistory(rst, clk, advanceX, xIRvalid, xIR, pc, xpc, takb, predict_taken);
30 30 robfinch
input rst;
31
input clk;
32
input advanceX;
33 45 robfinch
input xIRvalid;
34 41 robfinch
input [31:0] xIR;
35 30 robfinch
input [63:0] pc;
36
input [63:0] xpc;
37
input takb;
38
output predict_taken;
39
 
40
integer n;
41
reg [2:0] gbl_branch_hist;
42
reg [1:0] branch_history_table [255:0];
43
// For simulation only, initialize the history table to zeros.
44
// In the real world we don't care.
45
initial begin
46
        for (n = 0; n < 256; n = n + 1)
47
                branch_history_table[n] = 0;
48
end
49 41 robfinch
wire [7:0] bht_wa = {xpc[7:2],gbl_branch_hist[2:1]};             // write address
50
wire [7:0] bht_ra1 = {xpc[7:2],gbl_branch_hist[2:1]};            // read address (EX stage)
51
wire [7:0] bht_ra2 = {pc[7:2],gbl_branch_hist[2:1]};     // read address (IF stage)
52 30 robfinch
wire [1:0] bht_xbits = branch_history_table[bht_ra1];
53
wire [1:0] bht_ibits = branch_history_table[bht_ra2];
54
assign predict_taken = bht_ibits==2'd0 || bht_ibits==2'd1;
55
 
56 41 robfinch
wire [6:0] xOpcode = xIR[31:25];
57 30 robfinch
wire isxBranchI = (xOpcode==`BEQI || xOpcode==`BNEI ||
58
                                        xOpcode==`BLTI || xOpcode==`BLEI || xOpcode==`BGTI || xOpcode==`BGEI ||
59
                                        xOpcode==`BLTUI || xOpcode==`BLEUI || xOpcode==`BGTUI || xOpcode==`BGEUI)
60
                                ;
61 45 robfinch
wire isxBranch = xIRvalid && (isxBranchI || xOpcode==`TRAPcc || xOpcode==`TRAPcci || xOpcode==`BTRI || xOpcode==`BTRR);
62 30 robfinch
 
63
// Two bit saturating counter
64
reg [1:0] xbits_new;
65
always @(takb or bht_xbits)
66
if (takb) begin
67
        if (bht_xbits != 2'd1)
68
                xbits_new <= bht_xbits + 2'd1;
69
        else
70
                xbits_new <= bht_xbits;
71
end
72
else begin
73
        if (bht_xbits != 2'd2)
74
                xbits_new <= bht_xbits - 2'd1;
75
        else
76
                xbits_new <= bht_xbits;
77
end
78
 
79
always @(posedge clk)
80
if (rst)
81
        gbl_branch_hist <= 3'b000;
82
else begin
83
        if (advanceX) begin
84
                if (isxBranch) begin
85
                        gbl_branch_hist <= {gbl_branch_hist[1:0],takb};
86
                        branch_history_table[bht_wa] <= xbits_new;
87
                end
88
        end
89
end
90
 
91
endmodule
92
 

powered by: WebSVN 2.1.0

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