Skip to contentSkip to conversation

memory: inline and optimize devend_memop

PATCH In review Paolo Bonzini 3 participants 3 messages Sep 12, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memory: inline and optimize devend_memop

devend_memop can rely on the fact that the result is always either 0 or MO_BSWAP, corresponding respectively to host endianness and the opposite. Native (target) endianness in turn can be either the host endianness, in which case MO_BSWAP is only returned for host-opposite endianness, or the opposite, in which case 0 is only returned for host endianness.

With this in mind, devend_memop can be compiled as a setcond+shift for every target. Do this and, while at it, move it to include/exec/memory.h since !NEED_CPU_H files do not (and should not) need it.

---
 include/exec/memory.h | 19 ++++++++++++++++++-
 memory.c              | 18 ------------------
 2 files changed, 18 insertions(+), 19 deletions(-)
include/exec/memory.h +18 -1
index 2dd810259d..d898cfb5db 100644
@@ -2201,8 +2201,25 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
     }
 }
 
+#ifdef NEED_CPU_H
 /* enum device_endian to MemOp.  */
-MemOp devend_memop(enum device_endian end);
+MemOp devend_memop(enum device_endian end)
+{
+    QEMU_BUILD_BUG_ON(DEVICE_HOST_ENDIAN != DEVICE_LITTLE_ENDIAN &&
+                      DEVICE_HOST_ENDIAN != DEVICE_BIG_ENDIAN);
+
+#ifdef BSWAP_NEEDED
+    /* Swap if non-host endianness or native (target) endianness */
+    return (end == DEVICE_HOST_ENDIAN) ? 0 : MO_BSWAP;
+#else
+    const int non_host_endianness =
+        DEVICE_LITTLE_ENDIAN ^ DEVICE_BIG_ENDIAN ^ DEVICE_HOST_ENDIAN;
+
+    /* In this case, native (target) endianness needs no swap.  */
+    return (end == non_host_endianness) ? MO_BSWAP : 0;
+#endif
+}
+#endif
 
 #endif
 
memory.c +0 -18
index 61a254c3f9..b9dd6b94ca 100644
@@ -3267,21 +3267,3 @@ static void memory_register_types(void)
 }
 
 type_init(memory_register_types)
-
-MemOp devend_memop(enum device_endian end)
-{
-    static MemOp conv[] = {
-        [DEVICE_LITTLE_ENDIAN] = MO_LE,
-        [DEVICE_BIG_ENDIAN] = MO_BE,
-        [DEVICE_NATIVE_ENDIAN] = MO_TE,
-        [DEVICE_HOST_ENDIAN] = 0,
-    };
-    switch (end) {
-    case DEVICE_LITTLE_ENDIAN:
-    case DEVICE_BIG_ENDIAN:
-    case DEVICE_NATIVE_ENDIAN:
-        return conv[end];
-    default:
-        g_assert_not_reached();
-    }
-}
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · Paolo Bonzini

devend_memop can rely on the fact that the result is always either 0 or MO_BSWAP, corresponding respectively to host endianness and the opposite. Native (target) endianness in turn can be either the host endianness, in which case MO_BSWAP is only returned for host-opposite endianness, or the opposite, in which case 0 is only returned for host endianness.

With this in mind, devend_memop can be compiled as a setcond+shift for every target. Do this and, while at it, move it to include/exec/memory.h since !NEED_CPU_H files do not (and should not) need it.

Quoted 5 lines
---
 include/exec/memory.h | 19 ++++++++++++++++++-
 memory.c              | 18 ------------------
 2 files changed, 18 insertions(+), 19 deletions(-)

r~

#2 lore raw
In reply to Paolo Bonzini
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series failed the docker-quick@centos7 build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-centos7 V=1 NETWORK=1
time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===

libudev no
default devices yes

warning: Python 2 support is deprecated
warning: Python 3 will be required for building future versions of QEMU cross containers no

