X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=deps%2Flightrec%2Flightrec.c;h=1cfc4274902b8c3d93d1f1cf6106db8d6cbf3fc9;hb=bff52357698a47cef2e6deb91a6c004eb6efe2bc;hp=5cf459837d63edbf2399e16f84faa1b4a55d474f;hpb=f5ee77cadf78d389ce40f00988ee9bde1d567dc7;p=pcsx_rearmed.git diff --git a/deps/lightrec/lightrec.c b/deps/lightrec/lightrec.c index 5cf45983..1cfc4274 100644 --- a/deps/lightrec/lightrec.c +++ b/deps/lightrec/lightrec.c @@ -35,19 +35,21 @@ static bool lightrec_block_is_fully_tagged(const struct block *block); static void lightrec_mtc2(struct lightrec_state *state, u8 reg, u32 data); static u32 lightrec_mfc2(struct lightrec_state *state, u8 reg); +static void lightrec_reap_block(struct lightrec_state *state, void *data); + static void lightrec_default_sb(struct lightrec_state *state, u32 opcode, - void *host, u32 addr, u8 data) + void *host, u32 addr, u32 data) { - *(u8 *)host = data; + *(u8 *)host = (u8)data; if (!(state->opt_flags & LIGHTREC_OPT_INV_DMA_ONLY)) lightrec_invalidate(state, addr, 1); } static void lightrec_default_sh(struct lightrec_state *state, u32 opcode, - void *host, u32 addr, u16 data) + void *host, u32 addr, u32 data) { - *(u16 *)host = HTOLE16(data); + *(u16 *)host = HTOLE16((u16)data); if (!(state->opt_flags & LIGHTREC_OPT_INV_DMA_ONLY)) lightrec_invalidate(state, addr, 2); @@ -80,6 +82,27 @@ static u32 lightrec_default_lw(struct lightrec_state *state, return LE32TOH(*(u32 *)host); } +static u32 lightrec_default_lwu(struct lightrec_state *state, + u32 opcode, void *host, u32 addr) +{ + u32 val; + + memcpy(&val, host, 4); + + return LE32TOH(val); +} + +static void lightrec_default_swu(struct lightrec_state *state, u32 opcode, + void *host, u32 addr, u32 data) +{ + data = HTOLE32(data); + + memcpy(host, &data, 4); + + if (!(state->opt_flags & LIGHTREC_OPT_INV_DMA_ONLY)) + lightrec_invalidate(state, addr & ~0x3, 8); +} + static const struct lightrec_mem_map_ops lightrec_default_ops = { .sb = lightrec_default_sb, .sh = lightrec_default_sh, @@ -87,6 +110,8 @@ static const struct lightrec_mem_map_ops lightrec_default_ops = { .lb = lightrec_default_lb, .lh = lightrec_default_lh, .lw = lightrec_default_lw, + .lwu = lightrec_default_lwu, + .swu = lightrec_default_swu, }; static void __segfault_cb(struct lightrec_state *state, u32 addr, @@ -299,10 +324,10 @@ u32 lightrec_rw(struct lightrec_state *state, union code op, u32 base, switch (op.i.op) { case OP_SB: - ops->sb(state, opcode, host, addr, (u8) data); + ops->sb(state, opcode, host, addr, data); return 0; case OP_SH: - ops->sh(state, opcode, host, addr, (u16) data); + ops->sh(state, opcode, host, addr, data); return 0; case OP_SWL: lightrec_swl(state, ops, opcode, host, addr, data); @@ -331,6 +356,11 @@ u32 lightrec_rw(struct lightrec_state *state, union code op, u32 base, return lightrec_lwl(state, ops, opcode, host, addr, data); case OP_LWR: return lightrec_lwr(state, ops, opcode, host, addr, data); + case OP_META_LWU: + return ops->lwu(state, opcode, host, addr); + case OP_META_SWU: + ops->swu(state, opcode, host, addr, data); + return 0; case OP_LW: default: return ops->lw(state, opcode, host, addr); @@ -352,6 +382,7 @@ static void lightrec_rw_helper(struct lightrec_state *state, case OP_LWL: case OP_LWR: case OP_LW: + case OP_META_LWU: if (OPT_HANDLE_LOAD_DELAYS && unlikely(!state->in_delay_slot_n)) { state->temp_reg = ret; state->in_delay_slot_n = 0xff; @@ -674,9 +705,15 @@ static struct block * lightrec_get_block(struct lightrec_state *state, u32 pc) if (ENABLE_THREADED_COMPILER) lightrec_recompiler_remove(state->rec, block); - lightrec_unregister_block(state->block_cache, block); remove_from_code_lut(state->block_cache, block); - lightrec_free_block(state, block); + + if (ENABLE_THREADED_COMPILER) { + lightrec_reaper_add(state->reaper, + lightrec_reap_block, block); + } else { + lightrec_unregister_block(state->block_cache, block); + lightrec_free_block(state, block); + } } block = NULL; @@ -1482,6 +1519,8 @@ static bool lightrec_block_is_fully_tagged(const struct block *block) case OP_SWR: case OP_LWC2: case OP_SWC2: + case OP_META_LWU: + case OP_META_SWU: if (!LIGHTREC_FLAGS_GET_IO_MODE(op->flags)) return false; fallthrough; @@ -1528,6 +1567,8 @@ static void lightrec_reap_opcode_list(struct lightrec_state *state, void *data) int lightrec_compile_block(struct lightrec_cstate *cstate, struct block *block) { + struct block *dead_blocks[ARRAY_SIZE(cstate->targets)]; + u32 was_dead[ARRAY_SIZE(cstate->targets) / 8]; struct lightrec_state *state = cstate->state; struct lightrec_branch_target *target; bool fully_tagged = false; @@ -1646,11 +1687,8 @@ int lightrec_compile_block(struct lightrec_cstate *cstate, /* Add compiled function to the LUT */ lut_write(state, lut_offset(block->pc), block->function); - if (ENABLE_THREADED_COMPILER) - lightrec_reaper_continue(state->reaper); - /* Detect old blocks that have been covered by the new one */ - for (i = 0; i < cstate->nb_targets; i++) { + for (i = 0; ENABLE_THREADED_COMPILER && i < cstate->nb_targets; i++) { target = &cstate->targets[i]; if (!target->offset) @@ -1658,12 +1696,6 @@ int lightrec_compile_block(struct lightrec_cstate *cstate, offset = block->pc + target->offset * sizeof(u32); - /* Pause the reaper while we search for the block until we set - * the BLOCK_IS_DEAD flag, otherwise the block may be removed - * under our feet. */ - if (ENABLE_THREADED_COMPILER) - lightrec_reaper_pause(state->reaper); - block2 = lightrec_find_block(state->block_cache, offset); if (block2) { /* No need to check if block2 is compilable - it must @@ -1672,17 +1704,26 @@ int lightrec_compile_block(struct lightrec_cstate *cstate, /* Set the "block dead" flag to prevent the dynarec from * recompiling this block */ old_flags = block_set_flags(block2, BLOCK_IS_DEAD); + + if (old_flags & BLOCK_IS_DEAD) + was_dead[i / 32] |= BIT(i % 32); + else + was_dead[i / 32] &= ~BIT(i % 32); } - if (ENABLE_THREADED_COMPILER) { - lightrec_reaper_continue(state->reaper); + dead_blocks[i] = block2; - /* If block2 was pending for compilation, cancel it. - * If it's being compiled right now, wait until it - * finishes. */ - if (block2) - lightrec_recompiler_remove(state->rec, block2); - } + /* If block2 was pending for compilation, cancel it. + * If it's being compiled right now, wait until it finishes. */ + if (block2) + lightrec_recompiler_remove(state->rec, block2); + } + + for (i = 0; i < cstate->nb_targets; i++) { + target = &cstate->targets[i]; + + if (!target->offset) + continue; /* We know from now on that block2 (if present) isn't going to * be compiled. We can override the LUT entry with our new @@ -1690,6 +1731,12 @@ int lightrec_compile_block(struct lightrec_cstate *cstate, offset = lut_offset(block->pc) + target->offset; lut_write(state, offset, jit_address(target->label)); + if (ENABLE_THREADED_COMPILER) { + block2 = dead_blocks[i]; + } else { + offset = block->pc + target->offset * sizeof(u32); + block2 = lightrec_find_block(state->block_cache, offset); + } if (block2) { pr_debug("Reap block 0x%08x as it's covered by block " "0x%08x\n", block2->pc, block->pc); @@ -1698,7 +1745,7 @@ int lightrec_compile_block(struct lightrec_cstate *cstate, if (!ENABLE_THREADED_COMPILER) { lightrec_unregister_block(state->block_cache, block2); lightrec_free_block(state, block2); - } else if (!(old_flags & BLOCK_IS_DEAD)) { + } else if (!(was_dead[i / 32] & BIT(i % 32))) { lightrec_reaper_add(state->reaper, lightrec_reap_block, block2); @@ -1706,6 +1753,9 @@ int lightrec_compile_block(struct lightrec_cstate *cstate, } } + if (ENABLE_THREADED_COMPILER) + lightrec_reaper_continue(state->reaper); + if (ENABLE_DISASSEMBLER) { pr_debug("Compiling block at PC: 0x%08x\n", block->pc); jit_disassemble(); @@ -1910,7 +1960,7 @@ struct lightrec_state * lightrec_init(char *argv0, else lut_size = CODE_LUT_SIZE * sizeof(void *); - init_jit(argv0); + init_jit_with_debug(argv0, stdout); state = calloc(1, sizeof(*state) + lut_size); if (!state)