From 59836cc9e529a04f2f5cb9c799ad003a401cfb83 Mon Sep 17 00:00:00 2001 From: Jonathan Woodruff Date: Thu, 25 Nov 2021 17:39:46 +0000 Subject: [PATCH] Hopefully optimise this function to have just one call to modifyOffset. --- src_Core/RISCY_OOO/procs/lib/Exec.bsv | 33 +++++++++++++++++++-------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src_Core/RISCY_OOO/procs/lib/Exec.bsv b/src_Core/RISCY_OOO/procs/lib/Exec.bsv index d5e64cb..de79c83 100755 --- a/src_Core/RISCY_OOO/procs/lib/Exec.bsv +++ b/src_Core/RISCY_OOO/procs/lib/Exec.bsv @@ -355,18 +355,31 @@ endfunction (* noinline *) function CapPipe brAddrCalc(CapPipe pc, CapPipe val, IType iType, Data imm, Bool taken, Bit #(32) orig_inst, Bool cap); CapPipe pcPlusN = addPc(pc, ((orig_inst [1:0] == 2'b11) ? 4 : 2)); - if (!cap) val = setOffset(pc, getAddr(val)).value; - CapPipe branchTarget = incOffset(pc, imm).value; - CapPipe jumpTarget = incOffset(val, imm).value; - jumpTarget = setAddrUnsafe(jumpTarget, {truncateLSB(getAddr(jumpTarget)), 1'b0}); - jumpTarget = setKind(jumpTarget, UNSEALED); // It is checked elsewhere that we have an unsealed cap already, or sentry if permitted - CapPipe targetAddr = (case (iType) - J, CJAL : branchTarget; - Jr,CCall,CJALR : jumpTarget; - Br : (taken? branchTarget : pcPlusN); + + //if (!cap) val = setOffset(pc, getAddr(val)).value; + //CapPipe branchTarget = incOffset(pc, imm).value; + //CapPipe jumpTarget = incOffset(val, imm).value; + + CapPipe nextPc = pc; + Data offset = imm; + Bool doInc = True; + if (iType==Jr || iType==CCall || iType ==CJALR) begin + if (cap) nextPc = val; + else begin + offset = getAddr(val) + imm; + doInc = False; + end + end + CapPipe targetAddr = modifyOffset(nextPc, offset, doInc).value; + // jumpTarget.address[0] = 1'b0; + targetAddr = setAddrUnsafe(targetAddr, {truncateLSB(getAddr(targetAddr)), 1'b0}); + targetAddr = setKind(targetAddr, UNSEALED); // It is checked elsewhere that we have an unsealed cap already, or sentry if permitted + + return (case (iType) + J, CJAL, Jr, CCall, CJALR: targetAddr; + Br : (taken ? targetAddr : pcPlusN); default : pcPlusN; endcase); - return targetAddr; endfunction /* (* noinline *)