gte: split arm code for pollux, generate flagless handlers
[pcsx_rearmed.git] / libpcsxcore / gte.c
index 00e7954..0acca65 100644 (file)
 
 #define gteop (psxRegs.code & 0x1ffffff)
 
+#ifndef FLAGLESS
+
 static inline s64 BOUNDS(s64 n_value, s64 n_max, int n_maxflag, s64 n_min, int n_minflag) {
        if (n_value > n_max) {
                gteFLAG |= n_maxflag;
@@ -189,6 +191,31 @@ static inline s32 LIM(s32 value, s32 max, s32 min, u32 flag) {
        return ret;
 }
 
+static inline u32 limE(u32 result) {
+       if (result > 0x1ffff) {
+               gteFLAG |= (1 << 31) | (1 << 17);
+               return 0x1ffff;
+       }
+       return result;
+}
+
+#else
+
+#define BOUNDS(a, ...) (a)
+
+static inline s32 LIM(s32 value, s32 max, s32 min, u32 flag_unused) {
+       s32 ret = value;
+       if (value > max)
+               ret = max;
+       else if (value < min)
+               ret = min;
+       return ret;
+}
+
+#define limE(a) ((a) & 0x1ffff)
+
+#endif
+
 #define A1(a) BOUNDS((a), 0x7fffffff, (1 << 30), -(s64)0x80000000, (1 << 31) | (1 << 27))
 #define A2(a) BOUNDS((a), 0x7fffffff, (1 << 29), -(s64)0x80000000, (1 << 31) | (1 << 26))
 #define A3(a) BOUNDS((a), 0x7fffffff, (1 << 28), -(s64)0x80000000, (1 << 31) | (1 << 25))
@@ -200,21 +227,15 @@ static inline s32 LIM(s32 value, s32 max, s32 min, u32 flag) {
 #define limC3(a) LIM((a), 0x00ff, 0x0000, (1 << 19))
 #define limD(a) LIM((a), 0xffff, 0x0000, (1 << 31) | (1 << 18))
 
-static inline u32 limE(u32 result) {
-       if (result > 0x1ffff) {
-               gteFLAG |= (1 << 31) | (1 << 17);
-               return 0x1ffff;
-       }
-       return result;
-}
-
 #define F(a) BOUNDS((a), 0x7fffffff, (1 << 31) | (1 << 16), -(s64)0x80000000, (1 << 31) | (1 << 15))
 #define limG1(a) LIM((a), 0x3ff, -0x400, (1 << 31) | (1 << 14))
 #define limG2(a) LIM((a), 0x3ff, -0x400, (1 << 31) | (1 << 13))
-#define limH(a) LIM((a), 0xfff, 0x000, (1 << 12))
+#define limH(a) LIM((a), 0x1000, 0x0000, (1 << 12))
 
 #include "gte_divider.h"
 
+#ifndef FLAGLESS
+
 static inline u32 MFC2(int reg) {
        switch (reg) {
                case 1:
@@ -240,9 +261,6 @@ static inline u32 MFC2(int reg) {
                        break;
 
                case 28:
-               case 30:
-                       return 0;
-
                case 29:
                        psxRegs.CP2D.r[reg] = LIM(gteIR1 >> 7, 0x1f, 0, 0) |
                                                                        (LIM(gteIR2 >> 7, 0x1f, 0, 0) << 5) |
@@ -289,8 +307,6 @@ static inline void MTC2(u32 value, int reg) {
                        }
                        break;
 
-               case 7:
-               case 29:
                case 31:
                        return;
 
@@ -348,6 +364,9 @@ void gteSWC2() {
        psxMemWrite32(_oB_, MFC2(_Rt_));
 }
 
+#endif // FLAGLESS
+
+#if 0
 #define DIVIDE DIVIDE_
 static u32 DIVIDE_(s16 n, u16 d) {
        if (n >= 0 && n < d * 2) {
@@ -357,6 +376,7 @@ static u32 DIVIDE_(s16 n, u16 d) {
        }
        return 0xffffffff;
 }
+#endif
 
 void gteRTPS() {
        int quotient;
@@ -382,8 +402,8 @@ void gteRTPS() {
        gteSX2 = limG1(F((s64)gteOFX + ((s64)gteIR1 * quotient)) >> 16);
        gteSY2 = limG2(F((s64)gteOFY + ((s64)gteIR2 * quotient)) >> 16);
 
-       gteMAC0 = F((s64)(gteDQB + ((s64)gteDQA * quotient)) >> 12);
-       gteIR0 = limH(gteMAC0);
+       gteMAC0 = F((s64)gteDQB + ((s64)gteDQA * quotient));
+       gteIR0 = limH(gteMAC0 >> 12);
 }
 
 void gteRTPT() {
@@ -412,8 +432,8 @@ void gteRTPT() {
                fSX(v) = limG1(F((s64)gteOFX + ((s64)gteIR1 * quotient)) >> 16);
                fSY(v) = limG2(F((s64)gteOFY + ((s64)gteIR2 * quotient)) >> 16);
        }
-       gteMAC0 = F((s64)(gteDQB + ((s64)gteDQA * quotient)) >> 12);
-       gteIR0 = limH(gteMAC0);
+       gteMAC0 = F((s64)gteDQB + ((s64)gteDQA * quotient));
+       gteIR0 = limH(gteMAC0 >> 12);
 }
 
 void gteMVMVA() {
@@ -483,9 +503,9 @@ void gteSQR() {
        gteMAC1 = A1((gteIR1 * gteIR1) >> shift);
        gteMAC2 = A2((gteIR2 * gteIR2) >> shift);
        gteMAC3 = A3((gteIR3 * gteIR3) >> shift);
-       gteIR1 = limB1(gteMAC1 >> shift, lm);
-       gteIR2 = limB2(gteMAC2 >> shift, lm);
-       gteIR3 = limB3(gteMAC3 >> shift, lm);
+       gteIR1 = limB1(gteMAC1, lm);
+       gteIR2 = limB2(gteMAC2, lm);
+       gteIR3 = limB3(gteMAC3, lm);
 }
 
 void gteNCCS() {