PPCTables: Use std::array instead of raw C arrays

This commit is contained in:
Lioncash 2017-01-18 01:17:37 -05:00
parent 1a1ce42889
commit 6c61021eb1
5 changed files with 34 additions and 29 deletions

View File

@ -484,7 +484,7 @@ void Jit64::mtcrf(UGeckoInstruction inst)
} }
else else
{ {
MOV(64, R(RSCRATCH2), ImmPtr(m_crTable)); MOV(64, R(RSCRATCH2), ImmPtr(m_crTable.data()));
gpr.Lock(inst.RS); gpr.Lock(inst.RS);
gpr.BindToRegister(inst.RS, true, false); gpr.BindToRegister(inst.RS, true, false);
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
@ -531,7 +531,7 @@ void Jit64::mcrxr(UGeckoInstruction inst)
// [SO OV CA 0] << 3 // [SO OV CA 0] << 3
SHL(32, R(RSCRATCH), Imm8(4)); SHL(32, R(RSCRATCH), Imm8(4));
MOV(64, R(RSCRATCH2), ImmPtr(m_crTable)); MOV(64, R(RSCRATCH2), ImmPtr(m_crTable.data()));
MOV(64, R(RSCRATCH), MRegSum(RSCRATCH, RSCRATCH2)); MOV(64, R(RSCRATCH), MRegSum(RSCRATCH, RSCRATCH2));
MOV(64, PPCSTATE(cr_val[inst.CRFD]), R(RSCRATCH)); MOV(64, PPCSTATE(cr_val[inst.CRFD]), R(RSCRATCH));
@ -623,7 +623,7 @@ void Jit64::mcrfs(UGeckoInstruction inst)
} }
AND(32, R(RSCRATCH), Imm32(mask)); AND(32, R(RSCRATCH), Imm32(mask));
MOV(32, PPCSTATE(fpscr), R(RSCRATCH)); MOV(32, PPCSTATE(fpscr), R(RSCRATCH));
LEA(64, RSCRATCH, M(&m_crTable)); LEA(64, RSCRATCH, M(m_crTable.data()));
MOV(64, R(RSCRATCH), MComplex(RSCRATCH, RSCRATCH2, SCALE_8, 0)); MOV(64, R(RSCRATCH), MComplex(RSCRATCH, RSCRATCH2, SCALE_8, 0));
MOV(64, PPCSTATE(cr_val[inst.CRFD]), R(RSCRATCH)); MOV(64, PPCSTATE(cr_val[inst.CRFD]), R(RSCRATCH));
} }

View File

