From patchwork Thu Sep 7 22:40:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111973 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp721773qge; Thu, 7 Sep 2017 15:43:29 -0700 (PDT) X-Received: by 10.200.45.26 with SMTP id n26mr1381691qta.183.1504824209731; Thu, 07 Sep 2017 15:43:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824209; cv=none; d=google.com; s=arc-20160816; b=a8ozWzIBlpUScR/0Y9ipLFmu/nphlsSjbISfojMHV2Mz1W+ZVisgDurAvtrp35hM9/ 13kWj6NceiD2K2/hzuuZ7ImxiPf1OQHTeAUw6WyR33ta9TGa0+JUv52lE8QXRD3KmfgX BNt8ZYggIYkOXFzOygpH43+rraSqpI3D9PWsf8ovrgj5sKe3bsdwkydBrBifasQgRQKe sxeHqTfV4Gpwni8gI4u1e3c1RvKZOxhY98R7q0SsDzxHeADsMU5FSBk0OljntY/u3AIZ I3tCwMWHwb4YLaazgKQcYrSh8dzf7pFQZqXI2qaWPLln0BlgFkubahkvi8eX+B4HdjG5 TGKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=K/R2gnM8fsYbqRdhzqJY4H3SJFOLlrFJBxKGEBBoreY=; b=JOEEb2Cml4MAFQW3dW1s3E3K7sYKJaEPlsr8brLgkx3OUrtEg4fiQvOnypjuIbtDRR JEJ3QZXXv0fixiP0jP6MzZRyawqi2Ra/D/JTelZCegkJ6rS8u+FeLVsgiNFDzGuZ4hlU UGt3/TMY6dGrKUgQhhQkqsC8NVKM3nOucvM8CeisU3b9WcQpqcLaLtuCFAtKv6hSGKWK Je914uk85b8ggpNprQ+Pie0FQND6H+BfFbol763qQT/2Ns83++TfbmolWr5Z6xdFBdT0 3j0PDnQkWc+Wqz1GD91SljCvuVIXWmO2A7r3AapIY2HfqPXh7V7/xmcibypJlQwODBgg D9IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iNLY8+ec; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x88si454321qte.437.2017.09.07.15.43.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:43:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=iNLY8+ec; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5WB-0004XN-8d for patch@linaro.org; Thu, 07 Sep 2017 18:43:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Tr-0002xL-Fj for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5Tl-0007zB-At for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:03 -0400 Received: from mail-pg0-x22c.google.com ([2607:f8b0:400e:c05::22c]:36680) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5Tl-0007yM-1K for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:40:57 -0400 Received: by mail-pg0-x22c.google.com with SMTP id m9so1817621pgd.3 for ; Thu, 07 Sep 2017 15:40:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=K/R2gnM8fsYbqRdhzqJY4H3SJFOLlrFJBxKGEBBoreY=; b=iNLY8+ecvky4JB4uUapfm0nOGvOqrFqFAx2w0GuGl28yTD0UGZooGTK1K3sZMCRV3X 6rQwAPex0E7tVwHCq6K/s9nry6y64DTQbl168kUD2rDrpt0s7oodjtaEVj0X845O+yLU RgEwJAL9UMJe3PQkIj+oOMeWFwCcRlqn+Ypto= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=K/R2gnM8fsYbqRdhzqJY4H3SJFOLlrFJBxKGEBBoreY=; b=oSKPhGjubDENZCnqNae8X75DNK/lWST76zoadB740SdUwP4FMkfSCgb4xnZ2jGR2c9 K8612Byi9/a2rJrdAED7vGfVfK6GbbfYRibmaQX98NM/hsT3B7G59AQIqOk1C4ZyAt/U BCcU/qkK2uPq3OSS+H3bZ/jQ9VhISU17eRL/scNrhfWiODd7bfLOvTGY64KxNPhOP0YG UvSxnEUCfJyUBM32Lsu21ECR075pEROPLuNPrl0ndrcEO7Y54cMrfW+C+L5gK1D1rH6R NlL7bCRlczhlwCDbZ0yEd/SyY25en/T639w0iTpO+vek2pBJg23FbjJx6G2QJPrHum1K Zr8w== X-Gm-Message-State: AHPjjUgbOtoTSJAeQA9UJqQ2U/SHy2oshpliyn9RIB5zVGUR6uT/7pQp lMABpOKY/ytrNSo8xiGQnw== X-Google-Smtp-Source: ADKCNb7Np6c2Ybo7/EeNnjgrPnS3HZH0N9dIeH9x7iRLYC2mjV25hwXIsEx3i7s9zXTOn2MwIZRVBQ== X-Received: by 10.98.10.146 with SMTP id 18mr952466pfk.346.1504824055503; Thu, 07 Sep 2017 15:40:55 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.40.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:40:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:29 -0700 Message-Id: <20170907224051.21518-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::22c Subject: [Qemu-devel] [PULL 01/23] tcg: Move USE_DIRECT_JUMP discriminator to tcg/cpu/tcg-target.h X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Replace the USE_DIRECT_JUMP ifdef with a TCG_TARGET_HAS_direct_jump boolean test. Replace the tb_set_jmp_target1 ifdef with an unconditional function tb_target_set_jmp_target. While we're touching all backends, add a parameter for tb->tc_ptr; we're going to need it shortly for some backends. Move tb_set_jmp_target and tb_add_jump from exec-all.h to cpu-exec.c. This opens the possibility for TCG_TARGET_HAS_direct_jump to be a runtime decision -- based on host cpu capabilities, the size of code_gen_buffer, or a future debugging switch. Signed-off-by: Richard Henderson --- include/exec/exec-all.h | 95 ++------------------------------------------ tcg/aarch64/tcg-target.h | 5 ++- tcg/arm/tcg-target.h | 6 ++- tcg/i386/tcg-target.h | 9 +++++ tcg/mips/tcg-target.h | 5 ++- tcg/ppc/tcg-target.h | 2 + tcg/s390/tcg-target.h | 10 +++++ tcg/sparc/tcg-target.h | 3 ++ tcg/tcg.h | 4 +- tcg/tci/tcg-target.h | 9 +++++ accel/tcg/cpu-exec.c | 35 ++++++++++++++++ accel/tcg/translate-all.c | 14 +++---- tcg/aarch64/tcg-target.inc.c | 13 +++--- tcg/mips/tcg-target.inc.c | 3 +- tcg/ppc/tcg-target.inc.c | 6 ++- tcg/sparc/tcg-target.inc.c | 3 +- 16 files changed, 106 insertions(+), 116 deletions(-) -- 2.13.5 diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index ff8fbe423d..673fc066d0 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -301,15 +301,6 @@ static inline void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr) #define CODE_GEN_AVG_BLOCK_SIZE 150 #endif -#if defined(_ARCH_PPC) \ - || defined(__x86_64__) || defined(__i386__) \ - || defined(__sparc__) || defined(__aarch64__) \ - || defined(__s390x__) || defined(__mips__) \ - || defined(CONFIG_TCG_INTERPRETER) -/* NOTE: Direct jump patching must be atomic to be thread-safe. */ -#define USE_DIRECT_JUMP -#endif - struct TranslationBlock { target_ulong pc; /* simulated PC corresponding to this block (EIP + CS base) */ target_ulong cs_base; /* CS base for this block */ @@ -347,11 +338,8 @@ struct TranslationBlock { */ uint16_t jmp_reset_offset[2]; /* offset of original jump target */ #define TB_JMP_RESET_OFFSET_INVALID 0xffff /* indicates no jump generated */ -#ifdef USE_DIRECT_JUMP - uint16_t jmp_insn_offset[2]; /* offset of native jump instruction */ -#else - uintptr_t jmp_target_addr[2]; /* target address for indirect jump */ -#endif + uintptr_t jmp_target_arg[2]; /* target address or offset */ + /* Each TB has an assosiated circular list of TBs jumping to this one. * jmp_list_first points to the first TB jumping to this one. * jmp_list_next is used to point to the next TB in a list. @@ -373,84 +361,7 @@ void tb_flush(CPUState *cpu); void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr); TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, target_ulong cs_base, uint32_t flags); - -#if defined(USE_DIRECT_JUMP) - -#if defined(CONFIG_TCG_INTERPRETER) -static inline void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr) -{ - /* patch the branch destination */ - atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4)); - /* no need to flush icache explicitly */ -} -#elif defined(_ARCH_PPC) -void ppc_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr); -#define tb_set_jmp_target1 ppc_tb_set_jmp_target -#elif defined(__i386__) || defined(__x86_64__) -static inline void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr) -{ - /* patch the branch destination */ - atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4)); - /* no need to flush icache explicitly */ -} -#elif defined(__s390x__) -static inline void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr) -{ - /* patch the branch destination */ - intptr_t disp = addr - (jmp_addr - 2); - atomic_set((int32_t *)jmp_addr, disp / 2); - /* no need to flush icache explicitly */ -} -#elif defined(__aarch64__) -void aarch64_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr); -#define tb_set_jmp_target1 aarch64_tb_set_jmp_target -#elif defined(__sparc__) || defined(__mips__) -void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr); -#else -#error tb_set_jmp_target1 is missing -#endif - -static inline void tb_set_jmp_target(TranslationBlock *tb, - int n, uintptr_t addr) -{ - uint16_t offset = tb->jmp_insn_offset[n]; - tb_set_jmp_target1((uintptr_t)(tb->tc_ptr + offset), addr); -} - -#else - -/* set the jump target */ -static inline void tb_set_jmp_target(TranslationBlock *tb, - int n, uintptr_t addr) -{ - tb->jmp_target_addr[n] = addr; -} - -#endif - -/* Called with tb_lock held. */ -static inline void tb_add_jump(TranslationBlock *tb, int n, - TranslationBlock *tb_next) -{ - assert(n < ARRAY_SIZE(tb->jmp_list_next)); - if (tb->jmp_list_next[n]) { - /* Another thread has already done this while we were - * outside of the lock; nothing to do in this case */ - return; - } - qemu_log_mask_and_addr(CPU_LOG_EXEC, tb->pc, - "Linking TBs %p [" TARGET_FMT_lx - "] index %d -> %p [" TARGET_FMT_lx "]\n", - tb->tc_ptr, tb->pc, n, - tb_next->tc_ptr, tb_next->pc); - - /* patch the native jump address */ - tb_set_jmp_target(tb, n, (uintptr_t)tb_next->tc_ptr); - - /* add in TB jmp circular list */ - tb->jmp_list_next[n] = tb_next->jmp_list_first; - tb_next->jmp_list_first = (uintptr_t)tb | n; -} +void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr); /* GETPC is the true target of the return instruction that we'll execute. */ #if defined(CONFIG_TCG_INTERPRETER) diff --git a/tcg/aarch64/tcg-target.h b/tcg/aarch64/tcg-target.h index b41a248bee..719861fe3e 100644 --- a/tcg/aarch64/tcg-target.h +++ b/tcg/aarch64/tcg-target.h @@ -111,12 +111,15 @@ typedef enum { #define TCG_TARGET_HAS_muls2_i64 0 #define TCG_TARGET_HAS_muluh_i64 1 #define TCG_TARGET_HAS_mulsh_i64 1 +#define TCG_TARGET_HAS_direct_jump 1 + +#define TCG_TARGET_DEFAULT_MO (0) static inline void flush_icache_range(uintptr_t start, uintptr_t stop) { __builtin___clear_cache((char *)start, (char *)stop); } -#define TCG_TARGET_DEFAULT_MO (0) +void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); #endif /* AARCH64_TCG_TARGET_H */ diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h index a38be15a39..7117ebf4fc 100644 --- a/tcg/arm/tcg-target.h +++ b/tcg/arm/tcg-target.h @@ -124,16 +124,20 @@ extern bool use_idiv_instructions; #define TCG_TARGET_HAS_div_i32 use_idiv_instructions #define TCG_TARGET_HAS_rem_i32 0 #define TCG_TARGET_HAS_goto_ptr 1 +#define TCG_TARGET_HAS_direct_jump 0 enum { TCG_AREG0 = TCG_REG_R6, }; +#define TCG_TARGET_DEFAULT_MO (0) + static inline void flush_icache_range(uintptr_t start, uintptr_t stop) { __builtin___clear_cache((char *) start, (char *) stop); } -#define TCG_TARGET_DEFAULT_MO (0) +/* not defined -- call should be eliminated at compile time */ +void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); #endif diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h index 73a15f7e80..2fd28fa6a5 100644 --- a/tcg/i386/tcg-target.h +++ b/tcg/i386/tcg-target.h @@ -108,6 +108,7 @@ extern bool have_popcnt; #define TCG_TARGET_HAS_muluh_i32 0 #define TCG_TARGET_HAS_mulsh_i32 0 #define TCG_TARGET_HAS_goto_ptr 1 +#define TCG_TARGET_HAS_direct_jump 1 #if TCG_TARGET_REG_BITS == 64 #define TCG_TARGET_HAS_extrl_i64_i32 0 @@ -166,6 +167,14 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop) { } +static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, + uintptr_t jmp_addr, uintptr_t addr) +{ + /* patch the branch destination */ + atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4)); + /* no need to flush icache explicitly */ +} + /* This defines the natural memory order supported by this * architecture before guarantees made by various barrier * instructions. diff --git a/tcg/mips/tcg-target.h b/tcg/mips/tcg-target.h index e9558d15bc..928a762bd7 100644 --- a/tcg/mips/tcg-target.h +++ b/tcg/mips/tcg-target.h @@ -131,6 +131,7 @@ extern bool use_mips32r2_instructions; #define TCG_TARGET_HAS_mulsh_i32 1 #define TCG_TARGET_HAS_bswap32_i32 1 #define TCG_TARGET_HAS_goto_ptr 1 +#define TCG_TARGET_HAS_direct_jump 1 #if TCG_TARGET_REG_BITS == 64 #define TCG_TARGET_HAS_add2_i32 0 @@ -201,11 +202,13 @@ extern bool use_mips32r2_instructions; #include #endif +#define TCG_TARGET_DEFAULT_MO (0) + static inline void flush_icache_range(uintptr_t start, uintptr_t stop) { cacheflush ((void *)start, stop-start, ICACHE); } -#define TCG_TARGET_DEFAULT_MO (0) +void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); #endif diff --git a/tcg/ppc/tcg-target.h b/tcg/ppc/tcg-target.h index 5a092b038a..aa44e715d8 100644 --- a/tcg/ppc/tcg-target.h +++ b/tcg/ppc/tcg-target.h @@ -83,6 +83,7 @@ extern bool have_isa_3_00; #define TCG_TARGET_HAS_muluh_i32 1 #define TCG_TARGET_HAS_mulsh_i32 1 #define TCG_TARGET_HAS_goto_ptr 1 +#define TCG_TARGET_HAS_direct_jump 1 #if TCG_TARGET_REG_BITS == 64 #define TCG_TARGET_HAS_add2_i32 0 @@ -124,6 +125,7 @@ extern bool have_isa_3_00; #endif void flush_icache_range(uintptr_t start, uintptr_t stop); +void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); #define TCG_TARGET_DEFAULT_MO (0) diff --git a/tcg/s390/tcg-target.h b/tcg/s390/tcg-target.h index bedda5edf6..31a9eb4ac7 100644 --- a/tcg/s390/tcg-target.h +++ b/tcg/s390/tcg-target.h @@ -95,6 +95,7 @@ extern uint64_t s390_facilities; #define TCG_TARGET_HAS_extrl_i64_i32 0 #define TCG_TARGET_HAS_extrh_i64_i32 0 #define TCG_TARGET_HAS_goto_ptr 1 +#define TCG_TARGET_HAS_direct_jump 1 #define TCG_TARGET_HAS_div2_i64 1 #define TCG_TARGET_HAS_rot_i64 1 @@ -145,4 +146,13 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop) { } +static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, + uintptr_t jmp_addr, uintptr_t addr) +{ + /* patch the branch destination */ + intptr_t disp = addr - (jmp_addr - 2); + atomic_set((int32_t *)jmp_addr, disp / 2); + /* no need to flush icache explicitly */ +} + #endif diff --git a/tcg/sparc/tcg-target.h b/tcg/sparc/tcg-target.h index 4515c9ab48..da98743817 100644 --- a/tcg/sparc/tcg-target.h +++ b/tcg/sparc/tcg-target.h @@ -124,6 +124,7 @@ extern bool use_vis3_instructions; #define TCG_TARGET_HAS_muluh_i32 0 #define TCG_TARGET_HAS_mulsh_i32 0 #define TCG_TARGET_HAS_goto_ptr 1 +#define TCG_TARGET_HAS_direct_jump 1 #define TCG_TARGET_HAS_extrl_i64_i32 1 #define TCG_TARGET_HAS_extrh_i64_i32 1 @@ -172,4 +173,6 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop) } } +void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); + #endif diff --git a/tcg/tcg.h b/tcg/tcg.h index 17b7750ee6..46957d9bd7 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -652,8 +652,8 @@ struct TCGContext { /* goto_tb support */ tcg_insn_unit *code_buf; uint16_t *tb_jmp_reset_offset; /* tb->jmp_reset_offset */ - uint16_t *tb_jmp_insn_offset; /* tb->jmp_insn_offset if USE_DIRECT_JUMP */ - uintptr_t *tb_jmp_target_addr; /* tb->jmp_target_addr if !USE_DIRECT_JUMP */ + uintptr_t *tb_jmp_insn_offset; /* tb->jmp_target_arg if direct_jump */ + uintptr_t *tb_jmp_target_addr; /* tb->jmp_target_arg if !direct_jump */ TCGRegSet reserved_regs; intptr_t current_frame_offset; diff --git a/tcg/tci/tcg-target.h b/tcg/tci/tcg-target.h index 8df628a319..26140d78cb 100644 --- a/tcg/tci/tcg-target.h +++ b/tcg/tci/tcg-target.h @@ -86,6 +86,7 @@ #define TCG_TARGET_HAS_muluh_i32 0 #define TCG_TARGET_HAS_mulsh_i32 0 #define TCG_TARGET_HAS_goto_ptr 0 +#define TCG_TARGET_HAS_direct_jump 1 #if TCG_TARGET_REG_BITS == 64 #define TCG_TARGET_HAS_extrl_i64_i32 0 @@ -197,4 +198,12 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop) We prefer consistency across hosts on this. */ #define TCG_TARGET_DEFAULT_MO (0) +static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, + uintptr_t jmp_addr, uintptr_t addr) +{ + /* patch the branch destination */ + atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4)); + /* no need to flush icache explicitly */ +} + #endif /* TCG_TARGET_H */ diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index d84b01d1b8..ff6866624a 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -329,6 +329,41 @@ TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, return qht_lookup(&tcg_ctx.tb_ctx.htable, tb_cmp, &desc, h); } +void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr) +{ + if (TCG_TARGET_HAS_direct_jump) { + uintptr_t offset = tb->jmp_target_arg[n]; + uintptr_t tc_ptr = (uintptr_t)tb->tc_ptr; + tb_target_set_jmp_target(tc_ptr, tc_ptr + offset, addr); + } else { + tb->jmp_target_arg[n] = addr; + } +} + +/* Called with tb_lock held. */ +static inline void tb_add_jump(TranslationBlock *tb, int n, + TranslationBlock *tb_next) +{ + assert(n < ARRAY_SIZE(tb->jmp_list_next)); + if (tb->jmp_list_next[n]) { + /* Another thread has already done this while we were + * outside of the lock; nothing to do in this case */ + return; + } + qemu_log_mask_and_addr(CPU_LOG_EXEC, tb->pc, + "Linking TBs %p [" TARGET_FMT_lx + "] index %d -> %p [" TARGET_FMT_lx "]\n", + tb->tc_ptr, tb->pc, n, + tb_next->tc_ptr, tb_next->pc); + + /* patch the native jump address */ + tb_set_jmp_target(tb, n, (uintptr_t)tb_next->tc_ptr); + + /* add in TB jmp circular list */ + tb->jmp_list_next[n] = tb_next->jmp_list_first; + tb_next->jmp_list_first = (uintptr_t)tb | n; +} + static inline TranslationBlock *tb_find(CPUState *cpu, TranslationBlock *last_tb, int tb_exit) diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 37ecafa931..93a1cf2ba8 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1289,13 +1289,13 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->jmp_reset_offset[0] = TB_JMP_RESET_OFFSET_INVALID; tb->jmp_reset_offset[1] = TB_JMP_RESET_OFFSET_INVALID; tcg_ctx.tb_jmp_reset_offset = tb->jmp_reset_offset; -#ifdef USE_DIRECT_JUMP - tcg_ctx.tb_jmp_insn_offset = tb->jmp_insn_offset; - tcg_ctx.tb_jmp_target_addr = NULL; -#else - tcg_ctx.tb_jmp_insn_offset = NULL; - tcg_ctx.tb_jmp_target_addr = tb->jmp_target_addr; -#endif + if (TCG_TARGET_HAS_direct_jump) { + tcg_ctx.tb_jmp_insn_offset = tb->jmp_target_arg; + tcg_ctx.tb_jmp_target_addr = NULL; + } else { + tcg_ctx.tb_jmp_insn_offset = NULL; + tcg_ctx.tb_jmp_target_addr = tb->jmp_target_arg; + } #ifdef CONFIG_PROFILER tcg_ctx.tb_count++; diff --git a/tcg/aarch64/tcg-target.inc.c b/tcg/aarch64/tcg-target.inc.c index 04bc369a92..a1e5dd2f03 100644 --- a/tcg/aarch64/tcg-target.inc.c +++ b/tcg/aarch64/tcg-target.inc.c @@ -871,9 +871,8 @@ static inline void tcg_out_call(TCGContext *s, tcg_insn_unit *target) } } -#ifdef USE_DIRECT_JUMP - -void aarch64_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr) +void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, + uintptr_t addr) { tcg_insn_unit i1, i2; TCGType rt = TCG_TYPE_I64; @@ -898,8 +897,6 @@ void aarch64_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr) flush_icache_range(jmp_addr, jmp_addr + 8); } -#endif - static inline void tcg_out_goto_label(TCGContext *s, TCGLabel *l) { if (!l->has_value) { @@ -1412,7 +1409,7 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, case INDEX_op_goto_tb: if (s->tb_jmp_insn_offset != NULL) { - /* USE_DIRECT_JUMP */ + /* TCG_TARGET_HAS_direct_jump */ /* Ensure that ADRP+ADD are 8-byte aligned so that an atomic write can be used to patch the target address. */ if ((uintptr_t)s->code_ptr & 7) { @@ -1420,11 +1417,11 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, } s->tb_jmp_insn_offset[a0] = tcg_current_code_size(s); /* actual branch destination will be patched by - aarch64_tb_set_jmp_target later. */ + tb_target_set_jmp_target later. */ tcg_out_insn(s, 3406, ADRP, TCG_REG_TMP, 0); tcg_out_insn(s, 3401, ADDI, TCG_TYPE_I64, TCG_REG_TMP, TCG_REG_TMP, 0); } else { - /* !USE_DIRECT_JUMP */ + /* !TCG_TARGET_HAS_direct_jump */ tcg_debug_assert(s->tb_jmp_target_addr != NULL); intptr_t offset = tcg_pcrel_diff(s, (s->tb_jmp_target_addr + a0)) >> 2; tcg_out_insn(s, 3305, LDR, offset, TCG_REG_TMP); diff --git a/tcg/mips/tcg-target.inc.c b/tcg/mips/tcg-target.inc.c index 1a8169f5fc..04f8c839fe 100644 --- a/tcg/mips/tcg-target.inc.c +++ b/tcg/mips/tcg-target.inc.c @@ -2642,7 +2642,8 @@ static void tcg_target_init(TCGContext *s) tcg_regset_set_reg(s->reserved_regs, TCG_REG_GP); /* global pointer */ } -void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr) +void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, + uintptr_t addr) { atomic_set((uint32_t *)jmp_addr, deposit32(OPC_J, 0, 26, addr >> 2)); flush_icache_range(jmp_addr, jmp_addr + 4); diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c index 1f690df20d..018c240f6d 100644 --- a/tcg/ppc/tcg-target.inc.c +++ b/tcg/ppc/tcg-target.inc.c @@ -1296,7 +1296,8 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0) } #ifdef __powerpc64__ -void ppc_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr) +void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, + uintptr_t addr) { tcg_insn_unit i1, i2; uint64_t pair; @@ -1328,7 +1329,8 @@ void ppc_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr) flush_icache_range(jmp_addr, jmp_addr + 8); } #else -void ppc_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr) +void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, + uintptr_t addr) { intptr_t diff = addr - jmp_addr; tcg_debug_assert(in_range_b(diff)); diff --git a/tcg/sparc/tcg-target.inc.c b/tcg/sparc/tcg-target.inc.c index 18afce2f87..06cabbedf5 100644 --- a/tcg/sparc/tcg-target.inc.c +++ b/tcg/sparc/tcg-target.inc.c @@ -1708,7 +1708,8 @@ void tcg_register_jit(void *buf, size_t buf_size) tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); } -void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr) +void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, + uintptr_t addr) { uint32_t *ptr = (uint32_t *)jmp_addr; uintptr_t disp = addr - jmp_addr; From patchwork Thu Sep 7 22:40:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111975 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp722429qge; Thu, 7 Sep 2017 15:44:14 -0700 (PDT) X-Received: by 10.237.60.22 with SMTP id t22mr1340008qte.249.1504824254268; Thu, 07 Sep 2017 15:44:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824254; cv=none; d=google.com; s=arc-20160816; b=qIhN5yHlYw+6qeED5Q+OR9V7NgMz+pU+A5L5gu3tghcplmqxWETzKtJXufdSvgWwTS o0A24rdX6OY7QWSvvyBhkeHGAiWYZjK24u4wmFp+wo5V66GJWCHETQBPOF3KP5f2y/DA oQ2e9d457D+6n/fofsf+JXeX6Y8/7dcUpVFTY8kclaptMa6ULC2VOhSVl0xYuEuKzN0X 9RIMnWk1mUdG0h2CrOq9chgeCKleA+0Fo97Bd+idJWxHPY8nPS6g9pasroKP0bye2hMg WieVOrl4Z9u6pDZ59dAUcvnjHDQRG3XGMZyvJsD5CQpMCdUfibbg9SiMq7gISr8BKPpp lVCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=S2df7Us213tGoZSMo2fbN848O/tBS8d6oJFU35pfhgE=; b=FCLIi7yc8Paio4Sh/Tvdl3gSV2/ruFr681mrO3Ds8AW4OYsr/b+hmhVBPwCXiPWatq 9yOVXDZX7wtsYitDGyxFFvONaAQm7pmmfyawhjN5kBAqiO1iSoLdp35dY/U09yiUHUeN zmLX5601Yvq7CQmGqvAdhnatn887Or54g0QXJy4M0ff+ia/xYWrJdT7SYTEUUS0PReVN 1fMPzzGSW99d+wKSHT1IJy9V0syWGxiSuBLFBTWCSrWpmflZEv9nVGS+eB6MKN/iXpVM Fd/3Hnt8hvNysACpEV2cq4AHhyAJB3yE+Q+J1a50lmpjS8+avTtGiNHlmaGXyl4yXq93 GXtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SGTs+iwD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t2si475434qkd.16.2017.09.07.15.44.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:44:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SGTs+iwD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Wt-0005PZ-Sy for patch@linaro.org; Thu, 07 Sep 2017 18:44:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Ts-0002xQ-Eo for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5Tm-00080a-OT for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:04 -0400 Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]:36486) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5Tm-000808-GA for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:40:58 -0400 Received: by mail-pf0-x231.google.com with SMTP id e199so1621667pfh.3 for ; Thu, 07 Sep 2017 15:40:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S2df7Us213tGoZSMo2fbN848O/tBS8d6oJFU35pfhgE=; b=SGTs+iwDlmQLCEYn+/CnomKa6Hhv52TDnhUX9A2DC7nww0HcNe/RlzKxLWzW/hu6vo I868QkGnLB52iJ9zimqqOSvpp7d8a8HjxD4oVikMnq3irZyibQPLPFfTffSYjJA9UzPE 10gbG9KmhDHX1JQxUk7TZE0JMFds8nAtBLAgo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S2df7Us213tGoZSMo2fbN848O/tBS8d6oJFU35pfhgE=; b=U/S6og9XqMczZD94ru72HBYD0Xu39AaOsW5zCB892O6d9V1gkd/lhvsoIH7STPoa+g o8rMiqQv+QqKsTL/vIX8ylyn7i3uELv3zU4UwpevQ31aV8GRQSoiAj/KWouAFOgxuFeY 370rCtEQkJXBso/LDSrK5SMb1KFtW2tNdWT50XOm48xZm7wrcnI3UmuVB60Pai4fu8l3 yVz/sZGeDeWvZw3qxjxGjAHpmb/Bp01DNHa32wZ2scnBtcWgT6IT+AzlZEJZCThWoo1A XoQAxioVeaWdDRjtZuAOT45+9hofMFxj6Yt/NZPivKCl17sqnbtpbsLEaO+qKHQc5W5r TjCA== X-Gm-Message-State: AHPjjUjuxkHi4oYSCLrBnFZj4xte7g/UNCM61k6znToEqwz/NZcDx48B 7Y7LrYml/9gicPH9CRZLLg== X-Google-Smtp-Source: ADKCNb6qBpk6oaMiqTghNtPZr+ktqqzkNR4kpdWOLaUKulxV/FtYfqMDeH6sHdcDDI3mKvxmAgxVXg== X-Received: by 10.98.31.217 with SMTP id l86mr970172pfj.136.1504824057037; Thu, 07 Sep 2017 15:40:57 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.40.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:40:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:30 -0700 Message-Id: <20170907224051.21518-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::231 Subject: [Qemu-devel] [PULL 02/23] tcg: Rearrange ldst label tracking X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Dispense with TCGBackendData, as it has never been used for more than holding a single pointer. Use a define in the cpu/tcg-target.h to signal requirement for TCGLabelQemuLdst, so that we can drop the no-op tcg-be-null.h stubs. Rename tcg-be-ldst.h to tcg-ldst.inc.c. Reviewed-by: Paolo Bonzini Signed-off-by: Richard Henderson --- tcg/aarch64/tcg-target.h | 4 ++++ tcg/arm/tcg-target.h | 4 ++++ tcg/i386/tcg-target.h | 4 ++++ tcg/mips/tcg-target.h | 4 ++++ tcg/ppc/tcg-target.h | 4 ++++ tcg/s390/tcg-target.h | 4 ++++ tcg/tcg-be-null.h | 44 ----------------------------------- tcg/tcg.h | 6 +++-- tcg/tci/tcg-target.h | 4 ++++ tcg/aarch64/tcg-target.inc.c | 3 ++- tcg/arm/tcg-target.inc.c | 3 ++- tcg/i386/tcg-target.inc.c | 4 ++-- tcg/mips/tcg-target.inc.c | 4 ++-- tcg/ppc/tcg-target.inc.c | 4 ++-- tcg/s390/tcg-target.inc.c | 4 ++-- tcg/sparc/tcg-target.inc.c | 2 -- tcg/{tcg-be-ldst.h => tcg-ldst.inc.c} | 27 ++++----------------- tcg/tcg.c | 17 +++++++------- tcg/tci/tcg-target.inc.c | 2 -- 19 files changed, 57 insertions(+), 91 deletions(-) delete mode 100644 tcg/tcg-be-null.h rename tcg/{tcg-be-ldst.h => tcg-ldst.inc.c} (85%) -- 2.13.5 diff --git a/tcg/aarch64/tcg-target.h b/tcg/aarch64/tcg-target.h index 719861fe3e..1bdbd7058b 100644 --- a/tcg/aarch64/tcg-target.h +++ b/tcg/aarch64/tcg-target.h @@ -122,4 +122,8 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop) void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); +#ifdef CONFIG_SOFTMMU +#define TCG_TARGET_NEED_LDST_LABELS +#endif + #endif /* AARCH64_TCG_TARGET_H */ diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h index 7117ebf4fc..2e92cb3283 100644 --- a/tcg/arm/tcg-target.h +++ b/tcg/arm/tcg-target.h @@ -140,4 +140,8 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop) /* not defined -- call should be eliminated at compile time */ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); +#ifdef CONFIG_SOFTMMU +#define TCG_TARGET_NEED_LDST_LABELS +#endif + #endif diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h index 2fd28fa6a5..11ee7fadd1 100644 --- a/tcg/i386/tcg-target.h +++ b/tcg/i386/tcg-target.h @@ -186,4 +186,8 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, #define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD) +#ifdef CONFIG_SOFTMMU +#define TCG_TARGET_NEED_LDST_LABELS +#endif + #endif diff --git a/tcg/mips/tcg-target.h b/tcg/mips/tcg-target.h index 928a762bd7..a8222476f0 100644 --- a/tcg/mips/tcg-target.h +++ b/tcg/mips/tcg-target.h @@ -211,4 +211,8 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop) void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); +#ifdef CONFIG_SOFTMMU +#define TCG_TARGET_NEED_LDST_LABELS +#endif + #endif diff --git a/tcg/ppc/tcg-target.h b/tcg/ppc/tcg-target.h index aa44e715d8..3772cc6648 100644 --- a/tcg/ppc/tcg-target.h +++ b/tcg/ppc/tcg-target.h @@ -129,4 +129,8 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); #define TCG_TARGET_DEFAULT_MO (0) +#ifdef CONFIG_SOFTMMU +#define TCG_TARGET_NEED_LDST_LABELS +#endif + #endif diff --git a/tcg/s390/tcg-target.h b/tcg/s390/tcg-target.h index 31a9eb4ac7..52010c30cb 100644 --- a/tcg/s390/tcg-target.h +++ b/tcg/s390/tcg-target.h @@ -155,4 +155,8 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, /* no need to flush icache explicitly */ } +#ifdef CONFIG_SOFTMMU +#define TCG_TARGET_NEED_LDST_LABELS +#endif + #endif diff --git a/tcg/tcg-be-null.h b/tcg/tcg-be-null.h deleted file mode 100644 index 5222fe29e2..0000000000 --- a/tcg/tcg-be-null.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * TCG Backend Data: No backend data - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -typedef struct TCGBackendData { - /* Empty */ - char dummy; -} TCGBackendData; - - -/* - * Initialize TB backend data at the beginning of the TB. - */ - -static inline void tcg_out_tb_init(TCGContext *s) -{ -} - -/* - * Generate TB finalization at the end of block - */ - -static inline bool tcg_out_tb_finalize(TCGContext *s) -{ - return true; -} diff --git a/tcg/tcg.h b/tcg/tcg.h index 46957d9bd7..b0e00e744e 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -712,8 +712,10 @@ struct TCGContext { CPUState *cpu; /* *_trans */ TCGv_env tcg_env; /* *_exec */ - /* The TCGBackendData structure is private to tcg-target.inc.c. */ - struct TCGBackendData *be; + /* These structures are private to tcg-target.inc.c. */ +#ifdef TCG_TARGET_NEED_LDST_LABELS + struct TCGLabelQemuLdst *ldst_labels; +#endif TCGTempSet free_temps[TCG_TYPE_COUNT * 2]; TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */ diff --git a/tcg/tci/tcg-target.h b/tcg/tci/tcg-target.h index 26140d78cb..5d692e1f4b 100644 --- a/tcg/tci/tcg-target.h +++ b/tcg/tci/tcg-target.h @@ -206,4 +206,8 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, /* no need to flush icache explicitly */ } +#ifdef CONFIG_SOFTMMU +#define TCG_TARGET_NEED_LDST_LABELS +#endif + #endif /* TCG_TARGET_H */ diff --git a/tcg/aarch64/tcg-target.inc.c b/tcg/aarch64/tcg-target.inc.c index a1e5dd2f03..c7c751bafc 100644 --- a/tcg/aarch64/tcg-target.inc.c +++ b/tcg/aarch64/tcg-target.inc.c @@ -10,7 +10,6 @@ * See the COPYING file in the top-level directory for details. */ -#include "tcg-be-ldst.h" #include "qemu/bitops.h" /* We're going to re-use TCGType in setting of the SF bit, which controls @@ -1070,6 +1069,8 @@ static void tcg_out_cltz(TCGContext *s, TCGType ext, TCGReg d, } #ifdef CONFIG_SOFTMMU +#include "tcg-ldst.inc.c" + /* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr, * TCGMemOpIdx oi, uintptr_t ra) */ diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index 37efcf06af..81ea900852 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -23,7 +23,6 @@ */ #include "elf.h" -#include "tcg-be-ldst.h" int arm_arch = __ARM_ARCH; @@ -1060,6 +1059,8 @@ static inline void tcg_out_mb(TCGContext *s, TCGArg a0) } #ifdef CONFIG_SOFTMMU +#include "tcg-ldst.inc.c" + /* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr, * int mmu_idx, uintptr_t ra) */ diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c index e4b120a40c..1a1ad96906 100644 --- a/tcg/i386/tcg-target.inc.c +++ b/tcg/i386/tcg-target.inc.c @@ -22,8 +22,6 @@ * THE SOFTWARE. */ -#include "tcg-be-ldst.h" - #ifdef CONFIG_DEBUG_TCG static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { #if TCG_TARGET_REG_BITS == 64 @@ -1214,6 +1212,8 @@ static void tcg_out_nopn(TCGContext *s, int n) } #if defined(CONFIG_SOFTMMU) +#include "tcg-ldst.inc.c" + /* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr, * int mmu_idx, uintptr_t ra) */ diff --git a/tcg/mips/tcg-target.inc.c b/tcg/mips/tcg-target.inc.c index 04f8c839fe..750baadf37 100644 --- a/tcg/mips/tcg-target.inc.c +++ b/tcg/mips/tcg-target.inc.c @@ -24,8 +24,6 @@ * THE SOFTWARE. */ -#include "tcg-be-ldst.h" - #ifdef HOST_WORDS_BIGENDIAN # define MIPS_BE 1 #else @@ -1112,6 +1110,8 @@ static void tcg_out_call(TCGContext *s, tcg_insn_unit *arg) } #if defined(CONFIG_SOFTMMU) +#include "tcg-ldst.inc.c" + static void * const qemu_ld_helpers[16] = { [MO_UB] = helper_ret_ldub_mmu, [MO_SB] = helper_ret_ldsb_mmu, diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c index 018c240f6d..d772faf7be 100644 --- a/tcg/ppc/tcg-target.inc.c +++ b/tcg/ppc/tcg-target.inc.c @@ -22,8 +22,6 @@ * THE SOFTWARE. */ -#include "tcg-be-ldst.h" - #if defined _CALL_DARWIN || defined __APPLE__ #define TCG_TARGET_CALL_DARWIN #endif @@ -1418,6 +1416,8 @@ static const uint32_t qemu_exts_opc[4] = { }; #if defined (CONFIG_SOFTMMU) +#include "tcg-ldst.inc.c" + /* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr, * int mmu_idx, uintptr_t ra) */ diff --git a/tcg/s390/tcg-target.inc.c b/tcg/s390/tcg-target.inc.c index 38b9e791ee..ee0dff995a 100644 --- a/tcg/s390/tcg-target.inc.c +++ b/tcg/s390/tcg-target.inc.c @@ -24,8 +24,6 @@ * THE SOFTWARE. */ -#include "tcg-be-ldst.h" - /* We only support generating code for 64-bit mode. */ #if TCG_TARGET_REG_BITS != 64 #error "unsupported code generation mode" @@ -1458,6 +1456,8 @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCGMemOp opc, TCGReg data, } #if defined(CONFIG_SOFTMMU) +#include "tcg-ldst.inc.c" + /* We're expecting to use a 20-bit signed offset on the tlb memory ops. Using the offset of the second entry in the last tlb table ensures that we can index all of the elements of the first entry. */ diff --git a/tcg/sparc/tcg-target.inc.c b/tcg/sparc/tcg-target.inc.c index 06cabbedf5..bb7f7e8906 100644 --- a/tcg/sparc/tcg-target.inc.c +++ b/tcg/sparc/tcg-target.inc.c @@ -22,8 +22,6 @@ * THE SOFTWARE. */ -#include "tcg-be-null.h" - #ifdef CONFIG_DEBUG_TCG static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { "%g0", diff --git a/tcg/tcg-be-ldst.h b/tcg/tcg-ldst.inc.c similarity index 85% rename from tcg/tcg-be-ldst.h rename to tcg/tcg-ldst.inc.c index 17777aec5a..0e14cf4357 100644 --- a/tcg/tcg-be-ldst.h +++ b/tcg/tcg-ldst.inc.c @@ -20,8 +20,6 @@ * THE SOFTWARE. */ -#ifdef CONFIG_SOFTMMU - typedef struct TCGLabelQemuLdst { bool is_ld; /* qemu_ld: true, qemu_st: false */ TCGMemOpIdx oi; @@ -35,19 +33,6 @@ typedef struct TCGLabelQemuLdst { struct TCGLabelQemuLdst *next; } TCGLabelQemuLdst; -typedef struct TCGBackendData { - TCGLabelQemuLdst *labels; -} TCGBackendData; - - -/* - * Initialize TB backend data at the beginning of the TB. - */ - -static inline void tcg_out_tb_init(TCGContext *s) -{ - s->be->labels = NULL; -} /* * Generate TB finalization at the end of block @@ -56,12 +41,12 @@ static inline void tcg_out_tb_init(TCGContext *s) static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l); static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l); -static bool tcg_out_tb_finalize(TCGContext *s) +static bool tcg_out_ldst_finalize(TCGContext *s) { TCGLabelQemuLdst *lb; /* qemu_ld/st slow paths */ - for (lb = s->be->labels; lb != NULL; lb = lb->next) { + for (lb = s->ldst_labels; lb != NULL; lb = lb->next) { if (lb->is_ld) { tcg_out_qemu_ld_slow_path(s, lb); } else { @@ -85,13 +70,9 @@ static bool tcg_out_tb_finalize(TCGContext *s) static inline TCGLabelQemuLdst *new_ldst_label(TCGContext *s) { - TCGBackendData *be = s->be; TCGLabelQemuLdst *l = tcg_malloc(sizeof(*l)); - l->next = be->labels; - be->labels = l; + l->next = s->ldst_labels; + s->ldst_labels = l; return l; } -#else -#include "tcg-be-null.h" -#endif /* CONFIG_SOFTMMU */ diff --git a/tcg/tcg.c b/tcg/tcg.c index 35598296c5..dd74eabb0a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -112,10 +112,9 @@ static bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val, static void tcg_out_call(TCGContext *s, tcg_insn_unit *target); static int tcg_target_const_match(tcg_target_long val, TCGType type, const TCGArgConstraint *arg_ct); -static void tcg_out_tb_init(TCGContext *s); -static bool tcg_out_tb_finalize(TCGContext *s); - - +#ifdef TCG_TARGET_NEED_LDST_LABELS +static bool tcg_out_ldst_finalize(TCGContext *s); +#endif static TCGRegSet tcg_target_available_regs[2]; static TCGRegSet tcg_target_call_clobber_regs; @@ -470,8 +469,6 @@ void tcg_func_start(TCGContext *s) s->gen_op_buf[0].prev = 0; s->gen_next_op_idx = 1; s->gen_next_parm_idx = 0; - - s->be = tcg_malloc(sizeof(TCGBackendData)); } static inline int temp_idx(TCGContext *s, TCGTemp *ts) @@ -2619,7 +2616,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) s->code_buf = tb->tc_ptr; s->code_ptr = tb->tc_ptr; - tcg_out_tb_init(s); +#ifdef TCG_TARGET_NEED_LDST_LABELS + s->ldst_labels = NULL; +#endif num_insns = -1; for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) { @@ -2694,9 +2693,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) s->gen_insn_end_off[num_insns] = tcg_current_code_size(s); /* Generate TB finalization at the end of block */ - if (!tcg_out_tb_finalize(s)) { +#ifdef TCG_TARGET_NEED_LDST_LABELS + if (!tcg_out_ldst_finalize(s)) { return -1; } +#endif /* flush instruction cache */ flush_icache_range((uintptr_t)s->code_buf, (uintptr_t)s->code_ptr); diff --git a/tcg/tci/tcg-target.inc.c b/tcg/tci/tcg-target.inc.c index b6a15569f8..94461b2baf 100644 --- a/tcg/tci/tcg-target.inc.c +++ b/tcg/tci/tcg-target.inc.c @@ -22,8 +22,6 @@ * THE SOFTWARE. */ -#include "tcg-be-null.h" - /* TODO list: * - See TODO comments in code. */ From patchwork Thu Sep 7 22:40:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111976 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp722698qge; Thu, 7 Sep 2017 15:44:33 -0700 (PDT) X-Received: by 10.200.50.144 with SMTP id z16mr1359481qta.0.1504824273614; Thu, 07 Sep 2017 15:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824273; cv=none; d=google.com; s=arc-20160816; b=UvIF6uqQ0O0DxsOYTGDXWRUVKKUSEn6pPIC8BNyjCZB4ufTliZ3ZGEghaXC153pRq/ b/Rzkj1mVhk+vH0AwxUzI3aCnD6jmkYhGOsiIxiQSLQWRw8qlvCs3jjpRhl2sR76as36 mwx1xRhdzCvJYhXs9PSjmo238ZFUCkd2p2z0UMxNd7kYmrMmImKPGgugVGlLDDosjFt2 1j9oiOSRupx6K1hvgMmBNsgTWGUdJ9731+SysvvtB8l8rC3OOPT4gITt8/1MVVa8relz o1MugtvV1v0wgRvJgckcQDH7M1PxKQn4r8zs7TQhzh6GYmT75d3mSnqY6dbMFdPEIGSF +e8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=G9JuhqRkFFcCCYIIM7arlN45+QOyUMSOUNFmUZiEKSo=; b=FmWL4FHialX7kc9Khn5y9ImToeqq6ZNNebYsX3/GKdlHnoRVY4Yrkk0coNjAZzt2ap ucgrs/jdCmQsmLjWSvlLly2UwzJFBbHAeNwiTNSGBCi7B7U4tZiqUDsfyK26xlXz5zLr DC5WL5eYBcLnsC20WugOylU6RCtuLIiMLbIM9Y+OMdr3q6s5ovy3phfwYo5h91kr7dcq omZ48MwFVp6LWMLZtTkHf95efEpRTakFIATkxJ0ZHm94KqWLqj8uEMeBDGasWdSHrHa1 Ze/gIfHiGM/viPZAnpc/qGlN1lkc196SNXz0D2tSgJv1yjm9NdsfUtIMHwkCNC6N4m8i 8j9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Bm3Z35X0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e12si471309qkj.326.2017.09.07.15.44.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:44:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Bm3Z35X0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5XD-0005fO-E3 for patch@linaro.org; Thu, 07 Sep 2017 18:44:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Tt-0002xX-Da for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5To-00082x-89 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:05 -0400 Received: from mail-pf0-x234.google.com ([2607:f8b0:400e:c00::234]:36486) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5Tn-00081G-VM for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:00 -0400 Received: by mail-pf0-x234.google.com with SMTP id e199so1621728pfh.3 for ; Thu, 07 Sep 2017 15:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=G9JuhqRkFFcCCYIIM7arlN45+QOyUMSOUNFmUZiEKSo=; b=Bm3Z35X0TtXRp7MNlpEI/V45co6dea/IhIds3XiRuLV2COlaclxL6tZG/WofgIWzvS TDSuqaDqy5pa0FeCclgPE+8y0KTlW4vKJYmOCi0E5XEygEmuCvyx5dGxu9l2WvahvVJH WZewjlzg+GT6gU1tTxtfvB/AwQjYlFVP+VmTc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=G9JuhqRkFFcCCYIIM7arlN45+QOyUMSOUNFmUZiEKSo=; b=f3DzXIEteqBis0mbK03RlumfAnQj/aF4/jHX0h5IUeLOqhn5Mqhg/HGCwsBYMmLxPS 1Yo+CaZ9oo3mytoDFkeqchaaDxiGWlIoy8eUCo/wSIzzGFFhoKuTg9Gs1TBry38klGp/ +45hwroZo1DDDGcm4xsfiG/J4o+URIKNsGflyXAEHxW+PkuXwobwAGsQdM+JxSUmTNVv L4TmzaFult30joj16SbN06N7eBp9ZQL1vHc8I+BhZm0c9lD2NxBkpkt0Yh0Utw+m8fYH piupP8AsSk6Cl1TD3/ffmOip+eykuN9wFyQvt5J2qatjKHtfJ7kmQ0NSV0F1opwbEi8X fpSw== X-Gm-Message-State: AHPjjUgHCa7yp15+htjvvpKzqsRXPGFYCEixywOJNV/+DQR1qcMIJHP9 N6mOEUBnodGyDg7PbPDPZA== X-Google-Smtp-Source: ADKCNb6P9LnCmgh7AThbKNM6ZYG0wgtvwGkZl8hufr/Yze7IUFpsgKtqDUfYIKkx7hxKQ+DyRast/w== X-Received: by 10.99.171.73 with SMTP id k9mr961814pgp.196.1504824058584; Thu, 07 Sep 2017 15:40:58 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.40.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:40:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:31 -0700 Message-Id: <20170907224051.21518-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::234 Subject: [Qemu-devel] [PULL 03/23] tcg: Infrastructure for managing constant pools X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson A new shared header tcg-pool.inc.c adds new_pool_label, for registering a tcg_target_ulong to be emitted after the generated code, plus relocation data to install a pointer to the data. A new pointer is added to the TCGContext, so that we dump the constant pool as data, not code. Signed-off-by: Richard Henderson --- tcg/tcg.h | 4 +++ accel/tcg/translate-all.c | 22 +++++++++++- tcg/tcg-pool.inc.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++ tcg/tcg.c | 9 +++++ 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 tcg/tcg-pool.inc.c -- 2.13.5 diff --git a/tcg/tcg.h b/tcg/tcg.h index b0e00e744e..ac94133870 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -702,6 +702,7 @@ struct TCGContext { void *code_gen_buffer; size_t code_gen_buffer_size; void *code_gen_ptr; + void *data_gen_ptr; /* Threshold to flush the translated code buffer. */ void *code_gen_highwater; @@ -716,6 +717,9 @@ struct TCGContext { #ifdef TCG_TARGET_NEED_LDST_LABELS struct TCGLabelQemuLdst *ldst_labels; #endif +#ifdef TCG_TARGET_NEED_POOL_LABELS + struct TCGLabelPoolData *pool_labels; +#endif TCGTempSet free_temps[TCG_TYPE_COUNT * 2]; TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */ diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 93a1cf2ba8..2d1ed06065 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1329,7 +1329,27 @@ TranslationBlock *tb_gen_code(CPUState *cpu, qemu_log_in_addr_range(tb->pc)) { qemu_log_lock(); qemu_log("OUT: [size=%d]\n", gen_code_size); - log_disas(tb->tc_ptr, gen_code_size); + if (tcg_ctx.data_gen_ptr) { + size_t code_size = tcg_ctx.data_gen_ptr - tb->tc_ptr; + size_t data_size = gen_code_size - code_size; + size_t i; + + log_disas(tb->tc_ptr, code_size); + + for (i = 0; i < data_size; i += sizeof(tcg_target_ulong)) { + if (sizeof(tcg_target_ulong) == 8) { + qemu_log("0x%08" PRIxPTR ": .quad 0x%016" PRIx64 "\n", + (uintptr_t)tcg_ctx.data_gen_ptr + i, + *(uint64_t *)(tcg_ctx.data_gen_ptr + i)); + } else { + qemu_log("0x%08" PRIxPTR ": .long 0x%08x\n", + (uintptr_t)tcg_ctx.data_gen_ptr + i, + *(uint32_t *)(tcg_ctx.data_gen_ptr + i)); + } + } + } else { + log_disas(tb->tc_ptr, gen_code_size); + } qemu_log("\n"); qemu_log_flush(); qemu_log_unlock(); diff --git a/tcg/tcg-pool.inc.c b/tcg/tcg-pool.inc.c new file mode 100644 index 0000000000..8a85131405 --- /dev/null +++ b/tcg/tcg-pool.inc.c @@ -0,0 +1,85 @@ +/* + * TCG Backend Data: constant pool. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +typedef struct TCGLabelPoolData { + struct TCGLabelPoolData *next; + tcg_target_ulong data; + tcg_insn_unit *label; + intptr_t addend; + int type; +} TCGLabelPoolData; + + +static void new_pool_label(TCGContext *s, tcg_target_ulong data, int type, + tcg_insn_unit *label, intptr_t addend) +{ + TCGLabelPoolData *n = tcg_malloc(sizeof(*n)); + TCGLabelPoolData *i, **pp; + + n->data = data; + n->label = label; + n->type = type; + n->addend = addend; + + /* Insertion sort on the pool. */ + for (pp = &s->pool_labels; (i = *pp) && i->data < data; pp = &i->next) { + continue; + } + n->next = *pp; + *pp = n; +} + +/* To be provided by cpu/tcg-target.inc.c. */ +static void tcg_out_nop_fill(tcg_insn_unit *p, int count); + +static bool tcg_out_pool_finalize(TCGContext *s) +{ + TCGLabelPoolData *p = s->pool_labels; + tcg_target_ulong d, *a; + + if (p == NULL) { + return true; + } + + /* ??? Round up to qemu_icache_linesize, but then do not round + again when allocating the next TranslationBlock structure. */ + a = (void *)ROUND_UP((uintptr_t)s->code_ptr, sizeof(tcg_target_ulong)); + tcg_out_nop_fill(s->code_ptr, (tcg_insn_unit *)a - s->code_ptr); + s->data_gen_ptr = a; + + /* Ensure the first comparison fails. */ + d = p->data + 1; + + for (; p != NULL; p = p->next) { + if (p->data != d) { + d = p->data; + if (unlikely((void *)a > s->code_gen_highwater)) { + return false; + } + *a++ = d; + } + patch_reloc(p->label, p->type, (intptr_t)(a - 1), p->addend); + } + + s->code_ptr = (void *)a; + return true; +} diff --git a/tcg/tcg.c b/tcg/tcg.c index dd74eabb0a..fd8a3dfe93 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -399,6 +399,7 @@ TranslationBlock *tcg_tb_alloc(TCGContext *s) return NULL; } s->code_gen_ptr = next; + s->data_gen_ptr = NULL; return tb; } @@ -2619,6 +2620,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) #ifdef TCG_TARGET_NEED_LDST_LABELS s->ldst_labels = NULL; #endif +#ifdef TCG_TARGET_NEED_POOL_LABELS + s->pool_labels = NULL; +#endif num_insns = -1; for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) { @@ -2698,6 +2702,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) return -1; } #endif +#ifdef TCG_TARGET_NEED_POOL_LABELS + if (!tcg_out_pool_finalize(s)) { + return -1; + } +#endif /* flush instruction cache */ flush_icache_range((uintptr_t)s->code_buf, (uintptr_t)s->code_ptr); From patchwork Thu Sep 7 22:40:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111982 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp727037qge; Thu, 7 Sep 2017 15:49:42 -0700 (PDT) X-Received: by 10.55.40.41 with SMTP id o41mr1215585qkh.271.1504824582947; Thu, 07 Sep 2017 15:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824582; cv=none; d=google.com; s=arc-20160816; b=MYCGV1VfQX7/JgAIJPz5zTniuF0EGT5HvPW0SuwU1ZQIT1zmc8bKBeF8Bz31QEQSof irCfbwtnQlWg87yfRW8Ee0TRlnzJUnx4LyiXRuBQhsIarPkZtPjP6hcBl62EHDF264oI AG/F9/B/EUKLN/aF05iZjC4ohlBfb79liDlqZuqnTNhxdZg/L1o+4g6aG4gMhH+xx8J9 cIkKBZK416Lb4c5IeH1pyM5L5pkiWRO5bo0eHw3ISoPBzcUJLhq3KIdcwFLCoYRw+QC8 1rh3XjPsrxnmhG+YcEEVpk6RAd+5tU27Zeazbp2Lgw6EGPwUxra0XTCT9fn+pNaos9/m hnqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=daMSdqMbQuDE4qwwdspqIaJ34DPgPJe16DeZ0MUqsHw=; b=eHMhTcn1ydOv8UXMbXqwc4k+Y95WS5trUu+4Kg7thjyEZFYTUgpZTvOWASK+hPkqvP FRSmaOkbsJyMlCaKyLhxE6XI6nb78pNGiqFU1TF3LNshRBTfLypOeeNphMuUo8B0DsXq FMFfSAjsZP09NiTidUhN2BBm7qZzul32zm/qjYvmTLSJnzWKCS4ref15/etKmk/gEMtt J4qkM4AzejxjlQIWLCeozNkoPqdtiS0ZhFS0cPh1zFzK8qKrWhNKcNgLbbPa8birUzET xsnomv2/LubRyMNaljFn8RiJBk4IyK1q/E16ut6m/I+WlAWUe9sRkASVKuoBDZvcLtBA YGfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SBJD/udz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a125si485339qkg.57.2017.09.07.15.49.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:49:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SBJD/udz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42544 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5cC-0001Tq-Qv for patch@linaro.org; Thu, 07 Sep 2017 18:49:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Tu-0002xY-5U for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5Tp-000843-Id for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:06 -0400 Received: from mail-pg0-x236.google.com ([2607:f8b0:400e:c05::236]:33212) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5Tp-00083V-Cf for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:01 -0400 Received: by mail-pg0-x236.google.com with SMTP id t3so1832918pgt.0 for ; Thu, 07 Sep 2017 15:41:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=daMSdqMbQuDE4qwwdspqIaJ34DPgPJe16DeZ0MUqsHw=; b=SBJD/udzGS6O7LRdXlb75Ry24Fp5dFFrzLGlJhDE302XvbNazE67qBdjv73nfctlDC KutfV2ZLzbfUCB89WucE4maAZICZz+3jUbARahZvQXbED1dzJju/0sYcBgwZqD6sAdQd 7AacvqSp5Wk3w50nobkElvY0QQ5oldM5gBnCE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=daMSdqMbQuDE4qwwdspqIaJ34DPgPJe16DeZ0MUqsHw=; b=Nm4FxHCUkb+wMpBcCbShEMQ2HCb9gBnPqmFDf3x1IIWYYmGgfUF+hOjXrvmXIXdigO qA2txqKt/m+yAhB2VlGN/qwoACR8xLdvEXkJqQ/twXCMTmMv8ePeDVw5qpAhaFOrB+Je ksTxaZ783kOy4V+NuhZbKDvTMMr2mjV2iueUkkHRbtK7XuHaDLxjm74PLn7Uf2+89dh9 /BfYPvZy89U3Sn6p/z99MgqDbBr3JP73cK8sagRVtlJvncNBTppCyTZtRxE++87DSb0Z iJIZlNDs7FwwPE7EUiF/pNr/2wF9Yuqz+WgCmsl5ais+6tas3BVi1oQWzsRom16EqtI2 TvLQ== X-Gm-Message-State: AHPjjUgWigKtISjOlKdTWd2afMTDqGbxL4NSiST/izYeQwgk6/FRsuoH o23xG+A+0otGlvPQWAkFbg== X-Google-Smtp-Source: ADKCNb50pmjHwiFsMkL6m8hX/bfOjZELvV9WlmZAOpVIV01TAlsn6Frm7qtamlSfNO5mJfjtd4Q6mQ== X-Received: by 10.99.105.196 with SMTP id e187mr937282pgc.360.1504824060061; Thu, 07 Sep 2017 15:41:00 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.40.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:40:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:32 -0700 Message-Id: <20170907224051.21518-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::236 Subject: [Qemu-devel] [PULL 04/23] tcg/i386: Store out-of-range call targets in constant pool X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Already it saves 2 bytes per call, but also the constant pool entry may well be shared across multiple calls. Signed-off-by: Richard Henderson --- tcg/i386/tcg-target.h | 1 + tcg/i386/tcg-target.inc.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) -- 2.13.5 diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h index 11ee7fadd1..b89dababf4 100644 --- a/tcg/i386/tcg-target.h +++ b/tcg/i386/tcg-target.h @@ -189,5 +189,6 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS #endif +#define TCG_TARGET_NEED_POOL_LABELS #endif diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c index 1a1ad96906..5231056fd3 100644 --- a/tcg/i386/tcg-target.inc.c +++ b/tcg/i386/tcg-target.inc.c @@ -22,6 +22,8 @@ * THE SOFTWARE. */ +#include "tcg-pool.inc.c" + #ifdef CONFIG_DEBUG_TCG static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { #if TCG_TARGET_REG_BITS == 64 @@ -1180,9 +1182,14 @@ static void tcg_out_branch(TCGContext *s, int call, tcg_insn_unit *dest) tcg_out_opc(s, call ? OPC_CALL_Jz : OPC_JMP_long, 0, 0, 0); tcg_out32(s, disp); } else { - tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R10, (uintptr_t)dest); - tcg_out_modrm(s, OPC_GRP5, - call ? EXT5_CALLN_Ev : EXT5_JMPN_Ev, TCG_REG_R10); + /* rip-relative addressing into the constant pool. + This is 6 + 8 = 14 bytes, as compared to using an + an immediate load 10 + 6 = 16 bytes, plus we may + be able to re-use the pool constant for more calls. */ + tcg_out_opc(s, OPC_GRP5, 0, 0, 0); + tcg_out8(s, (call ? EXT5_CALLN_Ev : EXT5_JMPN_Ev) << 3 | 5); + new_pool_label(s, (uintptr_t)dest, R_386_PC32, s->code_ptr, -4); + tcg_out32(s, 0); } } @@ -2595,6 +2602,11 @@ static void tcg_target_qemu_prologue(TCGContext *s) #endif } +static void tcg_out_nop_fill(tcg_insn_unit *p, int count) +{ + memset(p, 0x90, count); +} + static void tcg_target_init(TCGContext *s) { #ifdef CONFIG_CPUID_H From patchwork Thu Sep 7 22:40:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111974 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp721825qge; Thu, 7 Sep 2017 15:43:32 -0700 (PDT) X-Received: by 10.55.23.205 with SMTP id 74mr1243281qkx.134.1504824212751; Thu, 07 Sep 2017 15:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824212; cv=none; d=google.com; s=arc-20160816; b=nB6liYB7xWtnJIaDQb+ZIK2BqM0LneN7nCDzlSSQofOc0hbinI0rndzbBn/hFCAxmn +YZIsrBKLASSNNCkB9rhBxafvh16gCKc1+vwJe4UComgi97M49P8cN/PqGG9MSTjP/dU ZFBtgPSyNUuUh1c0DeQ2D4ci+rxXxB/srtw9EDrBr6FqT5TibWeKkt1Vf12BCvOMrbzW VLlOVz3Axexm9saOllMNCa+qv/v1qltEBOui1YkQdvG7Vxwr2l7Pzqpq379QdloPEa0Q w2a/1ScJul2r2GEOSLpr78a3B5+/moIqg7dKs+1ghTtf0MyJ9q6X5JiMaL2GZmYuIH7Z xMEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=AsoJlWiUc2xIlOEw/Aqp10soH/fjgwUnxjIzF/rW2gY=; b=WjvnCJR/PDGAHMTLCHuer528ky6o5kWa/yyqc+WAH9nz5b5Oz0oLF2iBplmGmtnXHi no/jjGs7nFNzc2QWS+1RARuEZ+Vny5MJv8eNttOHowqjYHG6DWB/c1E68DQc4NosEXQ7 c0eoUDUXeqMsAHe0Sulg0RQFgE9a3ZEPBmlQYyfO7VJ0pJURon0CPNzy90TLGTBbelER tvrytfEDqMwVFGZGU/ZsHPRlJ0cLrcws7n1znQNGEkRbqA3xZfdcSnEItZgfqIOcoxza UuzhOsWeLXJ2T7k3zQAtSioigd/egUH4xQyclb8o9ngN0LOvg6nKJlCz06CHXPGfduBp zRqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MilTOnt5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f1si465372qtl.107.2017.09.07.15.43.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:43:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MilTOnt5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5WE-0004c8-JB for patch@linaro.org; Thu, 07 Sep 2017 18:43:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Tv-0002yJ-PS for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5Tq-000859-RW for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:07 -0400 Received: from mail-pg0-x22a.google.com ([2607:f8b0:400e:c05::22a]:33213) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5Tq-00084W-J7 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:02 -0400 Received: by mail-pg0-x22a.google.com with SMTP id t3so1832996pgt.0 for ; Thu, 07 Sep 2017 15:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AsoJlWiUc2xIlOEw/Aqp10soH/fjgwUnxjIzF/rW2gY=; b=MilTOnt5bR0VOkATf0S31FOyrhcAg563hoBcomNSz7fPMeVCo632x9OfhF1sKsHtHK hOLpjeS6Y83B9BUvVefe7eR3/hoKTIa1QR8GY3uRSMYQHoQFmP1exzeEwByagYLIvZ8E xLvdKUbCzUR+tYyrDc/cZHf1EsZ/HgFjqsfvU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AsoJlWiUc2xIlOEw/Aqp10soH/fjgwUnxjIzF/rW2gY=; b=dmRuSurYUcXHYVDHzqrPuciStcnpeL+rr6kyveY7dQJhuy1uzaL6D3doTKTiUJkT4g 6hMmKqZ1DxveqLNjuUpuGORGeudxc0vXDO6el2zYix+EiMcMgQoO4G/pl740BF83yaaK 4uOp0MGIZh6HK051aFBetUwtJIV00FSkgEGBD+SUVniJ281PIMA32otvmkS6ullu6RSL XrstGZtfeOAO5hV4iFhYEmZNqb6n3hdOyN1Ok2QNa1Fmw542uTcd09/Gnylq04c1XBCe 7uNYj4FhD5uYkbeu50J9Swzen88SP3FaGO2bEJ7EBUyNE7Q2lAgpaQo3FAQi1SrZ21+A AkWg== X-Gm-Message-State: AHPjjUjiRJzIIov4ozjTUNJO2NVMLMi2mi0wQ0uNRfeP9JqeBex5EPH9 hiT9KvlUV+tFn5RCSx5o+A== X-Google-Smtp-Source: ADKCNb5aCksKsO78EiindBGqssFd6nR9200pM+/zUiK0wZshWGqYnBqNQZchTfjYW4X7tdcdb8MapA== X-Received: by 10.99.98.131 with SMTP id w125mr977385pgb.214.1504824061249; Thu, 07 Sep 2017 15:41:01 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:33 -0700 Message-Id: <20170907224051.21518-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::22a Subject: [Qemu-devel] [PULL 05/23] tcg/s390: Introduce TCG_REG_TB X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/s390/tcg-target.h | 2 +- tcg/s390/tcg-target.inc.c | 71 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 12 deletions(-) -- 2.13.5 diff --git a/tcg/s390/tcg-target.h b/tcg/s390/tcg-target.h index 52010c30cb..9c9c8cd464 100644 --- a/tcg/s390/tcg-target.h +++ b/tcg/s390/tcg-target.h @@ -95,7 +95,7 @@ extern uint64_t s390_facilities; #define TCG_TARGET_HAS_extrl_i64_i32 0 #define TCG_TARGET_HAS_extrh_i64_i32 0 #define TCG_TARGET_HAS_goto_ptr 1 -#define TCG_TARGET_HAS_direct_jump 1 +#define TCG_TARGET_HAS_direct_jump (s390_facilities & FACILITY_GEN_INST_EXT) #define TCG_TARGET_HAS_div2_i64 1 #define TCG_TARGET_HAS_rot_i64 1 diff --git a/tcg/s390/tcg-target.inc.c b/tcg/s390/tcg-target.inc.c index ee0dff995a..e007586315 100644 --- a/tcg/s390/tcg-target.inc.c +++ b/tcg/s390/tcg-target.inc.c @@ -51,6 +51,12 @@ /* A scratch register that may be be used throughout the backend. */ #define TCG_TMP0 TCG_REG_R1 +/* A scratch register that holds a pointer to the beginning of the TB. + We don't need this when we have pc-relative loads with the general + instructions extension facility. */ +#define TCG_REG_TB TCG_REG_R12 +#define USE_REG_TB (!(s390_facilities & FACILITY_GEN_INST_EXT)) + #ifndef CONFIG_SOFTMMU #define TCG_GUEST_BASE_REG TCG_REG_R13 #endif @@ -556,8 +562,8 @@ static void tcg_out_mov(TCGContext *s, TCGType type, TCGReg dst, TCGReg src) } /* load a register with an immediate value */ -static void tcg_out_movi(TCGContext *s, TCGType type, - TCGReg ret, tcg_target_long sval) +static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, + tcg_target_long sval, bool in_prologue) { static const S390Opcode lli_insns[4] = { RI_LLILL, RI_LLILH, RI_LLIHL, RI_LLIHH @@ -601,13 +607,22 @@ static void tcg_out_movi(TCGContext *s, TCGType type, } } - /* Try for PC-relative address load. */ + /* Try for PC-relative address load. For odd addresses, + attempt to use an offset from the start of the TB. */ if ((sval & 1) == 0) { ptrdiff_t off = tcg_pcrel_diff(s, (void *)sval) >> 1; if (off == (int32_t)off) { tcg_out_insn(s, RIL, LARL, ret, off); return; } + } else if (USE_REG_TB && !in_prologue) { + ptrdiff_t off = sval - (uintptr_t)s->code_gen_ptr; + if (off == sextract64(off, 0, 20)) { + /* This is certain to be an address within TB, and therefore + OFF will be negative; don't try RX_LA. */ + tcg_out_insn(s, RXY, LAY, ret, TCG_REG_TB, TCG_REG_NONE, off); + return; + } } /* If extended immediates are not present, then we may have to issue @@ -663,6 +678,11 @@ static void tcg_out_movi(TCGContext *s, TCGType type, } } +static void tcg_out_movi(TCGContext *s, TCGType type, + TCGReg ret, tcg_target_long sval) +{ + tcg_out_movi_int(s, type, ret, sval, false); +} /* Emit a load/store type instruction. Inputs are: DATA: The register to be loaded or stored. @@ -739,6 +759,13 @@ static void tcg_out_ld_abs(TCGContext *s, TCGType type, TCGReg dest, void *abs) return; } } + if (USE_REG_TB) { + ptrdiff_t disp = abs - (void *)s->code_gen_ptr; + if (disp == sextract64(disp, 0, 20)) { + tcg_out_ld(s, type, dest, TCG_REG_TB, disp); + return; + } + } tcg_out_movi(s, TCG_TYPE_PTR, dest, addr & ~0xffff); tcg_out_ld(s, type, dest, dest, addr & 0xffff); @@ -1690,6 +1717,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, break; case INDEX_op_goto_tb: + a0 = args[0]; if (s->tb_jmp_insn_offset) { /* branch displacement must be aligned for atomic patching; * see if we need to add extra nop before branch @@ -1697,21 +1725,34 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, if (!QEMU_PTR_IS_ALIGNED(s->code_ptr + 1, 4)) { tcg_out16(s, NOP); } + tcg_debug_assert(!USE_REG_TB); tcg_out16(s, RIL_BRCL | (S390_CC_ALWAYS << 4)); - s->tb_jmp_insn_offset[args[0]] = tcg_current_code_size(s); + s->tb_jmp_insn_offset[a0] = tcg_current_code_size(s); s->code_ptr += 2; } else { - /* load address stored at s->tb_jmp_target_addr + args[0] */ - tcg_out_ld_abs(s, TCG_TYPE_PTR, TCG_TMP0, - s->tb_jmp_target_addr + args[0]); + /* load address stored at s->tb_jmp_target_addr + a0 */ + tcg_out_ld_abs(s, TCG_TYPE_PTR, TCG_REG_TB, + s->tb_jmp_target_addr + a0); /* and go there */ - tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, TCG_TMP0); + tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, TCG_REG_TB); + } + s->tb_jmp_reset_offset[a0] = tcg_current_code_size(s); + + /* For the unlinked path of goto_tb, we need to reset + TCG_REG_TB to the beginning of this TB. */ + if (USE_REG_TB) { + int ofs = -tcg_current_code_size(s); + assert(ofs == (int16_t)ofs); + tcg_out_insn(s, RI, AGHI, TCG_REG_TB, ofs); } - s->tb_jmp_reset_offset[args[0]] = tcg_current_code_size(s); break; case INDEX_op_goto_ptr: - tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, args[0]); + a0 = args[0]; + if (USE_REG_TB) { + tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_TB, a0); + } + tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, a0); break; OP_32_64(ld8u): @@ -2476,6 +2517,9 @@ static void tcg_target_init(TCGContext *s) /* XXX many insns can't be used with R0, so we better avoid it for now */ tcg_regset_set_reg(s->reserved_regs, TCG_REG_R0); tcg_regset_set_reg(s->reserved_regs, TCG_REG_CALL_STACK); + if (USE_REG_TB) { + tcg_regset_set_reg(s->reserved_regs, TCG_REG_TB); + } } #define FRAME_SIZE ((int)(TCG_TARGET_CALL_STACK_OFFSET \ @@ -2496,12 +2540,17 @@ static void tcg_target_qemu_prologue(TCGContext *s) #ifndef CONFIG_SOFTMMU if (guest_base >= 0x80000) { - tcg_out_movi(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base); + tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base, true); tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG); } #endif tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]); + if (USE_REG_TB) { + tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_TB, + tcg_target_call_iarg_regs[1]); + } + /* br %r3 (go to TB) */ tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, tcg_target_call_iarg_regs[1]); From patchwork Thu Sep 7 22:40:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111983 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp727769qge; Thu, 7 Sep 2017 15:50:33 -0700 (PDT) X-Received: by 10.55.203.210 with SMTP id u79mr1174005qkl.189.1504824633130; Thu, 07 Sep 2017 15:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824633; cv=none; d=google.com; s=arc-20160816; b=Fj0qvTV5EGKVqWUG3iX4/4eDIkIhwZmUhtpno3AL4HYB3PMhp2LzQ3OS7Fdfuk5zcI gmgSt3JG7qmwhqUDQAiYFf+ljPE64HaK7DZwEKp+VF38Wu103tSLY3HXmZSAWV+y2dUr VfKVDYbIfaKA03XI5tjoZ3WJqa6Xy7nNJ0sogyHA9MqoX9ooEJo3sTl2szVL8/VmsmrB C8FDXgai8+T4xl+P94I4B2M9vmWyenFFuYgkYppt8mf+h+1eOvK8sbI6ODe/O7Fpsl1F fRR/5oUuAcKl9UPJw/zMiPgOc97QCtbfqgMPSNVKMPvMoLy0MuJyqnNnJ3Ku0zteZUC3 Dq+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=D31O/54Mb9A2MohOqll5CAXSVcOTWb7bn2dqdUgudLw=; b=tkTdXvoOTfi1mnEFNLKxcopDFhinsLiCiObI+5lEYNuvCpxJOomDNnnIeMyGGWafFr H2APgJBgj1j1LiQV6cEWSXLpmakhWu3KpYgy3Ur0UGHxk+qnn6G1gLjBB4eRwuA8SojD f5Nvm2dbgY0PCdSoZuApNDqLFERyQkg4o7cerPxXgEIIPg2z1iADlUMfe4HLcrXUdWPG pWP+fuViLK6Fa8LnSkpM3UOAIsEKiNmWgaZ+Rzq4Fgo51Bod8Cr2rZLJ/EmbcmwzV0/T uNrotMSLyZJXgHXxid94I+G0+vpsLFgKGHIlNPREbcnrDBm6APrIrUj5dtDCLBdr0Ag9 cjZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CIZg1MuI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h184si450945qkf.379.2017.09.07.15.50.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:50:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CIZg1MuI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5d0-0002Pd-Qu for patch@linaro.org; Thu, 07 Sep 2017 18:50:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Tw-0002yt-PB for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5Tr-00086H-VS for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:08 -0400 Received: from mail-pg0-x232.google.com ([2607:f8b0:400e:c05::232]:37894) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5Tr-00085b-PI for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:03 -0400 Received: by mail-pg0-x232.google.com with SMTP id v66so1788082pgb.5 for ; Thu, 07 Sep 2017 15:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=D31O/54Mb9A2MohOqll5CAXSVcOTWb7bn2dqdUgudLw=; b=CIZg1MuIwqRCwe5o5unI5m6eLfXNnEW6lU8TAoV7i4ufkt201S/eOmhF4SOHCfxUUB jt22TC3bDCbCnPJ708C7EJAXv82U0iMlIIBPvfoCUEFbyrsKzO2r4QNc0K9WubCw8db9 FoL0HVSq5sr8gVo5rdHSL7F0/gPYWqTDblQRU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=D31O/54Mb9A2MohOqll5CAXSVcOTWb7bn2dqdUgudLw=; b=N3TUnBp+AttLuftr8Gl8UzAutUbkFpbXb1mr9g6/f+3vw0KRpXmdxF3tBUxymf828T BGOvB0yNYOfJj6Q6o68D2gVIflbq4rXIyuXay5olGWYOkctnTs6bsHZ96UHlV4KQ+v9K bmi4Q9uNqENDZb0dXydSyExF8nYMbrZaF+VCUxXAN3vb4pWmsLpKoh8YS4ZXH0FcFiag F7DYayoq1HXh8aJsUGegsNorfOzZSlgqQCKOXf9fb9d83R57JAiXwzEsgSsm0dpNuiST o/XcyfNPLyPgGkKemDfqUhkmhhfavZWG9L1eQGwLPluFgMAKAfrciEiHUj8MQ8Xe3Jwe btvw== X-Gm-Message-State: AHPjjUjQbS2JXdPcEL2btDcGXxyodyPCtk5gOElcvkzXXN1ZMU0SAoc6 2p64DO8c0BJ8lyUgiWkFtg== X-Google-Smtp-Source: ADKCNb5OuI8i2lHiSBe/jOKOB+up0EoPJ9TX7ivy/kY3xp8nW6SWlBl7g2BQilWJ2cjnv6G/F9hMNg== X-Received: by 10.99.106.69 with SMTP id f66mr936143pgc.425.1504824062498; Thu, 07 Sep 2017 15:41:02 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:34 -0700 Message-Id: <20170907224051.21518-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::232 Subject: [Qemu-devel] [PULL 06/23] tcg/s390: Fix sign of patch_reloc addend X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson We were passing in -2 instead of +2, but then ignoring the actual contents of addend in the calculation. Signed-off-by: Richard Henderson --- tcg/s390/tcg-target.inc.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) -- 2.13.5 diff --git a/tcg/s390/tcg-target.inc.c b/tcg/s390/tcg-target.inc.c index e007586315..59c0da0922 100644 --- a/tcg/s390/tcg-target.inc.c +++ b/tcg/s390/tcg-target.inc.c @@ -360,21 +360,22 @@ uint64_t s390_facilities; static void patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) { - intptr_t pcrel2 = (tcg_insn_unit *)value - (code_ptr - 1); - tcg_debug_assert(addend == -2); + intptr_t pcrel2; + + value += addend; + pcrel2 = (tcg_insn_unit *)value - code_ptr; switch (type) { case R_390_PC16DBL: - tcg_debug_assert(pcrel2 == (int16_t)pcrel2); + assert(pcrel2 == (int16_t)pcrel2); tcg_patch16(code_ptr, pcrel2); break; case R_390_PC32DBL: - tcg_debug_assert(pcrel2 == (int32_t)pcrel2); + assert(pcrel2 == (int32_t)pcrel2); tcg_patch32(code_ptr, pcrel2); break; default: - tcg_abort(); - break; + g_assert_not_reached(); } } @@ -1270,11 +1271,11 @@ static void tgen_branch(TCGContext *s, int cc, TCGLabel *l) tgen_gotoi(s, cc, l->u.value_ptr); } else if (USE_LONG_BRANCHES) { tcg_out16(s, RIL_BRCL | (cc << 4)); - tcg_out_reloc(s, s->code_ptr, R_390_PC32DBL, l, -2); + tcg_out_reloc(s, s->code_ptr, R_390_PC32DBL, l, 2); s->code_ptr += 2; } else { tcg_out16(s, RI_BRC | (cc << 4)); - tcg_out_reloc(s, s->code_ptr, R_390_PC16DBL, l, -2); + tcg_out_reloc(s, s->code_ptr, R_390_PC16DBL, l, 2); s->code_ptr += 1; } } @@ -1289,7 +1290,7 @@ static void tgen_compare_branch(TCGContext *s, S390Opcode opc, int cc, } else { /* We need to keep the offset unchanged for retranslation. */ off = s->code_ptr[1]; - tcg_out_reloc(s, s->code_ptr + 1, R_390_PC16DBL, l, -2); + tcg_out_reloc(s, s->code_ptr + 1, R_390_PC16DBL, l, 2); } tcg_out16(s, (opc & 0xff00) | (r1 << 4) | r2); @@ -1307,7 +1308,7 @@ static void tgen_compare_imm_branch(TCGContext *s, S390Opcode opc, int cc, } else { /* We need to keep the offset unchanged for retranslation. */ off = s->code_ptr[1]; - tcg_out_reloc(s, s->code_ptr + 1, R_390_PC16DBL, l, -2); + tcg_out_reloc(s, s->code_ptr + 1, R_390_PC16DBL, l, 2); } tcg_out16(s, (opc & 0xff00) | (r1 << 4) | cc); @@ -1571,7 +1572,7 @@ static void tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) TCGMemOpIdx oi = lb->oi; TCGMemOp opc = get_memop(oi); - patch_reloc(lb->label_ptr[0], R_390_PC16DBL, (intptr_t)s->code_ptr, -2); + patch_reloc(lb->label_ptr[0], R_390_PC16DBL, (intptr_t)s->code_ptr, 2); tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_R2, TCG_AREG0); if (TARGET_LONG_BITS == 64) { @@ -1592,7 +1593,7 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb) TCGMemOpIdx oi = lb->oi; TCGMemOp opc = get_memop(oi); - patch_reloc(lb->label_ptr[0], R_390_PC16DBL, (intptr_t)s->code_ptr, -2); + patch_reloc(lb->label_ptr[0], R_390_PC16DBL, (intptr_t)s->code_ptr, 2); tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_R2, TCG_AREG0); if (TARGET_LONG_BITS == 64) { From patchwork Thu Sep 7 22:40:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111978 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp724326qge; Thu, 7 Sep 2017 15:46:19 -0700 (PDT) X-Received: by 10.55.73.213 with SMTP id w204mr1299160qka.215.1504824379579; Thu, 07 Sep 2017 15:46:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824379; cv=none; d=google.com; s=arc-20160816; b=Pomlj0Wd0pQDG7ztUpJDb+PJEsZvm4JqZnFwfglWg7n6jc5L/KwJeL6z4V0U5VCTB5 f2+f5eQUg1wFG6+9aqnYT/yI6vzsviaa8oc2z9YbwCqmLmIWzrseIPEdOPDDZoTjTAbR Mauzlr+QjQK/2eQIgdmJd9uqoWAU0XL1Z+rXF43vzWkyyq/n+9sNDBkiHkpHVijxqxSy ZBgBsp7SE+W+Fsi17f60w4f1HwQlg7wjiNcRmpNATYeKfcKI7No2ADl0qxt4bKiNpLEd 8S04e9uVB792brN4eTZKLUCZw4xBo2+LjgueOeJWdPiuKqeRlZGJQSfaaSKxNiMCjvr8 zJpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=sJPZYRXenZB9l4KsHJUB2AueMWnCWt02iaTztenK5Zk=; b=qzdrg/V7p7WM7crWOsJJhpHlEiASEuFEzAG7AL1MNG205EN2iVeDdj/L1TP2gDFBSf v2fE6pROmloKrnlu6PYbTbsNeseeslpsbi7LwbOzpe2jOyFJiJhNa6Mza9c5a5/M3X7w 6TQKvVWhWiDUuE8XkFuvrbcXfLuxLwGq0Eawqn1ye41oU53+Ys9GIQCg8wTo5dt0fAAK CDKEAwvER+02QaS5WfKrAU8qxonifu0A5id5OUv5unSfDdeWXxRtnY96Esf08VYpme2C 83dzpLKT43BBOqL8PpY5rTPoVKH1KrKOqRdyeSKpUoZEe80Hzvwql2vPlkYZvyJvu3ui eX7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jsbqvqt+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t123si477237qke.262.2017.09.07.15.46.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:46:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jsbqvqt+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42535 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Yv-0006xu-B3 for patch@linaro.org; Thu, 07 Sep 2017 18:46:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Ty-00031e-Tl for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5Tt-00087W-PN for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:10 -0400 Received: from mail-pg0-x235.google.com ([2607:f8b0:400e:c05::235]:37894) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5Tt-00086u-H5 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:05 -0400 Received: by mail-pg0-x235.google.com with SMTP id v66so1788168pgb.5 for ; Thu, 07 Sep 2017 15:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sJPZYRXenZB9l4KsHJUB2AueMWnCWt02iaTztenK5Zk=; b=jsbqvqt+35Uh5cmXuTfgbCcIUhAUCVzzD7h8Y/cmxB0/mdnn5XcEoxRV8bpUWiUAJw iqPqaVDjsP0CBk2nxxnrHSerwCDZSynW7e5wgYbX+9hmTMPDKUiQv162YN9jNfWmXsEi b2qBsyR4zAEmR/RpZRPrkUsaTYYpM1Z0ELGOQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sJPZYRXenZB9l4KsHJUB2AueMWnCWt02iaTztenK5Zk=; b=VVKrLTuuKeOZy4gdo1cJ9g6FcgM2r54hmqwJgvY7PGIFovC/JeGoRgoYo3k8X0QOfd GvuMJTU8kgTlBD63iHZWaz0yGkBiMu/Ndc0ASktoa5cDiyTSPwQ9kkbNkgcRr7EYYW12 B84axXK9qFaSSncCG52xFCq/78zFdYCch91XNx9TCdnMDy40zE4iLq4uwGNsnVP1zlRM ziJHlpTlFniwbXoR6ZDzV6W3f5JsZECH1G0TfLrlygmI3Xuj9S9AsPotr5tE7I8VSh8m lIqVBluIQXyA7d3y39L91M/TwmNs37sv/h98jZ+wE76pr+ik0vQFZJnqyTSoUwoZkKza 9/2g== X-Gm-Message-State: AHPjjUjHdc6rQ49c4iYwM875BD1mDqynGKSgQSptmh3uf9BJvYHhL4Yh PMbkMqx5Q2byzqvGq3PLTg== X-Google-Smtp-Source: ADKCNb576cECp2qzAj1Tw0h5mxFoBNCU1JQ3sy6m0YDIp3SY+zrNZ7HKTVbHMAWeyuBWegOhau8xyw== X-Received: by 10.99.67.130 with SMTP id q124mr940512pga.97.1504824064097; Thu, 07 Sep 2017 15:41:04 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:35 -0700 Message-Id: <20170907224051.21518-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::235 Subject: [Qemu-devel] [PULL 07/23] tcg/s390: Use constant pool for movi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Split out maybe_out_small_movi for use with other operations that want to add to the constant pool. Signed-off-by: Richard Henderson --- include/elf.h | 3 +- tcg/s390/tcg-target.h | 1 + tcg/s390/tcg-target.inc.c | 130 +++++++++++++++++++++++++++------------------- 3 files changed, 80 insertions(+), 54 deletions(-) -- 2.13.5 diff --git a/include/elf.h b/include/elf.h index cd51434877..e8a515ce3d 100644 --- a/include/elf.h +++ b/include/elf.h @@ -942,8 +942,9 @@ typedef struct { #define R_390_TLS_DTPOFF 55 /* Offset in TLS block. */ #define R_390_TLS_TPOFF 56 /* Negate offset in static TLS block. */ +#define R_390_20 57 /* Keep this the last entry. */ -#define R_390_NUM 57 +#define R_390_NUM 58 /* x86-64 relocation types */ #define R_X86_64_NONE 0 /* No reloc */ diff --git a/tcg/s390/tcg-target.h b/tcg/s390/tcg-target.h index 9c9c8cd464..6f2b06a7d1 100644 --- a/tcg/s390/tcg-target.h +++ b/tcg/s390/tcg-target.h @@ -158,5 +158,6 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS #endif +#define TCG_TARGET_NEED_POOL_LABELS #endif diff --git a/tcg/s390/tcg-target.inc.c b/tcg/s390/tcg-target.inc.c index 59c0da0922..29b77ff67f 100644 --- a/tcg/s390/tcg-target.inc.c +++ b/tcg/s390/tcg-target.inc.c @@ -29,6 +29,7 @@ #error "unsupported code generation mode" #endif +#include "tcg-pool.inc.c" #include "elf.h" /* ??? The translation blocks produced by TCG are generally small enough to @@ -361,6 +362,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) { intptr_t pcrel2; + uint32_t old; value += addend; pcrel2 = (tcg_insn_unit *)value - code_ptr; @@ -374,6 +376,12 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type, assert(pcrel2 == (int32_t)pcrel2); tcg_patch32(code_ptr, pcrel2); break; + case R_390_20: + assert(value == sextract64(value, 0, 20)); + old = *(uint32_t *)code_ptr & 0xf00000ff; + old |= ((value & 0xfff) << 16) | ((value & 0xff000) >> 4); + tcg_patch32(code_ptr, old); + break; default: g_assert_not_reached(); } @@ -562,14 +570,16 @@ static void tcg_out_mov(TCGContext *s, TCGType type, TCGReg dst, TCGReg src) } } -/* load a register with an immediate value */ -static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, - tcg_target_long sval, bool in_prologue) -{ - static const S390Opcode lli_insns[4] = { - RI_LLILL, RI_LLILH, RI_LLIHL, RI_LLIHH - }; +static const S390Opcode lli_insns[4] = { + RI_LLILL, RI_LLILH, RI_LLIHL, RI_LLIHH +}; +static const S390Opcode ii_insns[4] = { + RI_IILL, RI_IILH, RI_IIHL, RI_IIHH +}; +static bool maybe_out_small_movi(TCGContext *s, TCGType type, + TCGReg ret, tcg_target_long sval) +{ tcg_target_ulong uval = sval; int i; @@ -581,17 +591,37 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, /* Try all 32-bit insns that can load it in one go. */ if (sval >= -0x8000 && sval < 0x8000) { tcg_out_insn(s, RI, LGHI, ret, sval); - return; + return true; } for (i = 0; i < 4; i++) { tcg_target_long mask = 0xffffull << i*16; if ((uval & mask) == uval) { tcg_out_insn_RI(s, lli_insns[i], ret, uval >> i*16); - return; + return true; } } + return false; +} + +/* load a register with an immediate value */ +static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, + tcg_target_long sval, bool in_prologue) +{ + tcg_target_ulong uval; + + /* Try all 32-bit insns that can load it in one go. */ + if (maybe_out_small_movi(s, type, ret, sval)) { + return; + } + + uval = sval; + if (type == TCG_TYPE_I32) { + uval = (uint32_t)sval; + sval = (int32_t)sval; + } + /* Try all 48-bit insns that can load it in one go. */ if (s390_facilities & FACILITY_EXT_IMM) { if (sval == (int32_t)sval) { @@ -603,7 +633,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, return; } if ((uval & 0xffffffff) == 0) { - tcg_out_insn(s, RIL, LLIHF, ret, uval >> 31 >> 1); + tcg_out_insn(s, RIL, LLIHF, ret, uval >> 32); return; } } @@ -626,55 +656,44 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, } } - /* If extended immediates are not present, then we may have to issue - several instructions to load the low 32 bits. */ - if (!(s390_facilities & FACILITY_EXT_IMM)) { - /* A 32-bit unsigned value can be loaded in 2 insns. And given - that the lli_insns loop above did not succeed, we know that - both insns are required. */ - if (uval <= 0xffffffff) { - tcg_out_insn(s, RI, LLILL, ret, uval); - tcg_out_insn(s, RI, IILH, ret, uval >> 16); - return; - } + /* A 32-bit unsigned value can be loaded in 2 insns. And given + that LLILL, LLIHL, LLILF above did not succeed, we know that + both insns are required. */ + if (uval <= 0xffffffff) { + tcg_out_insn(s, RI, LLILL, ret, uval); + tcg_out_insn(s, RI, IILH, ret, uval >> 16); + return; + } - /* If all high bits are set, the value can be loaded in 2 or 3 insns. - We first want to make sure that all the high bits get set. With - luck the low 16-bits can be considered negative to perform that for - free, otherwise we load an explicit -1. */ - if (sval >> 31 >> 1 == -1) { - if (uval & 0x8000) { - tcg_out_insn(s, RI, LGHI, ret, uval); - } else { - tcg_out_insn(s, RI, LGHI, ret, -1); - tcg_out_insn(s, RI, IILL, ret, uval); - } - tcg_out_insn(s, RI, IILH, ret, uval >> 16); - return; + /* When allowed, stuff it in the constant pool. */ + if (!in_prologue) { + if (USE_REG_TB) { + tcg_out_insn(s, RXY, LG, ret, TCG_REG_TB, TCG_REG_NONE, 0); + new_pool_label(s, sval, R_390_20, s->code_ptr - 2, + -(intptr_t)s->code_gen_ptr); + } else { + tcg_out_insn(s, RIL, LGRL, ret, 0); + new_pool_label(s, sval, R_390_PC32DBL, s->code_ptr - 2, 2); } + return; } - /* If we get here, both the high and low parts have non-zero bits. */ - - /* Recurse to load the lower 32-bits. */ - tcg_out_movi(s, TCG_TYPE_I64, ret, uval & 0xffffffff); - - /* Insert data into the high 32-bits. */ - uval = uval >> 31 >> 1; + /* What's left is for the prologue, loading GUEST_BASE, and because + it failed to match above, is known to be a full 64-bit quantity. + We could try more than this, but it probably wouldn't pay off. */ if (s390_facilities & FACILITY_EXT_IMM) { - if (uval < 0x10000) { - tcg_out_insn(s, RI, IIHL, ret, uval); - } else if ((uval & 0xffff) == 0) { - tcg_out_insn(s, RI, IIHH, ret, uval >> 16); - } else { - tcg_out_insn(s, RIL, IIHF, ret, uval); - } + tcg_out_insn(s, RIL, LLILF, ret, uval); + tcg_out_insn(s, RIL, IIHF, ret, uval >> 32); } else { - if (uval & 0xffff) { - tcg_out_insn(s, RI, IIHL, ret, uval); - } - if (uval & 0xffff0000) { - tcg_out_insn(s, RI, IIHH, ret, uval >> 16); + const S390Opcode *insns = lli_insns; + int i; + + for (i = 0; i < 4; i++) { + uint16_t part = uval >> (16 * i); + if (part) { + tcg_out_insn_RI(s, insns[i], ret, part); + insns = ii_insns; + } } } } @@ -2573,6 +2592,11 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, TCG_REG_R14); } +static void tcg_out_nop_fill(tcg_insn_unit *p, int count) +{ + memset(p, 0x07, count * sizeof(tcg_insn_unit)); +} + typedef struct { DebugFrameHeader h; uint8_t fde_def_cfa[4]; From patchwork Thu Sep 7 22:40:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111981 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp726284qge; Thu, 7 Sep 2017 15:48:49 -0700 (PDT) X-Received: by 10.200.25.124 with SMTP id g57mr1377783qtk.60.1504824529803; Thu, 07 Sep 2017 15:48:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824529; cv=none; d=google.com; s=arc-20160816; b=Y0NEveSboiHvbSs3ellml/bWvNXZWGl9lEGHrzL2n493EtjLOk8VZ7LcIhcSQ+W9UO CFMeLj1/bQlebdJg0QQJvUsl6HvDNBxhXwyTMnysbVlBJ1wa/H/g99P8SAnhGJGYuGPT UDX6VMp9i1KRX7S9NuHXa20YBWOKCznJMGCrVjZ4tdDa9WoF264+SSOtoyj669YMCo1L /qqeqb4msL00ZUUvFbtIrEzxOUedz3SsaSC6jZoiZN65P+h1VjWRu0lFUf948qXsyDU6 I20eU2TileQrqOzjUVlwIEorfspdEdGDjvsQaHwskiebz0wrdewVdD3UMW/Dy+G3eqB3 D9FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=rGbRrj0jmlEL38dOoU7mQ92x2mbFZxz0QiK0pcfEGz0=; b=iQUkm7ck+bfbHTgNdlmXxqS/2Rc4zvZg3v2B/IjU4VWZdhXjC9LpaULZ2mWpoqoNrk gIPGEyD/vlT8EqDeCoIIgpcr1/0BKoEzzQmA1ZQ3rG2Frm67xLZoJezKu24teW9kIv3V Tj5WuAUihi3TQvSvMsLgdhBaNXTfM8HOtB9uKayl5DhxwoE2BkbCJnuurD0ZJ7XM+X07 ZqLWEekPGO7inAWTwr29dGXZ7ZqvDZAax7+zb3558xHxee+8ok/diUdoZP27c0u5Bybp 81BJZnpIvewyXYfuR67Dq4cMwI6esmqSqDyWE2zQSOEf8BKddT+RIYhYuZAme3cSfg9v AycA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jBYkufR6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id r9si359197qkh.90.2017.09.07.15.48.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:48:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=jBYkufR6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5bL-0000r2-PX for patch@linaro.org; Thu, 07 Sep 2017 18:48:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Tz-00032B-NE for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5Tu-00088V-TC for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:11 -0400 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]:32922) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5Tu-00087n-NS for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:06 -0400 Received: by mail-pf0-x229.google.com with SMTP id y29so859862pff.0 for ; Thu, 07 Sep 2017 15:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rGbRrj0jmlEL38dOoU7mQ92x2mbFZxz0QiK0pcfEGz0=; b=jBYkufR60avJ+5wm8Zgr7Asm/1ifTFL8S73nIP2HAcABj0mGwEr4oaICgFlhMAcEq4 eCY22ysDa02W7FPM5j4cey4Wp4nS8PT8T5gEVT59Xs+K2mCPFRiivpNmVJNpxYzFeMZ9 r8tf13lItEqzVZBOAgW7ZsJ9iOz3/ls61rkbU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rGbRrj0jmlEL38dOoU7mQ92x2mbFZxz0QiK0pcfEGz0=; b=kz0CZloXi/iOs5DsREi84gnoDNJELGBH8w0+WzWuo1bo37/X50Cj2bPOrvhkigPvQC EDynH7ON1F+PtbS3XmDEfZmqOwrzXYJCVhGDpB0KjPWuQd/IIzTnoIw4J0Zo1GVsEZyU TiRYxzeMx0k7yr/prYI6NCP3kRwPZOFFdSbNaA9OFVEKQMOofXYesekjaFf5QypyrHU7 M1+VD77sBrdpsrG/FzyQv4e2txiUyGnvrSqQxm1/Bo3i0QwOGQSBW84Np/Lb5HRRcWd4 COkqtViRAiRQUmk5VthZASBrps+SqGHlzbdWOSI8Bo9m0RMqt9QUzImGxu6qL6c5MueB cJlA== X-Gm-Message-State: AHPjjUgVBxDUHRh3A06jTpWWahyquiIGupWi1WFU8D1hgu5OPyy53+r9 Yb4ITuAFhX3dZX1rKExKuA== X-Google-Smtp-Source: ADKCNb6F7621rB8eAoZKsClcOtWl13/2AUhAvW1V1aSKadjC8ed4lXDBBmovcFZJtxUfaqmJIepk9w== X-Received: by 10.99.130.198 with SMTP id w189mr918235pgd.175.1504824065457; Thu, 07 Sep 2017 15:41:05 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:36 -0700 Message-Id: <20170907224051.21518-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::229 Subject: [Qemu-devel] [PULL 08/23] tcg/s390: Use constant pool for andi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/s390/tcg-target.inc.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) -- 2.13.5 diff --git a/tcg/s390/tcg-target.inc.c b/tcg/s390/tcg-target.inc.c index 29b77ff67f..4be57c5765 100644 --- a/tcg/s390/tcg-target.inc.c +++ b/tcg/s390/tcg-target.inc.c @@ -224,6 +224,7 @@ typedef enum S390Opcode { RXY_LRVG = 0xe30f, RXY_LRVH = 0xe31f, RXY_LY = 0xe358, + RXY_NG = 0xe380, RXY_STCY = 0xe372, RXY_STG = 0xe324, RXY_STHY = 0xe370, @@ -985,8 +986,17 @@ static void tgen_andi(TCGContext *s, TCGType type, TCGReg dest, uint64_t val) return; } - /* Fall back to loading the constant. */ - tcg_out_movi(s, type, TCG_TMP0, val); + /* Use the constant pool if USE_REG_TB, but not for small constants. */ + if (USE_REG_TB) { + if (!maybe_out_small_movi(s, type, TCG_TMP0, val)) { + tcg_out_insn(s, RXY, NG, dest, TCG_REG_TB, TCG_REG_NONE, 0); + new_pool_label(s, val & valid, R_390_20, s->code_ptr - 2, + -(intptr_t)s->code_gen_ptr); + return; + } + } else { + tcg_out_movi(s, type, TCG_TMP0, val); + } if (type == TCG_TYPE_I32) { tcg_out_insn(s, RR, NR, dest, TCG_TMP0); } else { @@ -2341,6 +2351,8 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) return &r_r_ri; case INDEX_op_sub_i32: case INDEX_op_sub_i64: + case INDEX_op_and_i32: + case INDEX_op_and_i64: return (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_ri : &r_0_ri); case INDEX_op_mul_i32: @@ -2375,10 +2387,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) ? (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_rM : &r_0_rM) : &r_0_r); - case INDEX_op_and_i32: - case INDEX_op_and_i64: - return (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_ri : &r_0_ri); - case INDEX_op_shl_i32: case INDEX_op_shr_i32: case INDEX_op_sar_i32: From patchwork Thu Sep 7 22:40:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111988 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp765922ybm; Thu, 7 Sep 2017 15:54:08 -0700 (PDT) X-Received: by 10.200.57.83 with SMTP id t19mr1479036qtb.150.1504824847940; Thu, 07 Sep 2017 15:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824847; cv=none; d=google.com; s=arc-20160816; b=ScfYvzMjXLVq4XhIDXd+y4ITG62nrM5XbImwDiGKBdO5S+J7augW3mzTW+rCJxGEqE XRSMf/6E22xtlQV66OWo1fOTezsQWgLGEiEa/GryPIf6z6kq+7LVIkyxczFEBaMFLHc9 HssVJIEQXadusm0Q1/2wkTcsp9bayjhUL/I5iOndzmBe7lcu+0HNq7+Afu5FWwo9z4gm nedKMmbqqVhFJxhdMjxRX3dq1EcKKhvnp1GwZMenUn05gg53mxqyE5IXJDuisVI99TUj ZECCQbX2EgNKs9IYjFff1MCRRW4r7GHk3YP/dIBLQXUdfUnAdp1fUFTtlVzbXV4EHEXt IO9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=6BZlkqXrN46LW44YziE4XJkyjG2E07rBsSu0/OqDgZ4=; b=hNSTocrbNe2x8jyoJW0kVW/g1W4+3TtgHAorYAKz1e35zFSH+RNbf6qQaspu0r3Y/8 oufd0G1u3guCy++qwLy2dY7838GSl3KBuVuS2cM0neVCClRGqiDTrhVyhNxAQdtk5Ckc wMZ6hp4Q/inKa7U3nd9wm36NZJqhESyu2xq4CWDfCr2u+SQVNoEE4Xfyb3AWEEJhjKzs xdktpnM+b3qpXLPyxrSZEk4HUZ1mQ4X+5Rs93LyoX4Etvnz1ssbbm32BxC4Lx4bYbNHA XpiBsSaAkMlxBNz66E4EAr6oHodStTX+MhBNTRI+2fu9sCb1p1YFell3oKIo1pO7SA14 CPWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=X0C8TEZH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id s53si495332qtj.322.2017.09.07.15.54.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:54:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=X0C8TEZH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5gT-0005IS-MR for patch@linaro.org; Thu, 07 Sep 2017 18:54:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5U2-00034f-10 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5Tw-0008AU-UJ for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:14 -0400 Received: from mail-pg0-x236.google.com ([2607:f8b0:400e:c05::236]:36680) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5Tw-00089a-Mf for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:08 -0400 Received: by mail-pg0-x236.google.com with SMTP id m9so1818296pgd.3 for ; Thu, 07 Sep 2017 15:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6BZlkqXrN46LW44YziE4XJkyjG2E07rBsSu0/OqDgZ4=; b=X0C8TEZHwGE0r3KhVzHXhj0eogm0P9cokFHCW8TqzmLZTf9NXsf2q2fujsOy0aK2Em v06iN67Et+Fl1YkwiHOHvcc6GZESsgj8rwUBAb/yGk+pnzroRAq3GiVyVKg/wX6JBJue gTwn4nKGZhL3UHuHTK1arPonfB1wbFm2MVQ+A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6BZlkqXrN46LW44YziE4XJkyjG2E07rBsSu0/OqDgZ4=; b=cBOCBeYTBh4kZTU1mbf9323lrfa1fpHDbZKO5nt5VfVrPBJGLA6gtkdo1sfQVFdc/1 M0IN/J8q8Vzpq4P5F0p8CgU7LFOOvT5P7S9BfF3oczYjq/xAegmgxUeM467hHfLhCKnh vkmQFjggAgETSFmdUP6zKPBhp/yR0hwxb66xmRzfjRCbdRPGoMUb2vyr1fhZMjXqUq1y jkMyUrAblF2bhvSm7q1ZBDmCkfF0Ej36T8MnhbM3HvRHK/CJePMLuBlVKA1Y5rt123zC wTE1L7gZMAT529b34nafJqH4Q8DBwh/9gHn1RPmQj0uWK4d9AGi9LOE63K1n1+U0QG4K 3GEQ== X-Gm-Message-State: AHPjjUiAj/W+fVAvaxDd2OgM591kDBj0aXSAv2SX/3eShFkPEV5WE2LA +gclL6wxRGTcm6L81+UCnQ== X-Google-Smtp-Source: ADKCNb69USj5KoA5Uhw6McWLOPHNZowhGXze5T7tUwEnLZx9RftruzBpr6yYUoin0GBZB/xYAXPDsw== X-Received: by 10.99.3.9 with SMTP id 9mr932146pgd.205.1504824067239; Thu, 07 Sep 2017 15:41:07 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:37 -0700 Message-Id: <20170907224051.21518-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::236 Subject: [Qemu-devel] [PULL 09/23] tcg/s390: Use constant pool for ori X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/s390/tcg-target.inc.c | 74 ++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 40 deletions(-) -- 2.13.5 diff --git a/tcg/s390/tcg-target.inc.c b/tcg/s390/tcg-target.inc.c index 4be57c5765..83fac71c31 100644 --- a/tcg/s390/tcg-target.inc.c +++ b/tcg/s390/tcg-target.inc.c @@ -225,6 +225,7 @@ typedef enum S390Opcode { RXY_LRVH = 0xe31f, RXY_LY = 0xe358, RXY_NG = 0xe380, + RXY_OG = 0xe381, RXY_STCY = 0xe372, RXY_STG = 0xe324, RXY_STHY = 0xe370, @@ -1004,55 +1005,60 @@ static void tgen_andi(TCGContext *s, TCGType type, TCGReg dest, uint64_t val) } } -static void tgen64_ori(TCGContext *s, TCGReg dest, tcg_target_ulong val) +static void tgen_ori(TCGContext *s, TCGType type, TCGReg dest, uint64_t val) { static const S390Opcode oi_insns[4] = { RI_OILL, RI_OILH, RI_OIHL, RI_OIHH }; - static const S390Opcode nif_insns[2] = { + static const S390Opcode oif_insns[2] = { RIL_OILF, RIL_OIHF }; int i; /* Look for no-op. */ - if (val == 0) { + if (unlikely(val == 0)) { return; } - if (s390_facilities & FACILITY_EXT_IMM) { - /* Try all 32-bit insns that can perform it in one go. */ - for (i = 0; i < 4; i++) { - tcg_target_ulong mask = (0xffffull << i*16); - if ((val & mask) != 0 && (val & ~mask) == 0) { - tcg_out_insn_RI(s, oi_insns[i], dest, val >> i*16); - return; - } + /* Try all 32-bit insns that can perform it in one go. */ + for (i = 0; i < 4; i++) { + tcg_target_ulong mask = (0xffffull << i*16); + if ((val & mask) != 0 && (val & ~mask) == 0) { + tcg_out_insn_RI(s, oi_insns[i], dest, val >> i*16); + return; } + } - /* Try all 48-bit insns that can perform it in one go. */ + /* Try all 48-bit insns that can perform it in one go. */ + if (s390_facilities & FACILITY_EXT_IMM) { for (i = 0; i < 2; i++) { tcg_target_ulong mask = (0xffffffffull << i*32); if ((val & mask) != 0 && (val & ~mask) == 0) { - tcg_out_insn_RIL(s, nif_insns[i], dest, val >> i*32); + tcg_out_insn_RIL(s, oif_insns[i], dest, val >> i*32); return; } } + } + /* Use the constant pool if USE_REG_TB, but not for small constants. */ + if (maybe_out_small_movi(s, type, TCG_TMP0, val)) { + if (type == TCG_TYPE_I32) { + tcg_out_insn(s, RR, OR, dest, TCG_TMP0); + } else { + tcg_out_insn(s, RRE, OGR, dest, TCG_TMP0); + } + } else if (USE_REG_TB) { + tcg_out_insn(s, RXY, OG, dest, TCG_REG_TB, TCG_REG_NONE, 0); + new_pool_label(s, val, R_390_20, s->code_ptr - 2, + -(intptr_t)s->code_gen_ptr); + } else { /* Perform the OR via sequential modifications to the high and low parts. Do this via recursion to handle 16-bit vs 32-bit masks in each half. */ - tgen64_ori(s, dest, val & 0x00000000ffffffffull); - tgen64_ori(s, dest, val & 0xffffffff00000000ull); - } else { - /* With no extended-immediate facility, we don't need to be so - clever. Just iterate over the insns and mask in the constant. */ - for (i = 0; i < 4; i++) { - tcg_target_ulong mask = (0xffffull << i*16); - if ((val & mask) != 0) { - tcg_out_insn_RI(s, oi_insns[i], dest, val >> i*16); - } - } + tcg_debug_assert(s390_facilities & FACILITY_EXT_IMM); + tgen_ori(s, type, dest, val & 0x00000000ffffffffull); + tgen_ori(s, type, dest, val & 0xffffffff00000000ull); } } @@ -1872,7 +1878,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, a0 = args[0], a1 = args[1], a2 = (uint32_t)args[2]; if (const_args[2]) { tcg_out_mov(s, TCG_TYPE_I32, a0, a1); - tgen64_ori(s, a0, a2); + tgen_ori(s, TCG_TYPE_I32, a0, a2); } else if (a0 == a1) { tcg_out_insn(s, RR, OR, a0, a2); } else { @@ -2104,7 +2110,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, a0 = args[0], a1 = args[1], a2 = args[2]; if (const_args[2]) { tcg_out_mov(s, TCG_TYPE_I64, a0, a1); - tgen64_ori(s, a0, a2); + tgen_ori(s, TCG_TYPE_I64, a0, a2); } else if (a0 == a1) { tcg_out_insn(s, RRE, OGR, a0, a2); } else { @@ -2312,7 +2318,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) static const TCGTargetOpDef r_0_ri = { .args_ct_str = { "r", "0", "ri" } }; static const TCGTargetOpDef r_0_rI = { .args_ct_str = { "r", "0", "rI" } }; static const TCGTargetOpDef r_0_rJ = { .args_ct_str = { "r", "0", "rJ" } }; - static const TCGTargetOpDef r_0_rN = { .args_ct_str = { "r", "0", "rN" } }; static const TCGTargetOpDef r_0_rM = { .args_ct_str = { "r", "0", "rM" } }; static const TCGTargetOpDef a2_r = { .args_ct_str = { "r", "r", "0", "1", "r", "r" } }; @@ -2353,6 +2358,8 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) case INDEX_op_sub_i64: case INDEX_op_and_i32: case INDEX_op_and_i64: + case INDEX_op_or_i32: + case INDEX_op_or_i64: return (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_ri : &r_0_ri); case INDEX_op_mul_i32: @@ -2363,19 +2370,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) case INDEX_op_mul_i64: return (s390_facilities & FACILITY_GEN_INST_EXT ? &r_0_rJ : &r_0_rI); - case INDEX_op_or_i32: - /* The use of [iNM] constraints are optimization only, since a full - 64-bit immediate OR can always be performed with 4 sequential - OI[LH][LH] instructions. By rejecting certain negative ranges, - the immediate load plus the reg-reg OR is smaller. */ - return (s390_facilities & FACILITY_EXT_IMM - ? (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_ri : &r_0_ri) - : &r_0_rN); - case INDEX_op_or_i64: - return (s390_facilities & FACILITY_EXT_IMM - ? (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_rM : &r_0_rM) - : &r_0_rN); - case INDEX_op_xor_i32: /* Without EXT_IMM, no immediates are supported. Otherwise, rejecting certain negative ranges leads to smaller code. */ From patchwork Thu Sep 7 22:40:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111971 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp720388qge; Thu, 7 Sep 2017 15:41:53 -0700 (PDT) X-Received: by 10.200.40.27 with SMTP id 27mr1387694qtq.148.1504824113459; Thu, 07 Sep 2017 15:41:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824113; cv=none; d=google.com; s=arc-20160816; b=K4Ji+qSf3z7Iumcrk+SnZzcgdb3v4xSAetDVzky2EmTXnQwMCVsAFtTxZOfsCTSZEQ 2p1tsl/2bL/yeGKouyqYRC/FL6x1dutBamb5qcQ9RoBD/eR5zE0nSfc2BHtrHYirHoQV 1Zp/Un91inJxz/YyI693nRhaeRduBfkCK/8hrPydiKJ6+CFKsxwn5n2w/kxahBRBC01k iSW+5Edc0M9GYOAXqWK1CB/LPozI9KIYC8DuErBXINYi1iUr55vHwKF4xhQJM9jlmHFg xwSJhu+J9VJiiniNw5WHk25bAHo39r8hfRkLQlgsk1Z5auucNgqyXYD8xLC42TW3g9jc 00EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=oyI5YSLX1e92RjCHfsEWw9AulBFo8RWIJPmlBultFFM=; b=rJVRWr2B6zZ+mM67MHBK9tCbXvLgasDhp4xr31K0XV434iEAEfAy3ptqbkXVDxGDWk YIzH2rhWdUFhtNRbAsOgUM2WCwk4BRQhWU65wVH8swVGC/T06SStGgh2Syjwwnlj8fwe aMbipNlzmZie9YTFOZpfybP+gim/OjhwvL0VbH/ZPtkVvF07c5f0+4H8PYqMJm38M69S x+g/zdHF8S5cwPycUY5GMxiHQ2J1pBfE+bsPYYnZJeN9VO8BIk2Dr/XiSpKyrZf4No0h d9CQ128W9hGMHS5AKMvndj7VBhKJzHxCgDFwWuRyFUqk8RX8FMloxYvr83+LeEWsGAeI MerA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PIKpuhUK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 61si488914qtg.119.2017.09.07.15.41.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:41:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PIKpuhUK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Ud-0003Bn-5b for patch@linaro.org; Thu, 07 Sep 2017 18:41:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5U3-000369-GA for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5Ty-0008DF-Jc for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:15 -0400 Received: from mail-pg0-x22c.google.com ([2607:f8b0:400e:c05::22c]:37895) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5Ty-0008C0-BN for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:10 -0400 Received: by mail-pg0-x22c.google.com with SMTP id v66so1788427pgb.5 for ; Thu, 07 Sep 2017 15:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oyI5YSLX1e92RjCHfsEWw9AulBFo8RWIJPmlBultFFM=; b=PIKpuhUKOZHlwiaDmyMEaOKOpsvHB8dTCxeqBlty/hWy0tSU885F+wlpuulnFDmNvn /jV6zg1WsTpSQ3+070mcpttW6nkPMDs8Z2a8Hai3gs+W4Ie1UOMtFPKrxfad3lCSOgr7 xYDanSt5p2QhhSMlMhLLUJ7J9dMRkLwjSj3E8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oyI5YSLX1e92RjCHfsEWw9AulBFo8RWIJPmlBultFFM=; b=OdrnqWCcJLaQMstqRtVY/zE8z5hIRIMXYNa/W7ouID4oGGaXDW523HPp1ddgFbyjh2 7CRTwKPrYfW5RgEF/zFHMmMgbMeb4O11sEnqVsMmSToRKb9CEztj/erBlzkrcixAHxXT mMar1pgNIw0zDSZPiz0uMnODl741I4RwKy0hAACvTJ/yHnvopX74VxqEGVoQzV49NVTI qB0oAgknqlIPFcxBJmtlNp7EC7UE0ee0lV8JqjTTFmIDzS5vyQ/bEr5oCcVh95Nftyl0 7Q3ZcPIuNvDQY4O6QAqeNs6aSWHSLe4PO86r/o5Y0W3a5uRQKDKqLQ6nW3caNvOI5gwP NwgA== X-Gm-Message-State: AHPjjUgh45D+sb9OhxiTLzMk6SyXvUDlPt2VskJ0JK75PzsCVNyNqYSM +4J+3Cq/al4yX8L7FvSffg== X-Google-Smtp-Source: ADKCNb7+HSU0Xs3a9D0YfO+yKlMhCWAeRIK/U6R0fSNsABv0LeV6c3l0XURlFJApHd6Q874iGaDvNw== X-Received: by 10.99.181.23 with SMTP id y23mr934634pge.191.1504824069009; Thu, 07 Sep 2017 15:41:09 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:38 -0700 Message-Id: <20170907224051.21518-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::22c Subject: [Qemu-devel] [PULL 10/23] tcg/s390: Use constant pool for xori X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/s390/tcg-target.inc.c | 77 ++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 37 deletions(-) -- 2.13.5 diff --git a/tcg/s390/tcg-target.inc.c b/tcg/s390/tcg-target.inc.c index 83fac71c31..b0b34fa5ab 100644 --- a/tcg/s390/tcg-target.inc.c +++ b/tcg/s390/tcg-target.inc.c @@ -39,11 +39,9 @@ #define TCG_CT_CONST_S16 0x100 #define TCG_CT_CONST_S32 0x200 -#define TCG_CT_CONST_NN16 0x400 -#define TCG_CT_CONST_NN32 0x800 -#define TCG_CT_CONST_U31 0x1000 -#define TCG_CT_CONST_S33 0x2000 -#define TCG_CT_CONST_ZERO 0x4000 +#define TCG_CT_CONST_U31 0x400 +#define TCG_CT_CONST_S33 0x800 +#define TCG_CT_CONST_ZERO 0x1000 /* Several places within the instruction set 0 means "no register" rather than TCG_REG_R0. */ @@ -234,6 +232,7 @@ typedef enum S390Opcode { RXY_STRVG = 0xe32f, RXY_STRVH = 0xe33f, RXY_STY = 0xe350, + RXY_XG = 0xe382, RX_A = 0x5a, RX_C = 0x59, @@ -424,12 +423,6 @@ static const char *target_parse_constraint(TCGArgConstraint *ct, case 'J': ct->ct |= TCG_CT_CONST_S32; break; - case 'N': - ct->ct |= TCG_CT_CONST_NN16; - break; - case 'M': - ct->ct |= TCG_CT_CONST_NN32; - break; case 'C': /* ??? We have no insight here into whether the comparison is signed or unsigned. The COMPARE IMMEDIATE insn uses a 32-bit @@ -474,10 +467,6 @@ static int tcg_target_const_match(tcg_target_long val, TCGType type, return val == (int32_t)val; } else if (ct & TCG_CT_CONST_S33) { return val >= -0xffffffffll && val <= 0xffffffffll; - } else if (ct & TCG_CT_CONST_NN16) { - return !(val < 0 && val == (int16_t)val); - } else if (ct & TCG_CT_CONST_NN32) { - return !(val < 0 && val == (int32_t)val); } else if (ct & TCG_CT_CONST_U31) { return val >= 0 && val <= 0x7fffffff; } else if (ct & TCG_CT_CONST_ZERO) { @@ -1062,14 +1051,40 @@ static void tgen_ori(TCGContext *s, TCGType type, TCGReg dest, uint64_t val) } } -static void tgen64_xori(TCGContext *s, TCGReg dest, tcg_target_ulong val) +static void tgen_xori(TCGContext *s, TCGType type, TCGReg dest, uint64_t val) { - /* Perform the xor by parts. */ - if (val & 0xffffffff) { - tcg_out_insn(s, RIL, XILF, dest, val); + /* Try all 48-bit insns that can perform it in one go. */ + if (s390_facilities & FACILITY_EXT_IMM) { + if ((val & 0xffffffff00000000ull) == 0) { + tcg_out_insn(s, RIL, XILF, dest, val); + return; + } + if ((val & 0x00000000ffffffffull) == 0) { + tcg_out_insn(s, RIL, XIHF, dest, val >> 32); + return; + } } - if (val > 0xffffffff) { - tcg_out_insn(s, RIL, XIHF, dest, val >> 31 >> 1); + + /* Use the constant pool if USE_REG_TB, but not for small constants. */ + if (maybe_out_small_movi(s, type, TCG_TMP0, val)) { + if (type == TCG_TYPE_I32) { + tcg_out_insn(s, RR, XR, dest, TCG_TMP0); + } else { + tcg_out_insn(s, RRE, XGR, dest, TCG_TMP0); + } + } else if (USE_REG_TB) { + tcg_out_insn(s, RXY, XG, dest, TCG_REG_TB, TCG_REG_NONE, 0); + new_pool_label(s, val, R_390_20, s->code_ptr - 2, + -(intptr_t)s->code_gen_ptr); + } else { + /* Perform the xor by parts. */ + tcg_debug_assert(s390_facilities & FACILITY_EXT_IMM); + if (val & 0xffffffff) { + tcg_out_insn(s, RIL, XILF, dest, val); + } + if (val > 0xffffffff) { + tcg_out_insn(s, RIL, XIHF, dest, val >> 32); + } } } @@ -1889,7 +1904,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, a0 = args[0], a1 = args[1], a2 = (uint32_t)args[2]; if (const_args[2]) { tcg_out_mov(s, TCG_TYPE_I32, a0, a1); - tgen64_xori(s, a0, a2); + tgen_xori(s, TCG_TYPE_I32, a0, a2); } else if (a0 == a1) { tcg_out_insn(s, RR, XR, args[0], args[2]); } else { @@ -2121,7 +2136,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, a0 = args[0], a1 = args[1], a2 = args[2]; if (const_args[2]) { tcg_out_mov(s, TCG_TYPE_I64, a0, a1); - tgen64_xori(s, a0, a2); + tgen_xori(s, TCG_TYPE_I64, a0, a2); } else if (a0 == a1) { tcg_out_insn(s, RRE, XGR, a0, a2); } else { @@ -2313,12 +2328,9 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) static const TCGTargetOpDef r_rC = { .args_ct_str = { "r", "rC" } }; static const TCGTargetOpDef r_rZ = { .args_ct_str = { "r", "rZ" } }; static const TCGTargetOpDef r_r_ri = { .args_ct_str = { "r", "r", "ri" } }; - static const TCGTargetOpDef r_r_rM = { .args_ct_str = { "r", "r", "rM" } }; - static const TCGTargetOpDef r_0_r = { .args_ct_str = { "r", "0", "r" } }; static const TCGTargetOpDef r_0_ri = { .args_ct_str = { "r", "0", "ri" } }; static const TCGTargetOpDef r_0_rI = { .args_ct_str = { "r", "0", "rI" } }; static const TCGTargetOpDef r_0_rJ = { .args_ct_str = { "r", "0", "rJ" } }; - static const TCGTargetOpDef r_0_rM = { .args_ct_str = { "r", "0", "rM" } }; static const TCGTargetOpDef a2_r = { .args_ct_str = { "r", "r", "0", "1", "r", "r" } }; static const TCGTargetOpDef a2_ri @@ -2360,6 +2372,8 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) case INDEX_op_and_i64: case INDEX_op_or_i32: case INDEX_op_or_i64: + case INDEX_op_xor_i32: + case INDEX_op_xor_i64: return (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_ri : &r_0_ri); case INDEX_op_mul_i32: @@ -2370,17 +2384,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) case INDEX_op_mul_i64: return (s390_facilities & FACILITY_GEN_INST_EXT ? &r_0_rJ : &r_0_rI); - case INDEX_op_xor_i32: - /* Without EXT_IMM, no immediates are supported. Otherwise, - rejecting certain negative ranges leads to smaller code. */ - return (s390_facilities & FACILITY_EXT_IMM - ? (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_ri : &r_0_ri) - : &r_0_r); - case INDEX_op_xor_i64: - return (s390_facilities & FACILITY_EXT_IMM - ? (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_rM : &r_0_rM) - : &r_0_r); - case INDEX_op_shl_i32: case INDEX_op_shr_i32: case INDEX_op_sar_i32: From patchwork Thu Sep 7 22:40:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111979 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp726082qge; Thu, 7 Sep 2017 15:48:34 -0700 (PDT) X-Received: by 10.200.27.6 with SMTP id y6mr1377212qtj.247.1504824514214; Thu, 07 Sep 2017 15:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824514; cv=none; d=google.com; s=arc-20160816; b=sl+tP0fvPBxh/7o0/RIFcxAmkVS+qyTjaYbVeBbeI3FO8gciuW6bXwty6G+OwiHn8X AJ2mMsbtxweG9ca51etofcwRCEN7XWKpSF7/aQYrz5FRJfSsfrVv3ADKzRNmcldVfYm2 c4zZMiCwx4CPkM9hA8W8kmInOj+YOPrGfYZ8nZmF13eAi9hT0pcW1qYsPCwTGZYQNkiv TnwKCrJ1AJypZ0uahvqVeRtXhqAgz09Mj0sArOwTbu+qkwKGBEvy/3CUXGyFchmqHHDb kQZhfCwo7h3ZfG9aQB7F5s/nXK2UwcGYyg126N3PNeBdrBnNw+Tp7B+h0G4nH4ucO2BY g/pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=UqbemKBcSAFRk6ka+QSoQnu16oHX7Q4v8g2SbdNvrNg=; b=CoFJnREaCL4xRNMA89+ux92xpe5qN/UPSyABJ+vrGtBAr4E+3Gpi1mIkd2fzJDfl5V R3fnFKU+m5W4+CUG7AuDfPNUGpmPGos7y7HtZqWrSmHLHFYPKTrMUv+WRwphDRj0cFTK WqDb/C2djIGuYt4Qs33rlQ0nbPcWDlZRy4Ch5P+uff/e6ZFnjp1VDqZrn2F8cmrVE6AM fUZabr7fhS+DIRXrDQnmhFLin7LPMb0JF43LbnfCoWMByFBB6rlKNVT/1YJ8F3cFytK6 aNE6tkxNBy7NsOydJNf6mkplWhKQ3g1IzHt2qnHCa6/jHgqTXrM7B/nut+9vDYlQjL3u RjdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XV66D4qT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n51si501730qtf.26.2017.09.07.15.48.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:48:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XV66D4qT; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5b6-0000ZD-0T for patch@linaro.org; Thu, 07 Sep 2017 18:48:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52177) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5U5-00037t-9w for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5U0-0008Ej-5j for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:17 -0400 Received: from mail-pg0-x22e.google.com ([2607:f8b0:400e:c05::22e]:36681) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5Tz-0008Dy-T7 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:12 -0400 Received: by mail-pg0-x22e.google.com with SMTP id m9so1818458pgd.3 for ; Thu, 07 Sep 2017 15:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UqbemKBcSAFRk6ka+QSoQnu16oHX7Q4v8g2SbdNvrNg=; b=XV66D4qTRKuoPoR3cygKOGztQhn4oTbTVRzufrL6MKhdzOftNQznijsU9sfoQLqX3y X3BFlJbssgee/3i2flY8mlgTj2FZq037uyCblmh3iQEkXRigKbjb247QUNQoNtaoSe+U Q3Fn0E2P6Ir32r+yCulyCLd1BSD4edjhn4TM0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UqbemKBcSAFRk6ka+QSoQnu16oHX7Q4v8g2SbdNvrNg=; b=DVs7GjtYDhGtrUP35qnRH94w0rKTjLvrZJsF/7zsro1hjNkjTfiktKoVOpHdBm9ugb tNN7/0ZsBxie28lkejZo8Co5Gk6aqQ8+zVmTQFJKwj/+xmJnuqnLYd+JHSy3g44baF/i br9xOi/HUhU7WzJjMfudcNYtyL2SeH0xv2HeN+8XjCq3iZfFWAZ30LH+YohI6DqPh12W h1fcExcoahJp3iGus2+2eRBwT9GEsneH9EM6OPtwkV1WzI/B/meZO3tXgEVgzQQO4cyz 4NtpXpAKzO603rPbg2fp2RZJRDIvPLlasWec8cbNjk2hN4pqTwB17ssJer4uqKEQ5btM 9f3A== X-Gm-Message-State: AHPjjUj0R0Q87ZBKmoL/qHpsDr0hJwNU1OtCCxgI6dCczBDVGRNRfAHl dsvSEjKibn4L+xcKRwKUEQ== X-Google-Smtp-Source: ADKCNb5+ckXCrF6q6YJFifvsgY+QZqxirFKKvIQepWd4NC/tI2knqNyVlnDGx7t+VUXo5hZUcCqETw== X-Received: by 10.99.116.21 with SMTP id p21mr944350pgc.93.1504824070414; Thu, 07 Sep 2017 15:41:10 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:39 -0700 Message-Id: <20170907224051.21518-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::22e Subject: [Qemu-devel] [PULL 11/23] tcg/s390: Use constant pool for cmpi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Also use CHI/CGHI for 16-bit signed constants. Signed-off-by: Richard Henderson --- tcg/s390/tcg-target.inc.c | 136 +++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 69 deletions(-) -- 2.13.5 diff --git a/tcg/s390/tcg-target.inc.c b/tcg/s390/tcg-target.inc.c index b0b34fa5ab..e7ab8e4df3 100644 --- a/tcg/s390/tcg-target.inc.c +++ b/tcg/s390/tcg-target.inc.c @@ -39,9 +39,8 @@ #define TCG_CT_CONST_S16 0x100 #define TCG_CT_CONST_S32 0x200 -#define TCG_CT_CONST_U31 0x400 -#define TCG_CT_CONST_S33 0x800 -#define TCG_CT_CONST_ZERO 0x1000 +#define TCG_CT_CONST_S33 0x400 +#define TCG_CT_CONST_ZERO 0x800 /* Several places within the instruction set 0 means "no register" rather than TCG_REG_R0. */ @@ -75,6 +74,10 @@ typedef enum S390Opcode { RIL_CGFI = 0xc20c, RIL_CLFI = 0xc20f, RIL_CLGFI = 0xc20e, + RIL_CLRL = 0xc60f, + RIL_CLGRL = 0xc60a, + RIL_CRL = 0xc60d, + RIL_CGRL = 0xc608, RIL_IIHF = 0xc008, RIL_IILF = 0xc009, RIL_LARL = 0xc000, @@ -97,6 +100,8 @@ typedef enum S390Opcode { RI_AGHI = 0xa70b, RI_AHI = 0xa70a, RI_BRC = 0xa704, + RI_CHI = 0xa70e, + RI_CGHI = 0xa70f, RI_IIHH = 0xa500, RI_IIHL = 0xa501, RI_IILH = 0xa502, @@ -206,6 +211,8 @@ typedef enum S390Opcode { RXY_AG = 0xe308, RXY_AY = 0xe35a, RXY_CG = 0xe320, + RXY_CLG = 0xe321, + RXY_CLY = 0xe355, RXY_CY = 0xe359, RXY_LAY = 0xe371, RXY_LB = 0xe376, @@ -423,20 +430,6 @@ static const char *target_parse_constraint(TCGArgConstraint *ct, case 'J': ct->ct |= TCG_CT_CONST_S32; break; - case 'C': - /* ??? We have no insight here into whether the comparison is - signed or unsigned. The COMPARE IMMEDIATE insn uses a 32-bit - signed immediate, and the COMPARE LOGICAL IMMEDIATE insn uses - a 32-bit unsigned immediate. If we were to use the (semi) - obvious "val == (int32_t)val" we would be enabling unsigned - comparisons vs very large numbers. The only solution is to - take the intersection of the ranges. */ - /* ??? Another possible solution is to simply lie and allow all - constants here and force the out-of-range values into a temp - register in tgen_cmp when we have knowledge of the actual - comparison code in use. */ - ct->ct |= TCG_CT_CONST_U31; - break; case 'Z': ct->ct |= TCG_CT_CONST_ZERO; break; @@ -467,8 +460,6 @@ static int tcg_target_const_match(tcg_target_long val, TCGType type, return val == (int32_t)val; } else if (ct & TCG_CT_CONST_S33) { return val >= -0xffffffffll && val <= 0xffffffffll; - } else if (ct & TCG_CT_CONST_U31) { - return val >= 0 && val <= 0x7fffffff; } else if (ct & TCG_CT_CONST_ZERO) { return val == 0; } @@ -1092,6 +1083,8 @@ static int tgen_cmp(TCGContext *s, TCGType type, TCGCond c, TCGReg r1, TCGArg c2, bool c2const, bool need_carry) { bool is_unsigned = is_unsigned_cond(c); + S390Opcode op; + if (c2const) { if (c2 == 0) { if (!(is_unsigned && need_carry)) { @@ -1102,44 +1095,67 @@ static int tgen_cmp(TCGContext *s, TCGType type, TCGCond c, TCGReg r1, } return tcg_cond_to_ltr_cond[c]; } - /* If we only got here because of load-and-test, - and we couldn't use that, then we need to load - the constant into a register. */ - if (!(s390_facilities & FACILITY_EXT_IMM)) { - c2 = TCG_TMP0; - tcg_out_movi(s, type, c2, 0); - goto do_reg; - } } - if (is_unsigned) { - if (type == TCG_TYPE_I32) { - tcg_out_insn(s, RIL, CLFI, r1, c2); - } else { - tcg_out_insn(s, RIL, CLGFI, r1, c2); - } - } else { + + if (!is_unsigned && c2 == (int16_t)c2) { + op = (type == TCG_TYPE_I32 ? RI_CHI : RI_CGHI); + tcg_out_insn_RI(s, op, r1, c2); + goto exit; + } + + if (s390_facilities & FACILITY_EXT_IMM) { if (type == TCG_TYPE_I32) { - tcg_out_insn(s, RIL, CFI, r1, c2); - } else { - tcg_out_insn(s, RIL, CGFI, r1, c2); + op = (is_unsigned ? RIL_CLFI : RIL_CFI); + tcg_out_insn_RIL(s, op, r1, c2); + goto exit; + } else if (c2 == (is_unsigned ? (uint32_t)c2 : (int32_t)c2)) { + op = (is_unsigned ? RIL_CLGFI : RIL_CGFI); + tcg_out_insn_RIL(s, op, r1, c2); + goto exit; } } - } else { - do_reg: - if (is_unsigned) { + + /* Use the constant pool, but not for small constants. */ + if (maybe_out_small_movi(s, type, TCG_TMP0, c2)) { + c2 = TCG_TMP0; + /* fall through to reg-reg */ + } else if (USE_REG_TB) { if (type == TCG_TYPE_I32) { - tcg_out_insn(s, RR, CLR, r1, c2); + op = (is_unsigned ? RXY_CLY : RXY_CY); + tcg_out_insn_RXY(s, op, r1, TCG_REG_TB, TCG_REG_NONE, 0); + new_pool_label(s, (uint32_t)c2, R_390_20, s->code_ptr - 2, + 4 - (intptr_t)s->code_gen_ptr); } else { - tcg_out_insn(s, RRE, CLGR, r1, c2); + op = (is_unsigned ? RXY_CLG : RXY_CG); + tcg_out_insn_RXY(s, op, r1, TCG_REG_TB, TCG_REG_NONE, 0); + new_pool_label(s, c2, R_390_20, s->code_ptr - 2, + -(intptr_t)s->code_gen_ptr); } + goto exit; } else { if (type == TCG_TYPE_I32) { - tcg_out_insn(s, RR, CR, r1, c2); + op = (is_unsigned ? RIL_CLRL : RIL_CRL); + tcg_out_insn_RIL(s, op, r1, 0); + new_pool_label(s, (uint32_t)c2, R_390_PC32DBL, + s->code_ptr - 2, 2 + 4); } else { - tcg_out_insn(s, RRE, CGR, r1, c2); + op = (is_unsigned ? RIL_CLGRL : RIL_CGRL); + tcg_out_insn_RIL(s, op, r1, 0); + new_pool_label(s, c2, R_390_PC32DBL, s->code_ptr - 2, 2); } + goto exit; } } + + if (type == TCG_TYPE_I32) { + op = (is_unsigned ? RR_CLR : RR_CR); + tcg_out_insn_RR(s, op, r1, c2); + } else { + op = (is_unsigned ? RRE_CLGR : RRE_CGR); + tcg_out_insn_RRE(s, op, r1, c2); + } + + exit: return tcg_cond_to_s390_cond[c]; } @@ -2325,8 +2341,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) static const TCGTargetOpDef r_L = { .args_ct_str = { "r", "L" } }; static const TCGTargetOpDef L_L = { .args_ct_str = { "L", "L" } }; static const TCGTargetOpDef r_ri = { .args_ct_str = { "r", "ri" } }; - static const TCGTargetOpDef r_rC = { .args_ct_str = { "r", "rC" } }; - static const TCGTargetOpDef r_rZ = { .args_ct_str = { "r", "rZ" } }; static const TCGTargetOpDef r_r_ri = { .args_ct_str = { "r", "r", "ri" } }; static const TCGTargetOpDef r_0_ri = { .args_ct_str = { "r", "0", "ri" } }; static const TCGTargetOpDef r_0_rI = { .args_ct_str = { "r", "0", "rI" } }; @@ -2401,10 +2415,8 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) return &r_r_ri; case INDEX_op_brcond_i32: - /* Without EXT_IMM, only the LOAD AND TEST insn is available. */ - return (s390_facilities & FACILITY_EXT_IMM ? &r_ri : &r_rZ); case INDEX_op_brcond_i64: - return (s390_facilities & FACILITY_EXT_IMM ? &r_rC : &r_rZ); + return &r_ri; case INDEX_op_bswap16_i32: case INDEX_op_bswap16_i64: @@ -2430,6 +2442,8 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) return &r_r; case INDEX_op_clz_i64: + case INDEX_op_setcond_i32: + case INDEX_op_setcond_i64: return &r_r_ri; case INDEX_op_qemu_ld_i32: @@ -2446,30 +2460,14 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode op) = { .args_ct_str = { "r", "rZ", "r" } }; return &dep; } - case INDEX_op_setcond_i32: - case INDEX_op_setcond_i64: - { - /* Without EXT_IMM, only the LOAD AND TEST insn is available. */ - static const TCGTargetOpDef setc_z - = { .args_ct_str = { "r", "r", "rZ" } }; - static const TCGTargetOpDef setc_c - = { .args_ct_str = { "r", "r", "rC" } }; - return (s390_facilities & FACILITY_EXT_IMM ? &setc_c : &setc_z); - } case INDEX_op_movcond_i32: case INDEX_op_movcond_i64: { - /* Without EXT_IMM, only the LOAD AND TEST insn is available. */ - static const TCGTargetOpDef movc_z - = { .args_ct_str = { "r", "r", "rZ", "r", "0" } }; - static const TCGTargetOpDef movc_c - = { .args_ct_str = { "r", "r", "rC", "r", "0" } }; + static const TCGTargetOpDef movc + = { .args_ct_str = { "r", "r", "ri", "r", "0" } }; static const TCGTargetOpDef movc_l - = { .args_ct_str = { "r", "r", "rC", "rI", "0" } }; - return (s390_facilities & FACILITY_EXT_IMM - ? (s390_facilities & FACILITY_LOAD_ON_COND2 - ? &movc_l : &movc_c) - : &movc_z); + = { .args_ct_str = { "r", "r", "ri", "rI", "0" } }; + return (s390_facilities & FACILITY_LOAD_ON_COND2 ? &movc_l : &movc); } case INDEX_op_div2_i32: case INDEX_op_div2_i64: From patchwork Thu Sep 7 22:40:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111984 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp763257ybm; Thu, 7 Sep 2017 15:50:54 -0700 (PDT) X-Received: by 10.237.63.82 with SMTP id q18mr1454145qtf.274.1504824654112; Thu, 07 Sep 2017 15:50:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824654; cv=none; d=google.com; s=arc-20160816; b=rvP0v+vDydPkRERfEZOy1PRmqFZvM4cZpVMfaYI1OwUHDaIP7cjlEtfY9R0sNX4nkL pV3nd6xUdzq7C9dzm1u7wZvNneIWl8M6HVzOftWfWKh6PhnndXNDZA3XsrPdaQWDKv+D fhfrRoWCQCLPKNVn47pT887t0lvn83NBSBZXZueT5GXlrPdsONhX7C8yAoSrXMt1CPYL ev+7AiqtkHkjn50TM+ytVbyQTxnmKCt9OBNJEBlxoHswIEDo7wcaZ8oJus6REtO+nAY0 qNxnP4WivZWOA/zpvP6i5c0t9xOaEgXTXjt8CxhX6i2GKIG7dFFX7NdyCjkZtVbco+P7 i+xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=GyID29fvgFconnX4hc2+M1A5fpECok1c1ASb0Yls7AI=; b=unyRxoBk7sYV60Wm0b7xMUch36GcQytP5vu+Tl7eM7YBpU9Bqivv1HggWlqDtqci/X RZyC2SU4Oy5DDsG4dU9xczDuHLBiPI1RPYN95mcYuR8IMP1RTaCpraEP6rgvPzRB5K6q gvEzq+4unP53lELa/0HtWZX4LEHI9oHO+U/vq+ol0m6q5c6HpPKeMx6jyseh2Qt9QDKD 6ro/WQnYFfgkseyJwzSMcbqx+Sldyo0wv35wkyCdiqbzLhiDVOGqvtAXdInr3IAy3yKW xy7Ze8NL99lGLVU6HWyfH0Ijsu6HxU68SPnPnoeyNHpeWpQ0zNoFSPa6Zi/Nq+bpwj4R ARwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=c+eSWtgp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d18si521638qte.200.2017.09.07.15.50.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:50:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=c+eSWtgp; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5dL-0002V9-SP for patch@linaro.org; Thu, 07 Sep 2017 18:50:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5U6-00038Q-EK for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5U1-0008Fv-Ea for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:18 -0400 Received: from mail-pg0-x229.google.com ([2607:f8b0:400e:c05::229]:34449) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5U1-0008FE-8L for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:13 -0400 Received: by mail-pg0-x229.google.com with SMTP id q68so1823968pgq.1 for ; Thu, 07 Sep 2017 15:41:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GyID29fvgFconnX4hc2+M1A5fpECok1c1ASb0Yls7AI=; b=c+eSWtgplQVb6y3VMQpZFHgivuI4nvnIPHf5QqNy3vA7mu4nxgpHE0pl4m2OBXOgkV qwDDgCiNKlugaHpyKbo0u3ckP7r7wRnIo3aIfLWctzJuqfhjC2WmTwQNiVHgeqh2Ea9l j3eVaBXjbtbg8J64tpXxzDtdMx5MeXsqVl1KI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GyID29fvgFconnX4hc2+M1A5fpECok1c1ASb0Yls7AI=; b=oc2b/Yt/xkohOl/yDyT24fozPYzC9cLfyj8pT+EYf4iyet5sKq6l8KoyN1aUr8qqwq F0M7+peShrWKC9MnK5jpP4pBjaTlFTnhRJgdnVVJU3RrUGE7kHhcKaFc8ViAFEh7eRl0 VCauHU/7FKIwBLV+tdgN0GS8q3FZjFqIWqjGIIKfOngQm/uo06h/jyNelZbQ3vhucJ85 W13YsRuP+e2451wrsIwKcxyeT7yDZfylrOLFMzowT6RyEvue0Fy3sanh8UZtqiQiXose xlOEhuv8uLbpUmTP00tn/Kf2mxicZstXvqBY91xbRXYrSvoWxiK/yT0MnSIJ2xd60B2n 6/Ag== X-Gm-Message-State: AHPjjUjiUG/BHyj5hF/AU2F7J0DSQC41w/RMw2fU1wYIhboliG+5rGfC zPX3i0htCo9UIZBjjCHEjA== X-Google-Smtp-Source: ADKCNb5RiOrZUxD6zNRfOR586hfFn8TuLhutQEKM4FlS1Zfl3w91fJT3WtNB9laBGV5BIOs39QXpYA== X-Received: by 10.99.171.73 with SMTP id k9mr962353pgp.196.1504824071887; Thu, 07 Sep 2017 15:41:11 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:40 -0700 Message-Id: <20170907224051.21518-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::229 Subject: [Qemu-devel] [PULL 12/23] tcg/aarch64: Use constant pool for movi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/aarch64/tcg-target.h | 1 + tcg/aarch64/tcg-target.inc.c | 62 +++++++++++++++++++++++--------------------- 2 files changed, 33 insertions(+), 30 deletions(-) -- 2.13.5 diff --git a/tcg/aarch64/tcg-target.h b/tcg/aarch64/tcg-target.h index 1bdbd7058b..c2525066ab 100644 --- a/tcg/aarch64/tcg-target.h +++ b/tcg/aarch64/tcg-target.h @@ -125,5 +125,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS #endif +#define TCG_TARGET_NEED_POOL_LABELS #endif /* AARCH64_TCG_TARGET_H */ diff --git a/tcg/aarch64/tcg-target.inc.c b/tcg/aarch64/tcg-target.inc.c index c7c751bafc..c2f3812214 100644 --- a/tcg/aarch64/tcg-target.inc.c +++ b/tcg/aarch64/tcg-target.inc.c @@ -10,6 +10,7 @@ * See the COPYING file in the top-level directory for details. */ +#include "tcg-pool.inc.c" #include "qemu/bitops.h" /* We're going to re-use TCGType in setting of the SF bit, which controls @@ -587,9 +588,11 @@ static void tcg_out_logicali(TCGContext *s, AArch64Insn insn, TCGType ext, static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, tcg_target_long value) { - int i, wantinv, shift; tcg_target_long svalue = value; tcg_target_long ivalue = ~value; + tcg_target_long t0, t1, t2; + int s0, s1; + AArch64Insn opc; /* For 32-bit values, discard potential garbage in value. For 64-bit values within [2**31, 2**32-1], we can create smaller sequences by @@ -638,38 +641,29 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd, } } - /* Would it take fewer insns to begin with MOVN? For the value and its - inverse, count the number of 16-bit lanes that are 0. */ - for (i = wantinv = 0; i < 64; i += 16) { - tcg_target_long mask = 0xffffull << i; - wantinv -= ((value & mask) == 0); - wantinv += ((ivalue & mask) == 0); - } - - if (wantinv <= 0) { - /* Find the lowest lane that is not 0x0000. */ - shift = ctz64(value) & (63 & -16); - tcg_out_insn(s, 3405, MOVZ, type, rd, value >> shift, shift); - /* Clear out the lane that we just set. */ - value &= ~(0xffffUL << shift); - /* Iterate until all non-zero lanes have been processed. */ - while (value) { - shift = ctz64(value) & (63 & -16); - tcg_out_insn(s, 3405, MOVK, type, rd, value >> shift, shift); - value &= ~(0xffffUL << shift); - } + /* Would it take fewer insns to begin with MOVN? */ + if (ctpop64(value) >= 32) { + t0 = ivalue; + opc = I3405_MOVN; } else { - /* Like above, but with the inverted value and MOVN to start. */ - shift = ctz64(ivalue) & (63 & -16); - tcg_out_insn(s, 3405, MOVN, type, rd, ivalue >> shift, shift); - ivalue &= ~(0xffffUL << shift); - while (ivalue) { - shift = ctz64(ivalue) & (63 & -16); - /* Provide MOVK with the non-inverted value. */ - tcg_out_insn(s, 3405, MOVK, type, rd, ~(ivalue >> shift), shift); - ivalue &= ~(0xffffUL << shift); + t0 = value; + opc = I3405_MOVZ; + } + s0 = ctz64(t0) & (63 & -16); + t1 = t0 & ~(0xffffUL << s0); + s1 = ctz64(t1) & (63 & -16); + t2 = t1 & ~(0xffffUL << s1); + if (t2 == 0) { + tcg_out_insn_3405(s, opc, type, rd, t0 >> s0, s0); + if (t1 != 0) { + tcg_out_insn(s, 3405, MOVK, type, rd, value >> s1, s1); } + return; } + + /* For more than 2 insns, dump it into the constant pool. */ + new_pool_label(s, value, R_AARCH64_CONDBR19, s->code_ptr, 0); + tcg_out_insn(s, 3305, LDR, 0, rd); } /* Define something more legible for general use. */ @@ -2030,6 +2024,14 @@ static void tcg_target_qemu_prologue(TCGContext *s) tcg_out_insn(s, 3207, RET, TCG_REG_LR); } +static void tcg_out_nop_fill(tcg_insn_unit *p, int count) +{ + int i; + for (i = 0; i < count; ++i) { + p[i] = NOP; + } +} + typedef struct { DebugFrameHeader h; uint8_t fde_def_cfa[4]; From patchwork Thu Sep 7 22:40:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111986 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp765073ybm; Thu, 7 Sep 2017 15:53:04 -0700 (PDT) X-Received: by 10.200.38.154 with SMTP id 26mr1266888qto.188.1504824784878; Thu, 07 Sep 2017 15:53:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824784; cv=none; d=google.com; s=arc-20160816; b=Ew17obBR02RT/W0O6goD+dJVx9pwbegs24UIOnLv7RfKtqjCJ1rGyESa2DpUZMiWzw zjh0O7Wds3YYUw+buZMC/nDXOM76379FTYduGNNZX6wcjLk/m2mM0NXzvmLbFZ4C8hBL fw0B471boFUzzpjo+8F9l8GpmWVvyz5jpI/cCyaGc4518QhppracpBNaqaeXUh+7gmEL 6XFKfVSKB1KSH0oRJ7FqsclNUiZGi/5cNJABWZoZ89EBPee5M0E7wHV/fh2qGUlKKADc Ke/w7FZCxhrmqOhegX976VkNbDGVsZ4T20v8wWMlIrjma4bN20ZdaWQXiBCvyOzke3xr IpEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=cXdlCKExCYaZyFIk5WVOvZ9EaDypXQcVXtME6fR453M=; b=q6zkQudl489RlAf0oG+eBovdhVEv4bRpZNPf5TYP91cMdet6YJ8xnzqftfMb2unHex hLNM0ZbSr9NpeNY+avf5J/N5Fm9WnKRwTFmrx6K9dGNAxbclAze1qvrwpDvKLAdtZaxj 9h/dAdQ7IqDBzB/IzddoUOr8Ah0G78lrVYg5xaMR1gA2ZwIUO+I+KtDVa3lpb39OPkmu teZuK7UQ3sitwqVpcDdnb4FUNwXXbVhdr/JDBosjpx5qhXLjRxZrusQ6BUhHEl+WgbZY GqXPMldkYCY0QX7GN+5CQWUZIQgFesjkkeU+C8Xc7IOEFqy+Nv5SpLOTo+05txp/u439 EpFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kyRNuONU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q10si519761qtb.128.2017.09.07.15.53.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:53:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kyRNuONU; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5fS-0004Tc-Mk for patch@linaro.org; Thu, 07 Sep 2017 18:53:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52223) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5U8-000397-Fr for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5U2-0008HU-UC for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:20 -0400 Received: from mail-pf0-x232.google.com ([2607:f8b0:400e:c00::232]:34082) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5U2-0008Gz-Lb for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:14 -0400 Received: by mail-pf0-x232.google.com with SMTP id e1so1640681pfk.1 for ; Thu, 07 Sep 2017 15:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cXdlCKExCYaZyFIk5WVOvZ9EaDypXQcVXtME6fR453M=; b=kyRNuONUkHl52b2ehWEZSOoq0VxaMpDFmzihlkCnXo3Zb30tr6FGmo7eNNLWCSUBPh /tLQFUDlIj1hdKTFghD16+hAI/B+f7fALKLcnysTrd7d9K6VjiM8PxIO4EFtzdEQ+/xW F+/EJwWnx9SXcmHKEYKBSPH5+K406IYr21E/U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cXdlCKExCYaZyFIk5WVOvZ9EaDypXQcVXtME6fR453M=; b=RvIcsg1Ga4EphHh4yUBfQFfBCQ5WRZFhM7ArlcGNFGTDdQhseOMF+Lj1NBBgteccYm 8xKhIMIgGF+Z/eysQcR1g5ALPhGQDgao8O/4OSPFC3YktFfeCYvczh9DfZoDzdMXpN21 Fp412A+LaCTuElwEsqp6N0h43Q5PIg6bWBU79Clw3NAbHX/70aYys0RSqN+ednzDjKLT +tNE58in86m8R7Jm74Xc8NOLbC9mOMnPk+gee9UtouDYKr5w13fdwCzJKEa1e5TWTrYN IZB9IOQd/To3PqBcetBAYlvjAjTcMMxq4aXDLV8B8cMg2Vart3Y115Lr2QSda7COEBIf sp5w== X-Gm-Message-State: AHPjjUg7XOPfI10o5QEXtJGVSHstmdoQEUVOIwT8sf6p7HOyflo0b4b3 2cLaOoRUS7yNfvME7KYMig== X-Google-Smtp-Source: ADKCNb5oRaW5Uolau6zdBeOOxjoBSBQKA8AUqorCcFemLlbEFKopIrma9lwBe4liS+zYCuRXbeeyOQ== X-Received: by 10.84.216.18 with SMTP id m18mr999289pli.451.1504824073241; Thu, 07 Sep 2017 15:41:13 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:41 -0700 Message-Id: <20170907224051.21518-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::232 Subject: [Qemu-devel] [PULL 13/23] tcg/sparc: Introduce TCG_REG_TB X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/sparc/tcg-target.inc.c | 170 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 140 insertions(+), 30 deletions(-) -- 2.13.5 diff --git a/tcg/sparc/tcg-target.inc.c b/tcg/sparc/tcg-target.inc.c index bb7f7e8906..7d73c25347 100644 --- a/tcg/sparc/tcg-target.inc.c +++ b/tcg/sparc/tcg-target.inc.c @@ -85,6 +85,9 @@ static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { # define TCG_GUEST_BASE_REG TCG_REG_I5 #endif +#define TCG_REG_TB TCG_REG_I1 +#define USE_REG_TB (sizeof(void *) > 4) + static const int tcg_target_reg_alloc_order[] = { TCG_REG_L0, TCG_REG_L1, @@ -249,6 +252,8 @@ static const int tcg_target_call_oarg_regs[] = { #define MEMBAR (INSN_OP(2) | INSN_OP3(0x28) | INSN_RS1(15) | (1 << 13)) +#define NOP (SETHI | INSN_RD(TCG_REG_G0) | 0) + #ifndef ASI_PRIMARY_LITTLE #define ASI_PRIMARY_LITTLE 0x88 #endif @@ -423,10 +428,11 @@ static inline void tcg_out_movi_imm13(TCGContext *s, TCGReg ret, int32_t arg) tcg_out_arithi(s, ret, TCG_REG_G0, arg, ARITH_OR); } -static void tcg_out_movi(TCGContext *s, TCGType type, - TCGReg ret, tcg_target_long arg) +static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, + tcg_target_long arg, bool in_prologue) { tcg_target_long hi, lo = (int32_t)arg; + tcg_target_long test, lsb; /* Make sure we test 32-bit constants for imm13 properly. */ if (type == TCG_TYPE_I32) { @@ -455,6 +461,27 @@ static void tcg_out_movi(TCGContext *s, TCGType type, return; } + /* A 21-bit constant, shifted. */ + lsb = ctz64(arg); + test = (tcg_target_long)arg >> lsb; + if (check_fit_tl(test, 13)) { + tcg_out_movi_imm13(s, ret, test); + tcg_out_arithi(s, ret, ret, lsb, SHIFT_SLLX); + return; + } else if (lsb > 10 && test == extract64(test, 0, 21)) { + tcg_out_sethi(s, ret, test << 10); + tcg_out_arithi(s, ret, ret, lsb - 10, SHIFT_SLLX); + return; + } + + if (USE_REG_TB && !in_prologue) { + intptr_t diff = arg - (uintptr_t)s->code_gen_ptr; + if (check_fit_ptr(diff, 13)) { + tcg_out_arithi(s, ret, TCG_REG_TB, diff, ARITH_ADD); + return; + } + } + /* A 64-bit constant decomposed into 2 32-bit pieces. */ if (check_fit_i32(lo, 13)) { hi = (arg - lo) >> 32; @@ -470,6 +497,12 @@ static void tcg_out_movi(TCGContext *s, TCGType type, } } +static inline void tcg_out_movi(TCGContext *s, TCGType type, + TCGReg ret, tcg_target_long arg) +{ + tcg_out_movi_int(s, type, ret, arg, false); +} + static inline void tcg_out_ldst_rr(TCGContext *s, TCGReg data, TCGReg a1, TCGReg a2, int op) { @@ -512,6 +545,11 @@ static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val, static void tcg_out_ld_ptr(TCGContext *s, TCGReg ret, uintptr_t arg) { + intptr_t diff = arg - (uintptr_t)s->code_gen_ptr; + if (USE_REG_TB && check_fit_ptr(diff, 13)) { + tcg_out_ld(s, TCG_TYPE_PTR, ret, TCG_REG_TB, diff); + return; + } tcg_out_movi(s, TCG_TYPE_PTR, ret, arg & ~0x3ff); tcg_out_ld(s, TCG_TYPE_PTR, ret, ret, arg & 0x3ff); } @@ -543,7 +581,7 @@ static void tcg_out_div32(TCGContext *s, TCGReg rd, TCGReg rs1, static inline void tcg_out_nop(TCGContext *s) { - tcg_out_sethi(s, TCG_REG_G0, 0); + tcg_out32(s, NOP); } static const uint8_t tcg_cond_to_bcond[] = { @@ -812,7 +850,8 @@ static void tcg_out_addsub2_i64(TCGContext *s, TCGReg rl, TCGReg rh, tcg_out_mov(s, TCG_TYPE_I64, rl, tmp); } -static void tcg_out_call_nodelay(TCGContext *s, tcg_insn_unit *dest) +static void tcg_out_call_nodelay(TCGContext *s, tcg_insn_unit *dest, + bool in_prologue) { ptrdiff_t disp = tcg_pcrel_diff(s, dest); @@ -820,14 +859,15 @@ static void tcg_out_call_nodelay(TCGContext *s, tcg_insn_unit *dest) tcg_out32(s, CALL | (uint32_t)disp >> 2); } else { uintptr_t desti = (uintptr_t)dest; - tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_T1, desti & ~0xfff); + tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_REG_T1, + desti & ~0xfff, in_prologue); tcg_out_arithi(s, TCG_REG_O7, TCG_REG_T1, desti & 0xfff, JMPL); } } static void tcg_out_call(TCGContext *s, tcg_insn_unit *dest) { - tcg_out_call_nodelay(s, dest); + tcg_out_call_nodelay(s, dest, false); tcg_out_nop(s); } @@ -915,7 +955,7 @@ static void build_trampolines(TCGContext *s) /* Set the env operand. */ tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O0, TCG_AREG0); /* Tail call. */ - tcg_out_call_nodelay(s, qemu_ld_helpers[i]); + tcg_out_call_nodelay(s, qemu_ld_helpers[i], true); tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O7, ra); } @@ -964,7 +1004,7 @@ static void build_trampolines(TCGContext *s) /* Set the env operand. */ tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O0, TCG_AREG0); /* Tail call. */ - tcg_out_call_nodelay(s, qemu_st_helpers[i]); + tcg_out_call_nodelay(s, qemu_st_helpers[i], true); tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O7, ra); } } @@ -992,11 +1032,17 @@ static void tcg_target_qemu_prologue(TCGContext *s) #ifndef CONFIG_SOFTMMU if (guest_base != 0) { - tcg_out_movi(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base); + tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base, true); tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG); } #endif + /* We choose TCG_REG_TB such that no move is required. */ + if (USE_REG_TB) { + QEMU_BUILD_BUG_ON(TCG_REG_TB != TCG_REG_I1); + tcg_regset_set_reg(s->reserved_regs, TCG_REG_TB); + } + tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I1, 0, JMPL); /* delay slot */ tcg_out_nop(s); @@ -1156,7 +1202,7 @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data, TCGReg addr, func = qemu_ld_trampoline[memop & (MO_BSWAP | MO_SSIZE)]; } tcg_debug_assert(func != NULL); - tcg_out_call_nodelay(s, func); + tcg_out_call_nodelay(s, func, false); /* delay slot */ tcg_out_movi(s, TCG_TYPE_I32, param, oi); @@ -1235,7 +1281,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data, TCGReg addr, func = qemu_st_trampoline[memop & (MO_BSWAP | MO_SIZE)]; tcg_debug_assert(func != NULL); - tcg_out_call_nodelay(s, func); + tcg_out_call_nodelay(s, func, false); /* delay slot */ tcg_out_movi(s, TCG_TYPE_I32, param, oi); @@ -1269,30 +1315,67 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, if (check_fit_ptr(a0, 13)) { tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN); tcg_out_movi_imm13(s, TCG_REG_O0, a0); - } else { - tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I0, a0 & ~0x3ff); - tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN); - tcg_out_arithi(s, TCG_REG_O0, TCG_REG_O0, a0 & 0x3ff, ARITH_OR); + break; + } else if (USE_REG_TB) { + intptr_t tb_diff = a0 - (uintptr_t)s->code_gen_ptr; + if (check_fit_ptr(tb_diff, 13)) { + tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN); + /* Note that TCG_REG_TB has been unwound to O1. */ + tcg_out_arithi(s, TCG_REG_O0, TCG_REG_O1, tb_diff, ARITH_ADD); + break; + } } + tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I0, a0 & ~0x3ff); + tcg_out_arithi(s, TCG_REG_G0, TCG_REG_I7, 8, RETURN); + tcg_out_arithi(s, TCG_REG_O0, TCG_REG_O0, a0 & 0x3ff, ARITH_OR); break; case INDEX_op_goto_tb: if (s->tb_jmp_insn_offset) { /* direct jump method */ - s->tb_jmp_insn_offset[a0] = tcg_current_code_size(s); - /* Make sure to preserve links during retranslation. */ - tcg_out32(s, CALL | (*s->code_ptr & ~INSN_OP(-1))); + if (USE_REG_TB) { + /* make sure the patch is 8-byte aligned. */ + if ((intptr_t)s->code_ptr & 4) { + tcg_out_nop(s); + } + s->tb_jmp_insn_offset[a0] = tcg_current_code_size(s); + tcg_out_sethi(s, TCG_REG_T1, 0); + tcg_out_arithi(s, TCG_REG_T1, TCG_REG_T1, 0, ARITH_OR); + tcg_out_arith(s, TCG_REG_G0, TCG_REG_TB, TCG_REG_T1, JMPL); + tcg_out_arith(s, TCG_REG_TB, TCG_REG_TB, TCG_REG_T1, ARITH_ADD); + } else { + s->tb_jmp_insn_offset[a0] = tcg_current_code_size(s); + tcg_out32(s, CALL); + tcg_out_nop(s); + } } else { /* indirect jump method */ - tcg_out_ld_ptr(s, TCG_REG_T1, + tcg_out_ld_ptr(s, TCG_REG_TB, (uintptr_t)(s->tb_jmp_target_addr + a0)); - tcg_out_arithi(s, TCG_REG_G0, TCG_REG_T1, 0, JMPL); + tcg_out_arithi(s, TCG_REG_G0, TCG_REG_TB, 0, JMPL); + tcg_out_nop(s); + } + s->tb_jmp_reset_offset[a0] = c = tcg_current_code_size(s); + + /* For the unlinked path of goto_tb, we need to reset + TCG_REG_TB to the beginning of this TB. */ + if (USE_REG_TB) { + c = -c; + if (check_fit_i32(c, 13)) { + tcg_out_arithi(s, TCG_REG_TB, TCG_REG_TB, c, ARITH_ADD); + } else { + tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_T1, c); + tcg_out_arith(s, TCG_REG_TB, TCG_REG_TB, + TCG_REG_T1, ARITH_ADD); + } } - tcg_out_nop(s); - s->tb_jmp_reset_offset[a0] = tcg_current_code_size(s); break; case INDEX_op_goto_ptr: tcg_out_arithi(s, TCG_REG_G0, a0, 0, JMPL); - tcg_out_nop(s); + if (USE_REG_TB) { + tcg_out_arith(s, TCG_REG_TB, a0, TCG_REG_G0, ARITH_OR); + } else { + tcg_out_nop(s); + } break; case INDEX_op_br: tcg_out_bpcc(s, COND_A, BPCC_PT, arg_label(a0)); @@ -1709,13 +1792,40 @@ void tcg_register_jit(void *buf, size_t buf_size) void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, uintptr_t addr) { - uint32_t *ptr = (uint32_t *)jmp_addr; - uintptr_t disp = addr - jmp_addr; + intptr_t tb_disp = addr - tc_ptr; + intptr_t br_disp = addr - jmp_addr; + tcg_insn_unit i1, i2; + + /* We can reach the entire address space for ILP32. + For LP64, the code_gen_buffer can't be larger than 2GB. */ + tcg_debug_assert(tb_disp == (int32_t)tb_disp); + tcg_debug_assert(br_disp == (int32_t)br_disp); + + if (!USE_REG_TB) { + atomic_set((uint32_t *)jmp_addr, deposit32(CALL, 0, 30, br_disp >> 2)); + flush_icache_range(jmp_addr, jmp_addr + 4); + return; + } - /* We can reach the entire address space for 32-bit. For 64-bit - the code_gen_buffer can't be larger than 2GB. */ - tcg_debug_assert(disp == (int32_t)disp); + /* This does not exercise the range of the branch, but we do + still need to be able to load the new value of TCG_REG_TB. + But this does still happen quite often. */ + if (check_fit_ptr(tb_disp, 13)) { + /* ba,pt %icc, addr */ + i1 = (INSN_OP(0) | INSN_OP2(1) | INSN_COND(COND_A) + | BPCC_ICC | BPCC_PT | INSN_OFF19(br_disp)); + i2 = (ARITH_ADD | INSN_RD(TCG_REG_TB) | INSN_RS1(TCG_REG_TB) + | INSN_IMM13(tb_disp)); + } else if (tb_disp >= 0) { + i1 = SETHI | INSN_RD(TCG_REG_T1) | ((tb_disp & 0xfffffc00) >> 10); + i2 = (ARITH_OR | INSN_RD(TCG_REG_T1) | INSN_RS1(TCG_REG_T1) + | INSN_IMM13(tb_disp & 0x3ff)); + } else { + i1 = SETHI | INSN_RD(TCG_REG_T1) | ((~tb_disp & 0xfffffc00) >> 10); + i2 = (ARITH_XOR | INSN_RD(TCG_REG_T1) | INSN_RS1(TCG_REG_T1) + | INSN_IMM13((tb_disp & 0x3ff) | -0x400)); + } - atomic_set(ptr, deposit32(CALL, 0, 30, disp >> 2)); - flush_icache_range(jmp_addr, jmp_addr + 4); + atomic_set((uint64_t *)jmp_addr, deposit64(i2, 32, 32, i1)); + flush_icache_range(jmp_addr, jmp_addr + 8); } From patchwork Thu Sep 7 22:40:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111985 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp763413ybm; Thu, 7 Sep 2017 15:51:05 -0700 (PDT) X-Received: by 10.200.5.132 with SMTP id a4mr1444622qth.316.1504824665488; Thu, 07 Sep 2017 15:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824665; cv=none; d=google.com; s=arc-20160816; b=HdLldwpP6obR73DoJ/1aiHOz1kJsX4fWS4R50tK9QG7uFgGwWpgtJkuG8o8M5olZx7 bMEa59Ij2zev4InQkzRI06zz7at1NW5Wq8WCpy4BcHD5AIDSmrIUHpDsFqBByNCy0HAP +PlFXSWKWB78kisingptSKt5MoXPvHOL4YTr6CdJQNsFq+Hy/3V0D6I6DYnErMVedpU+ LitnU3c2FEtVLm0Fn6F7rfoQ2qiebFLEVOcIDirrBFq2udB94b87YiOme0ROQ7mHfMKf DTG3b3lVk/P64mUNKN4LkquNPb2tkKqAMNKDTKfTpTlZkvOXiBvGaz/e5/cTPDRZNpIw 9NnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=VckR6G8VPrq0GOmaJPbnP93dBEfN3HLPmvmvcRM4IWU=; b=Jx/Gcoriclhrmx6BwLfYdoJhPgARLjiCwSnNiK0oD3eLjHWOqfYimKxkaUagZap+EG 9xSeIoR9CzrtAKJmCalB4EDppddy+vUnb8syabFfJq5UnZV7+cPTJcjstSe7VLj4cDsm IWeB7hLZrL6ujkGxms/BCaVIYDh+CtXr25JlSnY3eu7hqONp5zlCjjtKX0Ethlf8i5OR tIYvcLhiNUQYHhaP/qRH6RQ/D8/hGKjeqKys4K9GwZAIho/vB6ejpQMe6m4OrU7DIco/ 4A/1F4RR3YswmnF2kXei+9Tje4gdOGD169MvNh/W0Iuyk9i3bB5BiNwR5w4JL2RwEE6Z HM5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DTF7DrSt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g4si472299qti.519.2017.09.07.15.51.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:51:05 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=DTF7DrSt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5dX-0002fz-98 for patch@linaro.org; Thu, 07 Sep 2017 18:51:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5U8-00039U-Vy for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5U4-0008IK-9a for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:21 -0400 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]:32923) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5U4-0008I1-2e for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:16 -0400 Received: by mail-pf0-x229.google.com with SMTP id y29so860349pff.0 for ; Thu, 07 Sep 2017 15:41:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VckR6G8VPrq0GOmaJPbnP93dBEfN3HLPmvmvcRM4IWU=; b=DTF7DrSt7mPWu+RNcM6sal5Fb9PxWETIPQMOFIcy1OymCD0oKre594uonn8/s2gXKi EGI0e6PmeE7lCKRUQUuxUjkCVMskd/5DzHaMaf3WrJzIeATZLNTu3k6JbHJbXm7Dbvb2 GzGEPYwfrHo3pKnHYGi0vdwyS4twaUY2cxEQk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VckR6G8VPrq0GOmaJPbnP93dBEfN3HLPmvmvcRM4IWU=; b=sOFvlqoSPpLyEX9r2Ruu2oU51YWmvSCYRJux5PGfNSzKEuedoFafcMy8zgPsydihSs knQ3/djlihrppuJH7X+mugZqdnHbb9U43sPXxvNkfrcRuCpQy+PBofAZMLLvH0o4QBB1 VTTzjJgizHTiyUHJd2I2gW4e/jFZx0K8Y5LlV/CZbrzsZyJ/x3bS+hgpMUyFEREAqIAu GdlMGclYvH2aGn6+2FCQFH3db5YNnxLBI5gnJSkglt6JgmGfSjeB8RZx+fPkWylppnf9 S4CE+CdZp2bSMSgPFv8Afs8WrfsT3qPwp8TFV400hGCCrCqxt/zWIbaXfCh3xydZwIps hekQ== X-Gm-Message-State: AHPjjUgKZuNydvEAzsGxPXwqGh0Dy7/GaJ/pP6MTdWrU31+X5erPy6nf bKI2czu1yJ7n/kSSWuB6rg== X-Google-Smtp-Source: ADKCNb68/T24mW6po1TsPmkHb2+PD3ICI0o8ur0X4HVER5ZMEj/X4F+qVersYGwAQNYFHSastY/4HA== X-Received: by 10.101.67.2 with SMTP id j2mr949323pgq.182.1504824074754; Thu, 07 Sep 2017 15:41:14 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:42 -0700 Message-Id: <20170907224051.21518-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::229 Subject: [Qemu-devel] [PULL 14/23] tcg/sparc: Use constant pool for movi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/sparc/tcg-target.h | 2 ++ tcg/sparc/tcg-target.inc.c | 77 +++++++++++++++++++++++++++++++++------------- 2 files changed, 58 insertions(+), 21 deletions(-) -- 2.13.5 diff --git a/tcg/sparc/tcg-target.h b/tcg/sparc/tcg-target.h index da98743817..d8339bf010 100644 --- a/tcg/sparc/tcg-target.h +++ b/tcg/sparc/tcg-target.h @@ -175,4 +175,6 @@ static inline void flush_icache_range(uintptr_t start, uintptr_t stop) void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); +#define TCG_TARGET_NEED_POOL_LABELS + #endif diff --git a/tcg/sparc/tcg-target.inc.c b/tcg/sparc/tcg-target.inc.c index 7d73c25347..bd7c1461c6 100644 --- a/tcg/sparc/tcg-target.inc.c +++ b/tcg/sparc/tcg-target.inc.c @@ -22,6 +22,8 @@ * THE SOFTWARE. */ +#include "tcg-pool.inc.c" + #ifdef CONFIG_DEBUG_TCG static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { "%g0", @@ -292,33 +294,46 @@ static inline int check_fit_i32(int32_t val, unsigned int bits) static void patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) { - uint32_t insn; + uint32_t insn = *code_ptr; + intptr_t pcrel; - tcg_debug_assert(addend == 0); - value = tcg_ptr_byte_diff((tcg_insn_unit *)value, code_ptr); + value += addend; + pcrel = tcg_ptr_byte_diff((tcg_insn_unit *)value, code_ptr); switch (type) { case R_SPARC_WDISP16: - if (!check_fit_ptr(value >> 2, 16)) { - tcg_abort(); - } - insn = *code_ptr; + assert(check_fit_ptr(pcrel >> 2, 16)); insn &= ~INSN_OFF16(-1); - insn |= INSN_OFF16(value); - *code_ptr = insn; + insn |= INSN_OFF16(pcrel); break; case R_SPARC_WDISP19: - if (!check_fit_ptr(value >> 2, 19)) { - tcg_abort(); - } - insn = *code_ptr; + assert(check_fit_ptr(pcrel >> 2, 19)); insn &= ~INSN_OFF19(-1); - insn |= INSN_OFF19(value); - *code_ptr = insn; + insn |= INSN_OFF19(pcrel); + break; + case R_SPARC_13: + /* Note that we're abusing this reloc type for our own needs. */ + if (!check_fit_ptr(value, 13)) { + int adj = (value > 0 ? 0xff8 : -0x1000); + value -= adj; + assert(check_fit_ptr(value, 13)); + *code_ptr++ = (ARITH_ADD | INSN_RD(TCG_REG_T2) + | INSN_RS1(TCG_REG_TB) | INSN_IMM13(adj)); + insn ^= INSN_RS1(TCG_REG_TB) ^ INSN_RS1(TCG_REG_T2); + } + insn &= ~INSN_IMM13(-1); + insn |= INSN_IMM13(value); break; + case R_SPARC_32: + /* Note that we're abusing this reloc type for our own needs. */ + code_ptr[0] = deposit32(code_ptr[0], 0, 22, value >> 10); + code_ptr[1] = deposit32(code_ptr[1], 0, 10, value); + return; default: - tcg_abort(); + g_assert_not_reached(); } + + *code_ptr = insn; } /* parse target specific constraints */ @@ -474,12 +489,24 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, return; } - if (USE_REG_TB && !in_prologue) { - intptr_t diff = arg - (uintptr_t)s->code_gen_ptr; - if (check_fit_ptr(diff, 13)) { - tcg_out_arithi(s, ret, TCG_REG_TB, diff, ARITH_ADD); - return; + if (!in_prologue) { + if (USE_REG_TB) { + intptr_t diff = arg - (uintptr_t)s->code_gen_ptr; + if (check_fit_ptr(diff, 13)) { + tcg_out_arithi(s, ret, TCG_REG_TB, diff, ARITH_ADD); + } else { + new_pool_label(s, arg, R_SPARC_13, s->code_ptr, + -(intptr_t)s->code_gen_ptr); + tcg_out32(s, LDX | INSN_RD(ret) | INSN_RS1(TCG_REG_TB)); + /* May be used to extend the 13-bit range in patch_reloc. */ + tcg_out32(s, NOP); + } + } else { + new_pool_label(s, arg, R_SPARC_32, s->code_ptr, 0); + tcg_out_sethi(s, ret, 0); + tcg_out32(s, LDX | INSN_RD(ret) | INSN_RS1(ret) | INSN_IMM13(0)); } + return; } /* A 64-bit constant decomposed into 2 32-bit pieces. */ @@ -1058,6 +1085,14 @@ static void tcg_target_qemu_prologue(TCGContext *s) #endif } +static void tcg_out_nop_fill(tcg_insn_unit *p, int count) +{ + int i; + for (i = 0; i < count; ++i) { + p[i] = NOP; + } +} + #if defined(CONFIG_SOFTMMU) /* Perform the TLB load and compare. From patchwork Thu Sep 7 22:40:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111990 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp766501ybm; Thu, 7 Sep 2017 15:54:48 -0700 (PDT) X-Received: by 10.55.104.87 with SMTP id d84mr1253118qkc.202.1504824888727; Thu, 07 Sep 2017 15:54:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824888; cv=none; d=google.com; s=arc-20160816; b=ZP82dwjPGGpi7KQwhrFMFqF/QQ9SoR+H8VzQDmLm9zeM9aL/KFVO0kpiGAZWDHZspn CooNiSgPkJfA1R9g+mmXlidTXo03wzeXn6CmgUDeSAnImy0Y0jVYHS6ccSr9XbMdS8H3 7SvWP1GJ5nD5Hi9YVTJw+3oD3X9esMB7c+VKzuIvpEawITE536v8t4Ygx1S3ZQcecjAn o/js2ZMCxoavMbh4Vtb17rhdE2mEfWSzfPZHTkM5eghXbkWDyM5WL5elA3c3wRIGvp7Q q2ftSbBNPdQk1NGEPO3Zv4DGGf+4OsmpV03hE/lJWzx6jIcAiYIn8jSmutOjIaYf2Gzx a1mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=5QX8KOLakpmoalYp7gpxxqobtH+OmlG68TqfOqz5jpo=; b=Xxr5CWNqdlGM3G1OW5vdEI4JrZxTeLOeAmgCPnwIwwJi7ew39p0tlZb7ypgr5AXwmQ cgBnT2mdoAAAdmTg62jh0tdz00o+0FWOfr07J91wwNDOpWsMShP9aN6gCDeLv9vZac4l TStMBDLxBE35qj4RXiI9ca11n7P4NwqKOeQ3oZf301dyShKIpXNEwlc8ARGppvq6d6AV GqFdZt0Vqb4wxYLAmWRIbvGil2rb37Cykf68v6cm5JIj6+HFNY72UHA8HW70zbi75eI6 6JG2xuN3NMUekA4R0xXB4iKpFfhuuydgZb6wXOPRHhtWzOUP6rY8MLFs8PhSTYkqLLXL sJXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=avymF+iO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d17si500400qtl.109.2017.09.07.15.54.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:54:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=avymF+iO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5h8-0005zD-Fj for patch@linaro.org; Thu, 07 Sep 2017 18:54:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5UA-0003B0-DV for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5U5-0008JB-Js for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:22 -0400 Received: from mail-pg0-x235.google.com ([2607:f8b0:400e:c05::235]:37080) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5U5-0008Ig-Af for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:17 -0400 Received: by mail-pg0-x235.google.com with SMTP id d8so1804111pgt.4 for ; Thu, 07 Sep 2017 15:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5QX8KOLakpmoalYp7gpxxqobtH+OmlG68TqfOqz5jpo=; b=avymF+iOfoV8ayOmc8Mnwihij2BQDSjIC91GwHzdyHC85dBGmOAKFQVUNUKL6SoqHR HfsCyZPnb5oWDhqxFe5uMxIAm36ZL0815l1YPzK18v761+2voPbgt1wBv39eNtrBpyku LtzGCRbLx46rV185K81dEjxWwxjp6yl7diF9A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5QX8KOLakpmoalYp7gpxxqobtH+OmlG68TqfOqz5jpo=; b=JgkVAgAiKIDm6H/0nC15PrjYpkT2gRyy13enAxkF/ukQlJzgAKoPZb1gQxEEf6IYlW rDGHxkh/B/9PzEKR1N0j8jWrKWWpb9MfAQbYIWuxF6vildGztQzyn9LtQuVw91nvbIH2 VkibDzOllyA4q3Hn4si16uBmfXAcWrvEdZ07znvt5T3IOKH34k1YlrycImMKF0YzuFRQ 1QUut3EXaAt2y0pIyHIFpnh8XQsRDpRI0xr9z8BTNhZaNwu8a+QgivZVpo8wegrShEI2 f0DUrmJxjrdDf5hG5ELwyhIU903sGHa4ux3uz6MyVmnK1IEKNzp7JaUhiEZwPWDcNtLj SXog== X-Gm-Message-State: AHPjjUh8PLoIduf1YyN8KbTp5450uIRQSpVEhlNxRPafejJrWut1cOzy ErfA4PpVI40KWcW709Wvzg== X-Google-Smtp-Source: ADKCNb63ADnTh4NOSJD7r9onJtaYBix66AUmwIAEck69NSjD9CCs//JMcSPn5sgDBOYDsft4+/w9pw== X-Received: by 10.84.132.1 with SMTP id 1mr1003215ple.253.1504824076120; Thu, 07 Sep 2017 15:41:16 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:43 -0700 Message-Id: <20170907224051.21518-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::235 Subject: [Qemu-devel] [PULL 15/23] tcg/arm: Improve tlb load for armv7 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Use UBFX to avoid limitation on CPU_TLB_BITS. Since we're dropping the initial shift, we need to replace the page masking. We can use MOVW+BIC to do this without shifting. The result is the same size as the armv6 path with one less conditional instruction. Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.inc.c | 72 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 20 deletions(-) -- 2.13.5 diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index 81ea900852..66c369c239 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -1173,18 +1173,33 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi, unsigned s_bits = opc & MO_SIZE; unsigned a_bits = get_alignment_bits(opc); - /* Should generate something like the following: - * shr tmp, addrlo, #TARGET_PAGE_BITS (1) + /* V7 generates the following: + * ubfx r0, addrlo, #TARGET_PAGE_BITS, #CPU_TLB_BITS * add r2, env, #high - * and r0, tmp, #(CPU_TLB_SIZE - 1) (2) - * add r2, r2, r0, lsl #CPU_TLB_ENTRY_BITS (3) - * ldr r0, [r2, #cmp] (4) + * add r2, r2, r0, lsl #CPU_TLB_ENTRY_BITS + * ldr r0, [r2, #cmp] + * ldr r2, [r2, #add] + * movw tmp, #page_align_mask + * bic tmp, addrlo, tmp + * cmp r0, tmp + * + * Otherwise we generate: + * shr tmp, addrlo, #TARGET_PAGE_BITS + * add r2, env, #high + * and r0, tmp, #(CPU_TLB_SIZE - 1) + * add r2, r2, r0, lsl #CPU_TLB_ENTRY_BITS + * ldr r0, [r2, #cmp] + * ldr r2, [r2, #add] * tst addrlo, #s_mask - * ldr r2, [r2, #add] (5) * cmpeq r0, tmp, lsl #TARGET_PAGE_BITS */ - tcg_out_dat_reg(s, COND_AL, ARITH_MOV, TCG_REG_TMP, - 0, addrlo, SHIFT_IMM_LSR(TARGET_PAGE_BITS)); + if (use_armv7_instructions) { + tcg_out_extract(s, COND_AL, TCG_REG_R0, addrlo, + TARGET_PAGE_BITS, CPU_TLB_BITS); + } else { + tcg_out_dat_reg(s, COND_AL, ARITH_MOV, TCG_REG_TMP, + 0, addrlo, SHIFT_IMM_LSR(TARGET_PAGE_BITS)); + } /* We checked that the offset is contained within 16 bits above. */ if (add_off > 0xfff || (use_armv6_instructions && cmp_off > 0xff)) { @@ -1194,9 +1209,10 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi, add_off -= cmp_off & 0xff00; cmp_off &= 0xff; } - - tcg_out_dat_imm(s, COND_AL, ARITH_AND, - TCG_REG_R0, TCG_REG_TMP, CPU_TLB_SIZE - 1); + if (!use_armv7_instructions) { + tcg_out_dat_imm(s, COND_AL, ARITH_AND, + TCG_REG_R0, TCG_REG_TMP, CPU_TLB_SIZE - 1); + } tcg_out_dat_reg(s, COND_AL, ARITH_ADD, TCG_REG_R2, base, TCG_REG_R0, SHIFT_IMM_LSL(CPU_TLB_ENTRY_BITS)); @@ -1212,24 +1228,40 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi, } } + /* Load the tlb addend. */ + tcg_out_ld32_12(s, COND_AL, TCG_REG_R2, TCG_REG_R2, add_off); + /* Check alignment. We don't support inline unaligned acceses, but we can easily support overalignment checks. */ if (a_bits < s_bits) { a_bits = s_bits; } - if (a_bits) { - tcg_out_dat_imm(s, COND_AL, ARITH_TST, 0, addrlo, (1 << a_bits) - 1); - } - /* Load the tlb addend. */ - tcg_out_ld32_12(s, COND_AL, TCG_REG_R2, TCG_REG_R2, add_off); + if (use_armv7_instructions) { + tcg_target_ulong mask = ~(TARGET_PAGE_MASK | ((1 << a_bits) - 1)); + int rot = encode_imm(mask); - tcg_out_dat_reg(s, (a_bits ? COND_EQ : COND_AL), ARITH_CMP, 0, - TCG_REG_R0, TCG_REG_TMP, SHIFT_IMM_LSL(TARGET_PAGE_BITS)); + if (rot >= 0) { + tcg_out_dat_imm(s, COND_AL, ARITH_BIC, TCG_REG_TMP, addrlo, + rotl(mask, rot) | (rot << 7)); + } else { + tcg_out_movi32(s, COND_AL, TCG_REG_TMP, mask); + tcg_out_dat_reg(s, COND_AL, ARITH_BIC, TCG_REG_TMP, + addrlo, TCG_REG_TMP, 0); + } + tcg_out_dat_reg(s, COND_AL, ARITH_CMP, 0, TCG_REG_R0, TCG_REG_TMP, 0); + } else { + if (a_bits) { + tcg_out_dat_imm(s, COND_AL, ARITH_TST, 0, addrlo, + (1 << a_bits) - 1); + } + tcg_out_dat_reg(s, (a_bits ? COND_EQ : COND_AL), ARITH_CMP, + 0, TCG_REG_R0, TCG_REG_TMP, + SHIFT_IMM_LSL(TARGET_PAGE_BITS)); + } if (TARGET_LONG_BITS == 64) { - tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, 0, - TCG_REG_R1, addrhi, SHIFT_IMM_LSL(0)); + tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, 0, TCG_REG_R1, addrhi, 0); } return TCG_REG_R2; From patchwork Thu Sep 7 22:40:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111991 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp766612ybm; Thu, 7 Sep 2017 15:54:56 -0700 (PDT) X-Received: by 10.200.50.93 with SMTP id y29mr1327893qta.301.1504824896804; Thu, 07 Sep 2017 15:54:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824896; cv=none; d=google.com; s=arc-20160816; b=qHCGZLAkh3mElSbGZJZ1JcHU0k8jMKIWNfIpCtKL4giwas0abG+FFUJZwPccqI1Hl1 a+7qLm5c2DOYK97vyRCJWXufjKzS3prWk/fv7U35yWt/HolD/Pxo+XUnBVNSLPz6dz9u yPXDe5sptpNPaz/dH9xOmASS/FcUq6G35SgAqKqBBtiUS9zyy5z5qPiOs3/OJrk38vIc uGcVTXGB6mo0owVA4D9WVC4FngswEtmEZLtIQtR7LtIZgF7ZpiF4PcH75OLDiKo2+MZF /8hf2kgOTQ2jOSqIlSIoTY/kTyPD8DLkyxbHUNNtp+Pf2nUl43FbUvnHqlB5UfLTCHi6 VjLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=2N1o0vUjnZz5BCK8ZK7VFGbHwO2asiO5JbqCJsu9o+Y=; b=A7Ko0dSCOVuBYg4tWEY/M05qMsr2vtHrkAAtw1xQQupjK2oR1x3xD+tL7r9xh1AD+k XRrVRey+cpgpEb8R0KbXbwxJxBSLqq41bkfgU5lX01HA5Lze3yJ5zWAM6faCrCJG7vz+ Ae0OqdjK2Z/fDgWSRVvdsv5DjL8w8fdQldsFb3MsfmWFMlLkAeYWStxk4xBl6LWR3rS/ hTGSGht77BF6RFs1QLDb30PmUeyisFhZHmmn3MTSJBusbffzFJZ449vnTxGPSscWvS5E 0EoTXY6+66L3UuAWLqw4ZQZwp79XP35KcREuplq4s5u3GwUS9EGLueRM8LwZ0k39Cxd7 6dHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ic7ZBugQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id j127si532493qkd.99.2017.09.07.15.54.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:54:56 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ic7ZBugQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5hG-00066T-PY for patch@linaro.org; Thu, 07 Sep 2017 18:54:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5UB-0003CD-KM for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5U7-0008KH-07 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:23 -0400 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]:35370) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5U6-0008JY-R5 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:18 -0400 Received: by mail-pf0-x230.google.com with SMTP id g13so1629864pfm.2 for ; Thu, 07 Sep 2017 15:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2N1o0vUjnZz5BCK8ZK7VFGbHwO2asiO5JbqCJsu9o+Y=; b=ic7ZBugQCPbzUP5aStxddpM+ys7WR/lxY0abfdStBcRYMnsSNXKJT5Jrpv79G1WJPe ELlS8ZRCfoanSXMJGjh+s9yLCy5mYPoXCKvdcyU3DE+wxo8Qr9hxCFWe07Uk/8gyVaeH 7Se/wQQlOz9jqXSY148eQMQzbT5g4xfQPAxaQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2N1o0vUjnZz5BCK8ZK7VFGbHwO2asiO5JbqCJsu9o+Y=; b=Bk78j1nctPxBEsv2JtI513K4L/zaZ9NmJb7w6hKaCS3YyVxwpXIXIC7v+GFNIGALlH y7FfhjLgB+7WrhC7GWGHLjXNjPPasykojwJWBUtr9zIUpqkhCZBVGC9Rb9iX8teWdRSQ eEF2OSwG1tDPpMyItEhiP3FRnZILWLg5mwvZdOxGUcgiJRYgqKOlR9UVN2mMpgdLegmc H30S/20gSZQ60jiSL+7MVBpZCmy7gdhqsN92gkUhW/ztbivIUT+XtjA8FG7lBVTTSxlB o+adp0uU8w/nrFpSohUJHaDucx9ZJHN+I1iERnXZwGNdkmh5A+11NsmzIGe34ThGeZZP 4JPw== X-Gm-Message-State: AHPjjUhEvwjJvOHSpn1FaGGS5gPAA2lep3SP5MS8PfTBlh+ThIX5wAbq UW/l4LEL99HQHygbooLXdQ== X-Google-Smtp-Source: ADKCNb4LqiJVX+xYU9Adv2kxiCFAuWu2qk4MFd6rriOIgZ5961o1yziJdSVJ5zOrbzex9XAgol+b9Q== X-Received: by 10.99.54.7 with SMTP id d7mr956281pga.115.1504824077525; Thu, 07 Sep 2017 15:41:17 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:44 -0700 Message-Id: <20170907224051.21518-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::230 Subject: [Qemu-devel] [PULL 16/23] tcg/arm: Tighten tlb indexing offset test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson We are not going to use ldrd for loading the comparator for 32-bit guests, so don't limit cmp_off to 8 bits then. This eliminates one insn in the tlb load for some guests. Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.inc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.13.5 diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index 66c369c239..6c12b169ce 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -1202,7 +1202,9 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi, } /* We checked that the offset is contained within 16 bits above. */ - if (add_off > 0xfff || (use_armv6_instructions && cmp_off > 0xff)) { + if (add_off > 0xfff + || (use_armv6_instructions && TARGET_LONG_BITS == 64 + && cmp_off > 0xff)) { tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R2, base, (24 << 7) | (cmp_off >> 8)); base = TCG_REG_R2; From patchwork Thu Sep 7 22:40:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111987 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp765321ybm; Thu, 7 Sep 2017 15:53:23 -0700 (PDT) X-Received: by 10.55.40.152 with SMTP id o24mr1195704qko.235.1504824803349; Thu, 07 Sep 2017 15:53:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824803; cv=none; d=google.com; s=arc-20160816; b=l82Zry4aIdsJTpO4pPD/YJW0nbgWAT9TL/+Wosn3bu4zAxR2NM9mVGNrcNvpHPgOEu JS317xKAwk7nfDBvMntvIBLl7RsMS012EUwn+oVwbnLUMG5Aotf3PfRip1SMmZTTH9zB 6AnhbyYaMlDcNug1ATACSZ+CgWYTeh6JMguyDLU2SyfUA6mLYYpP2IF53aqITlQRRwBK xCCmZQJS8oRLbim4SLeBtDYrDbZxR/vCJOT3n7yr1C/C37B8cjrGNZek0USMWMuyUsiR W6+93/ErSJihYStn1RQRxEogVlB/fBPoOlGmAcQuysauTdJvwAZ2lkDg/zuTCm5ltrmc LE5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=my5u9zTRSGJTRSMPjvCTuuzuAPHbQ/HrYQ7To4qpkd4=; b=Xdm4H3sanGWpc//ZXNHFiph/bJCHOW/ZLljkj2FWSqYwbdLI3VgrNjDvP6wAdbDxF2 6RZdCv6Yvej5RNyws7WDF6XhC4rPK/z69jhlTiuLRyp93pCuFU3uKOZzA9BOrKRTKARj tlcFTq6N7j3+aTfid0oY7IDgVCNeS7HGrp+NOW1KVt5weig1wRKkAGEAiqBd/qtHpg5e 20OKky2NgUEAQVhqH236W51ALiOrHUcCZZUg9ND+FM+JGhAt0VspC5KWlQTXEWDIzOgA 3y4MFN+ALwSYDTbvfLgSAyTCveBBS42nd9fgIevMaMtJkOp0EdAJpwrMKUId4I5tJ0yc LKLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=c1o8Tht+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x2si492604qkl.98.2017.09.07.15.53.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:53:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=c1o8Tht+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5fl-0004gw-2x for patch@linaro.org; Thu, 07 Sep 2017 18:53:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5UF-0003Ge-II for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5U8-0008Li-TT for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:27 -0400 Received: from mail-pf0-x22a.google.com ([2607:f8b0:400e:c00::22a]:34083) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5U8-0008Kz-Kd for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:20 -0400 Received: by mail-pf0-x22a.google.com with SMTP id e1so1640981pfk.1 for ; Thu, 07 Sep 2017 15:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=my5u9zTRSGJTRSMPjvCTuuzuAPHbQ/HrYQ7To4qpkd4=; b=c1o8Tht+Y1OQ5l4EvBr7lPYOO8u99EiYJdKJnQtD/Tau++C3iq1BP97KCgOS+6ZwtO BoouIhijTnWMDTbEVicG+F89UVCu94EmYcAy7fq3ci34KkeTX/cC9I2MYb+5ymCxTt0N wEYk2P2Ms67EaK+k1VN47IqDZAZlZkeVhaoAY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=my5u9zTRSGJTRSMPjvCTuuzuAPHbQ/HrYQ7To4qpkd4=; b=hmkIMDsonARcbFWaFGY/Npx1t3L5YDJLnAlBk99EtYiG/2JMHLzVJWcbz0kH/OMLeL A+M1ybo3XvylIAduOtPlpD4pFZxKHwRARwmQbAqfFf+BAaeEc10i077bM7ulT/i+0ESu /EU6lOpS/5WTXi3+2H8jaFcytk9dUBdpLxbwyjdsgWsCqPkVU5LCKFFFJlEpeUXeWc8r oxNkhOOKqr3zus0Y9uqsQmr1cQxvOF9UJDN5bZELNhqk4dqGh1gILOpi3w7L647yL3YA 3ya0MAJbl8VGTbjA7eEzvcZ9RQLa5N7tfgIs2yotXVlIL03304eiUPJ1BJQ+GFvBYs4v 5xBw== X-Gm-Message-State: AHPjjUjQeJVCkOnn2LX6Vkm9To7NXSGf9O1Mzt7WtvPYSj1Yq/PKzDa8 dz1DSlC+oYSYlpZ4q7XqMw== X-Google-Smtp-Source: ADKCNb4X44g49RQ2XLMAe0r016eYXsXgEgEU/A90Kp4Pjx8UlOz1linE6hMQWb3tqmNlc/nFAzfAMg== X-Received: by 10.98.75.152 with SMTP id d24mr993866pfj.38.1504824078838; Thu, 07 Sep 2017 15:41:18 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:45 -0700 Message-Id: <20170907224051.21518-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22a Subject: [Qemu-devel] [PULL 17/23] tcg/arm: Code rearrangement X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Move constants before all of the functions. Move tcg_out_ functions before all of the others. No functional change. Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.inc.c | 599 +++++++++++++++++++++++------------------------ 1 file changed, 299 insertions(+), 300 deletions(-) -- 2.13.5 diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index 6c12b169ce..f40e87066f 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -85,6 +85,97 @@ static const int tcg_target_call_oarg_regs[2] = { #define TCG_REG_TMP TCG_REG_R12 +enum arm_cond_code_e { + COND_EQ = 0x0, + COND_NE = 0x1, + COND_CS = 0x2, /* Unsigned greater or equal */ + COND_CC = 0x3, /* Unsigned less than */ + COND_MI = 0x4, /* Negative */ + COND_PL = 0x5, /* Zero or greater */ + COND_VS = 0x6, /* Overflow */ + COND_VC = 0x7, /* No overflow */ + COND_HI = 0x8, /* Unsigned greater than */ + COND_LS = 0x9, /* Unsigned less or equal */ + COND_GE = 0xa, + COND_LT = 0xb, + COND_GT = 0xc, + COND_LE = 0xd, + COND_AL = 0xe, +}; + +#define TO_CPSR (1 << 20) + +#define SHIFT_IMM_LSL(im) (((im) << 7) | 0x00) +#define SHIFT_IMM_LSR(im) (((im) << 7) | 0x20) +#define SHIFT_IMM_ASR(im) (((im) << 7) | 0x40) +#define SHIFT_IMM_ROR(im) (((im) << 7) | 0x60) +#define SHIFT_REG_LSL(rs) (((rs) << 8) | 0x10) +#define SHIFT_REG_LSR(rs) (((rs) << 8) | 0x30) +#define SHIFT_REG_ASR(rs) (((rs) << 8) | 0x50) +#define SHIFT_REG_ROR(rs) (((rs) << 8) | 0x70) + +typedef enum { + ARITH_AND = 0x0 << 21, + ARITH_EOR = 0x1 << 21, + ARITH_SUB = 0x2 << 21, + ARITH_RSB = 0x3 << 21, + ARITH_ADD = 0x4 << 21, + ARITH_ADC = 0x5 << 21, + ARITH_SBC = 0x6 << 21, + ARITH_RSC = 0x7 << 21, + ARITH_TST = 0x8 << 21 | TO_CPSR, + ARITH_CMP = 0xa << 21 | TO_CPSR, + ARITH_CMN = 0xb << 21 | TO_CPSR, + ARITH_ORR = 0xc << 21, + ARITH_MOV = 0xd << 21, + ARITH_BIC = 0xe << 21, + ARITH_MVN = 0xf << 21, + + INSN_CLZ = 0x016f0f10, + INSN_RBIT = 0x06ff0f30, + + INSN_LDR_IMM = 0x04100000, + INSN_LDR_REG = 0x06100000, + INSN_STR_IMM = 0x04000000, + INSN_STR_REG = 0x06000000, + + INSN_LDRH_IMM = 0x005000b0, + INSN_LDRH_REG = 0x001000b0, + INSN_LDRSH_IMM = 0x005000f0, + INSN_LDRSH_REG = 0x001000f0, + INSN_STRH_IMM = 0x004000b0, + INSN_STRH_REG = 0x000000b0, + + INSN_LDRB_IMM = 0x04500000, + INSN_LDRB_REG = 0x06500000, + INSN_LDRSB_IMM = 0x005000d0, + INSN_LDRSB_REG = 0x001000d0, + INSN_STRB_IMM = 0x04400000, + INSN_STRB_REG = 0x06400000, + + INSN_LDRD_IMM = 0x004000d0, + INSN_LDRD_REG = 0x000000d0, + INSN_STRD_IMM = 0x004000f0, + INSN_STRD_REG = 0x000000f0, + + INSN_DMB_ISH = 0x5bf07ff5, + INSN_DMB_MCR = 0xba0f07ee, +} ARMInsn; + +static const uint8_t tcg_cond_to_arm_cond[] = { + [TCG_COND_EQ] = COND_EQ, + [TCG_COND_NE] = COND_NE, + [TCG_COND_LT] = COND_LT, + [TCG_COND_GE] = COND_GE, + [TCG_COND_LE] = COND_LE, + [TCG_COND_GT] = COND_GT, + /* unsigned */ + [TCG_COND_LTU] = COND_CC, + [TCG_COND_GEU] = COND_CS, + [TCG_COND_LEU] = COND_LS, + [TCG_COND_GTU] = COND_HI, +}; + static inline void reloc_pc24(tcg_insn_unit *code_ptr, tcg_insn_unit *target) { ptrdiff_t offset = (tcg_ptr_byte_diff(target, code_ptr) - 8) >> 2; @@ -236,183 +327,257 @@ static inline int tcg_target_const_match(tcg_target_long val, TCGType type, } } -#define TO_CPSR (1 << 20) +static inline void tcg_out_b(TCGContext *s, int cond, int32_t offset) +{ + tcg_out32(s, (cond << 28) | 0x0a000000 | + (((offset - 8) >> 2) & 0x00ffffff)); +} -typedef enum { - ARITH_AND = 0x0 << 21, - ARITH_EOR = 0x1 << 21, - ARITH_SUB = 0x2 << 21, - ARITH_RSB = 0x3 << 21, - ARITH_ADD = 0x4 << 21, - ARITH_ADC = 0x5 << 21, - ARITH_SBC = 0x6 << 21, - ARITH_RSC = 0x7 << 21, - ARITH_TST = 0x8 << 21 | TO_CPSR, - ARITH_CMP = 0xa << 21 | TO_CPSR, - ARITH_CMN = 0xb << 21 | TO_CPSR, - ARITH_ORR = 0xc << 21, - ARITH_MOV = 0xd << 21, - ARITH_BIC = 0xe << 21, - ARITH_MVN = 0xf << 21, +static inline void tcg_out_b_noaddr(TCGContext *s, int cond) +{ + /* We pay attention here to not modify the branch target by masking + the corresponding bytes. This ensure that caches and memory are + kept coherent during retranslation. */ + tcg_out32(s, deposit32(*s->code_ptr, 24, 8, (cond << 4) | 0x0a)); +} - INSN_CLZ = 0x016f0f10, - INSN_RBIT = 0x06ff0f30, +static inline void tcg_out_bl_noaddr(TCGContext *s, int cond) +{ + /* We pay attention here to not modify the branch target by masking + the corresponding bytes. This ensure that caches and memory are + kept coherent during retranslation. */ + tcg_out32(s, deposit32(*s->code_ptr, 24, 8, (cond << 4) | 0x0b)); +} - INSN_LDR_IMM = 0x04100000, - INSN_LDR_REG = 0x06100000, - INSN_STR_IMM = 0x04000000, - INSN_STR_REG = 0x06000000, +static inline void tcg_out_bl(TCGContext *s, int cond, int32_t offset) +{ + tcg_out32(s, (cond << 28) | 0x0b000000 | + (((offset - 8) >> 2) & 0x00ffffff)); +} - INSN_LDRH_IMM = 0x005000b0, - INSN_LDRH_REG = 0x001000b0, - INSN_LDRSH_IMM = 0x005000f0, - INSN_LDRSH_REG = 0x001000f0, - INSN_STRH_IMM = 0x004000b0, - INSN_STRH_REG = 0x000000b0, +static inline void tcg_out_blx(TCGContext *s, int cond, int rn) +{ + tcg_out32(s, (cond << 28) | 0x012fff30 | rn); +} - INSN_LDRB_IMM = 0x04500000, - INSN_LDRB_REG = 0x06500000, - INSN_LDRSB_IMM = 0x005000d0, - INSN_LDRSB_REG = 0x001000d0, - INSN_STRB_IMM = 0x04400000, - INSN_STRB_REG = 0x06400000, +static inline void tcg_out_blx_imm(TCGContext *s, int32_t offset) +{ + tcg_out32(s, 0xfa000000 | ((offset & 2) << 23) | + (((offset - 8) >> 2) & 0x00ffffff)); +} - INSN_LDRD_IMM = 0x004000d0, - INSN_LDRD_REG = 0x000000d0, - INSN_STRD_IMM = 0x004000f0, - INSN_STRD_REG = 0x000000f0, +static inline void tcg_out_dat_reg(TCGContext *s, + int cond, int opc, int rd, int rn, int rm, int shift) +{ + tcg_out32(s, (cond << 28) | (0 << 25) | opc | + (rn << 16) | (rd << 12) | shift | rm); +} - INSN_DMB_ISH = 0x5bf07ff5, - INSN_DMB_MCR = 0xba0f07ee, +static inline void tcg_out_nop(TCGContext *s) +{ + if (use_armv7_instructions) { + /* Architected nop introduced in v6k. */ + /* ??? This is an MSR (imm) 0,0,0 insn. Anyone know if this + also Just So Happened to do nothing on pre-v6k so that we + don't need to conditionalize it? */ + tcg_out32(s, 0xe320f000); + } else { + /* Prior to that the assembler uses mov r0, r0. */ + tcg_out_dat_reg(s, COND_AL, ARITH_MOV, 0, 0, 0, SHIFT_IMM_LSL(0)); + } +} -} ARMInsn; +static inline void tcg_out_mov_reg(TCGContext *s, int cond, int rd, int rm) +{ + /* Simple reg-reg move, optimising out the 'do nothing' case */ + if (rd != rm) { + tcg_out_dat_reg(s, cond, ARITH_MOV, rd, 0, rm, SHIFT_IMM_LSL(0)); + } +} -#define SHIFT_IMM_LSL(im) (((im) << 7) | 0x00) -#define SHIFT_IMM_LSR(im) (((im) << 7) | 0x20) -#define SHIFT_IMM_ASR(im) (((im) << 7) | 0x40) -#define SHIFT_IMM_ROR(im) (((im) << 7) | 0x60) -#define SHIFT_REG_LSL(rs) (((rs) << 8) | 0x10) -#define SHIFT_REG_LSR(rs) (((rs) << 8) | 0x30) -#define SHIFT_REG_ASR(rs) (((rs) << 8) | 0x50) -#define SHIFT_REG_ROR(rs) (((rs) << 8) | 0x70) +static inline void tcg_out_bx(TCGContext *s, int cond, TCGReg rn) +{ + /* Unless the C portion of QEMU is compiled as thumb, we don't + actually need true BX semantics; merely a branch to an address + held in a register. */ + if (use_armv5t_instructions) { + tcg_out32(s, (cond << 28) | 0x012fff10 | rn); + } else { + tcg_out_mov_reg(s, cond, TCG_REG_PC, rn); + } +} -enum arm_cond_code_e { - COND_EQ = 0x0, - COND_NE = 0x1, - COND_CS = 0x2, /* Unsigned greater or equal */ - COND_CC = 0x3, /* Unsigned less than */ - COND_MI = 0x4, /* Negative */ - COND_PL = 0x5, /* Zero or greater */ - COND_VS = 0x6, /* Overflow */ - COND_VC = 0x7, /* No overflow */ - COND_HI = 0x8, /* Unsigned greater than */ - COND_LS = 0x9, /* Unsigned less or equal */ - COND_GE = 0xa, - COND_LT = 0xb, - COND_GT = 0xc, - COND_LE = 0xd, - COND_AL = 0xe, -}; +static inline void tcg_out_dat_imm(TCGContext *s, + int cond, int opc, int rd, int rn, int im) +{ + tcg_out32(s, (cond << 28) | (1 << 25) | opc | + (rn << 16) | (rd << 12) | im); +} -static const uint8_t tcg_cond_to_arm_cond[] = { - [TCG_COND_EQ] = COND_EQ, - [TCG_COND_NE] = COND_NE, - [TCG_COND_LT] = COND_LT, - [TCG_COND_GE] = COND_GE, - [TCG_COND_LE] = COND_LE, - [TCG_COND_GT] = COND_GT, - /* unsigned */ - [TCG_COND_LTU] = COND_CC, - [TCG_COND_GEU] = COND_CS, - [TCG_COND_LEU] = COND_LS, - [TCG_COND_GTU] = COND_HI, -}; +/* Note that this routine is used for both LDR and LDRH formats, so we do + not wish to include an immediate shift at this point. */ +static void tcg_out_memop_r(TCGContext *s, int cond, ARMInsn opc, TCGReg rt, + TCGReg rn, TCGReg rm, bool u, bool p, bool w) +{ + tcg_out32(s, (cond << 28) | opc | (u << 23) | (p << 24) + | (w << 21) | (rn << 16) | (rt << 12) | rm); +} + +static void tcg_out_memop_8(TCGContext *s, int cond, ARMInsn opc, TCGReg rt, + TCGReg rn, int imm8, bool p, bool w) +{ + bool u = 1; + if (imm8 < 0) { + imm8 = -imm8; + u = 0; + } + tcg_out32(s, (cond << 28) | opc | (u << 23) | (p << 24) | (w << 21) | + (rn << 16) | (rt << 12) | ((imm8 & 0xf0) << 4) | (imm8 & 0xf)); +} + +static void tcg_out_memop_12(TCGContext *s, int cond, ARMInsn opc, TCGReg rt, + TCGReg rn, int imm12, bool p, bool w) +{ + bool u = 1; + if (imm12 < 0) { + imm12 = -imm12; + u = 0; + } + tcg_out32(s, (cond << 28) | opc | (u << 23) | (p << 24) | (w << 21) | + (rn << 16) | (rt << 12) | imm12); +} + +static inline void tcg_out_ld32_12(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, int imm12) +{ + tcg_out_memop_12(s, cond, INSN_LDR_IMM, rt, rn, imm12, 1, 0); +} + +static inline void tcg_out_st32_12(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, int imm12) +{ + tcg_out_memop_12(s, cond, INSN_STR_IMM, rt, rn, imm12, 1, 0); +} + +static inline void tcg_out_ld32_r(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) +{ + tcg_out_memop_r(s, cond, INSN_LDR_REG, rt, rn, rm, 1, 1, 0); +} + +static inline void tcg_out_st32_r(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) +{ + tcg_out_memop_r(s, cond, INSN_STR_REG, rt, rn, rm, 1, 1, 0); +} + +static inline void tcg_out_ldrd_8(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, int imm8) +{ + tcg_out_memop_8(s, cond, INSN_LDRD_IMM, rt, rn, imm8, 1, 0); +} + +static inline void tcg_out_ldrd_r(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) +{ + tcg_out_memop_r(s, cond, INSN_LDRD_REG, rt, rn, rm, 1, 1, 0); +} + +static inline void tcg_out_strd_8(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, int imm8) +{ + tcg_out_memop_8(s, cond, INSN_STRD_IMM, rt, rn, imm8, 1, 0); +} + +static inline void tcg_out_strd_r(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) +{ + tcg_out_memop_r(s, cond, INSN_STRD_REG, rt, rn, rm, 1, 1, 0); +} + +/* Register pre-increment with base writeback. */ +static inline void tcg_out_ld32_rwb(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) +{ + tcg_out_memop_r(s, cond, INSN_LDR_REG, rt, rn, rm, 1, 1, 1); +} + +static inline void tcg_out_st32_rwb(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) +{ + tcg_out_memop_r(s, cond, INSN_STR_REG, rt, rn, rm, 1, 1, 1); +} + +static inline void tcg_out_ld16u_8(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, int imm8) +{ + tcg_out_memop_8(s, cond, INSN_LDRH_IMM, rt, rn, imm8, 1, 0); +} -static inline void tcg_out_b(TCGContext *s, int cond, int32_t offset) +static inline void tcg_out_st16_8(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, int imm8) { - tcg_out32(s, (cond << 28) | 0x0a000000 | - (((offset - 8) >> 2) & 0x00ffffff)); + tcg_out_memop_8(s, cond, INSN_STRH_IMM, rt, rn, imm8, 1, 0); } -static inline void tcg_out_b_noaddr(TCGContext *s, int cond) +static inline void tcg_out_ld16u_r(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) { - /* We pay attention here to not modify the branch target by masking - the corresponding bytes. This ensure that caches and memory are - kept coherent during retranslation. */ - tcg_out32(s, deposit32(*s->code_ptr, 24, 8, (cond << 4) | 0x0a)); + tcg_out_memop_r(s, cond, INSN_LDRH_REG, rt, rn, rm, 1, 1, 0); } -static inline void tcg_out_bl_noaddr(TCGContext *s, int cond) +static inline void tcg_out_st16_r(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) { - /* We pay attention here to not modify the branch target by masking - the corresponding bytes. This ensure that caches and memory are - kept coherent during retranslation. */ - tcg_out32(s, deposit32(*s->code_ptr, 24, 8, (cond << 4) | 0x0b)); + tcg_out_memop_r(s, cond, INSN_STRH_REG, rt, rn, rm, 1, 1, 0); } -static inline void tcg_out_bl(TCGContext *s, int cond, int32_t offset) +static inline void tcg_out_ld16s_8(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, int imm8) { - tcg_out32(s, (cond << 28) | 0x0b000000 | - (((offset - 8) >> 2) & 0x00ffffff)); + tcg_out_memop_8(s, cond, INSN_LDRSH_IMM, rt, rn, imm8, 1, 0); } -static inline void tcg_out_blx(TCGContext *s, int cond, int rn) +static inline void tcg_out_ld16s_r(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) { - tcg_out32(s, (cond << 28) | 0x012fff30 | rn); + tcg_out_memop_r(s, cond, INSN_LDRSH_REG, rt, rn, rm, 1, 1, 0); } -static inline void tcg_out_blx_imm(TCGContext *s, int32_t offset) +static inline void tcg_out_ld8_12(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, int imm12) { - tcg_out32(s, 0xfa000000 | ((offset & 2) << 23) | - (((offset - 8) >> 2) & 0x00ffffff)); + tcg_out_memop_12(s, cond, INSN_LDRB_IMM, rt, rn, imm12, 1, 0); } -static inline void tcg_out_dat_reg(TCGContext *s, - int cond, int opc, int rd, int rn, int rm, int shift) +static inline void tcg_out_st8_12(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, int imm12) { - tcg_out32(s, (cond << 28) | (0 << 25) | opc | - (rn << 16) | (rd << 12) | shift | rm); + tcg_out_memop_12(s, cond, INSN_STRB_IMM, rt, rn, imm12, 1, 0); } -static inline void tcg_out_nop(TCGContext *s) +static inline void tcg_out_ld8_r(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) { - if (use_armv7_instructions) { - /* Architected nop introduced in v6k. */ - /* ??? This is an MSR (imm) 0,0,0 insn. Anyone know if this - also Just So Happened to do nothing on pre-v6k so that we - don't need to conditionalize it? */ - tcg_out32(s, 0xe320f000); - } else { - /* Prior to that the assembler uses mov r0, r0. */ - tcg_out_dat_reg(s, COND_AL, ARITH_MOV, 0, 0, 0, SHIFT_IMM_LSL(0)); - } + tcg_out_memop_r(s, cond, INSN_LDRB_REG, rt, rn, rm, 1, 1, 0); } -static inline void tcg_out_mov_reg(TCGContext *s, int cond, int rd, int rm) +static inline void tcg_out_st8_r(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) { - /* Simple reg-reg move, optimising out the 'do nothing' case */ - if (rd != rm) { - tcg_out_dat_reg(s, cond, ARITH_MOV, rd, 0, rm, SHIFT_IMM_LSL(0)); - } + tcg_out_memop_r(s, cond, INSN_STRB_REG, rt, rn, rm, 1, 1, 0); } -static inline void tcg_out_bx(TCGContext *s, int cond, TCGReg rn) +static inline void tcg_out_ld8s_8(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, int imm8) { - /* Unless the C portion of QEMU is compiled as thumb, we don't - actually need true BX semantics; merely a branch to an address - held in a register. */ - if (use_armv5t_instructions) { - tcg_out32(s, (cond << 28) | 0x012fff10 | rn); - } else { - tcg_out_mov_reg(s, cond, TCG_REG_PC, rn); - } + tcg_out_memop_8(s, cond, INSN_LDRSB_IMM, rt, rn, imm8, 1, 0); } -static inline void tcg_out_dat_imm(TCGContext *s, - int cond, int opc, int rd, int rn, int im) +static inline void tcg_out_ld8s_r(TCGContext *s, int cond, TCGReg rt, + TCGReg rn, TCGReg rm) { - tcg_out32(s, (cond << 28) | (1 << 25) | opc | - (rn << 16) | (rd << 12) | im); + tcg_out_memop_r(s, cond, INSN_LDRSB_REG, rt, rn, rm, 1, 1, 0); } static void tcg_out_movi32(TCGContext *s, int cond, int rd, uint32_t arg) @@ -747,172 +912,6 @@ static inline void tcg_out_sextract(TCGContext *s, int cond, TCGReg rd, | (ofs << 7) | ((len - 1) << 16)); } -/* Note that this routine is used for both LDR and LDRH formats, so we do - not wish to include an immediate shift at this point. */ -static void tcg_out_memop_r(TCGContext *s, int cond, ARMInsn opc, TCGReg rt, - TCGReg rn, TCGReg rm, bool u, bool p, bool w) -{ - tcg_out32(s, (cond << 28) | opc | (u << 23) | (p << 24) - | (w << 21) | (rn << 16) | (rt << 12) | rm); -} - -static void tcg_out_memop_8(TCGContext *s, int cond, ARMInsn opc, TCGReg rt, - TCGReg rn, int imm8, bool p, bool w) -{ - bool u = 1; - if (imm8 < 0) { - imm8 = -imm8; - u = 0; - } - tcg_out32(s, (cond << 28) | opc | (u << 23) | (p << 24) | (w << 21) | - (rn << 16) | (rt << 12) | ((imm8 & 0xf0) << 4) | (imm8 & 0xf)); -} - -static void tcg_out_memop_12(TCGContext *s, int cond, ARMInsn opc, TCGReg rt, - TCGReg rn, int imm12, bool p, bool w) -{ - bool u = 1; - if (imm12 < 0) { - imm12 = -imm12; - u = 0; - } - tcg_out32(s, (cond << 28) | opc | (u << 23) | (p << 24) | (w << 21) | - (rn << 16) | (rt << 12) | imm12); -} - -static inline void tcg_out_ld32_12(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, int imm12) -{ - tcg_out_memop_12(s, cond, INSN_LDR_IMM, rt, rn, imm12, 1, 0); -} - -static inline void tcg_out_st32_12(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, int imm12) -{ - tcg_out_memop_12(s, cond, INSN_STR_IMM, rt, rn, imm12, 1, 0); -} - -static inline void tcg_out_ld32_r(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_LDR_REG, rt, rn, rm, 1, 1, 0); -} - -static inline void tcg_out_st32_r(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_STR_REG, rt, rn, rm, 1, 1, 0); -} - -static inline void tcg_out_ldrd_8(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, int imm8) -{ - tcg_out_memop_8(s, cond, INSN_LDRD_IMM, rt, rn, imm8, 1, 0); -} - -static inline void tcg_out_ldrd_r(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_LDRD_REG, rt, rn, rm, 1, 1, 0); -} - -static inline void tcg_out_strd_8(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, int imm8) -{ - tcg_out_memop_8(s, cond, INSN_STRD_IMM, rt, rn, imm8, 1, 0); -} - -static inline void tcg_out_strd_r(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_STRD_REG, rt, rn, rm, 1, 1, 0); -} - -/* Register pre-increment with base writeback. */ -static inline void tcg_out_ld32_rwb(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_LDR_REG, rt, rn, rm, 1, 1, 1); -} - -static inline void tcg_out_st32_rwb(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_STR_REG, rt, rn, rm, 1, 1, 1); -} - -static inline void tcg_out_ld16u_8(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, int imm8) -{ - tcg_out_memop_8(s, cond, INSN_LDRH_IMM, rt, rn, imm8, 1, 0); -} - -static inline void tcg_out_st16_8(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, int imm8) -{ - tcg_out_memop_8(s, cond, INSN_STRH_IMM, rt, rn, imm8, 1, 0); -} - -static inline void tcg_out_ld16u_r(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_LDRH_REG, rt, rn, rm, 1, 1, 0); -} - -static inline void tcg_out_st16_r(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_STRH_REG, rt, rn, rm, 1, 1, 0); -} - -static inline void tcg_out_ld16s_8(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, int imm8) -{ - tcg_out_memop_8(s, cond, INSN_LDRSH_IMM, rt, rn, imm8, 1, 0); -} - -static inline void tcg_out_ld16s_r(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_LDRSH_REG, rt, rn, rm, 1, 1, 0); -} - -static inline void tcg_out_ld8_12(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, int imm12) -{ - tcg_out_memop_12(s, cond, INSN_LDRB_IMM, rt, rn, imm12, 1, 0); -} - -static inline void tcg_out_st8_12(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, int imm12) -{ - tcg_out_memop_12(s, cond, INSN_STRB_IMM, rt, rn, imm12, 1, 0); -} - -static inline void tcg_out_ld8_r(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_LDRB_REG, rt, rn, rm, 1, 1, 0); -} - -static inline void tcg_out_st8_r(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_STRB_REG, rt, rn, rm, 1, 1, 0); -} - -static inline void tcg_out_ld8s_8(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, int imm8) -{ - tcg_out_memop_8(s, cond, INSN_LDRSB_IMM, rt, rn, imm8, 1, 0); -} - -static inline void tcg_out_ld8s_r(TCGContext *s, int cond, TCGReg rt, - TCGReg rn, TCGReg rm) -{ - tcg_out_memop_r(s, cond, INSN_LDRSB_REG, rt, rn, rm, 1, 1, 0); -} - static inline void tcg_out_ld32u(TCGContext *s, int cond, int rd, int rn, int32_t offset) { From patchwork Thu Sep 7 22:40:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111993 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp769161ybm; Thu, 7 Sep 2017 15:58:22 -0700 (PDT) X-Received: by 10.55.114.194 with SMTP id n185mr1508632qkc.180.1504825102377; Thu, 07 Sep 2017 15:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504825102; cv=none; d=google.com; s=arc-20160816; b=hOGWuFRcp5qVnADKkUjsdsIdzdCX5AGl4Z2H3bX3VblYlXP6cqMkL6iCwXlblCWUaJ qjln34EFJMQfDtVr9NBYkh61A+6Z0V6/I2hBIiHyTonDmLK9/gQuw3cEKFeJU72Nyud6 hzkGoc/ZmnYu3fxn4UIdFyvTUBEVSATVfJEnD7fIl/zJ5f7jvylrHES+yNEtNw6yx6n/ WTtF6EN26WMw6/xVvJPhUWhPOdG2k7M3Q+8jkiN/qR/OsMcwtFexIJYEpxI3rPclllGx X/xDhyWQEA9y1EpXz8k8bgOu4Xji1nPjpQK6RL07F8zBCU1xu8WWRaQEH3lJNBLN82Ny epLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=H7OIZz6ye65zyAW3I3NdIdDeG7/KcItlzmmSrm81ckA=; b=wMRplLMIdMhipCerCo3kEL+btg2LHkPrDl7MK0W7sywsG0xhsjVuhq3e0F6UOcOXsK bCdn6QxbI6g1Q2g8tdElx7E0wu1+rXk6HzNdrtibjObp5Sr/7xH2wTWehXsrDID27gjK rMg3zc3Vvhk1WjWWKggj9w9jdlmXQeAfM51WsO6vKjQA7QMJeZY1Sxd+b2stedVwXi/d bU8SdWFQkov9cAaMIq2brQwqucji/fWDS1OXA7e9c8nBqinJD2fUIFhCshsBU/aqP4CO cTk5aZgDPU+ZpiyOI4x0w3DjTb9BWWx4ijJLVgqgCWd6u0WBg2KcY/YsU6cQ1OOzLD4k PqKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eVtRLIYz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 31si559014qkt.244.2017.09.07.15.58.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:58:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=eVtRLIYz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5ka-0000Zs-AU for patch@linaro.org; Thu, 07 Sep 2017 18:58:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5UE-0003F3-4r for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5U9-0008ME-Fe for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:26 -0400 Received: from mail-pg0-x22b.google.com ([2607:f8b0:400e:c05::22b]:37081) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5U9-0008LZ-9X for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:21 -0400 Received: by mail-pg0-x22b.google.com with SMTP id d8so1804327pgt.4 for ; Thu, 07 Sep 2017 15:41:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H7OIZz6ye65zyAW3I3NdIdDeG7/KcItlzmmSrm81ckA=; b=eVtRLIYzIkxxe18bIKbzDDOx0WkAT82Pfy8j8FceiJvoQwB2h+RK1tg3M9yzoZkti7 IoPQ8mPmWdX9Tzb/qVEd2xaRn17+oQwiKnMp2foSBgSC22SXOpHR3z+zNUPsaU+u4nMP Y6bXsLWkwzatTHIx/7j4H4EtyP/26yWywWH+Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=H7OIZz6ye65zyAW3I3NdIdDeG7/KcItlzmmSrm81ckA=; b=i0WYZ3f/TBvaUm56OoakEnqI2wfq2sKifRwkQM+2jVVNQJBEZ2v3qzOP4DM2oAV8EA qVxj2EUjqS/TX8ABz0FCo1RboPGhpUCR5qjK+OMR2sGvX8ovV/ia1V80oX8LiuybOgiK 7N90f+Lr9KmqrxGSWIz/LGqCoTToemaBSHZsxuH/bOoZQL9/zUrOpNvq5vq4gzNkbIYn faMYQMf0xgi7lQdQNO/OmKlTiGbNJw7rG5kfRBd3qyaRcAMfQYIveXibNobnsBwV135b FUHMTzRj2s1CNn2ddwRg3b7iwL4qT+Rxq+1TJ8NNjx68qfiP/TAXY33kGxETclgaKzyD 08qg== X-Gm-Message-State: AHPjjUibjk48dbgJsJV3NeBHyMJfxt57gjYO7QyqwOBOxEek4tRENktw DF8jS+fylCfBw6HA8+No1w== X-Google-Smtp-Source: ADKCNb7JS1VhXKBUsD4kUiWuHlcZTIKb7DTSkuw6p50sT30fHTAkb2yKA6ZlxHuheLYOxwMhmgjxww== X-Received: by 10.98.245.207 with SMTP id b76mr915846pfm.223.1504824080066; Thu, 07 Sep 2017 15:41:20 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:46 -0700 Message-Id: <20170907224051.21518-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::22b Subject: [Qemu-devel] [PULL 18/23] tcg/arm: Extract INSN_NOP X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson We'll want this for tcg_out_nop_fill. Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.inc.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) -- 2.13.5 diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index f40e87066f..78603a19db 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -160,8 +160,18 @@ typedef enum { INSN_DMB_ISH = 0x5bf07ff5, INSN_DMB_MCR = 0xba0f07ee, + + /* Architected nop introduced in v6k. */ + /* ??? This is an MSR (imm) 0,0,0 insn. Anyone know if this + also Just So Happened to do nothing on pre-v6k so that we + don't need to conditionalize it? */ + INSN_NOP_v6k = 0xe320f000, + /* Otherwise the assembler uses mov r0,r0 */ + INSN_NOP_v4 = (COND_AL << 28) | ARITH_MOV, } ARMInsn; +#define INSN_NOP (use_armv7_instructions ? INSN_NOP_v6k : INSN_NOP_v4) + static const uint8_t tcg_cond_to_arm_cond[] = { [TCG_COND_EQ] = COND_EQ, [TCG_COND_NE] = COND_NE, @@ -375,16 +385,7 @@ static inline void tcg_out_dat_reg(TCGContext *s, static inline void tcg_out_nop(TCGContext *s) { - if (use_armv7_instructions) { - /* Architected nop introduced in v6k. */ - /* ??? This is an MSR (imm) 0,0,0 insn. Anyone know if this - also Just So Happened to do nothing on pre-v6k so that we - don't need to conditionalize it? */ - tcg_out32(s, 0xe320f000); - } else { - /* Prior to that the assembler uses mov r0, r0. */ - tcg_out_dat_reg(s, COND_AL, ARITH_MOV, 0, 0, 0, SHIFT_IMM_LSL(0)); - } + tcg_out32(s, INSN_NOP); } static inline void tcg_out_mov_reg(TCGContext *s, int cond, int rd, int rm) From patchwork Thu Sep 7 22:40:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111977 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp722859qge; Thu, 7 Sep 2017 15:44:45 -0700 (PDT) X-Received: by 10.55.40.153 with SMTP id o25mr1201287qko.73.1504824285190; Thu, 07 Sep 2017 15:44:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824285; cv=none; d=google.com; s=arc-20160816; b=l+vY2eriTQ4BgYBN1ZvCJpaU+qaywnTIedlNLXCrsnqZmu/4EQalIkjHSPNR9NcfHQ u24ap2Xruiu5E+HMNye1TqcbsgNAHfgQRC/4XQ39WypdAAYX/3VqrGvqgLKyhknxXIas 0ZDecdo/aN7H64xbhmQ5OVHSFsNEjRYAqYmdGTnc538GOVOV5Ugi5O06yB5rFJdOYD/4 HqJa5+iMkyuXvgbXMqeSbldpLfYXLBe/OB/bmxNdosJod4v18/jdFGypetSy2s8NTUuz OVi8IItRJYuyDPRhiRYXzhX5ov74B4NlWW4CG+6WaZB/9To+gf4eISwd4i5zsbfQVK4E UFqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=yBOu7JqCOYL/zdGWF1N82TvQobuXyOfCGYZq1uRWpb0=; b=ayVSGSQnZbQq+UJsDd7URQNV465YgvFGqnsIilRW/2DZjMWaRvpOQThAezdCrtx0aN f4iehvaAwMjlIKyrgWgE/yI69BC33eMJQMu87exOu29L5y09/0htpTRJy9lcVB57maIw YVdAjHCCZQ4203QiyMsfGKHeM/lQfU4wHD986leQgOexkYImOoYuW/jDyhPeprYON5di EEJuckfmKvon+KaZqvJxJar0vN5LYmklPz7f9Z9PeM7XFCuJuKaJoploSVOc8DI9zQEP 610V0ESQ1m4jNfHq2qJ52owO/0ZfiHK7OUe6f2LpLBDfNxasLXZBVFdRXZAH/aoFsO+p E80A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VmPATD0p; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a15si465987qkc.304.2017.09.07.15.44.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:44:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=VmPATD0p; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5XO-0005pV-Uq for patch@linaro.org; Thu, 07 Sep 2017 18:44:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5UG-0003H4-1G for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5UA-0008NR-T7 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:28 -0400 Received: from mail-pf0-x233.google.com ([2607:f8b0:400e:c00::233]:35370) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5UA-0008Mo-L5 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:22 -0400 Received: by mail-pf0-x233.google.com with SMTP id g13so1630069pfm.2 for ; Thu, 07 Sep 2017 15:41:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yBOu7JqCOYL/zdGWF1N82TvQobuXyOfCGYZq1uRWpb0=; b=VmPATD0ptYLRoh1GGAo8LC3hiwDUVY2YE29ioS+3EobbsdwCP1G5WvXPff6bJIbng/ F9zkEkp385Ms4U0n1sdkK3eKRQWopTyYDUfeiu3gl0h/urwmd1pcUKDcp6e6k+VaS5r4 rEA3GOjvoBntcb2/xPpC6DG0+FAgjb4E0KEco= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yBOu7JqCOYL/zdGWF1N82TvQobuXyOfCGYZq1uRWpb0=; b=tbsRvl/O4QpaT6wHQjsNOz5funcWcT5dEwG4bkPPHUP/K1dIQg8mCByM1FauarJG5b hcocglKEzqYzgdZA6np4v+H4HtSE1ZMiV+Wc8YMTubvTBGx2UK0jlhxFqRb/+gHjAh9A 4tsP2GKt/KghXFXwhTfoXluYvxVgSNVMnQaoRbp0NkuYtliS5kaT1XT5GdMAxtnabOaw gyMTJ6/waKnZFbnDeOMzsj4gMjEj/SelE1UwRyfMehqg+3m7o6ho5m1EGo9fzgyPp7xE jnRBUFR/oZr44uNw1AEBG2Zr362Pp49crybebn0vAB0HSZFt0rwbSc8Fb2WnE8I/Pewu Vf2A== X-Gm-Message-State: AHPjjUj5zdmC/jrA0e7THcrqzcg2ZmgqP77aA/75qXOHdkhDobvnQusm Mkb3g3dp+9CxKs21jbGZzg== X-Google-Smtp-Source: ADKCNb4PdCLghz5H1eb2KnMixpdTsFMIvxHm+5EZbDHmuivHgmVb/fL50hg4zyaq30QF0FykgXPK/Q== X-Received: by 10.98.80.13 with SMTP id e13mr939480pfb.341.1504824081298; Thu, 07 Sep 2017 15:41:21 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:47 -0700 Message-Id: <20170907224051.21518-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::233 Subject: [Qemu-devel] [PULL 19/23] tcg/arm: Use constant pool for movi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.h | 1 + tcg/arm/tcg-target.inc.c | 92 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 75 insertions(+), 18 deletions(-) -- 2.13.5 diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h index 2e92cb3283..94b3578c55 100644 --- a/tcg/arm/tcg-target.h +++ b/tcg/arm/tcg-target.h @@ -143,5 +143,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS #endif +#define TCG_TARGET_NEED_POOL_LABELS #endif diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index 78603a19db..2736022d5a 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -23,6 +23,7 @@ */ #include "elf.h" +#include "tcg-pool.inc.c" int arm_arch = __ARM_ARCH; @@ -203,9 +204,39 @@ static inline void reloc_pc24_atomic(tcg_insn_unit *code_ptr, tcg_insn_unit *tar static void patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) { - tcg_debug_assert(type == R_ARM_PC24); tcg_debug_assert(addend == 0); - reloc_pc24(code_ptr, (tcg_insn_unit *)value); + + if (type == R_ARM_PC24) { + reloc_pc24(code_ptr, (tcg_insn_unit *)value); + } else if (type == R_ARM_PC13) { + intptr_t diff = value - (uintptr_t)(code_ptr + 2); + tcg_insn_unit insn = *code_ptr; + bool u; + + if (diff >= -0xfff && diff <= 0xfff) { + u = (diff >= 0); + if (!u) { + diff = -diff; + } + } else { + int rd = extract32(insn, 12, 4); + int rt = rd == TCG_REG_PC ? TCG_REG_TMP : rd; + assert(diff >= 0x1000 && diff < 0x100000); + /* add rt, pc, #high */ + *code_ptr++ = ((insn & 0xf0000000) | (1 << 25) | ARITH_ADD + | (TCG_REG_PC << 16) | (rt << 12) + | (20 << 7) | (diff >> 12)); + /* ldr rd, [rt, #low] */ + insn = deposit32(insn, 12, 4, rt); + diff &= 0xfff; + u = 1; + } + insn = deposit32(insn, 23, 1, u); + insn = deposit32(insn, 0, 12, diff); + *code_ptr = insn; + } else { + g_assert_not_reached(); + } } #define TCG_CT_CONST_ARM 0x100 @@ -581,9 +612,20 @@ static inline void tcg_out_ld8s_r(TCGContext *s, int cond, TCGReg rt, tcg_out_memop_r(s, cond, INSN_LDRSB_REG, rt, rn, rm, 1, 1, 0); } +static void tcg_out_movi_pool(TCGContext *s, int cond, int rd, uint32_t arg) +{ + /* The 12-bit range on the ldr insn is sometimes a bit too small. + In order to get around that we require two insns, one of which + will usually be a nop, but may be replaced in patch_reloc. */ + new_pool_label(s, arg, R_ARM_PC13, s->code_ptr, 0); + tcg_out_ld32_12(s, cond, rd, TCG_REG_PC, 0); + tcg_out_nop(s); +} + static void tcg_out_movi32(TCGContext *s, int cond, int rd, uint32_t arg) { - int rot, opc, rn, diff; + int rot, diff, opc, sh1, sh2; + uint32_t tt0, tt1, tt2; /* Check a single MOV/MVN before anything else. */ rot = encode_imm(arg); @@ -631,24 +673,30 @@ static void tcg_out_movi32(TCGContext *s, int cond, int rd, uint32_t arg) return; } - /* TODO: This is very suboptimal, we can easily have a constant - pool somewhere after all the instructions. */ + /* Look for sequences of two insns. If we have lots of 1's, we can + shorten the sequence by beginning with mvn and then clearing + higher bits with eor. */ + tt0 = arg; opc = ARITH_MOV; - rn = 0; - /* If we have lots of leading 1's, we can shorten the sequence by - beginning with mvn and then clearing higher bits with eor. */ - if (clz32(~arg) > clz32(arg)) { - opc = ARITH_MVN, arg = ~arg; + if (ctpop32(arg) > 16) { + tt0 = ~arg; + opc = ARITH_MVN; + } + sh1 = ctz32(tt0) & ~1; + tt1 = tt0 & ~(0xff << sh1); + sh2 = ctz32(tt1) & ~1; + tt2 = tt1 & ~(0xff << sh2); + if (tt2 == 0) { + rot = ((32 - sh1) << 7) & 0xf00; + tcg_out_dat_imm(s, cond, opc, rd, 0, ((tt0 >> sh1) & 0xff) | rot); + rot = ((32 - sh2) << 7) & 0xf00; + tcg_out_dat_imm(s, cond, ARITH_EOR, rd, rd, + ((tt0 >> sh2) & 0xff) | rot); + return; } - do { - int i = ctz32(arg) & ~1; - rot = ((32 - i) << 7) & 0xf00; - tcg_out_dat_imm(s, cond, opc, rd, rn, ((arg >> i) & 0xff) | rot); - arg &= ~(0xff << i); - opc = ARITH_EOR; - rn = rd; - } while (arg); + /* Otherwise, drop it into the constant pool. */ + tcg_out_movi_pool(s, cond, rd, arg); } static inline void tcg_out_dat_rI(TCGContext *s, int cond, int opc, TCGArg dst, @@ -2164,6 +2212,14 @@ static inline void tcg_out_movi(TCGContext *s, TCGType type, tcg_out_movi32(s, COND_AL, ret, arg); } +static void tcg_out_nop_fill(tcg_insn_unit *p, int count) +{ + int i; + for (i = 0; i < count; ++i) { + p[i] = INSN_NOP; + } +} + /* Compute frame size via macros, to share between tcg_target_qemu_prologue and tcg_register_jit. */ From patchwork Thu Sep 7 22:40:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111995 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp770798ybm; Thu, 7 Sep 2017 16:00:21 -0700 (PDT) X-Received: by 10.55.121.194 with SMTP id u185mr1330806qkc.101.1504825221590; Thu, 07 Sep 2017 16:00:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504825221; cv=none; d=google.com; s=arc-20160816; b=AQ8IHYIKjZhW0eXjAaYsPjt+yNiGwICLatt0omdkjvS7lL3kAVPZcMVTrQCfE0Q7CL 1D+zNlS2GJO1iFvDmc13BCGj/Ni5+DMr0mDWlESXoiW00no1UexT3xG24OA2WtOlfc4+ EqIwCJ4tJZG+/IZV3797ek6A0CywvVCb4b65yJ+qfGFLMbGikw8r+z/t4gFCcyNGRqyH YLVzF6Wl10+FSL0Ng7sc8fmkE1dMFFYeOYRMD4jewqlTBsjJZ5iDS9bl2IEndBhK1lew 0FQ9K184n2AIeslTcxHX73Edopi4SpHYA3bbZELLClwWG0WkUp34Vl8Q27s4B+xxH0GB IksA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=/pPbNEjmX+uxRZu6MhUxcaRB0QEpWumd838yfUa4lXE=; b=T3sX6IYLRFWzTWBj6yxkMi9Au9w5DdBEFUTy/We52SMebbCg6yJB9DChkXthCQnTAI pHTU0TINM1KtMZeIF5xPzjGDJ/d1CGNOcEOLLIpjm9boMwe1rPyHvElcEvkteV6bte9n EdzuVQsqaunDt+6lCkIqSKnOwL/kwbdUCyOlct/PUAZ/73e9fnJWzXs1WtC9eP7xMWyF Lur0OCDFeBeYoSeNJalwXQ+Z5kMsUYYjNZAXbOp4eg4K8wbbhdFLon+k8JsaoGpFxNko iEIou/zV1mxrdJiT5GoVp1oiOjiv/DGS+XVsdp466ZRhWSi1L9rHfplbaemJsRLdKlfU o7lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bUH1aWUr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id i4si511514qki.35.2017.09.07.16.00.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 16:00:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bUH1aWUr; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5mV-0002GS-JK for patch@linaro.org; Thu, 07 Sep 2017 19:00:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5UG-0003Hb-Gz for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5UB-0008ON-Um for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:28 -0400 Received: from mail-pf0-x235.google.com ([2607:f8b0:400e:c00::235]:35370) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5UB-0008Ng-OX for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:23 -0400 Received: by mail-pf0-x235.google.com with SMTP id g13so1630129pfm.2 for ; Thu, 07 Sep 2017 15:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/pPbNEjmX+uxRZu6MhUxcaRB0QEpWumd838yfUa4lXE=; b=bUH1aWUrjUIkCNtM4t410GExkDd+spICWAcqcZcdZAFt49/ysGYL8DA/gffyS+zNsa 8P46Yb2ZaLFsu2VnuWjeBVyVzZUQWbR+MhYevBFLIkhrZp2EErudBgXeyusVu0dkLMyt 6T+dqm6gL3jxHNJcxZFQTNzwXLMag/+qATGOo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/pPbNEjmX+uxRZu6MhUxcaRB0QEpWumd838yfUa4lXE=; b=lsvdMrSIeK1mNTpdSsB/XVLoJlM5Q/52ju/bn7k4kixshDdYDv8Tsqtu8YZ3ax3rQh 5CGBQwmiqw6shygUBIPVz2bQglUbacW1CdOj1sa9AWbpPw6RB40j+yaqucESrbeZ5LXu /xzAWDcQIOVwl0GFJ90emgWEJ/Y44An/8OpBn89PdNykOVzt1RhYra9BqOHtHirtkTjE CIXZnQSg71jwBevq8IdBEi1FanhXg59bkPs342SXyTW82AELMIuRg5paK7wRESQTcxi5 yUq8vPz7bKKK5yKKGnsABj5yetdIZ3ma2mSKUn5zydZzoEvMLgVKz1OXCXt35qRm3EdY 4rBg== X-Gm-Message-State: AHPjjUgfzgxHx2J58JAlygMdKPSoyZ3c80/KL5frLhLfEZ+WKJ/Kasu3 zYjRJxHTh7jSnQ2TVJ7s9Q== X-Google-Smtp-Source: ADKCNb7znRlPwqJ553KE28/8lfxQLoMYURYl8H8w8rhcV81Ny+PKMNY8+w1FY14P+N0HCK+VU8Bv1w== X-Received: by 10.84.233.67 with SMTP id k3mr1008124plt.416.1504824082509; Thu, 07 Sep 2017 15:41:22 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:48 -0700 Message-Id: <20170907224051.21518-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::235 Subject: [Qemu-devel] [PULL 20/23] tcg/arm: Use constant pool for call X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.inc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) -- 2.13.5 diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index 2736022d5a..db46aea38c 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -1054,10 +1054,7 @@ static void tcg_out_goto(TCGContext *s, int cond, tcg_insn_unit *addr) tcg_out_b(s, cond, disp); return; } - - assert(use_armv5t_instructions || (addri & 1) == 0); - tcg_out_movi32(s, cond, TCG_REG_TMP, addri); - tcg_out_bx(s, cond, TCG_REG_TMP); + tcg_out_movi_pool(s, cond, TCG_REG_PC, addri); } /* The call case is mostly used for helpers - so it's not unreasonable @@ -1081,9 +1078,9 @@ static void tcg_out_call(TCGContext *s, tcg_insn_unit *addr) tcg_out_movi32(s, COND_AL, TCG_REG_TMP, addri); tcg_out_blx(s, COND_AL, TCG_REG_TMP); } else { + /* ??? Know that movi_pool emits exactly 2 insns. */ tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R14, TCG_REG_PC, 4); - tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_PC, -4); - tcg_out32(s, addri); + tcg_out_movi_pool(s, COND_AL, TCG_REG_PC, addri); } } From patchwork Thu Sep 7 22:40:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111992 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp768758ybm; Thu, 7 Sep 2017 15:57:50 -0700 (PDT) X-Received: by 10.55.201.219 with SMTP id m88mr1211656qkl.303.1504825069997; Thu, 07 Sep 2017 15:57:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504825069; cv=none; d=google.com; s=arc-20160816; b=lRrt55aTbobAtYgWVhUYV2T4xjsUdLS3QtGEIgAMYSkUVuJsYnSdn2mxMlNkAAHVlY kDWHSgUDBOifmiJ5Rqvw6+KCLYLiRX84NGxH9LCAyDePDN+vUOqIjyTYCvNWLOK4sznE MfWHjNX22+satlhaYZ4MdwLLfV3zl1XtxmQDzxW+9KgtlHOYWR2Tgeubn8DbRrZDJ3wd TMieHc8f+QOMnHTQmYRGd0b2YrULNjtGWJsWWyee05c8WMsjZ+aUIJhciCp2itWvLmZV Tkq57I8W69dSBmjJZGTsxnhZ6cK1Hkgbu0b/ErH6BIoqpmbv3TPhlB+byyx7EuUs6946 5vsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=1KhGx0qtsp/MTCShkhoI1NsYI1NCaIblZvH8Oahm9TU=; b=cMkCpTMCVPMpzboN97VZ/N48vwyWd5XIctyX8yRHpVnHSTbKX5wqzgD38noTZVIbjE WGllXBKkDSGtuWpRzE4DrpYv17khAvr0Q/6gkmrz2sDOIykAWXG9uZRWI7P13oVICfTU VsZcYEJepw5XsbWsoa6wBYhQpF30cB5BCwL0hQO9iw+Lznvl0ZNA6Wks9IgD3A4cMsD2 3UMZwgUo03m5YtgkeNOxKzssK2DXl1Q+PvYgVHEEvYXlYJnah3oAtHVEV1U9VdrVMVZa 1UJDxtXlKq0IKYcbdl6I0UdIGc+SsdcIJNh5wcq+sbVEGWp5wg7t31u7ETmy7CRMX85q b6BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JUmCS+8I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k56si520174qtc.351.2017.09.07.15.57.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:57:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JUmCS+8I; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5k3-0008Kb-Ot for patch@linaro.org; Thu, 07 Sep 2017 18:57:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5UK-0003Ib-0A for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5UE-0008Pu-43 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:32 -0400 Received: from mail-pg0-x22b.google.com ([2607:f8b0:400e:c05::22b]:35578) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5UD-0008PQ-RX for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:26 -0400 Received: by mail-pg0-x22b.google.com with SMTP id 188so1820206pgb.2 for ; Thu, 07 Sep 2017 15:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1KhGx0qtsp/MTCShkhoI1NsYI1NCaIblZvH8Oahm9TU=; b=JUmCS+8IFZ3Uc+R9GEjERjaA+gpfRz+lajt26SqqjlK+ggOqFGFVmHlqdnCNazc2YA rBGo9guDx/h4e6e+QPYwS/JmXOKn76jIO+C4WDA4351PudXtl2wXzdXmDU0KwFG1Nt20 ENOOLb9vo9OeekDj3cqmYBZaXQ8e4U+C5ioxk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1KhGx0qtsp/MTCShkhoI1NsYI1NCaIblZvH8Oahm9TU=; b=X3g6qBywQv4X4FohLWKVmZ9L9pLk3PNoMCKAThYP+qhf9kBFdxvQAKa8vAuuhte+7h Z7+sZ0xAikvpq5ViM/PL9Kl2wkriMM3ZmRQeYbSuHfXKSUEDmUDbd9AxKT2tMFXewEZe UUl9lxpdYu0egtDJzKgPxZdU0yn76E9/Cy37tQ/snuc4HyM/3QWEpKi9yWTPuUdwjiwE P8Hg4eEueJE6EWPBI/DEDz+RF3jAo5IoG7UOUACdZHhVvwJmvrYd/TUPkqKeMv6wIbIY SDVpiA0ArjzCwREeCclnEIrKDqwGTCdx/Cbc2GSVbjlcMCZIXb3X2CdHhcCQZ/vwVVYG iIhA== X-Gm-Message-State: AHPjjUhnoFXSge5/AZIlhSY0noskBfGfEmly1enCSDy5bcOvR+/rBRs5 n+AV9FcBVfqhtSzPqkKy7A== X-Google-Smtp-Source: ADKCNb4OXM8IHipUs6E4EpekV7tppLEXaQ+W8Dduq2fEzoEOM/PbMid8w2TLQNonHoD+Y5oSHxW4bg== X-Received: by 10.99.126.84 with SMTP id o20mr947319pgn.141.1504824084272; Thu, 07 Sep 2017 15:41:24 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:49 -0700 Message-Id: <20170907224051.21518-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::22b Subject: [Qemu-devel] [PULL 21/23] tcg/ppc: Change TCG_REG_RA to TCG_REG_TB X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson At this point the conversion is a wash. Loading of TB+ofs is smaller, but the actual return address from exit_tb is larger. There are a few more insns required to transition between TBs. But the expectation is that accesses to the constant pool will on the whole be smaller. Signed-off-by: Richard Henderson --- tcg/ppc/tcg-target.inc.c | 273 +++++++++++++++++++++-------------------------- 1 file changed, 122 insertions(+), 151 deletions(-) -- 2.13.5 diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c index d772faf7be..bc14d2c9c6 100644 --- a/tcg/ppc/tcg-target.inc.c +++ b/tcg/ppc/tcg-target.inc.c @@ -39,29 +39,8 @@ # define TCG_REG_TMP1 TCG_REG_R12 #endif -/* For the 64-bit target, we don't like the 5 insn sequence needed to build - full 64-bit addresses. Better to have a base register to which we can - apply a 32-bit displacement. - - There are generally three items of interest: - (1) helper functions in the main executable, - (2) TranslationBlock data structures, - (3) the return address in the epilogue. - - For user-only, we USE_STATIC_CODE_GEN_BUFFER, so the code_gen_buffer - will be inside the main executable, and thus near enough to make a - pointer to the epilogue be within 2GB of all helper functions. - - For softmmu, we'll let the kernel choose the address of code_gen_buffer, - and odds are it'll be somewhere close to the main malloc arena, and so - a pointer to the epilogue will be within 2GB of the TranslationBlocks. - - For --enable-pie, everything will be kinda near everything else, - somewhere in high memory. - - Thus we choose to keep the return address in a call-saved register. */ -#define TCG_REG_RA TCG_REG_R31 -#define USE_REG_RA (TCG_TARGET_REG_BITS == 64) +#define TCG_REG_TB TCG_REG_R31 +#define USE_REG_TB (TCG_TARGET_REG_BITS == 64) /* Shorthand for size of a pointer. Avoid promotion to unsigned. */ #define SZP ((int)sizeof(void *)) @@ -614,50 +593,68 @@ static inline void tcg_out_shri64(TCGContext *s, TCGReg dst, TCGReg src, int c) tcg_out_rld(s, RLDICL, dst, src, 64 - c, c); } -static void tcg_out_movi32(TCGContext *s, TCGReg ret, int32_t arg) +static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, + tcg_target_long arg, bool in_prologue) { - if (arg == (int16_t) arg) { + intptr_t tb_diff; + int32_t high; + + tcg_debug_assert(TCG_TARGET_REG_BITS == 64 || type == TCG_TYPE_I32); + + if (TCG_TARGET_REG_BITS == 64 && type == TCG_TYPE_I32) { + arg = (int32_t)arg; + } + + /* Load 16-bit immediates with one insn. */ + if (arg == (int16_t)arg) { tcg_out32(s, ADDI | TAI(ret, 0, arg)); - } else { + return; + } + + /* Load addresses within the TB with one insn. */ + tb_diff = arg - (intptr_t)s->code_gen_ptr; + if (!in_prologue && USE_REG_TB && tb_diff == (int16_t)tb_diff) { + tcg_out32(s, ADDI | TAI(ret, TCG_REG_TB, tb_diff)); + return; + } + + /* Load 32-bit immediates with two insns. */ + if (TCG_TARGET_REG_BITS == 32 || arg == (int32_t)arg) { tcg_out32(s, ADDIS | TAI(ret, 0, arg >> 16)); if (arg & 0xffff) { tcg_out32(s, ORI | SAI(ret, ret, arg)); } + return; } -} - -static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg ret, - tcg_target_long arg) -{ - tcg_debug_assert(TCG_TARGET_REG_BITS == 64 || type == TCG_TYPE_I32); - if (type == TCG_TYPE_I32 || arg == (int32_t)arg) { - tcg_out_movi32(s, ret, arg); - } else if (arg == (uint32_t)arg && !(arg & 0x8000)) { + if (arg == (uint32_t)arg && !(arg & 0x8000)) { tcg_out32(s, ADDI | TAI(ret, 0, arg)); tcg_out32(s, ORIS | SAI(ret, ret, arg >> 16)); - } else { - int32_t high; + return; + } - if (USE_REG_RA) { - intptr_t diff = arg - (intptr_t)tb_ret_addr; - if (diff == (int32_t)diff) { - tcg_out_mem_long(s, ADDI, ADD, ret, TCG_REG_RA, diff); - return; - } - } + /* Load addresses within 2GB of TB with 2 (or rarely 3) insns. */ + if (!in_prologue && USE_REG_TB && tb_diff == (int32_t)tb_diff) { + tcg_out_mem_long(s, ADDI, ADD, ret, TCG_REG_TB, tb_diff); + return; + } - high = arg >> 31 >> 1; - tcg_out_movi32(s, ret, high); - if (high) { - tcg_out_shli64(s, ret, ret, 32); - } - if (arg & 0xffff0000) { - tcg_out32(s, ORIS | SAI(ret, ret, arg >> 16)); - } - if (arg & 0xffff) { - tcg_out32(s, ORI | SAI(ret, ret, arg)); - } + high = arg >> 31 >> 1; + tcg_out_movi(s, TCG_TYPE_I32, ret, high); + if (high) { + tcg_out_shli64(s, ret, ret, 32); } + if (arg & 0xffff0000) { + tcg_out32(s, ORIS | SAI(ret, ret, arg >> 16)); + } + if (arg & 0xffff) { + tcg_out32(s, ORI | SAI(ret, ret, arg)); + } +} + +static inline void tcg_out_movi(TCGContext *s, TCGType type, TCGReg ret, + tcg_target_long arg) +{ + tcg_out_movi_int(s, type, ret, arg, false); } static bool mask_operand(uint32_t c, int *mb, int *me) @@ -1293,49 +1290,43 @@ static void tcg_out_mb(TCGContext *s, TCGArg a0) tcg_out32(s, insn); } -#ifdef __powerpc64__ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, uintptr_t addr) { - tcg_insn_unit i1, i2; - uint64_t pair; - intptr_t diff = addr - jmp_addr; - - if (in_range_b(diff)) { - i1 = B | (diff & 0x3fffffc); - i2 = NOP; - } else if (USE_REG_RA) { - intptr_t lo, hi; - diff = addr - (uintptr_t)tb_ret_addr; - lo = (int16_t)diff; - hi = (int32_t)(diff - lo); - tcg_debug_assert(diff == hi + lo); - i1 = ADDIS | TAI(TCG_REG_TMP1, TCG_REG_RA, hi >> 16); - i2 = ADDI | TAI(TCG_REG_TMP1, TCG_REG_TMP1, lo); - } else { - tcg_debug_assert(TCG_TARGET_REG_BITS == 32 || addr == (int32_t)addr); - i1 = ADDIS | TAI(TCG_REG_TMP1, 0, addr >> 16); - i2 = ORI | SAI(TCG_REG_TMP1, TCG_REG_TMP1, addr); - } + if (TCG_TARGET_REG_BITS == 64) { + tcg_insn_unit i1, i2; + intptr_t tb_diff = addr - tc_ptr; + intptr_t br_diff = addr - (jmp_addr + 4); + uint64_t pair; + + /* This does not exercise the range of the branch, but we do + still need to be able to load the new value of TCG_REG_TB. + But this does still happen quite often. */ + if (tb_diff == (int16_t)tb_diff) { + i1 = ADDI | TAI(TCG_REG_TB, TCG_REG_TB, tb_diff); + i2 = B | (br_diff & 0x3fffffc); + } else { + intptr_t lo = (int16_t)tb_diff; + intptr_t hi = (int32_t)(tb_diff - lo); + assert(tb_diff == hi + lo); + i1 = ADDIS | TAI(TCG_REG_TB, TCG_REG_TB, hi >> 16); + i2 = ADDI | TAI(TCG_REG_TB, TCG_REG_TB, lo); + } #ifdef HOST_WORDS_BIGENDIAN - pair = (uint64_t)i1 << 32 | i2; + pair = (uint64_t)i1 << 32 | i2; #else - pair = (uint64_t)i2 << 32 | i1; + pair = (uint64_t)i2 << 32 | i1; #endif - atomic_set((uint64_t *)jmp_addr, pair); - flush_icache_range(jmp_addr, jmp_addr + 8); -} -#else -void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_addr, - uintptr_t addr) -{ - intptr_t diff = addr - jmp_addr; - tcg_debug_assert(in_range_b(diff)); - atomic_set((uint32_t *)jmp_addr, B | (diff & 0x3fffffc)); - flush_icache_range(jmp_addr, jmp_addr + 4); + atomic_set((uint64_t *)jmp_addr, pair); + flush_icache_range(jmp_addr, jmp_addr + 8); + } else { + intptr_t diff = addr - jmp_addr; + tcg_debug_assert(in_range_b(diff)); + atomic_set((uint32_t *)jmp_addr, B | (diff & 0x3fffffc)); + flush_icache_range(jmp_addr, jmp_addr + 4); + } } -#endif static void tcg_out_call(TCGContext *s, tcg_insn_unit *target) { @@ -1897,44 +1888,20 @@ static void tcg_target_qemu_prologue(TCGContext *s) #ifndef CONFIG_SOFTMMU if (guest_base) { - tcg_out_movi(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base); + tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base, true); tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG); } #endif tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]); tcg_out32(s, MTSPR | RS(tcg_target_call_iarg_regs[1]) | CTR); - - if (USE_REG_RA) { -#ifdef _CALL_AIX - /* Make the caller load the value as the TOC into R2. */ - tb_ret_addr = s->code_ptr + 2; - desc[1] = tb_ret_addr; - tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_RA, TCG_REG_R2); - tcg_out32(s, BCCTR | BO_ALWAYS); -#elif defined(_CALL_ELF) && _CALL_ELF == 2 - /* Compute from the incoming R12 value. */ - tb_ret_addr = s->code_ptr + 2; - tcg_out32(s, ADDI | TAI(TCG_REG_RA, TCG_REG_R12, - tcg_ptr_byte_diff(tb_ret_addr, s->code_buf))); - tcg_out32(s, BCCTR | BO_ALWAYS); -#else - /* Reserve max 5 insns for the constant load. */ - tb_ret_addr = s->code_ptr + 6; - tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_RA, (intptr_t)tb_ret_addr); - tcg_out32(s, BCCTR | BO_ALWAYS); - while (s->code_ptr < tb_ret_addr) { - tcg_out32(s, NOP); - } -#endif - } else { - tcg_out32(s, BCCTR | BO_ALWAYS); - tb_ret_addr = s->code_ptr; + if (USE_REG_TB) { + tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_TB, tcg_target_call_iarg_regs[1]); } + tcg_out32(s, BCCTR | BO_ALWAYS); /* Epilogue */ - tcg_debug_assert(tb_ret_addr == s->code_ptr); - s->code_gen_epilogue = tb_ret_addr; + s->code_gen_epilogue = tb_ret_addr = s->code_ptr; tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R0, TCG_REG_R1, FRAME_SIZE+LR_OFFSET); for (i = 0; i < ARRAY_SIZE(tcg_target_callee_save_regs); ++i) { @@ -1954,44 +1921,48 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, switch (opc) { case INDEX_op_exit_tb: - if (USE_REG_RA) { - ptrdiff_t disp = tcg_pcrel_diff(s, tb_ret_addr); - - /* Use a direct branch if we can, otherwise use the value in RA. - Note that the direct branch is always backward, thus we need - to account for the possibility of 5 insns from the movi. */ - if (!in_range_b(disp - 20)) { - tcg_out32(s, MTSPR | RS(TCG_REG_RA) | CTR); - tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R3, args[0]); - tcg_out32(s, BCCTR | BO_ALWAYS); - break; - } - } tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R3, args[0]); tcg_out_b(s, 0, tb_ret_addr); break; case INDEX_op_goto_tb: - tcg_debug_assert(s->tb_jmp_insn_offset); - /* Direct jump. */ -#ifdef __powerpc64__ - /* Ensure the next insns are 8-byte aligned. */ - if ((uintptr_t)s->code_ptr & 7) { - tcg_out32(s, NOP); - } - s->tb_jmp_insn_offset[args[0]] = tcg_current_code_size(s); - /* To be replaced by either a branch+nop or a load into TMP1. */ - s->code_ptr += 2; - tcg_out32(s, MTSPR | RS(TCG_REG_TMP1) | CTR); + if (s->tb_jmp_insn_offset) { + /* Direct jump. */ + if (TCG_TARGET_REG_BITS == 64) { + /* Ensure the next insns are 8-byte aligned. */ + if ((uintptr_t)s->code_ptr & 7) { + tcg_out32(s, NOP); + } + s->tb_jmp_insn_offset[args[0]] = tcg_current_code_size(s); + tcg_out32(s, ADDIS | TAI(TCG_REG_TB, TCG_REG_TB, 0)); + tcg_out32(s, ADDI | TAI(TCG_REG_TB, TCG_REG_TB, 0)); + } else { + s->tb_jmp_insn_offset[args[0]] = tcg_current_code_size(s); + tcg_out32(s, B); + s->tb_jmp_reset_offset[args[0]] = tcg_current_code_size(s); + break; + } + } else { + /* Indirect jump. */ + tcg_debug_assert(s->tb_jmp_insn_offset == NULL); + tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_TB, 0, + (intptr_t)(s->tb_jmp_insn_offset + args[0])); + } + tcg_out32(s, MTSPR | RS(TCG_REG_TB) | CTR); tcg_out32(s, BCCTR | BO_ALWAYS); -#else - /* To be replaced by a branch. */ - s->code_ptr++; -#endif - s->tb_jmp_reset_offset[args[0]] = tcg_current_code_size(s); + s->tb_jmp_reset_offset[args[0]] = c = tcg_current_code_size(s); + if (USE_REG_TB) { + /* For the unlinked case, need to reset TCG_REG_TB. */ + c = -c; + assert(c == (int16_t)c); + tcg_out32(s, ADDI | TAI(TCG_REG_TB, TCG_REG_TB, c)); + } break; case INDEX_op_goto_ptr: tcg_out32(s, MTSPR | RS(args[0]) | CTR); - tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R3, 0); + if (USE_REG_TB) { + tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_TB, args[0]); + } + tcg_out32(s, ADDI | TAI(TCG_REG_R3, 0, 0)); tcg_out32(s, BCCTR | BO_ALWAYS); break; case INDEX_op_br: @@ -2761,8 +2732,8 @@ static void tcg_target_init(TCGContext *s) tcg_regset_set_reg(s->reserved_regs, TCG_REG_R13); /* thread pointer */ #endif tcg_regset_set_reg(s->reserved_regs, TCG_REG_TMP1); /* mem temp */ - if (USE_REG_RA) { - tcg_regset_set_reg(s->reserved_regs, TCG_REG_RA); /* return addr */ + if (USE_REG_TB) { + tcg_regset_set_reg(s->reserved_regs, TCG_REG_TB); /* tb->tc_ptr */ } } From patchwork Thu Sep 7 22:40:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111994 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp769270ybm; Thu, 7 Sep 2017 15:58:29 -0700 (PDT) X-Received: by 10.200.50.93 with SMTP id y29mr1336700qta.301.1504825109058; Thu, 07 Sep 2017 15:58:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504825109; cv=none; d=google.com; s=arc-20160816; b=NMd+px5AAPLLDK1LDr/DNNAV2VsPGkTyJYHgr0xPKWh5VvVIXNqbH3tX+FYvUBLNv2 C1CFup37TWQgsUaXC01CPpk3ZXeAJLFAO0Tz7a6oQmvM0piUxDXu9cJU00y8Ah0FnDeP 83PzqVeOWJBdBXcMHIfI9YZzqTjpjXteLGQJW34HpiNAjodFcxSOqr3sRp6kAUWxWBgU E8v96lhsfo8uz3B9C1ywHC3Kgg2UnqxZFydVGgsT8t+CDFaF76aFA+G1XIyw4JrEgPqE Cp5AjV8ZeEgGc1bABRneNKM9Xy2UNCH7aq0J6V3LVIjxJSSSmulQNSRimoBsE3LDjZxg jRnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=aB8kwe4MCaWs6fQf1wJvIS4sD6K4qPPRJRJMHMGczQ0=; b=VBSTXNlk0kzTZe7Pp+TFmV6Wzvn9Fswme32WK+LTHSD8I7NhSgNnA+osNdSBXNMhro lYjUAV0l2EoFfK4rPKuw2VKE0MEvDtiKhxsAXnZPk2mJ79JmwHJ3cmTHm/fr6lNDtn9x GUYDSfSK4uLP041l9Xb2rPgApJ6dVHoGPgX7ac0MI4Ec5mcdCwuWebnyjILsJFbcJ8R7 lLwlIiwswNG2ZA8g06iSyjaczo7ATFGJzUdoA+2dQmgI9kuR+GMjYktNrOmtvjpdiDSk CvmzBiqO2m9E3CSs6s1PBQZwWnNcccLDlCxA5xoSi5II+D7KQo4WmwXaILBxFjdEI57q YZLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R2HaYZob; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id z37si489855qtg.402.2017.09.07.15.58.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:58:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R2HaYZob; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5kh-0000fL-16 for patch@linaro.org; Thu, 07 Sep 2017 18:58:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5UJ-0003IV-N4 for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5UE-0008Qr-Rp for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:31 -0400 Received: from mail-pf0-x22b.google.com ([2607:f8b0:400e:c00::22b]:35371) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5UE-0008Q0-LJ for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:26 -0400 Received: by mail-pf0-x22b.google.com with SMTP id g13so1630258pfm.2 for ; Thu, 07 Sep 2017 15:41:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aB8kwe4MCaWs6fQf1wJvIS4sD6K4qPPRJRJMHMGczQ0=; b=R2HaYZob2j7TcxBAlIpSlXx8Kgtdoy98AIB5khS83uFP8X3JE3mtZvYmxSIQGZEPxi m/QRbnjfjc7z1SQlJM1wRBu6xXdw3fgQc235D2yLxDmk+59EAcAxnyGevEaR+q1i17l+ L+SxVtFDQcdFrzMiZKqNjkslnvRHD9nYE8JJ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aB8kwe4MCaWs6fQf1wJvIS4sD6K4qPPRJRJMHMGczQ0=; b=Q13jB7SANqVdtOlfQV+XJhe0eFBjoZKIASVBCSsPUZXI8wbBP5XlYVYEidxzyLRNOR MRpUzrjBD+GGwyNytrOJWunYKyzhcaqj4FhJCiPX20f+4awJ7rtyVu3tVjp/r5t6dKtn 4n+ilPBZafTNEEdBPX+AYy0Qm2HX0TjcFMznRQ0hx1XxPJozpdCSTNB8DqgQEEVmR85A hB11bQrPb2pmRlkKgMUs/3DMIxtlsu3xtVogk6WzST87Z7gKAyIoFFjRjZ9ZF7E7/Wyl livLZsLe0qwbeo6QKypnOUDffdHDrW/SuBZjII8NZtplY1tFJrTwCS7v6qFPg86XE8cd yx3w== X-Gm-Message-State: AHPjjUheC1gi6pB6xCmhPvtCpn/Vvqy7mar8to8Xf1WbfKsH8CXrD5Hk I4GDBgWqCel0xig84aQILg== X-Google-Smtp-Source: ADKCNb4IjyZ6qzEkrv5Am0lcbFsUmMPfmCXgYDRbVNINnjJwuCwsSdkU4t1R1o3a65FOkQh9E2QVsA== X-Received: by 10.84.217.14 with SMTP id o14mr1080148pli.20.1504824085356; Thu, 07 Sep 2017 15:41:25 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:50 -0700 Message-Id: <20170907224051.21518-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22b Subject: [Qemu-devel] [PULL 22/23] tcg/ppc: Look for shifted constants X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/ppc/tcg-target.inc.c | 58 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 10 deletions(-) -- 2.13.5 diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c index bc14d2c9c6..df709c4a96 100644 --- a/tcg/ppc/tcg-target.inc.c +++ b/tcg/ppc/tcg-target.inc.c @@ -593,11 +593,26 @@ static inline void tcg_out_shri64(TCGContext *s, TCGReg dst, TCGReg src, int c) tcg_out_rld(s, RLDICL, dst, src, 64 - c, c); } +/* Emit a move into ret of arg, if it can be done in one insn. */ +static bool tcg_out_movi_one(TCGContext *s, TCGReg ret, tcg_target_long arg) +{ + if (arg == (int16_t)arg) { + tcg_out32(s, ADDI | TAI(ret, 0, arg)); + return true; + } + if (arg == (int32_t)arg && (arg & 0xffff) == 0) { + tcg_out32(s, ADDIS | TAI(ret, 0, arg >> 16)); + return true; + } + return false; +} + static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, tcg_target_long arg, bool in_prologue) { intptr_t tb_diff; - int32_t high; + tcg_target_long tmp; + int shift; tcg_debug_assert(TCG_TARGET_REG_BITS == 64 || type == TCG_TYPE_I32); @@ -606,8 +621,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, } /* Load 16-bit immediates with one insn. */ - if (arg == (int16_t)arg) { - tcg_out32(s, ADDI | TAI(ret, 0, arg)); + if (tcg_out_movi_one(s, ret, arg)) { return; } @@ -618,12 +632,11 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, return; } - /* Load 32-bit immediates with two insns. */ + /* Load 32-bit immediates with two insns. Note that we've already + eliminated bare ADDIS, so we know both insns are required. */ if (TCG_TARGET_REG_BITS == 32 || arg == (int32_t)arg) { tcg_out32(s, ADDIS | TAI(ret, 0, arg >> 16)); - if (arg & 0xffff) { - tcg_out32(s, ORI | SAI(ret, ret, arg)); - } + tcg_out32(s, ORI | SAI(ret, ret, arg)); return; } if (arg == (uint32_t)arg && !(arg & 0x8000)) { @@ -632,15 +645,40 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, return; } + /* Load masked 16-bit value. */ + if (arg > 0 && (arg & 0x8000)) { + tmp = arg | 0x7fff; + if ((tmp & (tmp + 1)) == 0) { + int mb = clz64(tmp + 1) + 1; + tcg_out32(s, ADDI | TAI(ret, 0, arg)); + tcg_out_rld(s, RLDICL, ret, ret, 0, mb); + return; + } + } + + /* Load common masks with 2 insns. */ + shift = ctz64(arg); + tmp = arg >> shift; + if (tmp == (int16_t)tmp) { + tcg_out32(s, ADDI | TAI(ret, 0, tmp)); + tcg_out_shli64(s, ret, ret, shift); + return; + } + shift = clz64(arg); + if (tcg_out_movi_one(s, ret, arg << shift)) { + tcg_out_shri64(s, ret, ret, shift); + return; + } + /* Load addresses within 2GB of TB with 2 (or rarely 3) insns. */ if (!in_prologue && USE_REG_TB && tb_diff == (int32_t)tb_diff) { tcg_out_mem_long(s, ADDI, ADD, ret, TCG_REG_TB, tb_diff); return; } - high = arg >> 31 >> 1; - tcg_out_movi(s, TCG_TYPE_I32, ret, high); - if (high) { + tmp = arg >> 31 >> 1; + tcg_out_movi(s, TCG_TYPE_I32, ret, tmp); + if (tmp) { tcg_out_shli64(s, ret, ret, 32); } if (arg & 0xffff0000) { From patchwork Thu Sep 7 22:40:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111989 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp765986ybm; Thu, 7 Sep 2017 15:54:12 -0700 (PDT) X-Received: by 10.55.201.5 with SMTP id q5mr1239686qki.31.1504824852746; Thu, 07 Sep 2017 15:54:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824852; cv=none; d=google.com; s=arc-20160816; b=GD222M0L/RopIqvR/FEK9MgTilz9mwAMz7qsPA+b+imrlex8+Orhytj1hWpWJvL5oj tBqfiWubNBsYG5/zEpwrCFnaSdxV0aK6SFGYpwB68U4PGUlFTQA5XvAIUXGbcmHlnu5N iGgkY73CAM10TBUWg6OaztYNqzNOh0H9LuQlAz4HVqTo9w5MEOmA37i7kc+NdrP4vuRh 5b/oBSERwWM9UZMkh64ms+DKly1BlMO9NguzchRPyKAtbEzTX/gp70PivfmjKncEg4yp KX5z8OCwKUrQRi6MIinate8Jg5wP/pj/QENLkmngYvAKqWzeG1N0ed+vvj4gscX9lki1 sqvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=H+LLtzCzH8QndIjCRi1FVfoNlieFGUHJ+Q0JqTEk1F0=; b=d0/5PHIktdyndFozSZNnrobhQYIlpvvAu8UoKdhlv02idNFbqnIGkaTED4XiIJ86Aj w3fFoJr01XjnEhyp8s/I30jlwOa4wgOek/1L8mJYwyLxWIkzPjHhLqdxL78fsgUoKBVo PKCH+ej/gEqDW9ofhSK29z7KanvWxaSPuBkll0zWHBCSKvubmXQLZ6wajQC8GZm2+9Ta 4IvwAs/Y5XkxK188AIJxGHkj4Ah4FRWaNZd1Vw7TYRM10xhHSrUtt+n0aHPTrd9mzVBr vnUHsadea1fQ/DpmKRpECXxzoPEeJ0yn0aMwdpvsO+Yr5SE1Ve9+/XscDNh8XxthrgPM 6yTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KMfepWU1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x90si529619qtd.515.2017.09.07.15.54.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:54:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KMfepWU1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42567 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5gY-0005X3-Nj for patch@linaro.org; Thu, 07 Sep 2017 18:54:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5UK-0003JO-NQ for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5UG-0008TD-3w for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:32 -0400 Received: from mail-pf0-x22e.google.com ([2607:f8b0:400e:c00::22e]:35371) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5UF-0008RY-Ug for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:28 -0400 Received: by mail-pf0-x22e.google.com with SMTP id g13so1630320pfm.2 for ; Thu, 07 Sep 2017 15:41:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=H+LLtzCzH8QndIjCRi1FVfoNlieFGUHJ+Q0JqTEk1F0=; b=KMfepWU1BTFsCzpiWSnTJDsNNF9XY8dKxpBTharm/iIT8MtltxGTkj65GxVIjyp2Mi UulfwoC3NDp8NeO+BwTl7oahTZ0ZrB8jDuglZ/28r+hOnu1jxZ77Lx+2DdAegF0AJhOy UlbyISnU8+SsH2VFZDfdlkpofR3XGk60wm5wM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=H+LLtzCzH8QndIjCRi1FVfoNlieFGUHJ+Q0JqTEk1F0=; b=Wv39fhSxtgf4ti3wo0E/ZOvpXiVc8IHRs489cvOMsHHyMxqWGiwem1zRY4QZxTDJRx oXfDNYR1D+tIhLzGXjVvPS/nY5NhXt5Em/PjYJWQ2eNkH95+bu0bUglks/Gnh2QUOSnt CYprO4OEAzGpUyQe+V6gCVwsEslQJ2S2fTyBBzW3zPhR9m0pukOgULyl3LA88cSQEtHe q3LUQokD0UxOsaAZnsLYudJjqheaZ+ZsvlbyPANJOKwFYylwdxdqnjviLB/7WE2ogif/ QiXlJJ18DktlFpdHL4I9OwuY21O2RbnINzw/nq90yI/XuU1oFjkjqcekBUVSCy0D53Am A6qQ== X-Gm-Message-State: AHPjjUiVV6P/JMXcLytgcDB8fdjlUbO0f4TelamjsG2MfNMFieY9p96e c1RFpyn7NeB37+VOzq8zUA== X-Google-Smtp-Source: ADKCNb580RProykv/FtOjQxwThKgfLAMc9hggbh/lJjN2aIJe2BcNjzz7mlm8RCzdsxi2b79CxpXMA== X-Received: by 10.99.130.198 with SMTP id w189mr919111pgd.175.1504824086701; Thu, 07 Sep 2017 15:41:26 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:51 -0700 Message-Id: <20170907224051.21518-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22e Subject: [Qemu-devel] [PULL 23/23] tcg/ppc: Use constant pool for movi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/ppc/tcg-target.h | 1 + tcg/ppc/tcg-target.inc.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) -- 2.13.5 diff --git a/tcg/ppc/tcg-target.h b/tcg/ppc/tcg-target.h index 3772cc6648..be52ad1d2e 100644 --- a/tcg/ppc/tcg-target.h +++ b/tcg/ppc/tcg-target.h @@ -132,5 +132,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS #endif +#define TCG_TARGET_NEED_POOL_LABELS #endif diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c index df709c4a96..21d764c102 100644 --- a/tcg/ppc/tcg-target.inc.c +++ b/tcg/ppc/tcg-target.inc.c @@ -22,6 +22,9 @@ * THE SOFTWARE. */ +#include "elf.h" +#include "tcg-pool.inc.c" + #if defined _CALL_DARWIN || defined __APPLE__ #define TCG_TARGET_CALL_DARWIN #endif @@ -58,8 +61,6 @@ static tcg_insn_unit *tb_ret_addr; -#include "elf.h" - bool have_isa_2_06; bool have_isa_3_00; @@ -224,9 +225,12 @@ static inline void tcg_out_bc_noaddr(TCGContext *s, int insn) static void patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) { - tcg_insn_unit *target = (tcg_insn_unit *)value; + tcg_insn_unit *target; + tcg_insn_unit old; + + value += addend; + target = (tcg_insn_unit *)value; - tcg_debug_assert(addend == 0); switch (type) { case R_PPC_REL14: reloc_pc14(code_ptr, target); @@ -234,6 +238,12 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type, case R_PPC_REL24: reloc_pc24(code_ptr, target); break; + case R_PPC_ADDR16: + assert(value == (int16_t)value); + old = *code_ptr; + old = deposit32(old, 0, 16, value); + *code_ptr = old; + break; default: tcg_abort(); } @@ -676,6 +686,14 @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret, return; } + /* Use the constant pool, if possible. */ + if (!in_prologue && USE_REG_TB) { + new_pool_label(s, arg, R_PPC_ADDR16, s->code_ptr, + -(intptr_t)s->code_gen_ptr); + tcg_out32(s, LD | TAI(ret, TCG_REG_TB, 0)); + return; + } + tmp = arg >> 31 >> 1; tcg_out_movi(s, TCG_TYPE_I32, ret, tmp); if (tmp) { @@ -1858,6 +1876,14 @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64) #endif } +static void tcg_out_nop_fill(tcg_insn_unit *p, int count) +{ + int i; + for (i = 0; i < count; ++i) { + p[i] = NOP; + } +} + /* Parameters for function call generation, used in tcg.c. */ #define TCG_TARGET_STACK_ALIGN 16 #define TCG_TARGET_EXTEND_ARGS 1