riscv: Reduce jit codesize a bit.

This commit is contained in:
Unknown W. Brackets committed 2023-07-23 18:01:00 -07:00
1 parent d31eded9ba
commit 76e3246065
4 files changed
+22 -29

No files matched your search

+9 -6
View File
@@ -1180,13 +1180,16 @@ bool RiscVEmitter::CJInRange(const void *src, const void *dst) const {
return BJInRange(src, dst, 12);
}
void RiscVEmitter::QuickCallFunction(RiscVReg scratchreg, const u8 *func) {
if (!JInRange(GetCodePointer(), func)) {
// TODO: Might be able to optimize a tiny bit by taking advantage of simm12.
LI(scratchreg, (uintptr_t)func);
JALR(R_RA, scratchreg, 0);
void RiscVEmitter::QuickJAL(RiscVReg scratchreg, RiscVReg rd, const u8 *dst) {
if (!JInRange(GetCodePointer(), dst)) {
static_assert(sizeof(intptr_t) <= sizeof(int64_t));
int64_t pcdelta = (int64_t)dst - (int64_t)GetCodePointer();
int32_t lower = (int32_t)SignReduce64(pcdelta, 12);
uintptr_t upper = ((pcdelta - lower) >> 12) << 12;
LI(scratchreg, (uintptr_t)GetCodePointer() + upper);
JALR(rd, scratchreg, lower);
} else {
JAL(R_RA, func);
JAL(rd, dst);
}
}
+7 -1
View File
@@ -213,7 +213,13 @@ public:
bool BInRange(const void *func) const;
bool JInRange(const void *func) const;
void QuickCallFunction(RiscVReg scratchreg, const u8 *func);
void QuickJAL(RiscVReg scratchreg, RiscVReg rd, const u8 *dst);
void QuickJ(RiscVReg scratchreg, const u8 *dst) {
QuickJAL(scratchreg, R_ZERO, dst);
}
void QuickCallFunction(RiscVReg scratchreg, const u8 *func) {
QuickJAL(scratchreg, R_RA, func);
}
template <typename T>
void QuickCallFunction(RiscVReg scratchreg, T *func) {
static_assert(std::is_function<T>::value, "QuickCallFunction without function");
+3 -18
View File
@@ -42,34 +42,19 @@ void RiscVJit::CompIR_Exit(IRInst inst) {
case IROp::ExitToConst:
FlushAll();
LI(SCRATCH1, inst.constant);
if (JInRange(dispatcherPCInSCRATCH1_)) {
J(dispatcherPCInSCRATCH1_);
} else {
LI(SCRATCH2, dispatcherPCInSCRATCH1_);
JALR(R_ZERO, SCRATCH2, 0);
}
QuickJ(SCRATCH2, dispatcherPCInSCRATCH1_);
break;
case IROp::ExitToReg:
exitReg = gpr.MapReg(inst.src1);
FlushAll();
MV(SCRATCH1, exitReg);
if (JInRange(dispatcherPCInSCRATCH1_)) {
J(dispatcherPCInSCRATCH1_);
} else {
LI(SCRATCH2, dispatcherPCInSCRATCH1_);
JALR(R_ZERO, SCRATCH2, 0);
}
QuickJ(SCRATCH2, dispatcherPCInSCRATCH1_);
break;
case IROp::ExitToPC:
FlushAll();
if (JInRange(dispatcher_)) {
J(dispatcher_);
} else {
LI(SCRATCH2, dispatcher_);
JALR(R_ZERO, SCRATCH2, 0);
}
QuickJ(SCRATCH2, dispatcher_);
break;
default:
+3 -4
View File
@@ -35,6 +35,7 @@ RiscVJit::RiscVJit(MIPSState *mipsState) : IRJit(mipsState), gpr(mipsState, &jo)
}
AllocCodeSpace(1024 * 1024 * 16);
SetAutoCompress(true);
// TODO: Consider replacing block num method form IRJit - this is 2MB.
blockStartAddrs_ = new const u8 *[MAX_ALLOWED_JIT_BLOCKS];
@@ -91,8 +92,7 @@ bool RiscVJit::CompileBlock(u32 em_address, std::vector<IRInst> &instructions, u
// Note: a properly constructed block should never get here.
// TODO: Need to do more than just this? Call a func to set an exception?
LI(SCRATCH2, crashHandler_);
JALR(R_ZERO, SCRATCH2, 0);
QuickJ(SCRATCH2, crashHandler_);
FlushIcache();
@@ -401,8 +401,7 @@ void RiscVJit::CompIR_Generic(IRInst inst) {
BNE(X10, R_ZERO, dispatcherPCInSCRATCH1_);
} else {
FixupBranch skip = BEQ(X10, R_ZERO);
LI(SCRATCH2, dispatcherPCInSCRATCH1_);
JALR(R_ZERO, SCRATCH2, 0);
QuickJ(SCRATCH2, dispatcherPCInSCRATCH1_);
SetJumpTarget(skip);
}
}