qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/2] reduce code duplication


From: Glauber Costa
Subject: [Qemu-devel] [PATCH 2/2] reduce code duplication
Date: Thu, 11 Dec 2008 09:11:50 -0500

Code for all versions of notdirty_mem_write are quite alike.
Rewrite it as a generator macro.

Signed-off-by: Glauber Costa <address@hidden>
---
 exec.c |   66 ++++++++++++++++-----------------------------------------------
 1 files changed, 17 insertions(+), 49 deletions(-)

diff --git a/exec.c b/exec.c
index 35e0b8e..986c3b0 100644
--- a/exec.c
+++ b/exec.c
@@ -2455,43 +2455,27 @@ static CPUWriteMemoryFunc *unassigned_mem_write[3] = {
     unassigned_mem_writel,
 };
 
-static void notdirty_mem_writeb(void *opaque, target_phys_addr_t ram_addr,
-                                uint32_t val)
+static inline void store_size(target_phys_addr_t addr, uint32_t val, char siz)
 {
-    int dirty_flags;
-    dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
-    if (!(dirty_flags & CODE_DIRTY_FLAG)) {
-#if !defined(CONFIG_USER_ONLY)
-        tb_invalidate_phys_page_fast(ram_addr, 'b');
-        dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
-#endif
+    switch (siz) {
+    case 'b': stb_p(addr, val); break;
+    case 'w': stw_p(addr, val); break;
+    case 'l': stl_p(addr, val); break;
     }
-    stb_p(phys_ram_base + ram_addr, val);
-#ifdef USE_KQEMU
-    if (cpu_single_env->kqemu_enabled &&
-        (dirty_flags & KQEMU_MODIFY_PAGE_MASK) != KQEMU_MODIFY_PAGE_MASK)
-        kqemu_modify_page(cpu_single_env, ram_addr);
-#endif
-    dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
-    phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS] = dirty_flags;
-    /* we remove the notdirty callback only if the code has been
-       flushed */
-    if (dirty_flags == 0xff)
-        tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
 }
 
-static void notdirty_mem_writew(void *opaque, target_phys_addr_t ram_addr,
-                                uint32_t val)
+static inline void notdirty_mem_write_size(void *opaque, target_phys_addr_t 
ram_addr,
+                                uint32_t val, char siz)
 {
     int dirty_flags;
     dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
     if (!(dirty_flags & CODE_DIRTY_FLAG)) {
 #if !defined(CONFIG_USER_ONLY)
-        tb_invalidate_phys_page_fast(ram_addr, 'w');
+        tb_invalidate_phys_page_fast(ram_addr, siz);
         dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
 #endif
     }
-    stw_p(phys_ram_base + ram_addr, val);
+    store_size((target_phys_addr_t)phys_ram_base + ram_addr, val, siz);
 #ifdef USE_KQEMU
     if (cpu_single_env->kqemu_enabled &&
         (dirty_flags & KQEMU_MODIFY_PAGE_MASK) != KQEMU_MODIFY_PAGE_MASK)
@@ -2505,30 +2489,14 @@ static void notdirty_mem_writew(void *opaque, 
target_phys_addr_t ram_addr,
         tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
 }
 
-static void notdirty_mem_writel(void *opaque, target_phys_addr_t ram_addr,
-                                uint32_t val)
-{
-    int dirty_flags;
-    dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
-    if (!(dirty_flags & CODE_DIRTY_FLAG)) {
-#if !defined(CONFIG_USER_ONLY)
-        tb_invalidate_phys_page_fast(ram_addr, 'l');
-        dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
-#endif
-    }
-    stl_p(phys_ram_base + ram_addr, val);
-#ifdef USE_KQEMU
-    if (cpu_single_env->kqemu_enabled &&
-        (dirty_flags & KQEMU_MODIFY_PAGE_MASK) != KQEMU_MODIFY_PAGE_MASK)
-        kqemu_modify_page(cpu_single_env, ram_addr);
-#endif
-    dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
-    phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS] = dirty_flags;
-    /* we remove the notdirty callback only if the code has been
-       flushed */
-    if (dirty_flags == 0xff)
-        tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
-}
+#define gen_notdirty(s) static void notdirty_mem_write##s(void *opaque, \
+                                    target_phys_addr_t ram_addr, uint32_t val)\
+{   notdirty_mem_write_size(opaque, ram_addr, val, #s[0]); }
+
+gen_notdirty(b)
+gen_notdirty(w)
+gen_notdirty(l)
+#undef gen_notdirty
 
 static CPUReadMemoryFunc *error_mem_read[3] = {
     NULL, /* never used */
-- 
1.5.6.5





reply via email to

[Prev in Thread] Current Thread [Next in Thread]