CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/MIPS/x86/X64IRJit.h
Views: 1401
// 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 "ppsspp_config.h"20#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)2122#include <string>23#include <vector>24#include "Common/x64Emitter.h"25#include "Core/MIPS/IR/IRJit.h"26#include "Core/MIPS/IR/IRNativeCommon.h"27#include "Core/MIPS/JitCommon/JitState.h"28#include "Core/MIPS/JitCommon/JitCommon.h"29#include "Core/MIPS/x86/X64IRRegCache.h"3031#if PPSSPP_PLATFORM(WINDOWS) && (defined(_MSC_VER) || defined(__clang__) || defined(__INTEL_COMPILER))32#define X64JIT_XMM_CALL __vectorcall33#define X64JIT_USE_XMM_CALL 134#elif PPSSPP_ARCH(AMD64)35// SystemV ABI supports XMM registers.36#define X64JIT_XMM_CALL37#define X64JIT_USE_XMM_CALL 138#else39// GCC on x86 doesn't support vectorcall.40#define X64JIT_XMM_CALL41#define X64JIT_USE_XMM_CALL 042#endif4344namespace MIPSComp {4546class X64JitBackend : public Gen::XCodeBlock, public IRNativeBackend {47public:48X64JitBackend(JitOptions &jo, IRBlockCache &blocks);49~X64JitBackend();5051bool DescribeCodePtr(const u8 *ptr, std::string &name) const override;5253void GenerateFixedCode(MIPSState *mipsState) override;54bool CompileBlock(IRBlockCache *irBlockCache, int block_num, bool preload) override;55void ClearAllBlocks() override;56void InvalidateBlock(IRBlockCache *irBlockCache, int block_num) override;5758protected:59const CodeBlockCommon &CodeBlock() const override {60return *this;61}6263private:64void RestoreRoundingMode(bool force = false);65void ApplyRoundingMode(bool force = false);66void MovFromPC(Gen::X64Reg r);67void MovToPC(Gen::X64Reg r);68void WriteDebugPC(uint32_t pc);69void WriteDebugPC(Gen::X64Reg r);70void WriteDebugProfilerStatus(IRProfilerStatus status);7172void SaveStaticRegisters();73void LoadStaticRegisters();7475// Note: destroys SCRATCH1.76void FlushAll();7778void WriteConstExit(uint32_t pc);79void OverwriteExit(int srcOffset, int len, int block_num) override;8081void CompIR_Arith(IRInst inst) override;82void CompIR_Assign(IRInst inst) override;83void CompIR_Basic(IRInst inst) override;84void CompIR_Bits(IRInst inst) override;85void CompIR_Breakpoint(IRInst inst) override;86void CompIR_Compare(IRInst inst) override;87void CompIR_CondAssign(IRInst inst) override;88void CompIR_CondStore(IRInst inst) override;89void CompIR_Div(IRInst inst) override;90void CompIR_Exit(IRInst inst) override;91void CompIR_ExitIf(IRInst inst) override;92void CompIR_FArith(IRInst inst) override;93void CompIR_FAssign(IRInst inst) override;94void CompIR_FCompare(IRInst inst) override;95void CompIR_FCondAssign(IRInst inst) override;96void CompIR_FCvt(IRInst inst) override;97void CompIR_FLoad(IRInst inst) override;98void CompIR_FRound(IRInst inst) override;99void CompIR_FSat(IRInst inst) override;100void CompIR_FSpecial(IRInst inst) override;101void CompIR_FStore(IRInst inst) override;102void CompIR_Generic(IRInst inst) override;103void CompIR_HiLo(IRInst inst) override;104void CompIR_Interpret(IRInst inst) override;105void CompIR_Load(IRInst inst) override;106void CompIR_LoadShift(IRInst inst) override;107void CompIR_Logic(IRInst inst) override;108void CompIR_Mult(IRInst inst) override;109void CompIR_RoundingMode(IRInst inst) override;110void CompIR_Shift(IRInst inst) override;111void CompIR_Store(IRInst inst) override;112void CompIR_StoreShift(IRInst inst) override;113void CompIR_System(IRInst inst) override;114void CompIR_Transfer(IRInst inst) override;115void CompIR_VecArith(IRInst inst) override;116void CompIR_VecAssign(IRInst inst) override;117void CompIR_VecClamp(IRInst inst) override;118void CompIR_VecHoriz(IRInst inst) override;119void CompIR_VecLoad(IRInst inst) override;120void CompIR_VecPack(IRInst inst) override;121void CompIR_VecStore(IRInst inst) override;122void CompIR_ValidateAddress(IRInst inst) override;123124void EmitConst4x32(const void **c, uint32_t v);125void EmitFPUConstants();126void EmitVecConstants();127128Gen::OpArg PrepareSrc1Address(IRInst inst);129void CopyVec4ToFPRLane0(Gen::X64Reg dest, Gen::X64Reg src, int lane);130131JitOptions &jo;132X64IRRegCache regs_;133134const u8 *outerLoop_ = nullptr;135const u8 *outerLoopPCInSCRATCH1_ = nullptr;136const u8 *dispatcherCheckCoreState_ = nullptr;137const u8 *dispatcherPCInSCRATCH1_ = nullptr;138const u8 *dispatcherNoCheck_ = nullptr;139const u8 *restoreRoundingMode_ = nullptr;140const u8 *applyRoundingMode_ = nullptr;141142const u8 *saveStaticRegisters_ = nullptr;143const u8 *loadStaticRegisters_ = nullptr;144145typedef struct { float f[4]; } Float4Constant;146struct Constants {147const void *noSignMask;148const void *signBitAll;149const void *positiveZeroes;150const void *positiveInfinity;151const void *positiveOnes;152const void *negativeOnes;153const void *qNAN;154const void *maxIntBelowAsFloat;155const float *mulTableVi2f;156const float *mulTableVf2i;157const Float4Constant *vec4InitValues;158};159Constants constants;160161int jitStartOffset_ = 0;162int compilingBlockNum_ = -1;163int logBlocks_ = 0;164// Only useful in breakpoints, where it's set immediately prior.165uint32_t lastConstPC_ = 0;166};167168class X64IRJit : public IRNativeJit {169public:170X64IRJit(MIPSState *mipsState)171: IRNativeJit(mipsState), x64Backend_(jo, blocks_) {172Init(x64Backend_);173}174175private:176X64JitBackend x64Backend_;177};178179} // namespace MIPSComp180181#endif182183184