Skip to content

Commit 1c2728b

Browse files
committed
Merge branch 'master' into jit-rs
2 parents b2274e2 + b4aeed1 commit 1c2728b

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,6 +1,7 @@
11
#include "v2_compiler.h"
22

33
#include "jit_rs.h"
4+
#include <dynarec/dynarec.h>
45
#include <log.h>
56
#include <mem/n64bus.h>
67
#include <disassemble.h>
@@ -42,10 +43,11 @@ bool should_break(u32 address) {
4243
static bool v2_idle_loop_detection_enabled = true;
4344

4445
int temp_code_len = 0;
45-
source_instruction_t temp_code[TEMP_CODE_SIZE];
46+
mips_instruction_t temp_code[TEMP_CODE_SIZE];
47+
dynarec_instruction_category_t temp_code_category[TEMP_CODE_SIZE];
4648
u64 temp_code_vaddr = 0;
4749

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

5153
u64 v2_get_last_compiled_block() {
@@ -69,18 +71,18 @@ void fill_temp_code(u64 virtual_address, u32 physical_address, bool* code_mask)
6971

7072
dynarec_instruction_category_t prev_instr_category = NORMAL;
7173
if (i > 0) {
72-
prev_instr_category = temp_code[i - 1].category;
74+
prev_instr_category = temp_code_category[i - 1];
7375
}
7476

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

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

8284
bool instr_ends_block;
83-
switch (temp_code[i].category) {
85+
switch (temp_code_category[i]) {
8486
// Possible to end block
8587
case CACHE:
8688
case STORE:
@@ -134,7 +136,7 @@ void fill_temp_code(u64 virtual_address, u32 physical_address, bool* code_mask)
134136
#endif
135137

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

170-
if (temp_code_len == 2 && temp_code[1].instr.raw == 0x00000000) {
172+
if (temp_code_len == 2 && temp_code[1].raw == 0x00000000) {
171173
// b -1
172174
// nop
173-
if (temp_code[0].instr.raw == 0x1000FFFF) {
175+
if (temp_code[0].raw == 0x1000FFFF) {
174176
return true;
175177
}
176178

177179
// j (self)
178180
// nop
179-
if (temp_code[0].instr.op == OPC_J && temp_code[0].instr.j.target == ((virtual_address >> 2) & 0x3FFFFFF)) {
181+
if (temp_code[0].op == OPC_J && temp_code[0].j.target == ((virtual_address >> 2) & 0x3FFFFFF)) {
180182
return true;
181183
}
182184
}
@@ -234,7 +236,7 @@ void v2_compile_new_block(
234236
for (int i = 0; i < temp_code_len; i++) {
235237
u64 instr_virtual_address = virtual_address + (i << 2);
236238
u32 instr_physical_address = physical_address + (i << 2);
237-
emit_instruction_ir(temp_code[i].instr, i, instr_virtual_address, instr_physical_address);
239+
emit_instruction_ir(temp_code[i], i, instr_virtual_address, instr_physical_address);
238240
}
239241

240242
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)