Path: blob/master/Core/MIPS/LoongArch64/LoongArch64RegCache.h
3188 views
// Copyright (c) 2023- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include "Common/LoongArch64Emitter.h"20#include "Core/MIPS/MIPS.h"21#include "Core/MIPS/IR/IRJit.h"22#include "Core/MIPS/IR/IRRegCache.h"2324namespace LoongArch64JitConstants {2526const LoongArch64Gen::LoongArch64Reg DOWNCOUNTREG = LoongArch64Gen::R28;27const LoongArch64Gen::LoongArch64Reg JITBASEREG = LoongArch64Gen::R29;28const LoongArch64Gen::LoongArch64Reg CTXREG = LoongArch64Gen::R30;29const LoongArch64Gen::LoongArch64Reg MEMBASEREG = LoongArch64Gen::R31;30const LoongArch64Gen::LoongArch64Reg SCRATCH1 = LoongArch64Gen::R12;31const LoongArch64Gen::LoongArch64Reg SCRATCH2 = LoongArch64Gen::R13;32const LoongArch64Gen::LoongArch64Reg SCRATCHF1 = LoongArch64Gen::F8;33const LoongArch64Gen::LoongArch64Reg SCRATCHF2 = LoongArch64Gen::F9;3435} // namespace LoongArch64JitConstants3637class LoongArch64RegCache : public IRNativeRegCacheBase {38public:39LoongArch64RegCache(MIPSComp::JitOptions *jo);4041void Init(LoongArch64Gen::LoongArch64Emitter *emitter);4243// May fail and return INVALID_REG if it needs flushing.44LoongArch64Gen::LoongArch64Reg TryMapTempImm(IRReg reg);4546// Returns an LA register containing the requested MIPS register.47LoongArch64Gen::LoongArch64Reg MapGPR(IRReg reg, MIPSMap mapFlags = MIPSMap::INIT);48LoongArch64Gen::LoongArch64Reg MapGPRAsPointer(IRReg reg);49LoongArch64Gen::LoongArch64Reg MapFPR(IRReg reg, MIPSMap mapFlags = MIPSMap::INIT);50LoongArch64Gen::LoongArch64Reg MapVec4(IRReg first, MIPSMap mapFlags = MIPSMap::INIT);5152LoongArch64Gen::LoongArch64Reg MapWithFPRTemp(const IRInst &inst);5354bool IsNormalized32(IRReg reg);5556// Copies to another reg if specified, otherwise same reg.57LoongArch64Gen::LoongArch64Reg Normalize32(IRReg reg, LoongArch64Gen::LoongArch64Reg destReg = LoongArch64Gen::INVALID_REG);5859void FlushBeforeCall();6061LoongArch64Gen::LoongArch64Reg GetAndLockTempGPR();6263LoongArch64Gen::LoongArch64Reg R(IRReg preg); // Returns a cached register, while checking that it's NOT mapped as a pointer64LoongArch64Gen::LoongArch64Reg RPtr(IRReg preg); // Returns a cached register, if it has been mapped as a pointer65LoongArch64Gen::LoongArch64Reg F(IRReg preg);66LoongArch64Gen::LoongArch64Reg V(IRReg preg);6768// These are called once on startup to generate functions, that you should then call.69void EmitLoadStaticRegisters();70void EmitSaveStaticRegisters();7172protected:73void SetupInitialRegs() override;74const StaticAllocation *GetStaticAllocations(int &count) const override;75const int *GetAllocationOrder(MIPSLoc type, MIPSMap flags, int &count, int &base) const override;76void AdjustNativeRegAsPtr(IRNativeReg nreg, bool state) override;7778bool IsNativeRegCompatible(IRNativeReg nreg, MIPSLoc type, MIPSMap flags, int lanes) override;79void LoadNativeReg(IRNativeReg nreg, IRReg first, int lanes) override;80void StoreNativeReg(IRNativeReg nreg, IRReg first, int lanes) override;81void SetNativeRegValue(IRNativeReg nreg, uint32_t imm) override;82void StoreRegValue(IRReg mreg, uint32_t imm) override;83bool TransferNativeReg(IRNativeReg nreg, IRNativeReg dest, MIPSLoc type, IRReg first, int lanes, MIPSMap flags) override;8485private:86bool TransferVecTo1(IRNativeReg nreg, IRNativeReg dest, IRReg first, int oldlanes);87bool Transfer1ToVec(IRNativeReg nreg, IRNativeReg dest, IRReg first, int lanes);8889LoongArch64Gen::LoongArch64Reg FromNativeReg(IRNativeReg r) {90if (r >= NUM_LAGPR)91return (LoongArch64Gen::LoongArch64Reg)(LoongArch64Gen::V0 + (r - NUM_LAGPR));92return (LoongArch64Gen::LoongArch64Reg)(LoongArch64Gen::R0 + r);93}9495LoongArch64Gen::LoongArch64Emitter *emit_ = nullptr;9697enum {98NUM_LAGPR = 32,99NUM_LAFPR = 32,100};101};102103104