mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-11 06:05:49 +00:00
Changed name of cache parameter NUMLINES to NUMSETS to better match book.
This commit is contained in:
parent
a88d5f403b
commit
273b41df99
10
src/cache/cache.sv
vendored
10
src/cache/cache.sv
vendored
@ -29,7 +29,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
module cache import cvw::*; #(parameter cvw_t P,
|
module cache import cvw::*; #(parameter cvw_t P,
|
||||||
parameter PA_BITS, XLEN, LINELEN, NUMLINES, NUMWAYS, LOGBWPL, WORDLEN, MUXINTERVAL, READ_ONLY_CACHE) (
|
parameter PA_BITS, XLEN, LINELEN, NUMSETS, NUMWAYS, LOGBWPL, WORDLEN, MUXINTERVAL, READ_ONLY_CACHE) (
|
||||||
input logic clk,
|
input logic clk,
|
||||||
input logic reset,
|
input logic reset,
|
||||||
input logic Stall, // Stall the cache, preventing new accesses. In-flight access finished but does not return to READY
|
input logic Stall, // Stall the cache, preventing new accesses. In-flight access finished but does not return to READY
|
||||||
@ -63,12 +63,12 @@ module cache import cvw::*; #(parameter cvw_t P,
|
|||||||
// Cache parameters
|
// Cache parameters
|
||||||
localparam LINEBYTELEN = LINELEN/8; // Line length in bytes
|
localparam LINEBYTELEN = LINELEN/8; // Line length in bytes
|
||||||
localparam OFFSETLEN = $clog2(LINEBYTELEN); // Number of bits in offset field
|
localparam OFFSETLEN = $clog2(LINEBYTELEN); // Number of bits in offset field
|
||||||
localparam SETLEN = $clog2(NUMLINES); // Number of set bits
|
localparam SETLEN = $clog2(NUMSETS); // Number of set bits
|
||||||
localparam SETTOP = SETLEN+OFFSETLEN; // Number of set plus offset bits
|
localparam SETTOP = SETLEN+OFFSETLEN; // Number of set plus offset bits
|
||||||
localparam TAGLEN = PA_BITS - SETTOP; // Number of tag bits
|
localparam TAGLEN = PA_BITS - SETTOP; // Number of tag bits
|
||||||
localparam CACHEWORDSPERLINE = LINELEN/WORDLEN;// Number of words in cache line
|
localparam CACHEWORDSPERLINE = LINELEN/WORDLEN;// Number of words in cache line
|
||||||
localparam LOGCWPL = $clog2(CACHEWORDSPERLINE);// Log2 of ^
|
localparam LOGCWPL = $clog2(CACHEWORDSPERLINE);// Log2 of ^
|
||||||
localparam FLUSHADRTHRESHOLD = NUMLINES - 1; // Used to determine when flush is complete
|
localparam FLUSHADRTHRESHOLD = NUMSETS - 1; // Used to determine when flush is complete
|
||||||
localparam LOGLLENBYTES = $clog2(WORDLEN/8); // Number of bits to address a word
|
localparam LOGLLENBYTES = $clog2(WORDLEN/8); // Number of bits to address a word
|
||||||
|
|
||||||
|
|
||||||
@ -119,14 +119,14 @@ module cache import cvw::*; #(parameter cvw_t P,
|
|||||||
AdrSelMuxSelTag, CacheSetTag);
|
AdrSelMuxSelTag, CacheSetTag);
|
||||||
|
|
||||||
// Array of cache ways, along with victim, hit, dirty, and read merging logic
|
// Array of cache ways, along with victim, hit, dirty, and read merging logic
|
||||||
cacheway #(P, PA_BITS, XLEN, NUMLINES, LINELEN, TAGLEN, OFFSETLEN, SETLEN, READ_ONLY_CACHE) CacheWays[NUMWAYS-1:0](
|
cacheway #(P, PA_BITS, XLEN, NUMSETS, LINELEN, TAGLEN, OFFSETLEN, SETLEN, READ_ONLY_CACHE) CacheWays[NUMWAYS-1:0](
|
||||||
.clk, .reset, .CacheEn, .CacheSetData, .CacheSetTag, .PAdr, .LineWriteData, .LineByteMask, .SelVictim,
|
.clk, .reset, .CacheEn, .CacheSetData, .CacheSetTag, .PAdr, .LineWriteData, .LineByteMask, .SelVictim,
|
||||||
.SetValid, .ClearValid, .SetDirty, .ClearDirty, .VictimWay,
|
.SetValid, .ClearValid, .SetDirty, .ClearDirty, .VictimWay,
|
||||||
.FlushWay, .FlushCache, .ReadDataLineWay, .HitWay, .ValidWay, .DirtyWay, .HitDirtyWay, .TagWay, .FlushStage, .InvalidateCache);
|
.FlushWay, .FlushCache, .ReadDataLineWay, .HitWay, .ValidWay, .DirtyWay, .HitDirtyWay, .TagWay, .FlushStage, .InvalidateCache);
|
||||||
|
|
||||||
// Select victim way for associative caches
|
// Select victim way for associative caches
|
||||||
if(NUMWAYS > 1) begin:vict
|
if(NUMWAYS > 1) begin:vict
|
||||||
cacheLRU #(NUMWAYS, SETLEN, OFFSETLEN, NUMLINES) cacheLRU(
|
cacheLRU #(NUMWAYS, SETLEN, OFFSETLEN, NUMSETS) cacheLRU(
|
||||||
.clk, .reset, .FlushStage, .CacheEn, .HitWay, .ValidWay, .VictimWay, .CacheSetData, .CacheSetTag, .LRUWriteEn,
|
.clk, .reset, .FlushStage, .CacheEn, .HitWay, .ValidWay, .VictimWay, .CacheSetData, .CacheSetTag, .LRUWriteEn,
|
||||||
.SetValid, .ClearValid, .PAdr(PAdr[SETTOP-1:OFFSETLEN]), .InvalidateCache);
|
.SetValid, .ClearValid, .PAdr(PAdr[SETTOP-1:OFFSETLEN]), .InvalidateCache);
|
||||||
end else
|
end else
|
||||||
|
6
src/cache/cacheLRU.sv
vendored
6
src/cache/cacheLRU.sv
vendored
@ -29,7 +29,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
module cacheLRU
|
module cacheLRU
|
||||||
#(parameter NUMWAYS = 4, SETLEN = 9, OFFSETLEN = 5, NUMLINES = 128) (
|
#(parameter NUMWAYS = 4, SETLEN = 9, OFFSETLEN = 5, NUMSETS = 128) (
|
||||||
input logic clk,
|
input logic clk,
|
||||||
input logic reset,
|
input logic reset,
|
||||||
input logic FlushStage,
|
input logic FlushStage,
|
||||||
@ -48,7 +48,7 @@ module cacheLRU
|
|||||||
|
|
||||||
localparam LOGNUMWAYS = $clog2(NUMWAYS);
|
localparam LOGNUMWAYS = $clog2(NUMWAYS);
|
||||||
|
|
||||||
logic [NUMWAYS-2:0] LRUMemory [NUMLINES-1:0];
|
logic [NUMWAYS-2:0] LRUMemory [NUMSETS-1:0];
|
||||||
logic [NUMWAYS-2:0] CurrLRU;
|
logic [NUMWAYS-2:0] CurrLRU;
|
||||||
logic [NUMWAYS-2:0] NextLRU;
|
logic [NUMWAYS-2:0] NextLRU;
|
||||||
logic [LOGNUMWAYS-1:0] HitWayEncoded, Way;
|
logic [LOGNUMWAYS-1:0] HitWayEncoded, Way;
|
||||||
@ -146,7 +146,7 @@ module cacheLRU
|
|||||||
// Move to = to keep Verilator happy and simulator running fast
|
// Move to = to keep Verilator happy and simulator running fast
|
||||||
always_ff @(posedge clk) begin
|
always_ff @(posedge clk) begin
|
||||||
if (reset | (InvalidateCache & ~FlushStage))
|
if (reset | (InvalidateCache & ~FlushStage))
|
||||||
for (int set = 0; set < NUMLINES; set++) LRUMemory[set] = '0; // exclusion-tag: initialize
|
for (int set = 0; set < NUMSETS; set++) LRUMemory[set] = '0; // exclusion-tag: initialize
|
||||||
else if(CacheEn) begin
|
else if(CacheEn) begin
|
||||||
// Because we are using blocking assignments, change to LRUMemory must occur after LRUMemory is used so we get the proper value
|
// Because we are using blocking assignments, change to LRUMemory must occur after LRUMemory is used so we get the proper value
|
||||||
if(LRUWriteEn & (PAdr == CacheSetTag)) CurrLRU = NextLRU;
|
if(LRUWriteEn & (PAdr == CacheSetTag)) CurrLRU = NextLRU;
|
||||||
|
18
src/cache/cacheway.sv
vendored
18
src/cache/cacheway.sv
vendored
@ -29,14 +29,14 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
module cacheway import cvw::*; #(parameter cvw_t P,
|
module cacheway import cvw::*; #(parameter cvw_t P,
|
||||||
parameter PA_BITS, XLEN, NUMLINES=512, LINELEN = 256, TAGLEN = 26,
|
parameter PA_BITS, XLEN, NUMSETS=512, LINELEN = 256, TAGLEN = 26,
|
||||||
OFFSETLEN = 5, INDEXLEN = 9, READ_ONLY_CACHE = 0) (
|
OFFSETLEN = 5, INDEXLEN = 9, READ_ONLY_CACHE = 0) (
|
||||||
input logic clk,
|
input logic clk,
|
||||||
input logic reset,
|
input logic reset,
|
||||||
input logic FlushStage, // Pipeline flush of second stage (prevent writes and bus operations)
|
input logic FlushStage, // Pipeline flush of second stage (prevent writes and bus operations)
|
||||||
input logic CacheEn, // Enable the cache memory arrays. Disable hold read data constant
|
input logic CacheEn, // Enable the cache memory arrays. Disable hold read data constant
|
||||||
input logic [$clog2(NUMLINES)-1:0] CacheSetData, // Cache address, the output of the address select mux, NextAdr, PAdr, or FlushAdr
|
input logic [$clog2(NUMSETS)-1:0] CacheSetData, // Cache address, the output of the address select mux, NextAdr, PAdr, or FlushAdr
|
||||||
input logic [$clog2(NUMLINES)-1:0] CacheSetTag, // Cache address, the output of the address select mux, NextAdr, PAdr, or FlushAdr
|
input logic [$clog2(NUMSETS)-1:0] CacheSetTag, // Cache address, the output of the address select mux, NextAdr, PAdr, or FlushAdr
|
||||||
input logic [PA_BITS-1:0] PAdr, // Physical address
|
input logic [PA_BITS-1:0] PAdr, // Physical address
|
||||||
input logic [LINELEN-1:0] LineWriteData, // Final data written to cache (D$ only)
|
input logic [LINELEN-1:0] LineWriteData, // Final data written to cache (D$ only)
|
||||||
input logic SetValid, // Set the valid bit in the selected way and set
|
input logic SetValid, // Set the valid bit in the selected way and set
|
||||||
@ -63,8 +63,8 @@ module cacheway import cvw::*; #(parameter cvw_t P,
|
|||||||
localparam LOGXLENBYTES = $clog2(XLEN/8);
|
localparam LOGXLENBYTES = $clog2(XLEN/8);
|
||||||
localparam BYTESPERWORD = XLEN/8;
|
localparam BYTESPERWORD = XLEN/8;
|
||||||
|
|
||||||
logic [NUMLINES-1:0] ValidBits;
|
logic [NUMSETS-1:0] ValidBits;
|
||||||
logic [NUMLINES-1:0] DirtyBits;
|
logic [NUMSETS-1:0] DirtyBits;
|
||||||
logic [LINELEN-1:0] ReadDataLine;
|
logic [LINELEN-1:0] ReadDataLine;
|
||||||
logic [TAGLEN-1:0] ReadTag;
|
logic [TAGLEN-1:0] ReadTag;
|
||||||
logic Dirty;
|
logic Dirty;
|
||||||
@ -112,7 +112,7 @@ module cacheway import cvw::*; #(parameter cvw_t P,
|
|||||||
// Tag Array
|
// Tag Array
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ram1p1rwe #(.USE_SRAM(P.USE_SRAM), .DEPTH(NUMLINES), .WIDTH(TAGLEN)) CacheTagMem(.clk, .ce(CacheEn),
|
ram1p1rwe #(.USE_SRAM(P.USE_SRAM), .DEPTH(NUMSETS), .WIDTH(TAGLEN)) CacheTagMem(.clk, .ce(CacheEn),
|
||||||
.addr(CacheSetTag), .dout(ReadTag),
|
.addr(CacheSetTag), .dout(ReadTag),
|
||||||
.din(PAdr[PA_BITS-1:OFFSETLEN+INDEXLEN]), .we(SetValidEN));
|
.din(PAdr[PA_BITS-1:OFFSETLEN+INDEXLEN]), .we(SetValidEN));
|
||||||
|
|
||||||
@ -136,12 +136,12 @@ module cacheway import cvw::*; #(parameter cvw_t P,
|
|||||||
|
|
||||||
for(words = 0; words < NUMSRAM; words++) begin: word
|
for(words = 0; words < NUMSRAM; words++) begin: word
|
||||||
if (READ_ONLY_CACHE) begin:wordram // no byte-enable needed for i$.
|
if (READ_ONLY_CACHE) begin:wordram // no byte-enable needed for i$.
|
||||||
ram1p1rwe #(.USE_SRAM(P.USE_SRAM), .DEPTH(NUMLINES), .WIDTH(P.CACHE_SRAMLEN)) CacheDataMem(.clk, .ce(CacheEn), .addr(CacheSetData),
|
ram1p1rwe #(.USE_SRAM(P.USE_SRAM), .DEPTH(NUMSETS), .WIDTH(P.CACHE_SRAMLEN)) CacheDataMem(.clk, .ce(CacheEn), .addr(CacheSetData),
|
||||||
.dout(ReadDataLine[P.CACHE_SRAMLEN*(words+1)-1:P.CACHE_SRAMLEN*words]),
|
.dout(ReadDataLine[P.CACHE_SRAMLEN*(words+1)-1:P.CACHE_SRAMLEN*words]),
|
||||||
.din(LineWriteData[P.CACHE_SRAMLEN*(words+1)-1:P.CACHE_SRAMLEN*words]),
|
.din(LineWriteData[P.CACHE_SRAMLEN*(words+1)-1:P.CACHE_SRAMLEN*words]),
|
||||||
.we(SelectedWriteWordEn));
|
.we(SelectedWriteWordEn));
|
||||||
end else begin:wordram // D$ needs byte enables
|
end else begin:wordram // D$ needs byte enables
|
||||||
ram1p1rwbe #(.USE_SRAM(P.USE_SRAM), .DEPTH(NUMLINES), .WIDTH(P.CACHE_SRAMLEN)) CacheDataMem(.clk, .ce(CacheEn), .addr(CacheSetData),
|
ram1p1rwbe #(.USE_SRAM(P.USE_SRAM), .DEPTH(NUMSETS), .WIDTH(P.CACHE_SRAMLEN)) CacheDataMem(.clk, .ce(CacheEn), .addr(CacheSetData),
|
||||||
.dout(ReadDataLine[P.CACHE_SRAMLEN*(words+1)-1:P.CACHE_SRAMLEN*words]),
|
.dout(ReadDataLine[P.CACHE_SRAMLEN*(words+1)-1:P.CACHE_SRAMLEN*words]),
|
||||||
.din(LineWriteData[P.CACHE_SRAMLEN*(words+1)-1:P.CACHE_SRAMLEN*words]),
|
.din(LineWriteData[P.CACHE_SRAMLEN*(words+1)-1:P.CACHE_SRAMLEN*words]),
|
||||||
.we(SelectedWriteWordEn), .bwe(FinalByteMask[SRAMLENINBYTES*(words+1)-1:SRAMLENINBYTES*words]));
|
.we(SelectedWriteWordEn), .bwe(FinalByteMask[SRAMLENINBYTES*(words+1)-1:SRAMLENINBYTES*words]));
|
||||||
@ -173,7 +173,7 @@ module cacheway import cvw::*; #(parameter cvw_t P,
|
|||||||
if (!READ_ONLY_CACHE) begin:dirty
|
if (!READ_ONLY_CACHE) begin:dirty
|
||||||
always_ff @(posedge clk) begin
|
always_ff @(posedge clk) begin
|
||||||
// reset is optional. Consider merging with TAG array in the future.
|
// reset is optional. Consider merging with TAG array in the future.
|
||||||
//if (reset) DirtyBits <= {NUMLINES{1'b0}};
|
//if (reset) DirtyBits <= {NUMSETS{1'b0}};
|
||||||
if(CacheEn) begin
|
if(CacheEn) begin
|
||||||
Dirty <= DirtyBits[CacheSetTag];
|
Dirty <= DirtyBits[CacheSetTag];
|
||||||
if((SetDirtyWay | ClearDirtyWay) & ~FlushStage) DirtyBits[CacheSetData] <= SetDirtyWay; // exclusion-tag: cache UpdateDirty
|
if((SetDirtyWay | ClearDirtyWay) & ~FlushStage) DirtyBits[CacheSetData] <= SetDirtyWay; // exclusion-tag: cache UpdateDirty
|
||||||
|
@ -239,7 +239,7 @@ module ifu import cvw::*; #(parameter cvw_t P) (
|
|||||||
assign CacheRWF = ~ITLBMissF & CacheableF & ~SelIROM ? IFURWF : '0;
|
assign CacheRWF = ~ITLBMissF & CacheableF & ~SelIROM ? IFURWF : '0;
|
||||||
// *** RT: PAdr and NextSet are replaced with mux between PCPF/IEUAdrM and PCSpillNextF/IEUAdrE.
|
// *** RT: PAdr and NextSet are replaced with mux between PCPF/IEUAdrM and PCSpillNextF/IEUAdrE.
|
||||||
cache #(.P(P), .PA_BITS(P.PA_BITS), .XLEN(P.XLEN), .LINELEN(P.ICACHE_LINELENINBITS),
|
cache #(.P(P), .PA_BITS(P.PA_BITS), .XLEN(P.XLEN), .LINELEN(P.ICACHE_LINELENINBITS),
|
||||||
.NUMLINES(P.ICACHE_WAYSIZEINBYTES*8/P.ICACHE_LINELENINBITS),
|
.NUMSETS(P.ICACHE_WAYSIZEINBYTES*8/P.ICACHE_LINELENINBITS),
|
||||||
.NUMWAYS(P.ICACHE_NUMWAYS), .LOGBWPL(LOGBWPL), .WORDLEN(32), .MUXINTERVAL(16), .READ_ONLY_CACHE(1))
|
.NUMWAYS(P.ICACHE_NUMWAYS), .LOGBWPL(LOGBWPL), .WORDLEN(32), .MUXINTERVAL(16), .READ_ONLY_CACHE(1))
|
||||||
icache(.clk, .reset, .FlushStage(FlushD), .Stall(GatedStallD),
|
icache(.clk, .reset, .FlushStage(FlushD), .Stall(GatedStallD),
|
||||||
.FetchBuffer, .CacheBusAck(ICacheBusAck),
|
.FetchBuffer, .CacheBusAck(ICacheBusAck),
|
||||||
|
@ -329,7 +329,7 @@ module lsu import cvw::*; #(parameter cvw_t P) (
|
|||||||
assign CacheRWM = (CacheableM & ~SelDTIM) ? LSURWM : '0;
|
assign CacheRWM = (CacheableM & ~SelDTIM) ? LSURWM : '0;
|
||||||
assign FlushDCache = FlushDCacheM & ~(SelHPTW);
|
assign FlushDCache = FlushDCacheM & ~(SelHPTW);
|
||||||
|
|
||||||
cache #(.P(P), .PA_BITS(P.PA_BITS), .XLEN(P.XLEN), .LINELEN(P.DCACHE_LINELENINBITS), .NUMLINES(P.DCACHE_WAYSIZEINBYTES*8/LINELEN),
|
cache #(.P(P), .PA_BITS(P.PA_BITS), .XLEN(P.XLEN), .LINELEN(P.DCACHE_LINELENINBITS), .NUMSETS(P.DCACHE_WAYSIZEINBYTES*8/LINELEN),
|
||||||
.NUMWAYS(P.DCACHE_NUMWAYS), .LOGBWPL(LLENLOGBWPL), .WORDLEN(CACHEWORDLEN), .MUXINTERVAL(P.LLEN), .READ_ONLY_CACHE(0)) dcache(
|
.NUMWAYS(P.DCACHE_NUMWAYS), .LOGBWPL(LLENLOGBWPL), .WORDLEN(CACHEWORDLEN), .MUXINTERVAL(P.LLEN), .READ_ONLY_CACHE(0)) dcache(
|
||||||
.clk, .reset, .Stall(GatedStallW & ~SelSpillE), .SelBusBeat, .FlushStage(FlushW | IgnoreRequestTLB),
|
.clk, .reset, .Stall(GatedStallW & ~SelSpillE), .SelBusBeat, .FlushStage(FlushW | IgnoreRequestTLB),
|
||||||
.CacheRW(CacheRWM),
|
.CacheRW(CacheRWM),
|
||||||
|
Loading…
Reference in New Issue
Block a user