Skip to contentSkip to conversation

exec.c remove unnecessary operators on functions

PATCH In review Robert Reif 1 participant 2 messages Feb 20, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 exec.c remove unnecessary operators on functions

This patch removes unnecessary *function and &function usage.

Also, why is it necessary to take the address of a variable holding a function address rather than saving the function address directly in exec.c lines 2766 and 2771?

exec.c +10 -10
@@ -2658,7 +2658,7 @@
     printf("%s: subpage %p len %d addr " TARGET_FMT_plx " idx %d\n", __func__,
            mmio, len, addr, idx);
 #endif
-    ret = (**mmio->mem_read[idx][len])(mmio->opaque[idx][0][len],
+    ret = (*mmio->mem_read[idx][len])(mmio->opaque[idx][0][len],
                                        addr + mmio->region_offset[idx][0][len]);
 
     return ret;
@@ -2674,7 +2674,7 @@
     printf("%s: subpage %p len %d addr " TARGET_FMT_plx " idx %d value %08x\n", __func__,
            mmio, len, addr, idx, value);
 #endif
-    (**mmio->mem_write[idx][len])(mmio->opaque[idx][1][len],
+    (*mmio->mem_write[idx][len])(mmio->opaque[idx][1][len],
                                   addr + mmio->region_offset[idx][1][len],
                                   value);
 }
@@ -2733,16 +2733,16 @@
     subpage_writelen(opaque, addr, value, 2);
 }
 
-static CPUReadMemoryFunc *subpage_read[] = {
-    &subpage_readb,
-    &subpage_readw,
-    &subpage_readl,
+static CPUReadMemoryFunc *subpage_read[3] = {
+    subpage_readb,
+    subpage_readw,
+    subpage_readl,
 };
 
-static CPUWriteMemoryFunc *subpage_write[] = {
-    &subpage_writeb,
-    &subpage_writew,
-    &subpage_writel,
+static CPUWriteMemoryFunc *subpage_write[3] = {
+    subpage_writeb,
+    subpage_writew,
+    subpage_writel,
 };
 
 static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,
#1 lore raw
Quoted 6 lines · Robert Reif

Also, why is it necessary to take the address of a variable holding a function address rather than saving the function address directly in exec.c lines 2766 and 2771?

This removes the extra level of indirection. Comments?

exec.c +14 -14
@@ -197,8 +197,8 @@
 #define SUBPAGE_IDX(addr) ((addr) & ~TARGET_PAGE_MASK)
 typedef struct subpage_t {
     target_phys_addr_t base;
-    CPUReadMemoryFunc **mem_read[TARGET_PAGE_SIZE][4];
-    CPUWriteMemoryFunc **mem_write[TARGET_PAGE_SIZE][4];
+    CPUReadMemoryFunc *mem_read[TARGET_PAGE_SIZE][4];
+    CPUWriteMemoryFunc *mem_write[TARGET_PAGE_SIZE][4];
     void *opaque[TARGET_PAGE_SIZE][2][4];
     ram_addr_t region_offset[TARGET_PAGE_SIZE][2][4];
 } subpage_t;
@@ -2658,7 +2658,7 @@
     printf("%s: subpage %p len %d addr " TARGET_FMT_plx " idx %d\n", __func__,
            mmio, len, addr, idx);
 #endif
-    ret = (**mmio->mem_read[idx][len])(mmio->opaque[idx][0][len],
+    ret = mmio->mem_read[idx][len](mmio->opaque[idx][0][len],
                                        addr + mmio->region_offset[idx][0][len]);
 
     return ret;
@@ -2674,7 +2674,7 @@
     printf("%s: subpage %p len %d addr " TARGET_FMT_plx " idx %d value %08x\n", __func__,
            mmio, len, addr, idx, value);
 #endif
-    (**mmio->mem_write[idx][len])(mmio->opaque[idx][1][len],
+    mmio->mem_write[idx][len](mmio->opaque[idx][1][len],
                                   addr + mmio->region_offset[idx][1][len],
                                   value);
 }
@@ -2733,16 +2733,16 @@
     subpage_writelen(opaque, addr, value, 2);
 }
 
-static CPUReadMemoryFunc *subpage_read[] = {
-    &subpage_readb,
-    &subpage_readw,
-    &subpage_readl,
+static CPUReadMemoryFunc *subpage_read[3] = {
+    subpage_readb,
+    subpage_readw,
+    subpage_readl,
 };
 
-static CPUWriteMemoryFunc *subpage_write[] = {
-    &subpage_writeb,
-    &subpage_writew,
-    &subpage_writel,
+static CPUWriteMemoryFunc *subpage_write[3] = {
+    subpage_writeb,
+    subpage_writew,
+    subpage_writel,
 };
 
 static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end,
@@ -2763,12 +2763,12 @@
     for (; idx <= eidx; idx++) {
         for (i = 0; i < 4; i++) {
             if (io_mem_read[memory][i]) {
-                mmio->mem_read[idx][i] = &io_mem_read[memory][i];
+                mmio->mem_read[idx][i] = io_mem_read[memory][i];
                 mmio->opaque[idx][0][i] = io_mem_opaque[memory];
                 mmio->region_offset[idx][0][i] = region_offset;
             }
             if (io_mem_write[memory][i]) {
-                mmio->mem_write[idx][i] = &io_mem_write[memory][i];
+                mmio->mem_write[idx][i] = io_mem_write[memory][i];
                 mmio->opaque[idx][1][i] = io_mem_opaque[memory];
                 mmio->region_offset[idx][1][i] = region_offset;
             }