From patchwork Thu Oct 20 12:21:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 616728 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp235267pvb; Thu, 20 Oct 2022 05:52:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7MUgrk1I9SYazJ5G1bCI8kKFS/YZw+UWNPJNZGVtkwcv5EnDKT9FG+g8MzJlaPuFPpZV5b X-Received: by 2002:ad4:5ccb:0:b0:4b1:9179:fb8e with SMTP id iu11-20020ad45ccb000000b004b19179fb8emr11022898qvb.67.1666270322369; Thu, 20 Oct 2022 05:52:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666270322; cv=none; d=google.com; s=arc-20160816; b=vtLDPXlXsRKE2WNYCvEQXNwuwgTYxXtBsuBMb4UtN4rDAxuDvQmY11ZjSSVw0nDT+N T/IMFdrmYgVwN8Me4Nwq6T0BTx4MUHO0TjrhSitMsZs9bYS6H8ltctPuDGeyaWVHoOGb kRuNWb2I+9MyuPtGZTQ/7eh0hmLS7A1UlZnRwkfIIe6inimTKwfKHKSjxH2xnKPHk3Ql KRxC1ocyrModNQes2n0TXhCwz4sM3Sx2Qu5xv4/QbZNVtRlrBL+PFLoBrVSCoBSXuXmg 8ory3d21DKc2dFW97pINoM2v/ub0VxaaIsENIuT24SRuVycZ1gFF+hZw8Kbn7xOrA6M9 JTfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=XasLtqTE55A94kwKBu7X33zGDYkxtNkEgIEIZTHoGJ4=; b=rr4MybZrVL3kX2ndweu9g7cfzipbFNkF355U/zRKBu3V6cxAkLIEjcpDsfgisoP+Im jlDroLpr3P8HVvvVHzHJqJTADJhKwcTI1SYMIi5LMEsEYoRDxfarwjNwX8rsKCSSzQPb sXBVlrsYAGbqEaCoSq4H7MDcPr6idAxINpSxxnPTOb+Hbd5F7iQmzV0DU42HfzWQQvAC RUKyqXbxWxYWePPr0GaxQqPZ/aHHo0cmaU34EPkFBYduZ0jEUn9J+SVf6hIBVPPxpYx9 /ZNe9eZGn3dNSatFh1QDE4fFa8bnSu4RRX2we4245RgbBnihi3bWQaOouAsJgz6Syt2b revA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K92ynhp8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id eq3-20020ad45963000000b004968b28d4c0si9769725qvb.530.2022.10.20.05.52.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Oct 2022 05:52:02 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K92ynhp8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37898 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olV1k-0000ne-3V for patch@linaro.org; Thu, 20 Oct 2022 08:52:00 -0400 Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olUyB-0003Fq-9A for patch@linaro.org; Thu, 20 Oct 2022 08:48:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olUZL-0001b1-Mw for qemu-devel@nongnu.org; Thu, 20 Oct 2022 08:23:00 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:36678) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1olUZ1-00016t-IZ for qemu-devel@nongnu.org; Thu, 20 Oct 2022 08:22:33 -0400 Received: by mail-wm1-x333.google.com with SMTP id c3-20020a1c3503000000b003bd21e3dd7aso2194974wma.1 for ; Thu, 20 Oct 2022 05:22:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=XasLtqTE55A94kwKBu7X33zGDYkxtNkEgIEIZTHoGJ4=; b=K92ynhp8cQ0q13qxRwQbaehChxPas+vZB2c8NgUzrwQd8+Q6YAnHkPSPY4+DylYYWu gJGe+HuS7YpWkLi6ly8Ed65gPCPHRh1jmALvzXV7Mm/Zd7JSdLJtUBLXqnYgXnEEd+uf jSo0e3Mk+H6QAjIXFIDKBUZ01iXus5em++gcoPTjADb9w6FmCZuupp4rTOd7JxOG/4JH MCUVUQqJLmSvNK+ziSIx6Y0vIX34ejAe64hhzaJR8lpUP2L3xqogLKme/BHw0KsStUbI brebor0A9lXdrwet/C6O0qJ+HIau0ekGbImOsuCw3QdPJja4B/2/6xehU5d2OGXjK/Cf 2i9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XasLtqTE55A94kwKBu7X33zGDYkxtNkEgIEIZTHoGJ4=; b=wpMVS2PC2neC0gKxfyRe2Tgwxgczh+D+nspmSg5hLrIcR1CKu8Ah8ril41G5w1LFMs gM2w1N6elNjti91lCrVdyrIBiit0gbGUGnPZladwb1gfCLkl/loPe330Lr0QNX6biPPz qdDPKz/8sSh2ZH9O6XirDpYjqaYGBemPzsOpzd5eEBK2eo98Vlln6ZburvzSsi3arlz1 z2It3mIQ4h6PcrPOrJ78bJ8Xb4jHpL0AV/w3F63sNHfR0OlwMY9MRo//Au9QkNEYZVwt IFug4njRWS3DqXqIzla0GlKKKKOPh9X7j/hsKktExYUaPKipC8RD6dhTlLHZTsb2/dEG LsUg== X-Gm-Message-State: ACrzQf0TkZ+eJx6YkhljyXsjDRVbomcBWsOXfhX+1fhL5Taz7ccFra8t OIc68nNp2lUA4C5pTv1UtRLQbkcRvbD11w== X-Received: by 2002:a1c:f20f:0:b0:3be:eff3:bda2 with SMTP id s15-20020a1cf20f000000b003beeff3bda2mr29568700wmc.125.1666268534688; Thu, 20 Oct 2022 05:22:14 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id t15-20020a5d49cf000000b00230c9d427f9sm16520192wrs.53.2022.10.20.05.22.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 05:22:14 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 20/24] target/arm: Change gen_jmp* to work on displacements Date: Thu, 20 Oct 2022 13:21:42 +0100 Message-Id: <20221020122146.3177980-21-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020122146.3177980-1-peter.maydell@linaro.org> References: <20221020122146.3177980-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson In preparation for TARGET_TB_PCREL, reduce reliance on absolute values. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson Message-id: 20221020030641.2066807-7-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/translate.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/target/arm/translate.c b/target/arm/translate.c index 9104ab82325..ca128edab7e 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -266,6 +266,12 @@ static uint32_t read_pc(DisasContext *s) return s->pc_curr + (s->thumb ? 4 : 8); } +/* The pc_curr difference for an architectural jump. */ +static target_long jmp_diff(DisasContext *s, target_long diff) +{ + return diff + (s->thumb ? 4 : 8); +} + /* Set a variable to the value of a CPU register. */ void load_reg_var(DisasContext *s, TCGv_i32 var, int reg) { @@ -2592,7 +2598,7 @@ static void gen_goto_ptr(void) * cpu_loop_exec. Any live exit_requests will be processed as we * enter the next TB. */ -static void gen_goto_tb(DisasContext *s, int n, int diff) +static void gen_goto_tb(DisasContext *s, int n, target_long diff) { target_ulong dest = s->pc_curr + diff; @@ -2608,10 +2614,8 @@ static void gen_goto_tb(DisasContext *s, int n, int diff) } /* Jump, specifying which TB number to use if we gen_goto_tb() */ -static inline void gen_jmp_tb(DisasContext *s, uint32_t dest, int tbno) +static void gen_jmp_tb(DisasContext *s, target_long diff, int tbno) { - int diff = dest - s->pc_curr; - if (unlikely(s->ss_active)) { /* An indirect jump so that we still trigger the debug exception. */ gen_update_pc(s, diff); @@ -2653,9 +2657,9 @@ static inline void gen_jmp_tb(DisasContext *s, uint32_t dest, int tbno) } } -static inline void gen_jmp(DisasContext *s, uint32_t dest) +static inline void gen_jmp(DisasContext *s, target_long diff) { - gen_jmp_tb(s, dest, 0); + gen_jmp_tb(s, diff, 0); } static inline void gen_mulxy(TCGv_i32 t0, TCGv_i32 t1, int x, int y) @@ -8322,7 +8326,7 @@ static bool trans_CLRM(DisasContext *s, arg_CLRM *a) static bool trans_B(DisasContext *s, arg_i *a) { - gen_jmp(s, read_pc(s) + a->imm); + gen_jmp(s, jmp_diff(s, a->imm)); return true; } @@ -8337,14 +8341,14 @@ static bool trans_B_cond_thumb(DisasContext *s, arg_ci *a) return true; } arm_skip_unless(s, a->cond); - gen_jmp(s, read_pc(s) + a->imm); + gen_jmp(s, jmp_diff(s, a->imm)); return true; } static bool trans_BL(DisasContext *s, arg_i *a) { tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | s->thumb); - gen_jmp(s, read_pc(s) + a->imm); + gen_jmp(s, jmp_diff(s, a->imm)); return true; } @@ -8364,7 +8368,8 @@ static bool trans_BLX_i(DisasContext *s, arg_BLX_i *a) } tcg_gen_movi_i32(cpu_R[14], s->base.pc_next | s->thumb); store_cpu_field_constant(!s->thumb, thumb); - gen_jmp(s, (read_pc(s) & ~3) + a->imm); + /* This jump is computed from an aligned PC: subtract off the low bits. */ + gen_jmp(s, jmp_diff(s, a->imm - (s->pc_curr & 3))); return true; } @@ -8525,10 +8530,10 @@ static bool trans_WLS(DisasContext *s, arg_WLS *a) * when we take this upcoming exit from this TB, so gen_jmp_tb() is OK. */ } - gen_jmp_tb(s, s->base.pc_next, 1); + gen_jmp_tb(s, curr_insn_len(s), 1); gen_set_label(nextlabel); - gen_jmp(s, read_pc(s) + a->imm); + gen_jmp(s, jmp_diff(s, a->imm)); return true; } @@ -8608,7 +8613,7 @@ static bool trans_LE(DisasContext *s, arg_LE *a) if (a->f) { /* Loop-forever: just jump back to the loop start */ - gen_jmp(s, read_pc(s) - a->imm); + gen_jmp(s, jmp_diff(s, -a->imm)); return true; } @@ -8639,7 +8644,7 @@ static bool trans_LE(DisasContext *s, arg_LE *a) tcg_temp_free_i32(decr); } /* Jump back to the loop start */ - gen_jmp(s, read_pc(s) - a->imm); + gen_jmp(s, jmp_diff(s, -a->imm)); gen_set_label(loopend); if (a->tp) { @@ -8647,7 +8652,7 @@ static bool trans_LE(DisasContext *s, arg_LE *a) store_cpu_field(tcg_constant_i32(4), v7m.ltpsize); } /* End TB, continuing to following insn */ - gen_jmp_tb(s, s->base.pc_next, 1); + gen_jmp_tb(s, curr_insn_len(s), 1); return true; } @@ -8746,7 +8751,7 @@ static bool trans_CBZ(DisasContext *s, arg_CBZ *a) tcg_gen_brcondi_i32(a->nz ? TCG_COND_EQ : TCG_COND_NE, tmp, 0, s->condlabel); tcg_temp_free_i32(tmp); - gen_jmp(s, read_pc(s) + a->imm); + gen_jmp(s, jmp_diff(s, a->imm)); return true; }