From: notaz Date: Sun, 6 Feb 2022 23:41:12 +0000 (+0200) Subject: drc: try to make some passes not as slow, part 2 X-Git-Tag: r23~19 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53358c1d5b032cc7186b71e3cc14f0ad6c2d5468;p=pcsx_rearmed.git drc: try to make some passes not as slow, part 2 --- diff --git a/libpcsxcore/new_dynarec/assem_arm.c b/libpcsxcore/new_dynarec/assem_arm.c index da32f5b7..b9dd3cf9 100644 --- a/libpcsxcore/new_dynarec/assem_arm.c +++ b/libpcsxcore/new_dynarec/assem_arm.c @@ -522,12 +522,8 @@ static void emit_pcreladdr(u_int rt) static void emit_loadreg(int r, int hr) { - if(r&64) { - SysPrintf("64bit load in 32bit mode!\n"); - assert(0); - return; - } - if((r&63)==0) + assert(hr != EXCLUDE_REG); + if (r == 0) emit_zeroreg(hr); else { void *addr; @@ -552,11 +548,7 @@ static void emit_loadreg(int r, int hr) static void emit_storereg(int r, int hr) { - if(r&64) { - SysPrintf("64bit store in 32bit mode!\n"); - assert(0); - return; - } + assert(hr != EXCLUDE_REG); int addr = (int)&psxRegs.GPR.r[r]; switch (r) { //case HIREG: addr = &hi; break; diff --git a/libpcsxcore/new_dynarec/assem_arm64.c b/libpcsxcore/new_dynarec/assem_arm64.c index 1157aafe..ee7b4f7c 100644 --- a/libpcsxcore/new_dynarec/assem_arm64.c +++ b/libpcsxcore/new_dynarec/assem_arm64.c @@ -449,7 +449,6 @@ static void emit_readshword(void *addr, u_int rt) static void emit_loadreg(u_int r, u_int hr) { int is64 = 0; - assert(r < 64); if (r == 0) emit_zeroreg(hr); else { diff --git a/libpcsxcore/new_dynarec/new_dynarec.c b/libpcsxcore/new_dynarec/new_dynarec.c index 9913b116..95564230 100644 --- a/libpcsxcore/new_dynarec/new_dynarec.c +++ b/libpcsxcore/new_dynarec/new_dynarec.c @@ -220,9 +220,6 @@ static struct decoded_insn static struct regstat regs[MAXBLOCK]; static struct regstat branch_regs[MAXBLOCK]; static signed char minimum_free_regs[MAXBLOCK]; - static u_int needed_reg[MAXBLOCK]; - static u_int wont_dirty[MAXBLOCK]; - static u_int will_dirty[MAXBLOCK]; static int ccadj[MAXBLOCK]; static int slen; static void *instr_addr[MAXBLOCK]; @@ -608,6 +605,8 @@ static void clear_all_regs(signed char regmap[]) memset(regmap, -1, sizeof(regmap[0]) * HOST_REGS); } +// get_reg: get allocated host reg from mips reg +// returns -1 if no such mips reg was allocated #if defined(__arm__) && defined(HAVE_ARMV6) && HOST_REGS == 13 && EXCLUDE_REG == 11 extern signed char get_reg(const signed char regmap[], signed char r); @@ -628,6 +627,12 @@ static signed char get_reg(const signed char regmap[], signed char r) #endif +// get reg as mask bit (1 << hr) +static u_int get_regm(const signed char regmap[], signed char r) +{ + return (1u << (get_reg(regmap, r) & 31)) & ~(1u << 31); +} + static signed char get_reg_temp(const signed char regmap[]) { int hr; @@ -1442,15 +1447,14 @@ static void alloc_reg(struct regstat *cur,int i,signed char reg) if (reg == CCREG) preferred_reg = HOST_CCREG; if (reg == PTEMP || reg == FTEMP) preferred_reg = 12; assert(PREFERRED_REG_FIRST != EXCLUDE_REG && EXCLUDE_REG != HOST_REGS); + assert(reg >= 0); // Don't allocate unused registers if((cur->u>>reg)&1) return; // see if it's already allocated - for(hr=0;hrregmap[hr]==reg) return; - } + if (get_reg(cur->regmap, reg) >= 0) + return; // Keep the same mapping if the register was already allocated in a loop preferred_reg = loop_reg(i,reg,preferred_reg); @@ -2193,23 +2197,13 @@ static void wb_register(signed char r, const signed char regmap[], uint64_t dirt static void wb_valid(signed char pre[],signed char entry[],u_int dirty_pre,u_int dirty,uint64_t u) { //if(dirty_pre==dirty) return; - int hr,reg; - for(hr=0;hr>reg)&1) { - if(reg>0) { - if(((dirty_pre&~dirty)>>hr)&1) { - if(reg>0&®<34) { - emit_storereg(reg,hr); - } - else if(reg>=64) { - assert(0); - } - } - } - } - } + int hr, r; + for (hr = 0; hr < HOST_REGS; hr++) { + r = pre[hr]; + if (r < 1 || r > 33 || ((u >> r) & 1)) + continue; + if (((dirty_pre & ~dirty) >> hr) & 1) + emit_storereg(r, hr); } } @@ -4279,26 +4273,18 @@ static void wb_invalidate(signed char pre[],signed char entry[],uint64_t dirty,u // Load the specified registers // This only loads the registers given as arguments because // we don't want to load things that will be overwritten -static void load_regs(signed char entry[],signed char regmap[],int rs1,int rs2) +static inline void load_reg(signed char entry[], signed char regmap[], int rs) { - int hr; - // Load 32-bit regs - for(hr=0;hr=0) { - if(entry[hr]!=regmap[hr]) { - if(regmap[hr]==rs1||regmap[hr]==rs2) - { - if(regmap[hr]==0) { - emit_zeroreg(hr); - } - else - { - emit_loadreg(regmap[hr],hr); - } - } - } - } - } + int hr = get_reg(regmap, rs); + if (hr >= 0 && entry[hr] != regmap[hr]) + emit_loadreg(regmap[hr], hr); +} + +static void load_regs(signed char entry[], signed char regmap[], int rs1, int rs2) +{ + load_reg(entry, regmap, rs1); + if (rs1 != rs2) + load_reg(entry, regmap, rs2); } // Load registers prior to the start of a loop @@ -4306,27 +4292,12 @@ static void load_regs(signed char entry[],signed char regmap[],int rs1,int rs2) static void loop_preload(signed char pre[],signed char entry[]) { int hr; - for(hr=0;hr=0) { - if(get_reg(pre,entry[hr])<0) { - assem_debug("loop preload:\n"); - //printf("loop preload: %d\n",hr); - if(entry[hr]==0) { - emit_zeroreg(hr); - } - else if(entry[hr]= 0 && pre[hr] != r && get_reg(pre, r) < 0) { + assem_debug("loop preload:\n"); + if (r < TEMPREG) + emit_loadreg(r, hr); } } } @@ -4846,9 +4817,9 @@ static void ds_assemble_entry(int i) load_regs(regs[t].regmap_entry,regs[t].regmap,dops[t].rs1,dops[t].rs2); address_generation(t,®s[t],regs[t].regmap_entry); if (ram_offset && (dops[t].is_load || dops[t].is_store)) - load_regs(regs[t].regmap_entry,regs[t].regmap,ROREG,ROREG); + load_reg(regs[t].regmap_entry,regs[t].regmap,ROREG); if (dops[t].is_store) - load_regs(regs[t].regmap_entry,regs[t].regmap,INVCP,INVCP); + load_reg(regs[t].regmap_entry,regs[t].regmap,INVCP); is_delayslot=0; switch (dops[t].itype) { case SYSCALL: @@ -5223,7 +5194,7 @@ static void ujump_assemble(int i, const struct regstat *i_regs) uint64_t bc_unneeded=branch_regs[i].u; bc_unneeded|=1|(1LL<=0;i--) { int hr; + __builtin_prefetch(regs[i-2].regmap); if(dops[i].is_jump) { if(ba[i]=(start+slen*4)) @@ -7988,7 +7961,7 @@ static noinline void pass4_cull_unused_regs(void) if (!dops[i].is_ujump) { if(i=0&&get_reg(regs[i+2].regmap_entry,regmap_pre[i+2][hr])<0) nr&=~(1< 0 && !dops[i].bt && regs[i].wasdirty) for(hr=0;hr0&&!dops[i].bt&&((regs[i].wasdirty>>hr)&1)) { + if((regs[i].wasdirty>>hr)&1) { if((regmap_pre[i][hr]>0&&!((unneeded_reg[i]>>regmap_pre[i][hr])&1))) { if(dops[i-1].rt1==regmap_pre[i][hr]) nr|=1<