1 |
4 |
robfinch |
`timescale 1ns / 1ps
|
2 |
|
|
// ============================================================================
|
3 |
|
|
// __
|
4 |
|
|
// \\__/ o\ (C) 2015-2022 Robert Finch, Waterloo
|
5 |
|
|
// \ __ / All rights reserved.
|
6 |
|
|
// \/_// robfinch@finitron.ca
|
7 |
|
|
// ||
|
8 |
|
|
//
|
9 |
|
|
// BSD 3-Clause License
|
10 |
|
|
// Redistribution and use in source and binary forms, with or without
|
11 |
|
|
// modification, are permitted provided that the following conditions are met:
|
12 |
|
|
//
|
13 |
|
|
// 1. Redistributions of source code must retain the above copyright notice, this
|
14 |
|
|
// list of conditions and the following disclaimer.
|
15 |
|
|
//
|
16 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
17 |
|
|
// this list of conditions and the following disclaimer in the documentation
|
18 |
|
|
// and/or other materials provided with the distribution.
|
19 |
|
|
//
|
20 |
|
|
// 3. Neither the name of the copyright holder nor the names of its
|
21 |
|
|
// contributors may be used to endorse or promote products derived from
|
22 |
|
|
// this software without specific prior written permission.
|
23 |
|
|
//
|
24 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
25 |
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
26 |
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
27 |
|
|
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
28 |
|
|
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
29 |
|
|
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
30 |
|
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
31 |
|
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
32 |
|
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
33 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34 |
|
|
//
|
35 |
|
|
// ============================================================================
|
36 |
|
|
//
|
37 |
|
|
import mpmc9_pkg::*;
|
38 |
|
|
|
39 |
|
|
module mpmc9_spr_read_cache(rst, wclk, spr_num, wr, wadr, wdat, inv,
|
40 |
|
|
rclk, radr, rdat, hit
|
41 |
|
|
);
|
42 |
|
|
input rst;
|
43 |
|
|
input wclk;
|
44 |
|
|
input [4:0] spr_num;
|
45 |
|
|
input wr;
|
46 |
|
|
input [31:0] wadr;
|
47 |
|
|
input [127:0] wdat;
|
48 |
|
|
input inv;
|
49 |
|
|
input rclk;
|
50 |
|
|
input [31:0] radr;
|
51 |
|
|
output reg [127:0] rdat;
|
52 |
|
|
output reg hit;
|
53 |
|
|
|
54 |
|
|
(* ram_style="block" *)
|
55 |
|
|
reg [127:0] lines [0:511];
|
56 |
|
|
(* ram_style="block" *)
|
57 |
|
|
reg [27:0] tags [0:511];
|
58 |
|
|
(* ram_style="distributed" *)
|
59 |
|
|
reg [511:0] vbit;
|
60 |
|
|
reg [31:0] radrr;
|
61 |
|
|
reg [27:0] tago;
|
62 |
|
|
reg vbito;
|
63 |
|
|
wire [8:0] wadrs = {spr_num,wadr[7:4]};
|
64 |
|
|
wire [8:0] radrs = {spr_num,radrr[7:4]};
|
65 |
|
|
|
66 |
|
|
always_ff @(posedge rclk)
|
67 |
|
|
radrr <= radr;
|
68 |
|
|
always_ff @(posedge wclk)
|
69 |
|
|
if (wr) lines[wadrs] <= wdat;
|
70 |
|
|
always_ff @(posedge rclk)
|
71 |
|
|
rdat <= lines[radrs];
|
72 |
|
|
always_ff @(posedge rclk)
|
73 |
|
|
tago <= tags[radrs];
|
74 |
|
|
always_ff @(posedge rclk)
|
75 |
|
|
vbito <= vbit[radrs];
|
76 |
|
|
always_ff @(posedge wclk)
|
77 |
|
|
if (wr) tags[wadrs] <= wadr[31:4];
|
78 |
|
|
always_ff @(posedge wclk)
|
79 |
|
|
if (rst)
|
80 |
|
|
vbit <= 'b0;
|
81 |
|
|
else begin
|
82 |
|
|
if (wr)
|
83 |
|
|
vbit[wadrs] <= 1'b1;
|
84 |
|
|
else if (inv)
|
85 |
|
|
vbit[wadrs] <= 1'b0;
|
86 |
|
|
end
|
87 |
|
|
always_comb
|
88 |
|
|
hit = (tago==radrr[31:4]) && (vbito==1'b1);
|
89 |
|
|
|
90 |
|
|
endmodule
|