Merge pull request #221 from xsacha/vuops-2

Improve readability in the VUops.
This commit is contained in:
Pseudonym 2014-08-15 13:33:03 +01:00
commit 2286ac1c49
1 changed files with 96 additions and 122 deletions

View File

@ -117,7 +117,6 @@ void _vuFlushAll(VURegs* VU)
if ((VU->cycle - VU->fdiv.sCycle) >= VU->fdiv.Cycle) {
VUM_LOG("flushing FDIV pipe");
nRepeat = 1;
VU->fdiv.enable = 0;
VU->VI[REG_Q].UL = VU->fdiv.reg.UL;
VU->VI[REG_STATUS_FLAG].UL = VU->fdiv.statusflag;
@ -131,7 +130,6 @@ void _vuFlushAll(VURegs* VU)
if ((VU->cycle - VU->efu.sCycle) >= VU->efu.Cycle) {
// VUM_LOG("flushing EFU pipe");
nRepeat = 1;
VU->efu.enable = 0;
VU->VI[REG_P].UL = VU->efu.reg.UL;
}
@ -160,14 +158,14 @@ static void __fastcall _vuFMACTestStall(VURegs * VU, int reg, int xyzw) {
if (i == 8) return;
cycle = VU->fmac[i].Cycle - (VU->cycle - VU->fmac[i].sCycle) + 1; // add 1 delay! (fixes segaclassics bad geom)
VU->fmac[i].enable = 0;
VU->VI[REG_MAC_FLAG].UL = VU->fmac[i].macflag;
VU->VI[REG_STATUS_FLAG].UL = VU->fmac[i].statusflag;
VU->VI[REG_CLIP_FLAG].UL = VU->fmac[i].clipflag;
VUM_LOG("FMAC[%d] stall %d", i, cycle);
u32 newCycle = VU->fmac[i].Cycle + VU->fmac[i].sCycle + 1; // HACK: add 1 delay (fixes segaclassics bad geom)
VUM_LOG("FMAC[%d] stall %d", i, newCycle - VU->cycle);
VU->cycle+= cycle;
VU->cycle = newCycle;
_vuTestPipes(VU);
}
@ -216,27 +214,25 @@ static __ri void __fastcall _vuEFUAdd(VURegs * VU, int cycles) {
static __ri void __fastcall _vuFlushFDIV(VURegs * VU) {
int cycle;
if (VU->fdiv.enable == 0) return;
if (VU->fdiv.enable == 0)
return;
cycle = VU->fdiv.Cycle - (VU->cycle - VU->fdiv.sCycle);
VUM_LOG("waiting FDIV pipe %d", cycle);
u32 newCycle = VU->fdiv.Cycle + VU->fdiv.sCycle;
VUM_LOG("waiting FDIV pipe %d", newCycle - VU->cycle);
VU->fdiv.enable = 0;
VU->cycle+= cycle;
VU->cycle = newCycle;
VU->VI[REG_Q].UL = VU->fdiv.reg.UL;
VU->VI[REG_STATUS_FLAG].UL = VU->fdiv.statusflag;
}
static __ri void __fastcall _vuFlushEFU(VURegs * VU) {
int cycle;
if (VU->efu.enable == 0) return;
cycle = VU->efu.Cycle - (VU->cycle - VU->efu.sCycle);
// VUM_LOG("waiting EFU pipe %d", cycle);
if (VU->efu.enable == 0)
return;
VU->efu.enable = 0;
VU->cycle+= cycle;
VU->cycle = VU->efu.Cycle + VU->efu.sCycle;
VU->VI[REG_P].UL = VU->efu.reg.UL;
}
@ -1180,170 +1176,148 @@ static __fi void _vuMSUBAw(VURegs * VU) {
VU_STAT_UPDATE(VU);
}/*last updated 11/05/03 shadow*/
u32 _MAX(u32 a, u32 b) {
if (a & 0x80000000) { // -a
if (b & 0x80000000) { // -b
return (a & 0x7fffffff) > (b & 0x7fffffff) ? b : a;
} else { // +b
return b;
}
} else { // +a
if (b & 0x80000000) { // -b
return a;
} else { // +b
return (a & 0x7fffffff) > (b & 0x7fffffff) ? a : b;
}
}
// The functions below are floating point semantics min/max on integer representations to get
// the effect of a floating point min/max without issues with denormal and special numbers.
return 0;
// Finds the maximum integer value unless both values are negative, in which case it finds the minimum value.
static __fi u32 fp_max(u32 a, u32 b) {
return ((s32)a < 0 && (s32)b < 0) ? std::min<s32>(a, b) : std::max<s32>(a, b);
}
// Finds the minimum integer value unless both values are negative, in which case it finds the maximum value.
static __fi u32 fp_min(u32 a, u32 b) {
return ((s32)a < 0 && (s32)b < 0) ? std::max<s32>(a, b) : std::min<s32>(a, b);
}
static __fi void _vuMAX(VURegs * VU) {
if (_Fd_ == 0) return;
if (_Fd_ == 0)
return;
/* ft is bc */
if (_X) VU->VF[_Fd_].i.x = _MAX(VU->VF[_Fs_].i.x, (s32)VU->VF[_Ft_].i.x);
if (_Y) VU->VF[_Fd_].i.y = _MAX(VU->VF[_Fs_].i.y, (s32)VU->VF[_Ft_].i.y);
if (_Z) VU->VF[_Fd_].i.z = _MAX(VU->VF[_Fs_].i.z, (s32)VU->VF[_Ft_].i.z);
if (_W) VU->VF[_Fd_].i.w = _MAX(VU->VF[_Fs_].i.w, (s32)VU->VF[_Ft_].i.w);
if (_X) VU->VF[_Fd_].i.x = fp_max(VU->VF[_Fs_].i.x, VU->VF[_Ft_].i.x);
if (_Y) VU->VF[_Fd_].i.y = fp_max(VU->VF[_Fs_].i.y, VU->VF[_Ft_].i.y);
if (_Z) VU->VF[_Fd_].i.z = fp_max(VU->VF[_Fs_].i.z, VU->VF[_Ft_].i.z);
if (_W) VU->VF[_Fd_].i.w = fp_max(VU->VF[_Fs_].i.w, VU->VF[_Ft_].i.w);
}//checked 13/05/03 shadow
static __fi void _vuMAXi(VURegs * VU) {
if (_Fd_ == 0) return;
if (_Fd_ == 0)
return;
/* ft is bc */
if (_X) VU->VF[_Fd_].i.x = _MAX(VU->VF[_Fs_].i.x, VU->VI[REG_I].UL);
if (_Y) VU->VF[_Fd_].i.y = _MAX(VU->VF[_Fs_].i.y, VU->VI[REG_I].UL);
if (_Z) VU->VF[_Fd_].i.z = _MAX(VU->VF[_Fs_].i.z, VU->VI[REG_I].UL);
if (_W) VU->VF[_Fd_].i.w = _MAX(VU->VF[_Fs_].i.w, VU->VI[REG_I].UL);
if (_X) VU->VF[_Fd_].i.x = fp_max(VU->VF[_Fs_].i.x, VU->VI[REG_I].UL);
if (_Y) VU->VF[_Fd_].i.y = fp_max(VU->VF[_Fs_].i.y, VU->VI[REG_I].UL);
if (_Z) VU->VF[_Fd_].i.z = fp_max(VU->VF[_Fs_].i.z, VU->VI[REG_I].UL);
if (_W) VU->VF[_Fd_].i.w = fp_max(VU->VF[_Fs_].i.w, VU->VI[REG_I].UL);
}//checked 13/05/03 shadow
static __fi void _vuMAXx(VURegs * VU) {
s32 ftx;
if (_Fd_ == 0) return;
if (_Fd_ == 0)
return;
ftx=(s32)VU->VF[_Ft_].i.x;
if (_X) VU->VF[_Fd_].i.x = _MAX(VU->VF[_Fs_].i.x, ftx);
if (_Y) VU->VF[_Fd_].i.y = _MAX(VU->VF[_Fs_].i.y, ftx);
if (_Z) VU->VF[_Fd_].i.z = _MAX(VU->VF[_Fs_].i.z, ftx);
if (_W) VU->VF[_Fd_].i.w = _MAX(VU->VF[_Fs_].i.w, ftx);
u32 ftx = VU->VF[_Ft_].i.x;
if (_X) VU->VF[_Fd_].i.x = fp_max(VU->VF[_Fs_].i.x, ftx);
if (_Y) VU->VF[_Fd_].i.y = fp_max(VU->VF[_Fs_].i.y, ftx);
if (_Z) VU->VF[_Fd_].i.z = fp_max(VU->VF[_Fs_].i.z, ftx);
if (_W) VU->VF[_Fd_].i.w = fp_max(VU->VF[_Fs_].i.w, ftx);
}
//checked 13/05/03 shadow
static __fi void _vuMAXy(VURegs * VU) {
s32 fty;
if (_Fd_ == 0) return;
if (_Fd_ == 0)
return;
fty=(s32)VU->VF[_Ft_].i.y;
if (_X) VU->VF[_Fd_].i.x = _MAX(VU->VF[_Fs_].i.x, fty);
if (_Y) VU->VF[_Fd_].i.y = _MAX(VU->VF[_Fs_].i.y, fty);
if (_Z) VU->VF[_Fd_].i.z = _MAX(VU->VF[_Fs_].i.z, fty);
if (_W) VU->VF[_Fd_].i.w = _MAX(VU->VF[_Fs_].i.w, fty);
u32 fty = VU->VF[_Ft_].i.y;
if (_X) VU->VF[_Fd_].i.x = fp_max(VU->VF[_Fs_].i.x, fty);
if (_Y) VU->VF[_Fd_].i.y = fp_max(VU->VF[_Fs_].i.y, fty);
if (_Z) VU->VF[_Fd_].i.z = fp_max(VU->VF[_Fs_].i.z, fty);
if (_W) VU->VF[_Fd_].i.w = fp_max(VU->VF[_Fs_].i.w, fty);
}//checked 13/05/03 shadow
static __fi void _vuMAXz(VURegs * VU) {
s32 ftz;
if (_Fd_ == 0) return;
if (_Fd_ == 0)
return;
ftz=(s32)VU->VF[_Ft_].i.z;
if (_X) VU->VF[_Fd_].i.x = _MAX(VU->VF[_Fs_].i.x, ftz);
if (_Y) VU->VF[_Fd_].i.y = _MAX(VU->VF[_Fs_].i.y, ftz);
if (_Z) VU->VF[_Fd_].i.z = _MAX(VU->VF[_Fs_].i.z, ftz);
if (_W) VU->VF[_Fd_].i.w = _MAX(VU->VF[_Fs_].i.w, ftz);
u32 ftz = VU->VF[_Ft_].i.z;
if (_X) VU->VF[_Fd_].i.x = fp_max(VU->VF[_Fs_].i.x, ftz);
if (_Y) VU->VF[_Fd_].i.y = fp_max(VU->VF[_Fs_].i.y, ftz);
if (_Z) VU->VF[_Fd_].i.z = fp_max(VU->VF[_Fs_].i.z, ftz);
if (_W) VU->VF[_Fd_].i.w = fp_max(VU->VF[_Fs_].i.w, ftz);
}
static __fi void _vuMAXw(VURegs * VU) {
s32 ftw;
if (_Fd_ == 0) return;
if (_Fd_ == 0)
return;
ftw=(s32)VU->VF[_Ft_].i.w;
if (_X) VU->VF[_Fd_].i.x = _MAX(VU->VF[_Fs_].i.x, ftw);
if (_Y) VU->VF[_Fd_].i.y = _MAX(VU->VF[_Fs_].i.y, ftw);
if (_Z) VU->VF[_Fd_].i.z = _MAX(VU->VF[_Fs_].i.z, ftw);
if (_W) VU->VF[_Fd_].i.w = _MAX(VU->VF[_Fs_].i.w, ftw);
}
u32 _MINI(u32 a, u32 b) {
if (a & 0x80000000) { // -a
if (b & 0x80000000) { // -b
return (a & 0x7fffffff) < (b & 0x7fffffff) ? b : a;
} else { // +b
return a;
}
} else { // +a
if (b & 0x80000000) { // -b
return b;
} else { // +b
return (a & 0x7fffffff) < (b & 0x7fffffff) ? a : b;
}
}
return 0;
u32 ftw = VU->VF[_Ft_].i.w;
if (_X) VU->VF[_Fd_].i.x = fp_max(VU->VF[_Fs_].i.x, ftw);
if (_Y) VU->VF[_Fd_].i.y = fp_max(VU->VF[_Fs_].i.y, ftw);
if (_Z) VU->VF[_Fd_].i.z = fp_max(VU->VF[_Fs_].i.z, ftw);
if (_W) VU->VF[_Fd_].i.w = fp_max(VU->VF[_Fs_].i.w, ftw);
}
static __fi void _vuMINI(VURegs * VU) {
if (_Fd_ == 0) return;
if (_Fd_ == 0)
return;
/* ft is bc */
if (_X) VU->VF[_Fd_].i.x = _MINI(VU->VF[_Fs_].i.x, (s32)VU->VF[_Ft_].i.x);
if (_Y) VU->VF[_Fd_].i.y = _MINI(VU->VF[_Fs_].i.y, (s32)VU->VF[_Ft_].i.y);
if (_Z) VU->VF[_Fd_].i.z = _MINI(VU->VF[_Fs_].i.z, (s32)VU->VF[_Ft_].i.z);
if (_W) VU->VF[_Fd_].i.w = _MINI(VU->VF[_Fs_].i.w, (s32)VU->VF[_Ft_].i.w);
if (_X) VU->VF[_Fd_].i.x = fp_min(VU->VF[_Fs_].i.x, VU->VF[_Ft_].i.x);
if (_Y) VU->VF[_Fd_].i.y = fp_min(VU->VF[_Fs_].i.y, VU->VF[_Ft_].i.y);
if (_Z) VU->VF[_Fd_].i.z = fp_min(VU->VF[_Fs_].i.z, VU->VF[_Ft_].i.z);
if (_W) VU->VF[_Fd_].i.w = fp_min(VU->VF[_Fs_].i.w, VU->VF[_Ft_].i.w);
}//checked 13/05/03 shadow
static __fi void _vuMINIi(VURegs * VU) {
if (_Fd_ == 0) return;
if (_Fd_ == 0)
return;
/* ft is bc */
if (_X) VU->VF[_Fd_].i.x = _MINI(VU->VF[_Fs_].i.x, VU->VI[REG_I].UL);
if (_Y) VU->VF[_Fd_].i.y = _MINI(VU->VF[_Fs_].i.y, VU->VI[REG_I].UL);
if (_Z) VU->VF[_Fd_].i.z = _MINI(VU->VF[_Fs_].i.z, VU->VI[REG_I].UL);
if (_W) VU->VF[_Fd_].i.w = _MINI(VU->VF[_Fs_].i.w, VU->VI[REG_I].UL);
if (_X) VU->VF[_Fd_].i.x = fp_min(VU->VF[_Fs_].i.x, VU->VI[REG_I].UL);
if (_Y) VU->VF[_Fd_].i.y = fp_min(VU->VF[_Fs_].i.y, VU->VI[REG_I].UL);
if (_Z) VU->VF[_Fd_].i.z = fp_min(VU->VF[_Fs_].i.z, VU->VI[REG_I].UL);
if (_W) VU->VF[_Fd_].i.w = fp_min(VU->VF[_Fs_].i.w, VU->VI[REG_I].UL);
}//checked 13/05/03 shadow
static __fi void _vuMINIx(VURegs * VU) {
s32 ftx;
if (_Fd_ == 0) return;
if (_Fd_ == 0)
return;
ftx=(s32)VU->VF[_Ft_].i.x;
if (_X) VU->VF[_Fd_].i.x = _MINI(VU->VF[_Fs_].i.x, ftx);
if (_Y) VU->VF[_Fd_].i.y = _MINI(VU->VF[_Fs_].i.y, ftx);
if (_Z) VU->VF[_Fd_].i.z = _MINI(VU->VF[_Fs_].i.z, ftx);
if (_W) VU->VF[_Fd_].i.w = _MINI(VU->VF[_Fs_].i.w, ftx);
u32 ftx = VU->VF[_Ft_].i.x;
if (_X) VU->VF[_Fd_].i.x = fp_min(VU->VF[_Fs_].i.x, ftx);
if (_Y) VU->VF[_Fd_].i.y = fp_min(VU->VF[_Fs_].i.y, ftx);
if (_Z) VU->VF[_Fd_].i.z = fp_min(VU->VF[_Fs_].i.z, ftx);
if (_W) VU->VF[_Fd_].i.w = fp_min(VU->VF[_Fs_].i.w, ftx);
}
//checked 13/05/03 shadow
static __fi void _vuMINIy(VURegs * VU) {
s32 fty;
if (_Fd_ == 0) return;
fty=(s32)VU->VF[_Ft_].i.y;
if (_X) VU->VF[_Fd_].i.x = _MINI(VU->VF[_Fs_].i.x, fty);
if (_Y) VU->VF[_Fd_].i.y = _MINI(VU->VF[_Fs_].i.y, fty);
if (_Z) VU->VF[_Fd_].i.z = _MINI(VU->VF[_Fs_].i.z, fty);
if (_W) VU->VF[_Fd_].i.w = _MINI(VU->VF[_Fs_].i.w, fty);
u32 fty = VU->VF[_Ft_].i.y;
if (_X) VU->VF[_Fd_].i.x = fp_min(VU->VF[_Fs_].i.x, fty);
if (_Y) VU->VF[_Fd_].i.y = fp_min(VU->VF[_Fs_].i.y, fty);
if (_Z) VU->VF[_Fd_].i.z = fp_min(VU->VF[_Fs_].i.z, fty);
if (_W) VU->VF[_Fd_].i.w = fp_min(VU->VF[_Fs_].i.w, fty);
}//checked 13/05/03 shadow
static __fi void _vuMINIz(VURegs * VU) {
s32 ftz;
if (_Fd_ == 0) return;
ftz=(s32)VU->VF[_Ft_].i.z;
if (_X) VU->VF[_Fd_].i.x = _MINI(VU->VF[_Fs_].i.x, ftz);
if (_Y) VU->VF[_Fd_].i.y = _MINI(VU->VF[_Fs_].i.y, ftz);
if (_Z) VU->VF[_Fd_].i.z = _MINI(VU->VF[_Fs_].i.z, ftz);
if (_W) VU->VF[_Fd_].i.w = _MINI(VU->VF[_Fs_].i.w, ftz);
u32 ftz = VU->VF[_Ft_].i.z;
if (_X) VU->VF[_Fd_].i.x = fp_min(VU->VF[_Fs_].i.x, ftz);
if (_Y) VU->VF[_Fd_].i.y = fp_min(VU->VF[_Fs_].i.y, ftz);
if (_Z) VU->VF[_Fd_].i.z = fp_min(VU->VF[_Fs_].i.z, ftz);
if (_W) VU->VF[_Fd_].i.w = fp_min(VU->VF[_Fs_].i.w, ftz);
}
static __fi void _vuMINIw(VURegs * VU) {
s32 ftw;
if (_Fd_ == 0) return;
ftw=(s32)VU->VF[_Ft_].i.w;
if (_X) VU->VF[_Fd_].i.x = _MINI(VU->VF[_Fs_].i.x, ftw);
if (_Y) VU->VF[_Fd_].i.y = _MINI(VU->VF[_Fs_].i.y, ftw);
if (_Z) VU->VF[_Fd_].i.z = _MINI(VU->VF[_Fs_].i.z, ftw);
if (_W) VU->VF[_Fd_].i.w = _MINI(VU->VF[_Fs_].i.w, ftw);
u32 ftw = VU->VF[_Ft_].i.w;
if (_X) VU->VF[_Fd_].i.x = fp_min(VU->VF[_Fs_].i.x, ftw);
if (_Y) VU->VF[_Fd_].i.y = fp_min(VU->VF[_Fs_].i.y, ftw);
if (_Z) VU->VF[_Fd_].i.z = fp_min(VU->VF[_Fs_].i.z, ftw);
if (_W) VU->VF[_Fd_].i.w = fp_min(VU->VF[_Fs_].i.w, ftw);
}
static __fi void _vuOPMULA(VURegs * VU) {