[hatari-devel] Separate --cpu-caches option

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

As WinUAE CPU core supports it, attached is patch to enable CPU caches separately from cycle exact and prefetch/compatible options.

It should help in identifying compatibility issues better, and having more control over Hatari performance.

I'm not sure whether it makes sense to merge it before release though...

Comments?


	- Eero

PS. As WinUAE has internal option for enabling opcodes dropped for 060, maybe it would make sense to add Hatari option for that too. Needing to use FPSP060.PRG with most 060 programs is somewhat annoying...
From 5a1d96ea5eec94cad2a943792f3269317de502d5 Mon Sep 17 00:00:00 2001
From: Eero Tamminen <oak@xxxxxxxxxxxxxx>
Date: Sat, 16 Mar 2024 20:28:40 +0200
Subject: [PATCH] Add config & GUI option for CPU cache emulation

---
 python-ui/dialogs.py         |  9 ++++++--
 python-ui/hatari.py          | 12 +++++++++++
 src/change.c                 |  4 ++++
 src/configuration.c          |  3 +++
 src/gui-sdl/dlgCpu.c         | 41 ++++++++++++++++++++++--------------
 src/includes/configuration.h |  1 +
 src/m68000.c                 |  9 +-------
 src/options.c                | 10 ++++++++-
 src/statusbar.c              | 15 ++++++++-----
 tests/tosboot/tos_tester.py  |  1 +
 10 files changed, 73 insertions(+), 32 deletions(-)

diff --git a/python-ui/dialogs.py b/python-ui/dialogs.py
index a26de333..dd675aaf 100644
--- a/python-ui/dialogs.py
+++ b/python-ui/dialogs.py
@@ -946,10 +946,13 @@ class MachineDialog(HatariUIDialog):
         vbox2 = Gtk.VBox()
         self.compatible = Gtk.CheckButton("Prefetch emulation")
         self.compatible.set_tooltip_text("Needed for overscan and other timing sensitive things to work correctly. Uses more host CPU")
-        self.exact = Gtk.CheckButton("Cycle exact with cache emulation")
-        self.exact.set_tooltip_text("Cycle exactness increases emulation accuracy and 680x0 cache emulation increases emulated code performance, but requires significantly more host CPU")
+        self.caches = Gtk.CheckButton(">=030 cache emulation")
+        self.caches.set_tooltip_text("CPU cache emulation increases emulated code performance, but uses significantly more host CPU")
+        self.exact = Gtk.CheckButton("Cycle exact emulation")
+        self.exact.set_tooltip_text("Cycle exactness increases emulation accuracy, but uses more host CPU")
         self.mmu = Gtk.CheckButton("MMU emulation")
         vbox2.add(self.compatible)
+        vbox2.add(self.caches)
         vbox2.add(self.exact)
         vbox2.add(self.mmu)
         table_add_widget_row(table, row, col, None, vbox2, fullspan)
@@ -1006,6 +1009,7 @@ class MachineDialog(HatariUIDialog):
         self.timerd.set_active(config.get_timerd())
         self.cpulevel.set_active(config.get_cpulevel())
         self.compatible.set_active(config.get_compatible())
+        self.caches.set_active(config.get_cpu_caches())
         self.exact.set_active(config.get_cycle_exact())
         self.mmu.set_active(config.get_mmu())
         self.clocks.set_active(config.get_cpuclock())
@@ -1033,6 +1037,7 @@ class MachineDialog(HatariUIDialog):
         config.set_timerd(self.timerd.get_active())
         config.set_cpulevel(self.cpulevel.get_active())
         config.set_compatible(self.compatible.get_active())
+        config.set_cpu_caches(self.caches.get_active())
         config.set_cycle_exact(self.exact.get_active())
         config.set_mmu(self.mmu.get_active())
         config.set_cpuclock(self.clocks.get_active())
diff --git a/python-ui/hatari.py b/python-ui/hatari.py
index 813e1a08..2d531950 100644
--- a/python-ui/hatari.py
+++ b/python-ui/hatari.py
@@ -472,6 +472,18 @@ class HatariConfigMapping(ConfigStore):
         self.set("[System]", "bCompatibleCpu", value)
         self._change_option("--compatible %s" % value)
 
