1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 12:12:50 +01:00

- Improved PPU decoder

This commit is contained in:
DH 2013-07-01 15:08:58 +03:00
parent 1f6a7560e4
commit 4486cbb855
10 changed files with 902 additions and 500 deletions

View File

@ -281,7 +281,7 @@ public:
if(m_count == 0) return;
m_count = 0;
safe_delete(m_array);
safe_free(m_array);
}
inline T& Get(const u64 num)

View File

@ -2,6 +2,341 @@
class Decoder
{
protected:
class instr_caller
{
public:
virtual ~instr_caller()
{
}
virtual void operator ()() = 0;
};
instr_caller* m_instr_decoder;
template<typename TO>
class instr_binder_0 : public instr_caller
{
typedef void (TO::*func_t)();
TO* m_op;
func_t m_func;
public:
instr_binder_0(TO* op, func_t func)
: instr_caller()
, m_op(op)
, m_func(func)
{
}
virtual void operator ()()
{
(m_op->*m_func)();
}
};
template<typename TO, typename TD, typename T1>
class instr_binder_1 : public instr_caller
{
typedef void (TO::*func_t)(T1);
typedef T1 (TD::*arg_1_t)();
TO* m_op;
TD* m_dec;
func_t m_func;
arg_1_t m_arg_func_1;
public:
instr_binder_1(TO* op, TD* dec, func_t func, arg_1_t arg_func_1)
: instr_caller()
, m_op(op)
, m_dec(dec)
, m_func(func)
, m_arg_func_1(arg_func_1)
{
}
virtual void operator ()()
{
(m_op->*m_func)((m_dec->*m_arg_func_1)());
}
};
template<typename TO, typename TD, typename T1, typename T2>
class instr_binder_2 : public instr_caller
{
typedef void (TO::*func_t)(T1, T2);
typedef T1 (TD::*arg_1_t)();
typedef T2 (TD::*arg_2_t)();
TO* m_op;
TD* m_dec;
func_t m_func;
arg_1_t m_arg_func_1;
arg_2_t m_arg_func_2;
public:
instr_binder_2(TO* op, TD* dec, func_t func, arg_1_t arg_func_1, arg_2_t arg_func_2)
: instr_caller()
, m_op(op)
, m_dec(dec)
, m_func(func)
, m_arg_func_1(arg_func_1)
, m_arg_func_2(arg_func_2)
{
}
virtual void operator ()()
{
(m_op->*m_func)(
(m_dec->*m_arg_func_1)(),
(m_dec->*m_arg_func_2)()
);
}
};
template<typename TO, typename TD, typename T1, typename T2, typename T3>
class instr_binder_3 : public instr_caller
{
typedef void (TO::*func_t)(T1, T2, T3);
typedef T1 (TD::*arg_1_t)();
typedef T2 (TD::*arg_2_t)();
typedef T3 (TD::*arg_3_t)();
TO* m_op;
TD* m_dec;
func_t m_func;
arg_1_t m_arg_func_1;
arg_2_t m_arg_func_2;
arg_3_t m_arg_func_3;
public:
instr_binder_3(TO* op, TD* dec, func_t func,
arg_1_t arg_func_1,
arg_2_t arg_func_2,
arg_3_t arg_func_3)
: instr_caller()
, m_op(op)
, m_dec(dec)
, m_func(func)
, m_arg_func_1(arg_func_1)
, m_arg_func_2(arg_func_2)
, m_arg_func_3(arg_func_3)
{
}
virtual void operator ()()
{
(m_op->*m_func)(
(m_dec->*m_arg_func_1)(),
(m_dec->*m_arg_func_2)(),
(m_dec->*m_arg_func_3)()
);
}
};
template<typename TO, typename TD, typename T1, typename T2, typename T3, typename T4>
class instr_binder_4 : public instr_caller
{
typedef void (TO::*func_t)(T1, T2, T3, T4);
typedef T1 (TD::*arg_1_t)();
typedef T2 (TD::*arg_2_t)();
typedef T3 (TD::*arg_3_t)();
typedef T4 (TD::*arg_4_t)();
TO* m_op;
TD* m_dec;
func_t m_func;
arg_1_t m_arg_func_1;
arg_2_t m_arg_func_2;
arg_3_t m_arg_func_3;
arg_4_t m_arg_func_4;
public:
instr_binder_4(TO* op, TD* dec, func_t func,
arg_1_t arg_func_1,
arg_2_t arg_func_2,
arg_3_t arg_func_3,
arg_4_t arg_func_4)
: instr_caller()
, m_op(op)
, m_dec(dec)
, m_func(func)
, m_arg_func_1(arg_func_1)
, m_arg_func_2(arg_func_2)
, m_arg_func_3(arg_func_3)
, m_arg_func_4(arg_func_4)
{
}
virtual void operator ()()
{
(m_op->*m_func)(
(m_dec->*m_arg_func_1)(),
(m_dec->*m_arg_func_2)(),
(m_dec->*m_arg_func_3)(),
(m_dec->*m_arg_func_4)()
);
}
};
template<typename TO, typename TD, typename T1, typename T2, typename T3, typename T4, typename T5>
class instr_binder_5 : public instr_caller
{
typedef void (TO::*func_t)(T1, T2, T3, T4, T5);
typedef T1 (TD::*arg_1_t)();
typedef T2 (TD::*arg_2_t)();
typedef T3 (TD::*arg_3_t)();
typedef T4 (TD::*arg_4_t)();
typedef T5 (TD::*arg_5_t)();
TO* m_op;
TD* m_dec;
func_t m_func;
arg_1_t m_arg_func_1;
arg_2_t m_arg_func_2;
arg_3_t m_arg_func_3;
arg_4_t m_arg_func_4;
arg_5_t m_arg_func_5;
public:
instr_binder_5(TO* op, TD* dec, func_t func,
arg_1_t arg_func_1,
arg_2_t arg_func_2,
arg_3_t arg_func_3,
arg_4_t arg_func_4,
arg_5_t arg_func_5)
: instr_caller()
, m_op(op)
, m_dec(dec)
, m_func(func)
, m_arg_func_1(arg_func_1)
, m_arg_func_2(arg_func_2)
, m_arg_func_3(arg_func_3)
, m_arg_func_4(arg_func_4)
, m_arg_func_5(arg_func_5)
{
}
virtual void operator ()()
{
(m_op->*m_func)(
(m_dec->*m_arg_func_1)(),
(m_dec->*m_arg_func_2)(),
(m_dec->*m_arg_func_3)(),
(m_dec->*m_arg_func_4)(),
(m_dec->*m_arg_func_5)()
);
}
};
template<typename TO, typename TD, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
class instr_binder_6 : public instr_caller
{
typedef void (TO::*func_t)(T1, T2, T3, T4, T5, T6);
typedef T1 (TD::*arg_1_t)();
typedef T2 (TD::*arg_2_t)();
typedef T3 (TD::*arg_3_t)();
typedef T4 (TD::*arg_4_t)();
typedef T5 (TD::*arg_5_t)();
typedef T6 (TD::*arg_6_t)();
TO* m_op;
TD* m_dec;
func_t m_func;
arg_1_t m_arg_func_1;
arg_2_t m_arg_func_2;
arg_3_t m_arg_func_3;
arg_4_t m_arg_func_4;
arg_5_t m_arg_func_5;
arg_6_t m_arg_func_6;
public:
instr_binder_6(TO* op, TD* dec, func_t func,
arg_1_t arg_func_1,
arg_2_t arg_func_2,
arg_3_t arg_func_3,
arg_4_t arg_func_4,
arg_5_t arg_func_5,
arg_6_t arg_func_6)
: instr_caller()
, m_op(op)
, m_dec(dec)
, m_func(func)
, m_arg_func_1(arg_func_1)
, m_arg_func_2(arg_func_2)
, m_arg_func_3(arg_func_3)
, m_arg_func_4(arg_func_4)
, m_arg_func_5(arg_func_5)
, m_arg_func_6(arg_func_6)
{
}
virtual void operator ()()
{
(m_op->*m_func)(
(m_dec->*m_arg_func_1)(),
(m_dec->*m_arg_func_2)(),
(m_dec->*m_arg_func_3)(),
(m_dec->*m_arg_func_4)(),
(m_dec->*m_arg_func_5)(),
(m_dec->*m_arg_func_6)()
);
}
};
template<int count, typename TD, typename T>
class instr_list : public instr_caller
{
typedef T (TD::*func_t)();
TD* m_parent;
func_t m_func;
instr_caller* m_instrs[count];
instr_caller* m_error_func;
public:
instr_list(TD* parent, func_t func, instr_caller* error_func)
: instr_caller()
, m_parent(parent)
, m_func(func)
, m_error_func(error_func)
{
memset(m_instrs, 0, sizeof(instr_caller*) * count);
}
virtual ~instr_list()
{
for(int i=0; i<count; ++i)
{
delete m_instrs[i];
}
delete m_error_func;
}
void set_instr(uint pos, instr_caller* func)
{
assert(pos < count);
m_instrs[pos] = func;
}
virtual void operator ()()
{
instr_caller* instr = m_instrs[(m_parent->*m_func)() & (count - 1)];
if(instr)
{
(*instr)();
}
else if(m_error_func)
{
(*m_error_func)();
}
}
};
template<int count, typename TD, typename T>
instr_list<count, TD, T>* new_list(TD* parent, T (TD::*func)(), instr_caller* error_func)
{
return new instr_list<count, TD, T>(parent, func, error_func);
}
public:
virtual void Decode(const u32 code)=0;
};

