From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824196684672.3842247008644; Thu, 7 Sep 2017 15:43:16 -0700 (PDT) Received: from localhost ([::1]:42520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Vz-0004XN-Hr for importer@patchew.org; Thu, 07 Sep 2017 18:43:15 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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(AddressSpac= e *as, hwaddr addr) #define CODE_GEN_AVG_BLOCK_SIZE 150 #endif =20 -#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 =3D 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 =3D 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] =3D 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] =3D tb_next->jmp_list_first; - tb_next->jmp_list_first =3D (uintptr_t)tb | n; -} +void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr); =20 /* 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) =20 static inline void flush_icache_range(uintptr_t start, uintptr_t stop) { __builtin___clear_cache((char *)start, (char *)stop); } =20 -#define TCG_TARGET_DEFAULT_MO (0) +void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); =20 #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 =20 enum { TCG_AREG0 =3D TCG_REG_R6, }; =20 +#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); } =20 -#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); =20 #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 =20 #if TCG_TARGET_REG_BITS =3D=3D 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) { } =20 +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 =20 #if TCG_TARGET_REG_BITS =3D=3D 64 #define TCG_TARGET_HAS_add2_i32 0 @@ -201,11 +202,13 @@ extern bool use_mips32r2_instructions; #include #endif =20 +#define TCG_TARGET_DEFAULT_MO (0) + static inline void flush_icache_range(uintptr_t start, uintptr_t stop) { cacheflush ((void *)start, stop-start, ICACHE); } =20 -#define TCG_TARGET_DEFAULT_MO (0) +void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); =20 #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 =20 #if TCG_TARGET_REG_BITS =3D=3D 64 #define TCG_TARGET_HAS_add2_i32 0 @@ -124,6 +125,7 @@ extern bool have_isa_3_00; #endif =20 void flush_icache_range(uintptr_t start, uintptr_t stop); +void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); =20 #define TCG_TARGET_DEFAULT_MO (0) =20 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 =20 #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) { } =20 +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 =3D 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 =20 #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) } } =20 +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_JUM= P */ - uintptr_t *tb_jmp_target_addr; /* tb->jmp_target_addr if !USE_DIRECT_J= UMP */ + 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 */ =20 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 =20 #if TCG_TARGET_REG_BITS =3D=3D 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) =20 +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, targ= et_ulong pc, return qht_lookup(&tcg_ctx.tb_ctx.htable, tb_cmp, &desc, h); } =20 +void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr) +{ + if (TCG_TARGET_HAS_direct_jump) { + uintptr_t offset =3D tb->jmp_target_arg[n]; + uintptr_t tc_ptr =3D (uintptr_t)tb->tc_ptr; + tb_target_set_jmp_target(tc_ptr, tc_ptr + offset, addr); + } else { + tb->jmp_target_arg[n] =3D 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] =3D tb_next->jmp_list_first; + tb_next->jmp_list_first =3D (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] =3D TB_JMP_RESET_OFFSET_INVALID; tb->jmp_reset_offset[1] =3D TB_JMP_RESET_OFFSET_INVALID; tcg_ctx.tb_jmp_reset_offset =3D tb->jmp_reset_offset; -#ifdef USE_DIRECT_JUMP - tcg_ctx.tb_jmp_insn_offset =3D tb->jmp_insn_offset; - tcg_ctx.tb_jmp_target_addr =3D NULL; -#else - tcg_ctx.tb_jmp_insn_offset =3D NULL; - tcg_ctx.tb_jmp_target_addr =3D tb->jmp_target_addr; -#endif + if (TCG_TARGET_HAS_direct_jump) { + tcg_ctx.tb_jmp_insn_offset =3D tb->jmp_target_arg; + tcg_ctx.tb_jmp_target_addr =3D NULL; + } else { + tcg_ctx.tb_jmp_insn_offset =3D NULL; + tcg_ctx.tb_jmp_target_addr =3D tb->jmp_target_arg; + } =20 #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) } } =20 -#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 =3D TCG_TYPE_I64; @@ -898,8 +897,6 @@ void aarch64_tb_set_jmp_target(uintptr_t jmp_addr, uint= ptr_t addr) flush_icache_range(jmp_addr, jmp_addr + 8); } =20 -#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, =20 case INDEX_op_goto_tb: if (s->tb_jmp_insn_offset !=3D 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] =3D 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 !=3D NULL); intptr_t offset =3D 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 = */ } =20 -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) } =20 #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, uintpt= r_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 =3D 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)); } =20 -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 =3D (uint32_t *)jmp_addr; uintptr_t disp =3D addr - jmp_addr; --=20 2.13.5 From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824346680169.69704666122152; Thu, 7 Sep 2017 15:45:46 -0700 (PDT) Received: from localhost ([::1]:42533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5YP-0006hb-Fc for importer@patchew.org; Thu, 07 Sep 2017 18:45:45 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 =3D> 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 =3D> tcg-ldst.inc.c} (85%) 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) =20 void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); =20 +#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); =20 +#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 t= c_ptr, =20 #define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD) =20 +#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) =20 void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); =20 +#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, uin= tptr_t); =20 #define TCG_TARGET_DEFAULT_MO (0) =20 +#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 t= c_ptr, /* no need to flush icache explicitly */ } =20 +#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"), t= o deal - * in the Software without restriction, including without limitation the r= ights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll - * 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 OT= HER - * 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 */ =20 - /* 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 =20 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 t= c_ptr, /* no need to flush icache explicitly */ } =20 +#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. */ =20 -#include "tcg-be-ldst.h" #include "qemu/bitops.h" =20 /* 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, } =20 #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 @@ */ =20 #include "elf.h" -#include "tcg-be-ldst.h" =20 int arm_arch =3D __ARM_ARCH; =20 @@ -1060,6 +1059,8 @@ static inline void tcg_out_mb(TCGContext *s, TCGArg a= 0) } =20 #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. */ =20 -#include "tcg-be-ldst.h" - #ifdef CONFIG_DEBUG_TCG static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] =3D { #if TCG_TARGET_REG_BITS =3D=3D 64 @@ -1214,6 +1212,8 @@ static void tcg_out_nopn(TCGContext *s, int n) } =20 #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. */ =20 -#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) } =20 #if defined(CONFIG_SOFTMMU) +#include "tcg-ldst.inc.c" + static void * const qemu_ld_helpers[16] =3D { [MO_UB] =3D helper_ret_ldub_mmu, [MO_SB] =3D 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. */ =20 -#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] =3D { }; =20 #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. */ =20 -#include "tcg-be-ldst.h" - /* We only support generating code for 64-bit mode. */ #if TCG_TARGET_REG_BITS !=3D 64 #error "unsupported code generation mode" @@ -1458,6 +1456,8 @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCG= MemOp opc, TCGReg data, } =20 #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. */ =20 -#include "tcg-be-null.h" - #ifdef CONFIG_DEBUG_TCG static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] =3D { "%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. */ =20 -#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; =20 -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 =3D NULL; -} =20 /* * 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); =20 -static bool tcg_out_tb_finalize(TCGContext *s) +static bool tcg_out_ldst_finalize(TCGContext *s) { TCGLabelQemuLdst *lb; =20 /* qemu_ld/st slow paths */ - for (lb =3D s->be->labels; lb !=3D NULL; lb =3D lb->next) { + for (lb =3D s->ldst_labels; lb !=3D NULL; lb =3D 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) =20 static inline TCGLabelQemuLdst *new_ldst_label(TCGContext *s) { - TCGBackendData *be =3D s->be; TCGLabelQemuLdst *l =3D tcg_malloc(sizeof(*l)); =20 - l->next =3D be->labels; - be->labels =3D l; + l->next =3D s->ldst_labels; + s->ldst_labels =3D 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, T= CGArg 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 =20 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 =3D 0; s->gen_next_op_idx =3D 1; s->gen_next_parm_idx =3D 0; - - s->be =3D tcg_malloc(sizeof(TCGBackendData)); } =20 static inline int temp_idx(TCGContext *s, TCGTemp *ts) @@ -2619,7 +2616,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) s->code_buf =3D tb->tc_ptr; s->code_ptr =3D tb->tc_ptr; =20 - tcg_out_tb_init(s); +#ifdef TCG_TARGET_NEED_LDST_LABELS + s->ldst_labels =3D NULL; +#endif =20 num_insns =3D -1; for (oi =3D s->gen_op_buf[0].next; oi !=3D 0; oi =3D oi_next) { @@ -2694,9 +2693,11 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) s->gen_insn_end_off[num_insns] =3D tcg_current_code_size(s); =20 /* 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 =20 /* 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. */ =20 -#include "tcg-be-null.h" - /* TODO list: * - See TODO comments in code. */ --=20 2.13.5 From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824364119899.1372287685347; Thu, 7 Sep 2017 15:46:04 -0700 (PDT) Received: from localhost ([::1]:42534 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Yg-0006xB-Sa for importer@patchew.org; Thu, 07 Sep 2017 18:46:02 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 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; =20 /* 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 =20 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=3D%d]\n", gen_code_size); - log_disas(tb->tc_ptr, gen_code_size); + if (tcg_ctx.data_gen_ptr) { + size_t code_size =3D tcg_ctx.data_gen_ptr - tb->tc_ptr; + size_t data_size =3D gen_code_size - code_size; + size_t i; + + log_disas(tb->tc_ptr, code_size); + + for (i =3D 0; i < data_size; i +=3D sizeof(tcg_target_ulong)) { + if (sizeof(tcg_target_ulong) =3D=3D 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"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * 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 OT= HER + * 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 =3D tcg_malloc(sizeof(*n)); + TCGLabelPoolData *i, **pp; + + n->data =3D data; + n->label =3D label; + n->type =3D type; + n->addend =3D addend; + + /* Insertion sort on the pool. */ + for (pp =3D &s->pool_labels; (i =3D *pp) && i->data < data; pp =3D &i-= >next) { + continue; + } + n->next =3D *pp; + *pp =3D 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 =3D s->pool_labels; + tcg_target_ulong d, *a; + + if (p =3D=3D NULL) { + return true; + } + + /* ??? Round up to qemu_icache_linesize, but then do not round + again when allocating the next TranslationBlock structure. */ + a =3D (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 =3D a; + + /* Ensure the first comparison fails. */ + d =3D p->data + 1; + + for (; p !=3D NULL; p =3D p->next) { + if (p->data !=3D d) { + d =3D p->data; + if (unlikely((void *)a > s->code_gen_highwater)) { + return false; + } + *a++ =3D d; + } + patch_reloc(p->label, p->type, (intptr_t)(a - 1), p->addend); + } + + s->code_ptr =3D (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 =3D next; + s->data_gen_ptr =3D NULL; return tb; } =20 @@ -2619,6 +2620,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) #ifdef TCG_TARGET_NEED_LDST_LABELS s->ldst_labels =3D NULL; #endif +#ifdef TCG_TARGET_NEED_POOL_LABELS + s->pool_labels =3D NULL; +#endif =20 num_insns =3D -1; for (oi =3D s->gen_op_buf[0].next; oi !=3D 0; oi =3D 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 =20 /* flush instruction cache */ flush_icache_range((uintptr_t)s->code_buf, (uintptr_t)s->code_ptr); --=20 2.13.5 From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824572379723.1648802130325; Thu, 7 Sep 2017 15:49:32 -0700 (PDT) Received: from localhost ([::1]:42544 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5c3-0001Tq-CF for importer@patchew.org; Thu, 07 Sep 2017 18:49:31 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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 t= c_ptr, #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS #endif +#define TCG_TARGET_NEED_POOL_LABELS =20 #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. */ =20 +#include "tcg-pool.inc.c" + #ifdef CONFIG_DEBUG_TCG static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] =3D { #if TCG_TARGET_REG_BITS =3D=3D 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 =3D 14 bytes, as compared to using an + an immediate load 10 + 6 =3D 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); } } =20 @@ -2595,6 +2602,11 @@ static void tcg_target_qemu_prologue(TCGContext *s) #endif } =20 +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 --=20 2.13.5 From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824200892962.5255791374216; Thu, 7 Sep 2017 15:43:20 -0700 (PDT) Received: from localhost ([::1]:42521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5W3-0004c8-LO for importer@patchew.org; Thu, 07 Sep 2017 18:43:19 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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) =20 #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 =20 +/* 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, TC= GReg dst, TCGReg src) } =20 /* 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] =3D { RI_LLILL, RI_LLILH, RI_LLIHL, RI_LLIHH @@ -601,13 +607,22 @@ static void tcg_out_movi(TCGContext *s, TCGType type, } } =20 - /* 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) =3D=3D 0) { ptrdiff_t off =3D tcg_pcrel_diff(s, (void *)sval) >> 1; if (off =3D=3D (int32_t)off) { tcg_out_insn(s, RIL, LARL, ret, off); return; } + } else if (USE_REG_TB && !in_prologue) { + ptrdiff_t off =3D sval - (uintptr_t)s->code_gen_ptr; + if (off =3D=3D 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; + } } =20 /* 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, } } =20 +static void tcg_out_movi(TCGContext *s, TCGType type, + TCGReg ret, tcg_target_long sval) +{ + tcg_out_movi_int(s, type, ret, sval, false); +} =20 /* 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 =3D abs - (void *)s->code_gen_ptr; + if (disp =3D=3D sextract64(disp, 0, 20)) { + tcg_out_ld(s, type, dest, TCG_REG_TB, disp); + return; + } + } =20 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, TCGOpcod= e opc, break; =20 case INDEX_op_goto_tb: + a0 =3D 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, TCGOpc= ode 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]] =3D tcg_current_code_size(s); + s->tb_jmp_insn_offset[a0] =3D tcg_current_code_size(s); s->code_ptr +=3D 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] =3D 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 =3D -tcg_current_code_size(s); + assert(ofs =3D=3D (int16_t)ofs); + tcg_out_insn(s, RI, AGHI, TCG_REG_TB, ofs); } - s->tb_jmp_reset_offset[args[0]] =3D tcg_current_code_size(s); break; =20 case INDEX_op_goto_ptr: - tcg_out_insn(s, RR, BCR, S390_CC_ALWAYS, args[0]); + a0 =3D 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; =20 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); + } } =20 #define FRAME_SIZE ((int)(TCG_TARGET_CALL_STACK_OFFSET \ @@ -2496,12 +2540,17 @@ static void tcg_target_qemu_prologue(TCGContext *s) =20 #ifndef CONFIG_SOFTMMU if (guest_base >=3D 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 =20 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]); =20 --=20 2.13.5 From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824702951518.8121681732998; Thu, 7 Sep 2017 15:51:42 -0700 (PDT) Received: from localhost ([::1]:42556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5e9-0003Jv-UR for importer@patchew.org; Thu, 07 Sep 2017 18:51:41 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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 =3D (tcg_insn_unit *)value - (code_ptr - 1); - tcg_debug_assert(addend =3D=3D -2); + intptr_t pcrel2; + + value +=3D addend; + pcrel2 =3D (tcg_insn_unit *)value - code_ptr; =20 switch (type) { case R_390_PC16DBL: - tcg_debug_assert(pcrel2 =3D=3D (int16_t)pcrel2); + assert(pcrel2 =3D=3D (int16_t)pcrel2); tcg_patch16(code_ptr, pcrel2); break; case R_390_PC32DBL: - tcg_debug_assert(pcrel2 =3D=3D (int32_t)pcrel2); + assert(pcrel2 =3D=3D (int32_t)pcrel2); tcg_patch32(code_ptr, pcrel2); break; default: - tcg_abort(); - break; + g_assert_not_reached(); } } =20 @@ -1270,11 +1271,11 @@ static void tgen_branch(TCGContext *s, int cc, TCGL= abel *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 +=3D 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 +=3D 1; } } @@ -1289,7 +1290,7 @@ static void tgen_compare_branch(TCGContext *s, S390Op= code opc, int cc, } else { /* We need to keep the offset unchanged for retranslation. */ off =3D 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); } =20 tcg_out16(s, (opc & 0xff00) | (r1 << 4) | r2); @@ -1307,7 +1308,7 @@ static void tgen_compare_imm_branch(TCGContext *s, S3= 90Opcode opc, int cc, } else { /* We need to keep the offset unchanged for retranslation. */ off =3D 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); } =20 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 =3D lb->oi; TCGMemOp opc =3D get_memop(oi); =20 - 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); =20 tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_R2, TCG_AREG0); if (TARGET_LONG_BITS =3D=3D 64) { @@ -1592,7 +1593,7 @@ static void tcg_out_qemu_st_slow_path(TCGContext *s, = TCGLabelQemuLdst *lb) TCGMemOpIdx oi =3D lb->oi; TCGMemOp opc =3D get_memop(oi); =20 - 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); =20 tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_R2, TCG_AREG0); if (TARGET_LONG_BITS =3D=3D 64) { --=20 2.13.5 From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824366042286.5852356868518; Thu, 7 Sep 2017 15:46:06 -0700 (PDT) Received: from localhost ([::1]:42535 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Yi-0006xu-SY for importer@patchew.org; Thu, 07 Sep 2017 18:46:04 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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 =20 /* 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 t= c_ptr, #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS #endif +#define TCG_TARGET_NEED_POOL_LABELS =20 #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 =20 +#include "tcg-pool.inc.c" #include "elf.h" =20 /* ??? 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 ty= pe, intptr_t value, intptr_t addend) { intptr_t pcrel2; + uint32_t old; =20 value +=3D addend; pcrel2 =3D (tcg_insn_unit *)value - code_ptr; @@ -374,6 +376,12 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int t= ype, assert(pcrel2 =3D=3D (int32_t)pcrel2); tcg_patch32(code_ptr, pcrel2); break; + case R_390_20: + assert(value =3D=3D sextract64(value, 0, 20)); + old =3D *(uint32_t *)code_ptr & 0xf00000ff; + old |=3D ((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) } } =20 -/* 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] =3D { - RI_LLILL, RI_LLILH, RI_LLIHL, RI_LLIHH - }; +static const S390Opcode lli_insns[4] =3D { + RI_LLILL, RI_LLILH, RI_LLIHL, RI_LLIHH +}; +static const S390Opcode ii_insns[4] =3D { + RI_IILL, RI_IILH, RI_IIHL, RI_IIHH +}; =20 +static bool maybe_out_small_movi(TCGContext *s, TCGType type, + TCGReg ret, tcg_target_long sval) +{ tcg_target_ulong uval =3D sval; int i; =20 @@ -581,17 +591,37 @@ static void tcg_out_movi_int(TCGContext *s, TCGType t= ype, TCGReg ret, /* Try all 32-bit insns that can load it in one go. */ if (sval >=3D -0x8000 && sval < 0x8000) { tcg_out_insn(s, RI, LGHI, ret, sval); - return; + return true; } =20 for (i =3D 0; i < 4; i++) { tcg_target_long mask =3D 0xffffull << i*16; if ((uval & mask) =3D=3D uval) { tcg_out_insn_RI(s, lli_insns[i], ret, uval >> i*16); - return; + return true; } } =20 + 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 =3D sval; + if (type =3D=3D TCG_TYPE_I32) { + uval =3D (uint32_t)sval; + sval =3D (int32_t)sval; + } + /* Try all 48-bit insns that can load it in one go. */ if (s390_facilities & FACILITY_EXT_IMM) { if (sval =3D=3D (int32_t)sval) { @@ -603,7 +633,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType typ= e, TCGReg ret, return; } if ((uval & 0xffffffff) =3D=3D 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 t= ype, TCGReg ret, } } =20 - /* 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 <=3D 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 <=3D 0xffffffff) { + tcg_out_insn(s, RI, LLILL, ret, uval); + tcg_out_insn(s, RI, IILH, ret, uval >> 16); + return; + } =20 - /* If all high bits are set, the value can be loaded in 2 or 3 ins= ns. - 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 =3D=3D -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; } =20 - /* 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 =3D 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) =3D=3D 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 =3D lli_insns; + int i; + + for (i =3D 0; i < 4; i++) { + uint16_t part =3D uval >> (16 * i); + if (part) { + tcg_out_insn_RI(s, insns[i], ret, part); + insns =3D 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); } =20 +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]; --=20 2.13.5 From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824516934555.4678406265224; Thu, 7 Sep 2017 15:48:36 -0700 (PDT) Received: from localhost ([::1]:42543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5b9-0000r2-Qn for importer@patchew.org; Thu, 07 Sep 2017 18:48:35 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/s390/tcg-target.inc.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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 =3D 0xe30f, RXY_LRVH =3D 0xe31f, RXY_LY =3D 0xe358, + RXY_NG =3D 0xe380, RXY_STCY =3D 0xe372, RXY_STG =3D 0xe324, RXY_STHY =3D 0xe370, @@ -985,8 +986,17 @@ static void tgen_andi(TCGContext *s, TCGType type, TCG= Reg dest, uint64_t val) return; } =20 - /* 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 =3D=3D TCG_TYPE_I32) { tcg_out_insn(s, RR, NR, dest, TCG_TMP0); } else { @@ -2341,6 +2351,8 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpc= ode 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_r= i); =20 case INDEX_op_mul_i32: @@ -2375,10 +2387,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOp= code op) ? (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_rM : &r_= 0_rM) : &r_0_r); =20 - case INDEX_op_and_i32: - case INDEX_op_and_i64: - return (s390_facilities & FACILITY_DISTINCT_OPS ? &r_r_ri : &r_0_r= i); - case INDEX_op_shl_i32: case INDEX_op_shr_i32: case INDEX_op_sar_i32: --=20 2.13.5 From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824837524699.7791099395963; Thu, 7 Sep 2017 15:53:57 -0700 (PDT) Received: from localhost ([::1]:42563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5gK-0005IS-8k for importer@patchew.org; Thu, 07 Sep 2017 18:53:56 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/s390/tcg-target.inc.c | 74 ++++++++++++++++++++++---------------------= ---- 1 file changed, 34 insertions(+), 40 deletions(-) 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 =3D 0xe31f, RXY_LY =3D 0xe358, RXY_NG =3D 0xe380, + RXY_OG =3D 0xe381, RXY_STCY =3D 0xe372, RXY_STG =3D 0xe324, RXY_STHY =3D 0xe370, @@ -1004,55 +1005,60 @@ static void tgen_andi(TCGContext *s, TCGType type, = TCGReg dest, uint64_t val) } } =20 -static void tgen64_ori(TCGContext *s, TCGReg dest, tcg_target_ulong val) +static void tgen_ori(TCGContext *s, TCGType type, TCGReg dest, uint64_t va= l) { static const S390Opcode oi_insns[4] =3D { RI_OILL, RI_OILH, RI_OIHL, RI_OIHH }; - static const S390Opcode nif_insns[2] =3D { + static const S390Opcode oif_insns[2] =3D { RIL_OILF, RIL_OIHF }; =20 int i; =20 /* Look for no-op. */ - if (val =3D=3D 0) { + if (unlikely(val =3D=3D 0)) { return; } =20 - if (s390_facilities & FACILITY_EXT_IMM) { - /* Try all 32-bit insns that can perform it in one go. */ - for (i =3D 0; i < 4; i++) { - tcg_target_ulong mask =3D (0xffffull << i*16); - if ((val & mask) !=3D 0 && (val & ~mask) =3D=3D 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 =3D 0; i < 4; i++) { + tcg_target_ulong mask =3D (0xffffull << i*16); + if ((val & mask) !=3D 0 && (val & ~mask) =3D=3D 0) { + tcg_out_insn_RI(s, oi_insns[i], dest, val >> i*16); + return; } + } =20 - /* 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 =3D 0; i < 2; i++) { tcg_target_ulong mask =3D (0xffffffffull << i*32); if ((val & mask) !=3D 0 && (val & ~mask) =3D=3D 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; } } + } =20 + /* 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 =3D=3D 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 =3D 0; i < 4; i++) { - tcg_target_ulong mask =3D (0xffffull << i*16); - if ((val & mask) !=3D 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); } } =20 @@ -1872,7 +1878,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcod= e opc, a0 =3D args[0], a1 =3D args[1], a2 =3D (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 =3D=3D a1) { tcg_out_insn(s, RR, OR, a0, a2); } else { @@ -2104,7 +2110,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcod= e opc, a0 =3D args[0], a1 =3D args[1], a2 =3D 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 =3D=3D a1) { tcg_out_insn(s, RRE, OGR, a0, a2); } else { @@ -2312,7 +2318,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpc= ode op) static const TCGTargetOpDef r_0_ri =3D { .args_ct_str =3D { "r", "0", = "ri" } }; static const TCGTargetOpDef r_0_rI =3D { .args_ct_str =3D { "r", "0", = "rI" } }; static const TCGTargetOpDef r_0_rJ =3D { .args_ct_str =3D { "r", "0", = "rJ" } }; - static const TCGTargetOpDef r_0_rN =3D { .args_ct_str =3D { "r", "0", = "rN" } }; static const TCGTargetOpDef r_0_rM =3D { .args_ct_str =3D { "r", "0", = "rM" } }; static const TCGTargetOpDef a2_r =3D { .args_ct_str =3D { "r", "r", "0", "1", "r", "r" } }; @@ -2353,6 +2358,8 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpc= ode 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_r= i); =20 case INDEX_op_mul_i32: @@ -2363,19 +2370,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOp= code op) case INDEX_op_mul_i64: return (s390_facilities & FACILITY_GEN_INST_EXT ? &r_0_rJ : &r_0_r= I); =20 - 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. */ --=20 2.13.5 From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824206811290.8356723418599; Thu, 7 Sep 2017 15:43:26 -0700 (PDT) Received: from localhost ([::1]:42522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5W9-0004hy-Kx for importer@patchew.org; Thu, 07 Sep 2017 18:43:25 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/s390/tcg-target.inc.c | 77 ++++++++++++++++++++++++-------------------= ---- 1 file changed, 40 insertions(+), 37 deletions(-) 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 @@ =20 #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 =20 /* Several places within the instruction set 0 means "no register" rather than TCG_REG_R0. */ @@ -234,6 +232,7 @@ typedef enum S390Opcode { RXY_STRVG =3D 0xe32f, RXY_STRVH =3D 0xe33f, RXY_STY =3D 0xe350, + RXY_XG =3D 0xe382, =20 RX_A =3D 0x5a, RX_C =3D 0x59, @@ -424,12 +423,6 @@ static const char *target_parse_constraint(TCGArgConst= raint *ct, case 'J': ct->ct |=3D TCG_CT_CONST_S32; break; - case 'N': - ct->ct |=3D TCG_CT_CONST_NN16; - break; - case 'M': - ct->ct |=3D 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 =3D=3D (int32_t)val; } else if (ct & TCG_CT_CONST_S33) { return val >=3D -0xffffffffll && val <=3D 0xffffffffll; - } else if (ct & TCG_CT_CONST_NN16) { - return !(val < 0 && val =3D=3D (int16_t)val); - } else if (ct & TCG_CT_CONST_NN32) { - return !(val < 0 && val =3D=3D (int32_t)val); } else if (ct & TCG_CT_CONST_U31) { return val >=3D 0 && val <=3D 0x7fffffff; } else if (ct & TCG_CT_CONST_ZERO) { @@ -1062,14 +1051,40 @@ static void tgen_ori(TCGContext *s, TCGType type, T= CGReg dest, uint64_t val) } } =20 -static void tgen64_xori(TCGContext *s, TCGReg dest, tcg_target_ulong val) +static void tgen_xori(TCGContext *s, TCGType type, TCGReg dest, uint64_t v= al) { - /* 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) =3D=3D 0) { + tcg_out_insn(s, RIL, XILF, dest, val); + return; + } + if ((val & 0x00000000ffffffffull) =3D=3D 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 =3D=3D 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); + } } } =20 @@ -1889,7 +1904,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcod= e opc, a0 =3D args[0], a1 =3D args[1], a2 =3D (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 =3D=3D a1) { tcg_out_insn(s, RR, XR, args[0], args[2]); } else { @@ -2121,7 +2136,7 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcod= e opc, a0 =3D args[0], a1 =3D args[1], a2 =3D 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 =3D=3D a1) { tcg_out_insn(s, RRE, XGR, a0, a2); } else { @@ -2313,12 +2328,9 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOp= code op) static const TCGTargetOpDef r_rC =3D { .args_ct_str =3D { "r", "rC" } = }; static const TCGTargetOpDef r_rZ =3D { .args_ct_str =3D { "r", "rZ" } = }; static const TCGTargetOpDef r_r_ri =3D { .args_ct_str =3D { "r", "r", = "ri" } }; - static const TCGTargetOpDef r_r_rM =3D { .args_ct_str =3D { "r", "r", = "rM" } }; - static const TCGTargetOpDef r_0_r =3D { .args_ct_str =3D { "r", "0", "= r" } }; static const TCGTargetOpDef r_0_ri =3D { .args_ct_str =3D { "r", "0", = "ri" } }; static const TCGTargetOpDef r_0_rI =3D { .args_ct_str =3D { "r", "0", = "rI" } }; static const TCGTargetOpDef r_0_rJ =3D { .args_ct_str =3D { "r", "0", = "rJ" } }; - static const TCGTargetOpDef r_0_rM =3D { .args_ct_str =3D { "r", "0", = "rM" } }; static const TCGTargetOpDef a2_r =3D { .args_ct_str =3D { "r", "r", "0", "1", "r", "r" } }; static const TCGTargetOpDef a2_ri @@ -2360,6 +2372,8 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpc= ode 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_r= i); =20 case INDEX_op_mul_i32: @@ -2370,17 +2384,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOp= code op) case INDEX_op_mul_i64: return (s390_facilities & FACILITY_GEN_INST_EXT ? &r_0_rJ : &r_0_r= I); =20 - 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: --=20 2.13.5 From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824502720793.1787840597191; Thu, 7 Sep 2017 15:48:22 -0700 (PDT) Received: from localhost ([::1]:42542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5av-0000ZD-Ax for importer@patchew.org; Thu, 07 Sep 2017 18:48:21 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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 @@ =20 #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 =20 /* Several places within the instruction set 0 means "no register" rather than TCG_REG_R0. */ @@ -75,6 +74,10 @@ typedef enum S390Opcode { RIL_CGFI =3D 0xc20c, RIL_CLFI =3D 0xc20f, RIL_CLGFI =3D 0xc20e, + RIL_CLRL =3D 0xc60f, + RIL_CLGRL =3D 0xc60a, + RIL_CRL =3D 0xc60d, + RIL_CGRL =3D 0xc608, RIL_IIHF =3D 0xc008, RIL_IILF =3D 0xc009, RIL_LARL =3D 0xc000, @@ -97,6 +100,8 @@ typedef enum S390Opcode { RI_AGHI =3D 0xa70b, RI_AHI =3D 0xa70a, RI_BRC =3D 0xa704, + RI_CHI =3D 0xa70e, + RI_CGHI =3D 0xa70f, RI_IIHH =3D 0xa500, RI_IIHL =3D 0xa501, RI_IILH =3D 0xa502, @@ -206,6 +211,8 @@ typedef enum S390Opcode { RXY_AG =3D 0xe308, RXY_AY =3D 0xe35a, RXY_CG =3D 0xe320, + RXY_CLG =3D 0xe321, + RXY_CLY =3D 0xe355, RXY_CY =3D 0xe359, RXY_LAY =3D 0xe371, RXY_LB =3D 0xe376, @@ -423,20 +430,6 @@ static const char *target_parse_constraint(TCGArgConst= raint *ct, case 'J': ct->ct |=3D 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 =3D=3D (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 |=3D TCG_CT_CONST_U31; - break; case 'Z': ct->ct |=3D TCG_CT_CONST_ZERO; break; @@ -467,8 +460,6 @@ static int tcg_target_const_match(tcg_target_long val, = TCGType type, return val =3D=3D (int32_t)val; } else if (ct & TCG_CT_CONST_S33) { return val >=3D -0xffffffffll && val <=3D 0xffffffffll; - } else if (ct & TCG_CT_CONST_U31) { - return val >=3D 0 && val <=3D 0x7fffffff; } else if (ct & TCG_CT_CONST_ZERO) { return val =3D=3D 0; } @@ -1092,6 +1083,8 @@ static int tgen_cmp(TCGContext *s, TCGType type, TCGC= ond c, TCGReg r1, TCGArg c2, bool c2const, bool need_carry) { bool is_unsigned =3D is_unsigned_cond(c); + S390Opcode op; + if (c2const) { if (c2 =3D=3D 0) { if (!(is_unsigned && need_carry)) { @@ -1102,44 +1095,67 @@ static int tgen_cmp(TCGContext *s, TCGType type, TC= GCond 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 =3D TCG_TMP0; - tcg_out_movi(s, type, c2, 0); - goto do_reg; - } } - if (is_unsigned) { - if (type =3D=3D 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 =3D=3D (int16_t)c2) { + op =3D (type =3D=3D 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 =3D=3D TCG_TYPE_I32) { - tcg_out_insn(s, RIL, CFI, r1, c2); - } else { - tcg_out_insn(s, RIL, CGFI, r1, c2); + op =3D (is_unsigned ? RIL_CLFI : RIL_CFI); + tcg_out_insn_RIL(s, op, r1, c2); + goto exit; + } else if (c2 =3D=3D (is_unsigned ? (uint32_t)c2 : (int32_t)c2= )) { + op =3D (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 =3D TCG_TMP0; + /* fall through to reg-reg */ + } else if (USE_REG_TB) { if (type =3D=3D TCG_TYPE_I32) { - tcg_out_insn(s, RR, CLR, r1, c2); + op =3D (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 =3D (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 =3D=3D TCG_TYPE_I32) { - tcg_out_insn(s, RR, CR, r1, c2); + op =3D (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 =3D (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 =3D=3D TCG_TYPE_I32) { + op =3D (is_unsigned ? RR_CLR : RR_CR); + tcg_out_insn_RR(s, op, r1, c2); + } else { + op =3D (is_unsigned ? RRE_CLGR : RRE_CGR); + tcg_out_insn_RRE(s, op, r1, c2); + } + + exit: return tcg_cond_to_s390_cond[c]; } =20 @@ -2325,8 +2341,6 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpc= ode op) static const TCGTargetOpDef r_L =3D { .args_ct_str =3D { "r", "L" } }; static const TCGTargetOpDef L_L =3D { .args_ct_str =3D { "L", "L" } }; static const TCGTargetOpDef r_ri =3D { .args_ct_str =3D { "r", "ri" } = }; - static const TCGTargetOpDef r_rC =3D { .args_ct_str =3D { "r", "rC" } = }; - static const TCGTargetOpDef r_rZ =3D { .args_ct_str =3D { "r", "rZ" } = }; static const TCGTargetOpDef r_r_ri =3D { .args_ct_str =3D { "r", "r", = "ri" } }; static const TCGTargetOpDef r_0_ri =3D { .args_ct_str =3D { "r", "0", = "ri" } }; static const TCGTargetOpDef r_0_rI =3D { .args_ct_str =3D { "r", "0", = "rI" } }; @@ -2401,10 +2415,8 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOp= code op) return &r_r_ri; =20 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; =20 case INDEX_op_bswap16_i32: case INDEX_op_bswap16_i64: @@ -2430,6 +2442,8 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGOpc= ode op) return &r_r; =20 case INDEX_op_clz_i64: + case INDEX_op_setcond_i32: + case INDEX_op_setcond_i64: return &r_r_ri; =20 case INDEX_op_qemu_ld_i32: @@ -2446,30 +2460,14 @@ static const TCGTargetOpDef *tcg_target_op_def(TCGO= pcode op) =3D { .args_ct_str =3D { "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 - =3D { .args_ct_str =3D { "r", "r", "rZ" } }; - static const TCGTargetOpDef setc_c - =3D { .args_ct_str =3D { "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 - =3D { .args_ct_str =3D { "r", "r", "rZ", "r", "0" } }; - static const TCGTargetOpDef movc_c - =3D { .args_ct_str =3D { "r", "r", "rC", "r", "0" } }; + static const TCGTargetOpDef movc + =3D { .args_ct_str =3D { "r", "r", "ri", "r", "0" } }; static const TCGTargetOpDef movc_l - =3D { .args_ct_str =3D { "r", "r", "rC", "rI", "0" } }; - return (s390_facilities & FACILITY_EXT_IMM - ? (s390_facilities & FACILITY_LOAD_ON_COND2 - ? &movc_l : &movc_c) - : &movc_z); + =3D { .args_ct_str =3D { "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: --=20 2.13.5 From nobody Fri May 3 00:10:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15048246415041022.0177901318519; Thu, 7 Sep 2017 15:50:41 -0700 (PDT) Received: from localhost ([::1]:42552 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5dA-0002V9-Dj for importer@patchew.org; Thu, 07 Sep 2017 18:50:40 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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, uin= tptr_t); #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS #endif +#define TCG_TARGET_NEED_POOL_LABELS =20 #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. */ =20 +#include "tcg-pool.inc.c" #include "qemu/bitops.h" =20 /* 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, AArch64Ins= n 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 =3D value; tcg_target_long ivalue =3D ~value; + tcg_target_long t0, t1, t2; + int s0, s1; + AArch64Insn opc; =20 /* 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, } } =20 - /* 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 =3D wantinv =3D 0; i < 64; i +=3D 16) { - tcg_target_long mask =3D 0xffffull << i; - wantinv -=3D ((value & mask) =3D=3D 0); - wantinv +=3D ((ivalue & mask) =3D=3D 0); - } - - if (wantinv <=3D 0) { - /* Find the lowest lane that is not 0x0000. */ - shift =3D ctz64(value) & (63 & -16); - tcg_out_insn(s, 3405, MOVZ, type, rd, value >> shift, shift); - /* Clear out the lane that we just set. */ - value &=3D ~(0xffffUL << shift); - /* Iterate until all non-zero lanes have been processed. */ - while (value) { - shift =3D ctz64(value) & (63 & -16); - tcg_out_insn(s, 3405, MOVK, type, rd, value >> shift, shift); - value &=3D ~(0xffffUL << shift); - } + /* Would it take fewer insns to begin with MOVN? */ + if (ctpop64(value) >=3D 32) { + t0 =3D ivalue; + opc =3D I3405_MOVN; } else { - /* Like above, but with the inverted value and MOVN to start. */ - shift =3D ctz64(ivalue) & (63 & -16); - tcg_out_insn(s, 3405, MOVN, type, rd, ivalue >> shift, shift); - ivalue &=3D ~(0xffffUL << shift); - while (ivalue) { - shift =3D ctz64(ivalue) & (63 & -16); - /* Provide MOVK with the non-inverted value. */ - tcg_out_insn(s, 3405, MOVK, type, rd, ~(ivalue >> shift), shif= t); - ivalue &=3D ~(0xffffUL << shift); + t0 =3D value; + opc =3D I3405_MOVZ; + } + s0 =3D ctz64(t0) & (63 & -16); + t1 =3D t0 & ~(0xffffUL << s0); + s1 =3D ctz64(t1) & (63 & -16); + t2 =3D t1 & ~(0xffffUL << s1); + if (t2 =3D=3D 0) { + tcg_out_insn_3405(s, opc, type, rd, t0 >> s0, s0); + if (t1 !=3D 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); } =20 /* 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); } =20 +static void tcg_out_nop_fill(tcg_insn_unit *p, int count) +{ + int i; + for (i =3D 0; i < count; ++i) { + p[i] =3D NOP; + } +} + typedef struct { DebugFrameHeader h; uint8_t fde_def_cfa[4]; --=20 2.13.5 From nobody Fri May 3 00:10:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824774686687.858530873134; Thu, 7 Sep 2017 15:52:54 -0700 (PDT) Received: from localhost ([::1]:42561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5fJ-0004Tc-K7 for importer@patchew.org; Thu, 07 Sep 2017 18:52:53 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/sparc/tcg-target.inc.c | 170 +++++++++++++++++++++++++++++++++++++----= ---- 1 file changed, 140 insertions(+), 30 deletions(-) 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] =3D { # define TCG_GUEST_BASE_REG TCG_REG_I5 #endif =20 +#define TCG_REG_TB TCG_REG_I1 +#define USE_REG_TB (sizeof(void *) > 4) + static const int tcg_target_reg_alloc_order[] =3D { TCG_REG_L0, TCG_REG_L1, @@ -249,6 +252,8 @@ static const int tcg_target_call_oarg_regs[] =3D { =20 #define MEMBAR (INSN_OP(2) | INSN_OP3(0x28) | INSN_RS1(15) | (1 << 13)) =20 +#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); } =20 -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 =3D (int32_t)arg; + tcg_target_long test, lsb; =20 /* Make sure we test 32-bit constants for imm13 properly. */ if (type =3D=3D TCG_TYPE_I32) { @@ -455,6 +461,27 @@ static void tcg_out_movi(TCGContext *s, TCGType type, return; } =20 + /* A 21-bit constant, shifted. */ + lsb =3D ctz64(arg); + test =3D (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 =3D=3D 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 =3D 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 =3D (arg - lo) >> 32; @@ -470,6 +497,12 @@ static void tcg_out_movi(TCGContext *s, TCGType type, } } =20 +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, =20 static void tcg_out_ld_ptr(TCGContext *s, TCGReg ret, uintptr_t arg) { + intptr_t diff =3D 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, TCG= Reg rs1, =20 static inline void tcg_out_nop(TCGContext *s) { - tcg_out_sethi(s, TCG_REG_G0, 0); + tcg_out32(s, NOP); } =20 static const uint8_t tcg_cond_to_bcond[] =3D { @@ -812,7 +850,8 @@ static void tcg_out_addsub2_i64(TCGContext *s, TCGReg r= l, TCGReg rh, tcg_out_mov(s, TCG_TYPE_I64, rl, tmp); } =20 -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 =3D tcg_pcrel_diff(s, dest); =20 @@ -820,14 +859,15 @@ static void tcg_out_call_nodelay(TCGContext *s, tcg_i= nsn_unit *dest) tcg_out32(s, CALL | (uint32_t)disp >> 2); } else { uintptr_t desti =3D (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); } } =20 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); } =20 @@ -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); } =20 @@ -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) =20 #ifndef CONFIG_SOFTMMU if (guest_base !=3D 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 =20 + /* We choose TCG_REG_TB such that no move is required. */ + if (USE_REG_TB) { + QEMU_BUILD_BUG_ON(TCG_REG_TB !=3D 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 dat= a, TCGReg addr, func =3D qemu_ld_trampoline[memop & (MO_BSWAP | MO_SSIZE)]; } tcg_debug_assert(func !=3D 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); =20 @@ -1235,7 +1281,7 @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg dat= a, TCGReg addr, =20 func =3D qemu_st_trampoline[memop & (MO_BSWAP | MO_SIZE)]; tcg_debug_assert(func !=3D 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); =20 @@ -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 =3D 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_A= DD); + 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] =3D 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] =3D 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] =3D 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] =3D c =3D 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 =3D -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] =3D 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 =3D (uint32_t *)jmp_addr; - uintptr_t disp =3D addr - jmp_addr; + intptr_t tb_disp =3D addr - tc_ptr; + intptr_t br_disp =3D 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 =3D=3D (int32_t)tb_disp); + tcg_debug_assert(br_disp =3D=3D (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; + } =20 - /* 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 =3D=3D (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 =3D (INSN_OP(0) | INSN_OP2(1) | INSN_COND(COND_A) + | BPCC_ICC | BPCC_PT | INSN_OFF19(br_disp)); + i2 =3D (ARITH_ADD | INSN_RD(TCG_REG_TB) | INSN_RS1(TCG_REG_TB) + | INSN_IMM13(tb_disp)); + } else if (tb_disp >=3D 0) { + i1 =3D SETHI | INSN_RD(TCG_REG_T1) | ((tb_disp & 0xfffffc00) >> 10= ); + i2 =3D (ARITH_OR | INSN_RD(TCG_REG_T1) | INSN_RS1(TCG_REG_T1) + | INSN_IMM13(tb_disp & 0x3ff)); + } else { + i1 =3D SETHI | INSN_RD(TCG_REG_T1) | ((~tb_disp & 0xfffffc00) >> 1= 0); + i2 =3D (ARITH_XOR | INSN_RD(TCG_REG_T1) | INSN_RS1(TCG_REG_T1) + | INSN_IMM13((tb_disp & 0x3ff) | -0x400)); + } =20 - 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); } --=20 2.13.5 From nobody Fri May 3 00:10:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150482465554659.639980786239676; Thu, 7 Sep 2017 15:50:55 -0700 (PDT) Received: from localhost ([::1]:42554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5dO-0002fz-Bu for importer@patchew.org; Thu, 07 Sep 2017 18:50:54 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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) =20 void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t); =20 +#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. */ =20 +#include "tcg-pool.inc.c" + #ifdef CONFIG_DEBUG_TCG static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] =3D { "%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 =3D *code_ptr; + intptr_t pcrel; =20 - tcg_debug_assert(addend =3D=3D 0); - value =3D tcg_ptr_byte_diff((tcg_insn_unit *)value, code_ptr); + value +=3D addend; + pcrel =3D tcg_ptr_byte_diff((tcg_insn_unit *)value, code_ptr); =20 switch (type) { case R_SPARC_WDISP16: - if (!check_fit_ptr(value >> 2, 16)) { - tcg_abort(); - } - insn =3D *code_ptr; + assert(check_fit_ptr(pcrel >> 2, 16)); insn &=3D ~INSN_OFF16(-1); - insn |=3D INSN_OFF16(value); - *code_ptr =3D insn; + insn |=3D INSN_OFF16(pcrel); break; case R_SPARC_WDISP19: - if (!check_fit_ptr(value >> 2, 19)) { - tcg_abort(); - } - insn =3D *code_ptr; + assert(check_fit_ptr(pcrel >> 2, 19)); insn &=3D ~INSN_OFF19(-1); - insn |=3D INSN_OFF19(value); - *code_ptr =3D insn; + insn |=3D 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 =3D (value > 0 ? 0xff8 : -0x1000); + value -=3D adj; + assert(check_fit_ptr(value, 13)); + *code_ptr++ =3D (ARITH_ADD | INSN_RD(TCG_REG_T2) + | INSN_RS1(TCG_REG_TB) | INSN_IMM13(adj)); + insn ^=3D INSN_RS1(TCG_REG_TB) ^ INSN_RS1(TCG_REG_T2); + } + insn &=3D ~INSN_IMM13(-1); + insn |=3D INSN_IMM13(value); break; + case R_SPARC_32: + /* Note that we're abusing this reloc type for our own needs. */ + code_ptr[0] =3D deposit32(code_ptr[0], 0, 22, value >> 10); + code_ptr[1] =3D deposit32(code_ptr[1], 0, 10, value); + return; default: - tcg_abort(); + g_assert_not_reached(); } + + *code_ptr =3D insn; } =20 /* parse target specific constraints */ @@ -474,12 +489,24 @@ static void tcg_out_movi_int(TCGContext *s, TCGType t= ype, TCGReg ret, return; } =20 - if (USE_REG_TB && !in_prologue) { - intptr_t diff =3D 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 =3D 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; } =20 /* A 64-bit constant decomposed into 2 32-bit pieces. */ @@ -1058,6 +1085,14 @@ static void tcg_target_qemu_prologue(TCGContext *s) #endif } =20 +static void tcg_out_nop_fill(tcg_insn_unit *p, int count) +{ + int i; + for (i =3D 0; i < count; ++i) { + p[i] =3D NOP; + } +} + #if defined(CONFIG_SOFTMMU) /* Perform the TLB load and compare. =20 --=20 2.13.5 From nobody Fri May 3 00:10:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150482495762566.28374784975017; Thu, 7 Sep 2017 15:55:57 -0700 (PDT) Received: from localhost ([::1]:42576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5iG-0006w9-Ir for importer@patchew.org; Thu, 07 Sep 2017 18:55:56 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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, TCGRe= g addrlo, TCGReg addrhi, unsigned s_bits =3D opc & MO_SIZE; unsigned a_bits =3D get_alignment_bits(opc); =20 - /* 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)); + } =20 /* 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 -=3D cmp_off & 0xff00; cmp_off &=3D 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)); =20 @@ -1212,24 +1228,40 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGRe= g addrlo, TCGReg addrhi, } } =20 + /* 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 =3D s_bits; } - if (a_bits) { - tcg_out_dat_imm(s, COND_AL, ARITH_TST, 0, addrlo, (1 << a_bits) - = 1); - } =20 - /* 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 =3D ~(TARGET_PAGE_MASK | ((1 << a_bits) - 1)= ); + int rot =3D encode_imm(mask); =20 - 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_BIT= S)); + if (rot >=3D 0) {=20 + 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)); + } =20 if (TARGET_LONG_BITS =3D=3D 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); } =20 return TCG_REG_R2; --=20 2.13.5 From nobody Fri May 3 00:10:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824965698131.81401921380416; Thu, 7 Sep 2017 15:56:05 -0700 (PDT) Received: from localhost ([::1]:42577 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5iO-000734-DE for importer@patchew.org; Thu, 07 Sep 2017 18:56:04 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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, } =20 /* 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 =3D=3D 64 + && cmp_off > 0xff)) { tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_R2, base, (24 << 7) | (cmp_off >> 8)); base =3D TCG_REG_R2; --=20 2.13.5 From nobody Fri May 3 00:10:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150482479046370.09111703709016; Thu, 7 Sep 2017 15:53:10 -0700 (PDT) Received: from localhost ([::1]:42562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5fZ-0004gw-EN for importer@patchew.org; Thu, 07 Sep 2017 18:53:09 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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] =3D { =20 #define TCG_REG_TMP TCG_REG_R12 =20 +enum arm_cond_code_e { + COND_EQ =3D 0x0, + COND_NE =3D 0x1, + COND_CS =3D 0x2, /* Unsigned greater or equal */ + COND_CC =3D 0x3, /* Unsigned less than */ + COND_MI =3D 0x4, /* Negative */ + COND_PL =3D 0x5, /* Zero or greater */ + COND_VS =3D 0x6, /* Overflow */ + COND_VC =3D 0x7, /* No overflow */ + COND_HI =3D 0x8, /* Unsigned greater than */ + COND_LS =3D 0x9, /* Unsigned less or equal */ + COND_GE =3D 0xa, + COND_LT =3D 0xb, + COND_GT =3D 0xc, + COND_LE =3D 0xd, + COND_AL =3D 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 =3D 0x0 << 21, + ARITH_EOR =3D 0x1 << 21, + ARITH_SUB =3D 0x2 << 21, + ARITH_RSB =3D 0x3 << 21, + ARITH_ADD =3D 0x4 << 21, + ARITH_ADC =3D 0x5 << 21, + ARITH_SBC =3D 0x6 << 21, + ARITH_RSC =3D 0x7 << 21, + ARITH_TST =3D 0x8 << 21 | TO_CPSR, + ARITH_CMP =3D 0xa << 21 | TO_CPSR, + ARITH_CMN =3D 0xb << 21 | TO_CPSR, + ARITH_ORR =3D 0xc << 21, + ARITH_MOV =3D 0xd << 21, + ARITH_BIC =3D 0xe << 21, + ARITH_MVN =3D 0xf << 21, + + INSN_CLZ =3D 0x016f0f10, + INSN_RBIT =3D 0x06ff0f30, + + INSN_LDR_IMM =3D 0x04100000, + INSN_LDR_REG =3D 0x06100000, + INSN_STR_IMM =3D 0x04000000, + INSN_STR_REG =3D 0x06000000, + + INSN_LDRH_IMM =3D 0x005000b0, + INSN_LDRH_REG =3D 0x001000b0, + INSN_LDRSH_IMM =3D 0x005000f0, + INSN_LDRSH_REG =3D 0x001000f0, + INSN_STRH_IMM =3D 0x004000b0, + INSN_STRH_REG =3D 0x000000b0, + + INSN_LDRB_IMM =3D 0x04500000, + INSN_LDRB_REG =3D 0x06500000, + INSN_LDRSB_IMM =3D 0x005000d0, + INSN_LDRSB_REG =3D 0x001000d0, + INSN_STRB_IMM =3D 0x04400000, + INSN_STRB_REG =3D 0x06400000, + + INSN_LDRD_IMM =3D 0x004000d0, + INSN_LDRD_REG =3D 0x000000d0, + INSN_STRD_IMM =3D 0x004000f0, + INSN_STRD_REG =3D 0x000000f0, + + INSN_DMB_ISH =3D 0x5bf07ff5, + INSN_DMB_MCR =3D 0xba0f07ee, +} ARMInsn; + +static const uint8_t tcg_cond_to_arm_cond[] =3D { + [TCG_COND_EQ] =3D COND_EQ, + [TCG_COND_NE] =3D COND_NE, + [TCG_COND_LT] =3D COND_LT, + [TCG_COND_GE] =3D COND_GE, + [TCG_COND_LE] =3D COND_LE, + [TCG_COND_GT] =3D COND_GT, + /* unsigned */ + [TCG_COND_LTU] =3D COND_CC, + [TCG_COND_GEU] =3D COND_CS, + [TCG_COND_LEU] =3D COND_LS, + [TCG_COND_GTU] =3D COND_HI, +}; + static inline void reloc_pc24(tcg_insn_unit *code_ptr, tcg_insn_unit *targ= et) { ptrdiff_t offset =3D (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, } } =20 -#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)); +} =20 -typedef enum { - ARITH_AND =3D 0x0 << 21, - ARITH_EOR =3D 0x1 << 21, - ARITH_SUB =3D 0x2 << 21, - ARITH_RSB =3D 0x3 << 21, - ARITH_ADD =3D 0x4 << 21, - ARITH_ADC =3D 0x5 << 21, - ARITH_SBC =3D 0x6 << 21, - ARITH_RSC =3D 0x7 << 21, - ARITH_TST =3D 0x8 << 21 | TO_CPSR, - ARITH_CMP =3D 0xa << 21 | TO_CPSR, - ARITH_CMN =3D 0xb << 21 | TO_CPSR, - ARITH_ORR =3D 0xc << 21, - ARITH_MOV =3D 0xd << 21, - ARITH_BIC =3D 0xe << 21, - ARITH_MVN =3D 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)); +} =20 - INSN_CLZ =3D 0x016f0f10, - INSN_RBIT =3D 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)); +} =20 - INSN_LDR_IMM =3D 0x04100000, - INSN_LDR_REG =3D 0x06100000, - INSN_STR_IMM =3D 0x04000000, - INSN_STR_REG =3D 0x06000000, +static inline void tcg_out_bl(TCGContext *s, int cond, int32_t offset) +{ + tcg_out32(s, (cond << 28) | 0x0b000000 | + (((offset - 8) >> 2) & 0x00ffffff)); +} =20 - INSN_LDRH_IMM =3D 0x005000b0, - INSN_LDRH_REG =3D 0x001000b0, - INSN_LDRSH_IMM =3D 0x005000f0, - INSN_LDRSH_REG =3D 0x001000f0, - INSN_STRH_IMM =3D 0x004000b0, - INSN_STRH_REG =3D 0x000000b0, +static inline void tcg_out_blx(TCGContext *s, int cond, int rn) +{ + tcg_out32(s, (cond << 28) | 0x012fff30 | rn); +} =20 - INSN_LDRB_IMM =3D 0x04500000, - INSN_LDRB_REG =3D 0x06500000, - INSN_LDRSB_IMM =3D 0x005000d0, - INSN_LDRSB_REG =3D 0x001000d0, - INSN_STRB_IMM =3D 0x04400000, - INSN_STRB_REG =3D 0x06400000, +static inline void tcg_out_blx_imm(TCGContext *s, int32_t offset) +{ + tcg_out32(s, 0xfa000000 | ((offset & 2) << 23) | + (((offset - 8) >> 2) & 0x00ffffff)); +} =20 - INSN_LDRD_IMM =3D 0x004000d0, - INSN_LDRD_REG =3D 0x000000d0, - INSN_STRD_IMM =3D 0x004000f0, - INSN_STRD_REG =3D 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); +} =20 - INSN_DMB_ISH =3D 0x5bf07ff5, - INSN_DMB_MCR =3D 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)); + } +} =20 -} 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 !=3D rm) { + tcg_out_dat_reg(s, cond, ARITH_MOV, rd, 0, rm, SHIFT_IMM_LSL(0)); + } +} =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) +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); + } +} =20 -enum arm_cond_code_e { - COND_EQ =3D 0x0, - COND_NE =3D 0x1, - COND_CS =3D 0x2, /* Unsigned greater or equal */ - COND_CC =3D 0x3, /* Unsigned less than */ - COND_MI =3D 0x4, /* Negative */ - COND_PL =3D 0x5, /* Zero or greater */ - COND_VS =3D 0x6, /* Overflow */ - COND_VC =3D 0x7, /* No overflow */ - COND_HI =3D 0x8, /* Unsigned greater than */ - COND_LS =3D 0x9, /* Unsigned less or equal */ - COND_GE =3D 0xa, - COND_LT =3D 0xb, - COND_GT =3D 0xc, - COND_LE =3D 0xd, - COND_AL =3D 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); +} =20 -static const uint8_t tcg_cond_to_arm_cond[] =3D { - [TCG_COND_EQ] =3D COND_EQ, - [TCG_COND_NE] =3D COND_NE, - [TCG_COND_LT] =3D COND_LT, - [TCG_COND_GE] =3D COND_GE, - [TCG_COND_LE] =3D COND_LE, - [TCG_COND_GT] =3D COND_GT, - /* unsigned */ - [TCG_COND_LTU] =3D COND_CC, - [TCG_COND_GEU] =3D COND_CS, - [TCG_COND_LEU] =3D COND_LS, - [TCG_COND_GTU] =3D 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 r= t, + 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 r= t, + TCGReg rn, int imm8, bool p, bool w) +{ + bool u =3D 1; + if (imm8 < 0) { + imm8 =3D -imm8; + u =3D 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 =3D 1; + if (imm12 < 0) { + imm12 =3D -imm12; + u =3D 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); +} =20 -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); } =20 -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); } =20 -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); } =20 -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); } =20 -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); } =20 -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); } =20 -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); } =20 -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); } =20 -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 !=3D 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); } =20 -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); } =20 -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); } =20 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, in= t cond, TCGReg rd, | (ofs << 7) | ((len - 1) << 16)); } =20 -/* 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 r= t, - 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 r= t, - TCGReg rn, int imm8, bool p, bool w) -{ - bool u =3D 1; - if (imm8 < 0) { - imm8 =3D -imm8; - u =3D 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 =3D 1; - if (imm12 < 0) { - imm12 =3D -imm12; - u =3D 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) { --=20 2.13.5 From nobody Fri May 3 00:10:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150482509277473.3177883067874; Thu, 7 Sep 2017 15:58:12 -0700 (PDT) Received: from localhost ([::1]:42583 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5kR-0000Zs-Lm for importer@patchew.org; Thu, 07 Sep 2017 18:58:11 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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 { =20 INSN_DMB_ISH =3D 0x5bf07ff5, INSN_DMB_MCR =3D 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 =3D 0xe320f000, + /* Otherwise the assembler uses mov r0,r0 */ + INSN_NOP_v4 =3D (COND_AL << 28) | ARITH_MOV, } ARMInsn; =20 +#define INSN_NOP (use_armv7_instructions ? INSN_NOP_v6k : INSN_NOP_v4) + static const uint8_t tcg_cond_to_arm_cond[] =3D { [TCG_COND_EQ] =3D COND_EQ, [TCG_COND_NE] =3D COND_NE, @@ -375,16 +385,7 @@ static inline void tcg_out_dat_reg(TCGContext *s, =20 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); } =20 static inline void tcg_out_mov_reg(TCGContext *s, int cond, int rd, int rm) --=20 2.13.5 From nobody Fri May 3 00:10:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824373624987.9789370766069; Thu, 7 Sep 2017 15:46:13 -0700 (PDT) Received: from localhost ([::1]:42536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5Yq-00075O-HN for importer@patchew.org; Thu, 07 Sep 2017 18:46:12 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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, uin= tptr_t); #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS #endif +#define TCG_TARGET_NEED_POOL_LABELS =20 #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 @@ */ =20 #include "elf.h" +#include "tcg-pool.inc.c" =20 int arm_arch =3D __ARM_ARCH; =20 @@ -203,9 +204,39 @@ static inline void reloc_pc24_atomic(tcg_insn_unit *co= de_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 =3D=3D R_ARM_PC24); tcg_debug_assert(addend =3D=3D 0); - reloc_pc24(code_ptr, (tcg_insn_unit *)value); + + if (type =3D=3D R_ARM_PC24) { + reloc_pc24(code_ptr, (tcg_insn_unit *)value); + } else if (type =3D=3D R_ARM_PC13) { + intptr_t diff =3D value - (uintptr_t)(code_ptr + 2); + tcg_insn_unit insn =3D *code_ptr; + bool u; + + if (diff >=3D -0xfff && diff <=3D 0xfff) { + u =3D (diff >=3D 0); + if (!u) { + diff =3D -diff; + } + } else { + int rd =3D extract32(insn, 12, 4); + int rt =3D rd =3D=3D TCG_REG_PC ? TCG_REG_TMP : rd; + assert(diff >=3D 0x1000 && diff < 0x100000); + /* add rt, pc, #high */ + *code_ptr++ =3D ((insn & 0xf0000000) | (1 << 25) | ARITH_ADD + | (TCG_REG_PC << 16) | (rt << 12) + | (20 << 7) | (diff >> 12)); + /* ldr rd, [rt, #low] */ + insn =3D deposit32(insn, 12, 4, rt); + diff &=3D 0xfff; + u =3D 1; + } + insn =3D deposit32(insn, 23, 1, u); + insn =3D deposit32(insn, 0, 12, diff); + *code_ptr =3D insn; + } else { + g_assert_not_reached(); + } } =20 #define TCG_CT_CONST_ARM 0x100 @@ -581,9 +612,20 @@ static inline void tcg_out_ld8s_r(TCGContext *s, int c= ond, TCGReg rt, tcg_out_memop_r(s, cond, INSN_LDRSB_REG, rt, rn, rm, 1, 1, 0); } =20 +static void tcg_out_movi_pool(TCGContext *s, int cond, int rd, uint32_t ar= g) +{ + /* 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; =20 /* Check a single MOV/MVN before anything else. */ rot =3D encode_imm(arg); @@ -631,24 +673,30 @@ static void tcg_out_movi32(TCGContext *s, int cond, i= nt rd, uint32_t arg) return; } =20 - /* 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 =3D arg; opc =3D ARITH_MOV; - rn =3D 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 =3D ARITH_MVN, arg =3D ~arg; + if (ctpop32(arg) > 16) { + tt0 =3D ~arg; + opc =3D ARITH_MVN; + } + sh1 =3D ctz32(tt0) & ~1; + tt1 =3D tt0 & ~(0xff << sh1); + sh2 =3D ctz32(tt1) & ~1; + tt2 =3D tt1 & ~(0xff << sh2); + if (tt2 =3D=3D 0) { + rot =3D ((32 - sh1) << 7) & 0xf00; + tcg_out_dat_imm(s, cond, opc, rd, 0, ((tt0 >> sh1) & 0xff) | rot); + rot =3D ((32 - sh2) << 7) & 0xf00; + tcg_out_dat_imm(s, cond, ARITH_EOR, rd, rd, + ((tt0 >> sh2) & 0xff) | rot); + return; } - do { - int i =3D ctz32(arg) & ~1; - rot =3D ((32 - i) << 7) & 0xf00; - tcg_out_dat_imm(s, cond, opc, rd, rn, ((arg >> i) & 0xff) | rot); - arg &=3D ~(0xff << i); =20 - opc =3D ARITH_EOR; - rn =3D rd; - } while (arg); + /* Otherwise, drop it into the constant pool. */ + tcg_out_movi_pool(s, cond, rd, arg); } =20 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, TCGTy= pe type, tcg_out_movi32(s, COND_AL, ret, arg); } =20 +static void tcg_out_nop_fill(tcg_insn_unit *p, int count) +{ + int i; + for (i =3D 0; i < count; ++i) { + p[i] =3D INSN_NOP; + } +} + /* Compute frame size via macros, to share between tcg_target_qemu_prologue and tcg_register_jit. */ =20 --=20 2.13.5 From nobody Fri May 3 00:10:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504825212056926.2944052092201; Thu, 7 Sep 2017 16:00:12 -0700 (PDT) Received: from localhost ([::1]:42597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5mM-0002GS-TF for importer@patchew.org; Thu, 07 Sep 2017 19:00:10 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.inc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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, tc= g_insn_unit *addr) tcg_out_b(s, cond, disp); return; } - - assert(use_armv5t_instructions || (addri & 1) =3D=3D 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); } =20 /* 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); } } =20 --=20 2.13.5 From nobody Fri May 3 00:10:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504825059886144.7277231208459; Thu, 7 Sep 2017 15:57:39 -0700 (PDT) Received: from localhost ([::1]:42582 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5ju-0008Kb-VE for importer@patchew.org; Thu, 07 Sep 2017 18:57:38 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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 =20 -/* 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 =3D=3D 64) +#define TCG_REG_TB TCG_REG_R31 +#define USE_REG_TB (TCG_TARGET_REG_BITS =3D=3D 64) =20 /* 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, TCGR= eg dst, TCGReg src, int c) tcg_out_rld(s, RLDICL, dst, src, 64 - c, c); } =20 -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 =3D=3D (int16_t) arg) { + intptr_t tb_diff; + int32_t high; + + tcg_debug_assert(TCG_TARGET_REG_BITS =3D=3D 64 || type =3D=3D TCG_TYPE= _I32); + + if (TCG_TARGET_REG_BITS =3D=3D 64 && type =3D=3D TCG_TYPE_I32) { + arg =3D (int32_t)arg; + } + + /* Load 16-bit immediates with one insn. */ + if (arg =3D=3D (int16_t)arg) { tcg_out32(s, ADDI | TAI(ret, 0, arg)); - } else { + return; + } + + /* Load addresses within the TB with one insn. */ + tb_diff =3D arg - (intptr_t)s->code_gen_ptr; + if (!in_prologue && USE_REG_TB && tb_diff =3D=3D (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 =3D=3D 32 || arg =3D=3D (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 =3D=3D 64 || type =3D=3D TCG_TYPE= _I32); - if (type =3D=3D TCG_TYPE_I32 || arg =3D=3D (int32_t)arg) { - tcg_out_movi32(s, ret, arg); - } else if (arg =3D=3D (uint32_t)arg && !(arg & 0x8000)) { + if (arg =3D=3D (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; + } =20 - if (USE_REG_RA) { - intptr_t diff =3D arg - (intptr_t)tb_ret_addr; - if (diff =3D=3D (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 =3D=3D (int32_t)tb_diff) { + tcg_out_mem_long(s, ADDI, ADD, ret, TCG_REG_TB, tb_diff); + return; + } =20 - high =3D 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 =3D 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); } =20 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); } =20 -#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 =3D addr - jmp_addr; - - if (in_range_b(diff)) { - i1 =3D B | (diff & 0x3fffffc); - i2 =3D NOP; - } else if (USE_REG_RA) { - intptr_t lo, hi; - diff =3D addr - (uintptr_t)tb_ret_addr; - lo =3D (int16_t)diff; - hi =3D (int32_t)(diff - lo); - tcg_debug_assert(diff =3D=3D hi + lo); - i1 =3D ADDIS | TAI(TCG_REG_TMP1, TCG_REG_RA, hi >> 16); - i2 =3D ADDI | TAI(TCG_REG_TMP1, TCG_REG_TMP1, lo); - } else { - tcg_debug_assert(TCG_TARGET_REG_BITS =3D=3D 32 || addr =3D=3D (int= 32_t)addr); - i1 =3D ADDIS | TAI(TCG_REG_TMP1, 0, addr >> 16); - i2 =3D ORI | SAI(TCG_REG_TMP1, TCG_REG_TMP1, addr); - } + if (TCG_TARGET_REG_BITS =3D=3D 64) { + tcg_insn_unit i1, i2; + intptr_t tb_diff =3D addr - tc_ptr; + intptr_t br_diff =3D 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 =3D=3D (int16_t)tb_diff) { + i1 =3D ADDI | TAI(TCG_REG_TB, TCG_REG_TB, tb_diff); + i2 =3D B | (br_diff & 0x3fffffc); + } else { + intptr_t lo =3D (int16_t)tb_diff; + intptr_t hi =3D (int32_t)(tb_diff - lo); + assert(tb_diff =3D=3D hi + lo); + i1 =3D ADDIS | TAI(TCG_REG_TB, TCG_REG_TB, hi >> 16); + i2 =3D ADDI | TAI(TCG_REG_TB, TCG_REG_TB, lo); + } #ifdef HOST_WORDS_BIGENDIAN - pair =3D (uint64_t)i1 << 32 | i2; + pair =3D (uint64_t)i1 << 32 | i2; #else - pair =3D (uint64_t)i2 << 32 | i1; + pair =3D (uint64_t)i2 << 32 | i1; #endif =20 - 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 =3D 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 =3D 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 =20 static void tcg_out_call(TCGContext *s, tcg_insn_unit *target) { @@ -1897,44 +1888,20 @@ static void tcg_target_qemu_prologue(TCGContext *s) =20 #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 =20 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 =3D s->code_ptr + 2; - desc[1] =3D 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 =3D=3D 2 - /* Compute from the incoming R12 value. */ - tb_ret_addr =3D 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 =3D 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 =3D 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); =20 /* Epilogue */ - tcg_debug_assert(tb_ret_addr =3D=3D s->code_ptr); - s->code_gen_epilogue =3D tb_ret_addr; + s->code_gen_epilogue =3D tb_ret_addr =3D s->code_ptr; =20 tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R0, TCG_REG_R1, FRAME_SIZE+LR_OFFS= ET); for (i =3D 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, =20 switch (opc) { case INDEX_op_exit_tb: - if (USE_REG_RA) { - ptrdiff_t disp =3D tcg_pcrel_diff(s, tb_ret_addr); - - /* Use a direct branch if we can, otherwise use the value in R= A. - 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]] =3D tcg_current_code_size(s); - /* To be replaced by either a branch+nop or a load into TMP1. */ - s->code_ptr +=3D 2; - tcg_out32(s, MTSPR | RS(TCG_REG_TMP1) | CTR); + if (s->tb_jmp_insn_offset) { + /* Direct jump. */ + if (TCG_TARGET_REG_BITS =3D=3D 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]] =3D 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]] =3D tcg_current_code_size(s= ); + tcg_out32(s, B); + s->tb_jmp_reset_offset[args[0]] =3D tcg_current_code_size(= s); + break; + } + } else { + /* Indirect jump. */ + tcg_debug_assert(s->tb_jmp_insn_offset =3D=3D 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]] =3D tcg_current_code_size(s); + s->tb_jmp_reset_offset[args[0]] =3D c =3D tcg_current_code_size(s); + if (USE_REG_TB) { + /* For the unlinked case, need to reset TCG_REG_TB. */ + c =3D -c; + assert(c =3D=3D (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 */ } } =20 --=20 2.13.5 From nobody Fri May 3 00:10:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504825098717336.7176856790603; Thu, 7 Sep 2017 15:58:18 -0700 (PDT) Received: from localhost ([::1]:42584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5kX-0000fL-Oy for importer@patchew.org; Thu, 07 Sep 2017 18:58:17 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Richard Henderson Signed-off-by: Richard Henderson --- tcg/ppc/tcg-target.inc.c | 58 +++++++++++++++++++++++++++++++++++++++-----= ---- 1 file changed, 48 insertions(+), 10 deletions(-) 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, TCGR= eg dst, TCGReg src, int c) tcg_out_rld(s, RLDICL, dst, src, 64 - c, c); } =20 +/* 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 ar= g) +{ + if (arg =3D=3D (int16_t)arg) { + tcg_out32(s, ADDI | TAI(ret, 0, arg)); + return true; + } + if (arg =3D=3D (int32_t)arg && (arg & 0xffff) =3D=3D 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; =20 tcg_debug_assert(TCG_TARGET_REG_BITS =3D=3D 64 || type =3D=3D TCG_TYPE= _I32); =20 @@ -606,8 +621,7 @@ static void tcg_out_movi_int(TCGContext *s, TCGType typ= e, TCGReg ret, } =20 /* Load 16-bit immediates with one insn. */ - if (arg =3D=3D (int16_t)arg) { - tcg_out32(s, ADDI | TAI(ret, 0, arg)); + if (tcg_out_movi_one(s, ret, arg)) { return; } =20 @@ -618,12 +632,11 @@ static void tcg_out_movi_int(TCGContext *s, TCGType t= ype, TCGReg ret, return; } =20 - /* 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 =3D=3D 32 || arg =3D=3D (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 =3D=3D (uint32_t)arg && !(arg & 0x8000)) { @@ -632,15 +645,40 @@ static void tcg_out_movi_int(TCGContext *s, TCGType t= ype, TCGReg ret, return; } =20 + /* Load masked 16-bit value. */ + if (arg > 0 && (arg & 0x8000)) { + tmp =3D arg | 0x7fff; + if ((tmp & (tmp + 1)) =3D=3D 0) { + int mb =3D 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 =3D ctz64(arg); + tmp =3D arg >> shift; + if (tmp =3D=3D (int16_t)tmp) { + tcg_out32(s, ADDI | TAI(ret, 0, tmp)); + tcg_out_shli64(s, ret, ret, shift); + return; + } + shift =3D 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 =3D=3D (int32_t)tb_diff) { tcg_out_mem_long(s, ADDI, ADD, ret, TCG_REG_TB, tb_diff); return; } =20 - high =3D arg >> 31 >> 1; - tcg_out_movi(s, TCG_TYPE_I32, ret, high); - if (high) { + tmp =3D arg >> 31 >> 1; + tcg_out_movi(s, TCG_TYPE_I32, ret, tmp); + if (tmp) { tcg_out_shli64(s, ret, ret, 32); } if (arg & 0xffff0000) { --=20 2.13.5 From nobody Fri May 3 00:10:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1504824922916199.31274252364653; Thu, 7 Sep 2017 15:55:22 -0700 (PDT) Received: from localhost ([::1]:42570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5hh-0006Oa-Go for importer@patchew.org; Thu, 07 Sep 2017 18:55:21 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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(-) 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, uin= tptr_t); #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS #endif +#define TCG_TARGET_NEED_POOL_LABELS =20 #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. */ =20 +#include "elf.h" +#include "tcg-pool.inc.c" + #if defined _CALL_DARWIN || defined __APPLE__ #define TCG_TARGET_CALL_DARWIN #endif @@ -58,8 +61,6 @@ =20 static tcg_insn_unit *tb_ret_addr; =20 -#include "elf.h" - bool have_isa_2_06; bool have_isa_3_00; =20 @@ -224,9 +225,12 @@ static inline void tcg_out_bc_noaddr(TCGContext *s, in= t insn) static void patch_reloc(tcg_insn_unit *code_ptr, int type, intptr_t value, intptr_t addend) { - tcg_insn_unit *target =3D (tcg_insn_unit *)value; + tcg_insn_unit *target; + tcg_insn_unit old; + + value +=3D addend; + target =3D (tcg_insn_unit *)value; =20 - tcg_debug_assert(addend =3D=3D 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 t= ype, case R_PPC_REL24: reloc_pc24(code_ptr, target); break; + case R_PPC_ADDR16: + assert(value =3D=3D (int16_t)value); + old =3D *code_ptr; + old =3D deposit32(old, 0, 16, value); + *code_ptr =3D old; + break; default: tcg_abort(); } @@ -676,6 +686,14 @@ static void tcg_out_movi_int(TCGContext *s, TCGType ty= pe, TCGReg ret, return; } =20 + /* 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 =3D 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 TCG= Arg *args, bool is_64) #endif } =20 +static void tcg_out_nop_fill(tcg_insn_unit *p, int count) +{ + int i; + for (i =3D 0; i < count; ++i) { + p[i] =3D NOP; + } +} + /* Parameters for function call generation, used in tcg.c. */ #define TCG_TARGET_STACK_ALIGN 16 #define TCG_TARGET_EXTEND_ARGS 1 --=20 2.13.5