+    # ------------ CPU caches ---------------
+    def get_cpu_caches(self):
+        if not self.has_opts_2_5:
+            return True
+        return self.get("[System]", "bCpuCaches")
+
+    def set_cpu_caches(self, value):
+        if not self.has_opts_2_5:
+            return
+        self.set("[System]", "bCpuCaches", value)
+        self._change_option("--cpu-caches %s" % value)
+
     # ------------ CPU exact ---------------
     def get_cycle_exact(self):
         return self.get("[System]", "bCycleExactCpu")
diff --git a/src/change.c b/src/change.c
index f4ab4673..1fef3266 100644
--- a/src/change.c
+++ b/src/change.c
@@ -149,6 +149,10 @@ bool Change_DoNeedReset(CNF_PARAMS *current, CNF_PARAMS *changed)
 	if (changed->System.bCycleExactCpu != current->System.bCycleExactCpu)
 		return true;
 
+	/* Did change CPU cache emu? */
+	if (changed->System.bCpuCaches != current->System.bCpuCaches)
+		return true;
+
 	/* Did change MMU? */
 	if (changed->System.bMMU != current->System.bMMU)
 		return true;
diff --git a/src/configuration.c b/src/configuration.c
index b10cf378..b84980a4 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -542,6 +542,7 @@ static const struct Config_Tag configs_System[] =
 	{ "bFastForward", Bool_Tag, &ConfigureParams.System.bFastForward },
 	{ "bAddressSpace24", Bool_Tag, &ConfigureParams.System.bAddressSpace24 },
 	{ "bCycleExactCpu", Bool_Tag, &ConfigureParams.System.bCycleExactCpu },
+	{ "bCpuCaches", Bool_Tag, &ConfigureParams.System.bCpuCaches },
 	{ "n_FPUType", Int_Tag, &ConfigureParams.System.n_FPUType },
 /* JIT	{ "bCompatibleFPU", Bool_Tag, &ConfigureParams.System.bCompatibleFPU }, */
 	{ "bSoftFloatFPU", Bool_Tag, &ConfigureParams.System.bSoftFloatFPU },
@@ -847,6 +848,7 @@ void Configuration_SetDefault(void)
 	ConfigureParams.System.bCompatibleFPU = true; /* JIT */
 	ConfigureParams.System.bSoftFloatFPU = false;
 	ConfigureParams.System.bMMU = false;
+	ConfigureParams.System.bCpuCaches = true;
 	ConfigureParams.System.bCycleExactCpu = true;
 	ConfigureParams.System.VideoTimingMode = VIDEO_TIMING_MODE_WS3;
 	ConfigureParams.System.bCompatibleCpu = true;
@@ -1232,6 +1234,7 @@ void Configuration_MemorySnapShot_Capture(bool bSave)
 	MemorySnapShot_Store(&ConfigureParams.System.bPatchTimerD, sizeof(ConfigureParams.System.bPatchTimerD));
 	MemorySnapShot_Store(&ConfigureParams.System.bAddressSpace24, sizeof(ConfigureParams.System.bAddressSpace24));
 
+	MemorySnapShot_Store(&ConfigureParams.System.bCpuCaches, sizeof(ConfigureParams.System.bCpuCaches));
 	MemorySnapShot_Store(&ConfigureParams.System.bCycleExactCpu, sizeof(ConfigureParams.System.bCycleExactCpu));
 	MemorySnapShot_Store(&ConfigureParams.System.n_FPUType, sizeof(ConfigureParams.System.n_FPUType));
 	MemorySnapShot_Store(&ConfigureParams.System.bCompatibleFPU, sizeof(ConfigureParams.System.bCompatibleFPU));
diff --git a/src/gui-sdl/dlgCpu.c b/src/gui-sdl/dlgCpu.c
index 072af88b..aa6d599b 100644
--- a/src/gui-sdl/dlgCpu.c
+++ b/src/gui-sdl/dlgCpu.c
@@ -28,13 +28,14 @@ const char DlgCpu_fileid[] = "Hatari dlgCpu.c";
 #define DLGCPU_FPU_CPU_IN 20
 #define DLGCPU_PREFETCH   23
 #define DLGCPU_CYC_EXACT  24
