Skip to content

Commit b4aeed1

Browse files
committed
split temp_code into two arrays
1 parent c1fb56b commit b4aeed1

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

src/cpu/dynarec/v2/v2_compiler.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "v2_compiler.h"
22

3+
#include <dynarec/dynarec.h>
34
#include <log.h>
45
#include <mem/n64bus.h>
56
#include <disassemble.h>
@@ -41,10 +42,11 @@ bool should_break(u32 address) {
4142
static bool v2_idle_loop_detection_enabled = true;
4243

4344
int temp_code_len = 0;
44-
source_instruction_t temp_code[TEMP_CODE_SIZE];
45+
mips_instruction_t temp_code[TEMP_CODE_SIZE];
46+
dynarec_instruction_category_t temp_code_category[TEMP_CODE_SIZE];
4547
u64 temp_code_vaddr = 0;
4648

47-
#define LAST_INSTR_CATEGORY (temp_code[temp_code_len - 1].category)
49+
#define LAST_INSTR_CATEGORY (temp_code_category[temp_code_len - 1])
4850
#define LAST_INSTR_IS_BRANCH ((temp_code_len > 0) && ((LAST_INSTR_CATEGORY == BRANCH) || (LAST_INSTR_CATEGORY == BRANCH_LIKELY)))
4951

5052
u64 v2_get_last_compiled_block() {
@@ -68,18 +70,18 @@ void fill_temp_code(u64 virtual_address, u32 physical_address, bool* code_mask)
6870

6971
dynarec_instruction_category_t prev_instr_category = NORMAL;
7072
if (i > 0) {
71-
prev_instr_category = temp_code[i - 1].category;
73+
prev_instr_category = temp_code_category[i - 1];
7274
}
7375

7476
code_mask[BLOCKCACHE_INNER_INDEX(instr_address)] = true;
7577

76-
temp_code[i].instr.raw = n64_read_physical_word(instr_address);
77-
temp_code[i].category = instr_category(temp_code[i].instr);
78+
temp_code[i].raw = n64_read_physical_word(instr_address);
79+
temp_code_category[i] = instr_category(temp_code[i]);
7880
temp_code_len++;
7981
instructions_left_in_block--;
8082

8183
bool instr_ends_block;
82-
switch (temp_code[i].category) {
84+
switch (temp_code_category[i]) {
8385
// Possible to end block
8486
case CACHE:
8587
case STORE:
@@ -133,7 +135,7 @@ void fill_temp_code(u64 virtual_address, u32 physical_address, bool* code_mask)
133135
#endif
134136

135137
// If we filled up the buffer, make sure the last instruction is not a branch
136-
if (temp_code_len == TEMP_CODE_SIZE && is_branch(temp_code[TEMP_CODE_SIZE - 1].category)) {
138+
if (temp_code_len == TEMP_CODE_SIZE && is_branch(temp_code_category[TEMP_CODE_SIZE - 1])) {
137139
logwarn("Filled temp_code buffer, but the last instruction was a branch. Stripping it out.");
138140
temp_code_len--;
139141
}
@@ -166,16 +168,16 @@ bool detect_idle_loop(u64 virtual_address) {
166168
return false;
167169
}
168170

169-
if (temp_code_len == 2 && temp_code[1].instr.raw == 0x00000000) {
171+
if (temp_code_len == 2 && temp_code[1].raw == 0x00000000) {
170172
// b -1
171173
// nop
172-
if (temp_code[0].instr.raw == 0x1000FFFF) {
174+
if (temp_code[0].raw == 0x1000FFFF) {
173175
return true;
174176
}
175177

176178
// j (self)
177179
// nop
178-
if (temp_code[0].instr.op == OPC_J && temp_code[0].instr.j.target == ((virtual_address >> 2) & 0x3FFFFFF)) {
180+
if (temp_code[0].op == OPC_J && temp_code[0].j.target == ((virtual_address >> 2) & 0x3FFFFFF)) {
179181
return true;
180182
}
181183
}
@@ -224,7 +226,7 @@ void v2_compile_new_block(
224226
for (int i = 0; i < temp_code_len; i++) {
225227
u64 instr_virtual_address = virtual_address + (i << 2);
226228
u32 instr_physical_address = physical_address + (i << 2);
227-
emit_instruction_ir(temp_code[i].instr, i, instr_virtual_address, instr_physical_address);
229+
emit_instruction_ir(temp_code[i], i, instr_virtual_address, instr_physical_address);
228230
}
229231

230232
if (!ir_context.block_end_pc_ir_emitted && temp_code_len > 0) {

src/cpu/dynarec/v2/v2_compiler.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ INLINE bool is_memory(u64 address) {
77
return false; // TODO
88
}
99

10-
typedef struct source_instruction {
11-
mips_instruction_t instr;
12-
dynarec_instruction_category_t category;
13-
} source_instruction_t;
14-
1510
// Extra slot for the edge case where the branch delay slot is in the next page
1611
#define TEMP_CODE_SIZE (BLOCKCACHE_INNER_SIZE + 1)
1712
#define MAX_BLOCK_LENGTH BLOCKCACHE_INNER_SIZE
1813

1914
extern int temp_code_len;
2015
extern u64 temp_code_vaddr;
21-
extern source_instruction_t temp_code[TEMP_CODE_SIZE];
16+
extern mips_instruction_t temp_code[TEMP_CODE_SIZE];
17+
extern dynarec_instruction_category_t temp_code_category[TEMP_CODE_SIZE];
2218

2319
bool should_break(u32 address);
2420
u64 resolve_virtual_address_for_jit(u64 virtual, u64 except_pc, bus_access_t bus_access);

src/cpu/dynarec/v2/v2_compiler_x64.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void compile_ir_tlb_lookup(dasm_State** Dst, ir_instruction_t* instr) {
241241
if (instr->block_length <= 0) {
242242
logfatal("TLB lookup compiled with a block length of %d", instr->block_length);
243243
}
244-
bool prev_branch = instr->block_length > 1 && (temp_code[instr->block_length - 2].category == BRANCH || temp_code[instr->block_length - 2].category == BRANCH_LIKELY);
244+
bool prev_branch = instr->block_length > 1 && (temp_code_category[instr->block_length - 2] == BRANCH || temp_code_category[instr->block_length - 2] == BRANCH_LIKELY);
245245
static_assert(sizeof(N64CPU.prev_branch) == 1, "prev_branch should be one byte");
246246

247247
ir_set_constant_t prev_branch_const = { .type = VALUE_TYPE_U8, .value_u8 = prev_branch };

0 commit comments

Comments
 (0)