Skip to content

Commit 84a0808

Browse files
committed
gpu.c gpu_opcode_div use structs
Signed-off-by: Joseph Mattello <[email protected]>
1 parent 84f36d8 commit 84a0808

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

src/gpu.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,30 +1573,35 @@ INLINE static void gpu_opcode_abs(void)
15731573

15741574
INLINE static void gpu_opcode_div(void) // RN / RM
15751575
{
1576+
15761577
unsigned i;
15771578
// Real algorithm, courtesy of SCPCD: NYAN!
1578-
uint32_t q = RN;
1579-
uint32_t r = 0;
1579+
Bits32 q;
1580+
q.WORD = RN;
1581+
1582+
Bits32 r;
1583+
r.WORD = 0;
15801584

15811585
// If 16.16 division, stuff top 16 bits of RN into remainder and put the
15821586
// bottom 16 of RN in top 16 of quotient
1583-
if (gpu_div_control & 0x01)
1584-
q <<= 16, r = RN >> 16;
1587+
if (gpu_div_control & 0x01) {
1588+
r.WORD = q.words.UWORD;
1589+
q.words.UWORD = q.words.LWORD;
1590+
q.words.LWORD = 0;
1591+
}
15851592

15861593
for(i=0; i<32; i++)
15871594
{
1588-
uint32_t sign = r & 0x80000000;
1589-
r = (r << 1) | ((q >> 31) & 0x01);
1590-
r += (sign ? RM : -RM);
1591-
q = (q << 1) | (((~r) >> 31) & 0x01);
1595+
uint32_t sign = r.bits.b31;
1596+
r.WORD = (r.WORD << 1) | q.bits.b31;
1597+
r.WORD += (sign ? RM : -RM);
1598+
q.WORD = (q.WORD << 1) | !r.bits.b31; // (((~r) >> 31) & 0x01);
15921599
}
15931600

1594-
RN = q;
1595-
gpu_remain = r;
1596-
1601+
RN = q.WORD;
1602+
gpu_remain = r.WORD;
15971603
}
15981604

1599-
16001605
INLINE static void gpu_opcode_imultn(void)
16011606
{
16021607
uint32_t res = (int32_t)((int16_t)RN * (int16_t)RM);

0 commit comments

Comments
 (0)