-#define DLGCPU_MMU_EMUL   25
-#define DLGCPU_24BITS     26
-#define DLGCPU_SOFTFLOAT  27
+#define DLGCPU_CPU_CACHES 25
+#define DLGCPU_MMU_EMUL   26
+#define DLGCPU_24BITS     27
+#define DLGCPU_SOFTFLOAT  28
 
 static SGOBJ cpudlg[] =
 {
-	{ SGBOX, 0, 0, 0,0, 44,24, NULL },
+	{ SGBOX, 0, 0, 0,0, 44,25, NULL },
 	{ SGTEXT, 0, 0, 17,1, 12,1, "CPU options" },
 
 	{ SGBOX, 0, 0, 2,3, 12,8, NULL },
@@ -49,26 +50,27 @@ static SGOBJ cpudlg[] =
 	{ SGBOX, 0, 0, 16,3, 12,8, NULL },
 	{ SGTEXT, 0, 0, 17,3, 10,1, "CPU clock:" },
 	{ SGRADIOBUT, 0, 0, 17,5, 8,1, " _8 Mhz" },
-	{ SGRADIOBUT, 0, 0, 17,6, 8,1, "1_6 Mhz" },
+	{ SGRADIOBUT, 0, 0, 17,6, 8,1, "16 M_hz" },
 	{ SGRADIOBUT, 0, 0, 17,7, 8,1, "32 Mh_z" },
 
 	{ SGBOX, 0, 0, 30,3, 12,8, NULL },
 	{ SGTEXT, 0, 0, 31,3, 4,1, "FPU:" },
 	{ SGRADIOBUT, 0, 0, 31,5, 6,1, "_None" },
 	{ SGRADIOBUT, 0, 0, 31,6, 7,1, "68881" },
-	{ SGRADIOBUT, 0, 0, 31,7, 7,1, "68882" },
+	{ SGRADIOBUT, 0, 0, 31,7, 7,1, "_68882" },
 	{ SGRADIOBUT, 0, 0, 31,8, 10,1, "_Internal" },
 
-	{ SGBOX, 0, 0, 2,12, 40,9, NULL },
+	{ SGBOX, 0, 0, 2,12, 40,10, NULL },
 	{ SGTEXT, 0, 0, 9,12, 24,1, "CPU emulation parameters" },
 	{ SGCHECKBOX, 0, 0, 3,14, 21,1, "_Prefetch emulation*" },
-	{ SGCHECKBOX, 0, 0, 3,15, 35,1, "_Cycle-exact with cache emulation*" },
-	{ SGCHECKBOX, 0, 0, 3,16, 16,1, "_MMU emulation*" },
-	{ SGCHECKBOX, 0, 0, 3,17, 20,1, "24-bit _addressing" },
-	{ SGCHECKBOX, 0, 0, 3,18, 26,1, "Accurate _FPU emulation*" },
-	{ SGTEXT, 0, 0, 3,20, 20,1, "* Uses more host CPU" },
-
-	{ SGBUTTON, SG_DEFAULT, 0, 13,22, 19,1, "Back to main menu" },
+	{ SGCHECKBOX, 0, 0, 3,15, 35,1, "_Cycle-exact emulation*" },
+	{ SGCHECKBOX, 0, 0, 3,16, 35,1, "Cache _emulation* (>=030)" },
+	{ SGCHECKBOX, 0, 0, 3,17, 16,1, "_MMU emulation*" },
+	{ SGCHECKBOX, 0, 0, 3,18, 20,1, "24-bit _addressing" },
+	{ SGCHECKBOX, 0, 0, 3,19, 26,1, "Accurate _FPU emulation*" },
+	{ SGTEXT, 0, 0, 3,21, 20,1, "* Uses more host CPU" },
+
+	{ SGBUTTON, SG_DEFAULT, 0, 13,23, 19,1, "Back to main menu" },
 	{ SGSTOP, 0, 0, 0,0, 0,0, NULL }
 };
 