NOTE: guest cross-compilers enabled: cc
---
In file included from /tmp/qemu-test/src/include/exec/cpu-all.h:23:0,

                 from /tmp/qemu-test/src/target/i386/cpu.h:1792,
                 from /tmp/qemu-test/src/disas.c:7:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
                 from /tmp/qemu-test/src/target/i386/cpu.h:1792,
                 from /tmp/qemu-test/src/tcg/tcg.h:28,
                 from /tmp/qemu-test/src/tcg/tcg-common.c:26:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
In file included from /tmp/qemu-test/src/include/exec/cpu-all.h:23:0,
                 from /tmp/qemu-test/src/target/i386/cpu.h:1792,
                 from /tmp/qemu-test/src/exec.c:25:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
In file included from /tmp/qemu-test/src/include/exec/cpu-all.h:23:0,
                 from /tmp/qemu-test/src/target/i386/cpu.h:1792,
                 from /tmp/qemu-test/src/arch_init.c:25:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
In file included from /tmp/qemu-test/src/include/exec/cpu-all.h:23:0,
                 from /tmp/qemu-test/src/target/arm/cpu.h:3141,
                 from /tmp/qemu-test/src/exec.c:25:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
In file included from /tmp/qemu-test/src/include/exec/cpu-all.h:23:0,
                 from /tmp/qemu-test/src/target/i386/cpu.h:1792,
                 from /tmp/qemu-test/src/tcg/tcg-op-vec.c:21:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
                 from /tmp/qemu-test/src/target/i386/cpu.h:1792,
                 from /tmp/qemu-test/src/tcg/tcg.h:28,
                 from /tmp/qemu-test/src/tcg/tcg-op-gvec.c:21:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
                 from /tmp/qemu-test/src/target/arm/cpu.h:3141,
                 from /tmp/qemu-test/src/tcg/tcg.h:28,
                 from /tmp/qemu-test/src/tcg/tcg-common.c:26:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
                 from /tmp/qemu-test/src/tcg/tcg.h:28,
                 from /tmp/qemu-test/src/tcg/tcg-op.h:28,
                 from /tmp/qemu-test/src/tcg/optimize.c:27:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
In file included from /tmp/qemu-test/src/include/exec/cpu-all.h:23:0,
                 from /tmp/qemu-test/src/target/i386/cpu.h:1792,
                 from /tmp/qemu-test/src/tcg/tcg-op.c:26:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
In file included from /tmp/qemu-test/src/include/exec/cpu-all.h:23:0,
                 from /tmp/qemu-test/src/target/i386/cpu.h:1792,
                 from /tmp/qemu-test/src/tcg/tcg.c:43:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
In file included from /tmp/qemu-test/src/include/exec/cpu-all.h:23:0,
                 from /tmp/qemu-test/src/target/arm/cpu.h:3141,
                 from /tmp/qemu-test/src/tcg/tcg-op.c:26:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
In file included from /tmp/qemu-test/src/include/exec/cpu-all.h:23:0,
                 from /tmp/qemu-test/src/target/arm/cpu.h:3141,
                 from /tmp/qemu-test/src/tcg/tcg-op-vec.c:21:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
                 from /tmp/qemu-test/src/target/arm/cpu.h:3141,
                 from /tmp/qemu-test/src/tcg/tcg.h:28,
                 from /tmp/qemu-test/src/tcg/tcg-op-gvec.c:21:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^
cc1: all warnings being treated as errors
---
In file included from /tmp/qemu-test/src/include/exec/cpu-all.h:23:0,
                 from /tmp/qemu-test/src/target/arm/cpu.h:3141,
                 from /tmp/qemu-test/src/tcg/tcg.c:43:
/tmp/qemu-test/src/include/exec/memory.h:2206:7: error: no previous prototype for 'devend_memop' [-Werror=missing-prototypes]
 MemOp devend_memop(enum device_endian end)
       ^

cc1: all warnings being treated as errors

The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-quick@centos7/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]