From 33f5de0f5cc9564f07bf20c7a032c496691b2011 Mon Sep 17 00:00:00 2001 From: koooo142857 Date: Wed, 27 Oct 2021 12:43:55 -0700 Subject: [PATCH 1/9] aligned all files in ifu folder --- wally-pipelined/src/ifu/BTBPredictor.sv | 60 ++--- wally-pipelined/src/ifu/CodeAligner.py | 98 ++++++++ wally-pipelined/src/ifu/RAsPredictor.sv | 28 +-- wally-pipelined/src/ifu/SRAM2P1R1W.sv | 56 ++--- wally-pipelined/src/ifu/bpred.sv | 216 +++++++++--------- wally-pipelined/src/ifu/decompress.sv | 18 +- .../src/ifu/globalHistoryPredictor.sv | 70 +++--- wally-pipelined/src/ifu/gsharePredictor.sv | 70 +++--- wally-pipelined/src/ifu/ifu.sv | 214 ++++++++--------- .../src/ifu/localHistoryPredictor.sv | 72 +++--- wally-pipelined/src/ifu/satCounter2.sv | 20 +- wally-pipelined/src/ifu/twoBitPredictor.sv | 48 ++-- 12 files changed, 534 insertions(+), 436 deletions(-) create mode 100644 wally-pipelined/src/ifu/CodeAligner.py diff --git a/wally-pipelined/src/ifu/BTBPredictor.sv b/wally-pipelined/src/ifu/BTBPredictor.sv index 07a39c16..ad94b6ff 100644 --- a/wally-pipelined/src/ifu/BTBPredictor.sv +++ b/wally-pipelined/src/ifu/BTBPredictor.sv @@ -31,25 +31,25 @@ module BTBPredictor #(parameter int Depth = 10 ) - (input logic clk, - input logic reset, - input logic StallF, StallE, + (input logic clk, + input logic reset, + input logic StallF, StallE, input logic [`XLEN-1:0] LookUpPC, output logic [`XLEN-1:0] TargetPC, - output logic [4:0] InstrClass, - output logic Valid, + output logic [4:0] InstrClass, + output logic Valid, // update - input logic UpdateEN, + input logic UpdateEN, input logic [`XLEN-1:0] UpdatePC, input logic [`XLEN-1:0] UpdateTarget, - input logic [4:0] UpdateInstrClass, - input logic UpdateInvalid + input logic [4:0] UpdateInstrClass, + input logic UpdateInvalid ); localparam TotalDepth = 2 ** Depth; logic [TotalDepth-1:0] ValidBits; - logic [Depth-1:0] LookUpPCIndex, UpdatePCIndex, LookUpPCIndexQ, UpdatePCIndexQ; - logic UpdateENQ; + logic [Depth-1:0] LookUpPCIndex, UpdatePCIndex, LookUpPCIndexQ, UpdatePCIndexQ; + logic UpdateENQ; // hashing function for indexing the PC @@ -61,10 +61,10 @@ module BTBPredictor flopenr #(Depth) UpdatePCIndexReg(.clk(clk), - .reset(reset), - .en(~StallE), - .d(UpdatePCIndex), - .q(UpdatePCIndexQ)); + .reset(reset), + .en(~StallE), + .d(UpdatePCIndex), + .q(UpdatePCIndexQ)); // The valid bit must be resetable. always_ff @ (posedge clk) begin @@ -79,17 +79,17 @@ module BTBPredictor flopenr #(1) UpdateENReg(.clk(clk), - .reset(reset), - .en(~StallF), - .d(UpdateEN), - .q(UpdateENQ)); + .reset(reset), + .en(~StallF), + .d(UpdateEN), + .q(UpdateENQ)); flopenr #(Depth) LookupPCIndexReg(.clk(clk), - .reset(reset), - .en(~StallF), - .d(LookUpPCIndex), - .q(LookUpPCIndexQ)); + .reset(reset), + .en(~StallF), + .d(LookUpPCIndex), + .q(LookUpPCIndexQ)); @@ -98,14 +98,14 @@ module BTBPredictor // *** need to add forwarding. SRAM2P1R1W #(Depth, `XLEN+5) memory(.clk(clk), - .reset(reset), - .RA1(LookUpPCIndex), - .RD1({{InstrClass, TargetPC}}), - .REN1(~StallF), - .WA1(UpdatePCIndex), - .WD1({UpdateInstrClass, UpdateTarget}), - .WEN1(UpdateEN), - .BitWEN1({5'h1F, {`XLEN{1'b1}}})); // *** definitely not right. + .reset(reset), + .RA1(LookUpPCIndex), + .RD1({{InstrClass, TargetPC}}), + .REN1(~StallF), + .WA1(UpdatePCIndex), + .WD1({UpdateInstrClass, UpdateTarget}), + .WEN1(UpdateEN), + .BitWEN1({5'h1F, {`XLEN{1'b1}}})); // *** definitely not right. endmodule diff --git a/wally-pipelined/src/ifu/CodeAligner.py b/wally-pipelined/src/ifu/CodeAligner.py new file mode 100644 index 00000000..59f9de4e --- /dev/null +++ b/wally-pipelined/src/ifu/CodeAligner.py @@ -0,0 +1,98 @@ +import os + +# Kevin Wan kewan@hmc.edu 10/27/2021 +def read_input(filename): #1 + """Takes in a string filename and outputs the parsed verilog code by line into a list + such that each element of the list is one line of verilog code as a string.""" + lineOfCode = [] + input_file = open(filename, 'r') + for line in input_file: + lineOfCode.append(line) + return lineOfCode +################################################################################### +def ID_start(GiantString):#2 + """takes in the list of sv file lines, outputs the location that variable names should start""" + VarLoc = 0 + VarLineNum = None + for lines in GiantString: + if ' logic ' in lines and (lines.find("//") == -1 or lines.find("//") > lines.find(' logic ')): # // logic does not proceed. logic proceeds. logic // proceeds. + if "[" in lines and "]" in lines:# need to account for these space + NowLoc = lines.find(']') + 3# column number in sv code when 1st char of the var name should appear. + if NowLoc>VarLoc: + VarLoc = NowLoc + VarLineNum = GiantString.index(lines) # Update this number if new record is made. + else: + NowLoc = lines.find('logic') + 7 # same as before. + if NowLoc>VarLoc: + VarLoc = NowLoc + VarLineNum = GiantString.index(lines) + #print("Furthest variable appears on line", VarLineNum + 1,VarLoc) # Disable this line after debugging. + return VarLoc +################################################################################## +def modified_logNew(GS,SOV): #3 + Ind = SOV - 1 # SOV is for human readability, Ind is the character's index in computer, since computers count from 0's we need to correct it. + Out = [] + for l in GS: + lines = l.replace('\t',' ') + + if ' logic ' in lines and (lines.find("//") == -1 or lines.find("//") > lines.find(' logic ')): # // logic does not proceed. logic proceeds. logic // proceeds. + if "[" in lines and "]" in lines: # the line is an extended declaration. + EditLoc = lines.find("]") # Re-finds the string index number of ]. + VarLoc = FindCharRel(lines[EditLoc+1::]) + EditLoc + 1 # Checks where variable declaration currently is at. + #print(VarLoc,lines[VarLoc])# VERIFIED + NewLine = Mod_Space_at(lines,VarLoc,VarLoc-Ind) + Out.append(NewLine)# Verified0957 10272021 + else: + EditLoc1 = lines.find('c') # Hopefully sees the c in 'logic' + + VarLoc1 = FindCharRel(lines[EditLoc1+1::]) + EditLoc1 + 1 + NewLine1 = Mod_Space_at(lines,VarLoc1,VarLoc1-Ind) + + Out.append(NewLine1)# Verified 1005 10272021 + else: + Out.append(lines) + return Out +################################################################################ +def write_to_output(filename,GiantString,OW=True,Lines_editted=None): #4 + """Filename is preferrably passed from the early function calls""" + """GiantString has all the corrected features in the code, each line is a good verilog code line""" + newname = filename + if not OW or OW =='f': #which means no overwrite (create a new file) + Decomposed=filename.split('.') + newname = Decomposed[0] + "_AL." + Decomposed[1] # AL for aligned. + + OutFile = open(newname,'w') # This step should create a new file. + OutFile.writelines(GiantString) + OutFile.close() + print("Success! " + newname + " Now contains an aligned file!") + return newname +################################################################################# + +def FindCharRel(Ln): + #returns the computer location of a character's first occurence + for num in range(len(Ln)): + if Ln[num] != " ": + return num + + +def Mod_Space_at(Ln,loc,diff): + #loc is the varLoc from mln, diff is varLoc - Ind + if diff > 0: # to delete + NewString = Ln[:(loc-diff)] + Ln[loc:] + + if diff < 0: # to add + NewString = Ln[:loc] + (-diff)*" " + Ln[loc:] + if diff == 0: + NewString = Ln + + return NewString + +def main_filehandler(overwrite=False): + for filename in os.listdir(): + if ".py" not in filename: + GiantString = read_input(filename) + SOV = ID_start(GiantString) + ModifiedGS = modified_logNew(GiantString,SOV) + Newname = write_to_output(filename,ModifiedGS,overwrite) + +main_filehandler(True) \ No newline at end of file diff --git a/wally-pipelined/src/ifu/RAsPredictor.sv b/wally-pipelined/src/ifu/RAsPredictor.sv index 44929e3c..31f4568d 100644 --- a/wally-pipelined/src/ifu/RAsPredictor.sv +++ b/wally-pipelined/src/ifu/RAsPredictor.sv @@ -30,21 +30,21 @@ module RASPredictor #(parameter int StackSize = 16 ) - (input logic clk, - input logic reset, - input logic pop, + (input logic clk, + input logic reset, + input logic pop, output logic [`XLEN-1:0] popPC, - input logic push, - input logic incr, + input logic push, + input logic incr, input logic [`XLEN-1:0] pushPC ); - logic CounterEn; + logic CounterEn; localparam Depth = $clog2(StackSize); - logic [Depth-1:0] PtrD, PtrQ, PtrP1, PtrM1; - logic [StackSize-1:0] [`XLEN-1:0] memory; - integer index; + logic [Depth-1:0] PtrD, PtrQ, PtrP1, PtrM1; + logic [StackSize-1:0] [`XLEN-1:0] memory; + integer index; assign CounterEn = pop | push | incr; @@ -56,16 +56,16 @@ module RASPredictor // *** what happens if jal is executing and there is a return being flushed in Decode? flopenr #(Depth) PTR(.clk(clk), - .reset(reset), - .en(CounterEn), - .d(PtrD), - .q(PtrQ)); + .reset(reset), + .en(CounterEn), + .d(PtrD), + .q(PtrQ)); // RAS must be reset. always_ff @ (posedge clk) begin if(reset) begin for(index=0; index Date: Wed, 27 Oct 2021 13:45:37 -0700 Subject: [PATCH 2/9] Have replaced .* with signal names in ifu --- .../src/wally/wallypipelinedhart.sv | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/wally-pipelined/src/wally/wallypipelinedhart.sv b/wally-pipelined/src/wally/wallypipelinedhart.sv index 980166d9..ede4460e 100644 --- a/wally-pipelined/src/wally/wallypipelinedhart.sv +++ b/wally-pipelined/src/wally/wallypipelinedhart.sv @@ -154,9 +154,30 @@ module wallypipelinedhart ( logic BreakpointFaultM, EcallFaultM; - ifu ifu(.InstrInF(InstrRData), - .WalkerInstrPageFaultF(WalkerInstrPageFaultF), - .*); // instruction fetch unit: PC, branch prediction, instruction cache + ifu ifu( + .clk, .reset, + .StallF, .StallD, .StallE, .StallM, .StallW, + .FlushF, .FlushD, .FlushE, .FlushM, .FlushW, + .InstrInF(InstrRData), .InstrAckF, .PCF, .InstrPAdrF, .InstrReadF, .ICacheStallF, + .PCLinkE, .PCSrcE, .PCTargetE, .PCE, + .BPPredWrongE, + .RetM, .TrapM, + .PrivilegedNextPCM, .InvalidateICacheM, + .InstrD, .InstrM, + .PCM, .InstrClassM, + .BPPredDirWrongM,.BTBPredPCWrongM,.RASPredPCWrongM, .BPPredClassNonCFIWrongM, + .IllegalBaseInstrFaultD, .ITLBInstrPageFaultF, .IllegalIEUInstrFaultD, + .InstrMisalignedFaultM, .InstrMisalignedAdrM, + .PrivilegeModeW, .PTE, .PageType, .SATP_REGW, + .STATUS_MXR, .STATUS_SUM, .STATUS_MPRV, .STATUS_MPP, + .ITLBWriteF, .ITLBFlushF, + .WalkerInstrPageFaultF, + .ITLBMissF, + .PMPCFG_ARRAY_REGW, .PMPADDR_ARRAY_REGW, + .InstrAccessFaultF + + ); // instruction fetch unit: PC, branch prediction, instruction cache + ieu ieu(.*); // integer execution unit: integer register file, datapath and controller From ab711c498d0bf768e8ddc0d9acaf6d6c6f6c5f27 Mon Sep 17 00:00:00 2001 From: bbracker Date: Wed, 27 Oct 2021 14:10:29 -0700 Subject: [PATCH 3/9] checkpoint generator off-by-one error fix --- .../linux-testgen/testvector-generation/genCheckpoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wally-pipelined/linux-testgen/testvector-generation/genCheckpoint.sh b/wally-pipelined/linux-testgen/testvector-generation/genCheckpoint.sh index f3542034..fc22dd28 100755 --- a/wally-pipelined/linux-testgen/testvector-generation/genCheckpoint.sh +++ b/wally-pipelined/linux-testgen/testvector-generation/genCheckpoint.sh @@ -3,7 +3,7 @@ source genSettings.sh tcpPort=1236 -instrs=10000000 +instrs=480000000 checkOutDir="$outDir/checkpoint$instrs" checkIntermedDir="$checkOutDir/intermediate-outputs" @@ -32,7 +32,7 @@ then # Post-Process GDB outputs ./parseState.py "$checkOutDir" ./fix_mem.py "$checkIntermedDir/ramGDB.txt" "$checkOutDir/ram.txt" - tail -n+$instrs "$outDir/$traceFile" > "$checkOutDir/$traceFile" + tail -n+$($instrs+1) "$outDir/$traceFile" > "$checkOutDir/$traceFile" else echo "You can change the number of instructions by editing the \"instrs\" variable in this script." echo "Have a nice day!" From 35fcadbe7fd487e4bdf83d4fea34d6ad2985f0ed Mon Sep 17 00:00:00 2001 From: Ross Thompson Date: Thu, 28 Oct 2021 11:07:18 -0500 Subject: [PATCH 4/9] Applied batch from fpga branch which fixes the dcache fence bug. The should cause the dcache to flush all dirty cache lines to main memory. The bug caused the dirty reset to clear each way for a particular line. --- wally-pipelined/src/cache/dcache.sv | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wally-pipelined/src/cache/dcache.sv b/wally-pipelined/src/cache/dcache.sv index bf943169..b51e77e7 100644 --- a/wally-pipelined/src/cache/dcache.sv +++ b/wally-pipelined/src/cache/dcache.sv @@ -142,6 +142,8 @@ module dcache logic LRUWriteEn; + logic [NUMWAYS-1:0] VDWriteEnableWay; + // Read Path CPU (IEU) side mux4 #(INDEXLEN) @@ -167,7 +169,7 @@ module dcache .WAdr, .PAdr(MemPAdrM), .WriteEnable(SRAMWayWriteEnable), - .VDWriteEnable, + .VDWriteEnable(VDWriteEnableWay), .WriteWordEnable(SRAMWordEnable), .TagWriteEnable(SRAMBlockWayWriteEnableM), .WriteData(SRAMWriteData), @@ -329,6 +331,8 @@ module dcache .d(NextFlushWay), .q(FlushWay)); + assign VDWriteEnableWay = FlushWay & {NUMWAYS{VDWriteEnable}}; + assign NextFlushWay = {FlushWay[NUMWAYS-2:0], FlushWay[NUMWAYS-1]}; assign FlushAdrFlag = FlushAdr == FlushAdrThreshold[INDEXLEN-1:0] & FlushWay[NUMWAYS-1]; From 41dbb59e24285b0dbbdcea21a0ea9c9dd73a86cf Mon Sep 17 00:00:00 2001 From: Ross Thompson Date: Fri, 29 Oct 2021 11:03:37 -0500 Subject: [PATCH 7/9] Possible fix for the incorrect behavior of the pseudo LRU replacement policy for 4 ways set associative caches. --- .../src/cache/cachereplacementpolicy.sv | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/wally-pipelined/src/cache/cachereplacementpolicy.sv b/wally-pipelined/src/cache/cachereplacementpolicy.sv index e02c3675..47e521a8 100644 --- a/wally-pipelined/src/cache/cachereplacementpolicy.sv +++ b/wally-pipelined/src/cache/cachereplacementpolicy.sv @@ -82,7 +82,31 @@ module cachereplacementpolicy assign VictimWay[1] = ~BlockReplacementBits[0]; assign VictimWay[0] = BlockReplacementBits[0]; - end else if (NUMWAYS == 4) begin : FourWay + end else if (NUMWAYS == 4) begin : FourWay + + + // VictimWay is a function only of the current value of the LRU. + // binary encoding + //assign VictimWay[0] = BlockReplacementBits[2] ? BlockReplacementBits[1] : BlockReplacementBits[0]; + //assign VictimWay[1] = BlockReplacementBits[2]; + + // 1 hot encoding + assign VictimWay[0] = ~BlockReplacementBits[2] & ~BlockReplacementBits[0]; + assign VictimWay[1] = ~BlockReplacementBits[2] & BlockReplacementBits[0]; + assign VictimWay[2] = BlockReplacementBits[2] & ~BlockReplacementBits[1]; + assign VictimWay[3] = BlockReplacementBits[2] & BlockReplacementBits[1]; + + // New LRU bits which are updated is function only of the WayHit. + // However the not updated bits come from the old LRU. + assign LRUEn[2] = |WayHit; + assign LRUEn[1] = WayHit[3] | WayHit[2]; + assign LRUEn[0] = WayHit[1] | WayHit[0]; + + assign LRUMask[2] = WayHit[1] | WayHit[0]; + assign LRUMask[1] = WayHit[2]; + assign LRUMask[0] = WayHit[0]; + +/* -----\/----- EXCLUDED -----\/----- // selects assign LRUEn[2] = 1'b1; @@ -93,16 +117,19 @@ module cachereplacementpolicy assign LRUMask[0] = WayHit[1]; assign LRUMask[1] = WayHit[3]; assign LRUMask[2] = WayHit[3] | WayHit[2]; + -----/\----- EXCLUDED -----/\----- */ for(index = 0; index < NUMWAYS-1; index++) assign NewReplacement[index] = LRUEn[index] ? LRUMask[index] : BlockReplacementBits[index]; +/* -----\/----- EXCLUDED -----\/----- assign EncVicWay[1] = BlockReplacementBits[2]; assign EncVicWay[0] = BlockReplacementBits[2] ? BlockReplacementBits[0] : BlockReplacementBits[1]; onehotdecoder #(2) waydec(.bin(EncVicWay), .decoded({VictimWay[0], VictimWay[1], VictimWay[2], VictimWay[3]})); + -----/\----- EXCLUDED -----/\----- */ end else if (NUMWAYS == 8) begin : EightWay From 9c875d38a99aa4f22da1cb3dfa3e993e44b73401 Mon Sep 17 00:00:00 2001 From: Ross Thompson Date: Fri, 29 Oct 2021 12:46:02 -0500 Subject: [PATCH 9/9] Fixed the 4 way set associative pseudo LRU replacement policy. --- wally-pipelined/src/cache/cachereplacementpolicy.sv | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/wally-pipelined/src/cache/cachereplacementpolicy.sv b/wally-pipelined/src/cache/cachereplacementpolicy.sv index 47e521a8..a0b77474 100644 --- a/wally-pipelined/src/cache/cachereplacementpolicy.sv +++ b/wally-pipelined/src/cache/cachereplacementpolicy.sv @@ -59,7 +59,7 @@ module cachereplacementpolicy ReplacementBits[index] <= '0; end else begin RAdrD <= RAdr; - MemPAdrMD <= MemPAdrMD; + MemPAdrMD <= MemPAdrM; LRUWriteEnD <= LRUWriteEn; NewReplacementD <= NewReplacement; if (LRUWriteEnD) begin @@ -91,6 +91,14 @@ module cachereplacementpolicy //assign VictimWay[1] = BlockReplacementBits[2]; // 1 hot encoding + //| WayHit | LRU 2 | LRU 1 | LRU 0 | + //|--------+-------+-------+-------| + //| 0000 | - | - | - | + //| 0001 | 1 | - | 1 | + //| 0010 | 1 | - | 0 | + //| 0100 | 0 | 1 | - | + //| 1000 | 0 | 0 | - | + assign VictimWay[0] = ~BlockReplacementBits[2] & ~BlockReplacementBits[0]; assign VictimWay[1] = ~BlockReplacementBits[2] & BlockReplacementBits[0]; assign VictimWay[2] = BlockReplacementBits[2] & ~BlockReplacementBits[1];