X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=deps%2Flightrec%2Flightrec-private.h;h=12e953a2d9bbe6e7e930c177a46e9a212431ebf0;hb=cb72ea130a5ef1b2f47691ed586ad48bb0c39269;hp=3c043d5e93b7327d86c83a29fe4fe68824c46e2c;hpb=0b8caa417c2bef660d6a0c70cbab71f1e997023b;p=pcsx_rearmed.git diff --git a/deps/lightrec/lightrec-private.h b/deps/lightrec/lightrec-private.h index 3c043d5e..12e953a2 100644 --- a/deps/lightrec/lightrec-private.h +++ b/deps/lightrec/lightrec-private.h @@ -10,13 +10,21 @@ #include "lightrec-config.h" #include "disassembler.h" #include "lightrec.h" +#include "regcache.h" #if ENABLE_THREADED_COMPILER #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) @@ -45,12 +53,26 @@ #define fallthrough do {} while (0) /* fall-through */ +#define container_of(ptr, type, member) \ + ((type *)((void *)(ptr) - offsetof(type, member))) + +#ifdef _MSC_BUILD +# define popcount32(x) __popcnt(x) +# define clz32(x) _lzcnt_u32(x) +# define ctz32(x) _tzcnt_u32(x) +#else +# define popcount32(x) __builtin_popcount(x) +# define clz32(x) __builtin_clz(x) +# define ctz32(x) __builtin_ctz(x) +#endif + /* Flags for (struct block *)->flags */ #define BLOCK_NEVER_COMPILE BIT(0) #define BLOCK_SHOULD_RECOMPILE BIT(1) #define BLOCK_FULLY_TAGGED BIT(2) #define BLOCK_IS_DEAD BIT(3) #define BLOCK_IS_MEMSET BIT(4) +#define BLOCK_NO_OPCODE_LIST BIT(5) #define RAM_SIZE 0x200000 #define BIOS_SIZE 0x80000 @@ -59,6 +81,7 @@ #define REG_LO 32 #define REG_HI 33 +#define REG_TEMP (offsetof(struct lightrec_state, temp_reg) / sizeof(u32)) /* Definition of jit_state_t (avoids inclusion of ) */ struct jit_node; @@ -90,9 +113,10 @@ struct block { u32 precompile_date; unsigned int code_size; u16 nb_ops; - u8 flags; #if ENABLE_THREADED_COMPILER - atomic_flag op_list_freed; + _Atomic u8 flags; +#else + u8 flags; #endif }; @@ -109,35 +133,36 @@ struct lightrec_branch_target { enum c_wrappers { C_WRAPPER_RW, C_WRAPPER_RW_GENERIC, + C_WRAPPER_MFC, C_WRAPPER_MTC, C_WRAPPER_CP, - C_WRAPPER_SYSCALL, - C_WRAPPER_BREAK, C_WRAPPERS_COUNT, }; struct lightrec_cstate { struct lightrec_state *state; - struct jit_node *branches[512]; struct lightrec_branch local_branches[512]; struct lightrec_branch_target targets[512]; - unsigned int nb_branches; unsigned int nb_local_branches; unsigned int nb_targets; unsigned int cycles; struct regcache *reg_cache; + + _Bool no_load_delay; }; struct lightrec_state { struct lightrec_registers regs; + u32 temp_reg; u32 next_pc; + uintptr_t wrapper_regs[NUM_TEMPS]; + u8 in_delay_slot_n; u32 current_cycle; u32 target_cycle; u32 exit_flags; u32 old_cycle_counter; - u32 c_wrapper_arg; struct block *dispatcher, *c_wrapper_block; void *c_wrappers[C_WRAPPERS_COUNT]; void *wrappers_eps[C_WRAPPERS_COUNT]; @@ -147,30 +172,29 @@ struct lightrec_state { struct reaper *reaper; void *tlsf; void (*eob_wrapper_func)(void); + void (*interpreter_func)(void); + void (*ds_check_func)(void); void (*memset_func)(void); void (*get_next_block)(void); struct lightrec_ops ops; unsigned int nb_precompile; + unsigned int nb_compile; unsigned int nb_maps; const struct lightrec_mem_map *maps; - uintptr_t offset_ram, offset_bios, offset_scratch; + uintptr_t offset_ram, offset_bios, offset_scratch, offset_io; _Bool with_32bit_lut; _Bool mirrors_mapped; _Bool invalidate_from_dma_only; void *code_lut[]; }; -u32 lightrec_rw(struct lightrec_state *state, union code op, - u32 addr, u32 data, u16 *flags, - struct block *block); +u32 lightrec_rw(struct lightrec_state *state, union code op, u32 addr, + u32 data, u32 *flags, struct block *block, u16 offset); void lightrec_free_block(struct lightrec_state *state, struct block *block); void remove_from_code_lut(struct blockcache *cache, struct block *block); -enum psx_map -lightrec_get_map_idx(struct lightrec_state *state, u32 kaddr); - const struct lightrec_mem_map * lightrec_get_map(struct lightrec_state *state, void **host, u32 kaddr); @@ -238,7 +262,7 @@ static inline u32 get_ds_pc(const struct block *block, u16 offset, s16 imm) { u16 flags = block->opcode_list[offset].flags; - offset += !!(OPT_SWITCH_DELAY_SLOTS && (flags & LIGHTREC_NO_DS)); + offset += op_flag_no_ds(flags); return block->pc + (offset + imm << 2); } @@ -247,12 +271,12 @@ static inline u32 get_branch_pc(const struct block *block, u16 offset, s16 imm) { u16 flags = block->opcode_list[offset].flags; - offset -= !!(OPT_SWITCH_DELAY_SLOTS && (flags & LIGHTREC_NO_DS)); + offset -= op_flag_no_ds(flags); return block->pc + (offset + imm << 2); } -void lightrec_mtc(struct lightrec_state *state, union code op, u32 data); +void lightrec_mtc(struct lightrec_state *state, union code op, u8 reg, u32 data); u32 lightrec_mfc(struct lightrec_state *state, union code op); void lightrec_rfe(struct lightrec_state *state); void lightrec_cp(struct lightrec_state *state, union code op); @@ -262,11 +286,11 @@ void lightrec_free_cstate(struct lightrec_cstate *cstate); union code lightrec_read_opcode(struct lightrec_state *state, u32 pc); -struct block * lightrec_get_block(struct lightrec_state *state, u32 pc); int lightrec_compile_block(struct lightrec_cstate *cstate, struct block *block); -void lightrec_free_opcode_list(struct lightrec_state *state, struct block *block); +void lightrec_free_opcode_list(struct lightrec_state *state, + struct opcode *list); -unsigned int lightrec_cycles_of_opcode(union code code); +__cnst unsigned int lightrec_cycles_of_opcode(union code code); static inline u8 get_mult_div_lo(union code c) { @@ -278,4 +302,62 @@ static inline u8 get_mult_div_hi(union code c) return (OPT_FLAG_MULT_DIV && c.r.imm) ? c.r.imm : REG_HI; } +static inline s16 s16_max(s16 a, s16 b) +{ + return a > b ? a : b; +} + +static inline _Bool block_has_flag(struct block *block, u8 flag) +{ +#if ENABLE_THREADED_COMPILER + return atomic_load_explicit(&block->flags, memory_order_relaxed) & flag; +#else + return block->flags & flag; +#endif +} + +static inline u8 block_set_flags(struct block *block, u8 mask) +{ +#if ENABLE_THREADED_COMPILER + return atomic_fetch_or_explicit(&block->flags, mask, + memory_order_relaxed); +#else + u8 flags = block->flags; + + block->flags |= mask; + + return flags; +#endif +} + +static inline u8 block_clear_flags(struct block *block, u8 mask) +{ +#if ENABLE_THREADED_COMPILER + return atomic_fetch_and_explicit(&block->flags, ~mask, + memory_order_relaxed); +#else + u8 flags = block->flags; + + block->flags &= ~mask; + + return flags; +#endif +} + +static inline _Bool can_sign_extend(s32 value, u8 order) +{ + return (u32)(value >> order - 1) + 1 < 2; +} + +static inline _Bool can_zero_extend(u32 value, u8 order) +{ + return (value >> order) == 0; +} + +static inline const struct opcode * +get_delay_slot(const struct opcode *list, u16 i) +{ + return op_flag_no_ds(list[i].flags) ? &list[i - 1] : &list[i + 1]; +} + #endif /* __LIGHTREC_PRIVATE_H__ */