View File

@ -39,7 +39,8 @@ void PPCThreadManager::RemoveThread(const u32 id)
wxGetApp().SendDbgCommand(DID_REMOVE_THREAD, &m_threads[i]);
m_threads[i].Close();
m_threads.RemoveAt(i);
delete &m_threads[i];
m_threads.RemoveFAt(i);
break;
}

File diff suppressed because it is too large Load Diff

View File

@ -840,7 +840,7 @@ private:
Write(wxString::Format("bc [%x:%x:%x:%x:%x], cr%d[%x], 0x%x, %d, %d", bo0, bo1, bo2, bo3, bo4, bi/4, bi%4, bd, aa, lk));
}
void SC(const s32 sc_code)
void SC(OP_sIMM sc_code)
{
switch(sc_code)
{
@ -1427,7 +1427,7 @@ private:
{
DisAsm_F1_R2("lfsux", frd, ra, rb);
}
void SYNC(OP_REG l)
void SYNC(OP_uIMM l)
{
DisAsm_INT1("sync", l);
}

View File

@ -2054,7 +2054,7 @@ private:
CPU.SetBranch(branchTarget((aa ? 0 : CPU.PC), bd));
if(lk) CPU.LR = CPU.PC + 4;
}
void SC(const s32 sc_code)
void SC(OP_sIMM sc_code)
{
switch(sc_code)
{
@ -2889,7 +2889,7 @@ private:
CPU.FPR[frd] = (float&)CPU.FPR[frd];
CPU.GPR[ra] = addr;
}
void SYNC(OP_REG l)
void SYNC(OP_uIMM l)
{
}
void LFDX(OP_REG frd, OP_REG ra, OP_REG rb)

View File

@ -1,8 +1,8 @@
#pragma once
#define OP_REG const u32
#define OP_sIMM const s32
#define OP_uIMM const u32
#define OP_REG u32
#define OP_sIMM s32
#define OP_uIMM u32
#define START_OPCODES_GROUP(x) /*x*/
#define ADD_OPCODE(name, regs) virtual void(##name##)##regs##=0
#define ADD_NULL_OPCODE(name) virtual void(##name##)()=0
@ -622,7 +622,7 @@ public:
ADD_OPCODE(ADDI,(OP_REG rd, OP_REG ra, OP_sIMM simm16));
ADD_OPCODE(ADDIS,(OP_REG rd, OP_REG ra, OP_sIMM simm16));
ADD_OPCODE(BC,(OP_REG bo, OP_REG bi, OP_sIMM bd, OP_REG aa, OP_REG lk));
ADD_OPCODE(SC,(const s32 sc_code));
ADD_OPCODE(SC,(OP_sIMM sc_code));
ADD_OPCODE(B,(OP_sIMM ll, OP_REG aa, OP_REG lk));
START_OPCODES_GROUP(G_13)
@ -744,7 +744,7 @@ public:
/*0x21b*/ADD_OPCODE(SRD,(OP_REG ra, OP_REG rs, OP_REG rb, bool rc));
/*0x227*/ADD_OPCODE(LVRX,(OP_REG vd, OP_REG ra, OP_REG rb));
/*0x237*/ADD_OPCODE(LFSUX,(OP_REG frd, OP_REG ra, OP_REG rb));
/*0x256*/ADD_OPCODE(SYNC,(OP_REG l));
/*0x256*/ADD_OPCODE(SYNC,(OP_uIMM l));
/*0x257*/ADD_OPCODE(LFDX,(OP_REG frd, OP_REG ra, OP_REG rb));
/*0x277*/ADD_OPCODE(LFDUX,(OP_REG frd, OP_REG ra, OP_REG rb));
/*0x287*/ADD_OPCODE(STVLX,(OP_REG vs, OP_REG ra, OP_REG rb));
@ -853,6 +853,8 @@ public:
ADD_OPCODE(UNK,(const u32 code, const u32 opcode, const u32 gcode));
};
//instr_caller* g_instrs[0x40];
#undef START_OPCODES_GROUP
#undef ADD_OPCODE
#undef ADD_NULL_OPCODE

View File

@ -1,8 +1,8 @@
#pragma once
#define OP_REG const u32
#define OP_sIMM const s32
#define OP_uIMM const u32
#define OP_REG u32
#define OP_sIMM s32
#define OP_uIMM u32
#define START_OPCODES_GROUP(x) /*x*/
#define ADD_OPCODE(name, regs) virtual void(##name##)##regs##=0
#define ADD_NULL_OPCODE(name) virtual void(##name##)()=0

View File

@ -70,13 +70,13 @@
<IncludePath>.\;..\wxWidgets\include;..\SDL-1.3.0-5538\include;..\SDL_image-1.2.10;..\pthreads-2.8.0;..\;$(IncludePath)</IncludePath>
<OutDir>$(SolutionDir)bin\</OutDir>
<LibraryPath>..\libs\$(Configuration)\;$(LibraryPath)</LibraryPath>
<TargetName>$(ProjectName)-$(PlatformShortName)</TargetName>
<TargetName>$(ProjectName)-$(PlatformShortName)-dbg</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>.\;..\wxWidgets\include;..\SDL-1.3.0-5538\include;..\SDL_image-1.2.10;..\pthreads-2.8.0;..\;$(IncludePath)</IncludePath>
<OutDir>$(SolutionDir)bin\</OutDir>
<LibraryPath>..\libs\$(Configuration)\;$(LibraryPath)</LibraryPath>
<TargetName>$(ProjectName)-$(PlatformShortName)</TargetName>
<TargetName>$(ProjectName)-$(PlatformShortName)-dbg</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>

View File

@ -174,7 +174,8 @@ static void safe_realloc(T* ptr, uint new_size)
ptr = (T*)((ptr == NULL) ? malloc(new_size * sizeof(T)) : realloc(ptr, new_size * sizeof(T)));
}
#define safe_delete(x) {free(x);(x)=nullptr;}
#define safe_delete(x) do {delete (x);(x)=nullptr;} while(0)
#define safe_free(x) do {free(x);(x)=nullptr;} while(0)
enum Status
{