Replaced dcache generate ORing with or_rows.

This commit is contained in:
Ross Thompson 2021-08-25 13:46:36 -05:00
parent 83cc0266b2
commit b5eba44417
2 changed files with 16 additions and 23 deletions

View File

@ -30,13 +30,12 @@ module cacheway #(parameter NUMLINES=512, parameter BLOCKLEN = 256, TAGLEN = 26,
(input logic clk, (input logic clk,
input logic reset, input logic reset,
input logic [$clog2(NUMLINES)-1:0] Adr, input logic [$clog2(NUMLINES)-1:0] RAdr,
input logic [`PA_BITS-1:OFFSETLEN+INDEXLEN] MemPAdrM, input logic [`PA_BITS-1:OFFSETLEN+INDEXLEN] MemPAdrM,
input logic WriteEnable, input logic WriteEnable,
input logic [BLOCKLEN/`XLEN-1:0] WriteWordEnable, input logic [BLOCKLEN/`XLEN-1:0] WriteWordEnable,
input logic TagWriteEnable, input logic TagWriteEnable,
input logic [BLOCKLEN-1:0] WriteData, input logic [BLOCKLEN-1:0] WriteData,
input logic [TAGLEN-1:0] WriteTag,
input logic SetValid, input logic SetValid,
input logic ClearValid, input logic ClearValid,
input logic SetDirty, input logic SetDirty,
@ -63,7 +62,7 @@ module cacheway #(parameter NUMLINES=512, parameter BLOCKLEN = 256, TAGLEN = 26,
sram1rw #(.DEPTH(`XLEN), sram1rw #(.DEPTH(`XLEN),
.WIDTH(NUMLINES)) .WIDTH(NUMLINES))
CacheDataMem(.clk(clk), CacheDataMem(.clk(clk),
.Addr(Adr), .Addr(RAdr),
.ReadData(ReadDataBlockWayM[(words+1)*`XLEN-1:words*`XLEN]), .ReadData(ReadDataBlockWayM[(words+1)*`XLEN-1:words*`XLEN]),
.WriteData(WriteData[(words+1)*`XLEN-1:words*`XLEN]), .WriteData(WriteData[(words+1)*`XLEN-1:words*`XLEN]),
.WriteEnable(WriteEnable & WriteWordEnable[words])); .WriteEnable(WriteEnable & WriteWordEnable[words]));
@ -73,9 +72,9 @@ module cacheway #(parameter NUMLINES=512, parameter BLOCKLEN = 256, TAGLEN = 26,
sram1rw #(.DEPTH(TAGLEN), sram1rw #(.DEPTH(TAGLEN),
.WIDTH(NUMLINES)) .WIDTH(NUMLINES))
CacheTagMem(.clk(clk), CacheTagMem(.clk(clk),
.Addr(Adr), .Addr(RAdr),
.ReadData(ReadTag), .ReadData(ReadTag),
.WriteData(WriteTag), .WriteData(MemPAdrM),
.WriteEnable(TagWriteEnable)); .WriteEnable(TagWriteEnable));
assign WayHit = Valid & (ReadTag == MemPAdrM[`PA_BITS-1:OFFSETLEN+INDEXLEN]); assign WayHit = Valid & (ReadTag == MemPAdrM[`PA_BITS-1:OFFSETLEN+INDEXLEN]);
@ -88,17 +87,17 @@ module cacheway #(parameter NUMLINES=512, parameter BLOCKLEN = 256, TAGLEN = 26,
always_ff @(posedge clk, posedge reset) begin always_ff @(posedge clk, posedge reset) begin
if (reset) if (reset)
ValidBits <= {NUMLINES{1'b0}}; ValidBits <= {NUMLINES{1'b0}};
else if (SetValid & WriteEnable) ValidBits[Adr] <= 1'b1; else if (SetValid & WriteEnable) ValidBits[RAdr] <= 1'b1;
else if (ClearValid & WriteEnable) ValidBits[Adr] <= 1'b0; else if (ClearValid & WriteEnable) ValidBits[RAdr] <= 1'b0;
Valid <= ValidBits[Adr]; Valid <= ValidBits[RAdr];
end end
always_ff @(posedge clk, posedge reset) begin always_ff @(posedge clk, posedge reset) begin
if (reset) if (reset)
DirtyBits <= {NUMLINES{1'b0}}; DirtyBits <= {NUMLINES{1'b0}};
else if (SetDirty & WriteEnable) DirtyBits[Adr] <= 1'b1; else if (SetDirty & WriteEnable) DirtyBits[RAdr] <= 1'b1;
else if (ClearDirty & WriteEnable) DirtyBits[Adr] <= 1'b0; else if (ClearDirty & WriteEnable) DirtyBits[RAdr] <= 1'b0;
Dirty <= DirtyBits[Adr]; Dirty <= DirtyBits[RAdr];
end end

