From 13b02197fcb7575646408094d5583ed7391b1153 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 19 Oct 2022 18:24:29 +0100 Subject: [PATCH] git subrepo pull --force deps/lightrec subrepo: subdir: "deps/lightrec" merged: "782c220e5d" upstream: origin: "https://github.com/pcercuei/lightrec.git" branch: "master" commit: "782c220e5d" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" --- deps/lightrec/.gitrepo | 4 ++-- deps/lightrec/emitter.c | 30 +++++++++++++++++------------- deps/lightrec/emitter.h | 4 ++-- deps/lightrec/lightrec-private.h | 13 +++++++++++-- deps/lightrec/lightrec.c | 9 +++------ deps/lightrec/optimizer.c | 2 +- 6 files changed, 36 insertions(+), 26 deletions(-) diff --git a/deps/lightrec/.gitrepo b/deps/lightrec/.gitrepo index 3db9689b..ceb8643a 100644 --- a/deps/lightrec/.gitrepo +++ b/deps/lightrec/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/pcercuei/lightrec.git branch = master - commit = 75374fa374a367c85f5cac6c1b9fc2c583298d42 - parent = 22a3b99d24fada1c7a5e7ab4458c132a0c387d50 + commit = 782c220e5dd9bdf179415a4d058823ff439254b8 + parent = 5ced3945423cda0010597b27b7da6bce77b12baa method = merge cmdver = 0.4.3 diff --git a/deps/lightrec/emitter.c b/deps/lightrec/emitter.c index 270fd48a..3f7da585 100644 --- a/deps/lightrec/emitter.c +++ b/deps/lightrec/emitter.c @@ -87,21 +87,16 @@ static void lightrec_emit_end_of_block(struct lightrec_cstate *state, lightrec_jump_to_eob(state, _jit); } -void lightrec_emit_eob(struct lightrec_cstate *state, const struct block *block, - u16 offset, bool after_op) +void lightrec_emit_eob(struct lightrec_cstate *state, + const struct block *block, u16 offset) { struct regcache *reg_cache = state->reg_cache; jit_state_t *_jit = block->_jit; - union code c = block->opcode_list[offset].c; - u32 cycles = state->cycles; - - if (after_op) - cycles += lightrec_cycles_of_opcode(c); lightrec_clean_regs(reg_cache, _jit); jit_movi(JIT_V0, block->pc + (offset << 2)); - jit_subi(LIGHTREC_REG_CYCLE, LIGHTREC_REG_CYCLE, cycles); + jit_subi(LIGHTREC_REG_CYCLE, LIGHTREC_REG_CYCLE, state->cycles); lightrec_jump_to_eob(state, _jit); } @@ -250,7 +245,7 @@ static void rec_b(struct lightrec_cstate *state, const struct block *block, u16 if (op_flag_local_branch(op->flags)) { /* Recompile the delay slot */ - if (next && next->opcode && !op_flag_no_ds(op->flags)) + if (!op_flag_no_ds(op->flags) && next->opcode) lightrec_rec_opcode(state, block, offset + 1); if (link) { @@ -1127,6 +1122,13 @@ static u32 rec_ram_mask(struct lightrec_state *state) return (RAM_SIZE << (state->mirrors_mapped * 2)) - 1; } +static u32 rec_io_mask(const struct lightrec_state *state) +{ + u32 length = state->maps[PSX_MAP_HW_REGISTERS].length; + + return GENMASK(31 - clz32(length - 1), 0); +} + static void rec_store_memory(struct lightrec_cstate *cstate, const struct block *block, u16 offset, jit_code_t code, @@ -1258,7 +1260,7 @@ static void rec_store_io(struct lightrec_cstate *cstate, return rec_store_memory(cstate, block, offset, code, swap_code, cstate->state->offset_io, - 0x1fffffff, false); + rec_io_mask(cstate->state), false); } static void rec_store_direct_no_invalidate(struct lightrec_cstate *cstate, @@ -1582,7 +1584,7 @@ static void rec_load_io(struct lightrec_cstate *cstate, _jit_note(block->_jit, __FILE__, __LINE__); rec_load_memory(cstate, block, offset, code, swap_code, is_unsigned, - cstate->state->offset_io, 0x1fffffff); + cstate->state->offset_io, rec_io_mask(cstate->state)); } static void rec_load_direct(struct lightrec_cstate *cstate, @@ -1966,8 +1968,10 @@ rec_mtc0(struct lightrec_cstate *state, const struct block *block, u16 offset) lightrec_free_reg(reg_cache, rt); if (!op_flag_no_ds(block->opcode_list[offset].flags) && - (c.r.rd == 12 || c.r.rd == 13)) - lightrec_emit_eob(state, block, offset + 1, true); + (c.r.rd == 12 || c.r.rd == 13)) { + state->cycles += lightrec_cycles_of_opcode(c); + lightrec_emit_eob(state, block, offset + 1); + } } static void rec_cp0_MFC0(struct lightrec_cstate *state, diff --git a/deps/lightrec/emitter.h b/deps/lightrec/emitter.h index b7f54fd9..4cbe8da6 100644 --- a/deps/lightrec/emitter.h +++ b/deps/lightrec/emitter.h @@ -13,7 +13,7 @@ struct lightrec_cstate; struct opcode; void lightrec_rec_opcode(struct lightrec_cstate *state, const struct block *block, u16 offset); -void lightrec_emit_eob(struct lightrec_cstate *state, const struct block *block, - u16 offset, _Bool after_op); +void lightrec_emit_eob(struct lightrec_cstate *state, + const struct block *block, u16 offset); #endif /* __EMITTER_H__ */ diff --git a/deps/lightrec/lightrec-private.h b/deps/lightrec/lightrec-private.h index 6b6f7217..56032f50 100644 --- a/deps/lightrec/lightrec-private.h +++ b/deps/lightrec/lightrec-private.h @@ -16,8 +16,15 @@ #include #endif +#ifdef _MSC_BUILD +#include +#endif + #define ARRAY_SIZE(x) (sizeof(x) ? sizeof(x) / sizeof((x)[0]) : 0) +#define GENMASK(h, l) \ + (((uintptr_t)-1 << (l)) & ((uintptr_t)-1 >> (__WORDSIZE - 1 - (h)))) + #ifdef __GNUC__ # define likely(x) __builtin_expect(!!(x),1) # define unlikely(x) __builtin_expect(!!(x),0) @@ -51,10 +58,12 @@ #ifdef _MSC_BUILD # define popcount32(x) __popcnt(x) -# define ffs32(x) (31 - __lzcnt(x)) +# define clz32(x) _lzcnt_u32(x) +# define ctz32(x) _tzcnt_u32(x) #else # define popcount32(x) __builtin_popcount(x) -# define ffs32(x) (__builtin_ffs(x) - 1) +# define clz32(x) __builtin_clz(x) +# define ctz32(x) __builtin_ctz(x) #endif /* Flags for (struct block *)->flags */ diff --git a/deps/lightrec/lightrec.c b/deps/lightrec/lightrec.c index 43636b2a..be4da10f 100644 --- a/deps/lightrec/lightrec.c +++ b/deps/lightrec/lightrec.c @@ -28,9 +28,6 @@ #include #include -#define GENMASK(h, l) \ - (((uintptr_t)-1 << (l)) & ((uintptr_t)-1 >> (__WORDSIZE - 1 - (h)))) - static struct block * lightrec_precompile_block(struct lightrec_state *state, u32 pc); static bool lightrec_block_is_fully_tagged(const struct block *block); @@ -107,7 +104,7 @@ static void lightrec_swl(struct lightrec_state *state, u32 opcode, void *host, u32 addr, u32 data) { unsigned int shift = addr & 0x3; - unsigned int mask = GENMASK(31, (shift + 1) * 8); + unsigned int mask = shift < 3 ? GENMASK(31, (shift + 1) * 8) : 0; u32 old_data; /* Align to 32 bits */ @@ -171,7 +168,7 @@ static u32 lightrec_lwr(struct lightrec_state *state, u32 opcode, void *host, u32 addr, u32 data) { unsigned int shift = addr & 0x3; - unsigned int mask = GENMASK(31, 32 - shift * 8); + unsigned int mask = shift ? GENMASK(31, 32 - shift * 8) : 0; u32 old_data; /* Align to 32 bits */ @@ -1423,7 +1420,7 @@ int lightrec_compile_block(struct lightrec_cstate *cstate, pr_debug("Branch at offset 0x%x will be emulated\n", i << 2); - lightrec_emit_eob(cstate, block, i, false); + lightrec_emit_eob(cstate, block, i); skip_next = !op_flag_no_ds(elm->flags); } else { lightrec_rec_opcode(cstate, block, i); diff --git a/deps/lightrec/optimizer.c b/deps/lightrec/optimizer.c index 3e94cff3..10067a7d 100644 --- a/deps/lightrec/optimizer.c +++ b/deps/lightrec/optimizer.c @@ -1112,7 +1112,7 @@ static int lightrec_transform_ops(struct lightrec_state *state, struct block *bl else op->i.op = OP_META_MULTU2; - op->r.op = ffs32(values[op->r.rt]); + op->r.op = ctz32(values[op->r.rt]); break; case OP_SPECIAL_OR: case OP_SPECIAL_ADD: -- 2.39.5