From patchwork Mon Jan 2 16:33:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 133888 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D50A4B6F9C for ; Tue, 3 Jan 2012 04:41:24 +1100 (EST) Received: from localhost ([::1]:45464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RhkqJ-0007NH-Nb for incoming@patchwork.ozlabs.org; Mon, 02 Jan 2012 11:34:35 -0500 Received: from eggs.gnu.org ([140.186.70.92]:35576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rhkpe-0005Zc-2m for qemu-devel@nongnu.org; Mon, 02 Jan 2012 11:34:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rhkpb-0007HT-8s for qemu-devel@nongnu.org; Mon, 02 Jan 2012 11:33:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36158) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rhkpb-0007H5-1G for qemu-devel@nongnu.org; Mon, 02 Jan 2012 11:33:51 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q02GXo6j032607 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 2 Jan 2012 11:33:50 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q02GXmlp023466 for ; Mon, 2 Jan 2012 11:33:49 -0500 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 44A78250BA4; Mon, 2 Jan 2012 18:33:43 +0200 (IST) From: Avi Kivity To: qemu-devel@nongnu.org Date: Mon, 2 Jan 2012 18:33:25 +0200 Message-Id: <1325522015-503-7-git-send-email-avi@redhat.com> In-Reply-To: <1325522015-503-1-git-send-email-avi@redhat.com> References: <1325522015-503-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/16] Avoid range comparisons on io index types X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The code sometimes uses range comparisons on io indexes (e.g. index =< IO_MEM_ROM). Avoid these as they make moving to objects harder. Signed-off-by: Avi Kivity --- exec-all.h | 2 +- exec.c | 37 ++++++++++++++++++++----------------- memory.c | 3 ++- softmmu_template.h | 6 ++++-- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/exec-all.h b/exec-all.h index 23c4598..7db22fb 100644 --- a/exec-all.h +++ b/exec-all.h @@ -354,7 +354,7 @@ static inline tb_page_addr_t get_page_addr_code(CPUState *env1, target_ulong add ldub_code(addr); } pd = env1->tlb_table[mmu_idx][page_index].addr_code & ~TARGET_PAGE_MASK; - if (pd > IO_MEM_ROM && !(pd & IO_MEM_ROMD)) { + if (pd != IO_MEM_RAM && pd != IO_MEM_ROM && !(pd & IO_MEM_ROMD)) { #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SPARC) cpu_unassigned_access(env1, addr, 0, 1, 0, 4); #else diff --git a/exec.c b/exec.c index c366835..4fc981b 100644 --- a/exec.c +++ b/exec.c @@ -2084,6 +2084,17 @@ static void tlb_add_large_page(CPUState *env, target_ulong vaddr, env->tlb_flush_mask = mask; } +static bool is_ram_rom(ram_addr_t pd) +{ + pd &= ~TARGET_PAGE_MASK; + return pd == IO_MEM_RAM || pd == IO_MEM_ROM; +} + +static bool is_ram_rom_romd(ram_addr_t pd) +{ + return is_ram_rom(pd) || (pd & IO_MEM_ROMD); +} + /* Add a new TLB entry. At most one entry for a given virtual address is permitted. Only a single TARGET_PAGE_SIZE region is mapped, the supplied size is only used by tlb_flush_page. */ @@ -2114,12 +2125,12 @@ void tlb_set_page(CPUState *env, target_ulong vaddr, #endif address = vaddr; - if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && !(pd & IO_MEM_ROMD)) { + if (!is_ram_rom(pd) && !(pd & IO_MEM_ROMD)) { /* IO memory case (romd handled later) */ address |= TLB_MMIO; } addend = (unsigned long)qemu_get_ram_ptr(pd & TARGET_PAGE_MASK); - if ((pd & ~TARGET_PAGE_MASK) <= IO_MEM_ROM) { + if (is_ram_rom(pd)) { /* Normal RAM. */ iotlb = pd & TARGET_PAGE_MASK; if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_RAM) @@ -2543,16 +2554,14 @@ void cpu_register_physical_memory_log(target_phys_addr_t start_addr, } else { p->phys_offset = phys_offset; p->region_offset = region_offset; - if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM || - (phys_offset & IO_MEM_ROMD)) + if (is_ram_rom_romd(phys_offset)) phys_offset += TARGET_PAGE_SIZE; } } else { p = phys_page_find_alloc(addr >> TARGET_PAGE_BITS, 1); p->phys_offset = phys_offset; p->region_offset = region_offset; - if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM || - (phys_offset & IO_MEM_ROMD)) { + if (is_ram_rom_romd(phys_offset)) { phys_offset += TARGET_PAGE_SIZE; } else { target_phys_addr_t start_addr2, end_addr2; @@ -3727,8 +3736,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf, qemu_put_ram_ptr(ptr); } } else { - if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && - !(pd & IO_MEM_ROMD)) { + if (!is_ram_rom_romd(pd)) { target_phys_addr_t addr1; /* I/O case */ io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); @@ -3780,9 +3788,7 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr, p = phys_page_find(page >> TARGET_PAGE_BITS); pd = p.phys_offset; - if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM && - (pd & ~TARGET_PAGE_MASK) != IO_MEM_ROM && - !(pd & IO_MEM_ROMD)) { + if (!is_ram_rom_romd(pd)) { /* do nothing */ } else { unsigned long addr1; @@ -3953,8 +3959,7 @@ static inline uint32_t ldl_phys_internal(target_phys_addr_t addr, p = phys_page_find(addr >> TARGET_PAGE_BITS); pd = p.phys_offset; - if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && - !(pd & IO_MEM_ROMD)) { + if (!is_ram_rom_romd(pd)) { /* I/O case */ io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); addr = (addr & ~TARGET_PAGE_MASK) + p.region_offset; @@ -4015,8 +4020,7 @@ static inline uint64_t ldq_phys_internal(target_phys_addr_t addr, p = phys_page_find(addr >> TARGET_PAGE_BITS); pd = p.phys_offset; - if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && - !(pd & IO_MEM_ROMD)) { + if (!is_ram_rom_romd(pd)) { /* I/O case */ io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); addr = (addr & ~TARGET_PAGE_MASK) + p.region_offset; @@ -4085,8 +4089,7 @@ static inline uint32_t lduw_phys_internal(target_phys_addr_t addr, p = phys_page_find(addr >> TARGET_PAGE_BITS); pd = p.phys_offset; - if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && - !(pd & IO_MEM_ROMD)) { + if (is_ram_rom_romd(pd)) { /* I/O case */ io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); addr = (addr & ~TARGET_PAGE_MASK) + p.region_offset; diff --git a/memory.c b/memory.c index 63dc3dc..66accba 100644 --- a/memory.c +++ b/memory.c @@ -312,7 +312,8 @@ static void as_memory_range_add(AddressSpace *as, FlatRange *fr) /* cpu_register_physical_memory_log() wants region_offset for * mmio, but prefers offseting phys_offset for RAM. Humour it. */ - if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM) { + if ((phys_offset & ~TARGET_PAGE_MASK) == IO_MEM_RAM + || (phys_offset & ~TARGET_PAGE_MASK) == IO_MEM_ROM) { phys_offset += region_offset; region_offset = 0; } diff --git a/softmmu_template.h b/softmmu_template.h index a030b5f..726744c 100644 --- a/softmmu_template.h +++ b/softmmu_template.h @@ -65,7 +65,8 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr, index = (physaddr >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); physaddr = (physaddr & TARGET_PAGE_MASK) + addr; env->mem_io_pc = (unsigned long)retaddr; - if (index > (IO_MEM_NOTDIRTY >> IO_MEM_SHIFT) + if (index != IO_MEM_RAM && index != IO_MEM_ROM + && index != IO_MEM_UNASSIGNED && index != IO_MEM_NOTDIRTY && !can_do_io(env)) { cpu_io_recompile(env, retaddr); } @@ -207,7 +208,8 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr, int index; index = (physaddr >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); physaddr = (physaddr & TARGET_PAGE_MASK) + addr; - if (index > (IO_MEM_NOTDIRTY >> IO_MEM_SHIFT) + if (index != IO_MEM_RAM && index != IO_MEM_ROM + && index != IO_MEM_UNASSIGNED && index != IO_MEM_NOTDIRTY && !can_do_io(env)) { cpu_io_recompile(env, retaddr); }