mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
DSP LLE Jit, joined work with XK and skidu.
VERY EXPERIMENTAL DON'T EXPECT HIGH PERFORMANCE!. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5288 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
425
Source/Core/DSPCore/Src/Jit/DSPJitExtOps.cpp
Normal file
425
Source/Core/DSPCore/Src/Jit/DSPJitExtOps.cpp
Normal file
@ -0,0 +1,425 @@
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
#include "../DSPMemoryMap.h"
|
||||
#include "../DSPEmitter.h"
|
||||
#include "../DSPIntExtOps.h" // remove when getting rid of writebacklog
|
||||
// See docs in the interpeter
|
||||
|
||||
inline bool IsSameMemArea(u16 a, u16 b)
|
||||
{
|
||||
//LM: tested on WII
|
||||
if ((a>>10)==(b>>10))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
// DR $arR
|
||||
// xxxx xxxx 0000 01rr
|
||||
// Decrement addressing register $arR.
|
||||
void DSPEmitter::dr(const UDSPInstruction opc) {
|
||||
decrement_addr_reg(opc & 0x3);
|
||||
}
|
||||
|
||||
// IR $arR
|
||||
// xxxx xxxx 0000 10rr
|
||||
// Increment addressing register $arR.
|
||||
void DSPEmitter::ir(const UDSPInstruction opc) {
|
||||
increment_addr_reg(opc & 0x3);
|
||||
}
|
||||
|
||||
// NR $arR
|
||||
// xxxx xxxx 0000 11rr
|
||||
// Add corresponding indexing register $ixR to addressing register $arR.
|
||||
void DSPEmitter::nr(const UDSPInstruction opc) {
|
||||
u8 reg = opc & 0x3;
|
||||
|
||||
increase_addr_reg(reg);
|
||||
}
|
||||
|
||||
// MV $axD.D, $acS.S
|
||||
// xxxx xxxx 0001 ddss
|
||||
// Move value of $acS.S to the $axD.D.
|
||||
void DSPEmitter::mv(const UDSPInstruction opc)
|
||||
{
|
||||
u8 sreg = (opc & 0x3) + DSP_REG_ACL0;
|
||||
u8 dreg = ((opc >> 2) & 0x3);
|
||||
|
||||
#if 0 //more tests
|
||||
if ((sreg >= DSP_REG_ACM0) && (g_dsp.r[DSP_REG_SR] & SR_40_MODE_BIT))
|
||||
writeToBackLog(0, dreg + DSP_REG_AXL0, ((u16)dsp_get_acc_h(sreg-DSP_REG_ACM0) & 0x0080) ? 0x8000 : 0x7fff);
|
||||
else
|
||||
#endif
|
||||
writeToBackLog(0, dreg + DSP_REG_AXL0, g_dsp.r[sreg]);
|
||||
}
|
||||
|
||||
// S @$arD, $acS.S
|
||||
// xxxx xxxx 001s s0dd
|
||||
// Store value of $acS.S in the memory pointed by register $arD.
|
||||
// Post increment register $arD.
|
||||
void DSPEmitter::s(const UDSPInstruction opc)
|
||||
{
|
||||
u8 dreg = opc & 0x3;
|
||||
u8 sreg = ((opc >> 3) & 0x3) + DSP_REG_ACL0;
|
||||
|
||||
ext_dmem_write(dreg, sreg);
|
||||
increment_addr_reg(dreg);
|
||||
}
|
||||
|
||||
// SN @$arD, $acS.S
|
||||
// xxxx xxxx 001s s1dd
|
||||
// Store value of register $acS.S in the memory pointed by register $arD.
|
||||
// Add indexing register $ixD to register $arD.
|
||||
void DSPEmitter::sn(const UDSPInstruction opc)
|
||||
{
|
||||
u8 dreg = opc & 0x3;
|
||||
u8 sreg = ((opc >> 3) & 0x3) + DSP_REG_ACL0;
|
||||
|
||||
ext_dmem_write(dreg, sreg);
|
||||
increase_addr_reg(dreg);
|
||||
}
|
||||
|
||||
// L $axD.D, @$arS
|
||||
// xxxx xxxx 01dd d0ss
|
||||
// Load $axD.D/$acD.D with value from memory pointed by register $arS.
|
||||
// Post increment register $arS.
|
||||
void DSPEmitter::l(const UDSPInstruction opc)
|
||||
{
|
||||
u8 sreg = opc & 0x3;
|
||||
u8 dreg = ((opc >> 3) & 0x7) + DSP_REG_AXL0;
|
||||
|
||||
if ((dreg >= DSP_REG_ACM0) && (g_dsp.r[DSP_REG_SR] & SR_40_MODE_BIT))
|
||||
{
|
||||
u16 val = ext_dmem_read(g_dsp.r[sreg]);
|
||||
writeToBackLog(0, dreg - DSP_REG_ACM0 + DSP_REG_ACH0, (val & 0x8000) ? 0xFFFF : 0x0000);
|
||||
writeToBackLog(1, dreg, val);
|
||||
writeToBackLog(2, dreg - DSP_REG_ACM0 + DSP_REG_ACL0, 0);
|
||||
increment_addr_reg(sreg);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeToBackLog(0, dreg, ext_dmem_read(g_dsp.r[sreg]));
|
||||
increment_addr_reg(sreg);
|
||||
}
|
||||
}
|
||||
|
||||
// LN $axD.D, @$arS
|
||||
// xxxx xxxx 01dd d0ss
|
||||
// Load $axD.D/$acD.D with value from memory pointed by register $arS.
|
||||
// Add indexing register register $ixS to register $arS.
|
||||
void DSPEmitter::ln(const UDSPInstruction opc)
|
||||
{
|
||||
u8 sreg = opc & 0x3;
|
||||
u8 dreg = ((opc >> 3) & 0x7) + DSP_REG_AXL0;
|
||||
|
||||
if ((dreg >= DSP_REG_ACM0) && (g_dsp.r[DSP_REG_SR] & SR_40_MODE_BIT))
|
||||
{
|
||||
u16 val = ext_dmem_read(g_dsp.r[sreg]);
|
||||
writeToBackLog(0, dreg - DSP_REG_ACM0 + DSP_REG_ACH0, (val & 0x8000) ? 0xFFFF : 0x0000);
|
||||
writeToBackLog(1, dreg, val);
|
||||
writeToBackLog(2, dreg - DSP_REG_ACM0 + DSP_REG_ACL0, 0);
|
||||
increase_addr_reg(sreg);
|
||||
}
|
||||
else
|
||||
{
|
||||
writeToBackLog(0, dreg, ext_dmem_read(g_dsp.r[sreg]));
|
||||
increase_addr_reg(sreg);
|
||||
}
|
||||
}
|
||||
|
||||
// LS $axD.D, $acS.m
|
||||
// xxxx xxxx 10dd 000s
|
||||
// Load register $axD.D with value from memory pointed by register
|
||||
// $ar0. Store value from register $acS.m to memory location pointed by
|
||||
// register $ar3. Increment both $ar0 and $ar3.
|
||||
void DSPEmitter::ls(const UDSPInstruction opc)
|
||||
{
|
||||
u8 sreg = (opc & 0x1) + DSP_REG_ACM0;
|
||||
u8 dreg = ((opc >> 4) & 0x3) + DSP_REG_AXL0;
|
||||
|
||||
ext_dmem_write(DSP_REG_AR3, sreg);
|
||||
|
||||
writeToBackLog(0, dreg, ext_dmem_read(g_dsp.r[DSP_REG_AR0]));
|
||||
increment_addr_reg(DSP_REG_AR3);
|
||||
increment_addr_reg(DSP_REG_AR0);
|
||||
}
|
||||
|
||||
|
||||
// LSN $axD.D, $acS.m
|
||||
// xxxx xxxx 10dd 010s
|
||||
// Load register $axD.D with value from memory pointed by register
|
||||
// $ar0. Store value from register $acS.m to memory location pointed by
|
||||
// register $ar3. Add corresponding indexing register $ix0 to addressing
|
||||
// register $ar0 and increment $ar3.
|
||||
void DSPEmitter::lsn(const UDSPInstruction opc)
|
||||
{
|
||||
u8 sreg = (opc & 0x1) + DSP_REG_ACM0;
|
||||
u8 dreg = ((opc >> 4) & 0x3) + DSP_REG_AXL0;
|
||||
|
||||
ext_dmem_write(DSP_REG_AR3, sreg);
|
||||
|
||||
writeToBackLog(0, dreg, ext_dmem_read(g_dsp.r[DSP_REG_AR0]));
|
||||
increment_addr_reg(DSP_REG_AR3);
|
||||
increase_addr_reg(DSP_REG_AR0);
|
||||
}
|
||||
|
||||
// LSM $axD.D, $acS.m
|
||||
// xxxx xxxx 10dd 100s
|
||||
// Load register $axD.D with value from memory pointed by register
|
||||
// $ar0. Store value from register $acS.m to memory location pointed by
|
||||
// register $ar3. Add corresponding indexing register $ix3 to addressing
|
||||
// register $ar3 and increment $ar0.
|
||||
void DSPEmitter::lsm(const UDSPInstruction opc)
|
||||
{
|
||||
u8 sreg = (opc & 0x1) + DSP_REG_ACM0;
|
||||
u8 dreg = ((opc >> 4) & 0x3) + DSP_REG_AXL0;
|
||||
|
||||
ext_dmem_write(DSP_REG_AR3, sreg);
|
||||
|
||||
writeToBackLog(0, dreg, ext_dmem_read(g_dsp.r[DSP_REG_AR0]));
|
||||
increase_addr_reg(DSP_REG_AR3);
|
||||
increment_addr_reg(DSP_REG_AR0);
|
||||
}
|
||||
|
||||
// LSMN $axD.D, $acS.m
|
||||
// xxxx xxxx 10dd 110s
|
||||
// Load register $axD.D with value from memory pointed by register
|
||||
// $ar0. Store value from register $acS.m to memory location pointed by
|
||||
// register $ar3. Add corresponding indexing register $ix0 to addressing
|
||||
// register $ar0 and add corresponding indexing register $ix3 to addressing
|
||||
// register $ar3.
|
||||
void DSPEmitter::lsnm(const UDSPInstruction opc)
|
||||
{
|
||||
u8 sreg = (opc & 0x1) + DSP_REG_ACM0;
|
||||
u8 dreg = ((opc >> 4) & 0x3) + DSP_REG_AXL0;
|
||||
|
||||
ext_dmem_write(DSP_REG_AR3, sreg);
|
||||
|
||||
writeToBackLog(0, dreg, ext_dmem_read(g_dsp.r[DSP_REG_AR0]));
|
||||
increase_addr_reg(DSP_REG_AR3);
|
||||
increase_addr_reg(DSP_REG_AR0);
|
||||
}
|
||||
|
||||
// SL $acS.m, $axD.D
|
||||
// xxxx xxxx 10dd 001s
|
||||
// Store value from register $acS.m to memory location pointed by register
|
||||
// $ar0. Load register $axD.D with value from memory pointed by register
|
||||
// $ar3. Increment both $ar0 and $ar3.
|
||||
void DSPEmitter::sl(const UDSPInstruction opc)
|
||||
{
|
||||
u8 sreg = (opc & 0x1) + DSP_REG_ACM0;
|
||||
u8 dreg = ((opc >> 4) & 0x3) + DSP_REG_AXL0;
|
||||
|
||||
ext_dmem_write(DSP_REG_AR0, sreg);
|
||||
|
||||
writeToBackLog(0, dreg, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
increment_addr_reg(DSP_REG_AR3);
|
||||
increment_addr_reg(DSP_REG_AR0);
|
||||
}
|
||||
|
||||
// SLN $acS.m, $axD.D
|
||||
// xxxx xxxx 10dd 011s
|
||||
// Store value from register $acS.m to memory location pointed by register
|
||||
// $ar0. Load register $axD.D with value from memory pointed by register
|
||||
// $ar3. Add corresponding indexing register $ix0 to addressing register $ar0
|
||||
// and increment $ar3.
|
||||
void DSPEmitter::sln(const UDSPInstruction opc)
|
||||
{
|
||||
u8 sreg = (opc & 0x1) + DSP_REG_ACM0;
|
||||
u8 dreg = ((opc >> 4) & 0x3) + DSP_REG_AXL0;
|
||||
|
||||
ext_dmem_write(DSP_REG_AR0, sreg);
|
||||
|
||||
writeToBackLog(0, dreg, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
increment_addr_reg(DSP_REG_AR3);
|
||||
increase_addr_reg(DSP_REG_AR0);
|
||||
}
|
||||
|
||||
// SLM $acS.m, $axD.D
|
||||
// xxxx xxxx 10dd 101s
|
||||
// Store value from register $acS.m to memory location pointed by register
|
||||
// $ar0. Load register $axD.D with value from memory pointed by register
|
||||
// $ar3. Add corresponding indexing register $ix3 to addressing register $ar3
|
||||
// and increment $ar0.
|
||||
void DSPEmitter::slm(const UDSPInstruction opc)
|
||||
{
|
||||
u8 sreg = (opc & 0x1) + DSP_REG_ACM0;
|
||||
u8 dreg = ((opc >> 4) & 0x3) + DSP_REG_AXL0;
|
||||
|
||||
ext_dmem_write(DSP_REG_AR0, sreg);
|
||||
|
||||
writeToBackLog(0, dreg, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
increase_addr_reg(DSP_REG_AR3);
|
||||
increment_addr_reg(DSP_REG_AR0);
|
||||
}
|
||||
|
||||
// SLMN $acS.m, $axD.D
|
||||
// xxxx xxxx 10dd 111s
|
||||
// Store value from register $acS.m to memory location pointed by register
|
||||
// $ar0. Load register $axD.D with value from memory pointed by register
|
||||
// $ar3. Add corresponding indexing register $ix0 to addressing register $ar0
|
||||
// and add corresponding indexing register $ix3 to addressing register $ar3.
|
||||
void DSPEmitter::slnm(const UDSPInstruction opc)
|
||||
{
|
||||
u8 sreg = (opc & 0x1) + DSP_REG_ACM0;
|
||||
u8 dreg = ((opc >> 4) & 0x3) + DSP_REG_AXL0;
|
||||
|
||||
ext_dmem_write(DSP_REG_AR0, sreg);
|
||||
|
||||
writeToBackLog(0, dreg, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
increase_addr_reg(DSP_REG_AR3);
|
||||
increase_addr_reg(DSP_REG_AR0);
|
||||
}
|
||||
|
||||
// LD $ax0.d, $ax1.r, @$arS
|
||||
// xxxx xxxx 11dr 00ss
|
||||
// example for "nx'ld $AX0.L, $AX1.L, @$AR3"
|
||||
// Loads the word pointed by AR0 to AX0.H, then loads the word pointed by AR3
|
||||
// to AX0.L. Increments AR0 and AR3. If AR0 and AR3 point into the same
|
||||
// memory page (upper 6 bits of addr are the same -> games are not doing that!)
|
||||
// then the value pointed by AR0 is loaded to BOTH AX0.H and AX0.L. If AR0
|
||||
// points into an invalid memory page (ie 0x2000), then AX0.H keeps its old
|
||||
// value. (not implemented yet) If AR3 points into an invalid memory page, then
|
||||
// AX0.L gets the same value as AX0.H. (not implemented yet)
|
||||
void DSPEmitter::ld(const UDSPInstruction opc)
|
||||
{
|
||||
u8 dreg = (opc >> 5) & 0x1;
|
||||
u8 rreg = (opc >> 4) & 0x1;
|
||||
u8 sreg = opc & 0x3;
|
||||
|
||||
if (sreg != DSP_REG_AR3) {
|
||||
writeToBackLog(0, (dreg << 1) + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[sreg]));
|
||||
|
||||
if (IsSameMemArea(g_dsp.r[sreg], g_dsp.r[DSP_REG_AR3]))
|
||||
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, ext_dmem_read(g_dsp.r[sreg]));
|
||||
else
|
||||
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
|
||||
increment_addr_reg(sreg);
|
||||
} else {
|
||||
writeToBackLog(0, rreg + DSP_REG_AXH0, ext_dmem_read(g_dsp.r[dreg]));
|
||||
|
||||
if (IsSameMemArea(g_dsp.r[dreg], g_dsp.r[DSP_REG_AR3]))
|
||||
writeToBackLog(1, rreg + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[dreg]));
|
||||
else
|
||||
writeToBackLog(1, rreg + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
|
||||
increment_addr_reg(dreg);
|
||||
}
|
||||
|
||||
increment_addr_reg(DSP_REG_AR3);
|
||||
}
|
||||
|
||||
// LDN $ax0.d, $ax1.r, @$arS
|
||||
// xxxx xxxx 11dr 01ss
|
||||
void DSPEmitter::ldn(const UDSPInstruction opc)
|
||||
{
|
||||
u8 dreg = (opc >> 5) & 0x1;
|
||||
u8 rreg = (opc >> 4) & 0x1;
|
||||
u8 sreg = opc & 0x3;
|
||||
|
||||
if (sreg != DSP_REG_AR3) {
|
||||
writeToBackLog(0, (dreg << 1) + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[sreg]));
|
||||
|
||||
if (IsSameMemArea(g_dsp.r[sreg], g_dsp.r[DSP_REG_AR3]))
|
||||
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, ext_dmem_read(g_dsp.r[sreg]));
|
||||
else
|
||||
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
|
||||
increase_addr_reg(sreg);
|
||||
} else {
|
||||
writeToBackLog(0, rreg + DSP_REG_AXH0, ext_dmem_read(g_dsp.r[dreg]));
|
||||
|
||||
if (IsSameMemArea(g_dsp.r[dreg], g_dsp.r[DSP_REG_AR3]))
|
||||
writeToBackLog(1, rreg + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[dreg]));
|
||||
else
|
||||
writeToBackLog(1, rreg + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
|
||||
increase_addr_reg(dreg);
|
||||
}
|
||||
|
||||
increment_addr_reg(DSP_REG_AR3);
|
||||
}
|
||||
|
||||
// LDM $ax0.d, $ax1.r, @$arS
|
||||
// xxxx xxxx 11dr 10ss
|
||||
void DSPEmitter::ldm(const UDSPInstruction opc)
|
||||
{
|
||||
u8 dreg = (opc >> 5) & 0x1;
|
||||
u8 rreg = (opc >> 4) & 0x1;
|
||||
u8 sreg = opc & 0x3;
|
||||
|
||||
if (sreg != DSP_REG_AR3) {
|
||||
writeToBackLog(0, (dreg << 1) + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[sreg]));
|
||||
|
||||
if (IsSameMemArea(g_dsp.r[sreg], g_dsp.r[DSP_REG_AR3]))
|
||||
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, ext_dmem_read(g_dsp.r[sreg]));
|
||||
else
|
||||
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
|
||||
increment_addr_reg(sreg);
|
||||
} else {
|
||||
writeToBackLog(0, rreg + DSP_REG_AXH0, ext_dmem_read(g_dsp.r[dreg]));
|
||||
|
||||
if (IsSameMemArea(g_dsp.r[dreg], g_dsp.r[DSP_REG_AR3]))
|
||||
writeToBackLog(1, rreg + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[dreg]));
|
||||
else
|
||||
writeToBackLog(1, rreg + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
|
||||
increment_addr_reg(dreg);
|
||||
}
|
||||
|
||||
increase_addr_reg(DSP_REG_AR3);
|
||||
}
|
||||
|
||||
// LDNM $ax0.d, $ax1.r, @$arS
|
||||
// xxxx xxxx 11dr 11ss
|
||||
void DSPEmitter::ldnm(const UDSPInstruction opc)
|
||||
{
|
||||
u8 dreg = (opc >> 5) & 0x1;
|
||||
u8 rreg = (opc >> 4) & 0x1;
|
||||
u8 sreg = opc & 0x3;
|
||||
|
||||
if (sreg != DSP_REG_AR3) {
|
||||
writeToBackLog(0, (dreg << 1) + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[sreg]));
|
||||
|
||||
if (IsSameMemArea(g_dsp.r[sreg], g_dsp.r[DSP_REG_AR3]))
|
||||
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, ext_dmem_read(g_dsp.r[sreg]));
|
||||
else
|
||||
writeToBackLog(1, (rreg << 1) + DSP_REG_AXL1, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
|
||||
increase_addr_reg(sreg);
|
||||
} else {
|
||||
writeToBackLog(0, rreg + DSP_REG_AXH0, ext_dmem_read(g_dsp.r[dreg]));
|
||||
|
||||
if (IsSameMemArea(g_dsp.r[dreg], g_dsp.r[DSP_REG_AR3]))
|
||||
writeToBackLog(1, rreg + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[dreg]));
|
||||
else
|
||||
writeToBackLog(1, rreg + DSP_REG_AXL0, ext_dmem_read(g_dsp.r[DSP_REG_AR3]));
|
||||
|
||||
increase_addr_reg(dreg);
|
||||
}
|
||||
|
||||
increase_addr_reg(DSP_REG_AR3);
|
||||
}
|
||||
|
||||
|
||||
void DSPEmitter::writeAxAcc(const UDSPInstruction opc) {
|
||||
|
||||
}
|
||||
|
||||
|
213
Source/Core/DSPCore/Src/Jit/DSPJitUtil.cpp
Normal file
213
Source/Core/DSPCore/Src/Jit/DSPJitUtil.cpp
Normal file
@ -0,0 +1,213 @@
|
||||
// Copyright (C) 2010 Dolphin Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
#ifndef _DSP_JIT_UTIL_H
|
||||
#define _DSP_JIT_UTIL_H
|
||||
|
||||
#include "../DSPMemoryMap.h"
|
||||
#include "../DSPEmitter.h"
|
||||
#include "x64Emitter.h"
|
||||
#include "ABI.h"
|
||||
|
||||
using namespace Gen;
|
||||
|
||||
// HORRIBLE UGLINESS, someone please fix.
|
||||
// See http://code.google.com/p/dolphin-emu/source/detail?r=3125
|
||||
void DSPEmitter::increment_addr_reg(int reg)
|
||||
{
|
||||
ABI_PushAllCalleeSavedRegsAndAdjustStack();
|
||||
|
||||
// u16 tmb = g_dsp.r[DSP_REG_WR0 + reg];
|
||||
MOV(16, R(EAX), M(&g_dsp.r[DSP_REG_WR0 + reg]));
|
||||
|
||||
// tmb = tmb | (tmb >> 8);
|
||||
MOV(16, R(EBX), R(EAX));
|
||||
SHR(16, R(EBX), Imm8(8));
|
||||
OR(16, R(EAX), R(EBX));
|
||||
|
||||
// tmb = tmb | (tmb >> 4);
|
||||
MOV(16, R(EBX), R(EAX));
|
||||
SHR(16, R(EBX), Imm8(4));
|
||||
OR(16, R(EAX), R(EBX));
|
||||
|
||||
// tmb = tmb | (tmb >> 2);
|
||||
MOV(16, R(EBX), R(EAX));
|
||||
SHR(16, R(EBX), Imm8(2));
|
||||
OR(16, R(EAX), R(EBX));
|
||||
|
||||
// tmb = tmb | (tmb >> 1);
|
||||
MOV(16, R(EBX), R(EAX));
|
||||
SHR(16, R(EBX), Imm8(1));
|
||||
OR(16, R(EAX), R(EBX));
|
||||
|
||||
// s16 tmp = g_dsp.r[reg];
|
||||
MOV(16, R(EBX), M(&g_dsp.r[reg]));
|
||||
|
||||
// if ((tmp & tmb) == tmb)
|
||||
AND(16, R(EAX), R(EBX));
|
||||
CMP(16, R(EAX), R(EBX));
|
||||
FixupBranch not_equal = J_CC(CC_NZ);
|
||||
|
||||
// tmp ^= g_dsp.r[DSP_REG_WR0 + reg];
|
||||
XOR(16, R(EBX), M(&g_dsp.r[DSP_REG_WR0 + reg]));
|
||||
|
||||
FixupBranch end = J();
|
||||
SetJumpTarget(not_equal);
|
||||
// tmp++;
|
||||
ADD(16, R(EBX), Imm8(1));
|
||||
|
||||
SetJumpTarget(end);
|
||||
|
||||
// g_dsp.r[reg] = tmp;
|
||||
MOV(16, M(&g_dsp.r[reg]), R(EBX));
|
||||
|
||||
ABI_PopAllCalleeSavedRegsAndAdjustStack();
|
||||
|
||||
}
|
||||
|
||||
// See http://code.google.com/p/dolphin-emu/source/detail?r=3125
|
||||
void DSPEmitter::decrement_addr_reg(int reg)
|
||||
{
|
||||
ABI_PushAllCalleeSavedRegsAndAdjustStack();
|
||||
|
||||
// s16 tmp = g_dsp.r[reg];
|
||||
MOV(16, R(EAX), M(&g_dsp.r[reg]));
|
||||
|
||||
// if ((tmp & g_dsp.r[DSP_REG_WR0 + reg]) == 0)
|
||||
MOV(16, R(EBX), R(EAX));
|
||||
AND(16, R(EBX), M(&g_dsp.r[DSP_REG_WR0 + reg]));
|
||||
CMP(16, R(EBX), Imm8(0));
|
||||
FixupBranch not_equal = J_CC(CC_NZ);
|
||||
|
||||
// tmp |= g_dsp.r[DSP_REG_WR0 + reg];
|
||||
OR(16, R(EAX), M(&g_dsp.r[DSP_REG_WR0 + reg]));
|
||||
|
||||
FixupBranch end = J();
|
||||
SetJumpTarget(not_equal);
|
||||
// tmp--;
|
||||
SUB(16, R(EAX), Imm8(1));
|
||||
|
||||
SetJumpTarget(end);
|
||||
|
||||
// g_dsp.r[reg] = tmp;
|
||||
MOV(16, M(&g_dsp.r[reg]), R(EAX));
|
||||
|
||||
ABI_PopAllCalleeSavedRegsAndAdjustStack();
|
||||
}
|
||||
|
||||
// Increase addr register according to the correspond ix register
|
||||
void DSPEmitter::increase_addr_reg(int reg)
|
||||
{
|
||||
|
||||
/*
|
||||
MOV(16, R(EAX), M(&g_dsp.r[DSP_REG_IX0 + reg]));
|
||||
|
||||
CMP(16, R(EAX), Imm16(0));
|
||||
FixupBranch end = J_CC(CC_Z);
|
||||
FixupBranch negValue = J_CC(CC_L);
|
||||
|
||||
ABI_CallFunctionC((void *)increment_addr_reg, reg);
|
||||
|
||||
FixupBranch posValue = J();
|
||||
|
||||
SetJumpTarget(negValue);
|
||||
ABI_CallFunctionC((void *)decrement_addr_reg, reg);
|
||||
|
||||
SetJumpTarget(posValue);
|
||||
SetJumpTarget(end);
|
||||
*/
|
||||
|
||||
// TODO: DO RIGHT!
|
||||
s16 value = (s16)g_dsp.r[DSP_REG_IX0 + reg];
|
||||
|
||||
if (value > 0) {
|
||||
for (int i = 0; i < value; i++) {
|
||||
increment_addr_reg(reg);
|
||||
}
|
||||
} else if (value < 0) {
|
||||
for (int i = 0; i < (int)(-value); i++) {
|
||||
decrement_addr_reg(reg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Decrease addr register according to the correspond ix register
|
||||
void DSPEmitter::decrease_addr_reg(int reg)
|
||||
{
|
||||
// TODO: DO RIGHT!
|
||||
|
||||
s16 value = (s16)g_dsp.r[DSP_REG_IX0 + reg];
|
||||
|
||||
if (value > 0) {
|
||||
for (int i = 0; i < value; i++) {
|
||||
decrement_addr_reg(reg);
|
||||
}
|
||||
} else if (value < 0) {
|
||||
for (int i = 0; i < (int)(-value); i++) {
|
||||
increment_addr_reg(reg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DSPEmitter::ext_dmem_write(u32 dest, u32 src)
|
||||
{
|
||||
|
||||
u16 addr = g_dsp.r[dest];
|
||||
u16 val = g_dsp.r[src];
|
||||
switch (addr >> 12) {
|
||||
case 0x0: // 0xxx DRAM
|
||||
g_dsp.dram[addr & DSP_DRAM_MASK] = val;
|
||||
break;
|
||||
|
||||
case 0x1: // 1xxx COEF
|
||||
ERROR_LOG(DSPLLE, "Illegal write to COEF (pc = %02x)", g_dsp.pc);
|
||||
break;
|
||||
|
||||
case 0xf: // Fxxx HW regs
|
||||
// Can ext write to ifx?
|
||||
// gdsp_ifx_write(addr, val);
|
||||
ERROR_LOG(DSPLLE, "Illegal write to ifx (pc = %02x)", g_dsp.pc);
|
||||
break;
|
||||
|
||||
default: // Unmapped/non-existing memory
|
||||
ERROR_LOG(DSPLLE, "%04x DSP ERROR: Write to UNKNOWN (%04x) memory", g_dsp.pc, addr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
u16 DSPEmitter::ext_dmem_read(u16 addr)
|
||||
{
|
||||
switch (addr >> 12) {
|
||||
case 0x0: // 0xxx DRAM
|
||||
return g_dsp.dram[addr & DSP_DRAM_MASK];
|
||||
|
||||
case 0x1: // 1xxx COEF
|
||||
NOTICE_LOG(DSPLLE, "%04x : Coef Read @ %04x", g_dsp.pc, addr);
|
||||
return g_dsp.coef[addr & DSP_COEF_MASK];
|
||||
|
||||
case 0xf: // Fxxx HW regs
|
||||
// Can ext read from ifx?
|
||||
ERROR_LOG(DSPLLE, "Illegal read from ifx (pc = %02x)", g_dsp.pc);
|
||||
// return gdsp_ifx_read(addr);
|
||||
|
||||
default: // Unmapped/non-existing memory
|
||||
ERROR_LOG(DSPLLE, "%04x DSP ERROR: Read from UNKNOWN (%04x) memory", g_dsp.pc, addr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user