View File

@ -205,13 +205,12 @@ module dcache
cacheway #(.NUMLINES(NUMLINES), .BLOCKLEN(BLOCKLEN), .TAGLEN(TAGLEN), .OFFSETLEN(OFFSETLEN), .INDEXLEN(INDEXLEN)) cacheway #(.NUMLINES(NUMLINES), .BLOCKLEN(BLOCKLEN), .TAGLEN(TAGLEN), .OFFSETLEN(OFFSETLEN), .INDEXLEN(INDEXLEN))
MemWay[NUMWAYS-1:0](.clk, MemWay[NUMWAYS-1:0](.clk,
.reset, .reset,
.Adr(SRAMAdr), .RAdr(SRAMAdr),
.MemPAdrM(MemPAdrM[`PA_BITS-1:OFFSETLEN+INDEXLEN]), .MemPAdrM(MemPAdrM[`PA_BITS-1:OFFSETLEN+INDEXLEN]),
.WriteEnable(SRAMWayWriteEnable), .WriteEnable(SRAMWayWriteEnable),
.WriteWordEnable(SRAMWordEnable), .WriteWordEnable(SRAMWordEnable),
.TagWriteEnable(SRAMBlockWayWriteEnableM), .TagWriteEnable(SRAMBlockWayWriteEnableM),
.WriteData(SRAMWriteData), .WriteData(SRAMWriteData),
.WriteTag(MemPAdrM[`PA_BITS-1:OFFSETLEN+INDEXLEN]),
.SetValid(SetValidM), .SetValid(SetValidM),
.ClearValid(ClearValidM), .ClearValid(ClearValidM),
.SetDirty(SetDirtyM), .SetDirty(SetDirtyM),
@ -264,22 +263,17 @@ module dcache
// ReadDataBlockWayMaskedM is a 2d array of cache block len by number of ways. // ReadDataBlockWayMaskedM is a 2d array of cache block len by number of ways.
// Need to OR together each way in a bitwise manner. // Need to OR together each way in a bitwise manner.
// Final part of the AO Mux. // Final part of the AO Mux.
genvar index; or_rows #(NUMWAYS, BLOCKLEN) ReadDataAOMux(.a(ReadDataBlockWayMaskedM), .y(ReadDataBlockM));
always_comb begin or_rows #(NUMWAYS, TAGLEN) VictimTagAOMux(.a(VictimTagWay), .y(VictimTag));
ReadDataBlockM = '0;
VictimReadDataBlockM = '0;
VictimTag = '0;
for(int index = 0; index < NUMWAYS; index++) begin
ReadDataBlockM = ReadDataBlockM | ReadDataBlockWayMaskedM[index];
VictimTag = VictimTag | VictimTagWay[index];
end
end
assign VictimDirty = | VictimDirtyWay; assign VictimDirty = | VictimDirtyWay;
// Convert the Read data bus ReadDataSelectWay into sets of XLEN so we can // Convert the Read data bus ReadDataSelectWay into sets of XLEN so we can
// easily build a variable input mux. // easily build a variable input mux.
// *** consider using a limited range shift to do this final muxing. // *** consider using a limited range shift to do this final muxing.
genvar index;
generate generate
for (index = 0; index < WORDSPERLINE; index++) begin for (index = 0; index < WORDSPERLINE; index++) begin
assign ReadDataBlockSetsM[index] = ReadDataBlockM[((index+1)*`XLEN)-1: (index*`XLEN)]; assign ReadDataBlockSetsM[index] = ReadDataBlockM[((index+1)*`XLEN)-1: (index*`XLEN)];