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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64/] [rtl/] [common/] [FT64_RSB.v] - Blame information for rev 43

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 43 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64_RSB.v
9
//
10
// This source file is free software: you can redistribute it and/or modify 
11
// it under the terms of the GNU Lesser General Public License as published 
12
// by the Free Software Foundation, either version 3 of the License, or     
13
// (at your option) any later version.                                      
14
//                                                                          
15
// This source file is distributed in the hope that it will be useful,      
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
18
// GNU General Public License for more details.                             
19
//                                                                          
20
// You should have received a copy of the GNU General Public License        
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
22
//
23
// ============================================================================
24
//
25
`include "FT64_defines.vh"
26
 
27
// Return address stack predictor is updated during the fetch stage on the 
28
// assumption that previous flow controls (branches) predicted correctly.
29
// Otherwise many small routines wouldn't predict the return address
30
// correctly because they hit the RET before the CALL reaches the 
31
// commit stage.
32
 
33
module FT64_RSB(rst, clk, regLR, queued1, queued2,
34
        fetchbuf0_v, fetchbuf0_pc, fetchbuf0_instr,
35
        fetchbuf1_v, fetchbuf1_pc, fetchbuf1_instr,
36
        stompedRets, stompedRet,
37
        pc
38
);
39
parameter AMSB = 31;
40
parameter DEPTH = 32;
41
input rst;
42
input clk;
43
input [4:0] regLR;
44
input queued1;
45
input queued2;
46
input fetchbuf0_v;
47
input [31:0] fetchbuf0_instr;
48
input [AMSB:0] fetchbuf0_pc;
49
input fetchbuf1_v;
50
input [31:0] fetchbuf1_instr;
51
input [AMSB:0] fetchbuf1_pc;
52
input [3:0] stompedRets;
53
input stompedRet;
54
output [AMSB:0] pc;
55
 
56
parameter RSTPC = 32'hFFFC0100;
57
integer n;
58
reg [AMSB:0] ras [0:DEPTH-1];
59
reg [4:0] rasp;
60
assign pc = ras[rasp];
61
 
62
always @(posedge clk)
63
if (rst) begin
64
    for (n = 0; n < 32; n = n + 1)
65
         ras[n] <= RSTPC;
66
     rasp <= 5'd0;
67
end
68
else begin
69
        if (fetchbuf0_v && fetchbuf1_v && (queued1 || queued2)) begin
70
        case(fetchbuf0_instr[`INSTRUCTION_OP])
71
        `JAL:
72
                begin
73
                        // JAL LR,xxxx  assume call
74
                        if (fetchbuf0_instr[`INSTRUCTION_RB]==regLR) begin
75
                        ras[((rasp-6'd1)&31)] <= fetchbuf0_pc + 32'd4;
76
                        rasp <= rasp - 4'd1;
77
                        end
78
                        // JAL r0,[r29] assume a ret
79
                        else if (fetchbuf0_instr[`INSTRUCTION_RB]==5'd00 &&
80
                                         fetchbuf0_instr[`INSTRUCTION_RA]==regLR) begin
81
                                rasp <= rasp + 4'd1;
82
                        end
83
                end
84
        `CALL:
85
            begin
86
                 ras[((rasp-6'd1)&31)] <= fetchbuf0_pc + 32'd4;
87
                 rasp <= rasp - 4'd1;
88
            end
89
        `RET:   begin
90
                        $display("RSP: Added 1");
91
                        rasp <= rasp + 4'd1;
92
                        end
93
        default:        ;
94
        endcase
95
        end
96
    else if (fetchbuf1_v && queued1)
97
        case(fetchbuf1_instr[`INSTRUCTION_OP])
98
        `JAL:
99
                if (fetchbuf1_instr[`INSTRUCTION_RB]==regLR) begin
100
                 ras[((rasp-6'd1)&31)] <= fetchbuf1_pc + 32'd4;
101
                 rasp <= rasp - 4'd1;
102
                end
103
                else if (fetchbuf1_instr[`INSTRUCTION_RB]==5'd00 &&
104
                                 fetchbuf1_instr[`INSTRUCTION_RA]==regLR) begin
105
                        rasp <= rasp + 4'd1;
106
                end
107
        `CALL:
108
            begin
109
                 ras[((rasp-6'd1)&31)] <= fetchbuf1_pc + 32'd4;
110
                 rasp <= rasp - 4'd1;
111
            end
112
        `RET:   begin
113
                        rasp <= rasp + 4'd1;
114
                        $display("RSP: Added 1");
115
                        end
116
        default:        ;
117
        endcase
118
    else if (fetchbuf0_v && queued1)
119
        case(fetchbuf0_instr[`INSTRUCTION_OP])
120
        `JAL:
121
                if (fetchbuf0_instr[`INSTRUCTION_RB]==regLR) begin
122
                 ras[((rasp-6'd1)&31)] <= fetchbuf0_pc + 32'd4;
123
                 rasp <= rasp - 4'd1;
124
                end
125
                else if (fetchbuf0_instr[`INSTRUCTION_RB]==5'd00 &&
126
                                 fetchbuf0_instr[`INSTRUCTION_RA]==regLR) begin
127
                        rasp <= rasp + 4'd1;
128
                end
129
        `CALL:
130
            begin
131
                 ras[((rasp-6'd1)&31)] <= fetchbuf0_pc + 32'd4;
132
                 rasp <= rasp - 4'd1;
133
            end
134
        `RET:   begin
135
                        $display("RSP: Added 1");
136
                        rasp <= rasp + 4'd1;
137
                        end
138
        default:        ;
139
        endcase
140
    if (stompedRets > 4'd0) begin
141
        $display("Stomped Rets: %d", stompedRets);
142
        rasp <= rasp - stompedRets;
143
    end
144
    else if (stompedRet) begin
145
        $display("Stomped Ret");
146
        rasp <= rasp - 5'd1;
147
    end
148
end
149
 
150
endmodule

powered by: WebSVN 2.1.0

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