@ -102,7 +102,7 @@ void JitArm64::mcrxr(UGeckoInstruction inst)
// [SO OV CA 0] << 3 // [SO OV CA 0] << 3
LSL(WA, WA, 4); LSL(WA, WA, 4);
MOVP2R(XB, m_crTable); MOVP2R(XB, m_crTable.data());
LDR(XB, XB, XA); LDR(XB, XB, XA);
STR(INDEX_UNSIGNED, XB, PPC_REG, PPCSTATE_OFF(cr_val[inst.CRFD])); STR(INDEX_UNSIGNED, XB, PPC_REG, PPCSTATE_OFF(cr_val[inst.CRFD]));
@ -636,7 +636,7 @@ void JitArm64::mtcrf(UGeckoInstruction inst)
ARM64Reg XA = EncodeRegTo64(WA); ARM64Reg XA = EncodeRegTo64(WA);
ARM64Reg WB = gpr.GetReg(); ARM64Reg WB = gpr.GetReg();
ARM64Reg XB = EncodeRegTo64(WB); ARM64Reg XB = EncodeRegTo64(WB);
MOVP2R(XB, m_crTable); MOVP2R(XB, m_crTable.data());
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
{ {
if ((crm & (0x80 >> i)) != 0) if ((crm & (0x80 >> i)) != 0)

View File

@ -2,8 +2,12 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/PowerPC/PPCTables.h"
#include <algorithm> #include <algorithm>
#include <array>
#include <cinttypes> #include <cinttypes>
#include <cstddef>
#include <vector> #include <vector>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -13,25 +17,24 @@
#include "Core/PowerPC/Interpreter/Interpreter.h" #include "Core/PowerPC/Interpreter/Interpreter.h"
#include "Core/PowerPC/Interpreter/Interpreter_Tables.h" #include "Core/PowerPC/Interpreter/Interpreter_Tables.h"
#include "Core/PowerPC/JitInterface.h" #include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/PPCTables.h"
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
GekkoOPInfo* m_infoTable[64]; std::array<GekkoOPInfo*, 64> m_infoTable;
GekkoOPInfo* m_infoTable4[1024]; std::array<GekkoOPInfo*, 1024> m_infoTable4;
GekkoOPInfo* m_infoTable19[1024]; std::array<GekkoOPInfo*, 1024> m_infoTable19;
GekkoOPInfo* m_infoTable31[1024]; std::array<GekkoOPInfo*, 1024> m_infoTable31;
GekkoOPInfo* m_infoTable59[32]; std::array<GekkoOPInfo*, 32> m_infoTable59;
GekkoOPInfo* m_infoTable63[1024]; std::array<GekkoOPInfo*, 1024> m_infoTable63;
GekkoOPInfo* m_allInstructions[512]; std::array<GekkoOPInfo*, 512> m_allInstructions;
int m_numInstructions; size_t m_numInstructions;
const u64 m_crTable[16] = { const std::array<u64, 16> m_crTable = {{
PPCCRToInternal(0x0), PPCCRToInternal(0x1), PPCCRToInternal(0x2), PPCCRToInternal(0x3), PPCCRToInternal(0x0), PPCCRToInternal(0x1), PPCCRToInternal(0x2), PPCCRToInternal(0x3),
PPCCRToInternal(0x4), PPCCRToInternal(0x5), PPCCRToInternal(0x6), PPCCRToInternal(0x7), PPCCRToInternal(0x4), PPCCRToInternal(0x5), PPCCRToInternal(0x6), PPCCRToInternal(0x7),
PPCCRToInternal(0x8), PPCCRToInternal(0x9), PPCCRToInternal(0xA), PPCCRToInternal(0xB), PPCCRToInternal(0x8), PPCCRToInternal(0x9), PPCCRToInternal(0xA), PPCCRToInternal(0xB),
PPCCRToInternal(0xC), PPCCRToInternal(0xD), PPCCRToInternal(0xE), PPCCRToInternal(0xF), PPCCRToInternal(0xC), PPCCRToInternal(0xD), PPCCRToInternal(0xE), PPCCRToInternal(0xF),
}; }};
GekkoOPInfo* GetOpInfo(UGeckoInstruction _inst) GekkoOPInfo* GetOpInfo(UGeckoInstruction _inst)
{ {
@ -152,7 +155,7 @@ void PrintInstructionRunCounts()
typedef std::pair<const char*, u64> OpInfo; typedef std::pair<const char*, u64> OpInfo;
std::vector<OpInfo> temp; std::vector<OpInfo> temp;
temp.reserve(m_numInstructions); temp.reserve(m_numInstructions);
for (int i = 0; i < m_numInstructions; ++i) for (size_t i = 0; i < m_numInstructions; ++i)
{ {
GekkoOPInfo* pInst = m_allInstructions[i]; GekkoOPInfo* pInst = m_allInstructions[i];
temp.emplace_back(pInst->opname, pInst->runCount); temp.emplace_back(pInst->opname, pInst->runCount);
@ -175,7 +178,7 @@ void LogCompiledInstructions()
File::IOFile f(StringFromFormat("%sinst_log%i.txt", File::GetUserPath(D_LOGS_IDX).c_str(), time), File::IOFile f(StringFromFormat("%sinst_log%i.txt", File::GetUserPath(D_LOGS_IDX).c_str(), time),
"w"); "w");
for (int i = 0; i < m_numInstructions; i++) for (size_t i = 0; i < m_numInstructions; i++)
{ {
GekkoOPInfo* pInst = m_allInstructions[i]; GekkoOPInfo* pInst = m_allInstructions[i];
if (pInst->compileCount > 0) if (pInst->compileCount > 0)
@ -186,7 +189,7 @@ void LogCompiledInstructions()
} }
f.Open(StringFromFormat("%sinst_not%i.txt", File::GetUserPath(D_LOGS_IDX).c_str(), time), "w"); f.Open(StringFromFormat("%sinst_not%i.txt", File::GetUserPath(D_LOGS_IDX).c_str(), time), "w");
for (int i = 0; i < m_numInstructions; i++) for (size_t i = 0; i < m_numInstructions; i++)
{ {
GekkoOPInfo* pInst = m_allInstructions[i]; GekkoOPInfo* pInst = m_allInstructions[i];
if (pInst->compileCount == 0) if (pInst->compileCount == 0)

View File

@ -4,6 +4,9 @@
#pragma once #pragma once
#include <array>
#include <cstddef>
#include "Core/PowerPC/Gekko.h" #include "Core/PowerPC/Gekko.h"
#include "Core/PowerPC/Interpreter/Interpreter.h" #include "Core/PowerPC/Interpreter/Interpreter.h"
@ -92,16 +95,15 @@ struct GekkoOPInfo
int compileCount; int compileCount;
u32 lastUse; u32 lastUse;
}; };
extern GekkoOPInfo* m_infoTable[64]; extern std::array<GekkoOPInfo*, 64> m_infoTable;
extern GekkoOPInfo* m_infoTable4[1024]; extern std::array<GekkoOPInfo*, 1024> m_infoTable4;
extern GekkoOPInfo* m_infoTable19[1024]; extern std::array<GekkoOPInfo*, 1024> m_infoTable19;
extern GekkoOPInfo* m_infoTable31[1024]; extern std::array<GekkoOPInfo*, 1024> m_infoTable31;
extern GekkoOPInfo* m_infoTable59[32]; extern std::array<GekkoOPInfo*, 32> m_infoTable59;
extern GekkoOPInfo* m_infoTable63[1024]; extern std::array<GekkoOPInfo*, 1024> m_infoTable63;
extern GekkoOPInfo* m_allInstructions[512]; extern std::array<GekkoOPInfo*, 512> m_allInstructions;
extern size_t m_numInstructions;
extern int m_numInstructions;
GekkoOPInfo* GetOpInfo(UGeckoInstruction _inst); GekkoOPInfo* GetOpInfo(UGeckoInstruction _inst);
Interpreter::Instruction GetInterpreterOp(UGeckoInstruction _inst); Interpreter::Instruction GetInterpreterOp(UGeckoInstruction _inst);

View File

@ -325,7 +325,7 @@ inline u64 PPCCRToInternal(u8 value)
} }
// convert flags into 64-bit CR values with a lookup table // convert flags into 64-bit CR values with a lookup table
extern const u64 m_crTable[16]; extern const std::array<u64, 16> m_crTable;
// Warning: these CR operations are fairly slow since they need to convert from // Warning: these CR operations are fairly slow since they need to convert from
// PowerPC format (4 bit) to our internal 64 bit format. See the definition of // PowerPC format (4 bit) to our internal 64 bit format. See the definition of