[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 12/29] memory: inline and optimize devend_memop
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 12/29] memory: inline and optimize devend_memop |
Date: |
Mon, 16 Sep 2019 16:41:52 +0200 |
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.
Reviewed-by: Richard Henderson <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
include/exec/memory.h | 19 ++++++++++++++++++-
memory.c | 18 ------------------
2 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 2dd8102..a30245c 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -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);
+static inline MemOp devend_memop(enum device_endian end)
+{
+ QEMU_BUILD_BUG_ON(DEVICE_HOST_ENDIAN != DEVICE_LITTLE_ENDIAN &&
+ DEVICE_HOST_ENDIAN != DEVICE_BIG_ENDIAN);
+
+#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
+ /* 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
diff --git a/memory.c b/memory.c
index 61a254c..b9dd6b9 100644
--- a/memory.c
+++ b/memory.c
@@ -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();
- }
-}
--
1.8.3.1
- [Qemu-devel] [PULL 01/29] i386/kvm: support guest access CORE cstate, (continued)
- [Qemu-devel] [PULL 01/29] i386/kvm: support guest access CORE cstate, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 02/29] exec.c: replace hwaddr with uint64_t for better understanding, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 03/29] exec.c: get nodes_nb_alloc with one MAX calculation, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 04/29] exec.c: subpage->sub_section is already initialized to 0, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 06/29] exec.c: add a check between constants to see whether we could skip, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 05/29] exec.c: correct the maximum skip value during compact, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 07/29] win32: fix README file in NSIS installer, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 08/29] test-char: fix AddressSanitizer failure, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 09/29] hw/i386: Move CONFIG_ACPI_PCI to CONFIG_PC, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 10/29] elf-ops.h: fix int overflow in load_elf(), Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 12/29] memory: inline and optimize devend_memop,
Paolo Bonzini <=
- [Qemu-devel] [PULL 11/29] memory: fetch pmem size in get_file_size(), Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 15/29] hw/i386/pc: Use e820_get_num_entries() to access e820_entries, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 14/29] cpus: Fix throttling during vm_stop, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 16/29] hw/i386/pc: Extract e820 memory layout code, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 20/29] hw/i386/pc: Pass the apic_id_limit value by argument, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 13/29] qemu-thread: Add qemu_cond_timedwait, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 21/29] hw/i386/pc: Pass the CPUArchIdList array by argument, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 22/29] hw/i386/pc: Replace PCMachineState argument with MachineState in fw_cfg_arch_create, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 23/29] hw/i386/pc: Let pc_build_smbios() take a FWCfgState argument, Paolo Bonzini, 2019/09/16
- [Qemu-devel] [PULL 25/29] hw/i386/pc: Rename pc_build_smbios() as generic fw_cfg_build_smbios(), Paolo Bonzini, 2019/09/16