2013-01-25 23:09:11 +01:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-02-09 18:18:32 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../MIPS.h"
|
|
|
|
#include "../MIPSAnalyst.h"
|
2013-02-10 15:53:56 +01:00
|
|
|
#include "Core/MIPS/ARM/ArmRegCache.h"
|
2013-02-15 22:38:28 +01:00
|
|
|
#include "Core/MIPS/MIPSVFPUUtils.h"
|
2013-11-28 23:56:32 +10:00
|
|
|
#include "Common/ArmEmitter.h"
|
2013-02-09 18:18:32 +01:00
|
|
|
|
|
|
|
using namespace ArmGen;
|
|
|
|
|
|
|
|
enum {
|
2013-02-20 00:03:47 +01:00
|
|
|
NUM_TEMPS = 16,
|
2013-02-16 02:06:02 +01:00
|
|
|
TEMP0 = 32 + 128,
|
|
|
|
TOTAL_MAPPABLE_MIPSFPUREGS = 32 + 128 + NUM_TEMPS,
|
2013-02-09 18:18:32 +01:00
|
|
|
};
|
2013-01-25 23:09:11 +01:00
|
|
|
|
2013-02-09 18:18:32 +01:00
|
|
|
struct FPURegARM {
|
|
|
|
int mipsReg; // if -1, no mipsreg attached.
|
|
|
|
bool isDirty; // Should the register be written back?
|
|
|
|
};
|
2013-01-25 23:09:11 +01:00
|
|
|
|
2013-02-09 18:18:32 +01:00
|
|
|
struct FPURegMIPS {
|
|
|
|
// Where is this MIPS register?
|
|
|
|
RegMIPSLoc loc;
|
|
|
|
// Data (only one of these is used, depending on loc. Could make a union).
|
2013-02-20 00:03:47 +01:00
|
|
|
int reg;
|
2013-02-09 18:18:32 +01:00
|
|
|
bool spillLock; // if true, this register cannot be spilled.
|
2013-02-20 00:03:47 +01:00
|
|
|
bool tempLock;
|
2013-02-09 18:18:32 +01:00
|
|
|
// If loc == ML_MEM, it's back in its location in the CPU context struct.
|
|
|
|
};
|
2013-01-25 23:09:11 +01:00
|
|
|
|
2013-02-09 18:18:32 +01:00
|
|
|
class ArmRegCacheFPU
|
|
|
|
{
|
2013-01-25 23:09:11 +01:00
|
|
|
public:
|
2013-02-09 18:18:32 +01:00
|
|
|
ArmRegCacheFPU(MIPSState *mips);
|
|
|
|
~ArmRegCacheFPU() {}
|
|
|
|
|
|
|
|
void Init(ARMXEmitter *emitter);
|
|
|
|
void Start(MIPSAnalyst::AnalysisResults &stats);
|
|
|
|
|
|
|
|
// Protect the arm register containing a MIPS register from spilling, to ensure that
|
|
|
|
// it's being kept allocated.
|
|
|
|
void SpillLock(MIPSReg reg, MIPSReg reg2 = -1, MIPSReg reg3 = -1, MIPSReg reg4 = -1);
|
2013-02-20 00:03:47 +01:00
|
|
|
void SpillLockV(MIPSReg r) { SpillLock(r + 32); }
|
|
|
|
|
2013-07-31 00:07:34 +02:00
|
|
|
void ReleaseSpillLocksAndDiscardTemps();
|
2014-03-11 21:43:48 +01:00
|
|
|
void ReleaseSpillLock(int mipsreg) {
|
2013-02-16 02:06:02 +01:00
|
|
|
mr[mipsreg].spillLock = false;
|
|
|
|
}
|
2013-02-20 00:03:47 +01:00
|
|
|
void ReleaseSpillLockV(int mipsreg) {
|
|
|
|
ReleaseSpillLock(mipsreg + 32);
|
|
|
|
}
|
2013-02-09 18:18:32 +01:00
|
|
|
|
|
|
|
void SetImm(MIPSReg reg, u32 immVal);
|
|
|
|
bool IsImm(MIPSReg reg) const;
|
|
|
|
u32 GetImm(MIPSReg reg) const;
|
|
|
|
|
|
|
|
// Returns an ARM register containing the requested MIPS register.
|
|
|
|
ARMReg MapReg(MIPSReg reg, int mapFlags = 0);
|
|
|
|
void MapInIn(MIPSReg rd, MIPSReg rs);
|
2013-02-10 15:53:56 +01:00
|
|
|
void MapDirty(MIPSReg rd);
|
2013-02-09 18:18:32 +01:00
|
|
|
void MapDirtyIn(MIPSReg rd, MIPSReg rs, bool avoidLoad = true);
|
|
|
|
void MapDirtyInIn(MIPSReg rd, MIPSReg rs, MIPSReg rt, bool avoidLoad = true);
|
|
|
|
void FlushArmReg(ARMReg r);
|
2013-02-16 02:06:02 +01:00
|
|
|
void FlushR(MIPSReg r);
|
|
|
|
void DiscardR(MIPSReg r);
|
2013-11-19 16:25:38 +01:00
|
|
|
|
|
|
|
// VFPU register as single ARM VFP registers. Must not be used in the upcoming NEON mode!
|
|
|
|
void MapRegV(int vreg, int flags = 0);
|
|
|
|
void LoadToRegV(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);
|
2013-02-20 00:03:47 +01:00
|
|
|
bool IsTempX(ARMReg r) const;
|
2013-02-09 18:18:32 +01:00
|
|
|
|
2013-02-20 00:03:47 +01:00
|
|
|
MIPSReg GetTempR();
|
|
|
|
MIPSReg GetTempV() { return GetTempR() - 32; }
|
|
|
|
|
2014-03-11 21:43:48 +01:00
|
|
|
int FlushGetSequential(int a, int maxArmReg);
|
2013-02-09 18:18:32 +01:00
|
|
|
void FlushAll();
|
|
|
|
|
|
|
|
ARMReg R(int preg); // Returns a cached register
|
2013-02-15 22:38:28 +01:00
|
|
|
|
2013-11-19 16:25:38 +01:00
|
|
|
// VFPU registers as single VFP registers
|
2013-02-15 22:38:28 +01:00
|
|
|
ARMReg V(int vreg) { return R(vreg + 32); }
|
|
|
|
|
|
|
|
// NOTE: These require you to release spill locks manually!
|
2013-07-31 00:07:34 +02:00
|
|
|
void MapRegsAndSpillLockV(int vec, VectorSize vsz, int flags);
|
|
|
|
void MapRegsAndSpillLockV(const u8 *v, VectorSize vsz, int flags);
|
2013-02-15 22:38:28 +01:00
|
|
|
|
|
|
|
void SpillLockV(const u8 *v, VectorSize vsz);
|
|
|
|
void SpillLockV(int vec, VectorSize vsz);
|
2013-02-09 18:18:32 +01:00
|
|
|
|
2013-07-29 00:26:21 +10:00
|
|
|
void SetEmitter(ARMXEmitter *emitter) { emit_ = emitter; }
|
2013-02-09 18:18:32 +01:00
|
|
|
|
|
|
|
// For better log output only.
|
|
|
|
void SetCompilerPC(u32 compilerPC) { compilerPC_ = compilerPC; }
|
|
|
|
|
|
|
|
int GetMipsRegOffset(MIPSReg r);
|
2013-02-10 15:53:56 +01:00
|
|
|
int GetMipsRegOffsetV(MIPSReg r) {
|
|
|
|
return GetMipsRegOffset(r + 32);
|
|
|
|
}
|
2014-03-11 21:43:48 +01:00
|
|
|
int GetNumARMFPURegs();
|
2013-02-14 00:02:09 +01:00
|
|
|
|
2013-02-15 22:38:28 +01:00
|
|
|
private:
|
2014-03-29 20:34:17 -07:00
|
|
|
void SetupInitialRegs();
|
|
|
|
|
2013-02-09 18:18:32 +01:00
|
|
|
MIPSState *mips_;
|
2013-07-29 00:26:21 +10:00
|
|
|
ARMXEmitter *emit_;
|
2013-02-09 18:18:32 +01:00
|
|
|
u32 compilerPC_;
|
|
|
|
|
2013-11-09 20:14:02 +01:00
|
|
|
int numARMFpuReg_;
|
|
|
|
|
2013-02-09 18:18:32 +01:00
|
|
|
enum {
|
2013-11-09 20:14:02 +01:00
|
|
|
MAX_ARMFPUREG = 32, // TODO: Support 32, which you have with NEON
|
2013-02-09 18:18:32 +01:00
|
|
|
NUM_MIPSFPUREG = TOTAL_MAPPABLE_MIPSFPUREGS,
|
|
|
|
};
|
2013-01-25 23:09:11 +01:00
|
|
|
|
2013-11-09 20:14:02 +01:00
|
|
|
FPURegARM ar[MAX_ARMFPUREG];
|
2013-02-20 00:03:47 +01:00
|
|
|
FPURegMIPS mr[NUM_MIPSFPUREG];
|
|
|
|
FPURegMIPS *vr;
|
2014-03-29 20:34:17 -07:00
|
|
|
|
|
|
|
bool pendingFlush;
|
|
|
|
bool initialReady;
|
|
|
|
FPURegARM arInitial[MAX_ARMFPUREG];
|
|
|
|
FPURegMIPS mrInitial[NUM_MIPSFPUREG];
|
2013-02-09 18:18:32 +01:00
|
|
|
};
|