Skip to content

Commit ea5c2d7

Browse files
committed
drc: eliminate a global from get_addr_ht
1 parent 3d7a4cf commit ea5c2d7

File tree

7 files changed

+56
-30
lines changed

7 files changed

+56
-30
lines changed

libpcsxcore/new_dynarec/assem_arm64.c

+1
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,7 @@ static void do_jump_vaddr(u_int rs)
20382038
{
20392039
if (rs != 0)
20402040
emit_mov(rs, 0);
2041+
emit_readptr(&hash_table_ptr, 1);
20412042
emit_far_call(ndrc_get_addr_ht);
20422043
emit_jmpreg(0);
20432044
}

libpcsxcore/new_dynarec/emu_if.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,14 @@ static void ari64_execute_threaded_once(struct psxRegisters *regs,
356356
enum blockExecCaller block_caller)
357357
{
358358
void *drc_local = (char *)regs - LO_psxRegs;
359+
struct ht_entry *hash_table =
360+
*(void **)((char *)drc_local + LO_hash_table_ptr);
359361
void *target;
360362

361363
if (likely(!ndrc_g.thread.busy)) {
362364
ndrc_g.thread.addr = 0;
363-
target = ndrc_get_addr_ht_param(regs->pc, ndrc_cm_no_compile);
365+
target = ndrc_get_addr_ht_param(hash_table, regs->pc,
366+
ndrc_cm_no_compile);
364367
if (target) {
365368
clear_local_cache();
366369
new_dyna_start_at(drc_local, target);
@@ -428,6 +431,8 @@ static int ari64_thread_check_range(unsigned int start, unsigned int end)
428431

429432
static void ari64_compile_thread(void *unused)
430433
{
434+
struct ht_entry *hash_table =
435+
*(void **)((char *)dynarec_local + LO_hash_table_ptr);
431436
void *target;
432437
u32 addr;
433438

@@ -440,7 +445,8 @@ static void ari64_compile_thread(void *unused)
440445
if (!ndrc_g.thread.busy || !addr || ndrc_g.thread.exit)
441446
continue;
442447

443-
target = ndrc_get_addr_ht_param(addr, ndrc_cm_compile_in_thread);
448+
target = ndrc_get_addr_ht_param(hash_table, addr,
449+
ndrc_cm_compile_in_thread);
444450
//printf("c %08x -> %p\n", addr, target);
445451
ndrc_g.thread.busy = 0;
446452
}
@@ -520,7 +526,6 @@ static int ari64_thread_check_range(unsigned int start, unsigned int end) { retu
520526

521527
static int ari64_init()
522528
{
523-
static u32 scratch_buf[8*8*2] __attribute__((aligned(64)));
524529
size_t i;
525530

526531
new_dynarec_init();
@@ -548,7 +553,6 @@ static int ari64_init()
548553
#endif
549554
psxH_ptr = psxH;
550555
zeromem_ptr = zero_mem;
551-
scratch_buf_ptr = scratch_buf;
552556

553557
ari64_thread_init();
554558

@@ -576,11 +580,6 @@ R3000Acpu psxRec = {
576580
#else // if DRC_DISABLE
577581

578582
struct ndrc_globals ndrc_g; // dummy
579-
void *psxH_ptr;
580-
void *zeromem_ptr;
581-
u32 zero_mem[0x1000/4];
582-
void *mem_rtab;
583-
void *scratch_buf_ptr;
584583
void new_dynarec_init() {}
585584
void new_dyna_start(void *context) {}
586585
void new_dynarec_cleanup() {}

libpcsxcore/new_dynarec/linkage_arm.S

+9-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ DRC_VAR(mem_wtab, 4)
7979
DRC_VAR(psxH_ptr, 4)
8080
DRC_VAR(zeromem_ptr, 4)
8181
DRC_VAR(invc_ptr, 4)
82-
DRC_VAR(scratch_buf_ptr, 4)
82+
DRC_VAR(hash_table_ptr, 4)
8383
DRC_VAR(ram_offset, 4)
8484
DRC_VAR(mini_ht, 256)
8585

@@ -150,7 +150,9 @@ FUNCTION(dyna_linker):
150150
mov r5, r1
151151
lsl r6, r6, #8
152152
/* must not compile - that might expire the caller block */
153-
mov r1, #0 /* ndrc_compile_mode */
153+
ldr r0, [fp, #LO_hash_table_ptr]
154+
mov r1, r4
155+
mov r2, #0 /* ndrc_compile_mode=ndrc_cm_no_compile */
154156
bl ndrc_get_addr_ht_param
155157

156158
movs r8, r0
@@ -174,6 +176,7 @@ FUNCTION(dyna_linker):
174176
#else
175177
/* XXX: should be able to do better than this... */
176178
#endif
179+
ldr r1, [fp, #LO_hash_table_ptr]
177180
bl ndrc_get_addr_ht
178181
mov pc, r0
179182
.size dyna_linker, .-dyna_linker
@@ -223,6 +226,7 @@ FUNCTION(jump_vaddr_r7):
223226
add r0, r7, #0
224227
.size jump_vaddr_r7, .-jump_vaddr_r7
225228
FUNCTION(jump_vaddr_r0):
229+
ldr r1, [fp, #LO_hash_table_ptr]
226230
bl ndrc_get_addr_ht
227231
mov pc, r0
228232
.size jump_vaddr_r0, .-jump_vaddr_r0
@@ -248,6 +252,7 @@ FUNCTION(cc_interrupt):
248252
ldmfdne sp!, {r4, r5, r6, r7, r8, r9, sl, fp, ip, pc}
249253
cmp r0, r9
250254
moveq pc, lr
255+
ldr r1, [fp, #LO_hash_table_ptr]
251256
bl ndrc_get_addr_ht
252257
mov pc, r0
253258
.size cc_interrupt, .-cc_interrupt
@@ -304,6 +309,7 @@ FUNCTION(jump_to_new_pc):
304309
str r1, [fp, #LO_last_count]
305310
sub r10, r10, r1
306311
bne new_dyna_leave
312+
ldr r1, [fp, #LO_hash_table_ptr]
307313
bl ndrc_get_addr_ht
308314
mov pc, r0
309315
.size jump_to_new_pc, .-jump_to_new_pc
@@ -408,6 +414,7 @@ FUNCTION(new_dyna_start):
408414
stmfd sp!, {r4, r5, r6, r7, r8, r9, sl, fp, ip, lr}
409415
mov fp, r0 /* dynarec_local */
410416
ldr r0, [fp, #LO_pcaddr]
417+
ldr r1, [fp, #LO_hash_table_ptr]
411418
bl ndrc_get_addr_ht
412419
new_dyna_start_at_e:
413420
ldr r1, [fp, #LO_next_interupt]

libpcsxcore/new_dynarec/linkage_arm64.S

+6-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ DRC_VAR(mem_wtab, 8)
8181
DRC_VAR(psxH_ptr, 8)
8282
DRC_VAR(invc_ptr, 8)
8383
DRC_VAR(zeromem_ptr, 8)
84-
DRC_VAR(scratch_buf_ptr, 8)
84+
DRC_VAR(hash_table_ptr, 8)
8585
DRC_VAR(ram_offset, 8)
8686
DRC_VAR(mini_ht, 256)
8787

@@ -92,6 +92,7 @@ DRC_VAR(mini_ht, 256)
9292
FUNCTION(dyna_linker):
9393
/* r0 = virtual target address */
9494
/* r1 = instruction to patch */
95+
ldr x1, [rFP, #LO_hash_table_ptr]
9596
bl ndrc_get_addr_ht
9697
br x0
9798
ESIZE(dyna_linker, .-dyna_linker)
@@ -118,6 +119,7 @@ FUNCTION(cc_interrupt):
118119
bne 2f
119120
ret
120121
2:
122+
ldr x1, [rFP, #LO_hash_table_ptr]
121123
bl ndrc_get_addr_ht
122124
br x0
123125
ESIZE(cc_interrupt, .-cc_interrupt)
@@ -173,6 +175,7 @@ FUNCTION(jump_to_new_pc):
173175
sub rCC, rCC, w1
174176
str w1, [rFP, #LO_last_count]
175177
cbnz w2, new_dyna_leave
178+
ldr x1, [rFP, #LO_hash_table_ptr]
176179
bl ndrc_get_addr_ht
177180
br x0
178181
ESIZE(jump_to_new_pc, .-jump_to_new_pc)
@@ -188,8 +191,9 @@ FUNCTION(new_dyna_start):
188191
stp x29, x30, [sp, #-SSP_ALL]!
189192
mov rFP, x0
190193
ldr w0, [rFP, #LO_pcaddr]
194+
ldr x1, [rFP, #LO_hash_table_ptr]
191195
bl ndrc_get_addr_ht
192-
mov x1, x0
196+
mov x1, x0
193197
new_dyna_start_at_e:
194198
ldr w3, [rFP, #LO_next_interupt]
195199
ldr w2, [rFP, #LO_cycle]

libpcsxcore/new_dynarec/linkage_offsets.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
#define LO_psxH_ptr (LO_mem_wtab + PTRSZ)
3939
#define LO_zeromem_ptr (LO_psxH_ptr + PTRSZ)
4040
#define LO_invc_ptr (LO_zeromem_ptr + PTRSZ)
41-
#define LO_scratch_buf_ptr (LO_invc_ptr + PTRSZ)
42-
#define LO_saved_lr (LO_scratch_buf_ptr + PTRSZ)
41+
#define LO_hash_table_ptr (LO_invc_ptr + PTRSZ)
42+
#define LO_saved_lr (LO_hash_table_ptr + PTRSZ)
4343
#define LO_ram_offset (LO_saved_lr + PTRSZ)
4444
#define LO_mini_ht (LO_ram_offset + PTRSZ)
4545
#define LO_dynarec_local_size (LO_mini_ht + PTRSZ*32*2)

libpcsxcore/new_dynarec/new_dynarec.c

+27-14
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ extern int last_count; // last absolute target, often = next_interupt
7575

7676
extern int reg_cop2d[], reg_cop2c[];
7777

78+
extern void *hash_table_ptr;
7879
extern uintptr_t ram_offset;
7980
extern uintptr_t mini_ht[32][2];
8081

@@ -400,7 +401,7 @@ void jump_to_new_pc();
400401
void call_gteStall();
401402
void new_dyna_leave();
402403

403-
void *ndrc_get_addr_ht(u_int vaddr);
404+
void *ndrc_get_addr_ht(u_int vaddr, struct ht_entry *ht);
404405
void ndrc_add_jump_out(u_int vaddr, void *src);
405406
void ndrc_write_invalidate_one(u_int addr);
406407
static void ndrc_write_invalidate_many(u_int addr, u_int end);
@@ -642,9 +643,14 @@ static u_int get_page_prev(u_int vaddr)
642643
return page;
643644
}
644645

646+
static struct ht_entry *hash_table_get_p(struct ht_entry *ht, u_int vaddr)
647+
{
648+
return &ht[((vaddr >> 16) ^ vaddr) & 0xFFFF];
649+
}
650+
645651
static struct ht_entry *hash_table_get(u_int vaddr)
646652
{
647-
return &hash_table[((vaddr>>16)^vaddr)&0xFFFF];
653+
return hash_table_get_p(hash_table, vaddr);
648654
}
649655

650656
#define HASH_TABLE_BAD 0xbac
@@ -805,7 +811,8 @@ static noinline u_int generate_exception(u_int pc)
805811

806812
// Get address from virtual address
807813
// This is called from the recompiled JR/JALR instructions
808-
static void noinline *get_addr(const u_int vaddr, enum ndrc_compile_mode compile_mode)
814+
static void noinline *get_addr(struct ht_entry *ht, const u_int vaddr,
815+
enum ndrc_compile_mode compile_mode)
809816
{
810817
u_int start_page = get_page_prev(vaddr);
811818
u_int i, page, end_page = get_page(vaddr);
@@ -846,31 +853,32 @@ static void noinline *get_addr(const u_int vaddr, enum ndrc_compile_mode compile
846853

847854
int r = new_recompile_block(vaddr);
848855
if (likely(r == 0))
849-
return ndrc_get_addr_ht(vaddr);
856+
return ndrc_get_addr_ht(vaddr, ht);
850857

851858
if (compile_mode == ndrc_cm_compile_live)
852-
return ndrc_get_addr_ht(generate_exception(vaddr));
859+
return ndrc_get_addr_ht(generate_exception(vaddr), ht);
853860

854861
return NULL;
855862
}
856863

857864
// Look up address in hash table first
858-
void *ndrc_get_addr_ht_param(unsigned int vaddr, enum ndrc_compile_mode compile_mode)
865+
void *ndrc_get_addr_ht_param(struct ht_entry *ht, unsigned int vaddr,
866+
enum ndrc_compile_mode compile_mode)
859867
{
860868
//check_for_block_changes(vaddr, vaddr + MAXBLOCK);
861-
const struct ht_entry *ht_bin = hash_table_get(vaddr);
869+
const struct ht_entry *ht_bin = hash_table_get_p(ht, vaddr);
862870
u_int vaddr_a = vaddr & ~3;
863871
stat_inc(stat_ht_lookups);
864872
if (ht_bin->vaddr[0] == vaddr_a) return ht_bin->tcaddr[0];
865873
if (ht_bin->vaddr[1] == vaddr_a) return ht_bin->tcaddr[1];
866-
return get_addr(vaddr, compile_mode);
874+
return get_addr(ht, vaddr, compile_mode);
867875
}
868876

869877
// "usual" addr lookup for indirect branches, etc
870878
// to be used by currently running code only
871-
void *ndrc_get_addr_ht(u_int vaddr)
879+
void *ndrc_get_addr_ht(u_int vaddr, struct ht_entry *ht)
872880
{
873-
return ndrc_get_addr_ht_param(vaddr, ndrc_cm_compile_live);
881+
return ndrc_get_addr_ht_param(ht, vaddr, ndrc_cm_compile_live);
874882
}
875883

876884
static void clear_all_regs(signed char regmap[])
@@ -1317,6 +1325,7 @@ static const char *fpofs_name(u_int ofs)
13171325
ofscase(psxH_ptr);
13181326
ofscase(invc_ptr);
13191327
ofscase(ram_offset);
1328+
ofscase(hash_table_ptr);
13201329
#undef ofscase
13211330
}
13221331
buf[0] = 0;
@@ -3439,9 +3448,10 @@ static void store_assemble(int i, const struct regstat *i_regs, int ccadj_)
34393448
if(i_regs->regmap==regs[i].regmap) {
34403449
load_all_consts(regs[i].regmap_entry,regs[i].wasdirty,i);
34413450
wb_dirtys(regs[i].regmap_entry,regs[i].wasdirty);
3442-
emit_movimm(start+i*4+4,0);
3443-
emit_writeword(0,&psxRegs.pc);
3444-
emit_addimm(HOST_CCREG,2,HOST_CCREG);
3451+
emit_readptr(&hash_table_ptr, 1);
3452+
emit_movimm(start+i*4+4, 0);
3453+
emit_writeword(0, &psxRegs.pc);
3454+
emit_addimm(HOST_CCREG, 2, HOST_CCREG);
34453455
emit_far_call(ndrc_get_addr_ht);
34463456
emit_jmpreg(0);
34473457
}
@@ -3620,6 +3630,7 @@ static void cop0_assemble(int i, const struct regstat *i_regs, int ccadj_)
36203630
emit_cmp(HOST_TEMPREG, 0);
36213631
void *jaddr = out;
36223632
emit_jeq(0);
3633+
emit_readptr(&hash_table_ptr, 1);
36233634
emit_far_call(ndrc_get_addr_ht);
36243635
emit_jmpreg(0);
36253636
set_jump_target(jaddr, out);
@@ -6368,6 +6379,7 @@ void new_dynarec_init(void)
63686379
#endif
63696380
out = ndrc->translation_cache;
63706381
new_dynarec_clear_full();
6382+
hash_table_ptr = hash_table;
63716383
#ifdef HOST_IMM8
63726384
// Copy this into local area so we don't have to put it in every literal pool
63736385
invc_ptr=invalid_code;
@@ -6542,7 +6554,7 @@ void new_dynarec_load_blocks(const void *save, int size)
65426554
psxRegs.GPR.r[i] = 0x1f800000;
65436555
}
65446556

6545-
ndrc_get_addr_ht_param(sblocks[b].addr, ndrc_cm_compile_offline);
6557+
ndrc_get_addr_ht_param(hash_table, sblocks[b].addr, ndrc_cm_compile_offline);
65466558

65476559
for (f = sblocks[b].regflags, i = 0; f; f >>= 1, i++) {
65486560
if (f & 1)
@@ -9038,6 +9050,7 @@ static int new_recompile_block(u_int addr)
90389050
emit_addimm(0, 0x18, 0);
90399051
emit_adds_ptr(1, 1, 1);
90409052
emit_ldr_dualindexed(1, 0, 0);
9053+
emit_readptr(&hash_table_ptr, 1);
90419054
emit_writeword(0, &psxRegs.GPR.r[26]); // lw k0, 0x18(sp)
90429055
emit_far_call(ndrc_get_addr_ht);
90439056
emit_jmpreg(0); // jr k0

libpcsxcore/new_dynarec/new_dynarec.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ void new_dynarec_invalidate_all_pages(void);
4444
void new_dyna_start(void *context);
4545
void new_dyna_start_at(void *context, void *compiled_code);
4646

47+
struct ht_entry;
4748
enum ndrc_compile_mode {
4849
ndrc_cm_no_compile = 0,
4950
ndrc_cm_compile_live, // from executing code, vaddr is the current pc
5051
ndrc_cm_compile_offline,
5152
ndrc_cm_compile_in_thread,
5253
};
53-
void *ndrc_get_addr_ht_param(unsigned int vaddr, enum ndrc_compile_mode compile_mode);
54+
void *ndrc_get_addr_ht_param(struct ht_entry *ht, unsigned int vaddr,
55+
enum ndrc_compile_mode compile_mode);
5456

5557
extern unsigned int ndrc_smrv_regs[32];

0 commit comments

Comments
 (0)