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/JitCommon/JitState.h
Views: 1401
// Copyright (c) 2013- 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/.161718#pragma once1920#include "Common/CommonTypes.h"21#include "Common/Log.h"22#include "Core/MIPS/MIPS.h"2324struct JitBlock;25class JitBlockCache;2627namespace MIPSComp {2829enum CompileDelaySlotFlags30{31// Easy, nothing extra.32DELAYSLOT_NICE = 0,33// Flush registers after delay slot.34DELAYSLOT_FLUSH = 1,35// Preserve flags.36DELAYSLOT_SAFE = 2,37// Flush registers after and preserve flags.38DELAYSLOT_SAFE_FLUSH = DELAYSLOT_FLUSH | DELAYSLOT_SAFE,39};4041struct JitState42{43enum PrefixState44{45PREFIX_UNKNOWN = 0x00,46PREFIX_KNOWN = 0x01,47PREFIX_DIRTY = 0x10,48PREFIX_KNOWN_DIRTY = 0x11,49};5051enum AfterOp52{53AFTER_NONE = 0x00,54AFTER_CORE_STATE = 0x01,55};5657u32 compilerPC;58u32 blockStart;59u32 lastContinuedPC;60u32 initialBlockSize;61int nextExit;62bool cancel;63bool inDelaySlot;64// See JitState::AfterOp for values.65int afterOp;66int downcountAmount;67int numInstructions;68bool compiling; // TODO: get rid of this in favor of using analysis results to determine end of block69bool hadBreakpoints;70bool preloading = false;71JitBlock *curBlock;7273u8 hasSetRounding = 0;74u8 lastSetRounding = 0;75const u8 *currentRoundingFunc = nullptr;7677// VFPU prefix magic78bool startDefaultPrefix = true;79bool blockWrotePrefixes = false;80u32 prefixS;81u32 prefixT;82u32 prefixD;83PrefixState prefixSFlag = PREFIX_UNKNOWN;84PrefixState prefixTFlag = PREFIX_UNKNOWN;85PrefixState prefixDFlag = PREFIX_UNKNOWN;8687void PrefixStart() {88if (startDefaultPrefix) {89EatPrefix();90} else {91PrefixUnknown();92}93}9495void PrefixUnknown() {96prefixSFlag = PREFIX_UNKNOWN;97prefixTFlag = PREFIX_UNKNOWN;98prefixDFlag = PREFIX_UNKNOWN;99}100101bool HasSPrefix() const {102return (prefixSFlag & PREFIX_KNOWN) == 0 || prefixS != 0xE4;103}104105bool HasTPrefix() const {106return (prefixTFlag & PREFIX_KNOWN) == 0 || prefixT != 0xE4;107}108109bool HasDPrefix() const {110return (prefixDFlag & PREFIX_KNOWN) == 0 || prefixD != 0x0;111}112113bool MayHavePrefix() const {114if (HasUnknownPrefix()) {115return true;116} else if (prefixS != 0xE4 || prefixT != 0xE4 || prefixD != 0) {117return true;118}119return false;120}121122bool HasUnknownPrefix() const {123if (!(prefixSFlag & PREFIX_KNOWN) || !(prefixTFlag & PREFIX_KNOWN) || !(prefixDFlag & PREFIX_KNOWN)) {124return true;125}126return false;127}128129bool HasNoPrefix() const {130return !HasSPrefix() && !HasTPrefix() && !HasDPrefix();131}132133void EatPrefix() {134if (HasSPrefix())135prefixSFlag = PREFIX_KNOWN_DIRTY;136prefixS = 0xE4;137if (HasTPrefix())138prefixTFlag = PREFIX_KNOWN_DIRTY;139prefixT = 0xE4;140if (HasDPrefix())141prefixDFlag = PREFIX_KNOWN_DIRTY;142prefixD = 0x0;143}144145u8 VfpuWriteMask() const {146_assert_(prefixDFlag & JitState::PREFIX_KNOWN);147return (prefixD >> 8) & 0xF;148}149150bool VfpuWriteMask(int i) const {151_assert_(prefixDFlag & JitState::PREFIX_KNOWN);152return (prefixD >> (8 + i)) & 1;153}154155void LogPrefix() {156LogSTPrefix("S", prefixS, prefixSFlag);157LogSTPrefix("T", prefixT, prefixTFlag);158LogDPrefix();159}160161private:162void LogSTPrefix(const char *name, int p, int pflag) {163if ((prefixSFlag & PREFIX_KNOWN) == 0) {164ERROR_LOG(Log::JIT, "%s: unknown (%08x %i)", name, p, pflag);165} else if (prefixS != 0xE4) {166ERROR_LOG(Log::JIT, "%s: %08x flag: %i", name, p, pflag);167} else {168WARN_LOG(Log::JIT, "%s: %08x flag: %i", name, p, pflag);169}170}171void LogDPrefix() {172if ((prefixDFlag & PREFIX_KNOWN) == 0) {173ERROR_LOG(Log::JIT, "D: unknown (%08x %i)", prefixD, prefixDFlag);174} else if (prefixD != 0) {175ERROR_LOG(Log::JIT, "D: (%08x %i)", prefixD, prefixDFlag);176} else {177WARN_LOG(Log::JIT, "D: %08x flag: %i", prefixD, prefixDFlag);178}179}180};181182enum class JitDisable {183ALU = 0x0001,184ALU_IMM = 0x0002,185ALU_BIT = 0x0004,186MULDIV = 0x0008,187188FPU = 0x0010,189FPU_COMP = 0x0040,190FPU_XFER = 0x0080,191192VFPU_VEC = 0x0100,193VFPU_MTX_VTFM = 0x0200,194VFPU_COMP = 0x0400,195VFPU_XFER = 0x0800,196197LSU = 0x1000,198LSU_UNALIGNED = 0x2000,199LSU_FPU = 0x4000,200LSU_VFPU = 0x8000,201202SIMD = 0x00100000,203BLOCKLINK = 0x00200000,204POINTERIFY = 0x00400000,205STATIC_ALLOC = 0x00800000,206CACHE_POINTERS = 0x01000000,207REGALLOC_GPR = 0x02000000, // Doesn't really disable regalloc, but flushes after every instr.208REGALLOC_FPR = 0x04000000,209VFPU_MTX_VMMOV = 0x08000000,210VFPU_MTX_VMMUL = 0x10000000,211VFPU_MTX_VMSCL = 0x20000000,212213ALL_FLAGS = 0x3FFFFFFF,214};215216struct JitOptions {217JitOptions();218219bool Disabled(JitDisable bit);220221uint32_t disableFlags;222223// x86224bool enableVFPUSIMD;225bool reserveR15ForAsm;226227// ARM/ARM64228bool useBackJump;229bool useForwardJump;230bool cachePointers;231// ARM only232bool useNEONVFPU;233bool downcountInRegister;234// ARM64 only235bool useASIMDVFPU;236// ARM64 and RV64237bool useStaticAlloc;238bool enablePointerify;239// IR Interpreter240bool optimizeForInterpreter;241242// Common243bool enableBlocklink;244bool immBranches;245bool continueBranches;246bool continueJumps;247int continueMaxInstructions;248};249}250251252