Skip to content

Commit 465d588

Browse files
committed
gpu.c gpucontrol as union
GPU_RUNNING running macro was pretty slow on ARM for some reason. Bitswise structs are faster in my testing Signed-off-by: Joseph Mattello <[email protected]>
1 parent 3f6c66a commit 465d588

1 file changed

Lines changed: 36 additions & 36 deletions

File tree

src/gpu.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ static uint32_t gpu_flags;
177177
static uint32_t gpu_matrix_control;
178178
static uint32_t gpu_pointer_to_matrix;
179179
static uint32_t gpu_data_organization;
180-
static uint32_t gpu_control;
180+
static GPUControl gpu_control;
181+
181182
static uint32_t gpu_div_control;
182183
// There is a distinct advantage to having these separated out--there's no need to clear
183184
// a bit before writing a result. I.e., if the result of an operation leaves a zero in
@@ -192,7 +193,7 @@ static uint32_t gpu_instruction;
192193
static uint32_t gpu_opcode_first_parameter;
193194
static uint32_t gpu_opcode_second_parameter;
194195

195-
#define GPU_RUNNING (gpu_control & 0x01)
196+
#define GPU_RUNNING (gpu_control.bits.b0)
196197

197198
#define RM gpu_reg[gpu_opcode_first_parameter]
198199
#define RN gpu_reg[gpu_opcode_second_parameter]
@@ -342,34 +343,33 @@ uint32_t GPUReadLong(uint32_t offset, uint32_t who/*=UNKNOWN*/)
342343
{
343344
offset &= 0x1F;
344345
switch (offset)
345-
{
346-
case 0x00:
347-
gpu_flag_c = (gpu_flag_c ? 1 : 0);
348-
gpu_flag_z = (gpu_flag_z ? 1 : 0);
349-
gpu_flag_n = (gpu_flag_n ? 1 : 0);
350-
351-
gpu_flags = (gpu_flags & 0xFFFFFFF8) | (gpu_flag_n << 2) | (gpu_flag_c << 1) | gpu_flag_z;
352-
353-
return gpu_flags & 0xFFFFC1FF;
354-
case 0x04:
355-
return gpu_matrix_control;
356-
case 0x08:
357-
return gpu_pointer_to_matrix;
358-
case 0x0C:
359-
return gpu_data_organization;
360-
case 0x10:
361-
return gpu_pc;
362-
case 0x14:
363-
return gpu_control;
364-
case 0x18:
365-
return gpu_hidata;
366-
case 0x1C:
367-
return gpu_remain;
368-
default: // unaligned long read
369-
break;
370-
}
371-
372-
return 0;
346+
{
347+
case 0x00:
348+
gpu_flag_c = (gpu_flag_c ? 1 : 0);
349+
gpu_flag_z = (gpu_flag_z ? 1 : 0);
350+
gpu_flag_n = (gpu_flag_n ? 1 : 0);
351+
352+
gpu_flags = (gpu_flags & 0xFFFFFFF8) | (gpu_flag_n << 2) | (gpu_flag_c << 1) | gpu_flag_z;
353+
354+
return gpu_flags & 0xFFFFC1FF;
355+
case 0x04:
356+
return gpu_matrix_control;
357+
case 0x08:
358+
return gpu_pointer_to_matrix;
359+
case 0x0C:
360+
return gpu_data_organization;
361+
case 0x10:
362+
return gpu_pc;
363+
case 0x14:
364+
return gpu_control.WORD;
365+
case 0x18:
366+
return gpu_hidata;
367+
case 0x1C:
368+
return gpu_remain;
369+
default: // unaligned long read
370+
break;
371+
}
372+
return 0;
373373
}
374374

375375
return (JaguarReadWord(offset, who) << 16) | JaguarReadWord(offset + 2, who);
@@ -473,7 +473,7 @@ void GPUWriteLong(uint32_t offset, uint32_t data, uint32_t who/*=UNKNOWN*/)
473473
gpu_flag_c = (gpu_flags & CARRY_FLAG) >> 1;
474474
gpu_flag_n = (gpu_flags & NEGA_FLAG) >> 2;
475475
GPUUpdateRegisterBanks();
476-
gpu_control &= ~((gpu_flags & CINT04FLAGS) >> 3); // Interrupt latch clear bits
476+
gpu_control.WORD &= ~((gpu_flags & CINT04FLAGS) >> 3); // Interrupt latch clear bits
477477
//Writing here is only an interrupt enable--this approach is just plain wrong!
478478
// GPUHandleIRQs();
479479
//This, however, is A-OK! ;-)
@@ -523,7 +523,7 @@ void GPUWriteLong(uint32_t offset, uint32_t data, uint32_t who/*=UNKNOWN*/)
523523
data &= ~0x04;
524524
}
525525

526-
gpu_control = (gpu_control & 0xF7C0) | (data & (~0xF7C0));
526+
gpu_control.WORD = (gpu_control.WORD & 0xF7C0) | (data & (~0xF7C0));
527527

528528
// if gpu wasn't running but is now running, execute a few cycles
529529
#ifdef GPU_SINGLE_STEPPING
@@ -579,7 +579,7 @@ void GPUHandleIRQs(void)
579579
return;
580580

581581
// Get the interrupt latch & enable bits
582-
bits = (gpu_control >> 6) & 0x1F;
582+
bits = gpu_control.gpuIRQ.irqMask; //(gpu_control >> 6) & 0x1F;
583583
mask = (gpu_flags >> 4) & 0x1F;
584584

585585
// Bail out if latched interrupts aren't enabled
@@ -618,11 +618,11 @@ void GPUHandleIRQs(void)
618618
void GPUSetIRQLine(int irqline, int state)
619619
{
620620
uint32_t mask = 0x0040 << irqline;
621-
gpu_control &= ~mask; // Clear the interrupt latch
621+
gpu_control.WORD &= ~mask; // Clear the interrupt latch
622622

623623
if (state)
624624
{
625-
gpu_control |= mask; // Assert the interrupt latch
625+
gpu_control.WORD |= mask; // Assert the interrupt latch
626626
GPUHandleIRQs(); // And handle the interrupt...
627627
}
628628
}
@@ -644,7 +644,7 @@ void GPUReset(void)
644644
gpu_pointer_to_matrix = 0x00000000;
645645
gpu_data_organization = 0xFFFFFFFF;
646646
gpu_pc = 0x00F03000;
647-
gpu_control = 0x00002800; // Correctly sets this as TOM Rev. 2
647+
gpu_control.WORD = 0x00002800; // Correctly sets this as TOM Rev. 2
648648
gpu_hidata = 0x00000000;
649649
gpu_remain = 0x00000000; // These two registers are RO/WO
650650
gpu_div_control = 0x00000000;

0 commit comments

Comments
 (0)