drc: rework cycle counting
[pcsx_rearmed.git] / libpcsxcore / new_dynarec / patches / trace_drc_chk
CommitLineData
a151a8d8 1diff --git a/libpcsxcore/new_dynarec/new_dynarec.c b/libpcsxcore/new_dynarec/new_dynarec.c
2330734f 2index f1005db..ebd1d4f 100644
a151a8d8 3--- a/libpcsxcore/new_dynarec/new_dynarec.c
4+++ b/libpcsxcore/new_dynarec/new_dynarec.c
2330734f 5@@ -235,7 +235,7 @@ static struct decoded_insn
6 int new_dynarec_hacks_old;
7 int new_dynarec_did_compile;
8
9- #define HACK_ENABLED(x) ((new_dynarec_hacks | new_dynarec_hacks_pergame) & (x))
10+ #define HACK_ENABLED(x) ((NDHACK_NO_STALLS) & (x))
11
12 extern int cycle_count; // ... until end of the timeslice, counts -N -> 0
13 extern int last_count; // last absolute target, often = next_interupt
14@@ -471,6 +471,7 @@ int cycle_multiplier_old;
15
16 static int CLOCK_ADJUST(int x)
17 {
18+ return x * 2;
19 int m = cycle_multiplier_override && cycle_multiplier == CYCLE_MULT_DEFAULT
20 ? cycle_multiplier_override : cycle_multiplier;
21 int s=(x>>31)|1;
22@@ -522,6 +523,9 @@ static int doesnt_expire_soon(void *tcaddr)
a151a8d8 23 // This is called from the recompiled JR/JALR instructions
d1e4ebd9 24 void noinline *get_addr(u_int vaddr)
a151a8d8 25 {
26+#ifdef DRC_DBG
27+printf("get_addr %08x, pc=%08x\n", vaddr, psxRegs.pc);
28+#endif
29 u_int page=get_page(vaddr);
30 u_int vpage=get_vpage(vaddr);
31 struct ll_entry *head;
2330734f 32@@ -6248,7 +6252,7 @@ void unneeded_registers(int istart,int iend,int r)
a151a8d8 33 // R0 is always unneeded
d1e4ebd9 34 u|=1;
a151a8d8 35 // Save it
36- unneeded_reg[i]=u;
37+ unneeded_reg[i]=1;//u;
a151a8d8 38 gte_unneeded[i]=gte_u;
39 /*
d1e4ebd9 40 printf("ur (%d,%d) %x: ",istart,iend,start+i*4);
2330734f 41@@ -8794,6 +8798,7 @@ int new_recompile_block(u_int addr)
a151a8d8 42
43 // This allocates registers (if possible) one instruction prior
44 // to use, which can avoid a load-use penalty on certain CPUs.
45+#if 0
46 for(i=0;i<slen-1;i++)
47 {
37387d8b 48 if (!i || !dops[i-1].is_jump)
2330734f 49@@ -8950,6 +8955,7 @@ int new_recompile_block(u_int addr)
a151a8d8 50 }
51 }
52 }
53+#endif
54
55 /* Pass 6 - Optimize clean/dirty state */
56 clean_registers(0,slen-1,1);
2330734f 57@@ -9204,6 +9210,11 @@ int new_recompile_block(u_int addr)
58 load_regs(regs[i].regmap_entry,regs[i].regmap,INVCP,INVCP);
59
60 ds = assemble(i, &regs[i], ccadj[i]);
a151a8d8 61+#ifdef DRC_DBG
37387d8b 62+ // write-out non-consts, consts are likely different because of get_final_value()
63+ if (!dops[i].is_jump)
64+ wb_dirtys(regs[i].regmap,regs[i].dirty&~regs[i].loadedconst);
a151a8d8 65+#endif
2330734f 66
37387d8b 67 if (dops[i].is_ujump)
a151a8d8 68 literal_pool(1024);
2330734f 69@@ -9439,6 +9450,10 @@ int new_recompile_block(u_int addr)
a151a8d8 70 }
37387d8b 71 #ifdef ASSEM_PRINT
72 fflush(stdout);
73+#endif
a151a8d8 74+#ifdef DRC_DBG
75+printf("new_recompile_block done\n");
76+fflush(stdout);
37387d8b 77 #endif
a151a8d8 78 return 0;
79 }
2330734f 80diff --git a/libpcsxcore/new_dynarec/pcsxmem.c b/libpcsxcore/new_dynarec/pcsxmem.c
81index bb471b6..8f68a3b 100644
82--- a/libpcsxcore/new_dynarec/pcsxmem.c
83+++ b/libpcsxcore/new_dynarec/pcsxmem.c
84@@ -272,6 +272,8 @@ static void write_biu(u32 value)
85 if (address != 0xfffe0130)
86 return;
87
88+extern u32 handler_cycle;
89+handler_cycle = psxRegs.cycle;
90 switch (value) {
91 case 0x800: case 0x804:
92 unmap_ram_write();
93diff --git a/libpcsxcore/psxcounters.c b/libpcsxcore/psxcounters.c
94index b2cc07b..f916580 100644
95--- a/libpcsxcore/psxcounters.c
96+++ b/libpcsxcore/psxcounters.c
97@@ -378,9 +378,12 @@ void psxRcntUpdate()
98
99 /******************************************************************************/
100
101+extern u32 handler_cycle;
102+
103 void psxRcntWcount( u32 index, u32 value )
104 {
105 verboseLog( 2, "[RCNT %i] wcount: %x\n", index, value );
106+handler_cycle = psxRegs.cycle;
107
108 _psxRcntWcount( index, value );
109 psxRcntSet();
110@@ -389,6 +392,7 @@ void psxRcntWcount( u32 index, u32 value )
111 void psxRcntWmode( u32 index, u32 value )
112 {
113 verboseLog( 1, "[RCNT %i] wmode: %x\n", index, value );
114+handler_cycle = psxRegs.cycle;
115
116 _psxRcntWmode( index, value );
117 _psxRcntWcount( index, 0 );
118@@ -400,6 +404,7 @@ void psxRcntWmode( u32 index, u32 value )
119 void psxRcntWtarget( u32 index, u32 value )
120 {
121 verboseLog( 1, "[RCNT %i] wtarget: %x\n", index, value );
122+handler_cycle = psxRegs.cycle;
123
124 rcnts[index].target = value;
125
126@@ -412,6 +417,7 @@ void psxRcntWtarget( u32 index, u32 value )
127 u32 psxRcntRcount( u32 index )
128 {
129 u32 count;
130+handler_cycle = psxRegs.cycle;
131
132 count = _psxRcntRcount( index );
133