@@ -113,13 +115,19 @@ void DlgCpu_Main(void)
 		cpudlg[DLGCPU_24BITS].state |= SG_SELECTED;
 	else
 		cpudlg[DLGCPU_24BITS].state &= ~SG_SELECTED;
-		
+
 	/* Cycle exact CPU */
 	if (ConfigureParams.System.bCycleExactCpu)
 		cpudlg[DLGCPU_CYC_EXACT].state |= SG_SELECTED;
 	else
 		cpudlg[DLGCPU_CYC_EXACT].state &= ~SG_SELECTED;
 
+	/* CPU caches */
+	if (ConfigureParams.System.bCpuCaches)
+		cpudlg[DLGCPU_CPU_CACHES].state |= SG_SELECTED;
+	else
+		cpudlg[DLGCPU_CPU_CACHES].state &= ~SG_SELECTED;
+
 	/* FPU emulation */
 	for (i = DLGCPU_FPU_NONE; i <= DLGCPU_FPU_CPU_IN; i++)
 	{
@@ -168,8 +176,9 @@ void DlgCpu_Main(void)
 		Configuration_ChangeCpuFreq ( 8 );
 
 	ConfigureParams.System.bCompatibleCpu = (cpudlg[DLGCPU_PREFETCH].state & SG_SELECTED);
-
 	ConfigureParams.System.bCycleExactCpu = (cpudlg[DLGCPU_CYC_EXACT].state & SG_SELECTED);
+	ConfigureParams.System.bCpuCaches = (cpudlg[DLGCPU_CPU_CACHES].state & SG_SELECTED);
+
 	ConfigureParams.System.bMMU = (cpudlg[DLGCPU_MMU_EMUL].state & SG_SELECTED);
 	ConfigureParams.System.bAddressSpace24 = (cpudlg[DLGCPU_24BITS].state & SG_SELECTED);
 	ConfigureParams.System.bSoftFloatFPU = (cpudlg[DLGCPU_SOFTFLOAT].state & SG_SELECTED);
diff --git a/src/includes/configuration.h b/src/includes/configuration.h
index 44d4ec06..8a043012 100644
--- a/src/includes/configuration.h
+++ b/src/includes/configuration.h
@@ -403,6 +403,7 @@ typedef struct
   VIDEOTIMINGMODE VideoTimingMode;
 
   bool bCycleExactCpu;
+  bool bCpuCaches;
   FPUTYPE n_FPUType;
   bool bCompatibleFPU;            /* More compatible FPU */
   bool bSoftFloatFPU;
diff --git a/src/m68000.c b/src/m68000.c
index 99a30ede..f5d57574 100644
--- a/src/m68000.c
+++ b/src/m68000.c
@@ -364,6 +364,7 @@ void M68000_CheckCpuSettings(void)
 
 	changed_prefs.int_no_unimplemented = true;
 	changed_prefs.fpu_no_unimplemented = true;
+	changed_prefs.cpu_data_cache = ConfigureParams.System.bCpuCaches;
 	changed_prefs.cpu_compatible = ConfigureParams.System.bCompatibleCpu;
 	changed_prefs.cpu_cycle_exact = ConfigureParams.System.bCycleExactCpu;
 	changed_prefs.cpu_memory_cycle_exact = ConfigureParams.System.bCycleExactCpu;
@@ -386,14 +387,6 @@ void M68000_CheckCpuSettings(void)
 	/* We don't use JIT */
 	changed_prefs.cachesize = 0;
 
-	/* Always emulate instr/data caches for cpu >= 68020 */
-	/* Cache emulation requires cpu_compatible or cpu_cycle_exact mode */
-	if ( ( changed_prefs.cpu_model < 68020 ) ||
-	     ( ( changed_prefs.cpu_compatible == false ) && ( changed_prefs.cpu_cycle_exact == false ) ) )
-		changed_prefs.cpu_data_cache = false;
-	else
-		changed_prefs.cpu_data_cache = true;
-
 	/* Update SPCFLAG_MODE_CHANGE flag if needed */
 	check_prefs_changed_cpu();
 
diff --git a/src/options.c b/src/options.c
index 6b4d7d36..127a2166 100644
--- a/src/options.c
+++ b/src/options.c
@@ -165,6 +165,7 @@ enum {
 	OPT_CPULEVEL,		/* CPU options */
 	OPT_CPUCLOCK,
 	OPT_COMPATIBLE,
+	OPT_CPU_CACHES,
 	OPT_CPU_CYCLE_EXACT,
 	OPT_CPU_ADDR24,
 	OPT_FPU_TYPE,
@@ -435,7 +436,9 @@ static const opt_t HatariOptions[] = {
 	{ OPT_CPUCLOCK,  NULL, "--cpuclock",
 	  "<x>", "Set the CPU clock (x = 8/16/32)" },
 	{ OPT_COMPATIBLE, NULL, "--compatible",
-	  "<bool>", "Use a more compatible (but slower) prefetch mode for CPU" },
+	  "<bool>", "Use (more compatible) prefetch mode for CPU" },
+	{ OPT_CPU_CACHES, NULL, "--cpu-caches",
+	  "<bool>", "Emulate (>=030) CPU caches" },
 	{ OPT_CPU_CYCLE_EXACT, NULL, "--cpu-exact",
 	  "<bool>", "Use cycle exact CPU emulation" },
 	{ OPT_CPU_ADDR24, NULL, "--addr24",
@@ -1848,6 +1851,11 @@ bool Opt_ParseParameters(int argc, const char * const argv[])
 			bLoadAutoSave = false;
 			break;
 
+		case OPT_CPU_CACHES:
+			ok = Opt_Bool(argv[++i], OPT_CPU_CACHES, &ConfigureParams.System.bCpuCaches);
+			bLoadAutoSave = false;
+			break;
+
 		case OPT_CPU_CYCLE_EXACT:
 			ok = Opt_Bool(argv[++i], OPT_CPU_CYCLE_EXACT, &ConfigureParams.System.bCycleExactCpu);
 			bLoadAutoSave = false;
diff --git a/src/statusbar.c b/src/statusbar.c
index fdb05e53..91a988c8 100644
--- a/src/statusbar.c
+++ b/src/statusbar.c
@@ -501,10 +501,10 @@ void Statusbar_AddMessage(const char *msg, Uint32 msecs)
  */
 static char *Statusbar_AddString(char *buffer, const char *more)
 {
+	if (!more)
+		return buffer;
 	while (*more)
-	{
 		*buffer++ = *more++;
-	}
 	return buffer;
 }
 
@@ -540,11 +540,16 @@ void Statusbar_UpdateInfo(void)
 		*end++ = '0';
 	}
 
-	/* Prefetch mode or cycle exact mode ? */
+	const char *mode = NULL;
+	bool caches = ConfigureParams.System.bCpuCaches && ConfigureParams.System.nCpuLevel > 2;
+	/* Prefetch / cycle exact mode and caches? */
 	if ( ConfigureParams.System.bCycleExactCpu )
-		end = Statusbar_AddString(end, "(CE)");
+		mode = caches ? "(CEC)" : "(CE)";
 	else if ( ConfigureParams.System.bCompatibleCpu )
-		end = Statusbar_AddString(end, "(PF)");
+		mode = caches ? "(PFC)" : "(PF)";
+	else if (caches)
+		mode = "(C)";
+	end = Statusbar_AddString(end, mode);
 
 	/* additional WinUAE CPU/FPU info */
 	*end++ = '/';
diff --git a/tests/tosboot/tos_tester.py b/tests/tosboot/tos_tester.py
index cde438c0..db4069b2 100755
--- a/tests/tosboot/tos_tester.py
+++ b/tests/tosboot/tos_tester.py
@@ -538,6 +538,7 @@ bFastBoot = FALSE
 bPatchTimerD = FALSE
 bFastForward = TRUE
 bCompatibleCpu = TRUE
+bCpuCaches = TRUE
 bCycleExactCpu = TRUE
 bAddressSpace24 = TRUE
 bBlitter = FALSE
-- 
2.39.2



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/