#pragma once
#pragma once
#include "Core/MIPS/MIPS.h"
#include "Core/MIPS/ARM/ArmRegCache.h"
#include "Core/MIPS/MIPSVFPUUtils.h"
#include "Common/ArmEmitter.h"
namespace ArmJitConstants {
enum {
NUM_TEMPS = 16,
TEMP0 = 32 + 128,
TOTAL_MAPPABLE_MIPSFPUREGS = 32 + 128 + NUM_TEMPS,
};
enum {
MAP_READ = 0,
MAP_MTX_TRANSPOSED = 16,
MAP_PREFER_LOW = 16,
MAP_PREFER_HIGH = 32,
MAP_FORCE_LOW = 64,
MAP_FORCE_HIGH = 128,
};
}
namespace MIPSAnalyst {
struct AnalysisResults;
};
struct FPURegARM {
int mipsReg;
bool isDirty;
};
struct FPURegQuad {
int mipsVec;
VectorSize sz;
u8 vregs[4];
bool isDirty;
bool spillLock;
bool isTemp;
};
struct FPURegMIPS {
ArmJitConstants::RegMIPSLoc loc;
u32 reg;
int lane;
bool spillLock;
bool tempLock;
};
namespace MIPSComp {
struct JitOptions;
struct JitState;
}
class ArmRegCacheFPU {
public:
ArmRegCacheFPU(MIPSState *mipsState, MIPSComp::JitState *js, MIPSComp::JitOptions *jo);
~ArmRegCacheFPU() {}
void Init(ArmGen::ARMXEmitter *emitter);
void Start(MIPSAnalyst::AnalysisResults &stats);
void SpillLock(MIPSReg reg, MIPSReg reg2 = -1, MIPSReg reg3 = -1, MIPSReg reg4 = -1);
void SpillLockV(MIPSReg r) { SpillLock(r + 32); }
void ReleaseSpillLocksAndDiscardTemps();
void ReleaseSpillLock(int mipsreg) {
mr[mipsreg].spillLock = false;
}
void ReleaseSpillLockV(int mipsreg) {
ReleaseSpillLock(mipsreg + 32);
}
void SetImm(MIPSReg reg, u32 immVal);
bool IsImm(MIPSReg reg) const;
u32 GetImm(MIPSReg reg) const;
ArmGen::ARMReg MapReg(MIPSReg reg, int mapFlags = 0);
void MapInIn(MIPSReg rd, MIPSReg rs);
void MapDirty(MIPSReg rd);
void MapDirtyIn(MIPSReg rd, MIPSReg rs, bool avoidLoad = true);
void MapDirtyInIn(MIPSReg rd, MIPSReg rs, MIPSReg rt, bool avoidLoad = true);
bool IsMapped(MIPSReg r);
void FlushArmReg(ArmGen::ARMReg r);
void FlushR(MIPSReg r);
void DiscardR(MIPSReg r);
ArmGen::ARMReg R(int preg);
void MapRegV(int vreg, int flags = 0);
void LoadToRegV(ArmGen::ARMReg armReg, int vreg);
void MapInInV(int rt, int rs);
void MapDirtyInV(int rd, int rs, bool avoidLoad = true);
void MapDirtyInInV(int rd, int rs, int rt, bool avoidLoad = true);
bool IsTempX(ArmGen::ARMReg r) const;
MIPSReg GetTempV() { return GetTempR() - 32; }
ArmGen::ARMReg V(int vreg) { return R(vreg + 32); }
int FlushGetSequential(int a);
void FlushAll();
void FlushV(MIPSReg r);
ArmGen::ARMReg QMapReg(int vreg, VectorSize sz, int flags);
void QMapMatrix(ArmGen::ARMReg *regs, int matrix, MatrixSize mz, int flags);
ArmGen::ARMReg QAllocTemp(VectorSize sz);
void QAllowSpill(int quad);
void QFlush(int quad);
void QLoad4x4(MIPSGPReg regPtr, int vquads[4]);
void MapRegsAndSpillLockV(int vec, VectorSize vsz, int flags);
void MapRegsAndSpillLockV(const u8 *v, VectorSize vsz, int flags);
void SpillLockV(const u8 *v, VectorSize vsz);
void SpillLockV(int vec, VectorSize vsz);
void SetEmitter(ArmGen::ARMXEmitter *emitter) { emit_ = emitter; }
int GetMipsRegOffset(MIPSReg r);
private:
bool Consecutive(int v1, int v2) const;
bool Consecutive(int v1, int v2, int v3) const;
bool Consecutive(int v1, int v2, int v3, int v4) const;
MIPSReg GetTempR();
const ArmGen::ARMReg *GetMIPSAllocationOrder(int &count);
int GetMipsRegOffsetV(MIPSReg r) {
return GetMipsRegOffset(r + 32);
}
int QGetFreeQuad(int start, int count, const char *reason);
void SetupInitialRegs();
MIPSState *mips_;
ArmGen::ARMXEmitter *emit_;
MIPSComp::JitState *js_;
MIPSComp::JitOptions *jo_;
int qTime_;
enum {
NUM_ARMFPUREG = 32,
NUM_ARMQUADS = 16,
NUM_MIPSFPUREG = ArmJitConstants::TOTAL_MAPPABLE_MIPSFPUREGS,
};
FPURegARM ar[NUM_ARMFPUREG];
FPURegMIPS mr[NUM_MIPSFPUREG];
FPURegQuad qr[NUM_ARMQUADS];
FPURegMIPS *vr;
bool pendingFlush;
bool initialReady = false;
FPURegARM arInitial[NUM_ARMFPUREG];
FPURegMIPS mrInitial[NUM_MIPSFPUREG];
};