mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-11 06:05:49 +00:00
Added byte write enables to cache SRAMs.
This commit is contained in:
parent
b1340653cf
commit
d5f524a15e
5
pipelined/src/cache/cache.sv
vendored
5
pipelined/src/cache/cache.sv
vendored
@ -41,6 +41,7 @@ module cache #(parameter LINELEN, NUMLINES, NUMWAYS, DCACHE = 1) (
|
|||||||
input logic InvalidateCacheM,
|
input logic InvalidateCacheM,
|
||||||
input logic [11:0] NextAdr, // virtual address, but we only use the lower 12 bits.
|
input logic [11:0] NextAdr, // virtual address, but we only use the lower 12 bits.
|
||||||
input logic [`PA_BITS-1:0] PAdr, // physical address
|
input logic [`PA_BITS-1:0] PAdr, // physical address
|
||||||
|
input logic [(`XLEN-1)/8:0] ByteWEN,
|
||||||
input logic [`XLEN-1:0] FinalWriteData,
|
input logic [`XLEN-1:0] FinalWriteData,
|
||||||
output logic CacheCommitted,
|
output logic CacheCommitted,
|
||||||
output logic CacheStall,
|
output logic CacheStall,
|
||||||
@ -50,7 +51,7 @@ module cache #(parameter LINELEN, NUMLINES, NUMWAYS, DCACHE = 1) (
|
|||||||
output logic save, restore,
|
output logic save, restore,
|
||||||
// lsu control
|
// lsu control
|
||||||
input logic IgnoreRequestTLB,
|
input logic IgnoreRequestTLB,
|
||||||
input logic IgnoreRequestTrapM,
|
input logic IgnoreRequestTrapM,
|
||||||
input logic Cacheable,
|
input logic Cacheable,
|
||||||
// Bus fsm interface
|
// Bus fsm interface
|
||||||
output logic CacheFetchLine,
|
output logic CacheFetchLine,
|
||||||
@ -114,7 +115,7 @@ module cache #(parameter LINELEN, NUMLINES, NUMWAYS, DCACHE = 1) (
|
|||||||
|
|
||||||
// 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 #(NUMLINES, LINELEN, TAGLEN, OFFSETLEN, SETLEN) CacheWays[NUMWAYS-1:0](
|
cacheway #(NUMLINES, LINELEN, TAGLEN, OFFSETLEN, SETLEN) CacheWays[NUMWAYS-1:0](
|
||||||
.clk, .reset, .RAdr, .PAdr, .CacheWriteData,
|
.clk, .reset, .RAdr, .PAdr, .CacheWriteData, .ByteWEN,
|
||||||
.SetValidWay, .ClearValidWay, .SetDirtyWay, .ClearDirtyWay, .SelEvict, .VictimWay,
|
.SetValidWay, .ClearValidWay, .SetDirtyWay, .ClearDirtyWay, .SelEvict, .VictimWay,
|
||||||
.FlushWay, .SelFlush, .ReadDataLineWay, .HitWay, .VictimDirtyWay, .VictimTagWay,
|
.FlushWay, .SelFlush, .ReadDataLineWay, .HitWay, .VictimDirtyWay, .VictimTagWay,
|
||||||
.Invalidate(InvalidateCacheM));
|
.Invalidate(InvalidateCacheM));
|
||||||
|
9
pipelined/src/cache/cacheway.sv
vendored
9
pipelined/src/cache/cacheway.sv
vendored
@ -47,7 +47,7 @@ module cacheway #(parameter NUMLINES=512, parameter LINELEN = 256, TAGLEN = 26,
|
|||||||
input logic VictimWay,
|
input logic VictimWay,
|
||||||
input logic FlushWay,
|
input logic FlushWay,
|
||||||
input logic Invalidate,
|
input logic Invalidate,
|
||||||
|
input logic [(`XLEN-1)/8:0] ByteWEN,
|
||||||
|
|
||||||
output logic [LINELEN-1:0] ReadDataLineWay,
|
output logic [LINELEN-1:0] ReadDataLineWay,
|
||||||
output logic HitWay,
|
output logic HitWay,
|
||||||
@ -69,6 +69,7 @@ module cacheway #(parameter NUMLINES=512, parameter LINELEN = 256, TAGLEN = 26,
|
|||||||
logic [$clog2(NUMLINES)-1:0] RAdrD;
|
logic [$clog2(NUMLINES)-1:0] RAdrD;
|
||||||
logic [2**LOGWPL-1:0] MemPAdrDecoded;
|
logic [2**LOGWPL-1:0] MemPAdrDecoded;
|
||||||
logic [LINELEN/`XLEN-1:0] SelectedWriteWordEn;
|
logic [LINELEN/`XLEN-1:0] SelectedWriteWordEn;
|
||||||
|
logic [(`XLEN-1)/8:0] FinalByteWEN;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Write Enable demux
|
// Write Enable demux
|
||||||
@ -77,13 +78,15 @@ module cacheway #(parameter NUMLINES=512, parameter LINELEN = 256, TAGLEN = 26,
|
|||||||
.bin(PAdr[LOGWPL+LOGXLENBYTES-1:LOGXLENBYTES]), .decoded(MemPAdrDecoded));
|
.bin(PAdr[LOGWPL+LOGXLENBYTES-1:LOGXLENBYTES]), .decoded(MemPAdrDecoded));
|
||||||
// If writing the whole line set all write enables to 1, else only set the correct word.
|
// If writing the whole line set all write enables to 1, else only set the correct word.
|
||||||
assign SelectedWriteWordEn = SetValidWay ? '1 : SetDirtyWay ? MemPAdrDecoded : '0; // OR-AND
|
assign SelectedWriteWordEn = SetValidWay ? '1 : SetDirtyWay ? MemPAdrDecoded : '0; // OR-AND
|
||||||
|
//assign FinalByteWEN = SetValidWay ? '1 : ByteWEN; // OR
|
||||||
|
assign FinalByteWEN = '1;//SetValidWay ? '1 : ByteWEN; // OR
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Tag Array
|
// Tag Array
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
sram1p1rw #(.DEPTH(NUMLINES), .WIDTH(TAGLEN)) CacheTagMem(.clk,
|
sram1p1rw #(.DEPTH(NUMLINES), .WIDTH(TAGLEN)) CacheTagMem(.clk,
|
||||||
.Adr(RAdr), .ReadData(ReadTag),
|
.Adr(RAdr), .ReadData(ReadTag), .ByteWEN('1),
|
||||||
.CacheWriteData(PAdr[`PA_BITS-1:OFFSETLEN+INDEXLEN]), .WriteEnable(SetValidWay));
|
.CacheWriteData(PAdr[`PA_BITS-1:OFFSETLEN+INDEXLEN]), .WriteEnable(SetValidWay));
|
||||||
|
|
||||||
// AND portion of distributed tag multiplexer
|
// AND portion of distributed tag multiplexer
|
||||||
@ -102,7 +105,7 @@ module cacheway #(parameter NUMLINES=512, parameter LINELEN = 256, TAGLEN = 26,
|
|||||||
sram1p1rw #(.DEPTH(NUMLINES), .WIDTH(`XLEN)) CacheDataMem(.clk, .Adr(RAdr),
|
sram1p1rw #(.DEPTH(NUMLINES), .WIDTH(`XLEN)) CacheDataMem(.clk, .Adr(RAdr),
|
||||||
.ReadData(ReadDataLine[(words+1)*`XLEN-1:words*`XLEN] ),
|
.ReadData(ReadDataLine[(words+1)*`XLEN-1:words*`XLEN] ),
|
||||||
.CacheWriteData(CacheWriteData[(words+1)*`XLEN-1:words*`XLEN]),
|
.CacheWriteData(CacheWriteData[(words+1)*`XLEN-1:words*`XLEN]),
|
||||||
.WriteEnable(SelectedWriteWordEn[words]));
|
.WriteEnable(SelectedWriteWordEn[words]), .ByteWEN(FinalByteWEN));
|
||||||
end
|
end
|
||||||
|
|
||||||
// AND portion of distributed read multiplexers
|
// AND portion of distributed read multiplexers
|
||||||
|
19
pipelined/src/cache/sram1p1rw.sv
vendored
19
pipelined/src/cache/sram1p1rw.sv
vendored
@ -38,18 +38,31 @@ module sram1p1rw #(parameter DEPTH=128, WIDTH=256) (
|
|||||||
input logic [$clog2(DEPTH)-1:0] Adr,
|
input logic [$clog2(DEPTH)-1:0] Adr,
|
||||||
input logic [WIDTH-1:0] CacheWriteData,
|
input logic [WIDTH-1:0] CacheWriteData,
|
||||||
input logic WriteEnable,
|
input logic WriteEnable,
|
||||||
|
input logic [(WIDTH-1)/8:0] ByteWEN,
|
||||||
output logic [WIDTH-1:0] ReadData);
|
output logic [WIDTH-1:0] ReadData);
|
||||||
|
|
||||||
logic [WIDTH-1:0] StoredData[DEPTH-1:0];
|
logic [WIDTH-1:0] StoredData[DEPTH-1:0];
|
||||||
logic [$clog2(DEPTH)-1:0] AdrD;
|
logic [$clog2(DEPTH)-1:0] AdrD;
|
||||||
logic WriteEnableD;
|
logic WriteEnableD;
|
||||||
|
|
||||||
|
always_ff @(posedge clk) AdrD <= Adr;
|
||||||
|
|
||||||
|
genvar index;
|
||||||
|
for(index = 0; index < WIDTH/8; index++) begin
|
||||||
always_ff @(posedge clk) begin
|
always_ff @(posedge clk) begin
|
||||||
AdrD <= Adr;
|
if (WriteEnable & ByteWEN[index]) begin
|
||||||
if (WriteEnable) begin
|
StoredData[Adr][8*(index+1)-1:8*index] <= #1 CacheWriteData[8*(index+1)-1:8*index];
|
||||||
StoredData[Adr] <= #1 CacheWriteData;
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
// if not a multiple of 8, MSByte is not 8 bits long.
|
||||||
|
if(WIDTH%8 != 0) begin
|
||||||
|
always_ff @(posedge clk) begin
|
||||||
|
if (WriteEnable & ByteWEN[WIDTH/8]) begin
|
||||||
|
StoredData[Adr][WIDTH-1:WIDTH-WIDTH%8] <= #1 CacheWriteData[WIDTH-1:WIDTH-WIDTH%8];
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
assign ReadData = StoredData[AdrD];
|
assign ReadData = StoredData[AdrD];
|
||||||
endmodule
|
endmodule
|
||||||
|
@ -220,6 +220,7 @@ module ifu (
|
|||||||
.CacheWriteLine(), .ReadDataLine(ReadDataLine),
|
.CacheWriteLine(), .ReadDataLine(ReadDataLine),
|
||||||
.save, .restore, .Cacheable(CacheableF),
|
.save, .restore, .Cacheable(CacheableF),
|
||||||
.CacheMiss(ICacheMiss), .CacheAccess(ICacheAccess),
|
.CacheMiss(ICacheMiss), .CacheAccess(ICacheAccess),
|
||||||
|
.ByteWEN('0),
|
||||||
.FinalWriteData('0),
|
.FinalWriteData('0),
|
||||||
.RW(2'b10),
|
.RW(2'b10),
|
||||||
.Atomic('0), .FlushCache('0),
|
.Atomic('0), .FlushCache('0),
|
||||||
|
@ -105,7 +105,8 @@ module lsu (
|
|||||||
logic LSUBusWriteCrit;
|
logic LSUBusWriteCrit;
|
||||||
logic DataDAPageFaultM;
|
logic DataDAPageFaultM;
|
||||||
logic [`XLEN-1:0] LSUWriteDataM;
|
logic [`XLEN-1:0] LSUWriteDataM;
|
||||||
|
logic [(`XLEN-1)/8:0] FinalByteWENM;
|
||||||
|
|
||||||
// *** TO DO: Burst mode, byte write enables to DTIM, cache, exeternal memory, remove subword write from uncore,
|
// *** TO DO: Burst mode, byte write enables to DTIM, cache, exeternal memory, remove subword write from uncore,
|
||||||
|
|
||||||
flopenrc #(`XLEN) AddressMReg(clk, reset, FlushM, ~StallM, IEUAdrE, IEUAdrM);
|
flopenrc #(`XLEN) AddressMReg(clk, reset, FlushM, ~StallM, IEUAdrE, IEUAdrM);
|
||||||
@ -234,6 +235,7 @@ module lsu (
|
|||||||
.NUMWAYS(`DCACHE_NUMWAYS), .DCACHE(1)) dcache(
|
.NUMWAYS(`DCACHE_NUMWAYS), .DCACHE(1)) dcache(
|
||||||
.clk, .reset, .CPUBusy, .save, .restore, .RW(LSURWM), .Atomic(LSUAtomicM),
|
.clk, .reset, .CPUBusy, .save, .restore, .RW(LSURWM), .Atomic(LSUAtomicM),
|
||||||
.FlushCache(FlushDCacheM), .NextAdr(LSUAdrE), .PAdr(LSUPAdrM),
|
.FlushCache(FlushDCacheM), .NextAdr(LSUAdrE), .PAdr(LSUPAdrM),
|
||||||
|
.ByteWEN(FinalByteWENM),
|
||||||
.FinalWriteData(FinalWriteDataM), .Cacheable(CacheableM),
|
.FinalWriteData(FinalWriteDataM), .Cacheable(CacheableM),
|
||||||
.CacheStall(DCacheStallM), .CacheMiss(DCacheMiss), .CacheAccess(DCacheAccess),
|
.CacheStall(DCacheStallM), .CacheMiss(DCacheMiss), .CacheAccess(DCacheAccess),
|
||||||
.IgnoreRequestTLB, .IgnoreRequestTrapM, .CacheCommitted(DCacheCommittedM),
|
.IgnoreRequestTLB, .IgnoreRequestTrapM, .CacheCommitted(DCacheCommittedM),
|
||||||
@ -259,7 +261,7 @@ module lsu (
|
|||||||
//assign ReadDataWordMaskedM = ReadDataWordM; // *** this change only works because the i/o devices dont' write bytes other than the ones specific to their address.
|
//assign ReadDataWordMaskedM = ReadDataWordM; // *** this change only works because the i/o devices dont' write bytes other than the ones specific to their address.
|
||||||
subwordwrite subwordwrite(.HRDATA(ReadDataWordMaskedM), .HADDRD(LSUPAdrM[2:0]),
|
subwordwrite subwordwrite(.HRDATA(ReadDataWordMaskedM), .HADDRD(LSUPAdrM[2:0]),
|
||||||
.HSIZED({LSUFunct3M[2], 1'b0, LSUFunct3M[1:0]}),
|
.HSIZED({LSUFunct3M[2], 1'b0, LSUFunct3M[1:0]}),
|
||||||
.HWDATAIN(FinalAMOWriteDataM), .HWDATA(FinalWriteDataM));
|
.HWDATAIN(FinalAMOWriteDataM), .HWDATA(FinalWriteDataM), .ByteWEN(FinalByteWENM));
|
||||||
end else
|
end else
|
||||||
assign FinalWriteDataM = FinalAMOWriteDataM;
|
assign FinalWriteDataM = FinalAMOWriteDataM;
|
||||||
|
|
||||||
|
@ -35,14 +35,17 @@ module subwordwrite (
|
|||||||
input logic [2:0] HADDRD,
|
input logic [2:0] HADDRD,
|
||||||
input logic [3:0] HSIZED,
|
input logic [3:0] HSIZED,
|
||||||
input logic [`XLEN-1:0] HWDATAIN,
|
input logic [`XLEN-1:0] HWDATAIN,
|
||||||
output logic [`XLEN-1:0] HWDATA
|
output logic [`XLEN-1:0] HWDATA,
|
||||||
|
output logic [`XLEN/8-1:0] ByteWEN
|
||||||
);
|
);
|
||||||
|
|
||||||
logic [`XLEN-1:0] WriteDataSubwordDuplicated;
|
logic [`XLEN-1:0] WriteDataSubwordDuplicated;
|
||||||
|
|
||||||
|
|
||||||
if (`XLEN == 64) begin:sww
|
if (`XLEN == 64) begin:sww
|
||||||
logic [7:0] ByteMaskM;
|
logic [7:0] ByteMaskM;
|
||||||
// Compute write mask
|
// Compute write mask
|
||||||
|
assign ByteWEN = ByteMaskM;
|
||||||
always_comb
|
always_comb
|
||||||
case(HSIZED[1:0])
|
case(HSIZED[1:0])
|
||||||
2'b00: begin ByteMaskM = 8'b00000000; ByteMaskM[HADDRD[2:0]] = 1; end // sb
|
2'b00: begin ByteMaskM = 8'b00000000; ByteMaskM[HADDRD[2:0]] = 1; end // sb
|
||||||
@ -81,6 +84,7 @@ module subwordwrite (
|
|||||||
end else begin:sww // 32-bit
|
end else begin:sww // 32-bit
|
||||||
logic [3:0] ByteMaskM;
|
logic [3:0] ByteMaskM;
|
||||||
// Compute write mask
|
// Compute write mask
|
||||||
|
assign ByteWEN = ByteMaskM;
|
||||||
always_comb
|
always_comb
|
||||||
case(HSIZED[1:0])
|
case(HSIZED[1:0])
|
||||||
2'b00: begin ByteMaskM = 4'b0000; ByteMaskM[HADDRD[1:0]] = 1; end // sb
|
2'b00: begin ByteMaskM = 4'b0000; ByteMaskM[HADDRD[1:0]] = 1; end // sb
|
||||||
|
@ -95,7 +95,7 @@ module uncore (
|
|||||||
subwordwrite sww(
|
subwordwrite sww(
|
||||||
.HRDATA,
|
.HRDATA,
|
||||||
.HADDRD, .HSIZED,
|
.HADDRD, .HSIZED,
|
||||||
.HWDATAIN, .HWDATA);
|
.HWDATAIN, .HWDATA, .ByteWEN());
|
||||||
else assign HWDATA = HWDATAIN;
|
else assign HWDATA = HWDATAIN;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user