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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [common/] [FT64_dcache.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64_dcache.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
// Cache lines are 8 words long plus one hidden word for pointer tags
28
// The virtual address is multiplied by 9/8 to generate the physical address
29
// The tag memory is indexed by the virtual address.
30
 
31
module FT64_dcache(rst, wclk, ld, ldt, wr, sel, adr, i, spt, pti, rclk, o, pto, hit);
32
input rst;
33
input wclk;                             // write clock
34
input ld;                               // load cache data
35
input ldt;                              // load tagmem
36
input wr;
37
input [7:0] sel;
38
input [37:0] adr;                // virtual address
39
input [63:0] i;
40
input spt;                              // write pointer tag
41
input [7:0] pti;         // pointer tag value to write
42
input rclk;
43
output reg [63:0] o;
44
output reg [7:0] pto;    // pointer tag output
45
output reg hit;
46
parameter byt = 3'd0;
47
parameter wyde = 3'd1;
48
parameter tetra = 3'd2;
49
parameter octa = 3'd3;
50
 
51
integer n;
52
 
53
wire [63:0] dc0;
54
wire [31:0] v0, v1;
55
wire hit0a, hit1a;
56
 
57
wire [42:0] iadr33 = {adr,3'd0} + adr;   // 9*
58
wire [37:0] iadr = iadr33[42:3];         // /8
59
//wire [37:0] itadr = {iadr[42:6],6'd0} + 38'd64;
60
wire [2:0] itbitndx = {adr[5:3],3'd0};
61
 
62
reg [89:0] tagmem [0:255];
63
always @(posedge wclk)
64
if (rst) begin
65
        for (n = 0; n < 256; n = n + 1)
66
                tagmem[n][1:0] <= 2'b00; // clear valid and dirty bits
67
end
68
else begin
69
        casez({ldt,spt})
70
        2'b1?:  tagmem[adr[13:6]][89:0] <= {adr[37:14],1'b0,i};  // clear dirty bit on cache load
71
        2'b01:
72
                if (hit) begin
73
                        tagmem[adr[13:6]][89:64] <= {adr[37:14],1'b1};
74
                        for (n = 0; n < 8; n = n + 1)
75
                        tagmem[adr[13:6]][itbitndx|n] <= pti[n];
76
                end
77
        endcase
78
end
79
 
80
wire hit1 = tagmem[adr[13:6]][89:65]==adr[37:14] && tagmem[adr[13:6]][64]==1'b1;
81
reg hit2;
82
 
83
dcache_mem u1
84
(
85
        .rst(rst),
86
        .clka(wclk),
87
        .ena( wr | ld),
88
        .wea( ld ? 8'hFF: sel),
89
        .addra(adr[13:3]),
90
        .dina(i),
91
        .clkb(rclk),
92
        .addrb(adr[13:3]),
93
        .doutb(dc0),
94
        .ov(v0)
95
);
96
 
97
always @(posedge rclk)
98
        o <= dc0;
99
always @(posedge rclk)
100
        hit2 <= hit1;
101
always @(posedge rclk)
102
        hit <= hit2;
103
always @(posedge rclk)
104
begin
105
        for (n = 0; n < 8; n = n + 1)
106
        pto[n] <= tagmem[adr[13:6]][{adr[5:3],n[2:0]}];
107
end
108
 
109
endmodule
110
 
111
 
112
module dcache_mem(rst, clka, ena, wea, addra, dina, clkb, addrb, doutb, ov);
113
input rst;
114
input clka;
115
input ena;
116
input [7:0] wea;
117
input [10:0] addra;
118
input [63:0] dina;
119
input clkb;
120
input [10:0] addrb;
121
output reg [63:0] doutb;
122
output reg [7:0] ov;
123
 
124
reg [63:0] mem [0:2047];
125
reg [7:0] valid [0:2047];
126
reg [63:0] doutb1;
127
reg [7:0] ov1;
128
 
129
integer n;
130
 
131
initial begin
132
    for (n = 0; n < 2047; n = n + 1)
133
        valid[n] = 8'h00;
134
end
135
 
136
always @(posedge clka)
137
begin
138
    if (ena & wea[0])  mem[addra[13:3]][7:0] <= dina[7:0];
139
    if (ena & wea[1])  mem[addra[13:3]][15:8] <= dina[15:8];
140
    if (ena & wea[2])  mem[addra[13:3]][23:16] <= dina[23:16];
141
    if (ena & wea[3])  mem[addra[13:3]][31:24] <= dina[31:24];
142
    if (ena & wea[4])  mem[addra[13:3]][39:32] <= dina[39:32];
143
    if (ena & wea[5])  mem[addra[13:3]][47:40] <= dina[47:40];
144
    if (ena & wea[6])  mem[addra[13:3]][55:48] <= dina[55:48];
145
    if (ena & wea[7])  mem[addra[13:3]][63:56] <= dina[63:56];
146
    if (ena & wea[0])  valid[addra[13:3]][0] <= 1'b1;
147
    if (ena & wea[1])  valid[addra[13:3]][1] <= 1'b1;
148
    if (ena & wea[2])  valid[addra[13:3]][2] <= 1'b1;
149
    if (ena & wea[3])  valid[addra[13:3]][3] <= 1'b1;
150
    if (ena & wea[4])  valid[addra[13:3]][4] <= 1'b1;
151
    if (ena & wea[5])  valid[addra[13:3]][5] <= 1'b1;
152
    if (ena & wea[6])  valid[addra[13:3]][6] <= 1'b1;
153
    if (ena & wea[7])  valid[addra[13:3]][7] <= 1'b1;
154
end
155
 
156
always @(posedge clkb)
157
     doutb1 <= mem[addrb[13:3]];
158
always @(posedge clkb)
159
     doutb <= doutb1;
160
always @(posedge clkb)
161
     ov1 <= valid[addrb[13:3]];
162
always @(posedge clkb)
163
     ov <= ov1;
164
endmodule
165
 
166
 

powered by: WebSVN 2.1.0

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